version 1.3, 1996/06/26 05:42:15 |
version 1.4, 1996/08/11 00:17:31 |
|
|
|
|
char *NULLUNIT = ""; |
char *NULLUNIT = ""; |
|
|
|
#ifdef DOS |
|
#define SEPERATOR ";" |
|
#else |
|
#define SEPERATOR ":" |
|
#endif |
|
|
int unitcount; |
int unitcount; |
int prefixcount; |
int prefixcount; |
|
|
|
|
userfile); |
userfile); |
exit(1); |
exit(1); |
} |
} |
} |
} else { |
else { |
|
unitfile = fopen(UNITSFILE, "rt"); |
unitfile = fopen(UNITSFILE, "rt"); |
if (!unitfile) { |
if (!unitfile) { |
char *direc, *env; |
char *direc, *env; |
char filename[1000]; |
char filename[1000]; |
char separator[2]; |
char separator[2] = SEPERATOR; |
|
|
env = getenv("PATH"); |
env = getenv("PATH"); |
if (env) { |
if (env) { |
if (strchr(env, ';')) |
|
strcpy(separator, ";"); |
|
else |
|
strcpy(separator, ":"); |
|
direc = strtok(env, separator); |
direc = strtok(env, separator); |
while (direc) { |
while (direc) { |
strcpy(filename, ""); |
strcpy(filename, ""); |
|
|
continue; |
continue; |
if (lineptr[strlen(lineptr) - 1] == '-') { /* it's a prefix */ |
if (lineptr[strlen(lineptr) - 1] == '-') { /* it's a prefix */ |
if (prefixcount == MAXPREFIXES) { |
if (prefixcount == MAXPREFIXES) { |
fprintf(stderr, "Memory for prefixes exceeded in line %d\n", |
fprintf(stderr, |
|
"Memory for prefixes exceeded in line %d\n", |
linenum); |
linenum); |
continue; |
continue; |
} |
} |
|
|
prefixtable[prefixcount].prefixname = dupstr(lineptr); |
prefixtable[prefixcount].prefixname = dupstr(lineptr); |
for (i = 0; i < prefixcount; i++) |
for (i = 0; i < prefixcount; i++) |
if (!strcmp(prefixtable[i].prefixname, lineptr)) { |
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); |
lineptr, linenum); |
continue; |
continue; |
} |
} |
|
|
} |
} |
else { /* it's not a prefix */ |
else { /* it's not a prefix */ |
if (unitcount == MAXUNITS) { |
if (unitcount == MAXUNITS) { |
fprintf(stderr, "Memory for units exceeded in line %d\n", |
fprintf(stderr, |
|
"Memory for units exceeded in line %d\n", |
linenum); |
linenum); |
continue; |
continue; |
} |
} |
unittable[unitcount].uname = dupstr(lineptr); |
unittable[unitcount].uname = dupstr(lineptr); |
for (i = 0; i < unitcount; i++) |
for (i = 0; i < unitcount; i++) |
if (!strcmp(unittable[i].uname, lineptr)) { |
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); |
lineptr, linenum); |
continue; |
continue; |
} |
} |
|
|
void |
void |
usage() |
usage() |
{ |
{ |
fprintf(stderr, "\nunits [-f unitsfile] [-q] [-v] [from-unit to-unit]\n"); |
fprintf(stderr, "units [-f unitsfile] [-q] [-v] [from-unit to-unit]\n"); |
fprintf(stderr, "\n -f specify units file\n"); |
fprintf(stderr, " -f specify units file\n"); |
fprintf(stderr, " -q supress prompting (quiet)\n"); |
fprintf(stderr, " -q supress prompting (quiet)\n"); |
fprintf(stderr, " -v print version number\n"); |
fprintf(stderr, " -v print version number\n"); |
exit(3); |
exit(3); |
|
|
quiet = 1; |
quiet = 1; |
break; |
break; |
case 'v': |
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); |
VERSION); |
fprintf(stderr, " This program may be freely distributed\n"); |
fprintf(stderr, |
|
"This program may be freely distributed\n"); |
usage(); |
usage(); |
default: |
default: |
usage(); |
usage(); |
|
|
} |
} |
else { |
else { |
if (!quiet) |
if (!quiet) |
printf("%d units, %d prefixes\n\n", unitcount, |
printf("%d units, %d prefixes\n", unitcount, |
prefixcount); |
prefixcount); |
for (;;) { |
for (;;) { |
do { |
do { |
|
|
if (!quiet) |
if (!quiet) |
printf("You have: "); |
printf("You have: "); |
if (!fgets(havestr, 80, stdin)) { |
if (!fgets(havestr, 80, stdin)) { |
if (!quiet); |
if (!quiet) |
putchar('\n'); |
putchar('\n'); |
exit(0); |
exit(0); |
} |
} |
} while (addunit(&have, havestr, 0) || |
} while (addunit(&have, havestr, 0) || |
|
|
showanswer(&have, &want); |
showanswer(&have, &want); |
} |
} |
} |
} |
|
return (0); |
} |
} |