add copyright notice
[unix-history] / usr / src / usr.sbin / lpr / common_source / printcap.c
index 1c05280..ac52ab1 100644 (file)
@@ -1,10 +1,13 @@
-/*     printcap.c      1.3     81/06/01        */
+#ifndef lint
+static char sccsid[] = "@(#)printcap.c 1.6 (Berkeley) %G%";
+#endif
+
 /* Copyright (c) 1979 Regents of the University of California */
 #define        BUFSIZ  1024
 #define MAXHOP 32      /* max number of tc= indirections */
 
 #include <ctype.h>
 /* Copyright (c) 1979 Regents of the University of California */
 #define        BUFSIZ  1024
 #define MAXHOP 32      /* max number of tc= indirections */
 
 #include <ctype.h>
-#include "local/uparm.h"
+#include <stdio.h>
 /*
  * termcap - routines for dealing with the terminal capability data base
  *
 /*
  * termcap - routines for dealing with the terminal capability data base
  *
 #define V6
 #endif
 
 #define V6
 #endif
 
+static FILE *pfp = NULL;       /* printcap data base file pointer */
 static char *tbuf;
 static char *tbuf;
-static int hopcount;   /* detect infinite loops in termcap, init 0 */
+static int hopcount;           /* detect infinite loops in termcap, init 0 */
 char   *tskip();
 char   *tgetstr();
 char   *tdecode();
 char   *getenv();
 
 char   *tskip();
 char   *tgetstr();
 char   *tdecode();
 char   *getenv();
 
+/*
+ * Similar to tgetent except it returns the next enrty instead of
+ * doing a lookup.
+ */
+getprent(bp)
+       register char *bp;
+{
+       register int c, skip = 0;
+
+       if (pfp == NULL && (pfp = fopen(E_TERMCAP, "r")) == NULL)
+               return(-1);
+       tbuf = bp;
+       for (;;) {
+               switch (c = getc(pfp)) {
+               case EOF:
+                       fclose(pfp);
+                       pfp = NULL;
+                       return(0);
+               case '\n':
+                       if (bp == tbuf) {
+                               skip = 0;
+                               continue;
+                       }
+                       if (bp[-1] == '\\') {
+                               bp--;
+                               continue;
+                       }
+                       *bp = '\0';
+                       return(1);
+               case '#':
+                       if (bp == tbuf)
+                               skip++;
+               default:
+                       if (skip)
+                               continue;
+                       if (bp >= tbuf+BUFSIZ) {
+                               write(2, "Termcap entry too long\n", 23);
+                               *bp = '\0';
+                               return(1);
+                       }
+                       *bp++ = c;
+               }
+       }
+}
+
+endprent()
+{
+       if (pfp != NULL)
+               fclose(pfp);
+}
+
 /*
  * Get an entry for terminal name in buffer bp,
  * from the termcap file.  Parse is very rudimentary;
 /*
  * Get an entry for terminal name in buffer bp,
  * from the termcap file.  Parse is very rudimentary;