File: cccp.c.diff

package info (click to toggle)
cxref 1.6a-1.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,124 kB
  • ctags: 1,502
  • sloc: ansic: 18,209; yacc: 2,086; sh: 917; lex: 460; perl: 452; makefile: 418; lisp: 256; cpp: 188; python: 80
file content (278 lines) | stat: -rw-r--r-- 8,559 bytes parent folder | download | duplicates (2)
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
diff -u /home/amb/cxref/cpp/original/gcc-2.95.3/cccp.c /home/amb/cxref/cpp/cccp.c
--- /home/amb/cxref/cpp/original/gcc-2.95.3/cccp.c	2001-01-25 14:03:00.000000000 +0000
+++ /home/amb/cxref/cpp/cccp.c	2005-02-05 17:25:51.000000000 +0000
@@ -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 {
@@ -1024,7 +1034,8 @@
    retrying if necessary.  If MAX_READ_LEN is defined, read at most
    that bytes at a time.  Return a negative value if an error occurs,
    otherwise return the actual number of bytes read,
-   which must be LEN unless end-of-file was reached.  */
+   which may be < LEN if CRs have been skipped, though we try not to do
+   that.  */
 
 static int
 safe_read (desc, ptr, len)
@@ -1033,6 +1044,7 @@
      int len;
 {
   int left, rcount, nchars;
+  char *rptr;
 
   left = len;
   while (left > 0) {
@@ -1052,8 +1064,20 @@
       }
     if (nchars == 0)
       break;
-    ptr += nchars;
+
+    /* CRLF pairs, found with Unix when processing DOS files,
+       throw off backslash-newline removal.
+       Therefore, CRs are thrown away here. */
     left -= nchars;
+    rptr = ptr;
+    while(nchars--)
+      {
+	if(*rptr == '\r' && *(rptr+1) == '\n')
+	  left++;
+	else
+	  *ptr++ = *rptr;
+	rptr++;
+      }
   }
   return len - left;
 }
@@ -1707,6 +1731,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 +1809,83 @@
      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);
+             if(!dirtmp)
+                fatal ("File %s specifies invalid -I path",cxref_cpp_defines);
+
+             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.  */
@@ -2086,8 +2198,8 @@
     for (;;) {
       cnt = safe_read (f, (char *) fp->buf + size, bsize - size);
       if (cnt < 0) goto perror;	/* error! */
+      if (cnt == 0) break; /* End of file */
       size += cnt;
-      if (size != bsize) break;	/* End of file */
       bsize *= 2;
       fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
     }
@@ -5027,6 +5139,8 @@
 	  map_list_ptr->map_list_map = ptr;
 
 	  while ((ch = getc (f)) != '\n')
+	    if (ch == '\r')
+		continue;
 	    if (ch == EOF)
 	      break;
 	}
@@ -5259,9 +5373,9 @@
       i = safe_read (f, (char *) fp->buf + st_size, bsize - st_size);
       if (i < 0)
 	goto nope;      /* error! */
-      st_size += i;
-      if (st_size != bsize)
+      if (i == 0)
 	break;	/* End of file */
+      st_size += i;
       bsize *= 2;
       fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
     }
@@ -10102,6 +10216,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 +10231,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 +10240,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 +10257,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 +10281,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 +10444,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 +10464,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*";