|
|
1.1 root 1: %{
2: #include "style.h"
3: #include "names.h"
4: #include "conp.h"
5: FILE *deb;
6: int lineflg = 0;
7: int nosave = 1;
8: int part = 0;
9: int barebones = 0;
10: int topic = 0;
11: int style = 1;
12: int pastyle = 0;
13: int pstyle = 0;
14: int sstyle = 0;
15: int lstyle = 0;
16: int rstyle = 0;
17: int estyle = 0;
18: int nstyle = 0;
19: int Nstyle = 0;
20: int sprint = 0;
21: int sthresh;
22: int lthresh;
23: int rthresh;
24: int nomin;
25: char s[SCHAR];
26: char *sptr = s;
27: struct ss sent[SLENG];
28: struct ss *sentp = sent;
29: float wperc();
30: float sperc();
31: float typersent();
32: float vperc();
33: int numsent = 0;
34: int qcount = 0;
35: int icount = 0;
36: long vowel = 0;
37: long numwds = 0;
38: long twds = 0;
39: long numnonf = 0;
40: long letnonf = 0;
41: int maxsent = 0;
42: int maxindex = 0;
43: int minsent = 30;
44: int minindex = 0;
45: int simple = 0;
46: int compound = 0;
47: int compdx = 0;
48: int prepc = 0;
49: int conjc = 0;
50: int complex = 0;
51: int tobe = 0;
52: int adj = 0;
53: int infin = 0;
54: int pron = 0;
55: int passive = 0;
56: int aux = 0;
57: int adv = 0;
58: int verbc = 0;
59: int tverbc = 0;
60: int noun = 0;
61: long numlet = 0;
62: int beg[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
63: int sleng[50];
64: int nsleng = 0;
65: int j,jj,i;
66: int comma = 0;
67: int cflg;
68: int question;
69: int quote = 0;
70: char *st;
71: int initf = 0;
72: int over = 1;
73: int nroff = 0;
74: int nrofflg = 0;
75: int leng[MAXPAR];
76: int sentno= 0;
77: %}
78: C [A-DF-Za-z]
79: %%
80: ^{C}:.+ {
81: collect:
82: sentp->cc = sentp->ic = yytext[0];
83: if(sentp->cc == NOM)
84: sentp->cc = NOUN;
85: collect1:
86: nsleng++;
87: sentp->leng = yyleng-2;
88: sentp++->sp = sptr;
89: if(sentp >= &sent[SLENG-1]){
90: if(over)fprintf(stderr,"Parts: (part.l) sentence %d too many words\n",numsent+2);
91: over=0;
92: sentp--;
93: }
94: if(sptr+yyleng >= &s[SCHAR-1]){
95: if(over)fprintf(stderr,"sentence %d too many characters\n",numsent+2);
96: over=0;
97: }
98: else {
99: for(i=2;i<yyleng;i++)*sptr++=yytext[i];
100: *sptr++ = '\0';
101: }
102: }
103: ^";:".+ {
104: sentp->cc=END;
105: sentp->ic = ';';
106: goto collect1;
107: }
108: ^",:".+ {
109: comma++;
110: goto collect;
111: }
112: ^",:"[:,-]+ {
113: comma++;
114: goto collect;
115: }
116: [\n] ;
117: ^"\":".+ {
118: goto collect;
119: }
120: ^E:"~." {
121: cflg = 1;
122: goto sdone;
123: }
124: ^E:.+ {
125: cflg = 0;
126: sdone:
127: over=1;
128: sentp->cc=sentp->ic=END;
129: sentp++->sp = sptr;
130: for(i=2;i<yyleng;i++)*sptr++=yytext[i];
131: *sptr++='\0';
132: if(yytext[2]=='?')question=1;
133: else question=0;
134:
135: fragment:
136: jj=0;
137: if(quote == 1 && sent[jj].cc == ED){
138: sent[jj].cc = VERB;
139: quote = 0;
140: }
141: if(sent[jj].cc=='"')jj++;
142: if(sent[jj].cc==SUBCONJ){
143: if(sent[jj+1].cc == ','){
144: sent[jj].cc=ADV;
145: jj += 2;
146: comma--;
147: }
148: else {
149: jj=scan(1,',',0);
150: if(jj != -1)jj++;
151: comma--;
152: }
153: }
154: if(jj != -1){
155: if(sent[jj].cc==CONJ || sent[jj].cc=='"')jj++;
156: while((jj=scan(jj,END,cflg)) != -1){
157: jj++;
158: if(sent[jj].cc == SUBCONJ && sent[jj+1].cc == ','){
159: sent[jj].cc=ADV;
160: jj += 2;
161: comma--;
162: }
163: }
164: }
165: st = sent[i].sp;
166: if(*(st+1) == '"')
167: if(*st == '?' || *st == '!')quote = 1;
168: outp();
169: nsleng = 0;
170: if(nroff){
171: if(sentno > 0){
172: printf(".SL \"");
173: for(i=0;i<sentno;i++)
174: printf(" %d",leng[i]);
175: printf("\"\n");
176: sentno = 0;
177: }
178: printf("%s",&yytext[1]);
179: nroff = 0;
180: }
181: sptr=s;
182: sentp=sent;
183: comma=0;
184: }
185: ;.+ {
186: if(style){
187: nomin = atoi(&yytext[1]);
188: }
189: }
190: ^:.+[\n] {
191: if(lineflg == 2){
192: nrofflg=1;
193: if(sentp != sent){
194: sentp->cc = sentp->ic = END;
195: sentp++->sp = sptr;
196: *sptr++ = '.';
197: *sptr++ = '\0';
198: over = 1;
199: nroff = 1;
200: goto fragment;
201: }
202: if(sentno > 0){
203: printf(".SL \"");
204: for(i=0;i<sentno;i++)
205: printf(" %d",leng[i]);
206: printf("\"\n");
207: sentno = 0;
208: }
209: }
210: if(lineflg)
211: printf("%s",&yytext[1]);
212: }
213: %%
214: yywrap(){
215: int ii;
216: int ml,mg,lsum,gsum;
217: float aindex, avl, avw;
218: float cindex,kindex,findex,fgrad;
219: float syl, avsy, adjs,snonf;
220: FILE *io;
221:
222: if(style){
223: if(numwds == 0 || numsent == 0)exit(0);
224: avw = (float)(numwds)/(float)(numsent);
225: avl = (float)(numlet)/(float)(numwds);
226: aindex = 4.71*avl + .5*avw -21.43;
227: syl = .9981*vowel-.3432*twds;
228: avsy = syl/twds;
229: kindex = 11.8*avsy+.39*avw-15.59;
230: findex = 206.835-84.6*avsy-1.015*avw;
231: if(findex < 30.)fgrad = 17.;
232: else if(findex > 100.) fgrad = 4.;
233: else if(findex > 70.)fgrad=(100.-findex)/10 +5.;
234: else if(findex > 60.)fgrad =(70.-findex)/10+8.;
235: else if(findex >50.)fgrad=(60.-findex)/5+10;
236: else fgrad=(50.-findex)/6.66 +13.;
237: adjs = 100 * (float)numsent/numwds;
238: cindex = 5.89*avl-.3*adjs-15.8;
239: if(!sprint){
240: printf("readability grades:\n (Kincaid) %4.1f (auto) %4.1f (Coleman-Liau) %4.1f (Flesch) %4.1f (%4.1f)\n",kindex,aindex,cindex,fgrad,findex);
241: printf("sentence info:\n");
242: printf(" no. sent %d no. wds %ld\n",numsent,numwds);
243: printf(" av sent leng %4.1f av word leng %4.2f\n",avw,avl);
244: printf(" no. questions %d no. imperatives %d\n",qcount,icount);
245: }
246: else {
247: printf("%4.1f %4.1f %4.1f %4.1f %4.1f\n",kindex,aindex,cindex,fgrad,
248: findex);
249: printf("%d %ld %4.1f %4.2f %d %d\n",numsent,numwds,avw,avl,
250: qcount, icount);
251: }
252: if(numnonf != 0){
253: snonf = (float)(letnonf)/(float)(numnonf);
254: }
255: mg = avw + 10.5;
256: if(mg > 49)mg = 49;
257: ml = avw - 4.5;
258: if(ml <= 0)ml = 1;
259: else if(ml > 49)ml=48;
260: gsum = lsum = 0;
261: for(ii=0;ii<50;ii++){
262: if(ii < ml)lsum += sleng[ii];
263: else if(ii > mg)gsum+= sleng[ii];
264: }
265: if(verbc != 0)adjs = (float)(passive)*100/(float)(verbc);
266: else adjs=0;
267: ii=beg[0]+beg[7]+beg[6]+beg[3]+beg[8];
268: if(!sprint){
269: printf(" no. content wds %ld %4.1f%% av leng %4.2f\n",numnonf,(float)(numnonf)*100/numwds,snonf);
270: printf(" short sent (<%d)%3.0f%% (%d) long sent (>%d) %3.0f%% (%d)\n",ml,sperc(lsum),lsum,mg,sperc(gsum),gsum);
271: printf(" longest sent %d wds at sent %d; shortest sent %d wds at sent %d\n",maxsent,maxindex,minsent,minindex);
272: printf("sentence types:\n");
273: printf(" simple %3.0f%% (%d) complex %3.0f%% (%d)\n",sperc(simple),simple,sperc(complex),complex);
274: printf(" compound %3.0f%% (%d) compound-complex %3.0f%% (%d)\n",sperc(compound),compound,sperc(compdx),compdx);
275: printf("word usage:\n");
276: printf(" verb types as %% of total verbs\n");
277: printf(" tobe %3.0f%% (%d) aux %3.0f%% (%d) inf %3.0f%% (%d)\n",vperc(tobe),tobe,vperc(aux),aux,vperc(infin),infin);
278: printf(" passives as %% of non-inf verbs %3.0f%% (%d)\n",adjs,passive);
279: printf(" types as %% of total\n");
280: printf(" prep %3.1f%% (%d) conj %3.1f%% (%d) adv %3.1f%% (%d)\n",wperc(prepc),prepc,wperc(conjc),conjc,wperc(adv),adv);
281: printf(" noun %3.1f%% (%d) adj %3.1f%% (%d) pron %3.1f%% (%d)\n",wperc(noun),noun,
282: wperc(adj),adj,wperc(pron),pron);
283: printf(" nominalizations %3.0f %% (%d)\n",wperc(nomin),nomin);
284: printf("sentence beginnings:\n");
285: printf(" subject opener: noun (%d) pron (%d) pos (%d) adj (%d) art (%d) tot %3.0f%%\n",
286: beg[0],beg[7],beg[6],beg[3],beg[8],sperc(ii));
287: printf(" prep %3.0f%% (%d) adv %3.0f%% (%d) \n",sperc(beg[9]),beg[9],sperc(beg[4]),beg[4]);
288: printf(" verb %3.0f%% (%d) ",sperc(beg[1]+beg[10]+beg[11]),beg[1]+beg[10]+beg[11]);
289: printf(" sub_conj %3.0f%% (%d) conj %3.0f%% (%d)\n",sperc(beg[13]),beg[13],sperc(beg[5]),beg[5]);
290: printf(" expletives %3.0f%% (%d)\n",sperc(beg[14]),beg[14]);
291: }
292: else {
293: printf("%ld %4.1f %4.2f %d %3.0f %d %d %3.0f %d\n",numnonf,
294: (float)(numnonf)*100/numwds,snonf,ml,sperc(lsum),
295: lsum,mg,sperc(gsum),gsum);
296: printf("%d %d %d %d\n",maxsent,maxindex,minsent,minindex);
297: printf("%3.0f %d %3.0f %d %3.0f %d %3.0f %d\n",sperc(simple),simple,
298: sperc(complex),complex,sperc(compound),compound,sperc(compdx),
299: compdx);
300: printf("%3.0f %d %3.0f %d %3.0f %d %3.0f %d\n",vperc(tobe),tobe,
301: vperc(aux),aux,vperc(infin),infin,adjs,passive);
302: printf("%3.1f %d %3.1f %d %3.1f %d %3.1f %d %3.1f %d %3.1f %d %3.1f %d\n"
303: ,wperc(prepc),prepc,wperc(conjc),conjc,wperc(adv),adv,
304: wperc(noun),noun,wperc(adj),adj,wperc(pron),pron,
305: wperc(nomin),nomin);
306: printf("%d %d %d %d %d %3.0f\n",beg[0],beg[7],beg[6],beg[3],
307: beg[8],sperc(ii));
308: printf("%3.0f %d %3.0f %d %3.0f %d %3.0f %d %3.0f %d %3.0f %d\n" ,sperc(beg[9]),beg[9],sperc(beg[4]),beg[4],
309: sperc(beg[1]+beg[10]+beg[11]),
310: beg[1]+beg[10]+beg[11],sperc(beg[13]),beg[13],
311: sperc(beg[5]),beg[5],sperc(beg[14]),beg[14]);
312: }
313: #ifdef SCATCH
314: if(nosave && (fopen(SCATCH,"r")) != NULL){
315: if(((io=fopen(SCATCH,"a")) != NULL)){
316: fprintf(io," read %4.1f %4.1f %4.1f %4.1f %4.1f\n",kindex, aindex, cindex, findex, fgrad);
317: fprintf(io," sentl %d %ld %4.2f %4.2f %d %d %ld %4.2f\n",numsent,numwds,avw,avl,qcount,icount,numnonf,snonf);
318: fprintf(io," l var %d %d %d %d %d\n",ml,lsum,mg,gsum,maxsent);
319: fprintf(io," t var %d %d %d %d\n",simple,complex,compound,compdx);
320: fprintf(io," verbs %d %d %d %d %d %d\n",tverbc,verbc,tobe,aux,infin,passive);
321: fprintf(io," ty %d %d %d %d %d %d %d\n",prepc,conjc,adv,noun,adj,pron,nomin);
322: fprintf(io," beg %d %d %d %d %d %d\n",beg[0],beg[7],beg[6],beg[3],beg[8],ii);
323: fprintf(io," sbeg %d %d %d %d %d %d\n",beg[9],beg[4],beg[1]+beg[10]+beg[11],beg[13],beg[5],beg[14]);
324: }
325: }
326: #endif
327: }
328: return(1);
329: }
330: float
331: wperc(a)
332: {
333: return((float)(a)*100/numwds);
334: }
335: float
336: sperc(a)
337: {
338: return((float)(a)*100/numsent);
339: }
340: float
341: typersent(a)
342: {
343: return((float)(a)/numsent);
344: }
345: float
346: vperc(a)
347: {
348: if(tverbc == 0)return(0);
349: return((float)(a)*100/tverbc);
350: }
351: main(argc,argv)
352: char **argv;
353: {
354: while(--argc > 0 && (++argv)[0][0] == '-' ){
355: switch(argv[0][1]){
356: case 'd': nosave = 0;
357: continue;
358: case 'S': style=1;
359: continue;
360: case 'p': pastyle=style=1;
361: continue;
362: case 's': style = sstyle = 1;
363: sthresh = atoi(*(++argv));
364: argc--;
365: continue;
366: case 'a': pstyle=style=1;
367: continue;
368: case 'e': estyle = style = 1;
369: continue;
370: case 'E': sprint = style = 1;
371: continue;
372: case 'n': nstyle = style = 1;
373: continue;
374: case 'N': Nstyle = style = 1;
375: continue;
376: case 'l': style=lstyle=1;
377: lthresh = atoi(*(++argv));
378: argc--;
379: continue;
380: case 'r':
381: style=rstyle=1;
382: rthresh = atoi(*(++argv));
383: argc--;
384: continue;
385: case 'P':
386: part = 1;
387: style = 0;
388: continue;
389: case 'b': /* print bare bones info rje */
390: barebones = 1;
391: style = 0;
392: continue;
393: case 'T': /*topic*/
394: style = 0;
395: topic = 1;
396: continue;
397: case 'L': /*pass lineno info thru*/
398: lineflg = 1;
399: continue;
400: case 'C': /* pass commands thru */
401: lineflg = 2;
402: continue;
403: default:
404: fprintf(stderr,"unknown flag to part %s\n",*argv);
405: exit(1);
406: }
407: argv++;
408: }
409: #ifdef SNOM
410: if(fopen(SNOM,"r") != NULL){
411: deb = fopen(SNOM,"a"); /* SAVE NOM*/
412: }
413: #else
414: deb = NULL;
415: #endif
416: yylex();
417: if(nrofflg && sentno > 0){
418: printf(".SL \"");
419: for(i=0;i<sentno;i++)
420: printf(" %d",leng[i]);
421: printf("\"\n");
422: }
423: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.