version 1.6, 1999/06/13 16:34:21 |
version 1.7, 2001/01/17 19:29:49 |
|
|
struct { |
struct { |
char *uname; |
char *uname; |
char *uval; |
char *uval; |
} unittable[MAXUNITS]; |
} unittable[MAXUNITS]; |
|
|
struct unittype { |
struct unittype { |
char *numerator[MAXSUBUNITS]; |
char *numerator[MAXSUBUNITS]; |
|
|
struct { |
struct { |
char *prefixname; |
char *prefixname; |
char *prefixval; |
char *prefixval; |
} prefixtable[MAXPREFIXES]; |
} prefixtable[MAXPREFIXES]; |
|
|
|
|
char *NULLUNIT = ""; |
char *NULLUNIT = ""; |
|
|
{ |
{ |
char *ret; |
char *ret; |
|
|
ret = malloc(strlen(str) + 1); |
ret = strdup(str); |
if (!ret) { |
if (!ret) { |
fprintf(stderr, "Memory allocation error\n"); |
fprintf(stderr, "Memory allocation error\n"); |
exit(3); |
exit(3); |
} |
} |
strcpy(ret, str); |
|
return (ret); |
return (ret); |
} |
} |
|
|
|
|
copy[strlen(copy) - 1] = '\0'; |
copy[strlen(copy) - 1] = '\0'; |
for (i = 0; i < unitcount; i++) { |
for (i = 0; i < unitcount; i++) { |
if (!strcmp(unittable[i].uname, copy)) { |
if (!strcmp(unittable[i].uname, copy)) { |
strncpy(buffer, copy, sizeof(buffer) - 1); |
strlcpy(buffer, copy, sizeof(buffer)); |
buffer[sizeof(buffer) - 1] = '\0'; |
|
free(copy); |
free(copy); |
return buffer; |
return buffer; |
} |
} |
|
|
copy[strlen(copy) - 1] = 0; |
copy[strlen(copy) - 1] = 0; |
for (i = 0; i < unitcount; i++) { |
for (i = 0; i < unitcount; i++) { |
if (!strcmp(unittable[i].uname, copy)) { |
if (!strcmp(unittable[i].uname, copy)) { |
strncpy(buffer, copy, sizeof(buffer) - 1); |
strlcpy(buffer, copy, sizeof(buffer)); |
buffer[sizeof(buffer) - 1] = '\0'; |
|
free(copy); |
free(copy); |
return buffer; |
return buffer; |
} |
} |
|
|
copy[strlen(copy) - 1] = 0; |
copy[strlen(copy) - 1] = 0; |
for (i = 0; i < unitcount; i++) { |
for (i = 0; i < unitcount; i++) { |
if (!strcmp(unittable[i].uname, copy)) { |
if (!strcmp(unittable[i].uname, copy)) { |
strncpy(buffer, copy, sizeof(buffer) - 1); |
strlcpy(buffer, copy, sizeof(buffer)); |
buffer[sizeof(buffer) - 1] = '\0'; |
|
free(copy); |
free(copy); |
return buffer; |
return buffer; |
} |
} |
|
|
readunits(userfile); |
readunits(userfile); |
|
|
if (optind == argc - 2) { |
if (optind == argc - 2) { |
strncpy(havestr, argv[optind], sizeof(havestr) - 1); |
strlcpy(havestr, argv[optind], sizeof(havestr)); |
havestr[sizeof(havestr) - 1] = '\0'; |
strlcpy(wantstr, argv[optind + 1], sizeof(wantstr)); |
strncpy(wantstr, argv[optind + 1], sizeof(wantstr) - 1); |
|
wantstr[sizeof(wantstr) - 1] = '\0'; |
|
initializeunit(&have); |
initializeunit(&have); |
addunit(&have, havestr, 0); |
addunit(&have, havestr, 0); |
completereduce(&have); |
completereduce(&have); |