aboutsummaryrefslogtreecommitdiff
path: root/src/preproc.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-01 21:13:32 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-03 21:23:16 +0300
commit24ec67c9f6375d34d88e79981ed8abbe15a78169 (patch)
tree6e68b1b409b10b48581422df05cfac9caedb0af2 /src/preproc.c
parentda56e338d346e358de864d18ca42f574305d8dfc (diff)
downloadgrecs-24ec67c9f6375d34d88e79981ed8abbe15a78169.tar.gz
grecs-24ec67c9f6375d34d88e79981ed8abbe15a78169.tar.bz2
Reindent all, except wordsplit, which is shared with MU.
Diffstat (limited to 'src/preproc.c')
-rw-r--r--src/preproc.c222
1 files changed, 90 insertions, 132 deletions
diff --git a/src/preproc.c b/src/preproc.c
index 7ea9442..06924c1 100644
--- a/src/preproc.c
+++ b/src/preproc.c
@@ -34,14 +34,12 @@
34int grecs_log_to_stderr = 1; 34int grecs_log_to_stderr = 1;
35void (*grecs_log_setup_hook) () = NULL; 35void (*grecs_log_setup_hook) () = NULL;
36 36
37struct input_file_ident 37struct input_file_ident {
38{
39 ino_t i_node; 38 ino_t i_node;
40 dev_t device; 39 dev_t device;
41}; 40};
42 41
43struct buffer_ctx 42struct buffer_ctx {
44{
45 struct buffer_ctx *prev; /* Pointer to previous context */ 43 struct buffer_ctx *prev; /* Pointer to previous context */
46 grecs_locus_t locus; /* Current input location */ 44 grecs_locus_t locus; /* Current input location */
47 size_t namelen; /* Length of the file name */ 45 size_t namelen; /* Length of the file name */
@@ -75,19 +73,12 @@ pp_getline (char **pbuf, size_t *psize, FILE *fp)
75 size_t size = *psize; 73 size_t size = *psize;
76 ssize_t off = 0; 74 ssize_t off = 0;
77 75
78 do 76 do {
79 { 77 if (off == size - 1) {
80 size_t len; 78 if (!buf) {
81
82 if (off == size - 1)
83 {
84 if (!buf)
85 {
86 size = 1; 79 size = 1;
87 buf = grecs_malloc(size); 80 buf = grecs_malloc(size);
88 } 81 } else {
89 else
90 {
91 size_t nsize = 2 * size; 82 size_t nsize = 2 * size;
92 if (nsize < size) 83 if (nsize < size)
93 grecs_alloc_die(); 84 grecs_alloc_die();
@@ -95,8 +86,7 @@ pp_getline (char **pbuf, size_t *psize, FILE *fp)
95 size = nsize; 86 size = nsize;
96 } 87 }
97 } 88 }
98 if (!fgets (buf + off, size - off, fp)) 89 if (!fgets(buf + off, size - off, fp)) {
99 {
100 if (off == 0) 90 if (off == 0)
101 off = -1; 91 off = -1;
102 break; 92 break;
@@ -110,7 +100,6 @@ pp_getline (char **pbuf, size_t *psize, FILE *fp)
110 return off; 100 return off;
111} 101}
112 102
113
114static void 103static void
115putback(const char *str) 104putback(const char *str)
116{ 105{
@@ -119,8 +108,7 @@ putback (const char *str)
119 if (!*str) 108 if (!*str)
120 return; 109 return;
121 len = strlen(str) + 1; 110 len = strlen(str) + 1;
122 if (len > putback_max) 111 if (len > putback_max) {
123 {
124 putback_max = len; 112 putback_max = len;
125 putback_buffer = grecs_realloc(putback_buffer, putback_max); 113 putback_buffer = grecs_realloc(putback_buffer, putback_max);
126 } 114 }
@@ -134,7 +122,8 @@ pp_line_stmt ()
134 size_t ls_size; 122 size_t ls_size;
135 size_t pb_size; 123 size_t pb_size;
136 124
137 if (grecs_asprintf (&linebufbase, &linebufsize, "#line %lu \"%s\" %lu\n", 125 if (grecs_asprintf(&linebufbase, &linebufsize,
126 "#line %lu \"%s\" %lu\n",
138 (unsigned long) LOCUS.line, 127 (unsigned long) LOCUS.line,
139 LOCUS.file, (unsigned long) context_stack->xlines)) 128 LOCUS.file, (unsigned long) context_stack->xlines))
140 grecs_alloc_die(); 129 grecs_alloc_die();
@@ -142,8 +131,7 @@ pp_line_stmt ()
142 ls_size = strlen(linebufbase); 131 ls_size = strlen(linebufbase);
143 pb_size = putback_size + ls_size + 1; 132 pb_size = putback_size + ls_size + 1;
144 133
145 if (pb_size > putback_max) 134 if (pb_size > putback_max) {
146 {
147 putback_max = pb_size; 135 putback_max = pb_size;
148 putback_buffer = grecs_realloc(putback_buffer, putback_max); 136 putback_buffer = grecs_realloc(putback_buffer, putback_max);
149 } 137 }
@@ -162,12 +150,9 @@ next_line ()
162{ 150{
163 ssize_t rc; 151 ssize_t rc;
164 152
165 do 153 do {
166 { 154 if (putback_size) {
167 if (putback_size) 155 if (putback_size + 1 > bufsize) {
168 {
169 if (putback_size + 1 > bufsize)
170 {
171 bufsize = putback_size + 1; 156 bufsize = putback_size + 1;
172 linebuf = grecs_realloc(linebuf, bufsize); 157 linebuf = grecs_realloc(linebuf, bufsize);
173 } 158 }
@@ -179,8 +164,7 @@ next_line ()
179 return 0; 164 return 0;
180 else 165 else
181 rc = pp_getline(&linebuf, &bufsize, INFILE); 166 rc = pp_getline(&linebuf, &bufsize, INFILE);
182 } 167 } while (rc == -1 && pop_source() == 0);
183 while (rc == -1 && pop_source () == 0);
184 return rc; 168 return rc;
185} 169}
186 170
@@ -189,33 +173,27 @@ grecs_preproc_fill_buffer (char *buf, size_t size)
189{ 173{
190 size_t bufsize = size; 174 size_t bufsize = size;
191 175
192 while (next_line () > 0) 176 while (next_line() > 0) {
193 {
194 char *p; 177 char *p;
195 size_t len; 178 size_t len;
196 int is_line = 0; 179 int is_line = 0;
197 180
198 for (p = linebuf; *p && isspace(*p); p++) 181 for (p = linebuf; *p && isspace(*p); p++)
199 ; 182 ;
200 if (*p == '#') 183 if (*p == '#') {
201 {
202 size_t l; 184 size_t l;
203 for (p++; *p && isspace(*p); p++) 185 for (p++; *p && isspace(*p); p++)
204 ; 186 ;
205 l = strlen(p); 187 l = strlen(p);
206 if (STRMATCH (p, l, "include_once")) 188 if (STRMATCH(p, l, "include_once")) {
207 {
208 if (parse_include(linebuf, 1)) 189 if (parse_include(linebuf, 1))
209 putback("/*include_once*/\n"); 190 putback("/*include_once*/\n");
210 continue; 191 continue;
211 } 192 } else if (STRMATCH(p, l, "include")) {
212 else if (STRMATCH (p, l, "include"))
213 {
214 if (parse_include(linebuf, 0)) 193 if (parse_include(linebuf, 0))
215 putback("/*include*/\n"); 194 putback("/*include*/\n");
216 continue; 195 continue;
217 } 196 } else if (STRMATCH(p, l, "line"))
218 else if (STRMATCH (p, l, "line"))
219 is_line = 1; 197 is_line = 1;
220 } 198 }
221 199
@@ -228,8 +206,7 @@ grecs_preproc_fill_buffer (char *buf, size_t size)
228 buf += len; 206 buf += len;
229 size -= len; 207 size -= len;
230 208
231 if (size == 0) 209 if (size == 0) {
232 {
233 putback(linebuf + len); 210 putback(linebuf + len);
234 break; 211 break;
235 } 212 }
@@ -261,8 +238,7 @@ const char *grecs_preprocessor = NULL;
261static struct grecs_list *include_path; 238static struct grecs_list *include_path;
262static struct grecs_list *std_include_path; 239static struct grecs_list *std_include_path;
263 240
264struct file_data 241struct file_data {
265{
266 const char *name; 242 const char *name;
267 size_t namelen; 243 size_t namelen;
268 char *buf; 244 char *buf;
@@ -275,12 +251,10 @@ pp_list_find (struct grecs_list *list, struct file_data *dptr)
275{ 251{
276 struct grecs_list_entry *ep; 252 struct grecs_list_entry *ep;
277 253
278 for (ep = list->head; !dptr->found && ep; ep = ep->next) 254 for (ep = list->head; !dptr->found && ep; ep = ep->next) {
279 {
280 const char *dir = ep->data; 255 const char *dir = ep->data;
281 size_t size = strlen (dir) + 1 + dptr->namelen + 1; 256 size_t size = strlen (dir) + 1 + dptr->namelen + 1;
282 if (size > dptr->buflen) 257 if (size > dptr->buflen) {
283 {
284 dptr->buflen = size; 258 dptr->buflen = size;
285 dptr->buf = grecs_realloc(dptr->buf, dptr->buflen); 259 dptr->buf = grecs_realloc(dptr->buf, dptr->buflen);
286 } 260 }
@@ -292,18 +266,27 @@ pp_list_find (struct grecs_list *list, struct file_data *dptr)
292 return dptr->found; 266 return dptr->found;
293} 267}
294 268
269static void
270incl_free(void *data)
271{
272 free(data);
273}
274
295void 275void
296grecs_include_path_setup_v(char **dirs) 276grecs_include_path_setup_v(char **dirs)