/ Check-in [656a9c8b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 656a9c8b47d262e0982ad3a35db490e2ff4d856e
User & Date: drh 2012-08-20 15:46:08
Context
2012-08-20
15:53
Remove tab characters from source code files. Replace them with spaces. check-in: 7edd10a9 user: drh tags: trunk
15:46
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. check-in: 656a9c8b user: drh tags: trunk
2012-08-17
13:44
Clarify that the number-of-bytes parameter to sqlite3_bind_blob() must be non-negative. check-in: b1b01c4c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added tool/checkSpacing.c.

            1  +/*
            2  +** This program checks for formatting problems in source code:
            3  +**
            4  +**    *  Any use of tab characters
            5  +**    *  White space at the end of a line
            6  +**    *  Blank lines at the end of a file
            7  +**
            8  +** Any violations are reported.
            9  +*/
           10  +#include <stdio.h>
           11  +#include <stdlib.h>
           12  +#include <string.h>
           13  +
           14  +static void checkSpacing(const char *zFile, int crok){
           15  +  FILE *in = fopen(zFile, "rb");
           16  +  int i;
           17  +  int seenSpace;
           18  +  int seenTab;
           19  +  int ln = 0;
           20  +  int lastNonspace = 0;
           21  +  char zLine[2000];
           22  +  if( in==0 ){
           23  +    printf("cannot open %s\n", zFile);
           24  +    return;
           25  +  }
           26  +  while( fgets(zLine, sizeof(zLine), in) ){
           27  +    seenSpace = 0;
           28  +    seenTab = 0;
           29  +    ln++;
           30  +    for(i=0; zLine[i]; i++){
           31  +      if( zLine[i]=='\t' && seenTab==0 ){
           32  +        printf("%s:%d: tab (\\t) character\n", zFile, ln);
           33  +        seenTab = 1;
           34  +      }else if( zLine[i]=='\r' ){
           35  +        if( !crok ){
           36  +          printf("%s:%d: carriage-return (\\r) character\n", zFile, ln);
           37  +        }
           38  +      }else if( zLine[i]==' ' ){
           39  +        seenSpace = 1;
           40  +      }else if( zLine[i]!='\n' ){
           41  +        lastNonspace = ln;
           42  +        seenSpace = 0;
           43  +      }
           44  +    }
           45  +    if( seenSpace ){
           46  +      printf("%s:%d: whitespace at end-of-line\n", zFile, ln);
           47  +    }
           48  +  }
           49  +  fclose(in);
           50  +  if( lastNonspace<ln ){
           51  +    printf("%s:%d: blank lines at end of file (%d)\n",
           52  +        zFile, ln, ln - lastNonspace);
           53  +  }
           54  +}
           55  +
           56  +int main(int argc, char **argv){
           57  +  int i;
           58  +  int crok = 0;
           59  +  for(i=1; i<argc; i++){
           60  +    if( strcmp(argv[i], "--crok")==0 ){
           61  +      crok = 1;
           62  +    }else{
           63  +      checkSpacing(argv[i], crok);
           64  +    }
           65  +  }
           66  +  return 0;
           67  +}