=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/scanner.c,v retrieving revision 1.8 retrieving revision 1.11 diff -u -p -r1.8 -r1.11 --- OpenXM/src/kan96xx/Kan/scanner.c 2005/07/03 11:08:54 1.8 +++ OpenXM/src/kan96xx/Kan/scanner.c 2020/10/06 11:33:47 1.11 @@ -1,4 +1,4 @@ -/*$OpenXM: OpenXM/src/kan96xx/Kan/scanner.c,v 1.7 2004/09/12 00:26:21 takayama Exp $*/ +/*$OpenXM: OpenXM/src/kan96xx/Kan/scanner.c,v 1.10 2018/09/07 00:15:44 takayama Exp $*/ /* scanner.c (SM StackMachine) */ /* export: struct tokens getokenSM(actionType kind,char *str); scanner.c is used to get tokens from streams. @@ -62,41 +62,49 @@ static int FileStackP = 0; /**************** end of declaration part of lexical analizer ******/ static int getSM(); -static putSM(); +static void putSM(); static struct tokens flushSM(); -static isSpaceSM(); -static isDollarSM(); -static isBraceSM(); -static isKakkoSM(); -static isSymbolSM(); -static mygetchar(); -static myungetchar(); +static int isSpaceSM(); +static int isDollarSM(); +static int isBraceSM(); +static int isKakkoSM(); +static int isSymbolSM(); +static int mygetchar(); +static int myungetchar(); +int ScannerWhich = 0; +unsigned char ScannerBuf[SCANNERBUF_SIZE]; +int ScannerPt = 0; /* static mygetchar() { + return( getc(Cfp) ); } */ -static mygetchar() +static int mygetchar() { int c; + c = getc(Cfp); + if (c > 0) { /* ungetchar is ignored */ + ScannerPt++; if (ScannerPt >= SCANNERBUF_SIZE) ScannerPt = 0; + ScannerBuf[ScannerPt] = c; + } if (EchoInScanner) { - c = getc(Cfp); if (c==EOF) { - printf("\n%% EOF of file %x\n",(int) Cfp); + printf("\n%% EOF of file %p\n",Cfp); }else{ printf("%c",c); } return( c ); }else{ - return( getc(Cfp) ); + return( c ); } } -static myungetchar(c) +static int myungetchar(c) int c; { return( ungetc(c,Cfp) ); @@ -122,7 +130,7 @@ static int getSM() } else return(c); } -static putSM(c) +static void putSM(c) int c; /* put a letter on BufSM */ { @@ -168,35 +176,35 @@ static struct tokens flushSM() return(r); } -static isSpaceSM(c) +static int isSpaceSM(c) int c; { if (((c <= ' ') || c == ',') && (c!= EOF)) return(1); else return(0); } -static isDollarSM(c) +static int isDollarSM(c) int c; { if (c == '$') return(1); else return(0); } -static isBraceSM(c) +static int isBraceSM(c) int c; { if (c == '{') return(1); else return(0); } -static isKakkoSM(c) +static int isKakkoSM(c) int c; { if (c == '(') return(1); else return(0); } -static isSymbolSM(c) +static int isSymbolSM(c) int c; { if ((c == '{') || @@ -219,6 +227,10 @@ struct tokens getokenSM(kind,str) char fname[1024]; if (kind == INIT) { + ScannerWhich = 2; + ScannerPt = 0; + ScannerBuf[0] = 0; + StrpSM = 0; ExistSM = 0; @@ -430,4 +442,39 @@ char *getLOAD_SM1_PATH() { strcpy(p2,p); strcat(p2,"/"); return(p2); } +} + +char *traceShowScannerBuf() { + char *s; + int i,k; + s = NULL; + /* + printf("ScannerPt=%d\n",ScannerPt); + for (i=0; i 0) && (ScannerBuf[0] == 0)) { + s = sGC_malloc(ScannerPt+1); + for (i=1; i<=ScannerPt; i++) { + s[i-1] = ScannerBuf[i]; s[i] = 0; + } + return s; + } + if (ScannerBuf[0] != 0) { + s = sGC_malloc(SCANNERBUF_SIZE+1); + k = ScannerPt+1; + if (k >= SCANNERBUF_SIZE) k = 0; + for (i=0; i= SCANNERBUF_SIZE) k = 0; + } + return s; + } + return s; }