mkey2.c (0:68f95e015346) mkey2.c (719:6c26331bc6b8)
1/*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
1/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2/* All Rights Reserved */
3
6/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7/* All Rights Reserved */
8
4
5/*
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
9 */
10
9/*
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
13 */
14
11/*
12 * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13 * All Rights Reserved.
14 */
15#pragma ident "%Z%%M% %I% %E% SMI"
15
16
16#pragma ident "%Z%%M% %I% %E% SMI"
17
18#include <stdio.h>
19#include <ctype.h>
17#include <stdio.h>
18#include <ctype.h>
20#define MAXLINE 500
19#define MAXLINE 500
21
22static int eof = 0;
23static long lp, lim;
24static int alph, used, prevc;
25static char *p, key[20];
26
20
21static int eof = 0;
22static long lp, lim;
23static int alph, used, prevc;
24static char *p, key[20];
25
27dofile(f, name)
28FILE *f;
29char *name;
26extern int common();
27extern char *mindex();
28
29static void chkey(int, char *);
30static long grec(char *, FILE *);
31
32void
33dofile(FILE *f, char *name)
30{
31 /* read file f & spit out keys & ptrs */
32
33 char line[MAXLINE], *s;
34 extern int minlen, keycount, labels;
35 int c;
34{
35 /* read file f & spit out keys & ptrs */
36
37 char line[MAXLINE], *s;
38 extern int minlen, keycount, labels;
39 int c;
36 long grec();
37 extern int wholefile;
38 extern char *iglist;
40 extern int wholefile;
41 extern char *iglist;
39 alph=used=prevc=eof=0;
42 alph = used = prevc = eof = 0;
40
43
41 lp=0;
42 if (wholefile==0)
43 while (lim = grec(line,f))
44 {
45# if D1
46 fprintf(stderr, "line: /%s",line);
47# endif
48 used=alph=0;
44 lp = 0;
45 if (wholefile == 0) {
46 while (lim = grec(line, f)) {
47#if D1
48 fprintf(stderr, "line: /%s", line);
49#endif
50 used = alph = 0;
49 p = key;
51 p = key;
50 for(s=line; (c= *s) && (used<keycount); s++)
52 for (s = line; (c = *s) && (used < keycount); s++)
51 chkey(c, name);
52 lp += lim;
53 if (used) putchar('\n');
54 }
53 chkey(c, name);
54 lp += lim;
55 if (used) putchar('\n');
56 }
55 else
56 {
57 p=key;
58 used=alph=0;
59 while ( (c=getc(f)) != EOF && used<keycount)
60 chkey (c, name);
57 } else {
58 p = key;
59 used = alph = 0;
60 while ((c = getc(f)) != EOF && used < keycount)
61 chkey(c, name);
61 if (used) putchar('\n');
62 }
63 fclose(f);
64}
65
62 if (used) putchar('\n');
63 }
64 fclose(f);
65}
66
66outkey( ky, lead, trail)
67char *ky;
67static int
68outkey(char *ky, int lead, int trail)
68{
69 int n;
70 extern int minlen;
71 n = strlen(ky);
69{
70 int n;
71 extern int minlen;
72 n = strlen(ky);
72 if (n<minlen) return (0);
73 if (n<3)
74 {
75 if (trail == '.') return(0);
76 if (mindex(".%,!#$%&'();+:*", lead)!=0) return(0);
73 if (n < minlen)
74 return (0);
75 if (n < 3) {
76 if (trail == '.')
77 return (0);
78 if (mindex(".%,!#$%&'();+:*", lead) != 0)
79 return (0);
77 }
78 if (isdigit(ky[0]))
79 /* Allow years 1000 - 2099 */
80 if (!(ky[0] == '1' || (ky[0] == '2' && ky[1] == '0')) || n != 4)
80 }
81 if (isdigit(ky[0]))
82 /* Allow years 1000 - 2099 */
83 if (!(ky[0] == '1' || (ky[0] == '2' && ky[1] == '0')) || n != 4)
81 return(0);
84 return (0);
82 if (common(ky))
85 if (common(ky))
83 return(0);
84 return(1);
86 return (0);
87 return (1);
85}
86
88}
89
87long
88grec (s, f)
89char *s;
90FILE *f;
90static long
91grec(char *s, FILE *f)
91{
92 char tm[200];
93 int curtype = 0;
94 long len = 0L, tlen = 0L;
95 extern int wholefile;
96 extern char *iglist;
92{
93 char tm[200];
94 int curtype = 0;
95 long len = 0L, tlen = 0L;
96 extern int wholefile;
97 extern char *iglist;
97 if (eof) return(0);
98 if (eof)
99 return (0);
98 *s = 0;
100 *s = 0;
99 while (fgets(tm, 200, f))
100 {
101 while (fgets(tm, 200, f)) {
101 tlen += strlen(tm);
102 if (tm[0] == '%' || tm[0] == '.')
103 curtype = tm[1];
102 tlen += strlen(tm);
103 if (tm[0] == '%' || tm[0] == '.')
104 curtype = tm[1];
104 if (tlen < MAXLINE && mindex(iglist,curtype)==0)
105 if (tlen < MAXLINE && mindex(iglist, curtype) == 0)
105 strcat(s, tm);
106 len = tlen;
106 strcat(s, tm);
107 len = tlen;
107 if (wholefile==0 && tm[0] == '\n')
108 return(len);
109 if (wholefile>0 && len >= MAXLINE)
110 {
111 fseek (f, 0L, 2);
112 return(ftell(f));
108 if (wholefile == 0 && tm[0] == '\n')
109 return (len);
110 if (wholefile > 0 && len >= MAXLINE) {
111 fseek(f, 0L, 2);
112 return (ftell(f));
113 }
114 }
113 }
114 }
115 eof=1;
116 return(s[0] ? len : 0L);
115 eof = 1;
116 return (s[0] ? len : 0L);
117}
118
119char *
117}
118
119char *
120trimnl(ln)
121char *ln;
120trimnl(char *ln)
122{
121{
123 register char *p = ln;
122 char *p = ln;
124 while (*p) p++;
125 p--;
123 while (*p) p++;
124 p--;
126 if (*p == '\n') *p=0;
127 return(ln);
125 if (*p == '\n') *p = 0;
126 return (ln);
128}
129
127}
128
130chkey (c, name)
129static void
130chkey(int c, char *name)
131{
132 extern int labels;
133 extern int wholefile;
131{
132 extern int labels;
133 extern int wholefile;
134 if (isalpha(c) || isdigit(c))
135 {
134 if (isalpha(c) || isdigit(c)) {
136 if (alph++ < 6)
137 *p++ = c;
135 if (alph++ < 6)
136 *p++ = c;
138 }
139 else
140 {
137 } else {
141 *p = 0;
138 *p = 0;
142 for(p=key; *p; p++)
139 for (p = key; *p; p++)
143 *p |= 040;
140 *p |= 040;
144 if (outkey(p=key,prevc,c))
145 {
146 if (used==0)
147 {
148 if (labels)
149 {
150 if (wholefile==0)
151 printf("%s:%ld,%ld\t", name, lp, lim);
141 if (outkey(p = key, prevc, c)) {
142 if (used == 0) {
143 if (labels) {
144 if (wholefile == 0)
145 printf("%s:%ld,%ld\t", name,
146 lp, lim);
152 else
153 printf("%s\t", name);
154 }
147 else
148 printf("%s\t", name);
149 }
155 }
156 else
150 } else
157 putchar(' ');
158 fputs(key, stdout);
159 used++;
160 }
151 putchar(' ');
152 fputs(key, stdout);
153 used++;
154 }
161 prevc=c;
162 alph=0;
155 prevc = c;
156 alph = 0;
163 }
164}
157 }
158}