?? read_termcap.c
字號:
} *rp++ = c; /* * Enforce loop invariant: if no room * left in record buffer, try to get * some more. */ if (rp >= r_end) { unsigned pos; size_t newsize; pos = rp - record; newsize = r_end - record + BFRAG; record = DOALLOC(newsize); if (record == 0) { if (myfd) (void) close(fd); errno = ENOMEM; return (TC_SYS_ERR); } r_end = record + newsize; rp = record + pos; } } /* loop invariant lets us do this */ *rp++ = '\0'; /* * If encountered eof check next file. */ if (eof) break; /* * Toss blank lines and comments. */ if (*record == '\0' || *record == '#') continue; /* * See if this is the record we want ... */ if (_nc_cgetmatch(record, name) == 0 && (nfield == 0 || !_nc_nfcmp(nfield, record))) { foundit = TRUE; *beginning = first; break; /* found it! */ } } } if (foundit) break; } if (!foundit) return (TC_NOT_FOUND); } /* * Got the capability record, but now we have to expand all tc=name * references in it ... */ { register char *newicap, *s; register int newilen; unsigned ilen; int diff, iret, tclen, oline; char *icap, *scan, *tc, *tcstart, *tcend; /* * Loop invariants: * There is room for one more character in record. * R_end points just past end of record. * Rp points just past last character in record. * Scan points at remainder of record that needs to be * scanned for tc=name constructs. */ scan = record; tc_not_resolved = FALSE; for (;;) { if ((tc = _nc_cgetcap(scan, "tc", '=')) == 0) break; /* * Find end of tc=name and stomp on the trailing `:' * (if present) so we can use it to call ourselves. */ s = tc; while (*s != '\0') { if (*s++ == ':') { *(s - 1) = '\0'; break; } } tcstart = tc - 3; tclen = s - tcstart; tcend = s; iret = _nc_getent(&icap, &ilen, &oline, current, db_array, fd, tc, depth + 1, 0); newicap = icap; /* Put into a register. */ newilen = ilen; if (iret != TC_SUCCESS) { /* an error */ if (iret < TC_NOT_FOUND) { if (myfd) (void) close(fd); free(record); return (iret); } if (iret == TC_UNRESOLVED) tc_not_resolved = TRUE; /* couldn't resolve tc */ if (iret == TC_NOT_FOUND) { *(s - 1) = ':'; scan = s - 1; tc_not_resolved = TRUE; continue; } } /* not interested in name field of tc'ed record */ s = newicap; while (*s != '\0' && *s++ != ':') ; newilen -= s - newicap; newicap = s; /* make sure interpolated record is `:'-terminated */ s += newilen; if (*(s - 1) != ':') { *s = ':'; /* overwrite NUL with : */ newilen++; } /* * Make sure there's enough room to insert the * new record. */ diff = newilen - tclen; if (diff >= r_end - rp) { unsigned pos, tcpos, tcposend; size_t newsize; pos = rp - record; newsize = r_end - record + diff + BFRAG; tcpos = tcstart - record; tcposend = tcend - record; record = DOALLOC(newsize); if (record == 0) { if (myfd) (void) close(fd); free(icap); errno = ENOMEM; return (TC_SYS_ERR); } r_end = record + newsize; rp = record + pos; tcstart = record + tcpos; tcend = record + tcposend; } /* * Insert tc'ed record into our record. */ s = tcstart + newilen; memmove(s, tcend, (size_t) (rp - tcend)); memmove(tcstart, newicap, (size_t) newilen); rp += diff; free(icap); /* * Start scan on `:' so next cgetcap works properly * (cgetcap always skips first field). */ scan = s - 1; } } /* * Close file (if we opened it), give back any extra memory, and * return capability, length and success. */ if (myfd) (void) close(fd); *len = rp - record - 1; /* don't count NUL */ if (r_end > rp) { if ((record = DOALLOC((size_t) (rp - record))) == 0) { errno = ENOMEM; return (TC_SYS_ERR); } } *cap = record; if (tc_not_resolved) return (TC_UNRESOLVED); return (current);}/* * Cgetmatch will return 0 if name is one of the names of the capability * record buf, -1 if not. */static int_nc_cgetmatch(char *buf, const char *name){ register const char *np; register char *bp; /* * Start search at beginning of record. */ bp = buf; for (;;) { /* * Try to match a record name. */ np = name; for (;;) { if (*np == '\0') { if (*bp == '|' || *bp == ':' || *bp == '\0') return (0); else break; } else if (*bp++ != *np++) { break; } } /* * Match failed, skip to next name in record. */ bp--; /* a '|' or ':' may have stopped the match */ for (;;) { if (*bp == '\0' || *bp == ':') return (-1); /* match failed totally */ else if (*bp++ == '|') break; /* found next name */ } }}/* * Compare name field of record. */static int_nc_nfcmp(const char *nf, char *rec){ char *cp, tmp; int ret; for (cp = rec; *cp != ':'; cp++) ; tmp = *(cp + 1); *(cp + 1) = '\0'; ret = strcmp(nf, rec); *(cp + 1) = tmp; return (ret);}#endif /* HAVE_BSD_CGETENT *//* * Since ncurses provides its own 'tgetent()', we cannot use the native one. * So we reproduce the logic to get down to cgetent() -- or our cut-down * version of that -- to circumvent the problem of configuring against the * termcap library. */#define USE_BSD_TGETENT 1#if USE_BSD_TGETENT/* * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgment: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *//* static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93" */#define PBUFSIZ 512 /* max length of filename path */#define PVECSIZ 32 /* max number of names in path */#define TBUFSIZ (2048*2)static char *tbuf;/* * On entry, srcp points to a non ':' character which is the beginning of the * token, if any. We'll try to return a string that doesn't end with a ':'. */static char *get_tc_token(char **srcp, int *endp){ int ch; bool found = FALSE; char *s, *base; char *tok = 0; *endp = TRUE; for (s = base = *srcp; *s != '\0';) { ch = *s++; if (ch == '\\') { if (*s == '\0') { break; } else if (*s++ == '\n') { while (isspace(*s)) s++; } else { found = TRUE; } } else if (ch == ':') { if (found) { tok = base; s[-1] = '\0'; *srcp = s; *endp = FALSE; break; } base = s; } else if (isgraph(ch)) { found = TRUE; } } /* malformed entry may end without a ':' */ if (tok == 0 && found) { tok = base; } return tok;}static char *copy_tc_token(char *dst, const char *src, size_t len){ int ch; while ((ch = *src++) != '\0') { if (ch == '\\' && *src == '\n') { while (isspace(*src)) src++; continue; } if (--len == 0) { dst = 0; break; } *dst++ = ch; } return dst;}/* * Get an entry for terminal name in buffer bp from the termcap file. */static int_nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name){ static char *the_source; register char *p; register char *cp; char *dummy = NULL;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -