STATIC TOKEN_T lexSubString( STRM_T s ) /**************************************/ { char text[MAX_TOK_SIZE]; /* temporary storage */ unsigned pos; /* position in text */ TOKEN_T state; /* what are we collecting */ BOOLEAN done; /* are we done collecting ? */ VECSTR vec; /* build string here */ assert( isascii( s ) ); vec = StartVec(); if( ismacc( s ) ) { state = MAC_NAME; } else if( isws( s ) ) { state = MAC_WS; } else { state = MAC_PUNC; } pos = 0; done = FALSE; while( !done ) { text[pos++] = s; if( pos == MAX_TOK_SIZE - 1 ) { text[pos] = NULLCHAR; WriteVec( vec, text ); pos = 0; } s = PreGetCH(); switch( s ) { case EOL: /* always stop on these characters */ case STRM_END: case STRM_MAGIC: case ')': case DOLLAR: done = TRUE; break; default: switch( state ) { case MAC_NAME: done = !ismacc( s ); break; case MAC_WS: done = !isws( s ); break; case MAC_PUNC: done = ismacc( s ) || isws( s ); break; } } } UnGetCH( s ); text[pos] = NULLCHAR; WriteVec( vec, text ); CurAttr.u.ptr = FinishVec( vec ); return( state ); }
int main( void ) /***************/ { int i; bool noneyet; /*printf( "extern UINT8 IsArray[] = {\n" );*/ printf( "/*STRM_MAGIC*/ 0,\n" ); printf( "/*STRM_END */ 0" ); /* note: no ",\n" !! */ for( i = 0; i <= 255; i++ ) { noneyet = true; if( isprint( i ) ) { printf( ",\n/* '%c' */ ", i ); } else { printf( ",\n/* 0x%02x */ ", i ); } if( isws( i ) ) { BAR( IS_WS ); } if( isprt( i ) ) { BAR( IS_PRINT ); } if( isalpha( i ) ) { BAR( IS_ALPHA ); } if( isextc( i ) ) { BAR( IS_EXTC ); } if( isdirc( i ) ) { BAR( IS_DIRC ); } if( isfilec( i ) ) { BAR( IS_FILEC ); } if( ismacc( i ) ) { BAR( IS_MACC ); } if( isbarf( i ) ) { BAR( IS_BARF ); } if( noneyet ) { printf( "0" ); } } /*printf("\n};\n");*/ printf( "\n" ); return( 0 ); }
STATIC BOOLEAN checkMacro( STRM_T s ) /************************************* * returns: TRUE if the line WAS a macro defn * FALSE if it wasn't * recognizes: {macc}+{ws}*"="{ws}*{defn}*"\n" * {macc}+{ws}*"+="{ws}*{defn}*"\n" * second gets translated from "macro += defn" to "macro=$+$(macro)$- defn" */ { char mac[MAX_MAC_NAME]; unsigned pos; BOOLEAN ws; pos = 0; while( pos < MAX_MAC_NAME && ismacc( s ) ) { mac[pos++] = s; s = PreGetCH(); } if( pos == MAX_MAC_NAME ) { PrtMsgExit(( FTL | LOC | MAXIMUM_TOKEN_IS, MAX_MAC_NAME - 1 )); } mac[pos] = NULLCHAR; ws = isws( s ); while( isws( s ) ) { s = PreGetCH(); } if( s == '=' ) { DefMacro( mac ); return( TRUE ); /* go around again */ } else if( s == '+' ) { s = PreGetCH(); if( s == '=' ) { InsString( ")$-", FALSE ); InsString( mac, FALSE ); InsString( "$+$(", FALSE ); DefMacro( mac ); return( TRUE ); /* go around again */ } UnGetCH( s ); s = '+'; } UnGetCH( s ); /* not a macro line, put everything back*/ if( ws ) { UnGetCH( SPACE ); } InsString( StrDupSafe( mac + 1 ), TRUE ); return( FALSE ); }
TOKEN_T LexParser( STRM_T s ) /************************************ * returns: next token for parser * remarks: possibly defines a macro */ { static BOOLEAN atstart = TRUE; char *p; for( ;; ) { if( atstart ) { /* atstart == TRUE if either of these succeed */ if( isws( s ) ) { /* cmd line */ return( lexCmd() ); } if( ismacc( s ) && checkMacro( s ) ) { /* check if macro = body */ s = PreGetCH(); continue; } atstart = FALSE; UnGetCH( s ); /* put back our probe */ s = STRM_MAGIC; /* force macro expansion */ } switch( s ) { case STRM_END: atstart = TRUE; return( TOK_END ); case EOL: atstart = TRUE; return( TOK_EOL ); case STRM_TMP_LEX_START: case STRM_MAGIC: p = DeMacroDoubleQuote( FALSE ); /* expand to next white space */ if( *p == NULLCHAR ) { /* already at ws */ FreeSafe( p ); s = PreGetCH(); /* eat the ws */ while( isws( s ) ) { s = PreGetCH(); } if( s == EOL ) { atstart = TRUE; return( TOK_EOL ); } if( s == STRM_END ) { atstart = TRUE; return( TOK_END ); } UnGetCH( s ); p = DeMacroDoubleQuote( FALSE ); } UnGetCH( STRM_MAGIC ); /* mark spot we have to expand from nxt */ InsString( p, TRUE ); /* put expansion in stream */ break; case SPACE: /* fall through */ case TAB: break; case L_CURL_PAREN: /* could only be a sufsuf */ case DOT: UnGetCH( s ); return( lexDotName() ); /* could be a file... */ case SEMI: /* treat semi-colon as {nl}{ws} */ InsString( "\n ", FALSE ); break; /* try again */ case COLON: s = PreGetCH(); if( s == COLON ) { return( TOK_DCOLON ); } UnGetCH( s ); return( TOK_SCOLON ); default: if( isfilec( s ) || s == DOUBLEQUOTE || ( (Glob.compat_nmake || Glob.compat_posix) && s == SPECIAL_TMP_DOL_C ) ) { return( lexFileName( s ) ); } PrtMsg( WRN | LOC | UNKNOWN_TOKEN, s ); break; } s = PreGetCH(); /* fetch a character */ } }