Lines Matching +full:input +full:- +full:depth

2  * Copyright (c) 2002 - 2011 Tony Finch <dot@dotat.at>
27 * unifdef - remove ifdef'ed lines
31 * of unifdef carried the 4-clause BSD copyright licence. None of its code
60 "@(#) $Version: unifdef-2.5 $\n"
65 /* types of input lines: */
99 IS_TRUE_PREFIX, /* first non-false #(el)if is true */
100 IS_PASS_MIDDLE, /* first non-false #(el)if is unknown */
122 STARTING_COMMENT, /* just after slash-backslash-newline */
123 FINISHING_COMMENT, /* star-backslash-newline in a C comment */
165 static bool compblank; /* -B: compress blank lines */
166 static bool lnblank; /* -b: blank deleted lines */
167 static bool complement; /* -c: do the complement */
168 static bool debugging; /* -d: debugging reports */
169 static bool iocccok; /* -e: fewer IOCCC errors */
170 static bool strictlogic; /* -K: keep ambiguous #ifs */
171 static bool killconsts; /* -k: eval constant #ifs */
172 static bool lnnum; /* -n: add #line directives */
173 static bool symlist; /* -s: output symbol list */
174 static bool symdepth; /* -S: output symbol depth */
175 static bool text; /* -t: this is a text file */
178 static const char *value[MAXSYMS]; /* -Dsym=value */
179 static bool ignore[MAXSYMS]; /* -iDsym or -iUsym */
182 static FILE *input; /* input file pointer */ variable
183 static const char *filename; /* input file name */
187 static bool overwriting; /* output overwrites input */
190 static char tline[MAXLINE+EDITSLOP];/* input buffer plus space */
193 static const char *newline; /* input file format */
202 static int depth; /* current #if nesting */ variable
245 while ((opt = getopt(argc, argv, "i:D:U:I:o:bBcdeKklnsStV")) != -1) in main()
249 * For strict backwards-compatibility the U or D in main()
250 * should be immediately after the -i but it doesn't in main()
267 case 'I': /* no-op for compatibility with cpp */ in main()
276 case 'c': /* treat -D as -U and vice versa */ in main()
300 case 'S': /* list symbols with their nesting depth */ in main()
311 argc -= optind; in main()
314 errx(2, "-B and -b are mutually exclusive"); in main()
317 } else if (argc == 1 && strcmp(*argv, "-") != 0) { in main()
319 input = fopen(filename, "rb"); in main()
320 if (input == NULL) in main()
324 input = stdin; in main()
332 fstat(fileno(input), &ist) == 0) in main()
343 (int)(dirsep - ofilename), ofilename); in main()
348 if (ofd != -1) in main()
380 fprintf(stderr, "usage: unifdef [-bBcdeKknsStV] [-Ipath]" in usage()
381 " [-Dsym[=val]] [-Usym] [-iDsym[=val]] [-iUsym] ... [file]\n"); in usage()
391 * functions increase or decrease the depth. They also maintain the
395 * When we have processed a group that starts off with a known-false
407 * example being a multi-line comment hanging off the right of the
510 if (depth == 0) in ignoreoff()
512 ignoring[depth] = ignoring[depth-1]; in ignoreoff()
517 ignoring[depth] = true; in ignoreon()
522 snprintf(keyword, tline + sizeof(tline) - keyword, in keywordedit()
529 if (depth > MAXDEPTH-1) in nest()
531 if (depth == MAXDEPTH-1) in nest()
533 depth += 1; in nest()
534 stifline[depth] = linenum; in nest()
539 if (depth == 0) in unnest()
541 depth -= 1; in unnest()
546 ifstate[depth] = is; in state()
591 trans_table[ifstate[depth]][lineval](); in process()
592 debug("process line %d %s -> %s depth %d", in process()
594 ifstate_name[ifstate[depth]], depth); in process()
626 if (overwriting && rename(tempname, ofilename) == -1) { in done()
649 if (fgets(tline, MAXLINE, input) == NULL) in parseline()
669 keyword = tline + (cp - tline); in parseline()
671 kwlen = cp - keyword; in parseline()
695 retval = ifeval(&cp) - LT_IF + LT_ELIF; in parseline()
722 size_t len = cp - tline; in parseline()
723 if (fgets(tline + len, MAXLINE - len, input) == NULL) { in parseline()
786 * the expression is zero, LT_TRUE if it is non-zero, LT_IF if the expression
797 * in a table-driven way by eval_table. When it evaluates a subexpression it
799 * element of the table. Innermost expressions have special non-table-driven
835 debug("eval%d !", ops - eval_ops); in eval_unary()
846 debug("eval%d (", ops - eval_ops); in eval_unary()
854 debug("eval%d number", ops - eval_ops); in eval_unary()
862 debug("eval%d defined", ops - eval_ops); in eval_unary()
882 debug("eval%d symbol", ops - eval_ops); in eval_unary()
900 debug("eval%d bad expr", ops - eval_ops); in eval_unary()
905 debug("eval%d = %d", ops - eval_ops, *valp); in eval_unary()
910 * Table-driven evaluation of binary operators.
920 debug("eval%d", ops - eval_ops); in eval_table()
922 lt = ops->inner(ops+1, valp, &cp); in eval_table()
927 for (op = ops->op; op->str != NULL; op++) in eval_table()
928 if (strncmp(cp, op->str, strlen(op->str)) == 0) in eval_table()
930 if (op->str == NULL) in eval_table()
932 cp += strlen(op->str); in eval_table()
933 debug("eval%d %s", ops - eval_ops, op->str); in eval_table()
934 rt = ops->inner(ops+1, &val, &cp); in eval_table()
937 lt = op->fn(valp, lt, *valp, rt, val); in eval_table()
941 debug("eval%d = %d", ops - eval_ops, *valp); in eval_table()
942 debug("eval%d lt = %s", ops - eval_ops, linetype_name[lt]); in eval_table()
974 if (text || ignoring[depth]) { in skipcomment()
1095 level--; in skipargs()
1101 /* Rewind and re-detect the syntax error later. */ in skipargs()
1118 * the symbol table index, else we return -1.
1128 return (-1); in findsym()
1131 printf("%s%3d", zerosyms ? "" : "\n", depth); in findsym()
1135 (int)(cp-str), str, in findsym()
1141 if (strlcmp(symname[symind], str, cp-str) == 0) { in findsym()
1147 return (-1); in findsym()
1167 val = sym + (skipsym(sym) - sym); in addsym()
1192 while (n-- && *t != '\0') in strlcmp()
1194 return ((unsigned char)*s - (unsigned char)*t); in strlcmp()
1218 if (depth == 0) in error()
1221 warnx("%s: %d: %s (#if line %d depth %d)", in error()
1222 filename, linenum, msg, stifline[depth], depth); in error()