Pristine Ack-5.5
[Ack-5.5.git] / lang / m2 / comp / options.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  *
5  * Author: Ceriel J.H. Jacobs
6  */
7
8 /* U S E R   O P T I O N - H A N D L I N G */
9
10 /* $Id: options.c,v 1.40 1995/12/04 15:29:39 ceriel Exp $ */
11
12 #include        "idfsize.h"
13
14 #include        <em_arith.h>
15 #include        <em_label.h>
16 #include        <alloc.h>
17
18 #include        "strict3rd.h"
19 #include        "dbsymtab.h"
20 #include        "type.h"
21 #include        "main.h"
22 #include        "warning.h"
23 #include        "nostrict.h"
24 #include        "nocross.h"
25 #include        "class.h"
26 #include        "squeeze.h"
27
28 #define MINIDFSIZE      14
29
30 #if MINIDFSIZE < 14
31 You fouled up! MINIDFSIZE has to be at least 14 or the compiler will not
32 recognize some keywords!
33 #endif
34
35 extern int      idfsize;
36 static int      ndirs = 1;
37 int             warning_classes = W_INITIAL;
38 int             gdb_flag;
39
40 DoOption(text)
41         register char *text;
42 {
43         switch(*text++) {
44
45         case '-':
46                 options[*text]++;       /* debug options etc.   */
47                 break;
48
49         case 'U':       /* allow underscores in identifiers */
50                 inidf['_'] = 1;
51                 break;
52         case 'L':       /* no fil/lin */
53         case 'R':       /* no range checks */
54         case 'A':       /* extra array bound checks, for machines that do not
55                            implement it in AAR/LAR/SAR
56                         */
57         case 'n':       /* no register messages */
58         case 'x':       /* every name global */
59         case 's':       /* symmetric: MIN(INTEGER) = -MAX(INTEGER) */
60         case '3':       /* strict 3rd edition Modula-2 */
61         case 'l':       /* local additions enabled */
62                 options[text[-1]]++;
63                 break;
64
65 #ifdef DBSYMTAB
66         case 'g':       /* generate symbol table for debugger */
67                 options['g']++;
68                 if (*text == 'd') {
69                         /* Assume -gdb. */
70                         gdb_flag = 1;
71                 }
72                 options['n']++; /* no register vars ??? */
73                 break;
74 #endif /* DBSYMTAB */
75
76         case 'w':
77                 if (*text) {
78                         while (*text) {
79                                 switch(*text++) {
80 #ifndef STRICT_3RD_ED
81                                 case 'O':
82                                         warning_classes &= ~W_OLDFASHIONED;
83                                         break;
84 #endif
85 #ifndef NOSTRICT
86                                 case 'R':
87                                         warning_classes &= ~W_STRICT;
88                                         break;
89 #endif
90                                 case 'W':
91                                         warning_classes &= ~W_ORDINARY;
92                                         break;
93                                 }
94                         }
95                 }
96                 else warning_classes = W_ALWAYS;
97                 break;
98
99         case 'W':
100                 if (*text) {
101                         while (*text) {
102                                 switch(*text++) {
103 #ifndef STRICT_3RD_ED
104                                 case 'O':
105                                         warning_classes |= W_OLDFASHIONED;
106                                         break;
107 #endif
108 #ifndef NOSTRICT
109                                 case 'R':
110                                         warning_classes |= W_STRICT;
111                                         break;
112 #endif
113                                 case 'W':
114                                         warning_classes |= W_ORDINARY;
115                                         break;
116                                 }
117                         }
118                 }
119                 else warning_classes = W_ALL;
120                 break;
121
122         case 'M': {     /* maximum identifier length */
123 #ifndef SQUEEZE
124                 char *t = text;         /* because &text is illegal */
125
126                 idfsize = txt2int(&t);
127                 if (*t || idfsize <= 0)
128                         fatal("malformed -M option");
129                 if (idfsize > IDFSIZE) {
130                         idfsize = IDFSIZE;
131                         warning(W_ORDINARY,"maximum identifier length is %d", IDFSIZE);
132                 }
133                 if (idfsize < MINIDFSIZE) {
134                         warning(W_ORDINARY, "minimum identifier length is %d", MINIDFSIZE);
135                         idfsize = MINIDFSIZE;
136                 }
137 #endif
138                 }
139                 break;
140
141         case 'I' :
142                 if (*text) {
143                         register int i;
144                         register char *new = text;
145
146                         if (nDEF > mDEF) {
147                                 DEFPATH = (char **)
148                                   Realloc((char *)DEFPATH,(unsigned)(mDEF+=10)*sizeof(char *));
149                         }
150
151                         for (i = ndirs++; i < nDEF; i++) {
152                                 char *tmp = DEFPATH[i];
153         
154                                 DEFPATH[i] = new;
155                                 new = tmp;
156                         }
157                         ++nDEF;
158                 }
159                 else    DEFPATH[ndirs] = 0;
160                 break;
161
162         case 'V' :      /* set object sizes and alignment requirements  */
163 #ifndef NOCROSS
164         {
165                 register int size;
166                 register int algn;
167                 char c;
168                 char *t;
169
170                 while (c = *text++)     {
171                         char *strindex();
172
173                         t = text;
174                         size = txt2int(&t);
175                         algn = 0;
176                         if (*(text = t) == '.') {
177                                 t = text + 1;
178                                 algn = txt2int(&t);
179                                 text = t;
180                         }
181                         if (! strindex("wislfdpS", c)) {
182                                 error("-V: bad type indicator %c\n", c);
183                         }
184                         if (size != 0) switch (c)       {
185
186                         case 'w':       /* word         */
187                                 word_size = size;
188                                 dword_size = 2 * size;
189                                 break;
190                         case 'i':       /* int          */
191                                 int_size = size;
192                                 break;
193                         case 's':       /* short (subranges) */
194                                 short_size = size;
195                                 break;
196                         case 'l':       /* longint      */
197                                 long_size = size;
198                                 break;
199                         case 'f':       /* real         */
200                                 float_size = size;
201                                 break;
202                         case 'd':       /* longreal     */
203                                 double_size = size;
204                                 break;
205                         case 'p':       /* pointer      */
206                                 pointer_size = size;
207                                 break;
208                         }
209                         if (algn != 0) switch (c)       {
210
211                         case 'w':       /* word         */
212                                 word_align = algn;
213                                 break;
214                         case 'i':       /* int          */
215                                 int_align = algn;
216                                 break;
217                         case 's':       /* short (subranges) */
218                                 short_align = algn;
219                                 break;
220                         case 'l':       /* longint      */
221                                 long_align = algn;
222                                 break;
223                         case 'f':       /* real         */
224                                 float_align = algn;
225                                 break;
226                         case 'd':       /* longreal     */
227                                 double_align = algn;
228                                 break;
229                         case 'p':       /* pointer      */
230                                 pointer_align = algn;
231                                 break;
232                         case 'S':       /* initial record alignment     */
233                                 struct_align = algn;
234                                 break;
235                         }
236                 }
237         }
238 #endif /* NOCROSS */
239         break;
240         }
241 }
242
243 #if (!SQUEEZE) | (!NOCROSS)
244 int
245 txt2int(tp)
246         register char **tp;
247 {
248         /*      the integer pointed to by *tp is read, while increasing
249                 *tp; the resulting value is yielded.
250         */
251         register int val = 0;
252         register int ch;
253         
254         while (ch = **tp, ch >= '0' && ch <= '9')       {
255                 val = val * 10 + ch - '0';
256                 (*tp)++;
257         }
258         return val;
259 }
260 #endif