STRPTR ScanToken( BPTR File ) { STRPTR Anchor, Ptr = AllocPooled( Memory, sizeof( BYTE ) * 64 ); if( Anchor = Ptr ) { while( isspace( *Ptr = FGetC( File ))); if( *Ptr == '"' ) { *Ptr = ( BYTE )FGetC( File ); while( *Ptr != '"' ) *(++Ptr) = ( BYTE )FGetC( File ); } else { do *(++Ptr) = ( BYTE )FGetC( File ); while( !isspace( *Ptr )); } *Ptr = '\0'; } return Anchor; }
//========================================================================== // ReadToken //========================================================================== int ReadToken() { int ch = FGetC(); char *out = token; memset(token, 0, sizeof(token)); if(endOfSource) return false; // Skip whitespace and comments in the beginning. while((ch == '#' || isspace(ch))) { if(ch == '#') SkipComment(); ch = FGetC(); if(endOfSource) return false; } // Always store the first character. *out++ = ch; if(STOPCHAR(ch)) { // Stop here. *out = 0; return true; } while(!STOPCHAR(ch) && !endOfSource) { // Store the character in the buffer. ch = FGetC(); *out++ = ch; } *(out-1) = 0; // End token. // Put the last read character back in the stream. FUngetC(ch); return true; }
//========================================================================== // FGetC // Reads a single character from the input file. Increments the line // number counter if necessary. //========================================================================== int FGetC() { int ch = *sourcePos; if(ch) sourcePos++; else endOfSource = true; if(ch == '\n') lineNumber++; if(ch == '\r') return FGetC(); return ch; }
LONG ScanDigit( BPTR File ) { LONG Char, Digit; while( isspace( Char = FGetC( File ))); Digit = Char - '0'; do { Char = FGetC( File ); if( isdigit( Char )) { Digit *= 10; Digit += ( Char - '0' ); } else break; } while( 1 ); return Digit; }
//========================================================================== // SkipComment // Reads stuff until a newline is found. //========================================================================== void SkipComment() { int ch = FGetC(); bool seq = false; if(ch == '\n') return; // Comment ends right away. if(ch != '>') // Single-line comment? { while(FGetC() != '\n' && !endOfSource) {} } else // Multiline comment? { while(!endOfSource) { ch = FGetC(); if(seq) { if(ch == '#') break; seq = false; } if(ch == '<') seq = true; } } }
LONG dosstreamhook (struct Hook * hook, BPTR fh, ULONG * msg) { LONG rc; switch (*msg) { case BEIO_READ: rc = FGetC (fh); break; case BEIO_WRITE: rc = FPutC (fh, ((struct BEIOM_Write *)msg)->Data); break; case BEIO_IGNORE: Flush (fh); rc = Seek (fh, ((struct BEIOM_Ignore *)msg)->Count, OFFSET_CURRENT); break; } return rc; } /* dosstreamhook */
int getfidoline(char *fidoline,char *buffer,int linelen, int chrs, BPTR fh,char *quotepre,struct NiKomBase *NiKomBase) { int anttkn,foo,tmpret,hasquoted=FALSE,donotwordwrap=FALSE; UBYTE tmp,*findquotesign,insquotebuf[81]; strcpy(fidoline,buffer); anttkn=strlen(fidoline); buffer[0]=0; for(;;) { tmpret=FGetC(fh); if(tmpret==-1) return(FALSE); tmp=tmpret; if(tmp==0x8d) continue; if(tmp==0x0a) continue; if(tmp==0x00) continue; if(tmp==0x0d) { if(quotepre && !hasquoted) { // Om detta är sant så har ett return kommit if(fidoline[0]!=1 && fidoline[0]!=0) { // men raden var kortare än fem tecken så findquotesign=strchr(fidoline,'>'); // den har inte blivit citerad. if(findquotesign) { // Det kan också vara så att strängen som strcpy(insquotebuf,findquotesign); // kommer i buffervariabeln följs direkt av findquotesign[1]=0; // return. strcat(fidoline,insquotebuf); } else { strcpy(insquotebuf,fidoline); strcpy(fidoline,quotepre); strcat(fidoline,insquotebuf); } } } break; } switch(chrs) { case CHRS_CP437 : if(tmp<128) fidoline[anttkn++]=tmp; else fidoline[anttkn++]=NiKomBase->IbmToAmiga[tmp]; break; case CHRS_SIS7 : fidoline[anttkn++]=NiKomBase->SF7ToAmiga[tmp]; break; case CHRS_MAC : if(tmp<128) fidoline[anttkn++]=tmp; else fidoline[anttkn++]=NiKomBase->MacToAmiga[tmp]; break; case CHRS_LATIN1 : fidoline[anttkn++]=tmp; break; default : fidoline[anttkn++]=convnokludge(tmp); } fidoline[anttkn]=0; if(quotepre && !hasquoted && anttkn>=5) { // När antal tecken överstiger fem är det dags hasquoted = TRUE; // att kolla om raden redan är ett citat eller if(fidoline[0]!=1) { // inte. Om det är det ska bara ett extra '>' findquotesign=strchr(fidoline,'>'); // in. Annars ska hela quotepre in. if(findquotesign) { if(linelen<79) linelen = 79; donotwordwrap = TRUE; strcpy(insquotebuf,findquotesign); findquotesign[1]=0; strcat(fidoline,insquotebuf); } else { strcpy(insquotebuf,fidoline); strcpy(fidoline,quotepre); strcat(fidoline,insquotebuf); } anttkn=strlen(fidoline); } } if(anttkn>=linelen) { for(foo=anttkn;fidoline[foo]!=' ' && foo>0;foo--); if(foo!=0) { if(quotepre && foo <= strlen(quotepre)); // Om hela citatet är ett ord, wrappa inte else if(!donotwordwrap) { fidoline[foo]=0; strncpy(buffer,&fidoline[foo+1],anttkn-foo-1); buffer[anttkn-foo-1]=0; } } break; } } return(TRUE); }