122071Sdist /* 2*36499Sbostic * Copyright (c) 1980 The Regents of the University of California. 3*36499Sbostic * All rights reserved. 4*36499Sbostic * 5*36499Sbostic * Redistribution and use in source and binary forms are permitted 6*36499Sbostic * provided that the above copyright notice and this paragraph are 7*36499Sbostic * duplicated in all such forms and that any documentation, 8*36499Sbostic * advertising materials, and other materials related to such 9*36499Sbostic * distribution and use acknowledge that the software was developed 10*36499Sbostic * by the University of California, Berkeley. The name of the 11*36499Sbostic * University may not be used to endorse or promote products derived 12*36499Sbostic * from this software without specific prior written permission. 13*36499Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*36499Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*36499Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1622071Sdist */ 1722071Sdist 1813299Ssam #ifndef lint 19*36499Sbostic char copyright[] = 20*36499Sbostic "@(#) Copyright (c) 1980 The Regents of the University of California.\n\ 21*36499Sbostic All rights reserved.\n"; 22*36499Sbostic #endif /* not lint */ 2313299Ssam 24*36499Sbostic #ifndef lint 25*36499Sbostic static char sccsid[] = "@(#)tc3.c 5.2 (Berkeley) 01/03/89"; 26*36499Sbostic #endif /* not lint */ 27*36499Sbostic 2813299Ssam /* 2913299Ssam * tc3 [term] 3013299Ssam * Dummy program to test out termlib. 3113299Ssam * Input two numbers and it prints out the tgoto string generated. 3213299Ssam */ 3313299Ssam #include <stdio.h> 3413299Ssam char buf[1024]; 3513299Ssam char *getenv(), *tgetstr(); 3613299Ssam char *rdchar(); 3713299Ssam char *tgoto(); 3813299Ssam char *CM; 3913299Ssam char cmbuff[30]; 4013299Ssam char *x; 4113299Ssam char *UP; 4213299Ssam char *tgout; 4313299Ssam 4413299Ssam main(argc, argv) char **argv; { 4513299Ssam char *p; 4613299Ssam int rc; 4713299Ssam int row, col; 4813299Ssam 4913299Ssam if (argc < 2) 5013299Ssam p = getenv("TERM"); 5113299Ssam else 5213299Ssam p = argv[1]; 5313299Ssam rc = tgetent(buf,p); 5413299Ssam x = cmbuff; 5513299Ssam UP = tgetstr("up", &x); 5613299Ssam printf("UP = %x = ", UP); pr(UP); printf("\n"); 5713299Ssam if (UP && *UP==0) 5813299Ssam UP = 0; 5913299Ssam CM = tgetstr("cm", &x); 6013299Ssam printf("CM = "); pr(CM); printf("\n"); 6113299Ssam for (;;) { 6213299Ssam if (scanf("%d %d", &row, &col) < 2) 6313299Ssam exit(0); 6413299Ssam tgout = tgoto(CM, row, col); 6513299Ssam pr(tgout); 6613299Ssam printf("\n"); 6713299Ssam } 6813299Ssam } 6913299Ssam 7013299Ssam pr(p) 7113299Ssam register char *p; 7213299Ssam { 7313299Ssam for (; *p; p++) 7413299Ssam printf("%s", rdchar(*p)); 7513299Ssam } 7613299Ssam 7713299Ssam /* 7813299Ssam * rdchar: returns a readable representation of an ASCII char, using ^ notation. 7913299Ssam */ 8013299Ssam #include <ctype.h> 8113299Ssam char *rdchar(c) 8213299Ssam char c; 8313299Ssam { 8413299Ssam static char ret[4]; 8513299Ssam register char *p; 8613299Ssam 8713299Ssam /* 8813299Ssam * Due to a bug in isprint, this prints spaces as ^`, but this is OK 8913299Ssam * because we want something to show up on the screen. 9013299Ssam */ 9113299Ssam ret[0] = ((c&0377) > 0177) ? '\'' : ' '; 9213299Ssam c &= 0177; 9313299Ssam ret[1] = isprint(c) ? ' ' : '^'; 9413299Ssam ret[2] = isprint(c) ? c : c^0100; 9513299Ssam ret[3] = 0; 9613299Ssam for (p=ret; *p==' '; p++) 9713299Ssam ; 9813299Ssam return (p); 9913299Ssam } 100