Pristine Ack-5.5
[Ack-5.5.git] / lang / m2 / m2mm / 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 /* stripped down version from the one in the Modula-2 compiler */
11
12 /* $Id: options.c,v 1.6 1994/06/24 12:45:28 ceriel Exp $ */
13
14 #include        <alloc.h>
15 #include        "main.h"
16
17 static int      ndirs = 1;
18
19 DoOption(text)
20         register char *text;
21 {
22         extern char *mflags;
23         extern char *suff;
24         extern char *compiler;
25         extern char *llibs;
26
27         switch(*text++) {
28
29         case 'L' :
30                 AddLibDir(text);
31                 break;
32
33         case 'I' :
34                 AddInclDir(text);
35                 break;
36         
37         case 'M':
38                 mflags = text;
39                 break;
40
41         case 'C':
42                 compiler = text;
43                 break;
44
45         case 'S':
46                 suff = text;
47                 break;
48
49         case 'l':
50                 {       static unsigned int liblen = 0;
51                         unsigned int len = strlen(text) + 4;
52                         
53                         if (liblen) {
54                                 llibs = Realloc(llibs, liblen += len);
55                         }
56                         else {
57                                 llibs = Malloc(liblen = len);
58                                 *llibs = '\0';
59                         }
60                         strcat(llibs,"\\\n\t");
61                         strcat(llibs, text);
62                 }
63                 break;
64
65         default:
66                 Gerror("Unrecognized option: -%s", text-1);
67                 break;
68         }
69 }
70
71 AddInclDir(text)
72         char *text;
73 {
74         register int i;
75         register char *new = text;
76
77         if (! *text) {
78                 DEFPATH[ndirs] = 0;
79                 return;
80         }
81
82         if (++nDEF > mDEF) {
83                 mDEF += 10;
84                 DEFPATH = (char **) Realloc((char *)DEFPATH,
85                                         (unsigned)(mDEF * sizeof(char *)));
86         }
87
88         for (i = ndirs++; i < nDEF; i++) {
89                 char *tmp = DEFPATH[i];
90
91                 DEFPATH[i] = new;
92                 new = tmp;
93         }
94 }
95
96 AddLibDir(text)
97         char *text;
98 {
99         if (*text) {
100                 set_libdir(ndirs);
101                 AddInclDir(text);
102         }
103 }