int main(int argc, char **argv) { struct unittype have, want; char havestr[81], wantstr[81]; int optchar; char *userfile = 0; int quiet = 0; while ((optchar = getopt(argc, argv, "vqf:")) != -1) { switch (optchar) { case 'f': userfile = optarg; break; case 'q': quiet = 1; break; case 'v': fprintf(stderr, "\n units version %s Copyright (c) 1993 by Adrian Mariano\n", VERSION); fprintf(stderr, " This program may be freely distributed\n"); usage(); default: usage(); break; } } if (optind != argc - 2 && optind != argc) usage(); readunits(userfile); if (optind == argc - 2) { strlcpy(havestr, argv[optind], sizeof(havestr)); strlcpy(wantstr, argv[optind + 1], sizeof(wantstr)); initializeunit(&have); addunit(&have, havestr, 0, 1); completereduce(&have); initializeunit(&want); addunit(&want, wantstr, 0, 1); completereduce(&want); showanswer(&have, &want); } else { if (!quiet) printf("%d units, %d prefixes\n", unitcount, prefixcount); for (;;) { do { initializeunit(&have); if (!quiet) printf("You have: "); if (!fgets(havestr, sizeof(havestr), stdin)) { if (!quiet) putchar('\n'); exit(0); } } while (addunit(&have, havestr, 0, 1) || completereduce(&have)); do { initializeunit(&want); if (!quiet) printf("You want: "); if (!fgets(wantstr, sizeof(wantstr), stdin)) { if (!quiet) putchar('\n'); exit(0); } } while (addunit(&want, wantstr, 0, 1) || completereduce(&want)); showanswer(&have, &want); } } return(0); }
int main(int argc, char **argv) { struct unittype have, want; char havestr[81], wantstr[81]; int optchar; const char *userfile = 0; int list = 0, listexpand = 0; int quiet = 0; while ((optchar = getopt(argc, argv, "lLvqf:")) != -1) { switch (optchar) { case 'l': list = 1; break; case 'L': list = 1; listexpand = 1; precision = DBL_DIG; break; case 'f': userfile = optarg; break; case 'q': quiet = 1; break; case 'v': fprintf(stderr, "\n units version %s Copyright (c) 1993 by Adrian Mariano\n", VERSION); fprintf(stderr, " This program may be freely distributed\n"); usage(); default: usage(); break; } } argc -= optind; argv += optind; if ((argc != 3 && argc != 2 && argc != 0) || (list && argc != 0)) usage(); if (list) errprefix = "/ "; /* set this before reading the file */ readunits(userfile); if (list) return listunits(listexpand); if (argc == 3) { strlcpy(havestr, argv[0], sizeof(havestr)); strlcat(havestr, " ", sizeof(havestr)); strlcat(havestr, argv[1], sizeof(havestr)); argc--; argv++; argv[0] = havestr; } if (argc == 2) { strlcpy(havestr, argv[0], sizeof(havestr)); strlcpy(wantstr, argv[1], sizeof(wantstr)); initializeunit(&have); addunit(&have, havestr, 0); completereduce(&have); initializeunit(&want); addunit(&want, wantstr, 0); completereduce(&want); showanswer(&have, &want); } else { if (!quiet) printf("%d units, %d prefixes\n\n", unitcount, prefixcount); for (;;) { do { initializeunit(&have); if (!quiet) printf("You have: "); if (!fgets(havestr, 80, stdin)) { if (!quiet) putchar('\n'); exit(0); } } while (addunit(&have, havestr, 0) || completereduce(&have)); do { initializeunit(&want); if (!quiet) printf("You want: "); if (!fgets(wantstr, 80, stdin)) { if (!quiet) putchar('\n'); exit(0); } } while (addunit(&want, wantstr, 0) || completereduce(&want)); showanswer(&have, &want); } } return (0); }
int main(int argc, char **argv) { struct unittype have, want; char havestr[81], wantstr[81]; int optchar; char *userfile = 0; int quiet = 0; extern char *optarg; extern int optind; if (pledge("stdio rpath", NULL) == -1) err(1, "pledge"); while ((optchar = getopt(argc, argv, "vqf:")) != -1) { switch (optchar) { case 'f': userfile = optarg; break; case 'q': quiet = 1; break; case 'v': fprintf(stderr, "units version %s Copyright (c) 1993 by Adrian Mariano\n", VERSION); fprintf(stderr, "This program may be freely distributed\n"); usage(); default: usage(); break; } } argc -= optind; argv += optind; if (argc != 3 && argc != 2 && argc != 0) usage(); readunits(userfile); if (pledge("stdio", NULL) == -1) err(1, "pledge"); if (argc == 3) { strlcpy(havestr, argv[0], sizeof(havestr)); strlcat(havestr, " ", sizeof(havestr)); strlcat(havestr, argv[1], sizeof(havestr)); argc--; argv++; argv[0] = havestr; } if (argc == 2) { strlcpy(havestr, argv[0], sizeof(havestr)); strlcpy(wantstr, argv[1], sizeof(wantstr)); initializeunit(&have); addunit(&have, havestr, 0); completereduce(&have); initializeunit(&want); addunit(&want, wantstr, 0); completereduce(&want); showanswer(&have, &want); } else { if (!quiet) printf("%d units, %d prefixes\n", unitcount, prefixcount); for (;;) { do { initializeunit(&have); if (!quiet) printf("You have: "); if (!fgets(havestr, sizeof(havestr), stdin)) { if (!quiet) putchar('\n'); exit(0); } } while (addunit(&have, havestr, 0) || completereduce(&have)); do { initializeunit(&want); if (!quiet) printf("You want: "); if (!fgets(wantstr, sizeof(wantstr), stdin)) { if (!quiet) putchar('\n'); exit(0); } } while (addunit(&want, wantstr, 0) || completereduce(&want)); showanswer(&have, &want); } } return (0); }