revert between 56095 -> 55830 in arch
[AROS.git] / tools / cxref / cpp / cccp.c.diff
blob09661af9f194bb9629a9d99b0a2ac329d963eb76
1 --- original/cccp.c 2002-01-19 15:17:47.000000000 +0000
2 +++ cccp.c 2004-05-09 09:14:40.000000000 +0100
3 @@ -3,6 +3,10 @@
4 Written by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
7 + Modified by Andrew M. Bishop to provide better input to
8 + C documentation program `cxref' 1995,1996.
9 + All AMB hacks are indicated as such in the code (grep AMB).
11 This program is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2, or (at your option) any
14 @@ -70,6 +74,7 @@
15 #include <signal.h>
17 /* The following symbols should be autoconfigured:
18 + HAVE_ALLOCA_H - already in autoconfig.h, but not used, added by AMB
19 HAVE_FCNTL_H
20 HAVE_STDLIB_H
21 HAVE_SYS_TIME_H
22 @@ -117,6 +122,14 @@
23 # include <fcntl.h>
24 #endif
26 +/* Start new include added by AMB */
28 +#if HAVE_ALLOCA_H
29 +# include <alloca.h>
30 +#endif
32 +/* End new include added by AMB */
34 /* This defines "errno" properly for VMS, and gives us EACCES. */
35 #include <errno.h>
37 @@ -406,6 +419,16 @@
38 static enum {dump_none, dump_only, dump_names, dump_definitions}
39 dump_macros = dump_none;
41 +/* Start new option added by AMB */
43 +/* Nonzero means that the #include lines are to be passed through to
44 + output.
45 +*/
47 +static int dump_includes = 0;
49 +/* End new option added by AMB */
51 /* Nonzero means pass all #define and #undef directives which we actually
52 process through to the output stream. This feature is used primarily
53 to allow cc1 to record the #defines and #undefs for the sake of
54 @@ -655,6 +678,9 @@
55 include file directories. */
56 static char *include_prefix;
58 +/* File to include that contains the gcc definitions for cxref - AMB */
59 +static char *cxref_cpp_defines=CXREF_CPP_DEFINES;
61 /* Global list of strings read in from precompiled files. This list
62 is kept in the order the strings are read in, with new strings being
63 added at the end through stringlist_tailp. We use this list to output
64 @@ -964,7 +990,7 @@
65 /* Here is the actual list of #-directives, most-often-used first. */
67 static struct directive directive_table[] = {
68 - { 6, do_define, "define", T_DEFINE, 0, 1},
69 + { 6, do_define, "define", T_DEFINE, 0, 1, 1}, /* The last 1 is in future cccp.c added by AMB. */
70 { 2, do_if, "if", T_IF},
71 { 5, do_xifdef, "ifdef", T_IFDEF},
72 { 6, do_xifdef, "ifndef", T_IFNDEF},
73 @@ -1355,6 +1381,9 @@
74 no_line_directives = 0;
75 no_trigraphs = 1;
76 dump_macros = dump_none;
77 +/* Start new option added by AMB */
78 + dump_includes = 0;
79 +/* End new option added by AMB */
80 no_output = 0;
81 cplusplus = 0;
82 cplusplus_comments = 1;
83 @@ -1508,6 +1537,17 @@
85 break;
87 +/* Start new option added by AMB */
88 + case 'c':
89 + if (!strcmp (argv[i], "-cxref-cpp-defines")) {
90 + if (i + 1 == argc)
91 + fatal ("Filename missing after `-cxref-cpp-defines' option");
92 + else
93 + cxref_cpp_defines = argv[i+1], i++;
94 + }
95 + break;
96 +/* End new option added by AMB */
98 case 'o':
99 if (out_fname != NULL)
100 fatal ("Output filename specified twice");
101 @@ -1666,6 +1706,11 @@
102 case 'D':
103 dump_macros = dump_definitions;
104 break;
105 +/* Start new option added by AMB */
106 + case 'I':
107 + dump_includes = 1;
108 + break;
109 +/* End new option added by AMB */
113 @@ -1846,6 +1891,66 @@
114 and option processing. */
115 initialize_builtins (fp, &outbuf);
117 + /* Setup the cxref paths and definitions from gcc - AMB */
120 + int fd;
121 + int st_mode;
122 + long st_size;
123 + char *buf,*p,*oldp;
124 + char *include_dir1,*include_dir2,*include_dir3;
125 + struct default_include *incp;
127 + fd=open(cxref_cpp_defines, O_RDONLY, 0666);
128 + if(fd==-1)
129 + perror_with_name(cxref_cpp_defines);
131 + if(file_size_and_mode(fd, &st_mode, &st_size)<0)
132 + perror_with_name(cxref_cpp_defines);
134 + if(!S_ISREG(st_mode))
135 + perror_with_name(cxref_cpp_defines);
137 + buf=(U_CHAR *)xmalloc(st_size+2);
139 + if(safe_read(fd,buf,st_size)<0)
140 + perror_with_name(cxref_cpp_defines);
142 + p=oldp=buf;
144 + while(*p && (*p!='\r' && *p!='\n')) p++;
145 + while(*p && (*p=='\r' || *p=='\n')) *p++=0;
146 + predefs=savestring(oldp); oldp=p;
148 + while(*p && (*p!='\r' && *p!='\n')) p++;
149 + while(*p && (*p=='\r' || *p=='\n')) *p++=0;
150 + include_dir1=savestring(oldp); oldp=p;
152 + while(*p && (*p!='\r' && *p!='\n')) p++;
153 + while(*p && (*p=='\r' || *p=='\n')) *p++=0;
154 + include_dir2=savestring(oldp); oldp=p;
156 + while(*p && (*p!='\r' && *p!='\n')) p++;
157 + while(*p && (*p=='\r' || *p=='\n')) *p++=0;
158 + include_dir3=savestring(oldp); oldp=p;
160 + for(incp=include_defaults;incp->fname;incp++)
162 + if(!strcmp("INCLUDE_DIR1",incp->fname))
163 + incp->fname=include_dir1;
164 + if(!strcmp("INCLUDE_DIR2",incp->fname))
165 + incp->fname=include_dir2;
166 + if(!strcmp("INCLUDE_DIR3",incp->fname))
167 + incp->fname=include_dir3;
170 + lseek(fd,(int)(p-buf),SEEK_SET);
172 + no_output++; no_record_file++;
173 + finclude(fd,cxref_cpp_defines,&outbuf,0,NULL_PTR);
174 + no_output--; no_record_file--;
177 /* Do standard #defines and assertions
178 that identify system and machine type. */
180 @@ -1881,14 +1986,15 @@
181 past_name = assertion;
182 /* Locate end of name. */
183 while (*past_name && *past_name != ' '
184 - && *past_name != '\t' && *past_name != '(')
185 + && *past_name != '\t' && *past_name != '(' && *past_name != '=') /* Allowed to use 'foo=bar' instead of 'foo(bar)' by AMB */
186 past_name++;
187 /* Locate `(' at start of value. */
188 value = past_name;
189 while (*value && (*value == ' ' || *value == '\t'))
190 value++;
191 - if (*value++ != '(')
192 + if (*value != '(' && *value != '=') /* Allowed to use 'foo=bar' instead of 'foo(bar)' by AMB */
193 abort ();
194 + value++;
195 while (*value && (*value == ' ' || *value == '\t'))
196 value++;
197 past_value = value;
198 @@ -1897,10 +2003,14 @@
199 && *past_value != '\t' && *past_value != ')')
200 past_value++;
201 termination = past_value;
202 + /* Allowed to use 'foo=bar' instead of 'foo(bar)' by AMB
203 while (*termination && (*termination == ' ' || *termination == '\t'))
204 termination++;
205 if (*termination++ != ')')
206 abort ();
207 + */
208 + if (*termination == ')') /* Allowed to use 'foo=bar' instead of 'foo(bar)' by AMB */
209 + termination++;
210 if (*termination && *termination != ' ' && *termination != '\t')
211 abort ();
212 /* Temporarily null-terminate the value. */
213 @@ -3841,10 +3951,17 @@
214 bp = ip->bufp;
215 /* No need to copy the directive because of a comment at the end;
216 just don't include the comment in the directive. */
217 - if (bp == limit || *bp == '\n') {
218 - bp = obp;
219 - goto endloop1;
220 +/* Start of code from future cccp.c added by AMB */
221 + if (!put_out_comments) {
222 + U_CHAR *p;
223 + for (p = bp; *p == ' ' || *p == '\t'; p++)
224 + continue;
225 + if (*p == '\n') {
226 + bp = obp;
227 + goto endloop1;
230 +/* End of code from future cccp.c added by AMB */
231 /* Don't remove the comments if -traditional. */
232 if (! keep_comments)
233 copy_directive++;
234 @@ -3874,7 +3991,10 @@
236 /* If a directive should be copied through, and -E was given,
237 pass it through before removing comments. */
238 - if (!no_output && kt->pass_thru && put_out_comments) {
239 + if (!no_output && put_out_comments &&
240 +/* Start new option added by AMB */
241 + (kt->pass_thru || (kt->type == T_INCLUDE && dump_includes))) {
242 +/* End new option added by AMB */
243 int len;
245 /* Output directive name. */
246 @@ -4002,6 +4122,10 @@
248 if (!no_output && already_output == 0
249 && (kt->pass_thru
250 +/* Start new option added by AMB */
251 + || (kt->type == T_INCLUDE
252 + && dump_includes)
253 +/* End new option added by AMB */
254 || (kt->type == T_DEFINE
255 && (dump_macros == dump_names
256 || dump_macros == dump_definitions)))) {
257 @@ -4013,7 +4137,11 @@
258 bcopy (kt->name, (char *) op->bufp, kt->length);
259 op->bufp += kt->length;
261 - if (kt->pass_thru || dump_macros == dump_definitions) {
262 + if (kt->pass_thru || dump_macros == dump_definitions
263 +/* Start new option added by AMB */
264 + || dump_includes
265 +/* End new option added by AMB */
266 + ) {
267 /* Output arguments. */
268 len = (cp - buf);
269 check_expand (op, len);
270 @@ -9601,6 +9729,7 @@
271 install ((U_CHAR *) "__FILE__", -1, T_FILE, NULL_PTR, -1);
272 install ((U_CHAR *) "__BASE_FILE__", -1, T_BASE_FILE, NULL_PTR, -1);
273 install ((U_CHAR *) "__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, NULL_PTR, -1);
274 + /* Don't setup the standard #defines - AMB
275 install ((U_CHAR *) "__VERSION__", -1, T_VERSION, NULL_PTR, -1);
276 #ifndef NO_BUILTIN_SIZE_TYPE
277 install ((U_CHAR *) "__SIZE_TYPE__", -1, T_SIZE_TYPE, NULL_PTR, -1);
278 @@ -9615,6 +9744,7 @@
279 NULL_PTR, -1);
280 install ((U_CHAR *) "__IMMEDIATE_PREFIX__", -1, T_IMMEDIATE_PREFIX_TYPE,
281 NULL_PTR, -1);
282 + */
283 install ((U_CHAR *) "__TIME__", -1, T_TIME, NULL_PTR, -1);
284 if (!traditional) {
285 install ((U_CHAR *) "__STDC__", -1, T_CONST, "1", -1);
286 @@ -9639,6 +9769,7 @@
287 pass_thru_directive (udirective, &udirective[strlen (directive)],
288 outp, dp);
290 + /* Don't setup the standard #defines - AMB
291 sprintf (directive, " __VERSION__ \"%s\"\n", version_string);
292 output_line_directive (inp, outp, 0, same_file);
293 pass_thru_directive (udirective, &udirective[strlen (directive)],
294 @@ -9662,6 +9793,7 @@
295 output_line_directive (inp, outp, 0, same_file);
296 pass_thru_directive (udirective, &udirective[strlen (directive)],
297 outp, dp);
298 + */
300 sprintf (directive, " __DATE__ \"%s %2d %4d\"\n",
301 monthnames[timebuf->tm_mon],
302 @@ -9826,7 +9958,7 @@
303 U_CHAR *buf, *p, *q;
305 /* Copy the entire option so we can modify it. */
306 - buf = (U_CHAR *) alloca (strlen (str) + 1);
307 + buf = (U_CHAR *) alloca (strlen (str) + 2); /* 1 added to alloca length by AMB */
308 strcpy ((char *) buf, str);
309 /* Scan for any backslash-newline and remove it. */
310 p = q = buf;
311 @@ -9846,10 +9978,18 @@
312 while (is_idchar[*++p])
314 SKIP_WHITE_SPACE (p);
315 - if (! (*p == 0 || *p == '(')) {
316 + if (! (*p == 0 || *p == '(' || *p == '=')) { /* Allowed to use 'foo=bar' instead of 'foo(bar)' by AMB */
317 error ("malformed option `%s %s'", option, str);
318 return;
321 +/* Start change added by AMB (handles gcc 3.x "-Afoo=bar") */
322 + if(*p=='=')
324 + *p='(';
325 + strcat(p,")");
327 +/* End change added by AMB (handles gcc 3.x "-Afoo=bar") */
329 ip = &instack[++indepth];
330 ip->nominal_fname = ip->fname = "*Initialization*";