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

Diff for /src/usr.bin/tip/Attic/value.c between version 1.30 and 1.31

version 1.30, 2010/07/02 07:40:03 version 1.31, 2010/07/02 07:55:00
Line 78 
Line 78 
         { NULL,           0,                    NULL,    NULL, 0 },          { NULL,           0,                    NULL,    NULL, 0 },
 };  };
   
 #define MIDDLE  35  
   
 static int      vlookup(char *);  static int      vlookup(char *);
 static void     vtoken(char *);  static void     vtoken(char *);
 static void     vprint(value_t *);  static size_t   vprint(value_t *);
   static void     vprintall(void);
 static char    *vinterp(char *, int);  static char    *vinterp(char *, int);
   
 static size_t col = 0;  
   
 /* Get a string value. */  /* Get a string value. */
 char *  char *
 vgetstr(int value)  vgetstr(int value)
Line 150 
Line 147 
         vp->v_number = number;          vp->v_number = number;
 }  }
   
   /* Print a single variable and its value. */
   static size_t
   vprint(value_t *p)
   {
           char    *cp;
           size_t   width;
   
           width = size(p->v_name);
           switch (p->v_flags & V_TYPEMASK) {
           case V_BOOL:
                   if (!p->v_number) {
                           width++;
                           putchar('!');
                   }
                   printf("%s", p->v_name);
                   break;
           case V_STRING:
                   printf("%s=", p->v_name);
                   width++;
                   if (p->v_string) {
                           cp = interp(p->v_string);
                           width += size(cp);
                           printf("%s", cp);
                   }
                   break;
           case V_NUMBER:
                   width += 6;
                   printf("%s=%-5d", p->v_name, p->v_number);
                   break;
           case V_CHAR:
                   printf("%s=", p->v_name);
                   width++;
                   if (p->v_number) {
                           cp = ctrl(p->v_number);
                           width += size(cp);
                           printf("%s", cp);
                   }
                   break;
           }
           return (width);
   }
   
   /* Print all variables. */
   static void
   vprintall(void)
   {
           value_t *vp;
           size_t   width;
   
   #define MIDDLE 35
           width = 0;
           for (vp = vtable; vp->v_name; vp++) {
                   if (vp->v_flags & V_READONLY)
                           continue;
                   if (width > 0 && width < MIDDLE) {
                           while (width++ < MIDDLE)
                                   putchar(' ');
                   }
                   width += vprint(vp);
                   if (width > MIDDLE) {
                           printf("\r\n");
                           width = 0;
                   }
           }
   #undef MIDDLE
   }
   
 /* Find index of variable by name or abbreviation. */  /* Find index of variable by name or abbreviation. */
 static int  static int
 vlookup(char *s)  vlookup(char *s)
Line 230 
Line 294 
         value_t *p;          value_t *p;
         char *cp;          char *cp;
   
         if (strcmp(s, "all") == 0) {          if (strcmp(s, "all") == 0)
                 for (p = vtable; p->v_name; p++)                  vprintall();
                         vprint(p);          else {
         } else {  
                 do {                  do {
                         if ((cp = vinterp(s, ' ')))                          if ((cp = vinterp(s, ' ')))
                                 cp++;                                  cp++;
Line 241 
Line 304 
                         s = cp;                          s = cp;
                 } while (s);                  } while (s);
         }          }
         if (col > 0) {  
                 printf("\r\n");  
                 col = 0;  
         }  
 }  }
   
 /* Set a variable from a token. */  /* Set a variable from a token. */
Line 293 
Line 352 
         } else if ((cp = strchr(s, '?'))) {          } else if ((cp = strchr(s, '?'))) {
                 *cp = '\0';                  *cp = '\0';
                 if ((i = vlookup(s)) != -1) {                  if ((i = vlookup(s)) != -1) {
                         vprint(&vtable[i]);                          if (vprint(&vtable[i]) > 0)
                                   printf("\r\n");
                         return;                          return;
                 }                  }
         } else {          } else {
Line 317 
Line 377 
                 }                  }
         }          }
         printf("%s: unknown variable\r\n", s);          printf("%s: unknown variable\r\n", s);
 }  
   
 static void  
 vprint(value_t *p)  
 {  
         char *cp;  
   
         if (col > 0 && col < MIDDLE)  
                 while (col++ < MIDDLE)  
                         putchar(' ');  
         col += size(p->v_name);  
         switch (p->v_flags & V_TYPEMASK) {  
   
         case V_BOOL:  
                 if (!p->v_number) {  
                         col++;  
                         putchar('!');  
                 }  
                 printf("%s", p->v_name);  
                 break;  
   
         case V_STRING:  
                 printf("%s=", p->v_name);  
                 col++;  
                 if (p->v_string) {  
                         cp = interp(p->v_string);  
                         col += size(cp);  
                         printf("%s", cp);  
                 }  
                 break;  
   
         case V_NUMBER:  
                 col += 6;  
                 printf("%s=%-5d", p->v_name, p->v_number);  
                 break;  
   
         case V_CHAR:  
                 printf("%s=", p->v_name);  
                 col++;  
                 if (p->v_number) {  
                         cp = ctrl(p->v_number);  
                         col += size(cp);  
                         printf("%s", cp);  
                 }  
                 break;  
         }  
         if (col >= MIDDLE) {  
                 col = 0;  
                 printf("\r\n");  
                 return;  
         }  
 }  }
   
 static char *  static char *

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31