Bill Jolitz @ Berkeley received this version from Lorindia Cherry
[unix-history] / usr / src / usr.bin / diction / style2 / style2.l
CommitLineData
2958d0fe
RH
1%{
2#ifndef lint
280efb10 3static char sccsid[] = "@(#)style2.l 4.2 (Berkeley) 82/11/06";
2958d0fe
RH
4#endif not lint
5
6#include <stdio.h>
280efb10 7#include <ctype.h>
2958d0fe
RH
8#include "names.h"
9#include "ehash.c"
10#include "edict.c"
11#define OUT1(c) putchar(c); putchar(':'); for(i=yyleng-1;i>=0;)putchar(yytext[i--])
280efb10 12#define POUT1(c) putchar(c); putchar(':'); for(i=yyleng-1;i>0;)putchar(yytext[i--])
2958d0fe
RH
13int i;
14int nomin = 0;
280efb10 15int NOCAPS = 0; /*if set, all caps mapped to lower, plurals stripped*/
2958d0fe
RH
16%}
17
18C [A-Z0-9a-z",;]
19L [a-zA-Z-]
20
21%%
22^{C}:.+ {
23 ECHO;
24 }
25^ci.+ {
26 look(ic,2,ADJ);
27 }
28^de.+ {
29 look(ed,2,ED);
30 }
31^draw.+ {
280efb10
RH
32 if(yytext[5] == 'E'){
33 OUT1(NOUN_ADJ);
34 }
2958d0fe
RH
35 OUT1(ADJ_ADV);
36 }
37^eca.+ {
38 look(ace,3,NOUN_VERB);
39 }
40^eci.+ {
41 look(ice,3,NOUN_VERB);
42 }
43^ecne.+ {
280efb10 44 if(look(ence,4,NOM))nomin++;
2958d0fe
RH
45 }
46^ecna.+ {
280efb10 47 if(look(ance,4,NOM))nomin++;
2958d0fe
RH
48 }
49^ee.+ {
50 look(ee,2,NOUN);
51 }
52^ega.+ {
53 look(age,3,NOUN);
54 }
55^elba.+ {
56 look(able,4,ADJ);
57 }
58^elbi.+ {
59 look(ible,4,ADJ);
60 }
61^elc.+ {
62 look(cle,3,NOUN);
63 }
64^eru.+ {
280efb10 65 look(ure,3,NOUN);
2958d0fe
RH
66 }
67^eti.+ {
68 look(ite,3,NOUN);
69 }
70^evi.+ {
71 look(ive,3,ADJ);
72 }
73^ezi.+ {
74 look(ize,3,VERB);
75 }
76^gni.+ {
77 look(ing,3,ING);
78 }
79^hsi.+ {
80 look(ish,3,ADJ);
81 }
82^lac.+ {
83 look(cal,3,ADJ);
84 }
85^lanoi.+ {
86 look(ional,5,ADJ);
87 }
88^luf.+ {
89 look(ful,3,ADJ);
90 }
91^msi.+ {
92 OUT1(NOUN);
93 }
94^nam.* {
95 look(man,3,NOUN);
96 }
97^nem.* {
98 OUT1(NV_PL);
99 }
100^noi.+ {
280efb10 101 if(look(ion,3,NOM))nomin++;
2958d0fe
RH
102 }
103^pihs.+ {
104 look(ship,4,NOUN);
105 }
106^ral.+ {
107 look(lar,3,ADJ);
108 }
109^ronoh {
110 OUT1(NOUN_VERB);
111 }
112^ro.+ {
113 OUT1(NOUN);
114 }
115^si.+ {
116 look(is,2,NOUN);
117 }
118^ssel.+ {
119 look(less,4,ADJ);
120 }
121^ssen.+ {
122 look(ness,4,NOUN);
123 }
124^sse.+ {
125 look(ess,3,NOUN);
126 }
127^ss.+ {
128 look(ss,2,NOUN);
129 }
130^suo.+ {
131 look(ous,3,ADJ);
132 }
133^su.+ {
134 look(us,2,NOUN);
135 }
280efb10
RH
136^snoi.+ {
137 if(look(ion,4,PNOUN))nomin++;
138 }
139^stnem.+ {
140 if(look(ment,5,PNOUN))nomin++;
141 }
142^secne.+ {
143 if(look(ence,5,PNOUN))nomin++;
144 }
145^secna.+ {
146 if(look(ance,5,PNOUN))nomin++;
147 }
2958d0fe 148^s.+ {
280efb10
RH
149 if(isupper(yytext[yyleng-1])){
150 if(NOCAPS){
151 yytext[yyleng-1] = tolower(yytext[yyleng-1]);
152 POUT1(PNOUN);
153 }
154 else { OUT1(PNOUN); }
2958d0fe
RH
155 }
156 else {
280efb10
RH
157 if(NOCAPS){POUT1(NV_PL);}
158 else{ OUT1(NV_PL); }
2958d0fe
RH
159 }
160 }
161^tna.+ {
162 look(ant,3,NOUN_ADJ);
163 }
164^tnem.+ {
280efb10 165 if(look(ment,4,NOM))nomin++;
2958d0fe
RH
166 }
167^tse.+ {
168 look(est,3,ADJ);
169 }
170^tsi.+ {
171 look(ist,3,NOUN);
172 }
173[,\n] {
174 putchar(yytext[0]);
175 }
176{L}+ {
280efb10
RH
177 if(isupper(yytext[yyleng-1])){
178 if(NOCAPS)
179 yytext[yyleng-1] = tolower(yytext[yyleng-1]);
2958d0fe
RH
180 if((yytext[0] == 'n' || yytext[0] == 'l') && yytext[1] == 'a'){
181 OUT1(NOUN_ADJ);
182 }
183 else {
184 OUT1(NOUN);
185 }
186 }
187 else {
188 OUT1(UNK);
189 }
190 }
280efb10 191^:[\n] {
2958d0fe
RH
192 egetd();
193 }
280efb10
RH
194^:.+[\n] {
195 printf("%s",yytext);
196 }
2958d0fe
RH
197%%
198look(f,n,nc)
199char (*f)();
200int n;
201char nc;
202{
203 int in,nn,ret;
204 char sch;
205 in=0;
206 sch=yytext[yyleng-1];
280efb10
RH
207 if(isupper(sch)){
208 yytext[yyleng-1] = tolower(sch);
2958d0fe
RH
209 in=1;
210 }
211 if((*f)(&yytext[n],1,0) != 0){
212 nn = (*f)(&yytext[n],1,0);
280efb10
RH
213 if(nc == PNOUN)
214 if(nn == NOUN_VERB){
215 if(in == 1)nn=PNOUN;
216 else nn=NV_PL;
217 }
2958d0fe
RH
218 ret = 0;
219 }
220 else {
221 nn = nc;
222 ret = 1;
223 }
224 if(in==1){
225 if(nn == NOUN_VERB)nn=NOUN;
280efb10
RH
226 if(!NOCAPS)yytext[yyleng-1]=sch;
227 }
228 if(nn==PNOUN && yytext[0] == 's' && NOCAPS){
229 POUT1(nn);
230 }
231 else {
232 OUT1(nn);
2958d0fe 233 }
2958d0fe
RH
234 return(ret);
235}
236yywrap(){
237 printf(";%d\n",nomin);
238 return(1);
239}