From 91334be2ff4f8c68534c700ec05ea307af47c7ed Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Mon, 4 Apr 2016 19:38:03 +0300 Subject: [PATCH] Remove tabs from *.[ch] --- fortune-mod/tests/trailing-space-and-CRs.pl | 16 +- fortune-mod/util/randstr.c | 86 +++++----- fortune-mod/util/rot.c | 14 +- fortune-mod/util/strfile.h | 38 ++--- fortune-mod/util/unstr.c | 172 ++++++++++---------- 5 files changed, 168 insertions(+), 158 deletions(-) diff --git a/fortune-mod/tests/trailing-space-and-CRs.pl b/fortune-mod/tests/trailing-space-and-CRs.pl index b6eb647..904abb9 100644 --- a/fortune-mod/tests/trailing-space-and-CRs.pl +++ b/fortune-mod/tests/trailing-space-and-CRs.pl @@ -21,6 +21,7 @@ my %do_not_check = my @cr_results; my @trailing_whitespace_results; +my @tabs_results; while (my $r = $tree->next_obj()) { if ($r->is_file) @@ -46,24 +47,33 @@ while (my $r = $tree->next_obj()) { push @trailing_whitespace_results, $fn; } + elsif ($r->basename =~ /\.[ch]\z/ and $contents =~ /\t/) + { + push @tabs_results, $fn; + } } } } -if (@cr_results or @trailing_whitespace_results) +if (@cr_results or @trailing_whitespace_results or @tabs_results) { print "The following files contain carriage returns:\n\n"; - foreach my $r (@cr_results) { print "$r\n"; } - print "The following files contain trailing whitespace:\n\n"; + print "The following files contain trailing whitespace:\n\n"; foreach my $r (@trailing_whitespace_results) { print "$r\n"; } + + print "The following source files contain tabs:\n\n"; + foreach my $r (@tabs_results) + { + print "$r\n"; + } exit(-1); } else diff --git a/fortune-mod/util/randstr.c b/fortune-mod/util/randstr.c index 4aab967..eb4832a 100644 --- a/fortune-mod/util/randstr.c +++ b/fortune-mod/util/randstr.c @@ -27,7 +27,7 @@ /*- * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ken Arnold. @@ -42,8 +42,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -86,26 +86,26 @@ * Who're you gonna quote? Dan Quayle? */ -#include -#include -#include "strfile.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include "strfile.h" +#include +#include +#include +#include +#include +#include #ifndef MAXPATHLEN -#define MAXPATHLEN 1024 +#define MAXPATHLEN 1024 #endif /* MAXPATHLEN */ -char *Infile, /* name of input file */ - Datafile[MAXPATHLEN], /* name of data file */ - Delimch; /* delimiter character */ +char *Infile, /* name of input file */ + Datafile[MAXPATHLEN], /* name of data file */ + Delimch; /* delimiter character */ FILE *Inf, *Dataf, *Outf; -off_t pos, Seekpts[2]; /* seek pointers to fortunes */ +off_t pos, Seekpts[2]; /* seek pointers to fortunes */ void getargs(int ac, char *av[]) @@ -117,20 +117,20 @@ void getargs(int ac, char *av[]) if (*av) { - Infile = *av; + Infile = *av; /* Hmm. Don't output anything if we can help it. * fprintf(stderr, "Input file: %s\n",Infile); */ - if (!strrchr(Infile, '.')) - { - strcpy(Datafile, Infile); - strcat(Datafile, ".dat"); - } - else - { - strcpy(Datafile, Infile); - extc = strrchr(Infile, '.'); - *extc = '\0'; - } + if (!strrchr(Infile, '.')) + { + strcpy(Datafile, Infile); + strcat(Datafile, ".dat"); + } + else + { + strcpy(Datafile, Infile); + extc = strrchr(Infile, '.'); + *extc = '\0'; + } } else /* { @@ -150,7 +150,7 @@ void get_pos(STRFILE * fp) { pos = random() % fp->str_numstr; if (++(pos) >= fp->str_numstr) - pos -= fp->str_numstr; + pos -= fp->str_numstr; } /* @@ -178,33 +178,33 @@ void display(FILE * fp, STRFILE table) fseek(fp, (long) Seekpts[0], 0); for (i = 0; fgets(line, sizeof line, fp) != NULL && - !STR_ENDSTRING(line, table); i++) + !STR_ENDSTRING(line, table); i++) { - if (table.str_flags & STR_ROTATED) - for (p = line; (ch = *p); ++p) - if (isupper(ch)) - *p = 'A' + (ch - 'A' + 13) % 26; - else if (islower(ch)) - *p = 'a' + (ch - 'a' + 13) % 26; - fputs(line, stdout); + if (table.str_flags & STR_ROTATED) + for (p = line; (ch = *p); ++p) + if (isupper(ch)) + *p = 'A' + (ch - 'A' + 13) % 26; + else if (islower(ch)) + *p = 'a' + (ch - 'a' + 13) % 26; + fputs(line, stdout); } fflush(stdout); } int main(int ac, char **av) { - static STRFILE tbl; /* description table */ + static STRFILE tbl; /* description table */ getargs(ac, av); if ((Inf = fopen(Infile, "r")) == NULL) { - perror(Infile); - exit(1); + perror(Infile); + exit(1); } if ((Dataf = fopen(Datafile, "r")) == NULL) { - perror(Datafile); - exit(1); + perror(Datafile); + exit(1); } fread((char *) &tbl, sizeof tbl, 1, Dataf); tbl.str_version = ntohl(tbl.str_version); diff --git a/fortune-mod/util/rot.c b/fortune-mod/util/rot.c index c9d5a95..acab56d 100644 --- a/fortune-mod/util/rot.c +++ b/fortune-mod/util/rot.c @@ -13,13 +13,13 @@ int main(void) while ((a = getchar()) != EOF) { - if (isupper(a)) - b = 'A' + (a - 'A' + 13) % 26; - else if (islower(a)) - b = 'a' + (a - 'a' + 13) % 26; - else - b = a; - putchar(b); + if (isupper(a)) + b = 'A' + (a - 'A' + 13) % 26; + else if (islower(a)) + b = 'a' + (a - 'a' + 13) % 26; + else + b = a; + putchar(b); } exit(0); } diff --git a/fortune-mod/util/strfile.h b/fortune-mod/util/strfile.h index 6be8240..1ff90d4 100644 --- a/fortune-mod/util/strfile.h +++ b/fortune-mod/util/strfile.h @@ -1,8 +1,8 @@ -/* $NetBSD: strfile.h,v 1.3 1995/03/23 08:28:49 cgd Exp $ */ +/* $NetBSD: strfile.h,v 1.3 1995/03/23 08:28:49 cgd Exp $ */ /*- * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ken Arnold. @@ -17,8 +17,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -35,22 +35,22 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)strfile.h 8.1 (Berkeley) 5/31/93 + * @(#)strfile.h 8.1 (Berkeley) 5/31/93 */ -#define STR_ENDSTRING(line,tbl) \ - ((line)[0] == (tbl).str_delim && (line)[1] == '\n') +#define STR_ENDSTRING(line,tbl) \ + ((line)[0] == (tbl).str_delim && (line)[1] == '\n') -typedef struct { /* information table */ -#define VERSION 2 - u_int32_t str_version; /* version number */ - u_int32_t str_numstr; /* # of strings in the file */ - u_int32_t str_longlen; /* length of longest string */ - u_int32_t str_shortlen; /* length of shortest string */ -#define STR_RANDOM 0x1 /* randomized pointers */ -#define STR_ORDERED 0x2 /* ordered pointers */ -#define STR_ROTATED 0x4 /* rot-13'd text */ - u_int32_t str_flags; /* bit field for flags */ - u_int8_t stuff[4]; /* long aligned space */ -#define str_delim stuff[0] /* delimiting character */ +typedef struct { /* information table */ +#define VERSION 2 + u_int32_t str_version; /* version number */ + u_int32_t str_numstr; /* # of strings in the file */ + u_int32_t str_longlen; /* length of longest string */ + u_int32_t str_shortlen; /* length of shortest string */ +#define STR_RANDOM 0x1 /* randomized pointers */ +#define STR_ORDERED 0x2 /* ordered pointers */ +#define STR_ROTATED 0x4 /* rot-13'd text */ + u_int32_t str_flags; /* bit field for flags */ + u_int8_t stuff[4]; /* long aligned space */ +#define str_delim stuff[0] /* delimiting character */ } STRFILE; diff --git a/fortune-mod/util/unstr.c b/fortune-mod/util/unstr.c index 769df40..96e0093 100644 --- a/fortune-mod/util/unstr.c +++ b/fortune-mod/util/unstr.c @@ -2,7 +2,7 @@ /*- * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ken Arnold. @@ -17,8 +17,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -40,12 +40,12 @@ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1991, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; + The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)unstr.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)unstr.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #endif /* comment out the dreck, kill the warnings */ @@ -88,26 +88,26 @@ static char sccsid[] = "@(#)unstr.c 8.1 (Berkeley) 5/31/93"; * get a fortune that contains nothing but a newline. Karo syrup, syrup. * For the gory details, and lots of cussing, see strfile.c */ -#include -#include -#include -#include "strfile.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include "strfile.h" +#include +#include +#include +#include +#include #ifndef MAXPATHLEN -#define MAXPATHLEN 1024 +#define MAXPATHLEN 1024 #endif /* MAXPATHLEN */ -char *Infile, /* name of input file */ - Datafile[MAXPATHLEN], /* name of data file */ - Delimch, /* delimiter character */ +char *Infile, /* name of input file */ + Datafile[MAXPATHLEN], /* name of data file */ + Delimch, /* delimiter character */ Outfile[MAXPATHLEN]; -char NewDelch = '\0'; /* a replacement delimiter character */ +char NewDelch = '\0'; /* a replacement delimiter character */ FILE *Inf, *Dataf, *Outf; @@ -120,54 +120,54 @@ void getargs(int ac, char *av[]) int ch; while ((ch = getopt(ac, av, "c:")) != EOF) - switch (ch) - { - case 'c': - NewDelch = *optarg; - if (!isascii(NewDelch)) - { - fprintf(stderr, "Bad delimiting characher: '\\%o'\n", NewDelch); - } - break; - case '?': - default: - fprintf(stderr, "Usage:\n\tunstr [-c C] datafile[.ext] [outputfile]\n"); - exit(1); - } + switch (ch) + { + case 'c': + NewDelch = *optarg; + if (!isascii(NewDelch)) + { + fprintf(stderr, "Bad delimiting characher: '\\%o'\n", NewDelch); + } + break; + case '?': + default: + fprintf(stderr, "Usage:\n\tunstr [-c C] datafile[.ext] [outputfile]\n"); + exit(1); + } av += optind; if (*av) { - Infile = *av; - fprintf(stderr, "Input file: %s\n", Infile); - if (!strrchr(Infile, '.')) - { - strcpy(Datafile, Infile); - strcat(Datafile, ".dat"); - } - else - { - strcpy(Datafile, Infile); - extc = strrchr(Infile, '.'); - *extc = '\0'; - } - if (*++av) - { - strcpy(Outfile, *av); - fprintf(stderr, "Output file: %s\n", Outfile); - } + Infile = *av; + fprintf(stderr, "Input file: %s\n", Infile); + if (!strrchr(Infile, '.')) + { + strcpy(Datafile, Infile); + strcat(Datafile, ".dat"); + } + else + { + strcpy(Datafile, Infile); + extc = strrchr(Infile, '.'); + *extc = '\0'; + } + if (*++av) + { + strcpy(Outfile, *av); + fprintf(stderr, "Output file: %s\n", Outfile); + } } else { - fprintf(stderr, "No input file name\n"); - fprintf(stderr, "Usage:\n\tunstr [-c C] datafile[.ext] [outputfile]\n"); - exit(1); + fprintf(stderr, "No input file name\n"); + fprintf(stderr, "Usage:\n\tunstr [-c C] datafile[.ext] [outputfile]\n"); + exit(1); } if (!strcmp(Infile, Outfile)) { - fprintf(stderr, "The input file for strings (%s) must be different from the output file (%s)\n", Infile, Outfile); - exit(1); + fprintf(stderr, "The input file for strings (%s) must be different from the output file (%s)\n", Infile, Outfile); + exit(1); } } @@ -182,48 +182,48 @@ void order_unstr(tbl) for (i = 0; i <= tbl->str_numstr; i++) { - fread((char *) &pos, 1, sizeof pos, Dataf); - fseek(Inf, ntohl(pos), 0); - printedsome = 0; - for (;;) - { - sp = fgets(buf, sizeof buf, Inf); - if (sp == NULL || STR_ENDSTRING(sp, *tbl)) - { - if (sp || printedsome) - fprintf(Outf, "%c\n", Delimch); - break; - } - else - { - printedsome = 1; - fputs(sp, Outf); - } - } + fread((char *) &pos, 1, sizeof pos, Dataf); + fseek(Inf, ntohl(pos), 0); + printedsome = 0; + for (;;) + { + sp = fgets(buf, sizeof buf, Inf); + if (sp == NULL || STR_ENDSTRING(sp, *tbl)) + { + if (sp || printedsome) + fprintf(Outf, "%c\n", Delimch); + break; + } + else + { + printedsome = 1; + fputs(sp, Outf); + } + } } } int main(int ac, char **av) { - static STRFILE tbl; /* description table */ + static STRFILE tbl; /* description table */ getargs(ac, av); if ((Inf = fopen(Infile, "r")) == NULL) { - perror(Infile); - exit(1); + perror(Infile); + exit(1); } if ((Dataf = fopen(Datafile, "r")) == NULL) { - perror(Datafile); - exit(1); + perror(Datafile); + exit(1); } if (*Outfile == '\0') - Outf = stdout; + Outf = stdout; else if ((Outf = fopen(Outfile, "w+")) == NULL) { - perror(Outfile); - exit(1); + perror(Outfile); + exit(1); } fread(&tbl.str_version, sizeof(tbl.str_version), 1, Dataf); fread(&tbl.str_numstr, sizeof(tbl.str_numstr), 1, Dataf); @@ -233,13 +233,13 @@ int main(int ac, char **av) fread( tbl.stuff, sizeof(tbl.stuff), 1, Dataf); if (!(tbl.str_flags & (STR_ORDERED | STR_RANDOM)) && (!NewDelch)) { - fprintf(stderr, "nothing to do -- table in file order\n"); - exit(1); + fprintf(stderr, "nothing to do -- table in file order\n"); + exit(1); } if (NewDelch) - Delimch = NewDelch; + Delimch = NewDelch; else - Delimch = tbl.str_delim; + Delimch = tbl.str_delim; order_unstr(&tbl); fclose(Inf); fclose(Dataf); -- 2.40.0