aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/indent/indent.c
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2016-07-31 21:29:10 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2016-07-31 21:29:10 +0000
commitf7adee231414489cd75f0b6fe35e0266b286cd4a (patch)
tree037f6324471d94e96bdd47701e4f0bc715db7d22 /usr.bin/indent/indent.c
parent69e66b43bc87651d23bd8c84f5ec46c489c96ba9 (diff)
downloadsrc-f7adee231414489cd75f0b6fe35e0266b286cd4a.tar.gz
src-f7adee231414489cd75f0b6fe35e0266b286cd4a.zip
Notes
Diffstat (limited to 'usr.bin/indent/indent.c')
-rw-r--r--usr.bin/indent/indent.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c
index 84a3b0e82d9c..8f809f7a176a 100644
--- a/usr.bin/indent/indent.c
+++ b/usr.bin/indent/indent.c
@@ -1100,13 +1100,7 @@ check_type:
ps.pcase = false;
}
- if (strncmp(s_lab, "#if", 3) == 0) {
- if (blanklines_around_conditional_compilation) {
- int c;
- prefix_blankline_requested++;
- while ((c = getc(input)) == '\n');
- ungetc(c, input);
- }
+ if (strncmp(s_lab, "#if", 3) == 0) { /* also ifdef, ifndef */
if ((size_t)ifdef_level < nitems(state_stack)) {
match_state[ifdef_level].tos = -1;
state_stack[ifdef_level++] = ps;
@@ -1114,34 +1108,49 @@ check_type:
else
diag2(1, "#if stack overflow");
}
- else if (strncmp(s_lab, "#else", 5) == 0)
+ else if (strncmp(s_lab, "#el", 3) == 0) { /* else, elif */
if (ifdef_level <= 0)
- diag2(1, "Unmatched #else");
+ diag2(1, s_lab[3] == 'i' ? "Unmatched #elif" : "Unmatched #else");
else {
match_state[ifdef_level - 1] = ps;
ps = state_stack[ifdef_level - 1];
}
+ }
else if (strncmp(s_lab, "#endif", 6) == 0) {
if (ifdef_level <= 0)
diag2(1, "Unmatched #endif");
- else {
+ else
ifdef_level--;
-
-#ifdef undef
- /*
- * This match needs to be more intelligent before the
- * message is useful
- */
- if (match_state[ifdef_level].tos >= 0
- && bcmp(&ps, &match_state[ifdef_level], sizeof ps))
- diag2(0, "Syntactically inconsistent #ifdef alternatives");
-#endif
+ } else {
+ struct directives {
+ int size;
+ const char *string;
}
- if (blanklines_around_conditional_compilation) {
- postfix_blankline_requested++;
- n_real_blanklines = 0;
+ recognized[] = {
+ {7, "include"},
+ {6, "define"},
+ {5, "undef"},
+ {4, "line"},
+ {5, "error"},
+ {6, "pragma"}
+ };
+ int d = nitems(recognized);
+ while (--d >= 0)
+ if (strncmp(s_lab + 1, recognized[d].string, recognized[d].size) == 0)
+ break;
+ if (d < 0) {
+ diag2(1, "Unrecognized cpp directive");
+ break;
}
}
+ if (blanklines_around_conditional_compilation) {
+ postfix_blankline_requested++;
+ n_real_blanklines = 0;
+ }
+ else {
+ postfix_blankline_requested = 0;
+ prefix_blankline_requested = 0;
+ }
break; /* subsequent processing of the newline
* character will cause the line to be printed */