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

Function tgetent

sys/share/tclib.c:62–94  ·  view source on GitHub ↗

retrieve the specified terminal entry and return it in `entbuf' */

Source from the content-addressed store, hash-verified

60
61/* retrieve the specified terminal entry and return it in `entbuf' */
62int
63tgetent(char *entbuf, /* size must be at least [TCBUFSIZ] */
64 const char *term)
65{
66 int result;
67 FILE *fp;
68 char *tc = getenv("TERMCAP");
69
70 tc_entry = entbuf;
71 if (!entbuf || !term)
72 return -1;
73 /* if ${TERMCAP} is found as a file, it's not an inline termcap entry */
74 if ((fp = fopen(tc ? tc : TERMCAP, "r")) != 0)
75 tc = 0;
76 /* if ${TERMCAP} isn't a file and `term' matches ${TERM}, use ${TERMCAP}
77 */
78 if (tc) {
79 char *tm = getenv("TERM");
80 if (tm && strcmp(tm, term) == 0)
81 return tc_store(term, tc);
82 fp = fopen(TERMCAP, "r");
83 }
84 /* otherwise, look `term' up in the file */
85 if (fp) {
86 char wrkbuf[TCBUFSIZ];
87 tc = tc_find(fp, term, wrkbuf, (int) (sizeof wrkbuf - strlen(term)));
88 result = tc_store(term, tc);
89 (void) fclose(fp);
90 } else {
91 result = -1;
92 }
93 return result;
94}
95
96/* copy the entry into the output buffer */
97static int

Callers 1

term_startupFunction · 0.85

Calls 3

tc_storeFunction · 0.85
tc_findFunction · 0.85
fcloseFunction · 0.85

Tested by

no test coverage detected