static void do_directive(int first) { int c = first; /* handles lines starting with pound */ getword(c, isalpha_); if (strcmp(yytext, "#ident") == 0) goto done; if ((c = Getchar()) != ' ') fatal("malformed preprocessor directive - # .", 0); if (!isdigit_(c = Getchar())) fatal("malformed preprocessor directive - # .lineno", 0); getword(c, isdigit_); lineno = atoi(yytext); /* pickup the line number */ if ((c = Getchar()) == '\n') return; /* no filename */ if (c != ' ') fatal("malformed preprocessor directive - .fname", 0); if ((c = Getchar()) != '\"') { printf("got %c, expected \" -- lineno %d\n", c, lineno); fatal("malformed preprocessor directive - .fname (%s)", yytext); } getword(Getchar(), notquote); /* was getword(c, notquote); */ if (Getchar() != '\"') fatal("malformed preprocessor directive - fname.", 0); /* strcat(yytext, "\""); */ Fname = lookup(yytext); done: while (Getchar() != '\n') ; }
static void unescape_term_string(Term *t) { char *s, *start = 0, *ss; int length, base = 0; for (ss = s = t->string; *s; s++) { if (*s == '\\') { switch (s[1]) { case 'b': *ss = '\b'; s++; break; case 'f': *ss = '\f'; s++; break; case 'n': *ss = '\n'; s++; break; case 'r': *ss = '\r'; s++; break; case 't': *ss = '\t'; s++; break; case 'v': *ss = '\v'; s++; break; case 'a': *ss = '\a'; s++; break; case 'c': *ss = 0; return; case '\"': if (t->kind == TERM_REGEX) { *ss = '\"'; s++; break; } else goto Ldefault; case '\'': if (t->kind == TERM_STRING) { *ss = '\''; s++; break; } else goto Ldefault; case 'x': length = 0; if (isxdigit_(s[2])) { base = 16; start = s + 2; length++; if (isxdigit_(s[3])) length++; } s += length + 1; goto Lncont; case 'd': length = 0; if (isdigit_(s[2])) { base = 10; start = s + 2; length++; if (isdigit_(s[3])) { length++; if (isdigit_(s[4]) && ((s[2] < '2') || ((s[2] == '2') && ((s[3] < '5') || ((s[3] == '5') && (s[4] < '6')))))) length++; } } s += length + 1; goto Lncont; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': length = 1; base = 8; start = s + 1; if (isdigit_(s[2]) && (s[2] != '8') && (s[2] != '9')) { length++; if (isdigit_(s[3]) && (s[3] != '8') && (s[3] != '9')) { length++; } } s += length; /* fall through */ Lncont: if (length > 0) { char saved_c = start[length]; start[length] = '\0'; *ss = (unsigned char) strtol(start, NULL, base); start[length] = saved_c; if (*s > 0) break; d_fail("encountered an escaped NULL while processing '%s'", t->string); } else goto next; Ldefault: default: *ss++ = *s; *ss = s[1]; s++; break; } } else *ss = *s; ss++; next:; } *ss = 0; t->string_len = strlen(t->string); if (!t->string_len) d_fail("empty string after unescape '%s'", t->string); }
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; }