annotate src/termcap.c @ 5902:2dc8711af537

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