|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T t
Length: 3143 (0xc47) Types: TextFile Names: »tb_k2val.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« └─⟦e5a54fb17⟧ └─⟦this⟧ »pp-5.0/Lib/table/tb_k2val.c«
/* tb_k2val.c: primitive routine - convert key to value */ # ifndef lint static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Lib/table/RCS/tb_k2val.c,v 5.0 90/09/20 16:15:43 pp Exp Locker: pp $"; # endif /* * $Header: /cs/research/pp/hubris/pp-beta/Lib/table/RCS/tb_k2val.c,v 5.0 90/09/20 16:15:43 pp Exp Locker: pp $ * * $Log: tb_k2val.c,v $ * Revision 5.0 90/09/20 16:15:43 pp * rcsforce : 5.0 public release * */ #include "util.h" #include "table.h" #define MAXF 80 /* All the tables with open files */ static Table *tb_xall [MAXF]; static int curclose; extern char *tbldfldir; /* --------------------- Start Routines -------------------------------- */ int tb_k2val (tbl, key, val) register Table *tbl; char *key; char *val; { FILE *f; char linebuf[LINESIZE], value[LINESIZE]; int i, status; PP_DBG (("Lib/tb_k2val (%s)", key)); if (TB_SRC (tbl -> tb_flags) == TB_DBM) return (tb_dbmk2val (tbl, key, val)); if (tbl -> tb_fp == NULLFILE) { /* Must open the file.... */ if (*tbl -> tb_file != '/') { (void) sprintf (linebuf, "%s/%s", tbldfldir, tbl -> tb_file); f = fopen (linebuf, "r"); } else f = fopen (tbl -> tb_file, "r"); if (f == NULLFILE) { PP_OPER (tbl -> tb_file, ("Cannot open")); return (NOTOK); } tbl -> tb_fp = f; for (i = 0 ; i < MAXF ; i++) if (tb_xall [(i+curclose) % MAXF] == NULL) { tb_xall [(i+curclose) % MAXF] = tbl; goto got; } (void) fclose (tb_xall [curclose] -> tb_fp); tb_xall [curclose] -> tb_fp = NULLFILE; tb_xall [curclose++] = tbl; curclose %= MAXF; got:; } f = tbl -> tb_fp; rewind (f); while ((status = tab_fetch (f, linebuf, value)) != DONE) { if (status == NOTOK) continue; if (lexequ (linebuf, key) == 0) { /* Found now return it */ if (val == NULL) return (OK); (void) strcpy (val, value); return (OK); } } return (NOTOK); } int tab_fetch (f, key, val) register FILE *f; char *key; char *val; { register char *cp; int c; while ((c = getc(f)) != EOF && isspace (c)) continue; if (c == '#') { while ((c = getc(f)) != EOF && c != '\n') continue; return tab_fetch (f, key, val); } cp = key; do { if (c == '\n') { *cp = '\0'; PP_LOG (LLOG_EXCEPTIONS, ("no value - missing ':' key=%s", key)); return NOTOK; } if (c == ':') { if (cp > key && cp[-1] == '\\') cp [-1] = c; else break; } else *cp ++ = c; if (key - cp > LINESIZE) { *cp = '\0'; PP_LOG (LLOG_EXCEPTIONS, ("Key too long '%s'", key)); return NOTOK; } } while ((c = getc (f)) != EOF); if (c == EOF) return DONE; *cp = '\0'; while ((c = getc(f)) != EOF && c != '\n' && isspace (c)) continue; cp = val; do { if (c == '\n') break; else *cp ++ = c; if (val - cp > LINESIZE) { *cp = '\0'; PP_LOG (LLOG_EXCEPTIONS, ("Value too long %s:%s", key, val)); return NOTOK; } } while ((c = getc (f)) != EOF); if (c == EOF) return DONE; *cp = '\0'; return OK; }