summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-07-01 06:34:31 +0000
committercharnier <charnier@FreeBSD.org>1997-07-01 06:34:31 +0000
commit392cc87247bab93e1b147f7da4cc6d0955a7d5f4 (patch)
tree988a41eb9b2217db994ae9069e6a44be1b4acaac
parentee55475a0f2a0c7391240ed7c9adc2b5a6e10a94 (diff)
downloadFreeBSD-src-392cc87247bab93e1b147f7da4cc6d0955a7d5f4.zip
FreeBSD-src-392cc87247bab93e1b147f7da4cc6d0955a7d5f4.tar.gz
Add usage(), rcsid. Use getopt().
Obtained from: OpenBSD.
-rw-r--r--usr.bin/expand/expand.c56
1 files changed, 44 insertions, 12 deletions
diff --git a/usr.bin/expand/expand.c b/usr.bin/expand/expand.c
index c3a00e7..9d92f41 100644
--- a/usr.bin/expand/expand.c
+++ b/usr.bin/expand/expand.c
@@ -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 @@ bad:
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);
+}
OpenPOWER on IntegriCloud