Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/usr.bin/tput/tput.c between versions 1.2 and 1.3

version 1.2, 1993/08/01 18:04:38 version 1.3, 1994/01/24 23:54:57
Line 45  static char rcsid[] = "$Id$"; Line 45  static char rcsid[] = "$Id$";
 #include <sys/termios.h>  #include <sys/termios.h>
 #include <stdio.h>  #include <stdio.h>
 #include <unistd.h>  #include <unistd.h>
   #include <stdlib.h>
   #include <curses.h>
   
   static void   prlongname __P((char *));
   static void   setospeed __P((void));
   static void   outc       __P((int));
   static void   usage __P((void));
   static char **process __P((char *, char *, char **));
   
   int
 main(argc, argv)  main(argc, argv)
         int argc;          int argc;
         char **argv;          char **argv;
 {  {
         extern char *optarg;          extern char *optarg;
         extern int optind;          extern int optind;
         int ch, exitval, n, outc();          int ch, exitval, n;
         char *cptr, *p, *term, buf[1024], tbuf[1024];          char *cptr, *p, *term, buf[1024], tbuf[1024];
         char *getenv(), *tgetstr(), *realname();  
   
         term = NULL;          term = NULL;
         while ((ch = getopt(argc, argv, "T:")) != EOF)          while ((ch = getopt(argc, argv, "T:")) != EOF)
Line 78  main(argc, argv) Line 86  main(argc, argv)
                 exit(2);                  exit(2);
         }          }
         setospeed();          setospeed();
         for (cptr = buf, exitval = 0; p = *argv; ++argv) {          for (exitval = 0; (p = *argv) != NULL; ++argv) {
                 switch(*p) {                  switch(*p) {
                 case 'c':                  case 'c':
                         if (!strcmp(p, "clear"))                          if (!strcmp(p, "clear"))
Line 97  main(argc, argv) Line 105  main(argc, argv)
                                 p = "rs";                                  p = "rs";
                         break;                          break;
                 }                  }
                   cptr = buf;
                 if (tgetstr(p, &cptr))                  if (tgetstr(p, &cptr))
                         (void)tputs(buf, 1, outc);                          argv = process(p, buf, argv);
                 else if ((n = tgetnum(p)) != -1)                  else if ((n = tgetnum(p)) != -1)
                         (void)printf("%d\n", n);                          (void)printf("%d\n", n);
                 else                  else
                         exitval = !tgetflag(p);                          exitval = !tgetflag(p);
   
                   if (argv == NULL)
                           break;
         }          }
         exit(exitval);          exit(argv ? exitval : 2);
 }  }
   
   static void
 prlongname(buf)  prlongname(buf)
         char *buf;          char *buf;
 {  {
Line 114  prlongname(buf) Line 127  prlongname(buf)
         int savech;          int savech;
         char *savep;          char *savep;
   
         for (p = buf; *p && *p != ':'; ++p);          for (p = buf; *p && *p != ':'; ++p)
                   continue;
         savech = *(savep = p);          savech = *(savep = p);
         for (*p = '\0'; p >= buf && *p != '|'; --p);          for (*p = '\0'; p >= buf && *p != '|'; --p)
                   continue;
         (void)printf("%s\n", p + 1);          (void)printf("%s\n", p + 1);
         *savep = savech;          *savep = savech;
 }  }
   
   static void
 setospeed()  setospeed()
 {  {
         extern int errno, ospeed;  #undef ospeed
           extern short ospeed;
         struct termios t;          struct termios t;
         char *strerror();  
   
         if (tcgetattr(STDOUT_FILENO, &t) != -1)          if (tcgetattr(STDOUT_FILENO, &t) != -1)
                 ospeed = 0;                  ospeed = 0;
Line 133  setospeed() Line 149  setospeed()
                 ospeed = cfgetospeed(&t);                  ospeed = cfgetospeed(&t);
 }  }
   
   static void
 outc(c)  outc(c)
         int c;          int c;
 {  {
         putchar(c);          putchar(c);
 }  }
   
   static void
 usage()  usage()
 {  {
         (void)fprintf(stderr, "usage: tput [-T term] attribute ...\n");          (void)fprintf(stderr, "usage: tput [-T term] attribute ...\n");
         exit(1);          exit(1);
 }  }
   
   static char **
   process(cap, str, argv)
           char *cap;
           char *str;
           char **argv;
   {
           static char errfew[] =
                    "tput: Not enough arguments (%d) for capability `%s'\n";
           static char errmany[] =
                    "tput: Too many arguments (%d) for capability `%s'\n";
           static char erresc[] =
                    "tput: Unknown %% escape `%c' for capability `%s'\n";
           /*
            * Count home many values we need for this capability.
            */
           char *cp;
           int arg_need, arg_rows, arg_cols;
           for (cp = str, arg_need = 0; *cp; cp++)
                   if (*cp == '%')
                               switch (*++cp) {
                               case 'd':
                               case '2':
                               case '3':
                               case '.':
                               case '+':
                                       arg_need++;
                                       break;
   
                               case '%':
                               case '>':
                               case 'i':
                               case 'r':
                               case 'n':
                               case 'B':
                               case 'D':
                                       break;
   
                               default:
                                   /*
                                    * hpux has lot's of them, but we complain
                                    */
                                   (void)fprintf(stderr, erresc, *cp, cap);
                                   return NULL;
                               }
   
           /*
            * And print them
            */
           switch (arg_need) {
           case 0:
                   (void) tputs(str, 1, outc);
                   break;
   
           case 1:
                   arg_cols = 0;
   
                   argv++;
                   if (!*argv || *argv[0] == '\0') {
                           (void)fprintf(stderr, errfew, 1, cap);
                           return NULL;
                   }
                   arg_rows = atoi(*argv);
   
                   (void)tputs(tgoto(str, arg_cols, arg_rows), 1, outc);
                   break;
   
           case 2:
                   argv++;
                   if (!*argv || *argv[0] == '\0') {
                           (void)fprintf(stderr, errfew, 2, cap);
                           return NULL;
                   }
                   arg_cols = atoi(*argv);
   
                   argv++;
                   if (!*argv || *argv[0] == '\0') {
                           (void)fprintf(stderr, errfew, 2, cap);
                           return NULL;
                   }
                   arg_rows = atoi(*argv);
   
                   (void) tputs(tgoto(str, arg_cols, arg_rows), arg_rows, outc);
                   break;
   
           default:
                   (void)fprintf(stderr, errmany, arg_need, cap);
                   return NULL;
           }
           return argv;
   }

Removed from v.1.2  
changed lines
  Added in v.1.3


CVSweb <webmaster@jp.NetBSD.org>