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