annotate src/vms-pp.c @ 7:c153ca296910

Added tag r19-15b4 for changeset 27bc7f280385
author cvs
date Mon, 13 Aug 2007 08:47:16 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* vms_pp - preprocess emacs files in such a way that they can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 * compiled on VMS without warnings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 * Copyright (C) 1986 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: Not synched with FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 * Usage:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 * vms_pp infile outfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 * implicit inputs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 * The file "vms_pp.trans" has the names and their translations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 * description:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 * Vms_pp takes the input file and scans it, replacing the long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 * names with shorter names according to the table read in from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 * vms_pp.trans. The line is then written to the output file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 * Additionally, the "#undef foo" construct is replaced with:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 * #ifdef foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 * #undef foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 * #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 * The construct #if defined(foo) is replaced with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 * #ifdef foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 * #define foo_VAL 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 * #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 * #define foo_VAL 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 * #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 * #define defined(XX) XX_val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 * #if defined(foo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 * This last contruction only works on single line #if's and takes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 * advantage of a questionable C pre-processor trick. If there are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 * comments within the #if, that contain "defined", then this will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 * bomb.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #define Max_table 100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #define Table_name "vms_pp.trans"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #define Word_member \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 static FILE *in,*out; /* read from, write to */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 struct item { /* symbol table entries */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 char *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 char *value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 static struct item name_table[Max_table]; /* symbol table */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 static int defined_defined = 0; /* small optimization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 main(argc,argv) int argc; char **argv; {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 char buffer[1024];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 if(argc != 3) { /* check argument count */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 fprintf(stderr,"usage: vms_pp infile outfile");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 exit();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 init_table(); /* read in translation table */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 /* open input and output files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 if((in = fopen(argv[1],"r")) == NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 fprintf(stderr,"vms_pp: unable to open file '%s'",argv[1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 exit();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 if((out = fopen(argv[2],"w")) == NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 fprintf(stderr,"vms_pp: unable to create file '%s'",argv[2]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 exit();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 while(fgets(buffer,1023,in) != NULL) { /* loop through buffer until end */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 process_line(buffer); /* process the line */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 fputs(buffer,out); /* write out the line */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 /* buy - allocate and copy a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 static char *buy(str) char *str; {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 char *temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 if(!(temp = malloc(strlen(str)+1))) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 fprintf(stderr,"vms_pp: can't allocate memory");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 exit();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 strcpy(temp,str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 return temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 /* gather_word - return a buffer full of the next word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 static char *gather_word(ptr,word) char *ptr, *word;{
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 for(; strchr(Word_member,*ptr); ptr++,word++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 *word = *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 *word = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 return ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 /* skip_white - skip white space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 static char *skip_white(ptr) char *ptr; {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 while(*ptr == ' ' || *ptr == '\t')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ptr++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 return ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 /* init_table - initialize translation table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 init_table() {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 char buf[256],*ptr,word[128];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 FILE *in;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 if((in = fopen(Table_name,"r")) == NULL) { /* open file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 fprintf(stderr,"vms_pp: can't open '%s'",Table_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 exit();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 for(i = 0; fgets(buf,255,in) != NULL;) { /* loop through lines */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ptr = skip_white(buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 if(*ptr == '!') /* skip comments */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ptr = gather_word(ptr,word); /* get long word */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 if(*word == 0) { /* bad entry */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 fprintf(stderr,"vms_pp: bad input line '%s'\n",buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 name_table[i].name = buy(word); /* set up the name */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ptr = skip_white(ptr); /* skip white space */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ptr = gather_word(ptr,word); /* get equivalent name */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 if(*word == 0) { /* bad entry */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 fprintf(stderr,"vms_pp: bad input line '%s'\n",buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 name_table[i].value = buy(word); /* and the equivalent name */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 i++; /* increment to next position */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 for(; i < Max_table; i++) /* mark rest as unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 name_table[i].name = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 /* process_line - do actual line processing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 process_line(buf) char *buf; {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 char *in_ptr,*out_ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 char word[128],*ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 int len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 check_pp(buf); /* check for preprocessor lines */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 for(in_ptr = out_ptr = buf; *in_ptr;) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 if(!strchr(Word_member,*in_ptr)) /* non alpha-numeric? just copy */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 *out_ptr++ = *in_ptr++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 in_ptr = gather_word(in_ptr,word); /* get the 'word' */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 if(strlen(word) > 31) /* length is too long */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 replace_word(word); /* replace the word */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 for(ptr = word; *ptr; ptr++,out_ptr++) /* copy out the word */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 *out_ptr = *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 *out_ptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 /* check_pp - check for preprocessor lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 check_pp(buf) char *buf; {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 char *ptr,*p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 char word[128];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ptr = skip_white(buf); /* skip white space */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 if(*ptr != '#') /* is this a preprocessor line? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 return; /* no, just return */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ptr = skip_white(++ptr); /* skip white */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ptr = gather_word(ptr,word); /* get command word */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 if(!strcmp("undef",word)) { /* undef? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ptr = skip_white(ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ptr = gather_word(ptr,word); /* get the symbol to undef */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 fprintf(out,"#ifdef %s\n",word);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 fputs(buf,out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 strcpy(buf,"#endif");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 if(!strcmp("if",word)) { /* check for if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 for(;;) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ptr = strchr(ptr,'d'); /* look for d in defined */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 if(!ptr) /* are we done? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 if(strchr(Word_member,*(ptr-1))){ /* at beginning of word? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ptr++; continue; /* no, continue looking */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ptr = gather_word(ptr,word); /* get the word */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 if(strcmp(word,"defined")) /* skip if not defined */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ptr = skip_white(ptr); /* skip white */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 if(*ptr != '(') /* look for open paren */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 continue; /* error, continue */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ptr++; /* skip paren */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ptr = skip_white(ptr); /* more white skipping */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ptr = gather_word(ptr,word); /* get the thing to test */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 if(!*word) /* null word is bad */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 fprintf(out,"#ifdef %s\n",word); /* generate the code */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 fprintf(out,"#define %s_VAL 1\n",word);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 fprintf(out,"#else\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 fprintf(out,"#define %s_VAL 0\n",word);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 fprintf(out,"#endif\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 if(!defined_defined) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 fprintf(out,"#define defined(XXX) XXX/**/_VAL\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 defined_defined = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 /* replace_word - look the word up in the table, and replace it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 * if a match is found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 replace_word(word) char *word; {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 for(i = 0; i < Max_table && name_table[i].name; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 if(!strcmp(word,name_table[i].name)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 strcpy(word,name_table[i].value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 fprintf(stderr,"couldn't find '%s'\n",word);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 }