X-Git-Url: https://git.distorted.org.uk/~mdw/bascat/blobdiff_plain/992dc05925cd822fa045c644756408536217c9ac..85dd468c12f531710f50baff9fc9d5daad3813bb:/bascat.c diff --git a/bascat.c b/bascat.c index b685a5c..218b749 100644 --- a/bascat.c +++ b/bascat.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: bascat.c,v 1.4 1999/10/28 10:42:23 mdw Exp $ + * $Id$ * * Display BBC BASIC programs more or less anywhere * @@ -26,26 +26,6 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: bascat.c,v $ - * Revision 1.4 1999/10/28 10:42:23 mdw - * More minor twiddling. - * - * Revision 1.3 1999/10/28 10:18:17 mdw - * Minor name changes for new coding standards. - * - * Revision 1.2 1998/06/26 11:29:28 mdw - * Added support for line-numbers. - * - * Revision 1.1 1998/03/16 15:21:37 mdw - * Files placed under CVS control. - * - * Revision 1.1 1997/07/23 01:19:33 mdw - * Initial revision - * - */ - /*----- Header files ------------------------------------------------------*/ /* --- ANSI library headers --- */ @@ -70,7 +50,7 @@ /*----- Version information -----------------------------------------------*/ -#ifndef NDEBUG +#ifdef DEBUG # define D(x) x #else # define D(x) @@ -226,7 +206,7 @@ static void keyword(const char *s, FILE *fp) * Use: Decodes multibyte tokens. */ -static int mbtok(int byte, const char *t[], int n, FILE * fp) +static int mbtok(int byte, const char *t[], int n, FILE *fp) { byte -= 0x8E; if (byte >= n) @@ -246,7 +226,7 @@ static int mbtok(int byte, const char *t[], int n, FILE * fp) * Use: Decodes a byte, changing states as necessary. */ -static int decode(int byte, FILE * fp) +static int decode(int byte, FILE *fp) { switch (state) { @@ -324,17 +304,20 @@ static int decode(int byte, FILE * fp) /* --- Encoded line number states --- */ case s_linex: - lineno = ((((byte << 2) | (byte << 12)) & 0xc0c0u) ^ 0x4040u); + byte ^= 0x54; + lineno = (((byte & 0x30) << 2) | + ((byte & 0x0c) << 12) | + ((byte & 0x03) << 16)); state++; break; case s_liney: - lineno |= byte & 0x3fu; + lineno |= byte & 0x3f; state++; break; case s_linez: - lineno |= (byte << 8) & 0x3fu; + lineno |= (byte & 0x3f) << 8; fprintf(fp, "%u", lineno); state = s_normal; break; @@ -386,7 +369,7 @@ static int line(FILE *in, FILE *out) goto eof; len -= 4; - state = s_normal; + state = s_keyword; while (len) { byte = getc(in); D( fprintf(stderr, "state == %i, byte == %i\n",