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

version 1.6, 1999/03/06 20:19:22 version 1.7, 1999/03/06 20:27:42
Line 51 
Line 51 
   
 #include <err.h>  #include <err.h>
 #include <curses.h>  #include <curses.h>
 #include <term.h>  
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <unistd.h>  #include <unistd.h>
Line 59 
Line 58 
   
 static void   prlongname __P((char *));  static void   prlongname __P((char *));
 static void   setospeed __P((void));  static void   setospeed __P((void));
   static void   outc __P((int));
 static void   usage __P((void));  static void   usage __P((void));
 static char **process __P((char *, char *, char **));  static char **process __P((char *, char *, char **));
   
 extern char  *__progname;  
   
 int  int
 main(argc, argv)  main(argc, argv)
         int argc;          int argc;
         char **argv;          char **argv;
 {  {
         int ch, exitval, n, Sflag = 0;          extern char *optarg;
         size_t len;          extern int optind;
         char *p, *term, *str;          int ch, exitval, n;
           char *argv0, *cptr, *p, *term, buf[1024], tbuf[1024];
   
         term = NULL;          term = NULL;
         while ((ch = getopt(argc, argv, "ST:")) != -1)          while ((ch = getopt(argc, argv, "T:")) != -1)
                 switch(ch) {                  switch(ch) {
                 case 'T':                  case 'T':
                         term = optarg;                          term = optarg;
                         break;                          break;
                 case 'S':  
                         Sflag = 1;  
                         break;  
                 case '?':                  case '?':
                 default:                  default:
                         usage();                          usage();
                 }                  }
           if ((argv0 = (char *)strrchr(argv[0], '/')) != NULL)
                   argv0++;
           else
                   argv0 = argv[0];
         argc -= optind;          argc -= optind;
         argv += optind;          argv += optind;
   
         if (Sflag && argc > 0)  
                 usage();  
   
         if (!term && !(term = getenv("TERM")))          if (!term && !(term = getenv("TERM")))
 errx(2, "no terminal type specified and no TERM environmental variable.");  errx(2, "no terminal type specified and no TERM environmental variable.");
         if (setupterm(term, STDOUT_FILENO, NULL) == ERR)          if (tgetent(tbuf, term) != 1)
                 err(2, "setupterm failure");                  err(2, "tgetent failure");
         setospeed();          setospeed();
         if (strcmp(__progname, "clear") == 0) {          if (strcmp(argv0, "clear") == 0) {
                 if (Sflag)  
                         usage();  
                 *argv = "clear";                  *argv = "clear";
                 *(argv+1) = NULL;                  *(argv+1) = NULL;
         }          }
         if (Sflag) {  
                 char **av;  
   
                 /* Build new argv based on stdin */  
                 argc = n = 0;  
                 av = NULL;  
                 while ((str = fgetln(stdin, &len)) != NULL) {  
                         if (str[len-1] != '\n')  
                                 errx(1, "premature EOF");  
                         str[len-1] = '\0';  
                         /* grow av as needed */  
                         if (argc + 1 >= n) {  
                                 n += 64;  
                                 av = (char **)realloc(av, sizeof(char *) * n);  
                                 if (av == NULL)  
                                         errx(1, "out of memory");  
                                 av = &av[argc];  
                         }  
                         while ((p = strsep(&str, " \t")) != NULL)  
                                 if ((av[argc++] = strdup(p)) == NULL)  
                                         errx(1, "out of memory");  
                 }  
                 if (argc > 0) {  
                         av[argc] = NULL;  
                         argv = av;  
                 }  
         }  
         for (exitval = 0; (p = *argv) != NULL; ++argv) {          for (exitval = 0; (p = *argv) != NULL; ++argv) {
                 switch (*p) {                  switch (*p) {
                   case 'c':
                           if (!strcmp(p, "clear"))
                                   p = "cl";
                           break;
                 case 'i':                  case 'i':
                         if (!strcmp(p, "init"))                          if (!strcmp(p, "init"))
                                 p = "is2";      /* XXX - is1 as well? */                                  p = "is";
                         break;                          break;
                 case 'l':                  case 'l':
                         if (!strcmp(p, "longname")) {                          if (!strcmp(p, "longname")) {
                                 prlongname(CUR term_names);                                  prlongname(tbuf);
                                 continue;                                  continue;
                         }                          }
                         break;                          break;
                 case 'r':                  case 'r':
                         if (!strcmp(p, "reset"))                          if (!strcmp(p, "reset"))
                                 p = "rs2";      /* XXX - rs1 as well? */                                  p = "rs";
                         break;                          break;
                 }                  }
                 /* XXX - check termcap names too */                  cptr = buf;
                 if ((str = tigetstr(p)) != NULL && str != (char *)-1)                  if (tgetstr(p, &cptr))
                         argv = process(p, str, argv);                          argv = process(p, buf, argv);
                 else if ((n = tigetnum(p)) != -1 && n != -2)                  else if ((n = tgetnum(p)) != -1)
                         (void)printf("%d\n", n);                          (void)printf("%d\n", n);
                 else                  else
                         exitval = (tigetflag(p) == -1);                          exitval = !tgetflag(p);
   
                 if (argv == NULL)                  if (argv == NULL)
                         break;                          break;
Line 211 
Line 184 
                                     break;                                      break;
                             default:                              default:
                                 /*                                  /*
                                  * HP-UX has lots of them, but we complain                                   * hpux has lot's of them, but we complain
                                  */                                   */
                                  errx(2, erresc, *cp, cap);                                   errx(2, erresc, *cp, cap);
                             }                              }
Line 219 
Line 192 
         /* And print them. */          /* And print them. */
         switch (arg_need) {          switch (arg_need) {
         case 0:          case 0:
                 (void)putp(str);                  (void)tputs(str, 1, outc);
                 break;                  break;
         case 1:          case 1:
                 arg_cols = 0;                  arg_cols = 0;
Line 228 
Line 201 
                         errx(2, errfew, 1, cap);                          errx(2, errfew, 1, cap);
                 arg_rows = atoi(*argv);                  arg_rows = atoi(*argv);
   
                 (void)putp(tparm(str, arg_cols, arg_rows));                  (void)tputs(tgoto(str, arg_cols, arg_rows), 1, outc);
                 break;                  break;
         case 2:          case 2:
                 if (*++argv == NULL || *argv[0] == '\0')                  if (*++argv == NULL || *argv[0] == '\0')
Line 239 
Line 212 
                         errx(2, errfew, 2, cap);                          errx(2, errfew, 2, cap);
                 arg_cols = atoi(*argv);                  arg_cols = atoi(*argv);
   
                 (void) tputs(tparm(str, arg_cols, arg_rows), arg_rows, putchar);                  (void) tputs(tgoto(str, arg_cols, arg_rows), arg_rows, outc);
                 break;                  break;
   
         default:          default:
Line 262 
Line 235 
 }  }
   
 static void  static void
   outc(c)
           int c;
   {
           (void)putchar(c);
   }
   
   static void
 usage()  usage()
 {  {
         (void)fprintf(stderr,          (void)fprintf(stderr, "usage: tput [-T term] attribute ...\n");
             "usage: %s [-T term] attribute [attribute-args] ...\n"  
             "       %s [-T term] -S\n", __progname, __progname);  
         exit(1);          exit(1);
 }  }

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