static const string * lex(FormatState * fs){ //Ò»´Î¶ÁÈ¡Ò»¸ö×Ö·û´® while (fs->curpos+1 < fs->len) { unsigned char c = next(); //ÊÇ·ñÊÇ¿Õ°× if (c == '_' || isalpha(c)){ //identifier return readidentifier(fs); } else if (isdigit(c)){ //Êý×Ö return readdigit(fs); } else if (c == '-'){ if (peek() == '-'){ //×¢ÊÍ next(); return readcomment(fs); } return readpunct(fs); } else if (c == '\"') { return readstring(fs); } else if (c == '\'') { return readstring(fs); } else if (c == '[') { if (peek() == '[') { next(); return readstring(fs); } return readpunct(fs); } else if (ispunct(c)){ //±êµã return readpunct(fs); } else if (c == ' ' || c == '\t'){ return readblank(fs); } else if (c == '\r' || c == '\n') { return readnewline(fs); } else { assert(0); } } return 0; }
void showtext(int x1, int y1, int x2, int y2, char* headline, FILE * fileptr ) { int key; void * pscr; int i,l; linelist currentline=NULL,lastline; int width=x2-x1-1; int fc=fColor,bc=bColor; if (fileptr==NULL || !readnewline(fileptr,width,¤tline)) { messanykey(10,10," File is empty"); return; } if(y2<=y1+1) for (y2=y1+2;y2<maxRow()&&readnewline(fileptr,width,¤tline);y2++) currentline=currentline->next; get_text(x1,y1,x2,y2,&pscr); scrcolor(Black,White); chepbox(x1,y1,x2,y2); scrcolor(Red,White); goto_xy(x1+1,y1); print("*"); l=strlen(headline); if ( l < (x2-x1) ) { goto_xy(x1+(x2-x1-l)/2,y1); scrcolor(White,Black); print(headline); scrcolor(Black,White); } key = KB_PAGEU; do { switch (key) { case KB_PAGEU: for (i=y1+1;i<y2;i++) if (currentline->pred !=NULL) currentline=currentline->pred; break; case KB_UP: for(i=1;i<(y2-y1)/2;i++) if (currentline->pred !=NULL) currentline=currentline->pred; break; case KB_PAGED: for (i=y1+1;i<y2;i++) { readnewline(fileptr,width,¤tline); if (currentline->next !=NULL) currentline=currentline->next; } break; case KB_DOWN: for(i=1;i<(y2-y1)/2;i++) { readnewline(fileptr ,width,¤tline); if (currentline->next !=NULL) currentline=currentline->next; } break; } /* Case */ /* display */ lastline=currentline; goto_xy(x2-4,y1); if( lastline->pred == NULL) for (i=0;i<4;i++) print("%c",boxFrame[1]); else print("PgUp"); for (i =y1+1; i <y2; i++) { goto_xy(x1+1,i); readnewline(fileptr,width,&lastline); if ( lastline !=NULL ) { print("%s",lastline->line); lastline=lastline->next;} print(buff+where_x()+80-x2); } goto_xy(x2-4,y2); if (lastline == NULL) for (i=0;i<4;i++) print("%c",boxFrame[5]); else print("PgDn"); key = inkey(); /* mouse filter */ if ( (key == KB_MOUSE)&&(mouse_info.but1==2) &&(mouse_info.col >= x1)&&(mouse_info.col <= x2) ) { if (x2 - mouse_info.col <4 ) { if(mouse_info.row == y1) key=KB_PAGEU; else if(mouse_info.row == y2) key=KB_PAGED; } if ( (mouse_info.row == y1)&&(mouse_info.col - x1 <3)) key=KB_ESC; if ((mouse_info.row > y1)&&(mouse_info.row < y2)) { if (mouse_info.row < (y1+y2)/2) key=KB_UP; else key=KB_DOWN;} } /* end of filter */ } while ((key != KB_ESC)&&(key !=KB_BACKSP)); scrcolor(fc,bc); put_text(&pscr); while (currentline->pred != NULL ) currentline=currentline->pred; dellinelist(currentline); }