From f979599b2068f036405f1b51a9c4260619b06941 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Wed, 19 Jun 2013 12:31:23 -0400 Subject: Modernize entab source code Remove halt.c, improve comments, rename manual page file. --- src/tools/entab/Makefile | 2 +- src/tools/entab/entab.1 | 51 ++++++++++++++++++++++++++++++++++++++++ src/tools/entab/entab.c | 30 +++++++++++------------- src/tools/entab/entab.man | 52 ----------------------------------------- src/tools/entab/halt.c | 59 ----------------------------------------------- 5 files changed, 66 insertions(+), 128 deletions(-) create mode 100644 src/tools/entab/entab.1 delete mode 100644 src/tools/entab/entab.man delete mode 100644 src/tools/entab/halt.c (limited to 'src') diff --git a/src/tools/entab/Makefile b/src/tools/entab/Makefile index 00be1f5ee73..f02730d35f2 100644 --- a/src/tools/entab/Makefile +++ b/src/tools/entab/Makefile @@ -8,7 +8,7 @@ XFLAGS = CFLAGS = -O $(XFLAGS) LIBS = -$(TARGET): entab.o halt.o +$(TARGET): entab.o $(CC) -o $@ $(CFLAGS) $^ $(LIBS) clean: diff --git a/src/tools/entab/entab.1 b/src/tools/entab/entab.1 new file mode 100644 index 00000000000..bb3dcf45aad --- /dev/null +++ b/src/tools/entab/entab.1 @@ -0,0 +1,51 @@ +.TH ENTAB 1 local +.SH NAME +entab - tab processor +.SH SYNOPSIS +.nf +entab [-cdq] [-s min_spaces] [-t tab_width] [file ... ] +detab [-cq] [-s min_spaces] [-t tab_width] [file ... ] +.fi +.SH DESCRIPTION +Entab is a program designed to selectively add or remove tabs +from a file based on user-supplied criteria. +In default mode, entab prints the specified files to standard output +with the optimal mix of tabs and spaces. +Tabs default to every 8 characters, and tabs are used only when they +can replace more than one space, unlike 'col' which uses tabs wherever +possible. +.LP +The options are: +.in +0.5i +.nf +-c Clip trailing tabs and spaces from each line. +-d Delete all tabs from output +-q Protect single and double-quoted strings from tab replacement. + (This option is useful when operating on source code. + Line continuation with back-slashes is also understood.) +-s Minimum spaces needed to replace with a tab (default = 2). +-t Number of spaces in a tab stop (default = 8). +.fi +.in -0.5i +Detab is equivalent to entab -d. +.SH NOTES +Entab has improved tab handling for certain situations. +It only replaces tabs if there is a user-defined number of spaces +to be saved. +Other tab replacement programs put tabs wherever +possible, so if two words are separated by one space, and that +space is on a tab stop, a tab is inserted. +Then, when words are added to the left, the words are shifted over, +leaving a large gap. +The quote-protection option allows tab replacement without +quoted strings being changed. +Useful when strings in source code will not have the same tab stops +when executed in the program. +.LP +To change a text file created on a system with one size of tab +stop to display properly on a device with different tab setting, +use detab (or entab -d) to remove tabs from the file with the +tab size set to the original tab size, then use entab to re-tab +the file with the new tab size. +.SH AUTHOR +Bruce Momjian, bruce@momjian.us diff --git a/src/tools/entab/entab.c b/src/tools/entab/entab.c index cb5a406345e..c3b9776ea15 100644 --- a/src/tools/entab/entab.c +++ b/src/tools/entab/entab.c @@ -1,15 +1,8 @@ /* -** entab.c - add tabs to a text file -** by Bruce Momjian (root@candle.pha.pa.us) -** -** src/tools/entab/entab.c -** -** version 1.3 -** -** tabsize = 4 -** -*/ + * entab.c - adds/removes tabs from text files + */ +#include #include #include #include @@ -22,7 +15,7 @@ #define PG_BINARY_R "r" #endif -#define NUL '\0' +#define NUL '\0' #ifndef TRUE #define TRUE 1 @@ -31,8 +24,6 @@ #define FALSE 0 #endif -void halt(); - extern char *optarg; extern int optind; @@ -84,13 +75,14 @@ main(int argc, char **argv) break; case 'h': case '?': - halt("USAGE: %s [ -cdqst ] [file ...]\n\ + fprintf(stderr, "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); + exit(0); } argv += optind; @@ -103,7 +95,10 @@ main(int argc, char **argv) else { if ((in_file = fopen(*argv, PG_BINARY_R)) == NULL) - halt("PERROR: Cannot open file %s\n", argv[0]); + { + fprintf(stderr, "Cannot open file %s: %s\n", argv[0], strerror(errno)); + exit(1); + } argv++; } @@ -219,7 +214,10 @@ main(int argc, char **argv) *(dst++) = ' '; *dst = NUL; if (fputs(out_line, stdout) == EOF) - halt("PERROR: Error writing output.\n"); + { + fprintf(stderr, "Cannot write to output file %s: %s\n", argv[0], strerror(errno)); + exit(1); + } } } while (--argc > 0); return 0; diff --git a/src/tools/entab/entab.man b/src/tools/entab/entab.man deleted file mode 100644 index 362ec730f46..00000000000 --- a/src/tools/entab/entab.man +++ /dev/null @@ -1,52 +0,0 @@ -.\" src/tools/entab/entab.man -.TH ENTAB 1 local -.SH NAME -entab - tab processor -.SH SYNOPSIS -.nf -entab [-cdq] [-s min_spaces] [-t tab_width] [file ... ] -detab [-cq] [-s min_spaces] [-t tab_width] [file ... ] -.fi -.SH DESCRIPTION -Entab is a program designed to selectively add or remove tabs -from a file based on user-supplied criteria. -In default mode, entab prints the specified files to standard output -with the optimal mix of tabs and spaces. -Tabs default to every 8 characters, and tabs are used only when they -can replace more than one space, unlike 'col' which uses tabs wherever -possible. -.LP -The options are: -.in +0.5i -.nf --c Clip trailing tabs and spaces from each line. --d Delete all tabs from output --q Protect single and double-quoted strings from tab replacement. - (This option is useful when operating on source code. - Line continuation with back-slashes is also understood.) --s Minimum spaces needed to replace with a tab (default = 2). --t Number of spaces in a tab stop (default = 8). -.fi -.in -0.5i -Detab is equivalent to entab -d. -.SH NOTES -Entab has improved tab handling for certain situations. -It only replaces tabs if there is a user-defined number of spaces -to be saved. -Other tab replacement programs put tabs wherever -possible, so if two words are separated by one space, and that -space is on a tab stop, a tab is inserted. -Then, when words are added to the left, the words are shifted over, -leaving a large gap. -The quote-protection option allows tab replacement without -quoted strings being changed. -Useful when strings in source code will not have the same tab stops -when executed in the program. -.LP -To change a text file created on a system with one size of tab -stop to display properly on a device with different tab setting, -use detab (or entab -d) to remove tabs from the file with the -tab size set to the original tab size, then use entab to re-tab -the file with the new tab size. -.SH AUTHOR -Bruce Momjian, root@candle.pha.pa.us diff --git a/src/tools/entab/halt.c b/src/tools/entab/halt.c deleted file mode 100644 index e7d2e4496be..00000000000 --- a/src/tools/entab/halt.c +++ /dev/null @@ -1,59 +0,0 @@ -/* -** -** halt.c -** -** src/tools/entab/halt.c -** -** This is used to print out error messages and exit -*/ - -#include -#include -#include -#include -#include -#include - - -/*------------------------------------------------------------------------- -** -** halt - print error message, and call clean up routine or exit -** -**------------------------------------------------------------------------*/ - -/*VARARGS*/ -void -halt(const char *format,...) -{ - va_list arg_ptr; - const char *pstr; - void (*sig_func) (); - - va_start(arg_ptr, format); - if (strncmp(format, "PERROR", 6) != 0) - vfprintf(stderr, format, arg_ptr); - else - { - for (pstr = format + 6; *pstr == ' ' || *pstr == ':'; pstr++) - ; - 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); - exit(1); -} -- cgit v1.2.3