From c31008c78a3d299f14f6c59e99e235a68a20b62b Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 15 Jun 2000 19:03:01 +0000 Subject: [PATCH] Remove io.*, some cleanup git-svn-id: svn://svn.cc65.org/cc65/trunk@87 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/codegen.c | 1 - src/cc65/compile.c | 2 -- src/cc65/error.c | 1 - src/cc65/expr.c | 1 - src/cc65/input.c | 73 ++++++++++++++++++++++++++++++++------- src/cc65/input.h | 34 ++++++++++++++++++ src/cc65/io.c | 72 -------------------------------------- src/cc65/io.h | 74 ---------------------------------------- src/cc65/litpool.h | 4 +++ src/cc65/make/gcc.mak | 1 - src/cc65/make/watcom.mak | 1 - src/cc65/optimize.c | 2 +- src/cc65/pragma.c | 1 - src/cc65/preproc.c | 23 +++++++------ src/cc65/scanner.c | 1 - src/cc65/symtab.c | 1 - 16 files changed, 112 insertions(+), 180 deletions(-) delete mode 100644 src/cc65/io.c delete mode 100644 src/cc65/io.h diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index fc5a7c4a6..dfc986d09 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -45,7 +45,6 @@ #include "cpu.h" #include "error.h" #include "global.h" -#include "io.h" #include "litpool.h" #include "optimize.h" #include "util.h" diff --git a/src/cc65/compile.c b/src/cc65/compile.c index 4d62aefe5..1177c51e9 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -45,7 +45,6 @@ #include "function.h" #include "global.h" #include "incpath.h" -#include "io.h" #include "litpool.h" #include "macrotab.h" #include "pragma.h" @@ -66,7 +65,6 @@ static void Parse (void) int comma; SymEntry* Entry; - kill (); NextToken (); /* "prime" the pump */ NextToken (); while (curtok != TOK_CEOF) { diff --git a/src/cc65/error.c b/src/cc65/error.c index dd2d17c57..437b12763 100644 --- a/src/cc65/error.c +++ b/src/cc65/error.c @@ -39,7 +39,6 @@ #include "global.h" #include "input.h" -#include "io.h" #include "scanner.h" #include "stmt.h" #include "error.h" diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 470d690f8..4f1a46858 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -22,7 +22,6 @@ #include "funcdesc.h" #include "function.h" #include "global.h" -#include "io.h" #include "litpool.h" #include "macrotab.h" #include "preproc.h" diff --git a/src/cc65/input.c b/src/cc65/input.c index 72e157bdb..4bd910e61 100644 --- a/src/cc65/input.c +++ b/src/cc65/input.c @@ -44,7 +44,6 @@ #include "error.h" #include "global.h" #include "incpath.h" -#include "io.h" #include "input.h" @@ -55,6 +54,11 @@ +/* Input line stuff */ +static char LineBuf [LINESIZE]; +char* line = LineBuf; +char* lptr = LineBuf; + /* Maximum count of nested includes */ #define MAX_INC_NESTING 16 @@ -78,7 +82,7 @@ static IFile* Input = 0; /* Single linked list of active files */ /*****************************************************************************/ -/* struct IFile */ +/* struct IFile */ /*****************************************************************************/ @@ -142,7 +146,7 @@ void OpenIncludeFile (const char* Name, unsigned DirSpec) /* Check for the maximum include nesting */ if (IFileCount > MAX_INC_NESTING) { PPError (ERR_INCLUDE_NESTING); - return; + return; } /* Search for the file */ @@ -196,7 +200,7 @@ int NextLine (void) int Done; /* Setup the line */ - kill (); + ClearLine (); /* If there is no file open, bail out */ if (Input == 0) { @@ -210,8 +214,8 @@ int NextLine (void) while (fgets (line + Len, LINESIZE - Len, Input->F) == 0) { - /* eof */ - kill (); + /* Assume EOF */ + ClearLine (); /* Leave the current file */ CloseIncludeFile (); @@ -232,7 +236,7 @@ int NextLine (void) while (Len > 0 && line [Len-1] == '\n') { --Len; } - line [Len] = '\0'; + line [Len] = '\0'; /* Output the source line in the generated assembler file * if requested. @@ -246,9 +250,9 @@ int NextLine (void) */ if (Len > 0 && line[Len-1] == '\\') { line[Len-1] = '\n'; /* Replace by newline */ - } else { - Done = 1; - } + } else { + Done = 1; + } } /* Got a line */ @@ -257,13 +261,22 @@ int NextLine (void) +void ClearLine (void) +/* Clear the current input line */ +{ + line [0] = '\0'; + lptr = line; +} + + + const char* GetCurrentFile (void) /* Return the name of the current input file */ { if (Input == 0) { - return "(outside file scope)"; + return "(outside file scope)"; } else { - return Input->Name; + return Input->Name; } } @@ -277,3 +290,39 @@ unsigned GetCurrentLine (void) +int nch (void) +/* Get the next char in input stream (the one behind the current one) */ +{ + if (*lptr == '\0') { + return 0; + } else { + return lptr[1] & 0xFF; + } +} + + + +int cgch (void) +/* Get the current character in the input stream and advance line + * pointer (unless already at end of line). + */ +{ + if (*lptr == '\0') { + return (0); + } else { + return (*lptr++ & 0xFF); + } +} + + + +int gch (void) +/* Get the current character in the input stream and advance line + * pointer (no end of line check is performed). + */ +{ + return (*lptr++ & 0xFF); +} + + + diff --git a/src/cc65/input.h b/src/cc65/input.h index e938d6613..662ab2f59 100644 --- a/src/cc65/input.h +++ b/src/cc65/input.h @@ -38,6 +38,22 @@ +/*****************************************************************************/ +/* data */ +/*****************************************************************************/ + + + +/* Maximum length of an input line and the corresponding char array */ +#define LINEMAX 4095 +#define LINESIZE LINEMAX+1 + +/* Input line stuff */ +extern char* line; +extern char* lptr; + + + /*****************************************************************************/ /* Code */ /*****************************************************************************/ @@ -53,12 +69,30 @@ void OpenIncludeFile (const char* Name, unsigned DirSpec); int NextLine (void); /* Get a line from the current input. Returns 0 on end of file. */ +void ClearLine (void); +/* Clear the current input line */ + const char* GetCurrentFile (void); /* Return the name of the current input file */ unsigned GetCurrentLine (void); /* Return the line number in the current input file */ +int nch (void); +/* Get the next char in input stream (the one behind the current one) */ + +int cgch (void); +/* Get the current character in the input stream and advance line + * pointer (unless already at end of line). + */ + +int gch (void); +/* Get the current character in the input stream and advance line + * pointer (no end of line check is performed). + */ + + + /* End of input.h */ diff --git a/src/cc65/io.c b/src/cc65/io.c deleted file mode 100644 index 7e24cf3c6..000000000 --- a/src/cc65/io.c +++ /dev/null @@ -1,72 +0,0 @@ - -/* C I/O functions */ - -#include "global.h" -#include "io.h" - - - -/*****************************************************************************/ -/* data */ -/*****************************************************************************/ - - - -/* Input line stuff */ -char linebuf [LINESIZE]; -char* line = linebuf; -char* lptr = 0; - - - -/*****************************************************************************/ -/* code */ -/*****************************************************************************/ - - - -int nch (void) -/* Get the next char in input stream (the one behind the current one) */ -{ - if (*lptr == '\0') { - return 0; - } else { - return lptr[1] & 0xFF; - } -} - - - -int cgch (void) -/* Get the current character in the input stream and advance line - * pointer (unless already at end of line). - */ -{ - if (*lptr == '\0') { - return (0); - } else { - return (*lptr++ & 0xFF); - } -} - - - -int gch (void) -/* Get the current character in the input stream and advance line - * pointer (no end of line check is performed). - */ -{ - return (*lptr++ & 0xFF); -} - - - -void kill (void) -/* Reset input line pointer, clear input line */ -{ - lptr = line; - *lptr = '\0'; -} - - - diff --git a/src/cc65/io.h b/src/cc65/io.h deleted file mode 100644 index 0bf15974f..000000000 --- a/src/cc65/io.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * io.h - * - * Ullrich von Bassewitz, 19.06.1998 - */ - - - -#ifndef IO_H -#define IO_H - - - -#include - - - -/*****************************************************************************/ -/* data */ -/*****************************************************************************/ - - - -/* Maximum length of an input line and the corresponding char array */ -#define LINEMAX 4095 -#define LINESIZE LINEMAX+1 - -/* Maximum number of nested input files */ -#define MAXFILES 16 - -/* Input line stuff */ -extern char linebuf [LINESIZE]; -extern char* line; -extern char* lptr; - -/* File table entry */ -struct filent { - FILE* f_iocb; - char* f_name; - int f_ln; -}; - - - -/*****************************************************************************/ -/* code */ -/*****************************************************************************/ - - - -void kill (void); -/* Reset input line pointer, clear input line */ - -int nch (void); -/* Get the next char in input stream (the one behind the current one) */ - -int cgch (void); -/* Get the current character in the input stream and advance line - * pointer (unless already at end of line). - */ - -int gch (void); -/* Get the current character in the input stream and advance line - * pointer (no end of line check is performed). - */ - - - -/* End of io.h */ - -#endif - - - diff --git a/src/cc65/litpool.h b/src/cc65/litpool.h index f168d89cf..3cd69846b 100644 --- a/src/cc65/litpool.h +++ b/src/cc65/litpool.h @@ -38,6 +38,10 @@ +#include + + + /*****************************************************************************/ /* Data */ /*****************************************************************************/ diff --git a/src/cc65/make/gcc.mak b/src/cc65/make/gcc.mak index 149811221..92d7fe7bc 100644 --- a/src/cc65/make/gcc.mak +++ b/src/cc65/make/gcc.mak @@ -29,7 +29,6 @@ OBJS = anonname.o \ ident.o \ incpath.o \ input.o \ - io.o \ litpool.o \ locals.o \ loop.o \ diff --git a/src/cc65/make/watcom.mak b/src/cc65/make/watcom.mak index 5d49e31b7..98e602932 100644 --- a/src/cc65/make/watcom.mak +++ b/src/cc65/make/watcom.mak @@ -83,7 +83,6 @@ OBJS = anonname.obj \ ident.obj \ incpath.obj \ input.obj \ - io.obj \ litpool.obj \ locals.obj \ loop.obj \ diff --git a/src/cc65/optimize.c b/src/cc65/optimize.c index 66dfd53e2..9be2e5d4c 100644 --- a/src/cc65/optimize.c +++ b/src/cc65/optimize.c @@ -34,6 +34,7 @@ #include +#include #include #include @@ -45,7 +46,6 @@ #include "cpu.h" #include "error.h" #include "global.h" -#include "io.h" #include "optimize.h" diff --git a/src/cc65/pragma.c b/src/cc65/pragma.c index 9713f8af0..511eddb59 100644 --- a/src/cc65/pragma.c +++ b/src/cc65/pragma.c @@ -38,7 +38,6 @@ #include "global.h" #include "error.h" -#include "io.h" #include "litpool.h" #include "symtab.h" #include "preproc.h" diff --git a/src/cc65/preproc.c b/src/cc65/preproc.c index d27e8e2b9..835a5ff4f 100644 --- a/src/cc65/preproc.c +++ b/src/cc65/preproc.c @@ -16,7 +16,6 @@ #include "ident.h" #include "incpath.h" #include "input.h" -#include "io.h" #include "macrotab.h" #include "scanner.h" #include "util.h" @@ -154,11 +153,11 @@ static char* CopyQuotedString (int Quote, char* Target) static int macname (char *sname) -/* Get macro symbol name. If error, print message and kill line. */ +/* Get macro symbol name. If error, print message and clear line. */ { if (issym (sname) == 0) { PPError (ERR_IDENT_EXPECTED); - kill (); + ClearLine (); return 0; } else { return 1; @@ -319,7 +318,7 @@ static void ExpandMacro (Macro* M) if (M->ArgCount >= 0) { /* Function like macro */ if (MacroCall (M) == 0) { - kill (); + ClearLine (); } } else { /* Just copy the replacement text */ @@ -371,7 +370,7 @@ static void addmac (void) } if (*lptr != ')') { PPError (ERR_RPAREN_EXPECTED); - kill (); + ClearLine (); return; } gch (); @@ -677,8 +676,10 @@ static void doinclude (void) xfree (Name); Done: - /* clear rest of line so next read will come from new file (if open) */ - kill (); + /* Clear the remaining line so the next input will come from the new + * file (if open) + */ + ClearLine (); } @@ -694,7 +695,7 @@ static void doerror (void) } /* clear rest of line */ - kill (); + ClearLine (); } @@ -771,7 +772,7 @@ void preprocess (void) } if (!issym (sname)) { PPError (ERR_CPP_DIRECTIVE_EXPECTED); - kill (); + ClearLine (); } else { switch (searchtok (sname, pre_toks)) { @@ -828,7 +829,7 @@ void preprocess (void) /* Not allowed in strict ANSI mode */ if (ANSI) { PPError (ERR_CPP_DIRECTIVE_EXPECTED); - kill (); + ClearLine (); } break; @@ -849,7 +850,7 @@ void preprocess (void) default: PPError (ERR_CPP_DIRECTIVE_EXPECTED); - kill (); + ClearLine (); } } diff --git a/src/cc65/scanner.c b/src/cc65/scanner.c index 014286ff6..ce0aa1788 100644 --- a/src/cc65/scanner.c +++ b/src/cc65/scanner.c @@ -19,7 +19,6 @@ #include "global.h" #include "ident.h" #include "input.h" -#include "io.h" #include "litpool.h" #include "preproc.h" #include "symtab.h" diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 40f1661e8..28288df6c 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -50,7 +50,6 @@ #include "error.h" #include "funcdesc.h" #include "global.h" -#include "io.h" #include "symentry.h" #include "symtab.h" -- 2.39.5