=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tput/tput.c,v retrieving revision 1.6 retrieving revision 1.7 diff -c -r1.6 -r1.7 *** src/usr.bin/tput/tput.c 1999/03/06 20:19:22 1.6 --- src/usr.bin/tput/tput.c 1999/03/06 20:27:42 1.7 *************** *** 1,4 **** ! /* $OpenBSD: tput.c,v 1.6 1999/03/06 20:19:22 millert Exp $ */ /* $NetBSD: tput.c,v 1.8 1995/08/31 22:11:37 jtc Exp $ */ /*- --- 1,4 ---- ! /* $OpenBSD: tput.c,v 1.7 1999/03/06 20:27:42 millert Exp $ */ /* $NetBSD: tput.c,v 1.8 1995/08/31 22:11:37 jtc Exp $ */ /*- *************** *** 44,57 **** #if 0 static char sccsid[] = "@(#)tput.c 8.3 (Berkeley) 4/28/95"; #endif ! static char rcsid[] = "$OpenBSD: tput.c,v 1.6 1999/03/06 20:19:22 millert Exp $"; #endif /* not lint */ #include #include #include - #include #include #include #include --- 44,56 ---- #if 0 static char sccsid[] = "@(#)tput.c 8.3 (Berkeley) 4/28/95"; #endif ! static char rcsid[] = "$OpenBSD: tput.c,v 1.7 1999/03/06 20:27:42 millert Exp $"; #endif /* not lint */ #include #include #include #include #include #include *************** *** 59,159 **** static void prlongname __P((char *)); static void setospeed __P((void)); static void usage __P((void)); static char **process __P((char *, char *, char **)); - extern char *__progname; - int main(argc, argv) int argc; char **argv; { ! int ch, exitval, n, Sflag = 0; ! size_t len; ! char *p, *term, *str; term = NULL; ! while ((ch = getopt(argc, argv, "ST:")) != -1) switch(ch) { case 'T': term = optarg; break; - case 'S': - Sflag = 1; - break; case '?': default: usage(); } argc -= optind; argv += optind; - if (Sflag && argc > 0) - usage(); if (!term && !(term = getenv("TERM"))) errx(2, "no terminal type specified and no TERM environmental variable."); ! if (setupterm(term, STDOUT_FILENO, NULL) == ERR) ! err(2, "setupterm failure"); setospeed(); ! if (strcmp(__progname, "clear") == 0) { ! if (Sflag) ! usage(); *argv = "clear"; *(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) { switch (*p) { case 'i': if (!strcmp(p, "init")) ! p = "is2"; /* XXX - is1 as well? */ break; case 'l': if (!strcmp(p, "longname")) { ! prlongname(CUR term_names); continue; } break; case 'r': if (!strcmp(p, "reset")) ! p = "rs2"; /* XXX - rs1 as well? */ break; } ! /* XXX - check termcap names too */ ! if ((str = tigetstr(p)) != NULL && str != (char *)-1) ! argv = process(p, str, argv); ! else if ((n = tigetnum(p)) != -1 && n != -2) (void)printf("%d\n", n); else ! exitval = (tigetflag(p) == -1); if (argv == NULL) break; --- 58,132 ---- 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) int argc; char **argv; { ! extern char *optarg; ! extern int optind; ! int ch, exitval, n; ! char *argv0, *cptr, *p, *term, buf[1024], tbuf[1024]; term = NULL; ! while ((ch = getopt(argc, argv, "T:")) != -1) switch(ch) { case 'T': term = optarg; break; case '?': default: usage(); } + if ((argv0 = (char *)strrchr(argv[0], '/')) != NULL) + argv0++; + else + argv0 = argv[0]; argc -= optind; argv += optind; if (!term && !(term = getenv("TERM"))) errx(2, "no terminal type specified and no TERM environmental variable."); ! if (tgetent(tbuf, term) != 1) ! err(2, "tgetent failure"); setospeed(); ! if (strcmp(argv0, "clear") == 0) { *argv = "clear"; *(argv+1) = NULL; } for (exitval = 0; (p = *argv) != NULL; ++argv) { switch (*p) { + case 'c': + if (!strcmp(p, "clear")) + p = "cl"; + break; case 'i': if (!strcmp(p, "init")) ! p = "is"; break; case 'l': if (!strcmp(p, "longname")) { ! prlongname(tbuf); continue; } break; case 'r': if (!strcmp(p, "reset")) ! p = "rs"; break; } ! cptr = buf; ! if (tgetstr(p, &cptr)) ! argv = process(p, buf, argv); ! else if ((n = tgetnum(p)) != -1) (void)printf("%d\n", n); else ! exitval = !tgetflag(p); if (argv == NULL) break; *************** *** 211,217 **** break; default: /* ! * HP-UX has lots of them, but we complain */ errx(2, erresc, *cp, cap); } --- 184,190 ---- break; default: /* ! * hpux has lot's of them, but we complain */ errx(2, erresc, *cp, cap); } *************** *** 219,225 **** /* And print them. */ switch (arg_need) { case 0: ! (void)putp(str); break; case 1: arg_cols = 0; --- 192,198 ---- /* And print them. */ switch (arg_need) { case 0: ! (void)tputs(str, 1, outc); break; case 1: arg_cols = 0; *************** *** 228,234 **** errx(2, errfew, 1, cap); arg_rows = atoi(*argv); ! (void)putp(tparm(str, arg_cols, arg_rows)); break; case 2: if (*++argv == NULL || *argv[0] == '\0') --- 201,207 ---- errx(2, errfew, 1, cap); arg_rows = atoi(*argv); ! (void)tputs(tgoto(str, arg_cols, arg_rows), 1, outc); break; case 2: if (*++argv == NULL || *argv[0] == '\0') *************** *** 239,245 **** errx(2, errfew, 2, cap); arg_cols = atoi(*argv); ! (void) tputs(tparm(str, arg_cols, arg_rows), arg_rows, putchar); break; default: --- 212,218 ---- errx(2, errfew, 2, cap); arg_cols = atoi(*argv); ! (void) tputs(tgoto(str, arg_cols, arg_rows), arg_rows, outc); break; default: *************** *** 262,271 **** } static void usage() { ! (void)fprintf(stderr, ! "usage: %s [-T term] attribute [attribute-args] ...\n" ! " %s [-T term] -S\n", __progname, __progname); exit(1); } --- 235,249 ---- } static void + outc(c) + int c; + { + (void)putchar(c); + } + + static void usage() { ! (void)fprintf(stderr, "usage: tput [-T term] attribute ...\n"); exit(1); }