summaryrefslogtreecommitdiff
path: root/usr.bin/units
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-08-11 00:17:32 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-08-11 00:17:32 +0000
commitdb967d53a32c0484f2ef756a9dc99b9ea30f5994 (patch)
treeff2bb4b801ebf810cc874080e9f8648adc5efc23 /usr.bin/units
parent5a97bf016964824135dc7ab20da891ff2d97e6ce (diff)
two fixes from freebsd plus some more by me
Diffstat (limited to 'usr.bin/units')
-rw-r--r--usr.bin/units/units.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/usr.bin/units/units.c b/usr.bin/units/units.c
index 4fbe0c20afd..398445af68d 100644
--- a/usr.bin/units/units.c
+++ b/usr.bin/units/units.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: units.c,v 1.3 1996/06/26 05:42:15 deraadt Exp $ */
+/* $OpenBSD: units.c,v 1.4 1996/08/11 00:17:31 deraadt Exp $ */
/* $NetBSD: units.c,v 1.6 1996/04/06 06:01:03 thorpej Exp $ */
/*
@@ -59,6 +59,12 @@ struct {
char *NULLUNIT = "";
+#ifdef DOS
+#define SEPERATOR ";"
+#else
+#define SEPERATOR ":"
+#endif
+
int unitcount;
int prefixcount;
@@ -103,20 +109,15 @@ readunits(char *userfile)
userfile);
exit(1);
}
- }
- else {
+ } else {
unitfile = fopen(UNITSFILE, "rt");
if (!unitfile) {
char *direc, *env;
char filename[1000];
- char separator[2];
+ char separator[2] = SEPERATOR;
env = getenv("PATH");
if (env) {
- if (strchr(env, ';'))
- strcpy(separator, ";");
- else
- strcpy(separator, ":");
direc = strtok(env, separator);
while (direc) {
strcpy(filename, "");
@@ -152,7 +153,8 @@ readunits(char *userfile)
continue;
if (lineptr[strlen(lineptr) - 1] == '-') { /* it's a prefix */
if (prefixcount == MAXPREFIXES) {
- fprintf(stderr, "Memory for prefixes exceeded in line %d\n",
+ fprintf(stderr,
+ "Memory for prefixes exceeded in line %d\n",
linenum);
continue;
}
@@ -160,7 +162,8 @@ readunits(char *userfile)
prefixtable[prefixcount].prefixname = dupstr(lineptr);
for (i = 0; i < prefixcount; i++)
if (!strcmp(prefixtable[i].prefixname, lineptr)) {
- fprintf(stderr, "Redefinition of prefix '%s' on line %d ignored\n",
+ fprintf(stderr,
+ "Redefinition of prefix '%s' on line %d ignored\n",
lineptr, linenum);
continue;
}
@@ -176,14 +179,16 @@ readunits(char *userfile)
}
else { /* it's not a prefix */
if (unitcount == MAXUNITS) {
- fprintf(stderr, "Memory for units exceeded in line %d\n",
+ fprintf(stderr,
+ "Memory for units exceeded in line %d\n",
linenum);
continue;
}
unittable[unitcount].uname = dupstr(lineptr);
for (i = 0; i < unitcount; i++)
if (!strcmp(unittable[i].uname, lineptr)) {
- fprintf(stderr, "Redefinition of unit '%s' on line %d ignored\n",
+ fprintf(stderr,
+ "Redefinition of unit '%s' on line %d ignored\n",
lineptr, linenum);
continue;
}
@@ -618,8 +623,8 @@ showanswer(struct unittype * have, struct unittype * want)
void
usage()
{
- fprintf(stderr, "\nunits [-f unitsfile] [-q] [-v] [from-unit to-unit]\n");
- fprintf(stderr, "\n -f specify units file\n");
+ fprintf(stderr, "units [-f unitsfile] [-q] [-v] [from-unit to-unit]\n");
+ fprintf(stderr, " -f specify units file\n");
fprintf(stderr, " -q supress prompting (quiet)\n");
fprintf(stderr, " -v print version number\n");
exit(3);
@@ -648,9 +653,11 @@ main(int argc, char **argv)
quiet = 1;
break;
case 'v':
- fprintf(stderr, "\n units version %s Copyright (c) 1993 by Adrian Mariano\n",
+ fprintf(stderr,
+ "units version %s Copyright (c) 1993 by Adrian Mariano\n",
VERSION);
- fprintf(stderr, " This program may be freely distributed\n");
+ fprintf(stderr,
+ "This program may be freely distributed\n");
usage();
default:
usage();
@@ -676,7 +683,7 @@ main(int argc, char **argv)
}
else {
if (!quiet)
- printf("%d units, %d prefixes\n\n", unitcount,
+ printf("%d units, %d prefixes\n", unitcount,
prefixcount);
for (;;) {
do {
@@ -684,8 +691,8 @@ main(int argc, char **argv)
if (!quiet)
printf("You have: ");
if (!fgets(havestr, 80, stdin)) {
- if (!quiet);
- putchar('\n');
+ if (!quiet)
+ putchar('\n');
exit(0);
}
} while (addunit(&have, havestr, 0) ||
@@ -704,4 +711,5 @@ main(int argc, char **argv)
showanswer(&have, &want);
}
}
+ return (0);
}