comparison src/termcap.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents 74fd4e045ea6
children
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
24 #ifdef emacs 24 #ifdef emacs
25 #include <config.h> 25 #include <config.h>
26 #include "lisp.h" /* For encapsulated open, close, read */ 26 #include "lisp.h" /* For encapsulated open, close, read */
27 #include "device.h" /* For DEVICE_BAUD_RATE */ 27 #include "device.h" /* For DEVICE_BAUD_RATE */
28 #else /* not emacs */ 28 #else /* not emacs */
29 29 #if defined(USG) || defined(STDC_HEADERS)
30 #define memcpy(d, s, n) memcpy ((d), (s), (n))
31 #endif
32
33 #ifdef STDC_HEADERS
30 #include <stdlib.h> 34 #include <stdlib.h>
31 #include <string.h> 35 #include <string.h>
36 #else
37 char *getenv ();
38 char *malloc ();
39 char *realloc ();
40 #endif
32 41
33 #ifdef HAVE_UNISTD_H 42 #ifdef HAVE_UNISTD_H
34 #include <unistd.h> 43 #include <unistd.h>
35 #endif 44 #endif
36 #ifdef _POSIX_VERSION 45 #ifdef _POSIX_VERSION
92 101
93 /* The pointer to the data made by tgetent is left here 102 /* The pointer to the data made by tgetent is left here
94 for tgetnum, tgetflag and tgetstr to find. */ 103 for tgetnum, tgetflag and tgetstr to find. */
95 static char *term_entry; 104 static char *term_entry;
96 105
97 static const char *tgetst1 (const char *ptr, char **area); 106 static CONST char *tgetst1 (CONST char *ptr, char **area);
98 107
99 /* Search entry BP for capability CAP. 108 /* Search entry BP for capability CAP.
100 Return a pointer to the capability (in BP) if found, 109 Return a pointer to the capability (in BP) if found,
101 0 if not found. */ 110 0 if not found. */
102 111
103 static const char * 112 static CONST char *
104 find_capability (bp, cap) 113 find_capability (bp, cap)
105 const char *bp; 114 CONST char *bp;
106 const char *cap; 115 CONST char *cap;
107 { 116 {
108 for (; *bp; bp++) 117 for (; *bp; bp++)
109 if (bp[0] == ':' 118 if (bp[0] == ':'
110 && bp[1] == cap[0] 119 && bp[1] == cap[0]
111 && bp[2] == cap[1]) 120 && bp[2] == cap[1])
113 return 0; 122 return 0;
114 } 123 }
115 124
116 int 125 int
117 tgetnum (cap) 126 tgetnum (cap)
118 const char *cap; 127 CONST char *cap;
119 { 128 {
120 const char *ptr = find_capability (term_entry, cap); 129 CONST char *ptr = find_capability (term_entry, cap);
121 if (!ptr || ptr[-1] != '#') 130 if (!ptr || ptr[-1] != '#')
122 return -1; 131 return -1;
123 return atoi (ptr); 132 return atoi (ptr);
124 } 133 }
125 134
126 int 135 int
127 tgetflag (cap) 136 tgetflag (cap)
128 const char *cap; 137 CONST char *cap;
129 { 138 {
130 const char *ptr = find_capability (term_entry, cap); 139 CONST char *ptr = find_capability (term_entry, cap);
131 return 0 != ptr && ptr[-1] == ':'; 140 return 0 != ptr && ptr[-1] == ':';
132 } 141 }
133 142
134 /* Look up a string-valued capability CAP. 143 /* Look up a string-valued capability CAP.
135 If AREA is nonzero, it points to a pointer to a block in which 144 If AREA is nonzero, it points to a pointer to a block in which
136 to store the string. That pointer is advanced over the space used. 145 to store the string. That pointer is advanced over the space used.
137 If AREA is zero, space is allocated with `malloc'. */ 146 If AREA is zero, space is allocated with `malloc'. */
138 147
139 const char * 148 CONST char *
140 tgetstr (cap, area) 149 tgetstr (cap, area)
141 const char *cap; 150 CONST char *cap;
142 char **area; 151 char **area;
143 { 152 {
144 const char *ptr = find_capability (term_entry, cap); 153 CONST char *ptr = find_capability (term_entry, cap);
145 if (!ptr || (ptr[-1] != '=' && ptr[-1] != '~')) 154 if (!ptr || (ptr[-1] != '=' && ptr[-1] != '~'))
146 return 0; 155 return 0;
147 return tgetst1 (ptr, area); 156 return tgetst1 (ptr, area);
148 } 157 }
149 158
160 /* PTR points to a string value inside a termcap entry. 169 /* PTR points to a string value inside a termcap entry.
161 Copy that value, processing \ and ^ abbreviations, 170 Copy that value, processing \ and ^ abbreviations,
162 into the block that *AREA points to, 171 into the block that *AREA points to,
163 or to newly allocated storage if AREA is 0. */ 172 or to newly allocated storage if AREA is 0. */
164 173
165 static const char * 174 static CONST char *
166 tgetst1 (ptr, area) 175 tgetst1 (ptr, area)
167 const char *ptr; 176 CONST char *ptr;
168 char **area; 177 char **area;
169 { 178 {
170 const char *p; 179 CONST char *p;
171 char *r; 180 char *r;
172 int c; 181 int c;
173 int size; 182 int size;
174 char *ret; 183 char *ret;
175 int c1; 184 int c1;
248 -18, -24, -48, -96, -192, -288, -384, -576, -1152 257 -18, -24, -48, -96, -192, -288, -384, -576, -1152
249 }; 258 };
250 259
251 void 260 void
252 tputs (string, nlines, outfun) 261 tputs (string, nlines, outfun)
253 const char *string; 262 CONST char *string;
254 int nlines; 263 int nlines;
255 void (*outfun) (int); 264 void (*outfun) (int);
256 { 265 {
257 int padcount = 0; 266 int padcount = 0;
258 int speed; 267 int speed;
267 #endif 276 #endif
268 277
269 if (string == (char *) 0) 278 if (string == (char *) 0)
270 return; 279 return;
271 280
272 while (isdigit (* (const unsigned char *) string)) 281 while (isdigit (* (CONST unsigned char *) string))
273 { 282 {
274 padcount += *string++ - '0'; 283 padcount += *string++ - '0';
275 padcount *= 10; 284 padcount *= 10;
276 } 285 }
277 if (*string == '.') 286 if (*string == '.')
326 and store it in the block that BP points to. 335 and store it in the block that BP points to.
327 Record its address for future use. 336 Record its address for future use.
328 337
329 If BP is zero, space is dynamically allocated. */ 338 If BP is zero, space is dynamically allocated. */
330 339
340 extern char *getenv ();
341
331 int 342 int
332 tgetent (bp, name) 343 tgetent (bp, name)
333 char *bp; 344 char *bp;
334 const char *name; 345 CONST char *name;
335 { 346 {
336 char *tem; 347 char *tem;
337 int fd; 348 int fd;
338 struct buffer buf; 349 struct buffer buf;
339 char *bp1; 350 char *bp1;
340 char *bp2; 351 char *bp2;
341 const char *term; 352 CONST char *term;
342 int malloc_size = 0; 353 int malloc_size = 0;
343 int c; 354 int c;
344 char *tcenv; /* TERMCAP value, if it contais :tc=. */ 355 char *tcenv; /* TERMCAP value, if it contais :tc=. */
345 const char *indirect = 0; /* Terminal type in :tc= in TERMCAP value. */ 356 CONST char *indirect = 0; /* Terminal type in :tc= in TERMCAP value. */
346 357
347 tem = getenv ("TERMCAP"); 358 tem = getenv ("TERMCAP");
348 if (tem && *tem == 0) tem = 0; 359 if (tem && *tem == 0) tem = 0;
349 360
350 361
352 it is a file name to use instead of /etc/termcap. 363 it is a file name to use instead of /etc/termcap.
353 If it is non-null and does not start with /, 364 If it is non-null and does not start with /,
354 it is the entry itself, but only if 365 it is the entry itself, but only if
355 the name the caller requested matches the TERM variable. */ 366 the name the caller requested matches the TERM variable. */
356 367
357 if (tem && !IS_DIRECTORY_SEP (*tem) && !strcmp (name, getenv ("TERM"))) 368 if (tem && !IS_DIRECTORY_SEP (*tem) && !strcmp (name, (char *) getenv ("TERM")))
358 { 369 {
359 indirect = tgetst1 (find_capability (tem, "tc"), 0); 370 indirect = tgetst1 (find_capability (tem, "tc"), 0);
360 if (!indirect) 371 if (!indirect)
361 { 372 {
362 if (!bp) 373 if (!bp)
635 printf ("co: %d\n", tgetnum ("co")); 646 printf ("co: %d\n", tgetnum ("co"));
636 printf ("am: %d\n", tgetflag ("am")); 647 printf ("am: %d\n", tgetflag ("am"));
637 } 648 }
638 649
639 tprint (cap) 650 tprint (cap)
640 const char *cap; 651 CONST char *cap;
641 { 652 {
642 char *x = tgetstr (cap, 0); 653 char *x = tgetstr (cap, 0);
643 char *y; 654 char *y;
644 655
645 printf ("%s: ", cap); 656 printf ("%s: ", cap);