[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.6 and 1.7

version 1.6, 1999/06/13 16:34:21 version 1.7, 2001/01/17 19:29:49
Line 43 
Line 43 
 struct {  struct {
         char *uname;          char *uname;
         char *uval;          char *uval;
 }      unittable[MAXUNITS];  } unittable[MAXUNITS];
   
 struct unittype {  struct unittype {
         char *numerator[MAXSUBUNITS];          char *numerator[MAXSUBUNITS];
Line 54 
Line 54 
 struct {  struct {
         char *prefixname;          char *prefixname;
         char *prefixval;          char *prefixval;
 }      prefixtable[MAXPREFIXES];  } prefixtable[MAXPREFIXES];
   
   
 char *NULLUNIT = "";  char *NULLUNIT = "";
Line 74 
Line 74 
 {  {
         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);
 }  }
   
Line 443 
Line 442 
                 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;
                         }                          }
Line 456 
Line 454 
                 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;
                         }                          }
Line 466 
Line 463 
                         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;
                                 }                                  }
Line 669 
Line 665 
         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);

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7