1 --- original/cccp.c 2002-01-19 15:17:47.000000000 +0000
2 +++ cccp.c 2004-05-09 09:14:40.000000000 +0100
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
17 /* The following symbols should be autoconfigured:
18 + HAVE_ALLOCA_H - already in autoconfig.h, but not used, added by AMB
26 +/* Start new include added by AMB */
32 +/* End new include added by AMB */
34 /* This defines "errno" properly for VMS, and gives us EACCES. */
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
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
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
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},
74 no_line_directives = 0;
76 dump_macros = dump_none;
77 +/* Start new option added by AMB */
79 +/* End new option added by AMB */
82 cplusplus_comments = 1;
83 @@ -1508,6 +1537,17 @@
87 +/* Start new option added by AMB */
89 + if (!strcmp (argv[i], "-cxref-cpp-defines")) {
91 + fatal ("Filename missing after `-cxref-cpp-defines' option");
93 + cxref_cpp_defines = argv[i+1], i++;
96 +/* End new option added by AMB */
99 if (out_fname != NULL)
100 fatal ("Output filename specified twice");
101 @@ -1666,6 +1706,11 @@
103 dump_macros = dump_definitions;
105 +/* Start new option added by AMB */
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 */
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);
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);
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 */
187 /* Locate `(' at start of value. */
189 while (*value && (*value == ' ' || *value == '\t'))
191 - if (*value++ != '(')
192 + if (*value != '(' && *value != '=') /* Allowed to use 'foo=bar' instead of 'foo(bar)' by AMB */
195 while (*value && (*value == ' ' || *value == '\t'))
198 @@ -1897,10 +2003,14 @@
199 && *past_value != '\t' && *past_value != ')')
201 termination = past_value;
202 + /* Allowed to use 'foo=bar' instead of 'foo(bar)' by AMB
203 while (*termination && (*termination == ' ' || *termination == '\t'))
205 if (*termination++ != ')')
208 + if (*termination == ')') /* Allowed to use 'foo=bar' instead of 'foo(bar)' by AMB */
210 if (*termination && *termination != ' ' && *termination != '\t')
212 /* Temporarily null-terminate the value. */
213 @@ -3841,10 +3951,17 @@
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') {
220 +/* Start of code from future cccp.c added by AMB */
221 + if (!put_out_comments) {
223 + for (p = bp; *p == ' ' || *p == '\t'; p++)
230 +/* End of code from future cccp.c added by AMB */
231 /* Don't remove the comments if -traditional. */
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 */
245 /* Output directive name. */
246 @@ -4002,6 +4122,10 @@
248 if (!no_output && already_output == 0
250 +/* Start new option added by AMB */
251 + || (kt->type == T_INCLUDE
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 */
265 +/* End new option added by AMB */
267 /* Output arguments. */
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 @@
280 install ((U_CHAR *) "__IMMEDIATE_PREFIX__", -1, T_IMMEDIATE_PREFIX_TYPE,
283 install ((U_CHAR *) "__TIME__", -1, T_TIME, NULL_PTR, -1);
285 install ((U_CHAR *) "__STDC__", -1, T_CONST, "1", -1);
286 @@ -9639,6 +9769,7 @@
287 pass_thru_directive (udirective, &udirective[strlen (directive)],
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)],
300 sprintf (directive, " __DATE__ \"%s %2d %4d\"\n",
301 monthnames[timebuf->tm_mon],
302 @@ -9826,7 +9958,7 @@
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. */
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);
321 +/* Start change added by AMB (handles gcc 3.x "-Afoo=bar") */
327 +/* End change added by AMB (handles gcc 3.x "-Afoo=bar") */
329 ip = &instack[++indepth];
330 ip->nominal_fname = ip->fname = "*Initialization*";