MCPcopy Create free account
hub / github.com/NetHack/NetHack / tc_find

Function tc_find

sys/share/tclib.c:137–191  ·  view source on GitHub ↗

search for an entry in the termcap file */

Source from the content-addressed store, hash-verified

135
136/* search for an entry in the termcap file */
137static char *
138tc_find(FILE *fp, const char *term, char *buffer, int bufsiz)
139{
140 int in, len, first, skip;
141 char *ip, *op, *tc_fetch, tcbuf[TCBUFSIZ];
142
143 buffer[0] = '\0';
144 do {
145 ip = tcbuf, in = min(bufsiz, TCBUFSIZ);
146 first = 1, skip = 0;
147 /* load entire next entry, including any continuations */
148 do {
149 if (!fgets(ip, min(in, BUFSIZ), fp))
150 break;
151 if (first)
152 skip = (*ip == '#'), first = 0;
153 len = (int) strlen(ip);
154 if (!skip && len > 1 && *(ip + len - 1) == '\n'
155 && *(ip + len - 2) == '\\')
156 len -= 2;
157 ip += len, in -= len;
158 } while (*(ip - 1) != '\n' && in > 0);
159 if (ferror(fp) || ip == buffer || *(ip - 1) != '\n')
160 return (char *) 0;
161 *--ip = '\0'; /* strip newline */
162 if (!skip)
163 ip = tc_name(term, tcbuf);
164 } while (skip || !ip);
165
166 /* we have the desired entry; strip cruft and look for :tc=other: */
167 tc_fetch = 0;
168 for (op = buffer; *ip; ip++) {
169 if (op == buffer || *(op - 1) != ':'
170 || (*ip != ' ' && *ip != '\t' && *ip != ':'))
171 *op++ = *ip, bufsiz -= 1;
172 if (ip[0] == ':' && ip[1] == 't' && ip[2] == 'c' && ip[3] == '=') {
173 tc_fetch = &ip[4];
174 if ((ip = strchr(tc_fetch, ':')) != 0)
175 *ip = '\0';
176 break;
177 }
178 }
179 *op = '\0';
180
181 if (tc_fetch) {
182 rewind(fp);
183 tc_fetch = tc_find(fp, tc_fetch, tcbuf, min(bufsiz, TCBUFSIZ));
184 if (!tc_fetch)
185 return (char *) 0;
186 if (op > buffer && *(op - 1) == ':' && *tc_fetch == ':')
187 ++tc_fetch;
188 strcpy(op, tc_fetch);
189 }
190 return buffer;
191}
192
193/* check whether `ent' contains `nam'; return start of field entries */
194static char *

Callers 1

tgetentFunction · 0.85

Calls 2

fgetsFunction · 0.85
tc_nameFunction · 0.85

Tested by

no test coverage detected