Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Modernize entab source code
authorBruce Momjian <bruce@momjian.us>
Wed, 19 Jun 2013 16:31:23 +0000 (12:31 -0400)
committerBruce Momjian <bruce@momjian.us>
Wed, 19 Jun 2013 16:31:26 +0000 (12:31 -0400)
Remove halt.c, improve comments, rename manual page file.

src/tools/entab/Makefile
src/tools/entab/entab.1 [moved from src/tools/entab/entab.man with 96% similarity]
src/tools/entab/entab.c
src/tools/entab/halt.c [deleted file]

index 00be1f5ee732bd101394e84648dafc8e6502ac3b..f02730d35f26631e041ef686cd6d9c0bd25e417b 100644 (file)
@@ -8,7 +8,7 @@ XFLAGS =
 CFLAGS = -O $(XFLAGS)
 LIBS =
 
-$(TARGET): entab.o halt.o
+$(TARGET): entab.o
    $(CC) -o $@ $(CFLAGS) $^ $(LIBS)
 
 clean:
similarity index 96%
rename from src/tools/entab/entab.man
rename to src/tools/entab/entab.1
index 362ec730f46727a15f6ed84b03fd9f2aaf48696b..bb3dcf45aad8407840397a78ce6a9561492affaa 100644 (file)
@@ -1,4 +1,3 @@
-.\" src/tools/entab/entab.man
 .TH ENTAB 1 local
 .SH NAME
 entab - tab processor
@@ -49,4 +48,4 @@ 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
+Bruce Momjian, bruce@momjian.us
index cb5a406345ef5f034fe166fa5b8c791c87dde505..c3b9776ea15348835ffd530f450e86fd44d3becd 100644 (file)
@@ -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 <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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/halt.c b/src/tools/entab/halt.c
deleted file mode 100644 (file)
index e7d2e44..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
-**
-**     halt.c
-**
-** src/tools/entab/halt.c
-**
-**     This is used to print out error messages and exit
-*/
-
-#include <stdarg.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-
-/*-------------------------------------------------------------------------
-**
-**     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);
-}