Mercurial > emacs
annotate src/termcap.c @ 110734:72f46bad930c
Include <fcntl.h> unconditionally.
* src/termcap.c:
* src/sysdep.c:
* src/lread.c:
* src/keyboard.c:
* src/filelock.c:
* src/fileio.c:
* src/doc.c:
* src/callproc.c:
* src/alloc.c: Remove include guards for <fcntl.h>, process.c already
does it.
| author | Dan Nicolaescu <dann@ics.uci.edu> |
|---|---|
| date | Sun, 03 Oct 2010 08:19:34 -0700 |
| parents | 76e072dbe342 |
| children | 2b72330aa98a |
| rev | line source |
|---|---|
| 7306 | 1 /* Work-alike for termcap, plus extra features. |
|
64770
a0d1312ede66
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
2 Copyright (C) 1985, 1986, 1993, 1994, 1995, 2000, 2001, 2002, 2003, |
|
100960
69177b934405
Revert copyright year changes for files that are not part of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
100951
diff
changeset
|
3 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
| 7306 | 4 |
| 5 This program is free software; you can redistribute it and/or modify | |
| 6 it under the terms of the GNU General Public License as published by | |
| 7 the Free Software Foundation; either version 2, or (at your option) | |
| 8 any later version. | |
| 9 | |
| 10 This program is distributed in the hope that it will be useful, | |
| 11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 GNU General Public License for more details. | |
| 14 | |
| 15 You should have received a copy of the GNU General Public License | |
| 16 along with this program; see the file COPYING. If not, write to | |
| 64084 | 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 Boston, MA 02110-1301, USA. */ | |
| 7306 | 19 |
| 20 /* Emacs config.h may rename various library functions such as malloc. */ | |
|
12994
bd38619285f7
Don't assume that HAVE_CONFIG_H implies emacs.
David J. MacKenzie <djm@gnu.org>
parents:
12907
diff
changeset
|
21 #include <config.h> |
|
105669
68dd71358159
* alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100960
diff
changeset
|
22 #include <setjmp.h> |
|
29804
d8776351a540
[emacs] Test HAVE_FCNTL_H, not USG5. Include lisp.h and unistd.h.
Dave Love <fx@gnu.org>
parents:
23071
diff
changeset
|
23 #include <lisp.h> /* xmalloc is here */ |
| 7785 | 24 /* Get the O_* definitions for open et al. */ |
| 25 #include <sys/file.h> | |
| 26 #include <fcntl.h> | |
|
29804
d8776351a540
[emacs] Test HAVE_FCNTL_H, not USG5. Include lisp.h and unistd.h.
Dave Love <fx@gnu.org>
parents:
23071
diff
changeset
|
27 #ifdef HAVE_UNISTD_H |
|
d8776351a540
[emacs] Test HAVE_FCNTL_H, not USG5. Include lisp.h and unistd.h.
Dave Love <fx@gnu.org>
parents:
23071
diff
changeset
|
28 #include <unistd.h> |
|
d8776351a540
[emacs] Test HAVE_FCNTL_H, not USG5. Include lisp.h and unistd.h.
Dave Love <fx@gnu.org>
parents:
23071
diff
changeset
|
29 #endif |
| 7785 | 30 |
| 7306 | 31 #ifndef NULL |
| 32 #define NULL (char *) 0 | |
| 33 #endif | |
| 34 | |
| 7685 | 35 #ifndef O_RDONLY |
| 36 #define O_RDONLY 0 | |
| 37 #endif | |
| 38 | |
| 7306 | 39 /* BUFSIZE is the initial size allocated for the buffer |
| 40 for reading the termcap file. | |
| 41 It is not a limit. | |
| 42 Make it large normally for speed. | |
| 43 Make it variable when debugging, so can exercise | |
| 44 increasing the space dynamically. */ | |
| 45 | |
| 46 #ifndef BUFSIZE | |
| 47 #ifdef DEBUG | |
| 48 #define BUFSIZE bufsize | |
| 49 | |
| 50 int bufsize = 128; | |
| 51 #else | |
| 52 #define BUFSIZE 2048 | |
| 53 #endif | |
| 54 #endif | |
| 55 | |
|
12679
a14b26e55f25
TERMCAP_NAME -> TERMCAP_FILE.
David J. MacKenzie <djm@gnu.org>
parents:
12675
diff
changeset
|
56 #ifndef TERMCAP_FILE |
|
a14b26e55f25
TERMCAP_NAME -> TERMCAP_FILE.
David J. MacKenzie <djm@gnu.org>
parents:
12675
diff
changeset
|
57 #define TERMCAP_FILE "/etc/termcap" |
| 7306 | 58 #endif |
| 59 | |
| 60 | |
| 61 /* Looking up capabilities in the entry already found. */ | |
| 62 | |
| 63 /* The pointer to the data made by tgetent is left here | |
| 64 for tgetnum, tgetflag and tgetstr to find. */ | |
| 65 static char *term_entry; | |
| 66 | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
67 static char *tgetst1 (char *ptr, char **area); |
| 7306 | 68 |
| 69 /* Search entry BP for capability CAP. | |
| 70 Return a pointer to the capability (in BP) if found, | |
| 71 0 if not found. */ | |
| 72 | |
| 73 static char * | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
74 find_capability (register char *bp, register char *cap) |
| 7306 | 75 { |
| 76 for (; *bp; bp++) | |
| 77 if (bp[0] == ':' | |
| 78 && bp[1] == cap[0] | |
| 79 && bp[2] == cap[1]) | |
| 80 return &bp[4]; | |
| 81 return NULL; | |
| 82 } | |
| 83 | |
| 84 int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
85 tgetnum (char *cap) |
| 7306 | 86 { |
| 87 register char *ptr = find_capability (term_entry, cap); | |
| 88 if (!ptr || ptr[-1] != '#') | |
| 89 return -1; | |
| 90 return atoi (ptr); | |
| 91 } | |
| 92 | |
| 93 int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
94 tgetflag (char *cap) |
| 7306 | 95 { |
| 96 register char *ptr = find_capability (term_entry, cap); | |
| 97 return ptr && ptr[-1] == ':'; | |
| 98 } | |
| 99 | |
| 100 /* Look up a string-valued capability CAP. | |
| 101 If AREA is non-null, it points to a pointer to a block in which | |
| 102 to store the string. That pointer is advanced over the space used. | |
| 103 If AREA is null, space is allocated with `malloc'. */ | |
| 104 | |
| 105 char * | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
106 tgetstr (char *cap, char **area) |
| 7306 | 107 { |
| 108 register char *ptr = find_capability (term_entry, cap); | |
| 109 if (!ptr || (ptr[-1] != '=' && ptr[-1] != '~')) | |
| 110 return NULL; | |
| 111 return tgetst1 (ptr, area); | |
| 112 } | |
| 113 | |
|
23071
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
114 #ifdef IS_EBCDIC_HOST |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
115 /* Table, indexed by a character in range 0200 to 0300 with 0200 subtracted, |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
116 gives meaning of character following \, or a space if no special meaning. |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
117 Sixteen characters per line within the string. */ |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
118 |
|
105959
ba3ffbd9c422
* process.c (ifflag_def): Make flag_sym constant.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
119 static const char esctab[] |
|
23071
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
120 = " \057\026 \047\014 \ |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
121 \025 \015 \ |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
122 \005 \013 \ |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
123 "; |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
124 #else |
| 7306 | 125 /* Table, indexed by a character in range 0100 to 0140 with 0100 subtracted, |
| 126 gives meaning of character following \, or a space if no special meaning. | |
| 127 Eight characters per line within the string. */ | |
| 128 | |
|
105959
ba3ffbd9c422
* process.c (ifflag_def): Make flag_sym constant.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
129 static const char esctab[] |
| 7306 | 130 = " \007\010 \033\014 \ |
| 131 \012 \ | |
| 132 \015 \011 \013 \ | |
| 133 "; | |
|
23071
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
134 #endif |
| 7306 | 135 |
| 136 /* PTR points to a string value inside a termcap entry. | |
| 137 Copy that value, processing \ and ^ abbreviations, | |
| 138 into the block that *AREA points to, | |
| 139 or to newly allocated storage if AREA is NULL. | |
| 140 Return the address to which we copied the value, | |
| 141 or NULL if PTR is NULL. */ | |
| 142 | |
| 143 static char * | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
144 tgetst1 (char *ptr, char **area) |
| 7306 | 145 { |
| 146 register char *p, *r; | |
| 147 register int c; | |
| 148 register int size; | |
| 149 char *ret; | |
| 150 register int c1; | |
| 151 | |
| 152 if (!ptr) | |
| 153 return NULL; | |
| 154 | |
| 155 /* `ret' gets address of where to store the string. */ | |
| 156 if (!area) | |
| 157 { | |
| 158 /* Compute size of block needed (may overestimate). */ | |
| 159 p = ptr; | |
| 160 while ((c = *p++) && c != ':' && c != '\n') | |
| 161 ; | |
| 162 ret = (char *) xmalloc (p - ptr + 1); | |
| 163 } | |
| 164 else | |
| 165 ret = *area; | |
| 166 | |
| 167 /* Copy the string value, stopping at null or colon. | |
| 168 Also process ^ and \ abbreviations. */ | |
| 169 p = ptr; | |
| 170 r = ret; | |
| 171 while ((c = *p++) && c != ':' && c != '\n') | |
| 172 { | |
| 173 if (c == '^') | |
|
10186
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
174 { |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
175 c = *p++; |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
176 if (c == '?') |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
177 c = 0177; |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
178 else |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
179 c &= 037; |
|
af0b61d21a8f
(tgetst1): Let ^? stand for DEL character.
Richard M. Stallman <rms@gnu.org>
parents:
7785
diff
changeset
|
180 } |
| 7306 | 181 else if (c == '\\') |
| 182 { | |
| 183 c = *p++; | |
| 184 if (c >= '0' && c <= '7') | |
| 185 { | |
| 186 c -= '0'; | |
| 187 size = 0; | |
| 188 | |
| 189 while (++size < 3 && (c1 = *p) >= '0' && c1 <= '7') | |
| 190 { | |
| 191 c *= 8; | |
| 192 c += c1 - '0'; | |
| 193 p++; | |
| 194 } | |
| 195 } | |
|
23071
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
196 #ifdef IS_EBCDIC_HOST |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
197 else if (c >= 0200 && c < 0360) |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
198 { |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
199 c1 = esctab[(c & ~0100) - 0200]; |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
200 if (c1 != ' ') |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
201 c = c1; |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
202 } |
|
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
203 #else |
| 7306 | 204 else if (c >= 0100 && c < 0200) |
| 205 { | |
| 206 c1 = esctab[(c & ~040) - 0100]; | |
| 207 if (c1 != ' ') | |
| 208 c = c1; | |
| 209 } | |
|
23071
3790e185acc0
(tgetst1): Supprt EBCDIC systems.
Richard M. Stallman <rms@gnu.org>
parents:
22066
diff
changeset
|
210 #endif |
| 7306 | 211 } |
| 212 *r++ = c; | |
| 213 } | |
|
53306
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
214 |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
215 /* Sometimes entries have "%pN" which means use parameter N in the |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
216 next %-substitution. If all such N are continuous in the range |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
217 [1,9] we can remove each "%pN" because they are redundant, thus |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
218 reducing bandwidth requirements. True, Emacs is well beyond the |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
219 days of 150baud teletypes, but some of its users aren't much so. |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
220 |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
221 This pass could probably be integrated into the one above but |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
222 abbreviation expansion makes that effort a little more hairy than |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
223 its worth; this is cleaner. */ |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
224 { |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
225 register int last_p_param = 0; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
226 int remove_p_params = 1; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
227 struct { char *beg; int len; } cut[11]; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
228 |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
229 for (cut[0].beg = p = ret; p < r - 3; p++) |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
230 { |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
231 if (!remove_p_params) |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
232 break; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
233 if (*p == '%' && *(p + 1) == 'p') |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
234 { |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
235 if (*(p + 2) - '0' == 1 + last_p_param) |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
236 { |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
237 cut[last_p_param].len = p - cut[last_p_param].beg; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
238 last_p_param++; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
239 p += 3; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
240 cut[last_p_param].beg = p; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
241 } |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
242 else /* not continuous: bail */ |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
243 remove_p_params = 0; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
244 if (last_p_param > 10) /* too many: bail */ |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
245 remove_p_params = 0; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
246 } |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
247 } |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
248 if (remove_p_params && last_p_param) |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
249 { |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
250 register int i; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
251 char *wp; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
252 |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
253 cut[last_p_param].len = r - cut[last_p_param].beg; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
254 for (i = 0, wp = ret; i <= last_p_param; wp += cut[i++].len) |
|
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
255 memcpy (wp, cut[i].beg, cut[i].len); |
|
53306
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
256 r = wp; |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
257 } |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
258 } |
|
9e78a65be39a
(tgetst1): Scan for "%pN"; if all
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
259 |
| 7306 | 260 *r = '\0'; |
| 261 /* Update *AREA. */ | |
| 262 if (area) | |
| 263 *area = r + 1; | |
| 264 return ret; | |
| 265 } | |
| 266 | |
| 267 /* Outputting a string with padding. */ | |
| 268 | |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
269 #ifndef emacs |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
270 short ospeed; |
| 7306 | 271 /* If OSPEED is 0, we use this as the actual baud rate. */ |
| 272 int tputs_baud_rate; | |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
273 #endif |
|
44890
01b93e5e53a7
Patch for building Emacs on Mac OS X. April 26, 2002. See ChangeLog,
Andrew Choi <akochoi@shaw.ca>
parents:
43713
diff
changeset
|
274 |
| 7306 | 275 char PC; |
| 276 | |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
277 #ifndef emacs |
| 7306 | 278 /* Actual baud rate if positive; |
| 279 - baud rate / 100 if negative. */ | |
| 280 | |
|
105959
ba3ffbd9c422
* process.c (ifflag_def): Make flag_sym constant.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
281 static const int speeds[] = |
| 7306 | 282 { |
| 283 0, 50, 75, 110, 135, 150, -2, -3, -6, -12, | |
|
10739
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
284 -18, -24, -48, -96, -192, -288, -384, -576, -1152 |
| 7306 | 285 }; |
| 286 | |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
287 #endif /* not emacs */ |
| 37864 | 288 |
| 7306 | 289 void |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
290 tputs (register char *str, int nlines, register int (*outfun) (/* ??? */)) |
| 7306 | 291 { |
| 292 register int padcount = 0; | |
| 293 register int speed; | |
| 294 | |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
295 #ifdef emacs |
|
43713
f92c4d87863a
Change defvar_int def and vars to use EMACS_INT instead of just int.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43674
diff
changeset
|
296 extern EMACS_INT baud_rate; |
| 7306 | 297 speed = baud_rate; |
|
10739
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
298 /* For quite high speeds, convert to the smaller |
|
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
299 units to avoid overflow. */ |
|
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
300 if (speed > 10000) |
|
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
301 speed = - speed / 100; |
|
43674
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
302 #else |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
303 if (ospeed == 0) |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
304 speed = tputs_baud_rate; |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
305 else |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
306 speed = speeds[ospeed]; |
|
53deca397c95
[!emacs]: Replace ospeed for building standalone
Richard M. Stallman <rms@gnu.org>
parents:
37864
diff
changeset
|
307 #endif |
| 7306 | 308 |
| 309 if (!str) | |
| 310 return; | |
| 311 | |
| 312 while (*str >= '0' && *str <= '9') | |
| 313 { | |
| 314 padcount += *str++ - '0'; | |
| 315 padcount *= 10; | |
| 316 } | |
| 317 if (*str == '.') | |
| 318 { | |
| 319 str++; | |
| 320 padcount += *str++ - '0'; | |
| 321 } | |
| 322 if (*str == '*') | |
| 323 { | |
| 324 str++; | |
| 325 padcount *= nlines; | |
| 326 } | |
| 327 while (*str) | |
| 328 (*outfun) (*str++); | |
| 329 | |
|
10739
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
330 /* PADCOUNT is now in units of tenths of msec. |
| 10753 | 331 SPEED is measured in characters per 10 seconds |
|
10739
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
332 or in characters per .1 seconds (if negative). |
|
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
333 We use the smaller units for larger speeds to avoid overflow. */ |
|
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
334 padcount *= speed; |
| 7306 | 335 padcount += 500; |
| 336 padcount /= 1000; | |
|
10739
97096cdf6e55
(speeds): Make it ints. Add some higher speeds.
Richard M. Stallman <rms@gnu.org>
parents:
10186
diff
changeset
|
337 if (speed < 0) |
| 7306 | 338 padcount = -padcount; |
| 339 else | |
| 340 { | |
| 341 padcount += 50; | |
| 342 padcount /= 100; | |
| 343 } | |
| 344 | |
| 345 while (padcount-- > 0) | |
| 346 (*outfun) (PC); | |
| 347 } | |
| 348 | |
| 349 /* Finding the termcap entry in the termcap data base. */ | |
| 350 | |
|
22066
a09f2b697d0a
Renamed "struct buffer" to "struct termcap_buffer" to
Richard M. Stallman <rms@gnu.org>
parents:
14414
diff
changeset
|
351 struct termcap_buffer |
| 7306 | 352 { |
| 353 char *beg; | |
| 354 int size; | |
| 355 char *ptr; | |
| 356 int ateof; | |
| 357 int full; | |
| 358 }; | |
| 359 | |
| 360 /* Forward declarations of static functions. */ | |
| 361 | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
362 static int scan_file (char *str, int fd, register struct termcap_buffer *bufp); |
|
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
363 static char *gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end); |
|
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
364 static int compare_contin (register char *str1, register char *str2); |
|
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
365 static int name_match (char *line, char *name); |
| 7306 | 366 |
| 367 #ifdef MSDOS /* MW, May 1993 */ | |
| 368 static int | |
| 369 valid_filename_p (fn) | |
| 370 char *fn; | |
| 371 { | |
| 372 return *fn == '/' || fn[1] == ':'; | |
| 373 } | |
| 374 #else | |
| 375 #define valid_filename_p(fn) (*(fn) == '/') | |
| 376 #endif | |
| 377 | |
| 378 /* Find the termcap entry data for terminal type NAME | |
| 379 and store it in the block that BP points to. | |
| 380 Record its address for future use. | |
| 381 | |
| 382 If BP is null, space is dynamically allocated. | |
| 383 | |
| 384 Return -1 if there is some difficulty accessing the data base | |
| 385 of terminal types, | |
| 386 0 if the data base is accessible but the type NAME is not defined | |
| 387 in it, and some other value otherwise. */ | |
| 388 | |
| 389 int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
390 tgetent (char *bp, char *name) |
| 7306 | 391 { |
| 392 register char *termcap_name; | |
| 393 register int fd; | |
|
22066
a09f2b697d0a
Renamed "struct buffer" to "struct termcap_buffer" to
Richard M. Stallman <rms@gnu.org>
parents:
14414
diff
changeset
|
394 struct termcap_buffer buf; |
| 7306 | 395 register char *bp1; |
|
14132
85063feb159b
(tgetent): Find all the tc caps that there are.
Karl Heuer <kwzh@gnu.org>
parents:
13677
diff
changeset
|
396 char *tc_search_point; |
| 7306 | 397 char *term; |
| 398 int malloc_size = 0; | |
| 399 register int c; | |
| 33616 | 400 char *tcenv = NULL; /* TERMCAP value, if it contains :tc=. */ |
| 7306 | 401 char *indirect = NULL; /* Terminal type in :tc= in TERMCAP value. */ |
| 402 int filep; | |
| 403 | |
| 404 #ifdef INTERNAL_TERMINAL | |
| 405 /* For the internal terminal we don't want to read any termcap file, | |
| 406 so fake it. */ | |
| 407 if (!strcmp (name, "internal")) | |
| 408 { | |
| 409 term = INTERNAL_TERMINAL; | |
| 410 if (!bp) | |
| 411 { | |
| 412 malloc_size = 1 + strlen (term); | |
| 413 bp = (char *) xmalloc (malloc_size); | |
| 414 } | |
| 415 strcpy (bp, term); | |
| 416 goto ret; | |
| 417 } | |
| 418 #endif /* INTERNAL_TERMINAL */ | |
| 419 | |
|
12907
6cae53a06172
default to user-supplied buffer.
David J. MacKenzie <djm@gnu.org>
parents:
12679
diff
changeset
|
420 /* For compatibility with programs like `less' that want to |
|
6cae53a06172
default to user-supplied buffer.
David J. MacKenzie <djm@gnu.org>
parents:
12679
diff
changeset
|
421 put data in the termcap buffer themselves as a fallback. */ |
|
6cae53a06172
default to user-supplied buffer.
David J. MacKenzie <djm@gnu.org>
parents:
12679
diff
changeset
|
422 if (bp) |
|
6cae53a06172
default to user-supplied buffer.
David J. MacKenzie <djm@gnu.org>
parents:
12679
diff
changeset
|
423 term_entry = bp; |
|
6cae53a06172
default to user-supplied buffer.
David J. MacKenzie <djm@gnu.org>
parents:
12679
diff
changeset
|
424 |
| 7306 | 425 termcap_name = getenv ("TERMCAP"); |
| 426 if (termcap_name && *termcap_name == '\0') | |
| 427 termcap_name = NULL; | |
| 428 #if defined (MSDOS) && !defined (TEST) | |
| 429 if (termcap_name && (*termcap_name == '\\' | |
| 430 || *termcap_name == '/' | |
| 431 || termcap_name[1] == ':')) | |
| 432 dostounix_filename(termcap_name); | |
| 433 #endif | |
| 434 | |
| 435 filep = termcap_name && valid_filename_p (termcap_name); | |
| 436 | |
| 437 /* If termcap_name is non-null and starts with / (in the un*x case, that is), | |
| 438 it is a file name to use instead of /etc/termcap. | |
| 439 If it is non-null and does not start with /, | |
| 440 it is the entry itself, but only if | |
| 441 the name the caller requested matches the TERM variable. */ | |
| 442 | |
| 443 if (termcap_name && !filep && !strcmp (name, getenv ("TERM"))) | |
| 444 { | |
| 445 indirect = tgetst1 (find_capability (termcap_name, "tc"), (char **) 0); | |
| 446 if (!indirect) | |
| 447 { | |
| 448 if (!bp) | |
| 449 bp = termcap_name; | |
| 450 else | |
| 451 strcpy (bp, termcap_name); | |
| 452 goto ret; | |
| 453 } | |
| 454 else | |
| 455 { /* It has tc=. Need to read /etc/termcap. */ | |
| 456 tcenv = termcap_name; | |
| 457 termcap_name = NULL; | |
| 458 } | |
| 459 } | |
| 460 | |
| 461 if (!termcap_name || !filep) | |
|
12679
a14b26e55f25
TERMCAP_NAME -> TERMCAP_FILE.
David J. MacKenzie <djm@gnu.org>
parents:
12675
diff
changeset
|
462 termcap_name = TERMCAP_FILE; |
| 7306 | 463 |
| 464 /* Here we know we must search a file and termcap_name has its name. */ | |
| 465 | |
| 466 #ifdef MSDOS | |
| 7685 | 467 fd = open (termcap_name, O_RDONLY|O_TEXT, 0); |
| 7306 | 468 #else |
| 7685 | 469 fd = open (termcap_name, O_RDONLY, 0); |
| 7306 | 470 #endif |
| 471 if (fd < 0) | |
| 472 return -1; | |
| 473 | |
| 474 buf.size = BUFSIZE; | |
| 475 /* Add 1 to size to ensure room for terminating null. */ | |
| 476 buf.beg = (char *) xmalloc (buf.size + 1); | |
| 477 term = indirect ? indirect : name; | |
| 478 | |
| 479 if (!bp) | |
| 480 { | |
| 481 malloc_size = indirect ? strlen (tcenv) + 1 : buf.size; | |
| 482 bp = (char *) xmalloc (malloc_size); | |
| 483 } | |
|
14132
85063feb159b
(tgetent): Find all the tc caps that there are.
Karl Heuer <kwzh@gnu.org>
parents:
13677
diff
changeset
|
484 tc_search_point = bp1 = bp; |
| 7306 | 485 |
| 486 if (indirect) | |
| 487 /* Copy the data from the environment variable. */ | |
| 488 { | |
| 489 strcpy (bp, tcenv); | |
| 490 bp1 += strlen (tcenv); | |
| 491 } | |
| 492 | |
| 493 while (term) | |
| 494 { | |
| 495 /* Scan the file, reading it via buf, till find start of main entry. */ | |
| 496 if (scan_file (term, fd, &buf) == 0) | |
| 497 { | |
| 498 close (fd); | |
| 499 free (buf.beg); | |
| 500 if (malloc_size) | |
| 501 free (bp); | |
| 502 return 0; | |
| 503 } | |
| 504 | |
| 505 /* Free old `term' if appropriate. */ | |
| 506 if (term != name) | |
| 507 free (term); | |
| 508 | |
| 509 /* If BP is malloc'd by us, make sure it is big enough. */ | |
| 510 if (malloc_size) | |
| 511 { | |
|
34358
aa3b69684dbf
(tgetent): Change the way buffers are reallocated to
Gerd Moellmann <gerd@gnu.org>
parents:
33616
diff
changeset
|
512 int offset1 = bp1 - bp, offset2 = tc_search_point - bp; |
|
aa3b69684dbf
(tgetent): Change the way buffers are reallocated to
Gerd Moellmann <gerd@gnu.org>
parents:
33616
diff
changeset
|
513 malloc_size = offset1 + buf.size; |
|
aa3b69684dbf
(tgetent): Change the way buffers are reallocated to
Gerd Moellmann <gerd@gnu.org>
parents:
33616
diff
changeset
|
514 bp = termcap_name = (char *) xrealloc (bp, malloc_size); |
|
aa3b69684dbf
(tgetent): Change the way buffers are reallocated to
Gerd Moellmann <gerd@gnu.org>
parents:
33616
diff
changeset
|
515 bp1 = termcap_name + offset1; |
|
aa3b69684dbf
(tgetent): Change the way buffers are reallocated to
Gerd Moellmann <gerd@gnu.org>
parents:
33616
diff
changeset
|
516 tc_search_point = termcap_name + offset2; |
| 7306 | 517 } |
| 518 | |
| 519 /* Copy the line of the entry from buf into bp. */ | |
| 520 termcap_name = buf.ptr; | |
| 521 while ((*bp1++ = c = *termcap_name++) && c != '\n') | |
| 522 /* Drop out any \ newline sequence. */ | |
| 523 if (c == '\\' && *termcap_name == '\n') | |
| 524 { | |
| 525 bp1--; | |
| 526 termcap_name++; | |
| 527 } | |
| 528 *bp1 = '\0'; | |
| 529 | |
| 530 /* Does this entry refer to another terminal type's entry? | |
| 531 If something is found, copy it into heap and null-terminate it. */ | |
|
14132
85063feb159b
(tgetent): Find all the tc caps that there are.
Karl Heuer <kwzh@gnu.org>
parents:
13677
diff
changeset
|
532 tc_search_point = find_capability (tc_search_point, "tc"); |
|
85063feb159b
(tgetent): Find all the tc caps that there are.
Karl Heuer <kwzh@gnu.org>
parents:
13677
diff
changeset
|
533 term = tgetst1 (tc_search_point, (char **) 0); |
| 7306 | 534 } |
| 535 | |
| 536 close (fd); | |
| 537 free (buf.beg); | |
| 538 | |
| 539 if (malloc_size) | |
| 540 bp = (char *) xrealloc (bp, bp1 - bp + 1); | |
| 541 | |
| 542 ret: | |
| 543 term_entry = bp; | |
| 544 return 1; | |
| 545 } | |
| 546 | |
| 547 /* Given file open on FD and buffer BUFP, | |
| 548 scan the file from the beginning until a line is found | |
| 549 that starts the entry for terminal type STR. | |
| 550 Return 1 if successful, with that line in BUFP, | |
| 551 or 0 if no entry is found in the file. */ | |
| 552 | |
| 553 static int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
554 scan_file (char *str, int fd, register struct termcap_buffer *bufp) |
| 7306 | 555 { |
| 556 register char *end; | |
| 557 | |
| 558 bufp->ptr = bufp->beg; | |
| 559 bufp->full = 0; | |
| 560 bufp->ateof = 0; | |
| 561 *bufp->ptr = '\0'; | |
| 562 | |
| 563 lseek (fd, 0L, 0); | |
| 564 | |
| 565 while (!bufp->ateof) | |
| 566 { | |
| 567 /* Read a line into the buffer. */ | |
| 568 end = NULL; | |
| 569 do | |
| 570 { | |
| 571 /* if it is continued, append another line to it, | |
| 572 until a non-continued line ends. */ | |
| 573 end = gobble_line (fd, bufp, end); | |
| 574 } | |
| 575 while (!bufp->ateof && end[-2] == '\\'); | |
| 576 | |
| 577 if (*bufp->ptr != '#' | |
| 578 && name_match (bufp->ptr, str)) | |
| 579 return 1; | |
| 580 | |
| 581 /* Discard the line just processed. */ | |
| 582 bufp->ptr = end; | |
| 583 } | |
| 584 return 0; | |
| 585 } | |
| 586 | |
| 587 /* Return nonzero if NAME is one of the names specified | |
| 588 by termcap entry LINE. */ | |
| 589 | |
| 590 static int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
591 name_match (char *line, char *name) |
| 7306 | 592 { |
| 593 register char *tem; | |
| 594 | |
| 595 if (!compare_contin (line, name)) | |
| 596 return 1; | |
| 597 /* This line starts an entry. Is it the right one? */ | |
| 598 for (tem = line; *tem && *tem != '\n' && *tem != ':'; tem++) | |
| 599 if (*tem == '|' && !compare_contin (tem + 1, name)) | |
| 600 return 1; | |
| 601 | |
| 602 return 0; | |
| 603 } | |
| 604 | |
| 605 static int | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
606 compare_contin (register char *str1, register char *str2) |
| 7306 | 607 { |
| 608 register int c1, c2; | |
| 609 while (1) | |
| 610 { | |
| 611 c1 = *str1++; | |
| 612 c2 = *str2++; | |
| 613 while (c1 == '\\' && *str1 == '\n') | |
| 614 { | |
| 615 str1++; | |
| 616 while ((c1 = *str1++) == ' ' || c1 == '\t'); | |
| 617 } | |
| 618 if (c2 == '\0') | |
| 619 { | |
| 620 /* End of type being looked up. */ | |
| 621 if (c1 == '|' || c1 == ':') | |
| 622 /* If end of name in data base, we win. */ | |
| 623 return 0; | |
| 624 else | |
| 625 return 1; | |
| 626 } | |
| 627 else if (c1 != c2) | |
| 628 return 1; | |
| 629 } | |
| 630 } | |
| 631 | |
| 632 /* Make sure that the buffer <- BUFP contains a full line | |
| 633 of the file open on FD, starting at the place BUFP->ptr | |
| 634 points to. Can read more of the file, discard stuff before | |
| 635 BUFP->ptr, or make the buffer bigger. | |
| 636 | |
| 637 Return the pointer to after the newline ending the line, | |
| 638 or to the end of the file, if there is no newline to end it. | |
| 639 | |
| 640 Can also merge on continuation lines. If APPEND_END is | |
| 641 non-null, it points past the newline of a line that is | |
| 642 continued; we add another line onto it and regard the whole | |
| 643 thing as one line. The caller decides when a line is continued. */ | |
| 644 | |
| 645 static char * | |
|
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105959
diff
changeset
|
646 gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end) |
| 7306 | 647 { |
| 648 register char *end; | |
| 649 register int nread; | |
| 650 register char *buf = bufp->beg; | |
| 651 register char *tem; | |
| 652 | |
| 653 if (!append_end) | |
| 654 append_end = bufp->ptr; | |
| 655 | |
| 656 while (1) | |
| 657 { | |
| 658 end = append_end; | |
| 659 while (*end && *end != '\n') end++; | |
| 660 if (*end) | |
| 661 break; | |
| 662 if (bufp->ateof) | |
| 663 return buf + bufp->full; | |
| 664 if (bufp->ptr == buf) | |
| 665 { | |
| 666 if (bufp->full == bufp->size) | |
| 667 { | |
| 668 bufp->size *= 2; | |
| 669 /* Add 1 to size to ensure room for terminating null. */ | |
| 670 tem = (char *) xrealloc (buf, bufp->size + 1); | |
| 671 bufp->ptr = (bufp->ptr - buf) + tem; | |
| 672 append_end = (append_end - buf) + tem; | |
| 673 bufp->beg = buf = tem; | |
| 674 } | |
| 675 } | |
| 676 else | |
| 677 { | |
| 678 append_end -= bufp->ptr - buf; | |
|
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
679 memcpy (buf, bufp->ptr, bufp->full -= bufp->ptr - buf); |
| 7306 | 680 bufp->ptr = buf; |
| 681 } | |
| 682 if (!(nread = read (fd, buf + bufp->full, bufp->size - bufp->full))) | |
| 683 bufp->ateof = 1; | |
| 684 bufp->full += nread; | |
| 685 buf[bufp->full] = '\0'; | |
| 686 } | |
| 687 return end + 1; | |
| 688 } | |
| 689 | |
| 690 #ifdef TEST | |
| 691 | |
| 692 #ifdef NULL | |
| 693 #undef NULL | |
| 694 #endif | |
| 695 | |
| 696 #include <stdio.h> | |
| 697 | |
| 698 main (argc, argv) | |
| 699 int argc; | |
| 700 char **argv; | |
| 701 { | |
| 702 char *term; | |
| 703 char *buf; | |
| 704 | |
| 705 term = argv[1]; | |
| 706 printf ("TERM: %s\n", term); | |
| 707 | |
| 708 buf = (char *) tgetent (0, term); | |
| 709 if ((int) buf <= 0) | |
| 710 { | |
| 711 printf ("No entry.\n"); | |
| 712 return 0; | |
| 713 } | |
| 714 | |
| 715 printf ("Entry: %s\n", buf); | |
| 716 | |
| 717 tprint ("cm"); | |
| 718 tprint ("AL"); | |
| 719 | |
| 720 printf ("co: %d\n", tgetnum ("co")); | |
| 721 printf ("am: %d\n", tgetflag ("am")); | |
| 722 } | |
| 723 | |
| 724 tprint (cap) | |
| 725 char *cap; | |
| 726 { | |
| 727 char *x = tgetstr (cap, 0); | |
| 728 register char *y; | |
| 729 | |
| 730 printf ("%s: ", cap); | |
| 731 if (x) | |
| 732 { | |
| 733 for (y = x; *y; y++) | |
| 734 if (*y <= ' ' || *y == 0177) | |
| 735 printf ("\\%0o", *y); | |
| 736 else | |
| 737 putchar (*y); | |
| 738 free (x); | |
| 739 } | |
| 740 else | |
| 741 printf ("none"); | |
| 742 putchar ('\n'); | |
| 743 } | |
| 744 | |
| 745 #endif /* TEST */ | |
| 52401 | 746 |
| 747 /* arch-tag: c2e8d427-2271-4fac-95fe-411857238b80 | |
| 748 (do not change this comment) */ |
