2 ** This program checks for formatting problems in source code:
4 ** * Any use of tab characters
5 ** * White space at the end of a line
6 ** * Blank lines at the end of a file
8 ** Any violations are reported.
15 #define WSEOL_OK 0x002
17 static void checkSpacing(const char *zFile
, unsigned flags
){
18 FILE *in
= fopen(zFile
, "rb");
26 printf("cannot open %s\n", zFile
);
29 while( fgets(zLine
, sizeof(zLine
), in
) ){
33 for(i
=0; zLine
[i
]; i
++){
34 if( zLine
[i
]=='\t' && seenTab
==0 ){
35 printf("%s:%d: tab (\\t) character\n", zFile
, ln
);
37 }else if( zLine
[i
]=='\r' ){
38 if( (flags
& CR_OK
)==0 ){
39 printf("%s:%d: carriage-return (\\r) character\n", zFile
, ln
);
41 }else if( zLine
[i
]==' ' ){
43 }else if( zLine
[i
]!='\n' ){
48 if( seenSpace
&& (flags
& WSEOL_OK
)==0 ){
49 printf("%s:%d: whitespace at end-of-line\n", zFile
, ln
);
53 if( lastNonspace
<ln
){
54 printf("%s:%d: blank lines at end of file (%d)\n",
55 zFile
, ln
, ln
- lastNonspace
);
59 int main(int argc
, char **argv
){
61 unsigned flags
= WSEOL_OK
;
62 for(i
=1; i
<argc
; i
++){
63 const char *z
= argv
[i
];
65 while( z
[0]=='-' ) z
++;
66 if( strcmp(z
,"crok")==0 ){
68 }else if( strcmp(z
, "wseol")==0 ){
70 }else if( strcmp(z
, "help")==0 ){
71 printf("Usage: %s [options] FILE ...\n", argv
[0]);
72 printf(" --crok Do not report on carriage-returns\n");
73 printf(" --wseol Complain about whitespace at end-of-line\n");
74 printf(" --help This message\n");
76 printf("unknown command-line option: [%s]\n", argv
[i
]);
77 printf("use --help for additional information\n");
80 checkSpacing(argv
[i
], flags
);