2 * A Pedantic Check of Text Input/Output File Syntax
4 * (c) 2005--2007 Martin Mares <mj@ucw.cz>
15 static int warn_total, warn_shown;
17 static void warn(char *msg, ...)
20 static char *seen[NUM_TYPES];
21 static int cnt[NUM_TYPES];
30 for (type=0; type < NUM_TYPES && seen[type] && seen[type] != msg; type++)
32 if (type >= NUM_TYPES)
35 if (cnt[type]++ >= max)
39 printf("Line %d: ", line);
46 static void check(void)
53 while ((c = getchar()) >= 0)
58 warn("Trailing spaces");
59 if (line == 1 && !pos)
60 warn("Leading empty line");
64 warn("Consecutive empty lines");
74 warn("Leading spaces");
76 warn("Consecutive spaces");
82 if (c < ' ' || c >= 0x7f)
83 warn("Invalid character 0x%02x", c);
89 warn("Incomplete line at the end of file");
93 warn("Trailing empty line");
96 if (warn_shown < warn_total)
97 printf("(and %d more warnings)\n", warn_total - warn_shown);
99 printf("Found %d lines, the longest has %d chars\n", line-1, maxlen);
102 static void usage(void)
104 fprintf(stderr, "Usage: pedant [-m <max>] [-s]\n");
108 int main(int argc, char **argv)
111 while ((opt = getopt(argc, argv, "m:s")) >= 0)