From 9e6f124826d79eba63de3059495a6dcd51297556 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Sun, 9 Oct 1994 16:37:35 +0000 Subject: [PATCH] Preparation to split binary away, move caps to TESTS Add some testing bits to TESTS directory --- lib/libmytinfo/Makefile | 17 +- lib/libmytinfo/TESTS/Makefile | 42 ++ lib/libmytinfo/TESTS/caps.c | 173 +++++++ lib/libmytinfo/TESTS/clear.c | 156 ++++++ lib/libmytinfo/TESTS/quit.c | 72 +++ lib/libmytinfo/TESTS/tput.c | 196 ++++++++ lib/libmytinfo/TESTS/tset.c | 919 ++++++++++++++++++++++++++++++++++ lib/libmytinfo/TESTS/ttest.c | 297 +++++++++++ 8 files changed, 1863 insertions(+), 9 deletions(-) create mode 100644 lib/libmytinfo/TESTS/Makefile create mode 100644 lib/libmytinfo/TESTS/caps.c create mode 100644 lib/libmytinfo/TESTS/clear.c create mode 100644 lib/libmytinfo/TESTS/quit.c create mode 100644 lib/libmytinfo/TESTS/tput.c create mode 100644 lib/libmytinfo/TESTS/tset.c create mode 100644 lib/libmytinfo/TESTS/ttest.c diff --git a/lib/libmytinfo/Makefile b/lib/libmytinfo/Makefile index cbcbee3c9395..d60257e77416 100644 --- a/lib/libmytinfo/Makefile +++ b/lib/libmytinfo/Makefile @@ -1,3 +1,6 @@ +# Makefile for libmytinfo +# $Id$ + LIB= mytinfo BINDIR= /usr/bin SRCS= addstr.c binorder.c buildpath.c caplist.c capsort.c compar.c\ @@ -8,14 +11,13 @@ MAN1= tconv.1 MLINKS= tconv.1 tic.1 tconv.1 captoinfo.1 CLEANFILES+= binorder.c caplist.c capsort.c mkbinorder mkcaplist \ mkcapsort mktermhead mkversion readcaps.o term.h* \ - version.c quit.o tconv clear.t* *.test caps tput \ - tset ttest + version.c quit.o tconv CFLAGS+=-Wall CAPS= 1000 -all: $${_LIBS} tconv caps +all: $${_LIBS} tconv beforeinstall: term.h -cmp -s term.h ${DESTDIR}/usr/include/term.h > \ @@ -25,7 +27,7 @@ beforeinstall: term.h afterinstall: $(INSTALL) $(COPY) $(STRIP) -o $(BINOWN) -g $(BINGRP) -m $(BINMODE) \ - tconv caps ${DESTDIR}${BINDIR} + tconv ${DESTDIR}${BINDIR} rm -f ${DESTDIR}${BINDIR}/tic ln ${DESTDIR}${BINDIR}/tconv ${DESTDIR}${BINDIR}/tic rm -f ${DESTDIR}${BINDIR}/captoinfo @@ -65,11 +67,8 @@ mktermhead: mktermhead.c readcaps.o mkcaplist: mkcaplist.c readcaps.o $(CC) $(CFLAGS) $(LDFLAGS) -o mkcaplist ${.CURDIR}/mkcaplist.c readcaps.o -tconv: tconv.c quit.o version.o $${_LIBS} - $(CC) ${CFLAGS} $(LDFLAGS) -L. -o tconv ${.CURDIR}/tconv.c quit.o version.o -l$(LIB) - -caps: caps.c quit.o version.o $${_LIBS} - $(CC) $(CFLAGS) -o caps $(LDFLAGS) -L. ${.CURDIR}/caps.c quit.o version.o -l$(LIB) +tconv: tconv.c quit.o $${_LIBS} + $(CC) ${CFLAGS} $(LDFLAGS) -L. -o tconv ${.CURDIR}/tconv.c quit.o -l$(LIB) .include diff --git a/lib/libmytinfo/TESTS/Makefile b/lib/libmytinfo/TESTS/Makefile new file mode 100644 index 000000000000..eeaa6d241172 --- /dev/null +++ b/lib/libmytinfo/TESTS/Makefile @@ -0,0 +1,42 @@ +# Makefile for libmytinfo tests +# $Id$ + +LIB= mytinfo + +TESTS= ttest tputs.test tparm.test readcaps.test caps clear.tcap \ + clear.tinfo tset tput + +CFLAGS+= -Wall -I${.CURDIR}/.. + +CLEANFILES+= $(TESTS) quit.o + +all: $(TESTS) + +ttest: ttest.c quit.o + $(CC) $(CFLAGS) -o ttest $(LDFLAGS) ${.CURDIR}/ttest.c quit.o -l$(LIB) + +caps: caps.c quit.o + $(CC) $(CFLAGS) -o caps $(LDFLAGS) ${.CURDIR}/caps.c quit.o -l$(LIB) + +tputs.test: ${.CURDIR}/../tputs.c + $(CC) -o tputs.test $(LDFLAGS) $(CFLAGS) -DTEST ${.CURDIR}/../tputs.c -l$(LIB) + +tparm.test: ${.CURDIR}/../tparm.c + $(CC) -o tparm.test $(LDFLAGS) $(CFLAGS) -DTEST ${.CURDIR}/../tparm.c -l$(LIB) + +readcaps.test: ${.CURDIR}/../readcaps.c + $(CC) -o readcaps.test $(LDFLAGS) $(CFLAGS) -DTEST ${.CURDIR}/../readcaps.c -l$(LIB) + +clear.tcap: clear.c + $(CC) $(LDFLAGS) $(CFLAGS) -o clear.tcap ${.CURDIR}/clear.c -l$(LIB) + +clear.tinfo: clear.c + $(CC) $(LDFLAGS) $(CFLAGS) -DUSE_TERMINFO -o clear.tinfo ${.CURDIR}/clear.c -l$(LIB) + +tset: tset.c quit.o + $(CC) $(CFLAGS) $(LDFLAGS) -o tset ${.CURDIR}/tset.c quit.o -l$(LIB) + +tput: tput.c quit.o + $(CC) $(CFLAGS) $(LDFLAGS) -o tput ${.CURDIR}/tput.c quit.o -l$(LIB) + +.include diff --git a/lib/libmytinfo/TESTS/caps.c b/lib/libmytinfo/TESTS/caps.c new file mode 100644 index 000000000000..9d4f00f04acb --- /dev/null +++ b/lib/libmytinfo/TESTS/caps.c @@ -0,0 +1,173 @@ +/* + * caps.c + * + * By Ross Ridge + * Public Domain + * 92/02/01 07:29:45 + * + * caps [-c | -t] [term] + * + * -c use termcap names instead of terminfo variable names + * -t use terminfo capnames instead of variables names + * term name of terminal to use + * + * prints out all the capabilities given the specified terminal. If no + * terminal is given, it is taken from the environment variable TERM. + * + */ + +#define NOTLIB +#include "defs.h" +#include + +const char SCCSid[] = "@(#) mytinfo caps.c 3.2 92/02/01 public domain, By Ross Ridge"; + +/* output a string in a human readable format */ +void +putstr(s) +char *s; { + while(*s != '\0') { + switch(*s) { + case '\n': printf("\\n"); break; + case '\b': printf("\\b"); break; + case '\t': printf("\\t"); break; + case '\r': printf("\\r"); break; + case '\f': printf("\\f"); break; + case ' ': printf("\\s"); break; + case '\177': printf("^?"); break; + case '\200': printf("\\0"); break; + default: + if (*s > 0 && *s < 32) + printf("^%c", *s + 64); + else if (*s < 0) + printf("\\%03o", *s & 0xff); + else + putchar(*s); + break; + } + s++; + } +} + +void +do_cleanup(e) +int e; { + fprintf(stderr, "usage: %s [-c | -t ] [terminal]\n", prg_name); + return; +} + +int +main(argc, argv) +int argc; +char **argv; { + int names = 0; + register int i; + int flag, num; + char *str; + + prg_name = argv[0]; + cleanup = do_cleanup; + + if (argc > 3) + quit(-1, "argument count"); + + if (argc == 1) + setupterm(NULL, 2, (int *) 0); + else if (argc == 2) { + if (argv[1][0] != '-') + setupterm(argv[1], 2, (int *) 0); + else { + if (argv[1][1] == 'c') + names = 2; + else if (argv[1][1] == 't') + names = 1; + else + quit(-1, "unknown switch '%c'", argv[1][1]); + setupterm(NULL, 2, (int *) 0); + } + } else { + if (argv[1][0] != '-') + quit(-1, "bad switch"); + if (argv[1][1] == 'c') + names = 2; + else if (argv[1][1] == 't') + names = 1; + else + quit(-1, "unknown switch '%c'", argv[1][1]); + setupterm(argv[2], 2, (int *) 0); + + } + + fflush(stderr); + fflush(stdout); + printf("\n"); +#ifdef _CUR_TERM + printf("%s: %s\n", cur_term->name, cur_term->name_all); + printf("pad: %d xon: %d termcap: %d\n", + cur_term->pad, cur_term->xon, cur_term->termcap); + printf("true_columns: %d true_lines: %d baudrate: %lu\n", + cur_term->true_columns, cur_term->true_lines, + (unsigned long) cur_term->baudrate); + printf("\n"); +#endif + + printf("Booleans:\n"); + for(i = 0; boolnames[i] != NULL; i++) { +#ifdef _CUR_TERM + flag = cur_term->bools[i]; +#else + flag = tigetflag(boolnames[i]); +#endif + if (flag != -1 && flag != 0) { + switch(names) { + case 0: + printf(" %s\n", boolfnames[i]); + break; + case 1: + printf(" %s\n", boolnames[i]); + break; + case 2: + printf(" %s\n", boolcodes[i]); + break; + } + } + } + + printf("\nNumerics:\n"); + for(i = 0; numnames[i] != NULL; i++) { + num = tigetnum(numnames[i]); + if (num != -2 && num != -1) { + switch(names) { + case 0: + printf(" %-32s: %d\n", numfnames[i], num); + break; + case 1: + printf(" %-5s: %d\n", numnames[i], num); + break; + case 2: + printf(" %-2s: %d\n", numcodes[i], num); + break; + } + } + } + printf("\nStrings:\n"); + for(i = 0; strnames[i] != NULL; i++) { + str = tigetstr(strnames[i]); + if (str != (char *) -1 && str != (char *) 0) { + switch(names) { + case 0: + printf(" %-32s: ", strfnames[i]); + break; + case 1: + printf(" %-5s: ", strnames[i]); + break; + case 2: + printf(" %-2s: ", strcodes[i]); + break; + } + putstr(str); + putchar('\n'); + } + } + return 0; +} diff --git a/lib/libmytinfo/TESTS/clear.c b/lib/libmytinfo/TESTS/clear.c new file mode 100644 index 000000000000..1a4767aa7cf6 --- /dev/null +++ b/lib/libmytinfo/TESTS/clear.c @@ -0,0 +1,156 @@ +/* + * clear.c + * + * By Ross Ridge + * Public Domain + * 92/02/01 07:29:47 + * + * clear + * + * clears the terminal's screen + * + */ + +#include "defs.h" + +const char SCCSid[] = "@(#) mytinfo clear.c 3.2 92/02/01 public domain, By Ross Ridge"; + +#ifndef USE_TERMINFO + +#ifdef USE_SGTTY +#include +#endif +#ifdef USE_TERMIO +#include +#endif +#ifdef USE_TERMIOS +#include +#endif +#ifdef __FreeBSD__ +int tgetent __P((char *, char *)); +int tgetnum __P((char *)); +int tputs __P((char *, int, int (*)(char))); +#endif + +char PC; +short ospeed; + +int +#ifdef USE_PROTOTYPES +putch(char c) +#else +putch(c) +int c; +#endif +{ + return putchar(c); +} + +int +main(argc, argv) +int argc; +char **argv; { +#ifdef USE_PROTOTYPES + char *tgetstr(char *, char **); +#else + char *tgetstr(); +#endif + char *term; + char buf[MAX_BUF]; + char CL[MAX_LINE]; + char *s, *pc; + +#ifdef USE_SGTTY + struct sgttyb tty; + + gtty(1, &tty); + ospeed = tty.sg_ospeed; +#else +#ifdef USE_TERMIO + struct termio tty; + + ioctl(1, TCGETA, &tty); + ospeed = tty.c_cflag & CBAUD; +#else +#ifdef USE_TERMIOS + struct termios tty; + + tcgetattr(1, &tty); + switch(cfgetospeed(&tty)) { + case B0: ospeed = 0; break; + case B50: ospeed = 1; break; + case B75: ospeed = 2; break; + case B110: ospeed = 3; break; + case B134: ospeed = 4; break; + case B150: ospeed = 5; break; + case B200: ospeed = 6; break; + case B300: ospeed = 7; break; + case B600: ospeed = 8; break; + case B1200: ospeed = 9; break; + case B1800: ospeed = 10; break; + case B2400: ospeed = 11; break; + case B4800: ospeed = 12; break; + case B9600: ospeed = 13; break; + case EXTA: ospeed = 14; break; + case EXTB: ospeed = 15; break; +#ifdef B57600 + case B57600: ospeed = 16; break; +#endif +#ifdef B115200 + case B115200: ospeed = 17; break; +#endif + } +#else + ospeed = 0; +#endif +#endif +#endif + + term = getenv("TERM"); + if (term == NULL) + exit(1); + + if (tgetent(buf, term) != 1) + exit(1); + + s = CL; + pc = tgetstr("pc", &s); + if (pc != NULL) + PC = *pc; + + s = CL; + tgetstr("cl", &s); + + if (CL != NULL) { + tputs(CL, tgetnum("li"), putch); + exit(1); + } + + return 0; +} + +#else /* USE_TERMINFO */ + +#include + +int +#ifdef USE_PROTOTYPES +putch(char c) +#else +putch(c) +int c; +#endif +{ + return putchar(c); +} + +int +main() { + setupterm((char *) 0, 1, (int *) 0); + if (clear_screen == (char *) 0) + exit(1); + tputs(clear_screen, lines > 0 ? lines : 1, putch); + return 0; +} + +#endif /* USE_TERMINFO */ diff --git a/lib/libmytinfo/TESTS/quit.c b/lib/libmytinfo/TESTS/quit.c new file mode 100644 index 000000000000..f30fb5008d7f --- /dev/null +++ b/lib/libmytinfo/TESTS/quit.c @@ -0,0 +1,72 @@ +/* + * quit.c + * + * By Ross Ridge + * Public Domain + * 92/02/01 07:30:14 + * + * quit with a diagnostic message printed on stderr + * + */ + +#define NOTLIB +#include "defs.h" + +#ifdef USE_SCCS_IDS +static const char SCCSid[] = "@(#) mytinfo quit.c 3.2 92/02/01 public domain, By Ross Ridge"; +#endif + +char *prg_name; + +#if defined(USE_PROTOTYPES) && !defined(lint) +void (*cleanup)(int); +#else +void (*cleanup)(); +#endif + +/* PRINTFLIKE2 */ +noreturn +#ifdef USE_STDARG +#ifdef USE_PROTOTYPES +void +quit(int e, char *fmt, ...) +#else +void quit(e, fmt) +int e; +char *fmt; +#endif +#else +void quit(va_alist) +va_dcl +#endif +{ +#ifndef USE_STDARG + int e; + char *fmt; +#endif + va_list ap; + +#ifdef USE_STDARG + va_start(ap, fmt); +#else + va_start(ap); + e = va_arg(ap, int); + fmt = va_arg(ap, char *); +#endif + + (*cleanup)(e); + + if (e != 0) + fprintf(stderr, "%s: ", prg_name); +#ifdef USE_DOPRNT + _doprnt(fmt, ap, stderr); +#else + vfprintf(stderr, fmt, ap); +#endif + putc('\n', stderr); + if (e > 0 && e < sys_nerr) { + fprintf(stderr, "%d - %s\n", e, sys_errlist[e]); + } + fflush(stderr); + exit(e); +} diff --git a/lib/libmytinfo/TESTS/tput.c b/lib/libmytinfo/TESTS/tput.c new file mode 100644 index 000000000000..a3b4a163f011 --- /dev/null +++ b/lib/libmytinfo/TESTS/tput.c @@ -0,0 +1,196 @@ +/* + * tput.c + * + * By Ross Ridge + * Public Domain + * 92/02/01 07:30:39 + * + */ + +#define NOTLIB + +#include "defs.h" + +const char SCCSid[] = "@(#) mytinfo tput.c 3.2 92/02/01 public domain, By Ross Ridge"; + +#define SINGLE +#include + +#include + +#define PUTS(s) putp(s) +#define PUTCHAR(c) putchar(c) +#define FLUSH fflush(stdout) + +extern void (*cleanup)(); + +static void +clean(e) +int e; { + return; +} + +static void +usage(e) +int e; { + fprintf(stderr, "usage: %s [-T term] capname\n", prg_name); + return; +} + +int +main(argc, argv) +int argc; +char **argv; { + char *s; + int i, j, c; + int reset; + FILE *f; + char *term; + + prg_name = argv[0]; + s = strrchr(prg_name, '/'); + if (s != NULL && *++s != '\0') { + prg_name = s; + } + + term = getenv("TERM"); + + cleanup = usage; + + if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 'T') { + if (argv[1][2] == '\0' && argc > 3) { + term = argv[2]; + argc--; + argv++; + } else { + term = argv[1] + 2; + } + argc--; + argv++; + } + + if (argc != 2) { + quit(-1, "arg count"); + } + + cleanup = clean; + + setupterm(term, 1, (int *)0); + + reset = 0; + if (strcmp(argv[1], "reset") == 0) { + reset = 1; + } + if (reset || strcmp(argv[1], "init") == 0) { + + if (init_prog != NULL) { + system(init_prog); + } + FLUSH; + + if (reset && reset_1string != NULL) { + PUTS(reset_1string); + } else if (init_1string != NULL) { + PUTS(init_1string); + } + FLUSH; + + if (reset && reset_2string != NULL) { + PUTS(reset_2string); + } else if (init_2string != NULL) { + PUTS(init_2string); + } + FLUSH; + + if (set_lr_margin != NULL) { + PUTS(tparm(set_lr_margin, 0, columns - 1)); + } else if (set_left_margin_parm != NULL + && set_right_margin_parm != NULL) { + PUTS(tparm(set_left_margin_parm, 0)); + PUTS(tparm(set_right_margin_parm, columns - 1)); + } else if (clear_margins != NULL && set_left_margin != NULL + && set_right_margin != NULL) { + PUTS(clear_margins); + if (carriage_return != NULL) { + PUTS(carriage_return); + } else { + PUTCHAR('\r'); + } + PUTS(set_left_margin); + if (parm_right_cursor) { + PUTS(tparm(parm_right_cursor, columns - 1)); + } else { + for(i = 0; i < columns - 1; i++) { + PUTCHAR(' '); + } + } + PUTS(set_right_margin); + if (carriage_return != NULL) { + PUTS(carriage_return); + } else { + PUTCHAR('\r'); + } + } + FLUSH; + + if (init_tabs != 8) { + if (clear_all_tabs != NULL && set_tab != NULL) { + for(i = 0; i < columns - 1; i += 8) { + if (parm_right_cursor) { + PUTS(tparm(parm_right_cursor, + 8)); + } else { + for(j = 0; j < 8; j++) { + PUTCHAR(' '); + } + } + PUTS(set_tab); + } + FLUSH; + } + } + + if (reset && reset_file != NULL) { + f = fopen(reset_file, "r"); + if (f == NULL) { + quit(errno, "Can't open reset_file: '%s'", + reset_file); + } + while((c = fgetc(f)) != EOF) { + PUTCHAR(c); + } + fclose(f); + } else if (init_file != NULL) { + f = fopen(init_file, "r"); + if (f == NULL) { + quit(errno, "Can't open init_file: '%s'", + init_file); + } + while((c = fgetc(f)) != EOF) { + PUTCHAR(c); + } + fclose(f); + } + FLUSH; + + if (reset && reset_3string != NULL) { + PUTS(reset_3string); + } else if (init_2string != NULL) { + PUTS(init_3string); + } + FLUSH; + return 0; + } + + s = tigetstr(argv[1]); + + if (s == (char *) -1) { + quit(-1, "unknown capname '%s'", argv[1]); + } else if (s == NULL) { + return 0; + } + + putp(s); + + return 0; +} diff --git a/lib/libmytinfo/TESTS/tset.c b/lib/libmytinfo/TESTS/tset.c new file mode 100644 index 000000000000..f04c321391bd --- /dev/null +++ b/lib/libmytinfo/TESTS/tset.c @@ -0,0 +1,919 @@ +/* + * tset.c + * + * By Ross Ridge + * Public Domain + * 92/02/19 18:53:12 + * + */ + +#define NOTLIB + +#include "defs.h" + +const char SCCSid[] = "@(#) mytinfo tset.c 3.3 92/02/19 public domain, By Ross Ridge"; + +#define SINGLE +#include + +#include + +#if defined(USE_TERMIO) || defined(USE_TERMIOS) + +#ifndef ICANON +#ifdef USE_TERMIO +#include +#else +#include +#endif +#endif + +#undef USE_SUSPEND +#ifdef VSUSP +#define USE_SUSPEND +#endif + +#define USE_INTERRUPT + +#if defined(USE_TERMIO) && !defined(TCSETS) +#undef USE_SUSPEND +#endif + +#else /* USE_TERMIO */ +#ifdef USE_SGTTY + +#ifndef CBREAK +#include +#endif + +#undef USE_INTERRUPT +#ifdef TIOCGETC +#define USE_INTERRUPT +#endif + +#undef USE_SUSPEND +#ifdef TIOCGLTC +#define USE_SUSPEND +#endif + +#undef USE_NEWBSDTTY +#ifdef TIOCSETD +#ifdef NTTYDISC +#define USE_NEWBSDTTY +#endif +#endif + +#else /* USE_SGTTY */ + +#undef USE_SUSPEND +#define USE_NOTTY + +#endif /* else USE_SGTTY */ +#endif /* else USE_TERMIO */ + +#ifndef key_interrupt_char +#undef USE_INTERRUPT +#endif + +#ifndef key_suspend_char +#undef USE_SUSPEND +#endif + +char *term; +int asked = 0; +long baudrate; + +#ifndef USE_STDLIB +#ifdef USE_PROTOTYPES +long atol(char const *); +#else +long atol(); +#endif +#endif + +#define OUTPUT_TERM 1 +#define OUTPUT_SHELL 2 +#define OUTPUT_TERMCAP 3 + +#define PUTS(s) tputs(s, 1, putch) +#define PUTCHAR(c) putc(c, stderr) +#define FLUSH fflush(stderr) + +#ifdef USE_SMALLMEM +extern unsigned short _baud_tbl[]; +#else +extern long _baud_tbl[]; +#endif + +extern void (*cleanup)(); + +static void +clean(e) +int e; { + return; +} + +static int +#ifdef USE_PROTOTYPES +putch(char c) +#else +putch(c) +int c; +#endif +{ + return putc(c, stderr); +} + +void +set_term(name, query) +char *name; +int query; { + static char buf[MAX_LINE]; + char *s, *t; + + if (query) { + fprintf(stderr, "TERM = (%s) ", name); + fflush(stderr); + asked = 1; + if (fgets(buf, sizeof(buf), stdin) != NULL) { + s = buf; + while(*s != '\0' && isspace(*s)) + s++; + t = s; + while(*s != '\0' && !isspace(*s)) + s++; + *s = '\0'; + if (*t != '\0') { + term = t; + return; + } + } + } + term = strcpy(buf, name); +} + +int +map_term(map, ask) +char *map; +int ask; { + char *type; + char test = 0; + char *baud = NULL; + + type = map; +#ifndef USE_NOTTY + while(*map && strchr(">@': test = 'g'; break; + case '@': test = 'n'; break; + case '<': test = 'l'; break; + default: + quit(-1, "bad argument to 'm' switch"); + } + } else + test = *map; + *map++ = '\0'; + baud = map; + while(*map && *map != ':') + map++; + } + +#else + while(*map && *map != ':' && *map != '?') + map++; +#endif + + if (*map == ':') + *map++ = '\0'; + if (*map == '?') { + ask = 1; + *map++ = '\0'; + } + if (*map == '\0') + quit(-1, "bad argument to 'm' switch"); + + if (type[0] != '\0' && strcmp(type, term) != 0) { + return 0; + } + +#ifndef USE_NOTTY + switch(test) { + case '>': + if (baudrate <= atol(baud)) + return 0; + break; + case '<': + if (baudrate >= atol(baud)) + return 0; + break; + case '@': + if (baudrate != atol(baud)) + return 0; + break; + case 'l': + if (baudrate < atol(baud)) + return 0; + break; + case 'g': + if (baudrate > atol(baud)) + return 0; + break; + case 'n': + if (baudrate == atol(baud)) + return 0; + break; + } +#endif + + set_term(map, ask); + return 1; +} + +int +conv_char(s) +char *s; { + if (s[0] == '^' && s[1] >= '@' && s[1] < '\177') + return s[1] & 31; + else if (s[0] == '^' && s[1] == '?') + return '\177'; + else if (s[0] != '\0') + return s[0]; + else + return -2; +} + +char * +expand_char(c) +int c; { + static char buf[5]; + + if (c < 0 || c > 127) { + sprintf(buf, "\\%03o", c & 0177); + } else if (c == 127) { + return "DEL"; + } else if (c < 32) { + buf[0] = '^'; + buf[1] = c + 64; + buf[2] = '\0'; + } else { + buf[0] = c; + buf[1] = '\0'; + } + + return buf; +} + +#define START 1 +#define COPY 2 +#define ESCAPE 3 + +void +compress_buf(buf) +char *buf; { + char *s, *d; + int state = START; + + d = s = buf; + + while(*s) { + switch(state) { + case START: + if (isspace(*s) || *s == ':') { + s++; + break; + } + state = COPY; + /* FALLTHROUGH */ + case COPY: + switch(*s) { + case '^': + case '\\': + state = ESCAPE; + break; + case ':': + state = START; + break; + } + *d++ = *s++; + break; + + case ESCAPE: + *d++ = *s++; + state = COPY; + break; + } + } +} + +static void +usage(e) +int e; { +#ifdef USE_ANSIC + fprintf(stderr, "usage: %s [-] [-" +#define ARG(s) s +#else + fprintf(stderr, "usage: %s [-] [-", prg_name); +#define ARG(s) fputs(s, stderr); +#endif + ARG("l") +#ifndef USE_NOTTY +#ifdef USE_NEWBSDTTY + ARG("n") +#endif +#endif + ARG("rsAI") +#ifndef USE_NOTTY + ARG("Q") +#endif + ARG("S") +#ifndef USE_NOTTY + ARG("T") +#endif + ARG("]") +#ifndef USE_NOTTY + ARG(" [-e[c]] [-E[c]] [-k[c]]") +#ifdef USE_INTERRUPT + ARG(" [-i[c]]") +#endif +#ifdef USE_SUSPEND + ARG(" [-z[c]]") +#endif +#endif + ARG("\n\t[-m ident") +#ifndef USE_NOTTY + ARG("[[!][<@>]speed]") +#endif + ARG(":[?]term] [term]\n") +#ifdef USE_ANSIC + , prg_name); +#endif + +#undef ARG + + return; +} + +int +main(argc, argv) +int argc; +char **argv; { + char *s; + int i, j, r, c; + int ask = 0; +#ifndef USE_NOTTY + int erase_char = -1; + int erase_if_bs = 0; + int kill_char = -1; +#ifdef USE_INTERRUPT + int interrupt_char = -1; +#endif +#ifdef USE_SUSPEND + int suspend_char = -1; +#endif +#ifdef USE_NEWBSDTTY + int newbsdtty = 0; +#endif +#endif /* !USE_NOTTY */ + int output_type = 0; + int no_term_init = 0; + int term_type_is = 0; + int no_set_to = 0; + int reset = 0; + int matched = 0; + int expand_tabs = -1; + int is_csh; +#ifndef USE_NOTTTY +#if defined(USE_TERMIOS) || defined(USE_TERMIO) && defined(TCSETS) + struct termios tty; +#else +#ifdef USE_TERMIO + struct termio tty; +#else +#ifdef USE_SGTTY + struct sgttyb tty; +#ifdef USE_INTERRUPT + struct tchars tty2; +#endif +#ifdef USE_SUSPEND + struct ltchars tty3; +#endif +#endif /* USE_SGTTY */ +#endif /* else USE_TERMIO */ +#endif +#endif /* !USE_NOTTY */ + struct term_path *path; + char buf[MAX_BUF]; + FILE *f; + int datatype; + + prg_name = argv[0]; + s = strrchr(prg_name, '/'); + if (s != NULL && *++s != '\0') { + if (strcmp(s, "reset") == 0) { + reset = 1; + } + prg_name = s; + } + + cleanup = clean; + +#ifndef USE_NOTTY +#ifdef USE_TERMIOS + if (tcgetattr(2, &tty) == -1) + quit(errno, "tcgetattr failed"); + baudrate = cfgetospeed(&tty); +#else +#ifdef USE_TERMIO +#ifdef TCSETS + if (ioctl(2, TCGETS, &tty) == -1) +#else + if (ioctl(2, TCGETA, &tty) == -1) +#endif + { + quit(errno, "ioctl failed"); + } + baudrate = _baud_tbl[tty.c_cflag & CBAUD]; +#else +#ifdef USE_SGTTY + if (gtty(2, &tty) == -1) { + quit(errno, "gtty failed"); + } + baudrate = _baud_tbl[tty.sg_ospeed]; +#ifdef USE_INTERRUPT + if (ioctl(2, TIOCGETC, &tty2) == -1) { + quit(errno, "ioctl failed"); + } +#endif +#ifdef USE_SUSPEND + if (ioctl(2, TIOCGLTC, &tty3) == -1) { + quit(errno, "ioctl failed"); + } +#endif +#endif /* USE_SGTTY */ +#endif /* else USE_TERMIO */ +#endif +#endif /* !USE_NOTTY */ + + term = getenv("TERM"); + + cleanup = usage; + + for(i = 1; i < argc; i++) { + if (argv[i][0] != '-') { + if (term == NULL) { + term = argv[i]; + } + continue; + } + s = argv[i] + 1; + if (*s == '\0') { + output_type = OUTPUT_TERM; + continue; + } + while (*s != '\0') { + switch(*s++) { + case 'A': + ask = 1; + continue; +#ifndef USE_NOTTY + case 'E': + erase_if_bs = 1; + /* FALLTHROUGH */ + case 'e': + erase_char = conv_char(s); + break; + case 'k': + kill_char = conv_char(s); + break; +#ifdef USE_INTERRUPT + case 'i': + interrupt_char = conv_char(s); + break; +#endif +#ifdef USE_SUSPEND + case 'z': + suspend_char = conv_char(s); + break; +#endif + case 'T': + erase_char = kill_char +#ifdef USE_INTERRUPT + = interrupt_char +#endif +#ifdef USE_SUSPEND + = suspend_char +#endif + = -2; + continue; +#ifdef USE_NEWBSDTTY + case 'n': + newbsdtty = 1; + continue; +#endif + case 'Q': + no_set_to = 1; + continue; +#endif /* !USE_NOTTY */ + case 'l': + case 'I': + no_term_init = 1; + continue; + case 'r': + term_type_is = 1; + continue; + case 's': + output_type = OUTPUT_SHELL; + continue; + case 'S': + output_type = OUTPUT_TERMCAP; + continue; + case 'm': + if (*s == '\0') { + if (i == argc - 1) { + quit(-1, "'m' switch requires an argument."); + } + s = argv[++i]; + } + if (!matched) { + matched = map_term(s, ask); + } + break; + default: + quit(-1, "unknown switch '%c'", s[-1]); + break; + } + break; + } + } + + cleanup = clean; + + path = _buildpath("$MYTERMINFO", 2, + "$TERMINFO", 2, + "$TERMCAP", 1, +#ifdef TERMINFODIR + TERMINFODIR, 0, +#endif +#ifdef TERMCAPFILE + TERMCAPFILE, 0, +#endif +#ifdef TERMINFOSRC + TERMINFOSRC, 0, +#endif + NULL, -1); + + if (path == NULL) { + quit(-1, "malloc error"); + } + + do { + if (term == NULL) { + term = "unknown"; + } + + if (ask && !asked) { + set_term(term, 1); + } + + datatype = _fillterm(term, path, buf); + + switch(datatype) { + case -3: + quit(-1, "malloc error"); + /* NOTREACHED */ + case -2: + quit(-1, "database in bad format"); + /* NOTREACHED */ + case -1: + /* quit(-1, "database not found"); */ + case 0: + if (ask || asked) { + fprintf(stderr, "terminal type '%s' unknown.\n", + term); + term = NULL; + ask = 1; + asked = 0; + } else { + quit(-1, "terminal type '%s' unknown.\n", term); + } + break; + case 1: + case 2: + case 3: + break; + default: + quit(-1, "oops..."); + } + } while(term == NULL); + + _delpath(path); + + cur_term->baudrate = baudrate; + + if (!no_term_init) { + + if (init_prog != NULL) { + system(init_prog); + } + FLUSH; + + if (reset && reset_1string != NULL) { + PUTS(reset_1string); + } else if (init_1string != NULL) { + PUTS(init_1string); + } + FLUSH; + + if (reset && reset_2string != NULL) { + PUTS(reset_2string); + } else if (init_2string != NULL) { + PUTS(init_2string); + } + FLUSH; + + if (set_lr_margin != NULL) { + PUTS(tparm(set_lr_margin, 0, columns - 1)); + } else if (set_left_margin_parm != NULL + && set_right_margin_parm != NULL) { + PUTS(tparm(set_left_margin_parm, 0)); + PUTS(tparm(set_right_margin_parm, columns - 1)); + } else if (clear_margins != NULL && set_left_margin != NULL + && set_right_margin != NULL) { + PUTS(clear_margins); + if (carriage_return != NULL) { + PUTS(carriage_return); + } else { + PUTCHAR('\r'); + } + PUTS(set_left_margin); + if (parm_right_cursor) { + PUTS(tparm(parm_right_cursor, columns - 1)); + } else { + for(i = 0; i < columns - 1; i++) { + PUTCHAR(' '); + } + } + PUTS(set_right_margin); + if (carriage_return != NULL) { + PUTS(carriage_return); + } else { + PUTCHAR('\r'); + } + } + FLUSH; + + if (init_tabs != 8) { + if (clear_all_tabs != NULL && set_tab != NULL) { + if (carriage_return != NULL) { + PUTS(carriage_return); + } else { + PUTCHAR('\r'); + } + PUTS(clear_all_tabs); + PUTS(set_tab); + for(i = 8; i < columns - 1; i += 8) { + if (parm_right_cursor) { + PUTS(tparm(parm_right_cursor, + 8)); + } else { + for(j = 0; j < 8; j++) { + PUTCHAR(' '); + } + } + PUTS(set_tab); + } + if (carriage_return != NULL) { + PUTS(carriage_return); + } else { + PUTCHAR('\r'); + } + expand_tabs = 0; + FLUSH; + } else { + expand_tabs = 1; + } + } else { + expand_tabs = 0; + } + + if (reset && reset_file != NULL) { + f = fopen(reset_file, "r"); + if (f == NULL) { + quit(errno, "Can't open reset_file: '%s'", + reset_file); + } + while((c = fgetc(f)) != EOF) { + PUTCHAR(c); + } + fclose(f); + } else if (init_file != NULL) { + f = fopen(init_file, "r"); + if (f == NULL) { + quit(errno, "Can't open init_file: '%s'", + init_file); + } + while((c = fgetc(f)) != EOF) { + PUTCHAR(c); + } + fclose(f); + } + FLUSH; + + if (reset && reset_3string != NULL) { + PUTS(reset_3string); + } else if (init_2string != NULL) { + PUTS(init_3string); + } + FLUSH; + } + + if (term_type_is) { + fprintf(stderr, "Terminal type is %s\n", term); + } + +#ifndef USE_NOTTY +#if defined(USE_TERMIO) || defined(USE_TERMIOS) + +#ifdef USE_TERMIO + if (expand_tabs == 0 && (tty.c_cflag & TABDLY) == TAB3) { + tty.c_cflag = tty.c_cflag & ~TABDLY; + } else if (expand_tabs == 1) { + tty.c_cflag = (tty.c_cflag & ~TABDLY) | TAB3; + } +#else + if (!expand_tabs) + tty.c_oflag &= ~OXTABS; + else + tty.c_oflag |= OXTABS; +#endif + +#define SETTO(v, m, t, c) (c != tty.c_cc[v] ? (tty.c_cc[v] = c, \ + !no_set_to ? fprintf(stderr, "%s set to %s\n", t, \ + expand_char(c)) : 0) : 0) + +#endif +#ifdef USE_SGTTY + +#ifdef USE_NEWBSDTTY + if (newbsdtty) { + if (ioctl(2, TIOCSETD, NTTYDISC) == -1) { + quit(errno, "Can't switch tty to new line disc."); + } + } +#endif + + if (expand_tabs == 0) { + tty.sg_flags &= ~XTABS; + } else if (expand_tabs == 1) { + tty.sg_flags |= XTABS; + } + +#define SETTO(v, m, t, c) (c != m ? (m = c, \ + !no_set_to ? fprintf(stderr, "%s set to %s\n", t, \ + expand_char(c)) : 0) : 0) +#endif + + if (erase_char != -1 + && (!erase_if_bs || backspaces_with_bs + || (cursor_left == NULL && cursor_left[0] != '\b'))) { + if (erase_char != -2) { + c = erase_char; + } else if (cursor_left == NULL || cursor_left[0] == '\0' + || cursor_left[1] != '\0') { + c = '\b'; + } else { + c = cursor_left[0]; + } + SETTO(VERASE, tty.sg_erase, "Erase", c); + } + + if (kill_char != -1) { + if (kill_char != -2) { + c = kill_char; + } else if (key_kill_char == NULL || key_kill_char[0] == '\0' + || key_kill_char[1] != '\0') { + c = '\025'; + } else { + c = key_kill_char[0]; + } + SETTO(VKILL, tty.sg_kill, "Kill", c); + } + + +#ifdef USE_INTERRUPT + if (interrupt_char != -1) { + if (interrupt_char != -2) { + c = interrupt_char; + } else if (key_interrupt_char == NULL + || key_interrupt_char[0] == '\0' + || key_interrupt_char[1] != '\0') { + c = '\177'; + } else { + c = key_interrupt_char[0]; + } + SETTO(VINTR, tty2.t_intrc, "Interrupt", c); + } +#endif + +#ifdef USE_SUSPEND + if (suspend_char != -1) { + if (suspend_char != -2) { + c = suspend_char; + } else if (key_suspend_char == NULL + || key_suspend_char[0] == '\0' + || key_suspend_char[1] != '\0') { + c = '\032'; + } else { + c = key_suspend_char[0]; + } + SETTO(VSUSP, tty3.t_suspc, "Suspend", c); + } +#endif + +#ifdef USE_TERMIOS + if (tcsetattr(2, TCSADRAIN, &tty) == -1) + quit(errno, "tcsetattr failed"); +#else +#ifdef USE_TERMIO +#ifdef TCSETS + if (ioctl(2, TCSETS, &tty) == -1) +#else + if (ioctl(2, TCSETA, &tty) == -1) +#endif + { + quit(errno, "ioctl failed"); + } +#else +#ifdef USE_SGTTY + if (stty(2, &tty) == -1) { + quit(errno, "stty failed"); + } +#ifdef USE_INTERRUPT + if (ioctl(2, TIOCSETC, &tty2) == -1) { + quit(errno, "ioctl failed"); + } +#endif +#ifdef USE_SUSPEND + if (ioctl(2, TIOCSLTC, &tty3) == -1) { + quit(errno, "ioctl failed"); + } +#endif +#endif /* USE_SGTTY */ +#endif /* else USE_TERMIO */ +#endif +#endif /* !USE_NOTTY */ + + s = getenv("SHELL"); + r = strlen(s); + + if (r >= 3 && strcmp("csh", s + r - 3) == 0) { + is_csh = 1; + } else { + is_csh = 0; + } + + switch(output_type) { + case OUTPUT_TERM: + fprintf(stdout, "%s\n", term); + break; + + case OUTPUT_TERMCAP: + if (is_csh) { + if (datatype == 1) { + compress_buf(buf); + fprintf(stdout, "%s %s", term, buf); + } else { + s = getenv("TERMCAP"); + if (s == NULL || *s == '\0') { + s = ":"; + } + fprintf(stdout, "%s %s", term, s); + } + break; + } + /* FALLTHROUGH */ + case OUTPUT_SHELL: + if (is_csh) { + fprintf(stdout, "set noglob;\n"); + fprintf(stdout, "setenv TERM '%s';\n", term); + if (datatype == 1) { + compress_buf(buf); + fprintf(stdout, "setenv TERMCAP '%s';\n", buf); + } + fprintf(stdout, "unset noglob;\n"); + } else { + fprintf(stdout, "export TERM TERMCAP;\n"); + fprintf(stdout, "TERM='%s';\n", term); + if (datatype == 1) { + compress_buf(buf); + fprintf(stdout, "TERMCAP='%s';\n", buf); + } + } + break; + } + + return 0; +} diff --git a/lib/libmytinfo/TESTS/ttest.c b/lib/libmytinfo/TESTS/ttest.c new file mode 100644 index 000000000000..3839e9f1881b --- /dev/null +++ b/lib/libmytinfo/TESTS/ttest.c @@ -0,0 +1,297 @@ +/* + * ttest.c + * + * By Ross Ridge + * Public Domain + * 92/02/01 07:30:47 + * + */ + +#define NOTLIB +#include "defs.h" +#include + +const char SCCSid[] = "@(#) mytinfo ttest.c 3.2 92/02/01 public domain, By Ross Ridge"; + +int +cup(x,y) +int x, y; { + if (columns < 2 || lines < 2) + return -1; + if (cursor_address != NULL) + putp(tparm(cursor_address, y, x)); + else if (cursor_home != NULL && cursor_down != NULL + && cursor_right != NULL) { + putp(cursor_home); + if (parm_down_cursor != NULL) + putp(tparm(parm_down_cursor, y)); + else + for(; y > 0; y--) + putp(cursor_down); + if (parm_right_cursor != NULL) + putp(tparm(parm_right_cursor, y)); + else + for(; y > 0; y--) + putp(cursor_right); + } else if (cursor_to_ll != NULL && cursor_up != NULL + && cursor_right != NULL) { + putp(cursor_to_ll); + if (parm_up_cursor != NULL) + putp(tparm(parm_up_cursor, y)); + else + for(y++; y < columns ; y++) + putp(cursor_up); + if (parm_right_cursor != NULL) + putp(tparm(parm_right_cursor, y)); + else + for(; y > 0; y--) + putp(cursor_right); + } else + return 1; + return 0; +} + +int +clear() { + int r; + if (clear_screen != NULL) + putp(clear_screen); + else if (clr_eos != NULL) { + r = cup(0,0); + if (r != 0) + return r; + putp(clr_eos); + } else + return -2; + return 0; +} + +void +nl() { + if (newline != NULL) + putp(newline); + else if (carriage_return != NULL && cursor_down != NULL) { + putp(cursor_down); + putp(carriage_return); + } else + quit(-1, "can't do a newline"); + return; +} + +void +putln(s) +char *s; { + int i; + + if (columns < 2 || auto_right_margin) + fputs(s, stdout); + else { + i = 0; + while(*s) { + putchar(*s); + s++; + if (++i == columns) { + nl(); + i = 0; + } + } + } + nl(); +} + +void +anykey() { + fputs("-- press any key --", stdout); + fflush(stdout); + getchar(); + nl(); +} + +void +do_cleanup(e) +int e; { + fflush(stdout); + fflush(stderr); + reset_shell_mode(); + fprintf(stderr, "\n"); +} + +#ifdef USE_SGTTY +struct sgttyb new_tty; +#else +#ifdef USE_TERMIO +struct termio new_tty; +#else +struct termios new_tty; +#endif +#endif + +int +main(argc, argv) +int argc; +char **argv; { + register int i; + + prg_name = argv[0]; + cleanup = do_cleanup; + + if (argc == 1) + setupterm(NULL, 1, (int *) 0); + else if (argc == 2) + setupterm(argv[1], 1, (int *) 0); + else { + fprintf(stderr, "usage: %s [terminal]\n", argv[0]); + return 1; + } + fflush(stderr); + fflush(stdout); +#ifdef USE_SGTTY + ioctl(1, TIOCGETP, &new_tty); + new_tty.sg_flags &= ~(CRMOD | ECHO | XTABS); +#ifdef CBREAK + new_tty.sg_flags |= CBREAK; +#else + new_tty.sg_flags |= RAW; +#endif + ioctl(1, TIOCSETP, &new_tty); +#endif +#ifdef USE_TERMIO + ioctl(1, TCGETA, &new_tty); +#else +#ifdef USE_TERMIOS + tcgetattr(1, &new_tty); +#endif +#endif +#if defined(USE_TERMIO) || defined(USE_TERMIOS) + new_tty.c_lflag &= ~(ICANON | ECHO); + new_tty.c_oflag &= ~(OPOST); + new_tty.c_cc[VMIN] = 1; + new_tty.c_cc[VTIME] = 1; +#endif +#ifdef USE_TERMIO + ioctl(1, TCSETA, &new_tty); +#else +#ifdef USE_TERMIOS + tcsetattr(1, TCSADRAIN, &new_tty); +#endif +#endif + def_prog_mode(); + + clear(); + printf("columns = %d", columns); + nl(); + printf("lines = %d", lines); + if (columns < 2) + quit(-1, "columns must be > 1"); + nl(); + anykey(); + nl(); + if (auto_right_margin) { + putln("auto_right_margin = TRUE"); + nl(); + for(i = 0; i < columns; i++) + putchar('1'); + for(i = 0; i < columns / 2; i++) + putchar('2'); + nl(); + } else { + putln("auto_right_margin = FALSE"); + nl(); + for(i = 0; i < columns + columns / 2; i++) + putchar('1'); + nl(); + for(i = 0; i < columns / 2; i++) + putchar('2'); + nl(); + } + nl(); + putln("***a line of 1's followed by a line of 2's"); + nl(); + anykey(); + nl(); + + if (over_strike) { + putln("over_strike = TRUE"); + if (cursor_left != NULL) { + for(i = 0; i < columns / 4 + 1; i++) { + putchar('/'); + putp(cursor_left); + putchar('\\'); + } + } else if (carriage_return != NULL) { + for(i = 0; i < columns / 4 + 1; i++) + putchar('/'); + putp(carriage_return); + for(i = 0; i < columns / 4 + 1; i++) + putchar('\\'); + } + nl(); + nl(); + putln("*** X's made from \\'s overstriking /'s"); + nl(); + anykey(); + nl(); + } + + if (cup(0,0) == 0) { + clear(); + putln("cup test"); + for(i = 1; i < columns; i++) + putp(tparm(cursor_address, 0, i)); + for(i = 0; i < lines; i++) + putp(tparm(cursor_address, i, columns - 1)); + for(i = columns; i--;) + putp(tparm(cursor_address, lines - 1, i)); + for(i = lines; i--;) + putp(tparm(cursor_address, i, 0)); + nl(); + anykey(); + } + clear(); + + putln("Attribute test"); + nl(); + if (enter_blink_mode != NULL) { + putp(enter_blink_mode); + printf("blink"); + putp(exit_attribute_mode); + nl(); + } + if (enter_bold_mode != NULL) { + putp(enter_bold_mode); + printf("bold"); + putp(exit_attribute_mode); + nl(); + } + if (enter_dim_mode != NULL) { + putp(enter_dim_mode); + printf("dim"); + putp(exit_attribute_mode); + nl(); + } + if (enter_reverse_mode != NULL) { + putp(enter_reverse_mode); + printf("reverse"); + putp(exit_attribute_mode); + nl(); + } + if (enter_standout_mode != NULL) { + putp(enter_standout_mode); + printf("standout"); + putp(exit_standout_mode); + nl(); + } + if (enter_underline_mode != NULL) { + putp(enter_underline_mode); + printf("underline"); + putp(exit_underline_mode); + nl(); + } + nl(); + anykey(); + + clear(); + reset_shell_mode(); + + return (0); +}