static strbuf * copyvalue(const char *boundary, FILE *in, const int wantfile, strbuf *value, FILE *out) { int c, i, k, matched; matched = k = 0; while ((c = getc(in)) != EOF) { /* * If we partially match the boundary, then we copy the * entire matching prefix to the output. We do not need to * backtrack and look for shorter matching prefixes because * they cannot exist. The boundary always begins with '\r' * and never contains another '\r'. */ if (matched > 0 && c != boundary[matched]) { for (i = 0; i < matched; i++) { if (wantfile == 0) { value = savechar(value, k++, boundary[i]); } else if (out != 0) { fputc(boundary[i], out); } } matched = 0; } /* check for full or partial boundary match */ if (c == boundary[matched]) { if (boundary[++matched] == 0) { break; /* full match */ } continue; /* partial match */ } /* no match, so copy byte to output */ if (wantfile == 0) { value = savechar(value, k++, c); } else if (out != 0) { fputc(c, out); } } if (wantfile == 0) { return savechar(value, k, 0); } return 0; }
static strbuf * readline(strbuf *line, FILE *in) { int c, i = 0; while ((c = getc(in)) != EOF) { line = savechar(line, i++, c); if (c == '\n') { break; } } if (i == 0) { if (line != 0) { free(line); } return 0; } return savechar(line, i, 0); /* null terminate */ }
int Parser::gettoken(int filter) { int c,d,f; restorechar(); do { // recherche le début du token // on sauvegarde la position dans le source lign0=lign; offligne0=offligne; offchar0=index; c=nextchar(); if (!c) { return -1; // fin du fichier, pas de nouveau token } } while(c<=32); token=&src[offchar0]; f=0; if (c=='\"') // token chaîne de caractères while(1) { c=nextchar(); if (!c) { term->printf(LOG_COMPILER,"uncomplete string reaches EOF\n"); return -1; } if ((c=='\"')&&(f==0)) { savechar(index); return 0; } if (c=='\\') { f=1-f; } else { f=0; } } if (isletnum(c)) // token nombre ou label { int onlynum=1; while(1) { if (!isnum(c)) { onlynum=0; } c=nextchar(); if (!c) { return 0; } if ((c=='.')&&(onlynum)) // nombre flottant { while(1) { c=nextchar(); if (!c) { return 0; } if (!isnum(c)) { againchar(); savechar(index); return 0; } } } if (!isletnum(c)) { againchar(); savechar(index); return 0; } } } d=nextchar(); if (!d) { return 0; // fin du fichier sur un caractère spécial } if ( ((c=='&')&&(d=='&')) ||((c=='|')&&(d=='|')) ||((c==':')&&(d==':')) ||((c=='^')&&(d=='^')) ||((c==';')&&(d==';')) ||((c=='-')&&(d=='>')) ||((c=='<')&&((d=='<')||(d=='/'))) ||((c=='>')&&(d=='>')) ||((c=='=')&&(d=='=')) ||((c=='/')&&((d=='*')||(d=='>'))) ||((c=='*')&&(d=='/')) ) { // caractère double reconnu } else if ((c=='/')&&(d=='/')) { do // cas du commentaire // { c=nextchar(); if (c==10) { return -2; } } while (c); return -1; // fin de fichier, pas de nouveau token } else if (((c=='!')||(c=='>')||(c=='<'))&&(d=='=')) { /* d=nextchar(); if (!d) return 0; // fin du fichier sur un caractère spécial composé if (d!='.') againchar(); */ } else { againchar(); } savechar(index); return 0; }