-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.y
2118 lines (2016 loc) · 53.4 KB
/
parse.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%{
#ifndef lint
static char Rcs_Id[] =
"$Id: parse.y,v 1.67 2021-01-09 13:12:35-08 geoff Exp $";
#endif
/*
* Copyright 1992, 1993, 1999, 2001, 2005, Geoff Kuenning, Claremont, CA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All modifications to the source code must be clearly marked as
* such. Binary redistributions based on modified source code
* must be clearly marked as modified versions in the documentation
* and/or other materials provided with the distribution.
* 4. The code that causes the 'ispell -v' command to display a prominent
* link to the official ispell Web site may not be removed.
* 5. The name of Geoff Kuenning may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* $Log: parse.y,v $
* Revision 1.67 2021-01-09 13:12:35-08 geoff
* Fix some warnings generated by the new version of bison. Change
* addstringchar to sort stringchars with the character type as the major
* key and the character itself as the secondary key.
*
* Revision 1.66 2020-12-30 22:33:41-08 geoff
* Add support for character-set options.
*
* Revision 1.65 2005-04-20 16:16:32-07 geoff
* Rename some variables to make them more meaningful. Add (disabled)
* code to detect cases where not all alternate string characters are
* defined. Add (disabled) code to detect duplicate alternate string
* character definitions. Rewrite the code that assigns group numbers to
* string chracters, making it faster and more robust.
*
* Revision 1.64 2005/04/14 14:38:23 geoff
* Update license. Get rid of a stray semicolon that's been there for
* over a decade. For 64 mask bits, allow the non-alphabetic flag
* characters that fall between 'Z' and 'a'.
*
* Revision 1.63 2002/06/20 23:46:16 geoff
* Fix a bug in flag checking when using 64 mask bits.
*
* Revision 1.62 2001/09/06 00:30:29 geoff
* Changes from Eli Zaretskii to support DJGPP compilation.
*
* Revision 1.61 2001/07/25 21:51:46 geoff
* Minor license update.
*
* Revision 1.60 2001/07/23 20:24:04 geoff
* Update the copyright and the license.
*
* Revision 1.59 2000/08/22 10:52:25 geoff
* Fix a whole bunch of signed/unsigned discrepancies.
*
* Revision 1.58 2000/02/07 22:16:53 geoff
* Fix a minor typo in a synonym
*
* Revision 1.57 1999/01/18 03:28:40 geoff
* Turn many char declarations into unsigned char, so that we won't have
* sign-extension problems.
*
* Revision 1.56 1999/01/07 01:23:11 geoff
* Update the copyright.
*
* Revision 1.55 1999/01/03 01:46:41 geoff
* Add support for the "plain" deformatters.
*
* Revision 1.54 1997/12/02 06:25:04 geoff
* Get rid of some compile options that really shouldn't be optional.
*
* Revision 1.53 1995/11/08 05:09:22 geoff
* Allow html/sgml as a deformatter type.
*
* Revision 1.52 1994/11/21 07:03:03 geoff
* Get rid of the last vestiges of the "+" flag option.
*
* Revision 1.51 1994/11/02 06:56:13 geoff
* Remove the anyword feature, which I've decided is a bad idea.
*
* Revision 1.50 1994/10/25 05:46:22 geoff
* Add support for the "+" (any word) flag modifier.
*
* Revision 1.49 1994/09/16 04:48:30 geoff
* Allow more than 128 string characters, by using different types in the
* appropriate places.
*
* Revision 1.48 1994/05/24 05:31:25 geoff
* Remember to convert the flag bit from a character to a bit number
* before putting it in the hash file.
*
* Revision 1.47 1994/05/24 04:54:33 geoff
* Improve the error checking for affix flag names, detecting bad flags
* and duplicates.
*
* Revision 1.46 1994/05/22 01:38:02 geoff
* Don't force flags to uppercase if lowercase flags are legal
*
* Revision 1.45 1994/05/17 06:44:17 geoff
* Add support for controlled compound formation and the COMPOUNDONLY
* option to affix flags.
*
* Revision 1.44 1994/02/07 05:51:03 geoff
* Fix a place where atoi got the wrong argument type (lint error only)
*
* Revision 1.43 1994/01/25 07:12:01 geoff
* Get rid of all old RCS log lines in preparation for the 3.1 release.
*
*/
#include <ctype.h>
#include "config.h"
#include "ispell.h"
#include "proto.h"
#include "msgs.h"
%}
%union
{
int simple; /* Simple char or lval from yylex */
struct
{
unsigned char * set; /* Character set */
int complement; /* NZ if it is a complement set */
}
charset;
unsigned char * string; /* String */
ichar_t * istr; /* Internal string */
struct flagent * entry; /* Flag entry */
}
%{
static int yylex P ((void)); /* Trivial lexical analyzer */
static int kwanalyze P ((int backslashed, unsigned char * str));
/* Analyze a possible keyword */
static void getqstring P ((void));
/* Get (double-)quoted string */
static void getrange P ((void)); /* Get a lexical character range */
static int backch P ((void)); /* Process a backslashed character */
static void yyerror P ((char * msg));
/* Print out an error message */
int yyopen P ((char * file));
/* Open a table file */
void yyinit P ((void)); /* Initialize for parsing */
static int grabchar P ((void));
/* Get a character and track line number */
static void ungrabchar P ((int ch));
/* Unget a character, tracking line numbers */
static int sufcmp P ((struct flagent * flag1, struct flagent * flag2));
/* Compare suffix flags for qsort */
static int precmp P ((struct flagent * flag1, struct flagent * flag2));
/* Compare prefix flags for qsort */
static int addstringchar P ((unsigned char * str, int lower, int upper));
/* Add a string character to the table */
static int stringcharcmp P ((unsigned char * a, unsigned char * b));
/* Strcmp() done right, for Sun 4's */
#ifdef TBLDEBUG
static void tbldump P ((struct flagent * flagp, int numflags));
/* Dump a flag table */
static void entdump P ((struct flagent * flagp));
/* Dump one flag entry */
static void setdump P ((unsigned char * setp, int mask));
/* Dump a set specification */
static void subsetdump P ((unsigned char * setp, int mask, int dumpval));
/* Dump part of a set spec */
#endif
struct kwtab
{
char * kw; /* Syntactic keyword */
int val; /* Lexical value */
};
#define TBLINC 10 /* Size to allocate table by */
static FILE * aff_file = NULL; /* Input file pointer */
static int centnum; /* Number of entries in curents */
static int centsize = 0; /* Size of alloc'ed space in curents */
static int ctypechars; /* Size of string in current strtype */
static int ctypenum = 0; /* Number of entries in chartypes */
static int ctypesize = 0; /* Size of alloc'ed spc in chartypes */
static struct flagent * curents; /* Current flag entry collection */
static char * fname = "(stdin)"; /* Current file name */
static char lexungrab[MAXSTRINGCHARLEN * 2]; /* Spc for ungrabch */
static int lineno = 1; /* Current line number in file */
static int nbasestrings = 0; /* Number of base stringchars */
static struct flagent * table; /* Current table being built */
static int tblnum; /* Numer of entries in table */
static int tblsize = 0; /* Size of the flag table */
static int ungrablen; /* Size of ungrab area */
%}
%token <simple> '-'
%token <simple> '>'
%token <simple> ','
%token <simple> ':'
%token <simple> '.'
%token <simple> '*'
%token <simple> '~'
%token <simple> ALLAFFIXES
%token <simple> ALTSTRINGCHAR
%token <simple> ALTSTRINGTYPE
%token <simple> BOUNDARYCHARS
%token <simple> COMPOUNDMIN
%token <simple> COMPOUNDWORDS
%token <simple> CONTROLLED
%token <simple> DEFSTRINGTYPE
%token <simple> FLAG
%token <simple> FLAGMARKER
%token <simple> NROFFCHARS
%token <simple> OFF
%token <simple> ON
%token <simple> OPTIONS
%token <simple> PREFIXES
%token <charset> RANGE
%token <simple> SUFFIXES
%token <string> STRING
%token <simple> STRINGCHAR
%token <simple> TEXCHARS
%token <simple> WORDCHARS
%type <simple> file
%type <simple> headers
%type <simple> option_group
%type <simple> main_charset
%type <simple> charset_options
%type <simple> charset_group
%type <simple> altchar_group
%type <simple> charset_stmt
%type <simple> option_stmt
%type <simple> charset_option_group
%type <simple> charset_option
%type <simple> altchar_stmt
%type <simple> altchar_spec_group
%type <simple> altchar_spec
%type <simple> deftype_stmt
%type <string> stringtype_info
%type <simple> filesuf_list
%type <string> filesuf
%type <charset> char_set
%type <simple> tables
%type <simple> prefix_table
%type <simple> suffix_table
%type <simple> table
%type <simple> flagdef
%type <simple> flagoptions
%type <simple> flagoption
%type <simple> error
%type <simple> on_or_off
%type <simple> rules
%type <entry> affix_rule
%type <entry> cond_or_null
%type <entry> conditions
%type <istr> ichar_string
%%
file : headers tables
| tables
;
headers : option_group main_charset
| option_group main_charset altchar_group
| main_charset
| main_charset altchar_group
;
option_group : option_stmt
| option_group option_stmt
;
main_charset : deftype_stmt charset_options charset_group
| deftype_stmt charset_group
| charset_options charset_group
| charset_group
;
charset_group : charset_stmt
{
nbasestrings = hashheader.nstrchars;
}
| charset_group charset_stmt
{
nbasestrings = hashheader.nstrchars;
}
;
deftype_stmt : DEFSTRINGTYPE stringtype_info
;
altchar_group : altchar_stmt
/*
* The following error message is disabled (if 0)
* because (a) the test doesn't work right with
* PARSE_Y_MULTIPLE_STRINGS disabled, and (b) I'm
* not convinced that it's always a mistake to
* leave some alternates undefined.
*/
{
#if 0
if (hashheader.nstrchars
!= ctypenum * nbasestrings)
yyerror (PARSE_Y_WRONG_STRING_COUNT);
#endif /* 0 */
}
| altchar_group altchar_stmt
/*
* The following error message is disabled (if 0)
* because (a) the test doesn't work right with
* PARSE_Y_MULTIPLE_STRINGS disabled, and (b) I'm
* not convinced that it's always a mistake to
* leave some alternates undefined.
*/
{
#if 0
if (hashheader.nstrchars
!= ctypenum * nbasestrings)
yyerror (PARSE_Y_WRONG_STRING_COUNT);
#endif /* 0 */
}
;
charset_options : OPTIONS charset_option_group
;
charset_option_group : charset_option
| charset_option_group charset_option
;
charset_option : STRING
{
static struct
{
char* name;
int value;
}
choices[] =
{
{"raw_display", RAW_DISPLAY},
{"squeeze_strings", SQUEEZE_STRINGS},
};
unsigned int i;
for (i = 0;
i < sizeof choices / sizeof choices[0];
i++)
{
if (strcmp ((char *) $1, choices[i].name) == 0)
break;
}
if (i >= sizeof choices / sizeof choices[0])
{
yyerror (PARSE_Y_BAD_OPTION);
exit (1);
}
/*
* The current stringchar group is in defstringgroup
*/
chartypes[defstringgroup].options
|= choices[i].value;
}
;
charset_stmt : WORDCHARS char_set char_set
{
int nextlower;
int nextupper;
for (nextlower = SET_SIZE + hashheader.nstrchars;
--nextlower > SET_SIZE;
)
{
if ($2.set[nextlower] != 0
|| $3.set[nextlower] != 0)
{
yyerror (PARSE_Y_NO_WORD_STRINGS);
break;
}
}
for (nextlower = 0;
nextlower < SET_SIZE;
nextlower++)
{
hashheader.wordchars[nextlower]
|= $2.set[nextlower] | $3.set[nextlower];
hashheader.lowerchars[nextlower]
|= $2.set[nextlower];
hashheader.upperchars[nextlower]
|= $3.set[nextlower];
}
for (nextlower = nextupper = 0;
nextlower < SET_SIZE;
nextlower++)
{
if ($2.set[nextlower])
{
for ( ;
nextupper < SET_SIZE
&& !$3.set[nextupper];
nextupper++)
;
if (nextupper == SET_SIZE)
yyerror (PARSE_Y_UNMATCHED);
else
{
hashheader.lowerconv[nextupper]
= (ichar_t) nextlower;
hashheader.upperconv[nextlower]
= (ichar_t) nextupper;
hashheader.sortorder[nextupper]
= hashheader.sortval++;
hashheader.sortorder[nextlower]
= hashheader.sortval++;
nextupper++;
}
}
}
for ( ; nextupper < SET_SIZE; nextupper++)
{
if ($3.set[nextupper])
yyerror (PARSE_Y_UNMATCHED);
}
free ($2.set);
free ($3.set);
}
| WORDCHARS char_set
{
int i;
for (i = SET_SIZE + hashheader.nstrchars;
--i > SET_SIZE;
)
{
if ($2.set[i] != 0)
{
yyerror (PARSE_Y_NO_WORD_STRINGS);
break;
}
}
for (i = 0; i < SET_SIZE; i++)
{
if ($2.set[i])
{
hashheader.wordchars[i] = 1;
hashheader.sortorder[i]
= hashheader.sortval++;
}
}
free ($2.set);
}
| BOUNDARYCHARS char_set char_set
{
int nextlower;
int nextupper;
for (nextlower = SET_SIZE + hashheader.nstrchars;
--nextlower > SET_SIZE;
)
{
if ($2.set[nextlower] != 0
|| $3.set[nextlower] != 0)
{
yyerror (PARSE_Y_NO_BOUNDARY_STRINGS);
break;
}
}
for (nextlower = 0;
nextlower < SET_SIZE;
nextlower++)
{
hashheader.boundarychars[nextlower]
|= $2.set[nextlower] | $3.set[nextlower];
hashheader.lowerchars[nextlower]
|= $2.set[nextlower];
hashheader.upperchars[nextlower]
|= $3.set[nextlower];
}
for (nextlower = nextupper = 0;
nextlower < SET_SIZE;
nextlower++)
{
if ($2.set[nextlower])
{
for ( ;
nextupper < SET_SIZE
&& !$3.set[nextupper];
nextupper++)
;
if (nextupper == SET_SIZE)
yyerror (PARSE_Y_UNMATCHED);
else
{
hashheader.lowerconv[nextupper]
= (ichar_t) nextlower;
hashheader.upperconv[nextlower]
= (ichar_t) nextupper;
hashheader.sortorder[nextupper]
= hashheader.sortval++;
hashheader.sortorder[nextlower]
= hashheader.sortval++;
nextupper++;
}
}
}
for ( ; nextupper < SET_SIZE; nextupper++)
{
if ($3.set[nextupper])
yyerror (PARSE_Y_UNMATCHED);
}
free ($2.set);
free ($3.set);
}
| BOUNDARYCHARS char_set
{
int i;
for (i = SET_SIZE + hashheader.nstrchars;
--i > SET_SIZE;
)
{
if ($2.set[i] != 0)
{
yyerror (PARSE_Y_NO_BOUNDARY_STRINGS);
break;
}
}
for (i = 0; i < SET_SIZE; i++)
{
if ($2.set[i])
{
hashheader.boundarychars[i] = 1;
hashheader.sortorder[i]
= hashheader.sortval++;
}
}
free ($2.set);
}
| STRINGCHAR STRING
{
int len;
len = strlen ((char *) $2);
if (len > MAXSTRINGCHARLEN)
yyerror (PARSE_Y_LONG_STRING);
else if (len == 0)
yyerror (PARSE_Y_NULL_STRING);
else if (hashheader.nstrchars >= MAXSTRINGCHARS)
yyerror (PARSE_Y_MANY_STRINGS);
else
(void) addstringchar ($2, 0, 0);
free ((char *) $2);
}
| STRINGCHAR STRING STRING
{
int lcslot;
unsigned int len;
int ucslot;
len = strlen ((char *) $2);
if (strlen ((char *) $3) != len)
yyerror (PARSE_Y_LENGTH_MISMATCH);
else if (len > MAXSTRINGCHARLEN)
yyerror (PARSE_Y_LONG_STRING);
else if (len == 0)
yyerror (PARSE_Y_NULL_STRING);
else if (hashheader.nstrchars >= MAXSTRINGCHARS)
yyerror (PARSE_Y_MANY_STRINGS);
else
{
/*
* Add the uppercase character first, so that
* it will sort first.
*/
lcslot = ucslot = addstringchar ($3, 0, 1);
if (ucslot >= 0)
lcslot = addstringchar ($2, 1, 0);
if (ucslot >= 0 && lcslot >= 0)
{
if (ucslot >= lcslot)
ucslot++;
hashheader.lowerconv[ucslot] =
(ichar_t) lcslot;
hashheader.upperconv[lcslot] =
(ichar_t) ucslot;
}
}
free ((char *) $2);
free ((char *) $3);
}
;
altchar_stmt : ALTSTRINGTYPE stringtype_info
| ALTSTRINGTYPE stringtype_info charset_options
| ALTSTRINGTYPE stringtype_info altchar_spec_group
| ALTSTRINGTYPE stringtype_info charset_options
altchar_spec_group
;
stringtype_info : STRING STRING filesuf_list
{
chartypes[ctypenum].name = (unsigned char *) $1;
chartypes[ctypenum].deformatter = (char *) $2;
chartypes[ctypenum].options = 0;
/*
* Implement a few common synonyms. This should
* be generalized.
*/
if (strcmp ((char *) $2, "none") == 0)
(void) strcpy ((char *) $2, "plain");
else if (strcmp ((char *) $2, "TeX") == 0)
(void) strcpy ((char *) $2, "tex");
else if (strcmp ((char *) $2, "troff") == 0)
(void) strcpy ((char *) $2, "nroff");
else if (strcmp ((char *) $2, "HTML") == 0
|| strcmp ((char *) $2, "html") == 0
|| strcmp ((char *) $2, "SGML") == 0)
(void) strcpy ((char *) $2, "sgml");
/*
* Someday, we'll accept generalized deformatters.
* Then we can get rid of this test.
*/
if (strcmp ((char *) $2, "plain") != 0
&& strcmp ((char *) $2, "nroff") != 0
&& strcmp ((char *) $2, "tex") != 0
&& strcmp ((char *) $2, "sgml") != 0)
yyerror (PARSE_Y_BAD_DEFORMATTER);
ctypenum++;
hashheader.nstrchartype = ctypenum;
}
;
filesuf_list : filesuf
{
if (ctypenum >= ctypesize)
{
if (ctypesize == 0)
chartypes = (struct strchartype *)
malloc (TBLINC
* sizeof (struct strchartype));
else
chartypes = (struct strchartype *)
realloc ((char *) chartypes,
(ctypesize + TBLINC)
* sizeof (struct strchartype));
if (chartypes == NULL)
{
yyerror (PARSE_Y_NO_SPACE);
exit (1);
}
ctypesize += TBLINC;
}
ctypechars =
TBLINC * (strlen ((char *) $1) + 1) + 1;
chartypes[ctypenum].suffixes =
malloc ((unsigned int) ctypechars);
if (chartypes[ctypenum].suffixes == NULL)
{
yyerror (PARSE_Y_NO_SPACE);
exit (1);
}
(void) strcpy (chartypes[ctypenum].suffixes,
(char *) $1);
chartypes[ctypenum].suffixes
[strlen ((char *) $1) + 1]
= '\0';
free ((char *) $1);
}
| filesuf_list filesuf
{
char * nexttype;
int offset;
for (nexttype = chartypes[ctypenum].suffixes;
*nexttype != '\0';
nexttype += strlen (nexttype) + 1)
;
offset = nexttype - chartypes[ctypenum].suffixes;
if ((int) (offset + strlen ((char *) $2) + 1)
>= ctypechars)
{
ctypechars +=
TBLINC * (strlen ((char *) $2) + 1);
chartypes[ctypenum].suffixes =
realloc (chartypes[ctypenum].suffixes,
(unsigned int) ctypechars);
if (chartypes[ctypenum].suffixes == NULL)
{
yyerror (PARSE_Y_NO_SPACE);
exit (1);
}
nexttype =
chartypes[ctypenum].suffixes + offset;
}
(void) strcpy (nexttype, (char *) $2);
nexttype[strlen ((char *) $2) + 1] = '\0';
free ((char *) $2);
}
;
filesuf : STRING
;
altchar_spec_group
: altchar_spec
| altchar_spec_group altchar_spec
;
altchar_spec : ALTSTRINGCHAR STRING STRING
{
unsigned int len;
int slot;
defstringgroup = ctypenum - 1;
len = strlen ((char *) $2);
if (len > MAXSTRINGCHARLEN)
yyerror (PARSE_Y_LONG_STRING);
else if (len == 0)
yyerror (PARSE_Y_NULL_STRING);
else if (hashheader.nstrchars >= MAXSTRINGCHARS)
yyerror (PARSE_Y_MANY_STRINGS);
#if 0
/*
* The following error message is disabled (if 0)
* because it turns out some languages (e.g.,
* German) actually need to have multiple
* alternate stringchars mapping to the same base
* stringchar.
*/
else if (isstringch ($2, 0))
yyerror (PARSE_Y_MULTIPLE_STRINGS);
#endif /* 0 */
else if (!isstringch ($3, 1))
yyerror (PARSE_Y_NO_SUCH_STRING);
else
{
slot = addstringchar ($2, 0, 0) - SET_SIZE;
if (laststringch >= (unsigned int) slot)
laststringch++;
hashheader.stringdups[slot] = laststringch;
}
free ((char *) $2);
free ((char *) $3);
}
;
option_stmt : NROFFCHARS STRING
{
if (strlen ((char *) $2)
== sizeof (hashheader.nrchars))
(void) bcopy ((char *) $2, hashheader.nrchars,
sizeof (hashheader.nrchars));
else
yyerror (PARSE_Y_WRONG_NROFF);
free ((char *) $2);
}
| TEXCHARS STRING
{
if (strlen ((char *) $2)
== sizeof (hashheader.texchars))
(void) bcopy ((char *) $2, hashheader.texchars,
sizeof (hashheader.texchars));
else
yyerror (PARSE_Y_WRONG_TEX);
free ((char *) $2);
}
| COMPOUNDMIN STRING
{
unsigned char * digitp; /* Pointer to next digit */
for (digitp = $2; *digitp != '\0'; digitp++)
{
if (*digitp <= '0' || *digitp >= '9')
{
yyerror (PARSE_Y_BAD_NUMBER);
break;
}
}
hashheader.compoundmin = atoi ((char *) $2);
}
| COMPOUNDWORDS on_or_off
{
hashheader.compoundflag = $2;
}
| COMPOUNDWORDS CONTROLLED STRING
{
if (strlen ((char *) $3) != 1)
yyerror (PARSE_Y_LONG_FLAG);
else if (hashheader.compoundbit >= 0)
yyerror (PARSE_Y_DOUBLE_COMPOUND);
else
{
hashheader.compoundbit = (unsigned char) $3[0];
#if MASKBITS <= 128
hashheader.compoundbit &= 0x7f;
#endif /* MASKBITS */
#if MASKBITS <= 32
if (islower (hashheader.compoundbit))
hashheader.compoundbit =
toupper (hashheader.compoundbit);
#endif /* MASKBITS */
#if MASKBITS <= 64
if (hashheader.compoundbit < 'A'
|| hashheader.compoundbit > 'z')
yyerror (PARSE_Y_BAD_FLAG);
#endif /* MASKBITS */
hashheader.compoundbit =
CHARTOBIT (hashheader.compoundbit);
}
hashheader.compoundflag = COMPOUND_CONTROLLED;
}
| ALLAFFIXES on_or_off
{
hashheader.defhardflag = $2;
}
| FLAGMARKER STRING
{
if (strlen ((char *) $2) != 1)
yyerror (PARSE_Y_LONG_FLAG);
else
hashheader.flagmarker = $2[0];
free ((char *) $2);
}
;
char_set : '.'
{
int i;
unsigned char *
set;
set = (unsigned char *)
malloc (SET_SIZE + MAXSTRINGCHARS);
if (set == NULL)
{
yyerror (PARSE_Y_NO_SPACE);
exit (1);
}
$$.set = set;
for (i = SET_SIZE + MAXSTRINGCHARS; --i >= 0; )
*set++ = 1;
$$.complement = 0;
}
| STRING
{
unsigned int setlen;
$$.set = (unsigned char *)
malloc (SET_SIZE + MAXSTRINGCHARS);
if ($$.set == NULL)
{
yyerror (PARSE_Y_NO_SPACE);
exit (1);
}
(void) bzero ($$.set, SET_SIZE + MAXSTRINGCHARS);
if (l1_isstringch ($1, setlen, 1))
{
if (setlen != strlen ((char *) $1))
yyerror (PARSE_Y_NEED_BLANK);
$$.set[SET_SIZE + laststringch] = 1;
}
else
{
if (strlen ((char *) $1) != 1)
yyerror (PARSE_Y_NEED_BLANK);
$$.set[*$1] = 1;
}
free ((char *) $1);
$$.complement = 0;
}
| RANGE
;
on_or_off : ON
{
$$ = 1;
}
| OFF
{
$$ = 0;
}
;
tables : prefix_table suffix_table
| suffix_table prefix_table
| prefix_table
| suffix_table
;
prefix_table : PREFIXES table
{
pflaglist = table;
numpflags = tblnum;
/*
* Sort the flag table. This is critical so
* that ispell can build a correct index
* table. The idea is to put similar affixes
* together.
*/
qsort ((char *) table, (unsigned) tblnum,
sizeof (*table),
(int (*) P ((const void *, const void *)))
precmp);
#ifdef TBLDEBUG
(void) fprintf (stderr, "prefixes\n");
tbldump (table, tblnum);
#endif
tblsize = 0;
}
;
suffix_table : SUFFIXES table
{
sflaglist = table;
numsflags = tblnum;
/*
* See comments on the prefix sort.
*/
qsort ((char *) table, (unsigned) tblnum,
sizeof (*table),
(int (*) P ((const void *, const void *)))
sufcmp);
#ifdef TBLDEBUG
(void) fprintf (stderr, "suffixes\n");
tbldump (table, tblnum);
#endif
tblsize = 0;
}
;
table : flagdef
{
if (tblsize == 0)
{
tblsize = centnum + TBLINC;
tblnum = 0;
table = (struct flagent *)
malloc (tblsize * (sizeof (struct flagent)));
if (table == NULL)
{
yyerror (PARSE_Y_NO_SPACE);
exit (1);
}
}
else if (tblnum + centnum >= tblsize)
{
tblsize = tblnum + centnum + TBLINC;
table = (struct flagent *)
realloc ((char *) table,
tblsize * (sizeof (struct flagent)));
if (table == NULL)
{
yyerror (PARSE_Y_NO_SPACE);
exit (1);
}
}
for (tblnum = 0; tblnum < centnum; tblnum++)
table[tblnum] = curents[tblnum];
centnum = 0;
}
| table flagdef
{
int i;
if (tblnum + centnum >= tblsize)
{
tblsize = tblnum + centnum + TBLINC;
table = (struct flagent *)
realloc ((char *) table,
tblsize * (sizeof (struct flagent)));
if (table == NULL)
{
yyerror (PARSE_Y_NO_SPACE);
exit (1);
}
}
for (i = 0; i < centnum; i++)
table[tblnum + i] = curents[i];