2,6 → 2,9 |
* Copyright (c) 1980 The Regents of the University of California. |
* All rights reserved. |
* |
* Copyright (c) 2019 The PLANIX Project |
* All right reserved |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
31,14 → 34,12 |
* SUCH DAMAGE. |
*/ |
|
/* |
#ifndef lint |
static char sccsid[] = "@(#)termcap.c 5.6 (Berkeley) 7/3/92"; |
#endif */ /* not lint */ |
|
#define BUFSIZ 1024 |
#include <stdio.h> |
|
#define BUFSIZE 1024 |
#define MAXHOP 32 /* max number of tc= indirections */ |
#define PBUFSIZ 512 /* max length of filename path */ |
#define PBUFSIZE 512 /* max length of filename path */ |
#define PVECSIZ 32 /* max number of names in path */ |
|
#include <ctype.h> |
71,7 → 72,7 |
|
static char *tbuf; |
static int hopcount; /* detect infinite loops in termcap, init 0 */ |
static char pathbuf[PBUFSIZ]; /* holds raw path of filenames */ |
static char pathbuf[PBUFSIZE]; /* holds raw path of filenames */ |
static char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ |
static char **pvec; /* holds usable tail of path vector */ |
|
106,7 → 107,7 |
*/ |
if (!cp || *cp != '/') { /* no TERMCAP or it holds an entry */ |
if ( (termpath = getenv("TERMPATH")) ) |
strncpy(pathbuf, termpath, PBUFSIZ); |
strncpy(pathbuf, termpath, PBUFSIZE); |
else { |
if ( (home = getenv("HOME")) ) { /* set up default */ |
p += strlen(home); /* path, looking in */ |
113,11 → 114,11 |
strcpy(pathbuf, home); /* $HOME first */ |
*p++ = '/'; |
} /* if no $HOME look in current directory */ |
strncpy(p, _PATH_DEF, PBUFSIZ - (p - pathbuf)); |
strncpy(p, _PATH_DEF, PBUFSIZE - (p - pathbuf)); |
} |
} |
else /* user-defined name in TERMCAP */ |
strncpy(pathbuf, cp, PBUFSIZ); /* still can be tokenized */ |
strncpy(pathbuf, cp, PBUFSIZE); /* still can be tokenized */ |
|
*fname++ = pathbuf; /* tokenize path into vector of names */ |
while (*++p) |
162,7 → 163,7 |
register char *cp; |
register int c; |
register int i, cnt; |
char ibuf[BUFSIZ]; |
char ibuf[BUFSIZE]; |
int opencnt = 0; |
int tf; |
|
178,7 → 179,7 |
cp = bp; |
for (;;) { |
if (i == cnt) { |
cnt = read(tf, ibuf, BUFSIZ); |
cnt = read(tf, ibuf, BUFSIZE); |
if (cnt <= 0) { |
close(tf); |
pvec++; |
194,14 → 195,13 |
} |
break; |
} |
if (cp >= bp+BUFSIZ) { |
write(2,"Termcap entry too long\n", 23); |
if (cp >= bp+BUFSIZE) { |
fprintf(stderr,"Termcap entry too long\n"); |
break; |
} else |
*cp++ = c; |
} |
*cp = 0; |
|
/* |
* The real work for the match. |
*/ |
223,7 → 223,7 |
{ |
register char *p, *q; |
char tcname[16]; /* name of similar terminal */ |
char tcbuf[BUFSIZ]; |
char tcbuf[BUFSIZE]; |
char *holdtbuf = tbuf; |
int l; |
|
230,7 → 230,7 |
p = tbuf + strlen(tbuf) - 2; /* before the last colon */ |
while (*--p != ':') |
if (p<tbuf) { |
write(2, "Bad termcap entry\n", 18); |
fprintf(stderr, "Bad termcap entry\n"); |
return (0); |
} |
p++; |
243,7 → 243,7 |
q++; |
*q = 0; |
if (++hopcount > MAXHOP) { |
write(2, "Infinite tc= loop\n", 18); |
fprintf(stderr, "Infinite tc= loop\n"); |
return (0); |
} |
if (tfindent(tcbuf, tcname) != 1) { |
253,9 → 253,9 |
for (q=tcbuf; *q != ':'; q++) |
; |
l = p - holdtbuf + strlen(q); |
if (l > BUFSIZ) { |
write(2, "Termcap entry too long\n", 23); |
q[BUFSIZ - (p-tbuf)] = 0; |
if (l > BUFSIZE) { |
fprintf(stderr, "Termcap entry too long!\n"); |
q[BUFSIZE - (p-tbuf)] = 0; |
} |
strcpy(p, q+1); |
tbuf = holdtbuf; |