Modernize entab source code
Remove halt.c, improve comments, rename manual page file.
This commit is contained in:
parent
8791627b8f
commit
f979599b20
@ -8,7 +8,7 @@ XFLAGS =
|
|||||||
CFLAGS = -O $(XFLAGS)
|
CFLAGS = -O $(XFLAGS)
|
||||||
LIBS =
|
LIBS =
|
||||||
|
|
||||||
$(TARGET): entab.o halt.o
|
$(TARGET): entab.o
|
||||||
$(CC) -o $@ $(CFLAGS) $^ $(LIBS)
|
$(CC) -o $@ $(CFLAGS) $^ $(LIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
.\" src/tools/entab/entab.man
|
|
||||||
.TH ENTAB 1 local
|
.TH ENTAB 1 local
|
||||||
.SH NAME
|
.SH NAME
|
||||||
entab - tab processor
|
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
|
tab size set to the original tab size, then use entab to re-tab
|
||||||
the file with the new tab size.
|
the file with the new tab size.
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Bruce Momjian, root@candle.pha.pa.us
|
Bruce Momjian, bruce@momjian.us
|
@ -1,15 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
** entab.c - add tabs to a text file
|
* entab.c - adds/removes tabs from text files
|
||||||
** by Bruce Momjian (root@candle.pha.pa.us)
|
*/
|
||||||
**
|
|
||||||
** src/tools/entab/entab.c
|
|
||||||
**
|
|
||||||
** version 1.3
|
|
||||||
**
|
|
||||||
** tabsize = 4
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -22,7 +15,7 @@
|
|||||||
#define PG_BINARY_R "r"
|
#define PG_BINARY_R "r"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NUL '\0'
|
#define NUL '\0'
|
||||||
|
|
||||||
#ifndef TRUE
|
#ifndef TRUE
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
@ -31,8 +24,6 @@
|
|||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void halt();
|
|
||||||
|
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
extern int optind;
|
extern int optind;
|
||||||
|
|
||||||
@ -84,13 +75,14 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
case '?':
|
case '?':
|
||||||
halt("USAGE: %s [ -cdqst ] [file ...]\n\
|
fprintf(stderr, "USAGE: %s [ -cdqst ] [file ...]\n\
|
||||||
-c (clip trailing whitespace)\n\
|
-c (clip trailing whitespace)\n\
|
||||||
-d (delete tabs)\n\
|
-d (delete tabs)\n\
|
||||||
-q (protect quotes)\n\
|
-q (protect quotes)\n\
|
||||||
-s minimum_spaces\n\
|
-s minimum_spaces\n\
|
||||||
-t tab_width\n",
|
-t tab_width\n",
|
||||||
cp);
|
cp);
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
argv += optind;
|
argv += optind;
|
||||||
@ -103,7 +95,10 @@ main(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((in_file = fopen(*argv, PG_BINARY_R)) == NULL)
|
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++;
|
argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +214,10 @@ main(int argc, char **argv)
|
|||||||
*(dst++) = ' ';
|
*(dst++) = ' ';
|
||||||
*dst = NUL;
|
*dst = NUL;
|
||||||
if (fputs(out_line, stdout) == EOF)
|
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);
|
} while (--argc > 0);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -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);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user