[BACK]Return to units.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / units

Diff for /src/usr.bin/units/units.c between version 1.3 and 1.4

version 1.3, 1996/06/26 05:42:15 version 1.4, 1996/08/11 00:17:31
Line 59 
Line 59 
   
 char *NULLUNIT = "";  char *NULLUNIT = "";
   
   #ifdef DOS
   #define SEPERATOR       ";"
   #else
   #define SEPERATOR       ":"
   #endif
   
 int unitcount;  int unitcount;
 int prefixcount;  int prefixcount;
   
Line 103 
Line 109 
                             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, "");
Line 152 
Line 153 
                         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;
                         }                          }
Line 160 
Line 162 
                         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;
                                 }                                  }
Line 176 
Line 179 
                 }                  }
                 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;
                                 }                                  }
Line 618 
Line 623 
 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);
Line 648 
Line 653 
                         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();
Line 676 
Line 683 
         }          }
         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 {
Line 684 
Line 691 
                                 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) ||
Line 704 
Line 711 
                         showanswer(&have, &want);                          showanswer(&have, &want);
                 }                  }
         }          }
           return (0);
 }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4