diff options
author | drh <drh@noemail.net> | 2012-08-20 15:46:08 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2012-08-20 15:46:08 +0000 |
commit | 36ce6d2341792d766a5732053ce510600b4081a8 (patch) | |
tree | a96d44f4fbe872334ba0ef5ecf47e85df7509240 /tool/checkSpacing.c | |
parent | bcebd86f7c26dd96cee64067f2fe1599af55862a (diff) | |
download | sqlite-36ce6d2341792d766a5732053ce510600b4081a8.tar.gz sqlite-36ce6d2341792d766a5732053ce510600b4081a8.zip |
Add a command-line program to tool/ that will check source code files for
the presence of tabs, carriage-returns, whitespace at the ends of lines,
and blank lines at the ends of files.
FossilOrigin-Name: 656a9c8b47d262e0982ad3a35db490e2ff4d856e
Diffstat (limited to 'tool/checkSpacing.c')
-rw-r--r-- | tool/checkSpacing.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tool/checkSpacing.c b/tool/checkSpacing.c new file mode 100644 index 000000000..4cc289f18 --- /dev/null +++ b/tool/checkSpacing.c @@ -0,0 +1,67 @@ +/* +** This program checks for formatting problems in source code: +** +** * Any use of tab characters +** * White space at the end of a line +** * Blank lines at the end of a file +** +** Any violations are reported. +*/ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static void checkSpacing(const char *zFile, int crok){ + FILE *in = fopen(zFile, "rb"); + int i; + int seenSpace; + int seenTab; + int ln = 0; + int lastNonspace = 0; + char zLine[2000]; + if( in==0 ){ + printf("cannot open %s\n", zFile); + return; + } + while( fgets(zLine, sizeof(zLine), in) ){ + seenSpace = 0; + seenTab = 0; + ln++; + for(i=0; zLine[i]; i++){ + if( zLine[i]=='\t' && seenTab==0 ){ + printf("%s:%d: tab (\\t) character\n", zFile, ln); + seenTab = 1; + }else if( zLine[i]=='\r' ){ + if( !crok ){ + printf("%s:%d: carriage-return (\\r) character\n", zFile, ln); + } + }else if( zLine[i]==' ' ){ + seenSpace = 1; + }else if( zLine[i]!='\n' ){ + lastNonspace = ln; + seenSpace = 0; + } + } + if( seenSpace ){ + printf("%s:%d: whitespace at end-of-line\n", zFile, ln); + } + } + fclose(in); + if( lastNonspace<ln ){ + printf("%s:%d: blank lines at end of file (%d)\n", + zFile, ln, ln - lastNonspace); + } +} + +int main(int argc, char **argv){ + int i; + int crok = 0; + for(i=1; i<argc; i++){ + if( strcmp(argv[i], "--crok")==0 ){ + crok = 1; + }else{ + checkSpacing(argv[i], crok); + } + } + return 0; +} |