Xref: utzoo comp.sources.wanted:5575 comp.sources.d:2943 Path: utzoo!attcan!uunet!wyse!vsi1!ames!mailrus!purdue!i.cc.purdue.edu!j.cc.purdue.edu!mace.cc.purdue.edu!dls From: dls@mace.cc.purdue.edu (David L Stevens) Newsgroups: comp.sources.wanted,comp.sources.d Subject: Re: using curses from a script? Message-ID: <1145@mace.cc.purdue.edu> Date: 17 Nov 88 17:39:32 GMT References: <7668@well.UUCP> Reply-To: dls@mace.cc.purdue.edu (David L Stevens) Organization: PUCC UNIX Group Lines: 123 This is something I wrote a few years ago that does most termcap things. We have newer versions and a tgoto that need some work, but this gives you most of what you want, I believe. <<<<<<< begin term.c /* * Copyright (c) 1986, David L Stevens. * Distribution unlimited, with inclusion of this copyright notice. */ #include char *scap[] = { "ae", "al", "as", "bc", "bt", "CC", "cd", "ce", "ch", "cl", "cm", "cr", "cs", "cv", "dc", "dl", "dm", "do", "ed", "ei", "eo", "ff", "hd", "ho", "hu", "hz", "ic", "if", "ip", "is", "kb", "kd", "ke", "kh", "kl", "ko", "kr", "ks", "ku", "ll", "ma", "ml", "mu", "nd", "nl", "pc", "se", "sf", "so", "sr", "ta", "tc", "te", "ti", "uc", "ue", "up", "us", "vb", "ve", "vs", 0 }; char *ncap[] = { "co", "db", "dc", "df", "dn", "dt", "kn", "li", "ug", 0 }; char *fcap[] = { "am", "bw", "da", "db", "hc", "im", "in", "ms", "nc", "ns", "os", "pt", "ul", "xb", "xn", "xr", "xs", "xt", 0 }; #define IsFlag(s) IsCap(s, fcap) #define IsNumber(s) IsCap(s, ncap) #define IsString(s) IsCap(s, scap) main(argc, argv) int argc; char *argv[]; { char tbuf[1024], buf[1024], *bp = buf; char *term; int an, rv; char *sv, *getenv(), *tgetstr(); int eflag; term = getenv("TERM"); if (term == NULL) { fprintf(stderr, "term: Terminal type not specified.\n"); exit(1); } rv = tgetent(&tbuf[0], term); switch (rv) { case -1: fprintf(stderr, "term: Can't open termcap.\n"); exit(1); case 0: fprintf(stderr, "term: no termcap entry for \"%s\"\n", term); exit(1); case 1: break; default: fprintf(stderr, "term: termcap error-- tgetent returned %d\n", rv); exit(1); } eflag = 0; for (an = 1; an < argc; an++) { char *stmp; stmp = argv[an]; if (IsString(stmp)) { sv = tgetstr(stmp, &bp); if (sv == NULL) { fprintf(stderr, "term: No \"%s\" defined for %s\n", stmp, term); eflag++; continue; } fprintf(stdout, "%s", sv); } else if (IsNumber(stmp)) { rv = tgetnum(stmp); if (rv == -1) { fprintf(stderr, "term: No \"%s\" defined for %s\n", stmp, term); eflag++; continue; } fprintf(stdout, "%d", rv); } else if (IsFlag(stmp)) { fprintf(stdout, "%d", tgetflag(stmp)); } else { fprintf(stderr, "term: Unknown capability, \"%s\"\n", stmp); eflag++; continue; } } exit(eflag != 0); } IsCap(s, cap) char *s; char *cap[]; { char **tc; tc = &cap[0]; while (*tc != 0) { if (strcmp(*tc, s) == 0) { return 1; } tc++; } return 0; } >>>>>>> end term.c -- +-DLS (dls@mace.cc.purdue.edu)