Add usage(), rcsid. Use getopt().

Obtained from: OpenBSD.
This commit is contained in:
Philippe Charnier 1997-07-01 06:34:31 +00:00
parent 55f4e300b4
commit ca15609236
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=27147

View File

@ -38,16 +38,29 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)expand.c 8.1 (Berkeley) 6/9/93";
#else
static const char rcsid[] =
"$Id$";
#endif
#endif /* not lint */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
/*
* expand - expand tabs to equivalent spaces
*/
int nstops;
int tabstops[100];
static void getstops __P((char *));
static void usage __P((void));
int
main(argc, argv)
int argc;
char *argv[];
@ -55,12 +68,27 @@ main(argc, argv)
register int c, column;
register int n;
argc--, argv++;
do {
while (argc > 0 && argv[0][0] == '-') {
getstops(argv[0]);
argc--, argv++;
/* handle obsolete syntax */
while (argc > 1 && argv[1][0] && isdigit(argv[1][1])) {
getstops(&argv[1][1]);
argc--; argv++;
}
while ((c = getopt (argc, argv, "t:")) != -1) {
switch (c) {
case 't':
getstops(optarg);
break;
case '?':
default:
usage();
/* NOTREACHED */
}
}
argc -= optind;
argv += optind;
do {
if (argc > 0) {
if (freopen(argv[0], "r", stdin) == NULL) {
perror(argv[0]);
@ -69,12 +97,8 @@ main(argc, argv)
argc--, argv++;
}
column = 0;
for (;;) {
c = getc(stdin);
if (c == -1)
break;
while ((c = getchar()) != EOF) {
switch (c) {
case '\t':
if (nstops == 0) {
do {
@ -125,13 +149,13 @@ main(argc, argv)
exit(0);
}
static void
getstops(cp)
register char *cp;
{
register int i;
nstops = 0;
cp++;
for (;;) {
i = 0;
while (*cp >= '0' && *cp <= '9')
@ -146,7 +170,15 @@ getstops(cp)
tabstops[nstops++] = i;
if (*cp == 0)
break;
if (*cp++ != ',')
if (*cp != ',' && *cp != ' ')
goto bad;
cp++;
}
}
static void
usage()
{
(void)fprintf (stderr, "usage: expand [-t tablist] [file ...]\n");
exit(1);
}