Pristine Ack-5.5
[Ack-5.5.git] / lang / pc / comp / options.c
1 /* U S E R   O P T I O N - H A N D L I N G */
2
3 #include        <em_arith.h>
4 #include        <em_label.h>
5
6 #include        "class.h"
7 #include        "const.h"
8 #include        "idfsize.h"
9 #include        "main.h"
10 #include        "type.h"
11 #include        "nocross.h"
12 #include        "dbsymtab.h"
13
14 #define MINIDFSIZE      9
15
16 #if MINIDFSIZE < 9
17 You fouled up! MINIDFSIZE has to be at least 10 or the compiler will not
18 recognize some keywords!
19 #endif
20
21 extern int      idfsize;
22
23 DoOption(text)
24         register char *text;
25 {
26         switch( *text++ )       {
27
28         default:
29                 options[text[-1]]++;    /* flags, debug options etc.    */
30                 break;
31                                 /* recognized flags:
32                                         -i: largest value of set of integer
33                                         -u, -U: allow underscore in identifier
34                                         -w: no warnings
35                                         -R: no range checks
36                                         -A: range checks for array references
37                                    and many more if DEBUG
38                                 */
39
40
41 #ifdef DBSYMTAB
42         case 'g':
43                 options['g'] = 1;
44                 options['n'] = 1;
45                 break;
46 #endif
47         case 'i':       {               /* largest value of set of integer */
48                 char *t = text;
49
50                 max_intset = txt2int(&t);
51                 text = t;
52                 if( max_intset <= (arith) 0 || *t )     {
53                         error("bad -i flag : use -i<num>");
54                         max_intset = 0;
55                 }
56                 break;
57         }
58
59         case 'M': {     /* maximum identifier length */
60                 char *t = text;
61
62                 idfsize = txt2int(&t);
63                 text = t;
64                 if( idfsize <= 0 || *t ) {
65                         fatal("malformed -M option");
66                         /*NOTREACHED*/
67                 }
68                 if( idfsize > IDFSIZE ) {
69                         idfsize = IDFSIZE;
70                         warning("maximum identifier length is %d", IDFSIZE);
71                 }
72                 if( idfsize < MINIDFSIZE )      {
73                         idfsize = MINIDFSIZE;
74                         warning("minimum identifier length is %d", MINIDFSIZE);
75                 }
76                 break;
77         }
78
79         /* case 'u':                    /* underscore allowed in identifiers */
80                 /* class('_') = STIDF;
81                 /* inidf['_'] = 1;
82                 /* break;
83                 */
84
85         case 'V' :      { /* set object sizes and alignment requirements */
86                           /* syntax : -V[ [w|i|l|f|p] size? [.alignment]? ]* */
87 #ifndef NOCROSS
88                 register arith size;
89                 register int align;
90                 char c, *t;
91
92                 while( c = *text++ )    {
93                         char *strindex();
94
95                         t = text;
96                         size = txt2int(&t);
97                         align = 0;
98                         if( *(text = t) == '.' )        {
99                                 t = text + 1;
100                                 align = txt2int(&t);
101                                 text = t;
102                         }
103                         if( !strindex("wilfpS", c) )
104                                 error("-V: bad type indicator %c\n", c);
105                         if( size )
106                                 switch( c )     {
107                                 case 'w':       /* word         */
108                                         word_size = size;
109                                         break;
110                                 case 'i':       /* int          */
111                                         int_size = size;
112                                         break;
113                                 case 'l':       /* long         */
114                                         long_size = size;
115                                         break;
116                                 case 'f':       /* real         */
117                                         real_size = size;
118                                         break;
119                                 case 'p':       /* pointer      */
120                                         pointer_size = size;
121                                         break;
122                                 case 'S':       /* structure    */
123                                         /* discard size */
124                                         break;
125                                 }
126
127                         if( align )
128                                 switch( c )     {
129                                 case 'w':       /* word         */
130                                         word_align = align;
131                                         break;
132                                 case 'i':       /* int          */
133                                         int_align = align;
134                                         break;
135                                 case 'l':       /* long         */
136                                         long_align = align;
137                                         break;
138                                 case 'f':       /* real         */
139                                         real_align = align;
140                                         break;
141                                 case 'p':       /* pointer      */
142                                         pointer_align = align;
143                                         break;
144                                 case 'S':       /* initial record alignment */
145                                         struct_align = align;
146                                         break;
147                                 }
148                 }
149                 break;
150 #endif /* NOCROSS */
151         }
152         }
153 }
154
155 int
156 txt2int(tp)
157         register char **tp;
158 {
159         /*      the integer pointed to by *tp is read, while increasing
160                 *tp; the resulting value is yielded.
161         */
162         register int val = 0;
163         register int ch;
164         
165         while( ch = **tp, ch >= '0' && ch <= '9' )      {
166                 val = val * 10 + ch - '0';
167                 (*tp)++;
168         }
169         return val;
170 }