/ Check-in [be1faade]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Change the checkSpacing utility program to ignore whitespace at end-of-line unless the --wseol option is used.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: be1faadebd9464f1c7d4cc26104f219ed35384b8
User & Date: drh 2012-08-20 16:23:36
Context
2012-08-20
17:24
Add the SQLITE_DISABLE_FTS4_DEFERRED compile time option. check-in: e799222f user: dan tags: trunk
16:23
Change the checkSpacing utility program to ignore whitespace at end-of-line unless the --wseol option is used. check-in: be1faade user: drh tags: trunk
16:08
Silence harmless compiler warnings in the test code. check-in: 7653973a user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/checkSpacing.c.

     7      7   **
     8      8   ** Any violations are reported.
     9      9   */
    10     10   #include <stdio.h>
    11     11   #include <stdlib.h>
    12     12   #include <string.h>
    13     13   
    14         -static void checkSpacing(const char *zFile, int crok){
           14  +#define CR_OK      0x001
           15  +#define WSEOL_OK   0x002
           16  +
           17  +static void checkSpacing(const char *zFile, unsigned flags){
    15     18     FILE *in = fopen(zFile, "rb");
    16     19     int i;
    17     20     int seenSpace;
    18     21     int seenTab;
    19     22     int ln = 0;
    20     23     int lastNonspace = 0;
    21     24     char zLine[2000];
................................................................................
    28     31       seenTab = 0;
    29     32       ln++;
    30     33       for(i=0; zLine[i]; i++){
    31     34         if( zLine[i]=='\t' && seenTab==0 ){
    32     35           printf("%s:%d: tab (\\t) character\n", zFile, ln);
    33     36           seenTab = 1;
    34     37         }else if( zLine[i]=='\r' ){
    35         -        if( !crok ){
           38  +        if( (flags & CR_OK)==0 ){
    36     39             printf("%s:%d: carriage-return (\\r) character\n", zFile, ln);
    37     40           }
    38     41         }else if( zLine[i]==' ' ){
    39     42           seenSpace = 1;
    40     43         }else if( zLine[i]!='\n' ){
    41     44           lastNonspace = ln;
    42     45           seenSpace = 0;
    43     46         }
    44     47       }
    45         -    if( seenSpace ){
           48  +    if( seenSpace && (flags & WSEOL_OK)==0 ){
    46     49         printf("%s:%d: whitespace at end-of-line\n", zFile, ln);
    47     50       }
    48     51     }
    49     52     fclose(in);
    50     53     if( lastNonspace<ln ){
    51     54       printf("%s:%d: blank lines at end of file (%d)\n",
    52     55           zFile, ln, ln - lastNonspace);
    53     56     }
    54     57   }
    55     58   
    56     59   int main(int argc, char **argv){
    57     60     int i;
    58         -  int crok = 0;
           61  +  unsigned flags = WSEOL_OK;
    59     62     for(i=1; i<argc; i++){
    60         -    if( strcmp(argv[i], "--crok")==0 ){
    61         -      crok = 1;
           63  +    const char *z = argv[i];
           64  +    if( z[0]=='-' ){
           65  +      while( z[0]=='-' ) z++;
           66  +      if( strcmp(z,"crok")==0 ){
           67  +        flags |= CR_OK;
           68  +      }else if( strcmp(z, "wseol")==0 ){
           69  +        flags &= ~WSEOL_OK;
           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");
           75  +      }else{
           76  +        printf("unknown command-line option: [%s]\n", argv[i]);
           77  +        printf("use --help for additional information\n");
           78  +      }
    62     79       }else{
    63         -      checkSpacing(argv[i], crok);
           80  +      checkSpacing(argv[i], flags);
    64     81       }
    65     82     }
    66     83     return 0;
    67     84   }