Commit f979599b authored by Bruce Momjian's avatar Bruce Momjian

Modernize entab source code

Remove halt.c, improve comments, rename manual page file.
parent 8791627b
......@@ -8,7 +8,7 @@ XFLAGS =
CFLAGS = -O $(XFLAGS)
LIBS =
$(TARGET): entab.o halt.o
$(TARGET): entab.o
$(CC) -o $@ $(CFLAGS) $^ $(LIBS)
clean:
......
.\" 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
/*
** 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;
......
/*
**
** 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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment