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

Diff for /src/usr.bin/tput/tput.c between version 1.27 and 1.28

version 1.27, 2023/02/03 15:55:59 version 1.28, 2023/02/08 15:56:32
Line 44 
Line 44 
  * SUCH DAMAGE.   * SUCH DAMAGE.
  */   */
   
   #include <sys/wait.h>
 #include <ctype.h>  #include <ctype.h>
 #include <err.h>  #include <err.h>
 #include <curses.h>  #include <curses.h>
 #include <term.h>  #include <term.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <termios.h>  
 #include <unistd.h>  #include <unistd.h>
 #include <errno.h>  #include <errno.h>
 #include <limits.h>  #include <limits.h>
Line 58 
Line 58 
   
 #define MAXIMUM(a, b)   (((a) > (b)) ? (a) : (b))  #define MAXIMUM(a, b)   (((a) > (b)) ? (a) : (b))
   
 #include <sys/wait.h>  #define NUM_PARM        9       /* must match tic.h */
   
 static void   init(void);  static void   init(void);
 static char **process(char *, char *, char **);  static char **process(char *, char *, char **);
Line 67 
Line 67 
 static void   usage(void);  static void   usage(void);
   
 extern char  *__progname;  extern char  *__progname;
   extern int _nc_tparm_analyze(const char *string, char *p_is_s[NUM_PARM], int *popcount);
   
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
Line 192 
Line 193 
 static char **  static char **
 process(char *cap, char *str, char **argv)  process(char *cap, char *str, char **argv)
 {  {
         char *cp, *s, *nargv[9] = {0};          char *cp, *s, *nargv[NUM_PARM] = {0};
         int arg_need, popcount, i;          char *p_is_s[NUM_PARM];
           int arg_need, i;
   
         /* Count how many values we need for this capability. */          /* Count how many values we need for this capability. */
         for (cp = str, arg_need = popcount = 0; *cp != '\0'; cp++) {          i = _nc_tparm_analyze(str, p_is_s, &arg_need);
                 if (*cp == '%') {          if (arg_need == 0)
                         switch (*++cp) {                  arg_need = i;
                         case '%':          if (arg_need > NUM_PARM)
                                 cp++;  
                                 break;  
                         case 'i':  
                                 if (popcount < 2)  
                                         popcount = 2;  
                                 break;  
                         case 'p':  
                                 cp++;  
                                 if (isdigit((unsigned char)cp[1]) &&  
                                     popcount < cp[1] - '0')  
                                         popcount = cp[1] - '0';  
                                 break;  
                         case 'd':  
                         case 's':  
                         case '0':  
                         case '1':  
                         case '2':  
                         case '3':  
                         case '4':  
                         case '5':  
                         case '6':  
                         case '7':  
                         case '8':  
                         case '9':  
                         case '.':  
                         case '+':  
                                 arg_need++;  
                                 break;  
                         default:  
                                 break;  
                         }  
                 }  
         }  
         arg_need = MAXIMUM(arg_need, popcount);  
         if (arg_need > 9)  
                 errx(2, "too many arguments (%d) for capability `%s'",                  errx(2, "too many arguments (%d) for capability `%s'",
                     arg_need, cap);                      arg_need, cap);
   
         for (i = 0; i < arg_need; i++) {          for (i = 0; i < arg_need; i++) {
                   const char *errstr;
                 long l;                  long l;
   
                 if (argv[i] == NULL)                  if (argv[i] == NULL)
                         errx(2, "not enough arguments (%d) for capability `%s'",                          errx(2, "not enough arguments (%d) for capability `%s'",
                             arg_need, cap);                              arg_need, cap);
   
                 /* convert ascii representation of numbers to longs */                  if (p_is_s[i] != 0) {
                 if (isdigit((unsigned char)argv[i][0])  
                     && (l = strtol(argv[i], &cp, 10)) >= 0  
                     && l < LONG_MAX && *cp == '\0')  
                         nargv[i] = (char *)l;  
                 else  
                         nargv[i] = argv[i];                          nargv[i] = argv[i];
                   } else {
                           /* convert ascii representation of numbers to longs */
                           l = strtonum(argv[i], LONG_MIN, LONG_MAX, &errstr);
                           if (errstr != NULL)
                                   errx(2, "capability `%s' is %s", cap, errstr);
                           nargv[i] = (char *)l;
                   }
         }          }
   
         s = tparm(str, nargv[0], nargv[1], nargv[2], nargv[3],          s = tparm(str, nargv[0], nargv[1], nargv[2], nargv[3],

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28