|
|
1.1 root 1: /*********************************************************************
2: * COPYRIGHT NOTICE *
3: **********************************************************************
4: * This software is copyright (C) 1982 by Pavel Curtis *
5: * *
6: * Permission is granted to reproduce and distribute *
7: * this file by any means so long as no fee is charged *
8: * above a nominal handling fee and so long as this *
9: * notice is always included in the copies. *
10: * *
11: * Other rights are reserved except as explicitly granted *
12: * by written permission of the author. *
13: * Pavel Curtis *
14: * Computer Science Dept. *
15: * 405 Upson Hall *
16: * Cornell University *
17: * Ithaca, NY 14853 *
18: * *
19: * Ph- (607) 256-4934 *
20: * *
21: * Pavel.Cornell@Udel-Relay (ARPAnet) *
22: * decvax!cornell!pavel (UUCPnet) *
23: *********************************************************************/
24:
25: /*
26: * setupterm(termname, filedes, errret)
27: *
28: * Find and read the appropriate object file for the terminal
29: * Make cur_term point to the structure.
30: * Turn off the XTABS bit in the tty structure if it was on
31: * If XTABS was on, remove the tab and backtab capabilities.
32: *
33: * $Log: lib_setup.c,v $
34: * Revision 1.11 93/04/12 14:14:08 bin
35: * Udo: third color update
36: *
37: * Revision 2.4 92/11/29 15:40:02 munk
38: * Conditional usage of termio
39: *
40: * Revision 2.3 92/10/27 22:23:15 munk
41: * Initialize alternate character set map
42: *
43: * Revision 1.5 92/06/02 12:05:36 bin
44: * *** empty log message ***
45: *
46: * Revision 1.2 92/04/13 14:38:31 bin
47: * update by vlad
48: *
49: * Revision 2.2 91/04/20 21:45:19 munk
50: * Usage of register variables
51: * Made the large arrays static
52: *
53: * Revision 2.1 82/10/25 14:49:09 pavel
54: * Added Copyright Notice
55: *
56: * Revision 2.0 82/10/24 15:17:46 pavel
57: * Beta-one Test Release
58: *
59: * Revision 1.5 82/08/23 22:30:35 pavel
60: * The REAL Alpha-one Release Version
61: *
62: * Revision 1.4 82/08/20 15:12:24 pavel
63: * Fixed use of un-initialised cur_term.
64: *
65: * Revision 1.3 82/08/19 19:22:09 pavel
66: * Alpha Test Release One
67: *
68: * Revision 1.2 82/08/19 19:11:28 pavel
69: * Alpha Test Release One
70: *
71: * Revision 1.1 82/08/12 18:45:07 pavel
72: * Initial revision
73: *
74: *
75: */
76:
77: #ifdef RCSHDR
78: static char RCSid[] =
79: "$Header: /src386/usr/lib/ncurses/RCS/lib_setup.c,v 1.11 93/04/12 14:14:08 bin Exp Locker: bin $";
80: #endif
81:
82: #include <stdio.h>
83: #include "curses.h"
84: #include "curses.priv.h"
85: #include "term.h"
86:
87: #define ret_error(code, fmt, arg) if (errret)\
88: {\
89: *errret = code;\
90: return(code);\
91: }\
92: else\
93: {\
94: fprintf(stderr, fmt, arg);\
95: exit(1);\
96: }
97:
98:
99: chtype acs_map[128];
100: char ttytype[NAMESIZE];
101: struct term _first_term;
102:
103: int _tracing;
104: struct screen *SP = 0;
105:
106:
107: setupterm(termname, filedes, errret)
108: char *termname;
109: int filedes;
110: int *errret;
111: {
112: char filename[1024];
113: char *malloc(), *getenv(), *strncpy();
114: char *terminfo;
115: struct term *term_ptr;
116: int got_code;
117:
118: #ifdef TRACE
119: _init_trace();
120: if (_tracing)
121: _tracef("setupterm(%s,%d,%o) called", termname, filedes, errret);
122: #endif
123:
124: if (termname == NULL)
125: {
126: termname = getenv("TERM");
127: if (termname == NULL)
128: ret_error(-1, "TERM environment variable not set.\n", "");
129: }
130:
131: if (cur_term == 0)
132: term_ptr = &_first_term;
133: else
134: {
135: term_ptr = (struct term *) malloc(sizeof(struct term));
136:
137: if (term_ptr == NULL)
138: ret_error(-1, "Not enough memory to create terminal structure.\n", "");
139: }
140:
141: got_code = -1;
142: if ((terminfo = getenv("TERMINFO")) != NULL) {
143: sprintf(filename, "%s/%c/%s", terminfo, termname[0], termname);
144: got_code = read_entry(filename, term_ptr);
145: }
146: if (got_code < 0) {
147: sprintf(filename, "%s/%c/%s", SRCDIR, termname[0], termname);
148: if (read_entry(filename, term_ptr) < 0)
149: ret_error(0, "'%s': Unknown terminal type.\n", termname);
150: }
151:
152: if (command_character && getenv("CC"))
153: do_prototype();
154:
155: cur_term = term_ptr;
156: strncpy(ttytype, cur_term->term_names, NAMESIZE - 1);
157: ttytype[NAMESIZE - 1] = '\0';
158: cur_term->Filedes = filedes;
159: #ifdef USE_TERMIO
160: ioctl(filedes, TCGETA, &cur_term->Otermio);
161: if ((cur_term->Otermio.c_oflag & TABDLY) == TAB3)
162: tab = back_tab = NULL;
163:
164: cur_term->Ntermio = cur_term->Otermio;
165: cur_term->Ntermio.c_oflag &= ~TAB3;
166: #else
167: gtty(filedes, &cur_term->Ottyb);
168: if (cur_term->Ottyb.sg_flags & XTABS)
169: tab = back_tab = NULL;
170:
171: cur_term->Nttyb = cur_term->Ottyb;
172: cur_term->Nttyb.sg_flags &= ~XTABS;
173: #endif
174:
175: setup_acs();
176: fixterm();
177:
178: if (errret)
179: *errret = 1;
180:
181: return(1);
182: }
183:
184:
185: /*
186: ** do_prototype()
187: **
188: ** Take the real command character out of the CC environment variable
189: ** and substitute it in for the prototype given in 'command_character'.
190: **
191: */
192:
193: static
194: do_prototype()
195: {
196: register int i, j;
197: char CC;
198: char proto;
199:
200: CC = *getenv("CC");
201: proto = *command_character;
202:
203: for (i=0; i < STRCOUNT; i++)
204: {
205: j = 0;
206: while (cur_term->Strings[i][j])
207: {
208: if (cur_term->Strings[i][j] == proto)
209: cur_term->Strings[i][j] = CC;
210: j++;
211: }
212: }
213: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.