File: cccp.c.diff

package info (click to toggle)
cxref 1.6-8
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,068 kB
  • ctags: 1,502
  • sloc: ansic: 18,186; yacc: 2,094; sh: 918; lex: 460; perl: 452; makefile: 414; lisp: 256; cpp: 188; python: 80
file content (203 lines) | stat: -rw-r--r-- 6,486 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
--- original/2.95.3/cccp.c	2004-06-18 17:35:13.000000000 +0100
+++ cccp.c	2004-06-19 19:38:43.000000000 +0100
@@ -4,6 +4,10 @@
    Written by Paul Rubin, June 1986
    Adapted to ANSI C, Richard Stallman, Jan 1987
 
+Modfied for use as cxref-cpp by Andrew M. Bishop 2004.
+Changes marked with 'AMB' in the code.
+
+
 This program is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
 Free Software Foundation; either version 2, or (at your option) any
@@ -373,6 +377,9 @@
     char fname[1];
   };
 
+#define GCC_INCLUDE_DIR "." /* Not used - AMB */
+#define INCLUDE_DEFAULTS { { 0, 0, 0, 0, 0 } } /* No built-in include dirs - AMB */
+
 /* #include "file" looks in source file dir, then stack.  */
 /* #include <file> just looks in the stack.  */
 /* -I directories are added to the end, then the defaults are added.  */
@@ -457,6 +464,9 @@
    include file directories.  */
 static char *include_prefix;
 
+/* File to include that contains the gcc definitions for cxref-cpp - AMB */
+static char *cxref_cpp_defines=CXREF_CPP_DEFINES;
+
 /* Maintain and search list of included files.  */
 
 struct include_file {
@@ -1707,6 +1717,17 @@
 	}
 	break;
 
+/* Option for runtime cxref-cpp configuration file - AMB */
+      case 'c':
+	if (!strcmp (argv[i], "-cxref-cpp-defines")) {
+	  if (i + 1 == argc)
+	    fatal ("Filename missing after `-cxref-cpp-defines' option");
+	  else
+	    cxref_cpp_defines = argv[i+1], i++;
+	}
+	break;
+/* Option for runtime cxref-cpp configuration file - AMB */
+
       case 'n':
 	if (!strcmp (argv[i], "-nostdinc"))
 	  /* -nostdinc causes no default include directories.
@@ -1774,6 +1795,80 @@
      and option processing.  */
   initialize_builtins (fp, &outbuf);
 
+  /* Start of setup for the cxref paths and definitions from runtime config - AMB */
+
+  {
+   int fd;
+   struct stat sbuf;
+   char *buf,*p;
+   struct include_file *inc;
+
+   if(stat(cxref_cpp_defines,&sbuf)<0)
+     {perror_with_name(cxref_cpp_defines); exit(FATAL_EXIT_CODE);}
+
+   if(!S_ISREG(sbuf.st_mode))
+     {perror_with_name(cxref_cpp_defines); exit(FATAL_EXIT_CODE);}
+
+   fd=open_include_file(cxref_cpp_defines, NULL_PTR, NULL_PTR, &inc);
+   if(fd==-1)
+     {perror_with_name(cxref_cpp_defines); exit(FATAL_EXIT_CODE);}
+
+   buf=(U_CHAR *)xmalloc(sbuf.st_size+2);
+
+   if(safe_read(fd,buf,sbuf.st_size)<0)
+     {perror_with_name(cxref_cpp_defines); exit(FATAL_EXIT_CODE);}
+
+   p=buf;
+
+   while(!strncmp(p,"//",2))
+     {
+      char *oldp=p;
+
+      while(*p && (*p!='\r' && *p!='\n')) p++;
+      while(*p && (*p=='\r' || *p=='\n')) *p++=0;
+
+      if(!strncmp(oldp,"// -",4) && *(oldp+=4))
+         switch(*oldp)
+           {
+           case 'A':
+            make_assertion("-A",oldp+1);
+            break;
+
+           case 'D':
+            make_definition(oldp+1);
+            break;
+
+           case 'I': /* treat like -isystem */
+            {
+             struct file_name_list *dirtmp;
+
+             dirtmp = new_include_prefix(NULL_PTR,NULL_PTR,"",oldp+1);
+             dirtmp->c_system_include_path = 1;
+
+             if (before_system == 0)
+                before_system = dirtmp;
+             else
+                last_before_system->next = dirtmp;
+             last_before_system = dirtmp; /* Tail follows the last one */
+            }
+            break;
+
+           default:
+            ;
+           }
+     }
+
+   free(buf);
+
+   lseek(fd,0,SEEK_SET);
+
+   no_output++; no_record_file++;
+   finclude(fd,inc,&outbuf,0,NULL_PTR);
+   no_output--; no_record_file--;
+  }
+
+  /* End of setup for the cxref paths and definitions from runtime config - AMB */
+
   /* Now handle the command line options.  */
 
   /* Do -U's, -D's and -A's in the order they were seen.  */
@@ -10102,6 +10197,7 @@
   install ((U_CHAR *) "__FILE__", -1, T_FILE, NULL_PTR, -1);
   install ((U_CHAR *) "__BASE_FILE__", -1, T_BASE_FILE, NULL_PTR, -1);
   install ((U_CHAR *) "__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, NULL_PTR, -1);
+  /* Don't setup the standard #defines - AMB
   install ((U_CHAR *) "__VERSION__", -1, T_VERSION, NULL_PTR, -1);
 #ifndef NO_BUILTIN_SIZE_TYPE
   install ((U_CHAR *) "__SIZE_TYPE__", -1, T_SIZE_TYPE, NULL_PTR, -1);
@@ -10116,6 +10212,7 @@
 	   NULL_PTR, -1);
   install ((U_CHAR *) "__IMMEDIATE_PREFIX__", -1, T_IMMEDIATE_PREFIX_TYPE,
 	   NULL_PTR, -1);
+  */
   install ((U_CHAR *) "__TIME__", -1, T_TIME, NULL_PTR, -1);
   if (!traditional) {
     install ((U_CHAR *) "__STDC__", -1, T_CONST, "1", -1);
@@ -10124,7 +10221,9 @@
 /*  This is supplied using a -D by the compiler driver
     so that it is present only when truly compiling with GNU C.  */
 /*  install ((U_CHAR *) "__GNUC__", -1, T_CONST, "2", -1);  */
+  /* Don't setup the standard #defines - AMB
   install ((U_CHAR *) "__HAVE_BUILTIN_SETJMP__", -1, T_CONST, "1", -1);
+  */
 
   if (debug_output)
     {
@@ -10139,6 +10238,7 @@
       pass_thru_directive (udirective, &udirective[strlen (directive)],
 			   outp, dp);
 
+      /* Don't setup the standard #defines - AMB
       sprintf (directive, " __VERSION__ \"%s\"\n", version_string);
       output_line_directive (inp, outp, 0, same_file);
       pass_thru_directive (udirective, &udirective[strlen (directive)],
@@ -10162,6 +10262,7 @@
       output_line_directive (inp, outp, 0, same_file);
       pass_thru_directive (udirective, &udirective[strlen (directive)],
 			   outp, dp);
+      */
 
       sprintf (directive, " __DATE__ \"%s %2d %4d\"\n",
 	       monthnames[timebuf->tm_mon],
@@ -10324,7 +10425,7 @@
   U_CHAR *buf, *p, *q;
 
   /* Copy the entire option so we can modify it.  */
-  buf = (U_CHAR *) alloca (strlen (str) + 1);
+  buf = (U_CHAR *) alloca (strlen (str) + 2); /* Change to handle gcc 3.x "-Afoo=bar" - AMB */
   strcpy ((char *) buf, str);
   /* Scan for any backslash-newline and remove it.  */
   p = q = buf;
@@ -10344,10 +10445,18 @@
   while (is_idchar[*++p])
     ;
   SKIP_WHITE_SPACE (p);
-  if (! (*p == 0 || *p == '(')) {
+  if (! (*p == 0 || *p == '(' || *p == '=')) { /* Change to handle gcc 3.x "-Afoo=bar" - AMB */
     error ("malformed option `%s %s'", option, str);
     return;
   }
+
+/* Start change to handle gcc 3.x "-Afoo=bar" - AMB */
+  if(*p=='=')
+    {
+     *p='(';
+     strcat(p,")");
+    }
+/* End change to handle gcc 3.x "-Afoo=bar" - AMB */
   
   ip = &instack[++indepth];
   ip->nominal_fname = ip->fname = "*Initialization*";