diff options
| author | Bruce Momjian | 1997-09-07 05:04:48 +0000 |
|---|---|---|
| committer | Bruce Momjian | 1997-09-07 05:04:48 +0000 |
| commit | 1ccd423235a48739d6f7a4d7889705b5f9ecc69b (patch) | |
| tree | 8001c4e839dfad8f29ceda7f8c5f5dbb8759b564 /src/tools | |
| parent | 8fecd4febf8357f3cc20383ed29ced484877d5ac (diff) | |
Massive commit to run PGINDENT on all *.c and *.h files.
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/entab/entab.c | 153 | ||||
| -rw-r--r-- | src/tools/entab/halt.c | 54 |
2 files changed, 110 insertions, 97 deletions
diff --git a/src/tools/entab/entab.c b/src/tools/entab/entab.c index 2552658228..b11b84989e 100644 --- a/src/tools/entab/entab.c +++ b/src/tools/entab/entab.c @@ -1,10 +1,10 @@ /* -** entab.c - add tabs to a text file -** by Bruce Momjian (root@candle.pha.pa.us) +** entab.c - add tabs to a text file +** by Bruce Momjian (root@candle.pha.pa.us) ** -** version 1.3 +** version 1.3 ** -** tabsize = 4 +** tabsize = 4 ** */ @@ -12,78 +12,90 @@ #include <stdlib.h> #include <string.h> -#define NUL '\0' +#define NUL '\0' #ifndef TRUE -#define TRUE 1 +#define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif -void halt(); - -extern char *optarg; -extern int optind; +void halt(); -int main(argc, argv) -int argc; -char **argv; +extern char *optarg; +extern int optind; + +int +main(argc, argv) +int argc; +char **argv; { - int tab_size = 8, - min_spaces = 2, - protect_quotes = FALSE, - del_tabs = FALSE, - clip_lines = FALSE, - prv_spaces, - col_in_tab, - escaped, - nxt_spaces; - char in_line[BUFSIZ], - out_line[BUFSIZ], - *src, - *dst, - quote_char, - ch, - *cp; - FILE *in_file; - - if ((cp = strrchr(argv[0],'/')) != NULL) + int tab_size = 8, + min_spaces = 2, + protect_quotes = FALSE, + del_tabs = FALSE, + clip_lines = FALSE, + prv_spaces, + col_in_tab, + escaped, + nxt_spaces; + char in_line[BUFSIZ], + out_line[BUFSIZ], + *src, + *dst, + quote_char, + ch, + *cp; + FILE *in_file; + + if ((cp = strrchr(argv[0], '/')) != NULL) ++cp; else cp = argv[0]; - if (strcmp(cp,"detab") == 0) + if (strcmp(cp, "detab") == 0) del_tabs = 1; - + while ((ch = getopt(argc, argv, "cdhqs:t:")) != -1) switch (ch) { - case 'c' : clip_lines = TRUE; break; - case 'd' : del_tabs = TRUE; break; - case 'q' : protect_quotes = TRUE; break; - case 's' : min_spaces = atoi(optarg); break; - case 't' : tab_size = atoi(optarg); break; - case 'h' : - case '?' : - halt("USAGE: %s [ -cdqst ] [file ...]\n\ + case 'c': + clip_lines = TRUE; + break; + case 'd': + del_tabs = TRUE; + break; + case 'q': + protect_quotes = TRUE; + break; + case 's': + min_spaces = atoi(optarg); + break; + case 't': + tab_size = atoi(optarg); + break; + case 'h': + case '?': + halt("USAGE: %s [ -cdqst ] [file ...]\n\ -c (clip trailing whitespace)\n\ -d (delete tabs)\n\ -q (protect quotes)\n\ -s minimum_spaces\n\ -t tab_width\n", - cp); + cp); } argv += optind; argc -= optind; - - do { + + do + { if (argc < 1) in_file = stdin; else { - if ( (in_file=fopen(*argv,"r")) == NULL) - halt("PERROR: Can not open file %s\n",argv[0]); + if ((in_file = fopen(*argv, "r")) == NULL) + halt("PERROR: Can not open file %s\n", argv[0]); argv++; } @@ -114,30 +126,30 @@ char **argv; if (col_in_tab == tab_size) { + /* - Is the next character going to be a tab? - Needed to do tab replacement in current spot - if next char is going to be a tab, ignoring - min_spaces + * Is the next character going to be a tab? Needed + * to do tab replacement in current spot if next + * char is going to be a tab, ignoring min_spaces */ nxt_spaces = 0; while (1) { - if ( *(src+nxt_spaces+1) == NUL || - (*(src+nxt_spaces+1) != ' ' && - *(src+nxt_spaces+1) != '\t')) + if (*(src + nxt_spaces + 1) == NUL || + (*(src + nxt_spaces + 1) != ' ' && + *(src + nxt_spaces + 1) != '\t')) break; - if (*(src+nxt_spaces+1) == ' ') + if (*(src + nxt_spaces + 1) == ' ') ++nxt_spaces; - if (*(src+nxt_spaces+1) == '\t' || - nxt_spaces == tab_size) + if (*(src + nxt_spaces + 1) == '\t' || + nxt_spaces == tab_size) { nxt_spaces = tab_size; break; } } if ((prv_spaces >= min_spaces || - nxt_spaces == tab_size) && + nxt_spaces == tab_size) && del_tabs == FALSE) { *(dst++) = '\t'; @@ -154,7 +166,7 @@ char **argv; { for (; prv_spaces > 0; prv_spaces--) *(dst++) = ' '; - if (*src == '\t') /* only when in quote */ + if (*src == '\t') /* only when in quote */ col_in_tab = 0; if (*src == '\b') col_in_tab -= 2; @@ -164,22 +176,21 @@ char **argv; escaped = TRUE; if (*src == '"' || *src == '\'') if (quote_char == ' ') - quote_char = *src; + quote_char = *src; else if (*src == quote_char) - quote_char = ' '; + quote_char = ' '; } - else - if (*src != '\r' && *src != '\n') - escaped = FALSE; - - if (( *src == '\r' || *src == '\n') && + else if (*src != '\r' && *src != '\n') + escaped = FALSE; + + if ((*src == '\r' || *src == '\n') && quote_char == ' ' && clip_lines == TRUE && escaped == FALSE) { while (dst > out_line && - (*(dst-1) == ' ' || *(dst-1) == '\t')) - dst--; + (*(dst - 1) == ' ' || *(dst - 1) == '\t')) + dst--; prv_spaces = 0; } *(dst++) = *src; @@ -191,14 +202,14 @@ char **argv; if (clip_lines == TRUE && escaped == FALSE) { while (dst > out_line && - (*(dst-1) == ' ' || *(dst-1) == '\t')) - dst--; + (*(dst - 1) == ' ' || *(dst - 1) == '\t')) + dst--; prv_spaces = 0; } for (; prv_spaces > 0; prv_spaces--) *(dst++) = ' '; *dst = NUL; - if (fputs(out_line,stdout) == EOF) + if (fputs(out_line, stdout) == EOF) halt("PERROR: Error writing output.\n"); } } while (--argc > 0); diff --git a/src/tools/entab/halt.c b/src/tools/entab/halt.c index 7df7a45c0e..5d48f58152 100644 --- a/src/tools/entab/halt.c +++ b/src/tools/entab/halt.c @@ -1,8 +1,8 @@ /* ** -** halt.c +** halt.c ** -** This is used to print out error messages and exit +** This is used to print out error messages and exit */ #include <varargs.h> @@ -13,44 +13,46 @@ /*------------------------------------------------------------------------- ** -** halt - print error message, and call clean up routine or exit +** halt - print error message, and call clean up routine or exit ** **------------------------------------------------------------------------*/ /*VARARGS*/ -void halt(va_alist) +void +halt(va_alist) va_dcl { - va_list arg_ptr; - char *format, *pstr; - void (*sig_func)(); + va_list arg_ptr; + char *format, + *pstr; + void (*sig_func) (); va_start(arg_ptr); - format = va_arg(arg_ptr,char *); - if (strncmp(format,"PERROR", 6) != 0) - vfprintf(stderr,format,arg_ptr); + format = va_arg(arg_ptr, char *); + if (strncmp(format, "PERROR", 6) != 0) + vfprintf(stderr, format, arg_ptr); else { - for (pstr=format+6; *pstr == ' ' || *pstr == ':'; pstr++) + for (pstr = format + 6; *pstr == ' ' || *pstr == ':'; pstr++) ; - vfprintf(stderr,pstr,arg_ptr); + vfprintf(stderr, pstr, arg_ptr); perror(""); - } + } va_end(arg_ptr); fflush(stderr); - /* call one clean up function if defined */ - if ( (sig_func = signal(SIGTERM, SIG_DFL)) != SIG_DFL && - sig_func != SIG_IGN) - (*sig_func)(0); - else if ( (sig_func = signal(SIGHUP, SIG_DFL)) != SIG_DFL && - sig_func != SIG_IGN) - (*sig_func)(0); - else if ( (sig_func = signal(SIGINT, SIG_DFL)) != SIG_DFL && - sig_func != SIG_IGN) - (*sig_func)(0); - else if ( (sig_func = signal(SIGQUIT, SIG_DFL)) != SIG_DFL && - sig_func != SIG_IGN) - (*sig_func)(0); + /* call one clean up function if defined */ + if ((sig_func = signal(SIGTERM, SIG_DFL)) != SIG_DFL && + sig_func != SIG_IGN) + (*sig_func) (0); + else if ((sig_func = signal(SIGHUP, SIG_DFL)) != SIG_DFL && + sig_func != SIG_IGN) + (*sig_func) (0); + else if ((sig_func = signal(SIGINT, SIG_DFL)) != SIG_DFL && + sig_func != SIG_IGN) + (*sig_func) (0); + else if ((sig_func = signal(SIGQUIT, SIG_DFL)) != SIG_DFL && + sig_func != SIG_IGN) + (*sig_func) (0); exit(1); } |
