From a057f8e72cd899d0e1bf4f2b2777707634c21d39 Mon Sep 17 00:00:00 2001 From: kaashoek Date: Wed, 25 Nov 1987 11:49:48 +0000 Subject: [PATCH] Comments added --- util/ceg/EM_parser/common/scan.c | 69 +++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/util/ceg/EM_parser/common/scan.c b/util/ceg/EM_parser/common/scan.c index 44f1e13ae..a5e367924 100644 --- a/util/ceg/EM_parser/common/scan.c +++ b/util/ceg/EM_parser/common/scan.c @@ -1,14 +1,40 @@ #include -FILE *infile = stdin; +/* This file contains the scanner for mylex(), the following functions and + * variables are exported : + * + * int yylineno; - The current line number. + * + * char scanc(); - Return next character. + * + * backc( c); - Push back one character. + * char c; + * + * FILE *switch_input( new); - Scanner will from now on read from + * FILE *new; - 'new', old input-file is returned. + * + * The scanner must perform a lookahead of more than one character, so it uses + * it's own internal buffer. + */ + -#define BUF_SIZE 16 -char buf[BUF_SIZE], /* Bufer to save backc()-characters */ - *bufptr = buf; /* Pointer to space for backc()-character */ int yylineno = 1; -char nextc() +/********* Internal variables + functions ***********************/ + + +#define BUF_SIZE 16 + +static char buf[BUF_SIZE], /* Bufer to save backc()-characters */ + *bufptr = buf; /* Pointer to space for backc()-character */ + +static FILE *infile = stdin; + + + + +static char nextc() { if ( bufptr > buf) return( *--bufptr); @@ -17,25 +43,15 @@ char nextc() } -backc( c) -char c; -{ - if ( bufptr > buf + BUF_SIZE) - error( "backc(), no space in buffer left!"); - else { - if ( c == '\n') - yylineno--; - *bufptr++ = c; - } -} +/***************************************************************/ char scanc() -/* Get next character, but delete al C-comments */ +/* Get next character, but delete al C-comments and count lines */ { - char c; + char c, nextc(); c = nextc(); while ( c == '/') { @@ -56,10 +72,25 @@ char scanc() } +backc( c) +char c; +{ + if ( bufptr >= buf + BUF_SIZE) + error( "backc(), no space in buffer left!"); + else { + if ( c == '\n') + yylineno--; + *bufptr++ = c; + } +} + + FILE *switch_input( new) FILE *new; -/* Return the current FILE, if buf[] can't be cleaned NULL will be returned */ +/* Switch to a new input file, try to save the lookahead-characters in buf[] + * by calling ungetc(). If they can't be saved return NULL. + */ { char *ptr; FILE *old; -- 2.34.1