annotate src/termcap.c @ 104:cf808b4c4290 r20-1b4

Import from CVS: tag r20-1b4
author cvs
date Mon, 13 Aug 2007 09:16:51 +0200
parents 376386a54a3c
children 41ff10fd062f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Work-alike for termcap, plus extra features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: Not synched with FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 /* config.h may rename various library functions such as malloc. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include "lisp.h" /* For encapsulated open, close, read */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include "device.h" /* For DEVICE_BAUD_RATE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #else /* not emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #if defined(USG) || defined(STDC_HEADERS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #define memcpy(d, s, n) memcpy ((d), (s), (n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #ifdef STDC_HEADERS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 char *getenv ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 char *malloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 char *realloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #ifdef HAVE_UNISTD_H
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #include <unistd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #ifdef _POSIX_VERSION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include <fcntl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #endif /* not emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 /* BUFSIZE is the initial size allocated for the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 for reading the termcap file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 It is not a limit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 Make it large normally for speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 Make it variable when debugging, so can exercise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 increasing the space dynamically. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 #ifndef BUFSIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #define BUFSIZE bufsize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 int bufsize = 128;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 #define BUFSIZE 2048
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 #ifndef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 memory_out ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 write (2, "virtual memory exhausted\n", 25);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 static char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 xmalloc (size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 unsigned int size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 char *tem = malloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 if (!tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 memory_out ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 return tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 static char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 xrealloc (ptr, size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 unsigned size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 char *tem = realloc (ptr, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 if (!tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 memory_out ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 return tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 #endif /* not emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 /* Looking up capabilities in the entry already found. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 /* The pointer to the data made by tgetent is left here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 for tgetnum, tgetflag and tgetstr to find. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 static char *term_entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 static CONST char *tgetst1 (CONST char *ptr, char **area);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 /* Search entry BP for capability CAP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 Return a pointer to the capability (in BP) if found,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 0 if not found. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 static CONST char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 find_capability (bp, cap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 CONST char *bp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 CONST char *cap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 for (; *bp; bp++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 if (bp[0] == ':'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 && bp[1] == cap[0]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 && bp[2] == cap[1])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 return &bp[4];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 tgetnum (cap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 CONST char *cap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 CONST char *ptr = find_capability (term_entry, cap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 if (!ptr || ptr[-1] != '#')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 return atoi (ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 tgetflag (cap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 CONST char *cap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 CONST char *ptr = find_capability (term_entry, cap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 return 0 != ptr && ptr[-1] == ':';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 /* Look up a string-valued capability CAP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 If AREA is nonzero, it points to a pointer to a block in which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 to store the string. That pointer is advanced over the space used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 If AREA is zero, space is allocated with `malloc'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 CONST char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 tgetstr (cap, area)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 CONST char *cap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 char **area;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 CONST char *ptr = find_capability (term_entry, cap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 if (!ptr || (ptr[-1] != '=' && ptr[-1] != '~'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 return tgetst1 (ptr, area);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 /* Table, indexed by a character in range 0100 to 0140 with 0100 subtracted,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 gives meaning of character following \, or a space if no special meaning.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 Eight characters per line within the string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 static char esctab[]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 = " \007\010 \033\014 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 " \012 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 " \015 \011 \013 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 " ";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 /* PTR points to a string value inside a termcap entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 Copy that value, processing \ and ^ abbreviations,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 into the block that *AREA points to,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 or to newly allocated storage if AREA is 0. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 static CONST char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 tgetst1 (ptr, area)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 CONST char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 char **area;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 CONST char *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 char *r;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 int c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 int size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 char *ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 int c1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 if (!ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 /* `ret' gets address of where to store the string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 if (!area)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 /* Compute size of block needed (may overestimate). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 p = ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 while ((c = *p++) && c != ':' && c != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ret = (char *) xmalloc (p - ptr + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ret = *area;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 /* Copy the string value, stopping at null or colon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 Also process ^ and \ abbreviations. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 p = ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 r = ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 while ((c = *p++) && c != ':' && c != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 if (c == '^')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 c = *p++ & 037;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 else if (c == '\\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 c = *p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 if (c >= '0' && c <= '7')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 c -= '0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 while (++size < 3 && (c1 = *p) >= '0' && c1 <= '7')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 c *= 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 c += c1 - '0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 else if (c >= 0100 && c < 0200)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 c1 = esctab[(c & ~040) - 0100];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 if (c1 != ' ')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 c = c1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 *r++ = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 *r = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 /* Update *AREA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 if (area)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 *area = r + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 return ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 /* Outputting a string with padding. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 #ifdef LINUX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 speed_t ospeed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 short ospeed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 /* If `ospeed' is 0, we use `tputs_baud_rate' as the actual baud rate. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 int tputs_baud_rate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 char PC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 /* Actual baud rate if positive;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 - baud rate / 100 if negative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 static short speeds[] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 0, 50, 75, 110, 134, 150, -3, -6, -12, -18,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 -20, -24, -36, -48, -72, -96, -192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 #else /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 0, 50, 75, 110, 135, 150, -2, -3, -6, -12,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 -18, -24, -48, -96, -192, -288, -384, -576, -1152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 #endif /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 tputs (string, nlines, outfun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 CONST char *string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 int nlines;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 void (*outfun) (int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 int padcount = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 int speed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 speed = DEVICE_BAUD_RATE (XDEVICE (Fselected_device (Qnil)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 if (ospeed == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 speed = tputs_baud_rate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 speed = speeds[ospeed];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 if (string == (char *) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 while (isdigit (* (CONST unsigned char *) string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 padcount += *string++ - '0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 padcount *= 10;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 if (*string == '.')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 string++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 padcount += *string++ - '0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 if (*string == '*')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 string++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 padcount *= nlines;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 while (*string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (*outfun) (*string++);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 /* padcount is now in units of tenths of msec. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 padcount *= speeds[ospeed];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 padcount += 500;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 padcount /= 1000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 if (speeds[ospeed] < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 padcount = -padcount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 padcount += 50;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 padcount /= 100;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 while (padcount-- > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (*outfun) (PC);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 /* Finding the termcap entry in the termcap data base. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 struct buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 char *beg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 int size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 int ateof;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 int full;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 /* Forward declarations of static functions. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 static int scan_file ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 static char *gobble_line ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 static int compare_contin ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 static int name_match ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 #include <rmsdef.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 #include <fab.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 #include <nam.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 legal_filename_p (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 char *fn;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 struct FAB fab = cc$rms_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 struct NAM nam = cc$rms_nam;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 char esa[NAM$C_MAXRSS];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 fab.fab$l_fna = fn;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 fab.fab$b_fns = strlen(fn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 fab.fab$l_nam = &nam;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 fab.fab$l_fop = FAB$M_NAM;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 nam.nam$l_esa = esa;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 nam.nam$b_ess = sizeof esa;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 return SYS$PARSE(&fab, 0, 0) == RMS$_NORMAL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 /* Find the termcap entry data for terminal type NAME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 and store it in the block that BP points to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 Record its address for future use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 If BP is zero, space is dynamically allocated. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 extern char *getenv ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 tgetent (bp, name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 char *bp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 CONST char *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 char *tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 struct buffer buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 char *bp1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 char *bp2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 CONST char *term;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 int malloc_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 int c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 char *tcenv; /* TERMCAP value, if it contais :tc=. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 CONST char *indirect = 0; /* Terminal type in :tc= in TERMCAP value. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 int filep;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 tem = getenv ("TERMCAP");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 if (tem && *tem == 0) tem = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 filep = tem && legal_filename_p (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 filep = tem && (*tem == '/');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 /* If tem is non-null and starts with / (in the un*x case, that is),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 it is a file name to use instead of /etc/termcap.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 If it is non-null and does not start with /,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 it is the entry itself, but only if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 the name the caller requested matches the TERM variable. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 if (tem && !filep && !strcmp (name, (char *) getenv ("TERM")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 indirect = tgetst1 (find_capability (tem, "tc"), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 if (!indirect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 if (!bp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 bp = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 strcpy (bp, tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 goto ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 { /* We will need to read /etc/termcap. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 tcenv = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 tem = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 indirect = (char *) 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 if (!tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 tem = "emacs_library:[etc]termcap.dat";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 tem = "/etc/termcap";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 /* Here we know we must search a file and tem has its name. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 fd = open (tem, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 if (fd < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 buf.size = BUFSIZE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 /* Add 1 to size to ensure room for terminating null. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 buf.beg = (char *) xmalloc (buf.size + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 term = indirect ? indirect : name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 if (!bp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 malloc_size = indirect ? strlen (tcenv) + 1 : buf.size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 bp = (char *) xmalloc (malloc_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 bp1 = bp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 if (indirect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 /* Copy the data from the environment variable. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 strcpy (bp, tcenv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 bp1 += strlen (tcenv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 while (term)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 /* Scan the file, reading it via buf, till find start of main entry. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 if (scan_file (term, fd, &buf) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 /* Free old `term' if appropriate. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 if (term != name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 xfree (term);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 /* If BP is malloc'd by us, make sure it is big enough. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 if (malloc_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 malloc_size = bp1 - bp + buf.size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 tem = (char *) xrealloc (bp, malloc_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 bp1 += tem - bp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 bp = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 bp2 = bp1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 /* Copy the line of the entry from buf into bp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 tem = buf.ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 while ((*bp1++ = c = *tem++) && c != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 /* Drop out any \ newline sequence. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 if (c == '\\' && *tem == '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 bp1--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 tem++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 *bp1 = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 /* Does this entry refer to another terminal type's entry?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 If something is found, copy it into heap and null-terminate it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 term = tgetst1 (find_capability (bp2, "tc"), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 xfree (buf.beg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 if (malloc_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 bp = (char *) xrealloc (bp, bp1 - bp + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 ret:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 term_entry = bp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 if (malloc_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 /* #### yuck, why the hell are we casting a pointer to an int? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 return (int) (long) bp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 /* Given file open on FD and buffer BUFP,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 scan the file from the beginning until a line is found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 that starts the entry for terminal type STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 Returns 1 if successful, with that line in BUFP,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 or returns 0 if no entry found in the file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 scan_file (string, fd, bufp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 char *string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 struct buffer *bufp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 char *end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 bufp->ptr = bufp->beg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 bufp->full = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 bufp->ateof = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 *bufp->ptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 lseek (fd, 0L, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 while (!bufp->ateof)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 /* Read a line into the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 end = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 /* if it is continued, append another line to it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 until a non-continued line ends. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 end = gobble_line (fd, bufp, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 while (!bufp->ateof && end[-2] == '\\');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 if (*bufp->ptr != '#'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 && name_match (bufp->ptr, string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 /* Discard the line just processed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 bufp->ptr = end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 /* Return nonzero if NAME is one of the names specified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 by termcap entry LINE. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 name_match (line, name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 char *line, *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 char *tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 if (!compare_contin (line, name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 /* This line starts an entry. Is it the right one? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 for (tem = line; *tem && *tem != '\n' && *tem != ':'; tem++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 if (*tem == '|' && !compare_contin (tem + 1, name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 compare_contin (str1, str2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 char *str1, *str2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 int c1, c2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 c1 = *str1++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 c2 = *str2++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 while (c1 == '\\' && *str1 == '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 str1++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 while ((c1 = *str1++) == ' ' || c1 == '\t');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 if (c2 == '\0')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 /* End of type being looked up. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 if (c1 == '|' || c1 == ':')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 /* If end of name in data base, we win. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 else if (c1 != c2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 /* Make sure that the buffer <- BUFP contains a full line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 of the file open on FD, starting at the place BUFP->ptr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 points to. Can read more of the file, discard stuff before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 BUFP->ptr, or make the buffer bigger.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 Returns the pointer to after the newline ending the line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 or to the end of the file, if there is no newline to end it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 Can also merge on continuation lines. If APPEND_END is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 nonzero, it points past the newline of a line that is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 continued; we add another line onto it and regard the whole
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 thing as one line. The caller decides when a line is continued. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 static char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 gobble_line (fd, bufp, append_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 struct buffer *bufp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 char *append_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 char *end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 int nread;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 char *buf = bufp->beg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 char *tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 if (append_end == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 append_end = bufp->ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 end = append_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 while (*end && *end != '\n') end++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 if (*end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 if (bufp->ateof)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 return buf + bufp->full;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 if (bufp->ptr == buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 if (bufp->full == bufp->size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 bufp->size *= 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 /* Add 1 to size to ensure room for terminating null. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 tem = (char *) xrealloc (buf, bufp->size + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 bufp->ptr = (bufp->ptr - buf) + tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 append_end = (append_end - buf) + tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 bufp->beg = buf = tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 append_end -= bufp->ptr - buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 memcpy (buf, bufp->ptr, bufp->full -= bufp->ptr - buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 bufp->ptr = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 if (!(nread = read (fd, buf + bufp->full, bufp->size - bufp->full)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 bufp->ateof = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 bufp->full += nread;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 buf[bufp->full] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 return end + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 #ifdef TEST
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 main (argc, argv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 int argc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 char **argv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 char *term;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 char *buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 term = argv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 printf ("TERM: %s\n", term);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 buf = (char *) tgetent (0, term);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 if ((int) buf <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 printf ("No entry.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 printf ("Entry: %s\n", buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 tprint ("cm");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 tprint ("AL");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 printf ("co: %d\n", tgetnum ("co"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 printf ("am: %d\n", tgetflag ("am"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 tprint (cap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 CONST char *cap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 char *x = tgetstr (cap, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 char *y;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 printf ("%s: ", cap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 if (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 for (y = x; *y; y++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 if (*y <= ' ' || *y == 0177)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 printf ("\\%0o", *y);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 putchar (*y);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 xfree (x);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 printf ("none");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 putchar ('\n');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 #endif /* TEST */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713