Added package with the documentation and the examples
[lwc.git] / lwc_config.c
blob848a4ec1dc5faef25ca9b709bd7e38a4f508c7de
1 #include "global.h"
3 static NormPtr version (NormPtr p)
5 int maj = eval_int (CODE [p++]);
6 if (CODE [p++] != ',') parse_error (p, "version maj,min");
7 int min = eval_int (CODE [p++]);
8 if (maj > VERSION_MAJ || (maj == VERSION_MAJ && min > VERSION_MIN)) {
9 fprintf (stderr, "This program requires lwc version %i.%i\n", maj, min);
10 exit (0);
12 return CODE [p] == ';' ? p + 1 : p;
15 static NormPtr lwcdebug (NormPtr p)
17 #ifdef DEBUG
18 if (0);
19 #define DEBUGFLAG(x) else if (!tokcmp (CODE [p], #x)) debugflag.x=1;
20 DEBUGFLAG(GENERAL)
21 DEBUGFLAG(PROGRESS)
22 DEBUGFLAG(PEXPR)
23 DEBUGFLAG(PEXPR_EXTREME)
24 DEBUGFLAG(FUNCPROGRESS)
25 DEBUGFLAG(OUTPUT_INDENTED)
26 DEBUGFLAG(SHOWPROG)
27 DEBUGFLAG(DCL_TRACE)
28 DEBUGFLAG(TDEF_TRACE)
29 DEBUGFLAG(VIRTUALTABLES)
30 DEBUGFLAG(VIRTUALBASE)
31 DEBUGFLAG(VIRTUALCOMBINE)
32 DEBUGFLAG(PARSE_ERRORS_SEGFAULT)
33 DEBUGFLAG(NOSTDOUT)
34 DEBUGFLAG(REGEXP_DEBUG)
35 DEBUGFLAG(EXPR_ERRORS_FATAL)
36 else if (!tokcmp (CODE [p], "all")) {
37 debugflag.GENERAL = debugflag.PEXPR = debugflag.PEXPR_EXTREME =
38 debugflag.FUNCPROGRESS = debugflag.OUTPUT_INDENTED = debugflag.SHOWPROG =
39 debugflag.DCL_TRACE = debugflag.TDEF_TRACE = debugflag.VIRTUALTABLES =
40 debugflag.VIRTUALBASE = debugflag.VIRTUALCOMBINE = debugflag.REGEXP_DEBUG = 1;
41 } else if (CODE [p] == '>') {
42 char *s = expand (CODE [++p]);
43 if (*s == '"') {
44 s [strlen (s) - 1] = 0;
45 if (!(logstream = fopen (s + 1, "w")))
46 parse_error (p - 1, "Cant open this logfile");
47 } else if (*s >= '0' && *s <= '9')
48 logstream = fdopen (*s - '0', "w");
49 else parse_error (p, "You probably want : lwcdebug > \"file.out\"?");
50 } else parse_error (p, "debug flag not available");
51 #endif
52 return CODE [++p] == ';' ? p + 1 : p;
55 static NormPtr prologue (NormPtr p)
57 NormPtr p2;
58 for (p2 = p; CODE [p2] != ';'; p2++);
59 func_prologue = intndup (CODE + p, ++p2 - p);
60 return p2;
63 static NormPtr new (NormPtr p)
65 if (!syntax_pattern (p, '=', VERIFY_symbol, ';', -1))
66 parse_error (p, "new = func;");
67 new_wrap = CODE [p + 1];
68 return p + 3;
71 static NormPtr delete (NormPtr p)
73 if (!syntax_pattern (p, '=', VERIFY_symbol, ';', -1))
74 parse_error (p, "delete = func;");
75 delete_wrap = CODE [p + 1];
76 return p + 3;
79 static NormPtr comment_C (NormPtr p)
81 char *s = expand (CODE [p++]);
82 char *d = alloca (strlen (s));
83 if (*s != '"') parse_error (p, "comment_C \"string\";");
84 strcpy (d, s + 1);
85 d [strlen (d) - 1] = 0;
86 output_itoken (GLOBAL, new_symbol (strdup (d)));
87 return CODE [p] == ';' ? p + 1 : p;
90 #define BOOLEAN_GLOBAL(x, y, z) \
91 static inline NormPtr x (NormPtr p) \
93 y = z;\
94 return CODE [p] == ';' ? p + 1 : p;\
97 BOOLEAN_GLOBAL (struct_by_value, StructByRef, 0)
98 BOOLEAN_GLOBAL (struct_by_reference, StructByRef, 1)
99 BOOLEAN_GLOBAL (inline_virtual_tables, InlineAllVt, 1)
100 BOOLEAN_GLOBAL (const_virtual_tables, ConstVtables, 1)
101 BOOLEAN_GLOBAL (virtual_inheritance_declarations, VIDeclarations, 1)
102 BOOLEAN_GLOBAL (reentrant, Reentrant, 1)
103 BOOLEAN_GLOBAL (expand_all_auto, ExpandAllAutos, 1)
104 BOOLEAN_GLOBAL (noexceptions, ExceptionsUsed, 0)
105 BOOLEAN_GLOBAL (vtptr_noconst, vtptrConst, 0)
106 BOOLEAN_GLOBAL (no_linkonce, NoLinkonce, 1)
107 BOOLEAN_GLOBAL (gcc34cleanup, EHUnwind, 1)
108 BOOLEAN_GLOBAL (no_gcc34cleanup, EHUnwind, 0)
109 BOOLEAN_GLOBAL (onebigfile, OneBigFile, 1)
110 BOOLEAN_GLOBAL (no_have_aliases, HaveAliases, 0)
111 BOOLEAN_GLOBAL (x86stdcalls, StdcallMembers, 1)
112 BOOLEAN_GLOBAL (no_vtbl, ExportVtbl, 0)
115 NormPtr lwc_config (NormPtr p)
117 if (CODE [p++] != '{')
118 parse_error (p, "lwc_config");
120 while (CODE [p] != '}')
121 if (0);
122 #define OPTION(x) else if (!tokcmp (CODE [p], #x)) p = x (p + 1);
123 OPTION (version)
124 OPTION (lwcdebug)
125 OPTION (struct_by_value)
126 OPTION (struct_by_reference)
127 OPTION (comment_C)
128 OPTION (prologue)
129 OPTION (inline_virtual_tables)
130 OPTION (const_virtual_tables)
131 OPTION (virtual_inheritance_declarations)
132 OPTION (reentrant)
133 OPTION (expand_all_auto)
134 OPTION (noexceptions)
135 OPTION (vtptr_noconst)
136 OPTION (no_linkonce)
137 OPTION (gcc34cleanup)
138 OPTION (no_gcc34cleanup)
139 OPTION (onebigfile)
140 OPTION (no_have_aliases)
141 OPTION (x86stdcalls)
142 OPTION (new)
143 OPTION (delete)
144 OPTION (no_vtbl)
145 else parse_error_tok (CODE [p], "No such lwc option");
147 return p + 1;
150 //****************************************************************
152 NormPtr __C__ (NormPtr p)
154 if (!syntax_pattern (p, '=', VERIFY_string, ';', -1))
155 parse_error (p, "__C__ = \"string\";");
157 char *cc = expand (CODE [p + 1]);
158 char *s2 = (char*) alloca (strlen (cc));
159 strcpy (s2, cc + 1);
160 s2 [strlen (s2) - 1] = 0;
161 output_itoken (INCLUDE, new_symbol (strdup (s2)));
162 return p + 3;