/*
- * $Id: printcap.c,v 1.5 2001-07-31 19:50:14 srittau Exp $
+ * $Id: printcap.c,v 1.10 2005-04-28 20:49:49 bfernhomberg Exp $
*
* Copyright (c) 1990,1994 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
#include "config.h"
#endif /* HAVE_CONFIG_H */
-#ifndef lint
-static char sccsid[] = "@(#)printcap.c 5.7 (Berkeley) 3/4/91";
-#endif /* not lint */
-
#include <ctype.h>
#include <stdio.h>
#include <string.h>
* Added a "cap" parameter, so we can use these calls for printcap
* and papd.conf.
*/
-int getprent( cap, bp)
+int getprent( cap, bp, bufsize )
register char *cap;
register char *bp;
+ register int bufsize;
{
- register int c, skip = 0;
+ register int c, skip = 0, i;
if (pfp == NULL && (pfp = fopen( cap, "r")) == NULL)
return(-1);
tbuf = bp;
+ i = 0;
for (;;) {
switch (c = getc(pfp)) {
case EOF:
+ if (bp != tbuf) {
+ *bp = '\0';
+ return(1);
+ }
fclose(pfp);
pfp = NULL;
return(0);
return(1);
}
*bp++ = c;
+ if (++i >= bufsize) {
+ write(2, "config file too large\n", 22);
+ fclose(pfp);
+ pfp = NULL;
+ *bp = '\0';
+ return(1);
+ }
}
}
}
register int i = 0, cnt = 0;
char ibuf[BUFSIZ];
int tf;
+ int skip;
hopcount = 0;
tbuf = bp;
cp2 = getenv("TERM");
if (cp2==(char *) 0 || strcmp(name,cp2)==0) {
strcpy(bp,cp);
- return(tnchktc());
+ return(tnchktc(cap));
} else {
tf = open(cap, 0);
}
}
if (tf==0)
tf = open(cap, 0);
-#else
+#else /* V6 */
tf = open(cap, 0);
-#endif
+#endif /* V6 */
if (tf < 0)
return (-1);
for (;;) {
cp = bp;
+ skip = 0;
for (;;) {
if (i == cnt) {
cnt = read(tf, ibuf, BUFSIZ);
}
c = ibuf[i++];
if (c == '\n') {
- if (cp > bp && cp[-1] == '\\'){
+ if (!skip && cp > bp && cp[-1] == '\\') {
cp--;
continue;
}
- break;
+ skip = 0;
+ if (cp == bp)
+ continue;
+ else
+ break;
}
+ if (c == '#' && cp == bp)
+ skip++;
+ if (skip)
+ continue;
if (cp >= bp+BUFSIZ) {
write(2,"Termcap entry too long\n", 23);
break;
while (*bp && *bp != ':')
bp++;
- if (*bp == ':')
+ while (*bp && *bp == ':')
bp++;
return (bp);
}
}
static char *
-decodename(str, area)
+decodename(str, area, bufsize)
register char *str;
char **area;
+ int bufsize;
{
register char *cp;
register int c;
int i;
cp = *area;
- while ((c = *str++) && c != ':' && c != '|' ) {
+ while ((c = *str++) && --bufsize && c != ':' && c != '|' ) {
switch (c) {
case '^':
}
char *
-getpname( area )
- char **area;
+getpname( area, bufsize )
+ char **area;
+ int bufsize;
{
- return( decodename( tbuf, area ));
+ return( decodename( tbuf, area, bufsize));
}