int lex(void) { int c; again: c = Getchar(); yytext[0] = (char) c; yytext[1] = '\0'; switch (c) { case EOF: return c; case '\n': /* newline */ lineno++; /* make most semi-colons optional */ if (implied_semis && context && in_seq && par_cnt == 0 && follows_token(last_token)) { if (0) { printf("insert ; line %d, last_token %d in_seq %d\n", lineno-1, last_token, in_seq); } ValToken(1, SEMI); } /* else fall thru */ case '\r': /* carriage return */ goto again; case ' ': case '\t': case '\f': /* white space */ goto again; case '#': /* preprocessor directive */ if (in_comment) goto again; if (pp_mode) { last_token = PREPROC; return pre_proc(); } do_directive(c); goto again; case '\"': getword(c, notquote); if (Getchar() != '\"') fatal("string not terminated", yytext); strcat(yytext, "\""); SymToken(lookup(yytext), STRING) case '$': getword('\"', notdollar); if (Getchar() != '$') fatal("ltl definition not terminated", yytext); strcat(yytext, "\""); SymToken(lookup(yytext), STRING) case '\'': /* new 3.0.9 */ c = Getchar(); if (c == '\\') { c = Getchar(); if (c == 'n') c = '\n'; else if (c == 'r') c = '\r'; else if (c == 't') c = '\t'; else if (c == 'f') c = '\f'; } if (Getchar() != '\'' && !in_comment) fatal("character quote missing: %s", yytext); ValToken(c, CONST) default: break; } if (isdigit_(c)) { long int nr; getword(c, isdigit_); errno = 0; nr = strtol(yytext, NULL, 10); if (errno != 0) { fprintf(stderr, "spin: value out of range: '%s' read as '%d'\n", yytext, (int) nr); } ValToken((int)nr, CONST) } if (isalpha_(c) || c == '_') { getword(c, isalnum_); if (!in_comment) { c = check_name(yytext); if (c) { last_token = c; return c; } /* else fall through */ } goto again; } if (ltl_mode) { switch (c) { case '-': c = follow('>', IMPLIES, '-'); break; case '[': c = follow(']', ALWAYS, '['); break; case '<': c = follow('>', EVENTUALLY, '<'); if (c == '<') { c = Getchar(); if (c == '-') { c = follow('>', EQUIV, '-'); if (c == '-') { Ungetch(c); c = '<'; } } else { Ungetch(c); c = '<'; } } default: break; } } switch (c) { case '/': c = follow('*', 0, '/'); if (!c) { in_comment = 1; goto again; } break; case '*': c = follow('/', 0, '*'); if (!c) { in_comment = 0; goto again; } break; case ':': c = follow(':', SEP, ':'); break; case '-': c = follow('>', ARROW, follow('-', DECR, '-')); break; case '+': c = follow('+', INCR, '+'); break; case '<': c = follow('<', LSHIFT, follow('=', LE, LT)); break; case '>': c = follow('>', RSHIFT, follow('=', GE, GT)); break; case '=': c = follow('=', EQ, ASGN); break; case '!': c = follow('=', NE, follow('!', O_SND, SND)); break; case '?': c = follow('?', R_RCV, RCV); break; case '&': c = follow('&', AND, '&'); break; case '|': c = follow('|', OR, '|'); break; case ';': c = SEMI; break; case '.': c = follow('.', DOTDOT, '.'); break; case '{': scope_seq[scope_level++]++; set_cur_scope(); break; case '}': scope_level--; set_cur_scope(); break; default : break; } ValToken(0, c) }
static int lw_diff2wc_diff(int mindiff, int doChar, char *lw_diff_fn, char *wc_diff_fn) { FILE *lw_diff_fp, *wc_diff_fp, *fp[2], *pipe_fp; char line[BUFLEN], command[CMDLEN], pipe_ln[BUFLEN]; char *ok, *fn[2]; size_t i; int j; int space, alpha_, digit, l[2], k[2]; char wc_old_fn[CMDLEN], wc_new_fn[CMDLEN]; char *_d = mindiff ? "-d" : ""; TRACE(fprintf(STDERR, "lw_diff2wc_diff(%i,%i,%s,%s)\n", mindiff, doChar, lw_diff_fn, wc_diff_fn)); lw_diff_fp = Rfopen(lw_diff_fn); if (!(ok = fgets(line, BUFLEN, lw_diff_fp))) { fclose(lw_diff_fp); ERRHNDL(0, "empty file in lw_diff2wc_diff:", lw_diff_fn, 1); } sprintf(wc_old_fn, "%s%c.difflib-%ld-lw_diff2wc_diff-old", tmpdir(), DIR_SEP, (long) getpid()); fn[0] = wc_old_fn; sprintf(wc_new_fn, "%s%c.difflib-%ld-lw_diff2wc_diff-new", tmpdir(), DIR_SEP, (long) getpid()); fn[1] = wc_new_fn; wc_diff_fp = Wfopen(wc_diff_fn); while (ok && strncmp(line, "@@ -", 4)) { fprintf(wc_diff_fp, "%s", line); ok = fgets(line, BUFLEN, lw_diff_fp); } fflush(wc_diff_fp); fclose(wc_diff_fp); while (ok) { wc_diff_fp = Afopen(wc_diff_fn); do { fprintf(wc_diff_fp, "%s", line); } while (line[strlen(line) - 1] != '\n' && (ok = fgets(line, BUFLEN, lw_diff_fp))); fflush(wc_diff_fp); fclose(wc_diff_fp); l[0] = l[1] = k[0] = k[1] = 0; for (j = 0; j < 2; j++) fp[j] = Wfopen(fn[j]); while (ok && (ok = fgets(line, BUFLEN, lw_diff_fp)) && strchr(" -+", line[0])) { if (line[0] == ' ') { char l1 = line[1]; while (k[0] < k[1]) { markNL(fp[0], k[0]++); l[0]++; } while (k[1] < k[0]) { markNL(fp[1], k[1]++); l[1]++; } i = 1; do { for (j = 0; j < 2; j++) { fprintf(fp[j], "%s", line+i); } i = 0; } while (line[strlen(line) - 1] != '\n' && (ok = fgets(line, BUFLEN, lw_diff_fp))); for (j = 0; j < 2; j++) { l[j]++; } if (l1 == '\1') for (j = 0; j < 2; j++) { markNL(fp[j], k[j]++); l[j]++; } } else { if (line[0] == '-') j = 0; else j = 1; if (line[1] == '\1') { fprintf(fp[j], "\1\n"); markNL(fp[j], k[j]++); l[j] += 2; } else if (doChar) { i = 1; do { for (; line[i] != '\n' && line[i] != '\0'; i++) { fprintf(fp[j], "%c\n", line[i]); l[j]++; } i = 0; } while (line[strlen(line) - 1] != '\n' && (ok = fgets(line, BUFLEN, lw_diff_fp))); } else { space = isspace_((int) (line[1])); alpha_ = isalpha_((int) (line[1])); digit = isdigit_((int) (line[1])); i = 1; do { for (; line[i] != '\n' && line[i] != '\0'; i++) { if ((space && !isspace_((int) line[i])) || (!space && isspace_((int) line[i])) || (alpha_ && !isalpha_((int) line[i])) || (!alpha_ && isalpha_((int) line[i])) || (digit && !isdigit_((int) line[i])) || (!digit && isdigit_((int) line[i])) || (!isspace_((int) line[i]) && !isalpha_((int) line[i]) && !isdigit_((int) line[i]))) { fprintf(fp[j], "\n"); space = isspace_((int) line[i]); alpha_ = isalpha_((int) line[i]); digit = isdigit_((int) line[i]); l[j]++; } fprintf(fp[j], "%c", line[i]); } i = 0; } while (line[strlen(line) - 1] != '\n' && (ok = fgets(line, BUFLEN, lw_diff_fp))); fprintf(fp[j], "\n"); l[j]++; } } } for (j = 0; j < 2; j++) { fflush(fp[j]); fclose(fp[j]); } /* sprintf(command, "%s -a %s -u%i %s %s | egrep -v '^(@@ \\-|\\+\\+\\+ |\\-\\-\\- |[ \\+\\-]@\\+\\-)' >> %s", DIFF,_d,MAX(l[0],l[1]),fn[0],fn[1],wc_diff_fn); SYSTEM(command); */ sprintf(command, "%s -a %s -U%d %s %s", DIFF, _d, MAX(l[0], l[1]), fn[0], fn[1]); pipe_fp = popen(command, "r"); wc_diff_fp = Afopen(wc_diff_fn); while (fgets(pipe_ln, BUFLEN, pipe_fp)) { if (strncmp(pipe_ln, "@@ -", 4) && strncmp(pipe_ln, "+++ ", 4) && strncmp(pipe_ln, "--- ", 4) && strncmp(pipe_ln, " @+-", 4) && strncmp(pipe_ln, "+@+-", 4) && strncmp(pipe_ln, "-@+-", 4)) { fprintf(wc_diff_fp, "%s", pipe_ln); } } fflush(wc_diff_fp); fclose(wc_diff_fp); pclose(pipe_fp); } UNLINK(wc_old_fn); UNLINK(wc_new_fn); fclose(lw_diff_fp); return 1; }