annotate src/termcap.c @ 450:98528da0b7fc r21-2-40

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