|
|
1.1 root 1: /* library:checkdoc.c 1.7 */
2: #include "sccsid.h"
3: VERSION(@(#)library:checkdoc.c 1.7)
4:
5: /************* checkdoc.c ***************/
6:
7: /* This routine checks whether a given document id is legal.
8: * It checks in file
9: * WHERE/known.list
10: * to see if the document id meets any of the document ID formats
11: * listed there.
12: *
13: * The lines in known.list have 3 forms:
14: * start with ? mark - help text
15: * start with # - comments
16: * start with ^regular expression. This causes all the following
17: * lines to be scanned, ignoring if the given expression starts the
18: * document id
19: * all others are regular expression document ID formats.
20: * Return value:
21: * <0 on failure.
22: * 0 success - but no remarks allowed
23: * >0 success - remarks allowed.
24: */
25: #include <stdio.h>
26: #include <ctype.h>
27: static char *exp_ptr;
28:
29: #define INIT register char *sp = exp_ptr;
30: #define GETC() (*sp++)
31: #define PEEKC() (*sp)
32: #define UNGETC(x) (--sp)
33: #define RETURN(c) { exp_ptr = sp; return(c); }
34: #define ERROR(c) return(NULL);
35: #include "regexp.h"
36: #define LBSIZE 256
37: char *strchr();
38:
39: checkdoc(str)
40: char *str;
41: {
42: char expbuf[LBSIZE], rhsbuf[LBSIZE];
43: char genbuf[LBSIZE], line[100];
44: register char *ptr, *mstr;
45: static FILE *infile=NULL;
46: long value;
47: static char *bchecks="ABCDEFGHJKLMNPQRTSVWXYZ";
48: static char *schecks="ABCDEFHJKLMNPQRTVWXY";
49:
50: if (infile == NULL) {
51: sprintf(line, "%s/known.list", WHERE);
52: if ((infile = fopen(line, "r")) == NULL) {
53: fprintf(stderr, "No ID format file!! No requests sent!!\n");
54: exit(1);
55: }
56: }
57: rewind(infile);
58: *line = '^';
59: mstr = str;
60: while (fgets(line+1, 100, infile) != NULL) {
61: ptr = line+1;
62: if (*ptr == '?') continue;
63: if (*ptr == '#') continue;
64: if (*ptr == '\n') continue;
65: if (*ptr == '^') {
66: ptr++;
67: /* just a ^ resets to start of string */
68: if (*ptr == '\n') {
69: mstr = str;
70: continue;
71: }
72: *expbuf = 0;
73: exp_ptr = line+1;
74: if (compile((char *) 0, expbuf, expbuf+LBSIZE, '\t') == NULL)
75: return(-2);
76: compsub(rhsbuf, '\t');
77: if (match(expbuf, 0, mstr, genbuf)) mstr = loc2;
78: continue;
79: }
80: *expbuf = 0;
81: exp_ptr = line;
82: if (compile((char *) 0, expbuf, expbuf+LBSIZE, '\t') == NULL)
83: return(-2);
84: compsub(rhsbuf, '\t');
85: if (match(expbuf, 0, mstr, genbuf)) {
86: ptr = strchr(line, '\t');
87: if (ptr++ == NULL) return(0);
88: if (strncmp(ptr, "REMARK", 6) == 0) return(1);
89: else if (strncmp(ptr+1, "CHECK", 5) == 0) {
90: if (strlen(loc2) != 1) return(-3);
91: /* accept a question mark */
92: if (*loc2 == '?') return(0);
93: /* get the sum of the digits - note done with mstr */
94: for (value = 0, mstr=str; *mstr; mstr++)
95: if (isdigit(*mstr)) value = value * 10 + *mstr - '0';
96: /* check the check char */
97: if (*ptr == 'B')
98: ptr = bchecks;
99: else ptr = schecks;
100: value = (value % strlen(ptr));
101: if (*loc2 != ptr[value]) return(-3);
102: return(0);
103: }
104: if (strlen(loc2)) continue; /* more id than allowed - continue */
105: return(0);
106: }
107: }
108: return(-1);
109: }
110:
111: match(expbuf, gf, linebuf, genbuf)
112: char *expbuf, *linebuf, *genbuf;
113: {
114: register char *p1, *p2;
115:
116: if(gf) {
117: if (circf) return(0);
118: p1 = linebuf;
119: p2 = genbuf;
120: while(*p1++ = *p2++);
121: locs = p1 = loc2;
122: }
123: else {
124: p1 = linebuf;
125: locs = 0;
126: }
127: return(step(p1, expbuf));
128: }
129:
130: compsub(rhsbuf, sseof)
131: char *rhsbuf, sseof;
132: {
133: register char *p, *q;
134:
135: p = rhsbuf;
136: q = exp_ptr;
137: for(;;) {
138: if((*p = *q++) == '\\') {
139: *p = *q++;
140: if(*p > nbra + '0' && *p <= '9') return(NULL);
141: *p++ |= 0200;
142: continue;
143: }
144: if(*p == sseof) {
145: *p++ = '\0';
146: exp_ptr = q;
147: break;
148: }
149: if(*p++ == '\0') return(-1);
150: }
151: return(0);
152: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.