aboutsummaryrefslogtreecommitdiff
path: root/gconf/gconf-preproc.c
diff options
context:
space:
mode:
Diffstat (limited to 'gconf/gconf-preproc.c')
-rw-r--r--gconf/gconf-preproc.c728
1 files changed, 0 insertions, 728 deletions
diff --git a/gconf/gconf-preproc.c b/gconf/gconf-preproc.c
deleted file mode 100644
index 5bd0a95..0000000
--- a/gconf/gconf-preproc.c
+++ /dev/null
@@ -1,728 +0,0 @@
1/* gconf - General purpose configuration parser.
2 Copyright (C) 2007, 2008, 2009 Sergey Poznyakoff
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3 of the License, or (at your
7 option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20#include <gconf.h>
21#include <sys/types.h>
22#include <sys/stat.h>
23#include <sys/wait.h>
24#include <ctype.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <stdarg.h>
28#include <string.h>
29#include <errno.h>
30
31#include <xalloc.h>
32#include <hash.h>
33#include <gl_linked_list.h>
34#include <inttostr.h>
35#include <wordsplit.h>
36
37#if ENABLE_NLS
38# include "gettext.h"
39# define _(msgid) gettext (msgid)
40#else
41# define _(msgid) msgid
42#endif
43
44bool gconf_log_to_stderr = true;
45void (*gconf_log_setup_hook) () = NULL;
46
47struct input_file_ident
48{
49 ino_t i_node;
50 dev_t device;
51};
52
53struct buffer_ctx
54{
55 struct buffer_ctx *prev; /* Pointer to previous context */
56 gconf_locus_t locus; /* Current input location */
57 size_t namelen; /* Length of the file name */
58 size_t xlines; /* Number of #line directives output so far */
59 struct input_file_ident id;
60 FILE *infile;
61};
62
63extern int yy_flex_debug;
64static struct buffer_ctx *context_stack;
65
66#define INFILE context_stack->infile
67#define LOCUS context_stack->locus
68
69static char *linebuf;
70static size_t bufsize;
71static char *putback_buffer;
72static size_t putback_size;
73static size_t putback_max;
74
75static int push_source (const char *name, int once);
76static int pop_source (void);
77static int parse_include (const char *text, int once);
78
79static void
80putback (const char *str)
81{
82 size_t len;
83
84 if (!*str)
85 return;
86 len = strlen (str) + 1;
87 if (len > putback_max)
88 {
89 putback_max = len;
90 putback_buffer = xrealloc (putback_buffer, putback_max);
91 }
92 strcpy (putback_buffer, str);
93 putback_size = len - 1;
94}
95
96/* Compute the size of the line
97
98 #line NNN "FILENAME"
99*/
100static size_t
101pp_line_stmt_size ()
102{
103 char lbuf[INT_BUFSIZE_BOUND(uintmax_t)];
104 char xbuf[INT_BUFSIZE_BOUND(uintmax_t)];
105 char *lp, *xp;
106
107 lp = umaxtostr (LOCUS.line, lbuf);
108 xp = umaxtostr (context_stack->xlines + 1, xbuf);
109 if (context_stack->namelen == 0)
110 context_stack->namelen = strlen (LOCUS.file);
111 /* "#line " is 6 chars, two more spaces, two quotes and a linefeed
112 make another 5, summa facit 11 */
113 return 11 + strlen (lp) + strlen (xp) + context_stack->namelen;
114}
115
116static void
117pp_line_stmt ()
118{
119 char *p;
120 size_t ls_size = pp_line_stmt_size ();
121 size_t pb_size = putback_size + ls_size + 1;
122
123 if (pb_size > putback_max)
124 {
125 putback_max = pb_size;
126 putback_buffer = xrealloc (putback_buffer, putback_max);
127 }
128
129 p = putback_buffer + putback_size;
130 context_stack->xlines++;
131 snprintf (p, putback_max - putback_size,
132 "#line %lu \"%s\" %lu\n",
133 (unsigned long) LOCUS.line,
134 LOCUS.file, (unsigned long) context_stack->xlines);
135 putback_size += ls_size;
136}
137
138#define STRMATCH(p, len, s) (len >= sizeof(s) \
139 && memcmp (p, s, sizeof(s) - 1) == 0 \
140 && isspace(p[sizeof(s) - 1]))
141
142static int
143next_line ()
144{
145 ssize_t rc;
146
147 do
148 {
149 if (putback_size)
150 {
151 if (putback_size + 1 > bufsize)
152 {
153 bufsize = putback_size + 1;
154 linebuf = xrealloc (linebuf, bufsize);
155 }
156 strcpy (linebuf, putback_buffer);
157 rc = putback_size;
158 putback_size = 0;
159 }
160 else if (!context_stack)
161 return 0;
162 else
163 rc = getline (&linebuf, &bufsize, INFILE);
164 }
165 while (rc == -1 && pop_source () == 0);
166 return rc;
167}
168
169size_t
170gconf_preproc_fill_buffer (char *buf, size_t size)
171{
172 size_t bufsize = size;
173
174 while (next_line () > 0)
175 {
176 char *p;
177 size_t len;
178 int is_line = 0;
179
180 for (p = linebuf; *p && isspace (*p); p++)
181 ;
182 if (*p == '#')
183 {
184 size_t l;
185 for (p++; *p && isspace (*p); p++)
186 ;
187 l = strlen (p);
188 if (STRMATCH (p, l, "include_once"))
189 {
190 if (parse_include (linebuf, 1))
191 putback ("/*include_once*/\n");
192 continue;
193 }
194 else if (STRMATCH (p, l, "include"))
195 {
196 if (parse_include (linebuf, 0))
197 putback ("/*include*/\n");
198 continue;
199 }
200 else if (STRMATCH (p, l, "line"))
201 is_line = 1;
202 }
203
204 len = strlen (linebuf);
205
206 if (len > size)
207 len = size;
208
209 memcpy (buf, linebuf, len);
210 buf += len;
211 size -= len;
212
213 if (size == 0)
214 {
215 putback (linebuf + len);
216 break;
217 }
218
219 if (!is_line && len > 0 && linebuf[len - 1] == '\n')
220 LOCUS.line++;
221 }
222 return bufsize - size;
223}
224
225#define STAT_ID_EQ(st,id) ((id).i_node == (st).st_ino \
226 && (id).device == (st).st_dev)
227
228static struct buffer_ctx *
229ctx_lookup (struct stat *st)
230{
231 struct buffer_ctx *ctx;
232
233 if (!context_stack)
234 return NULL;
235
236 for (ctx = context_stack->prev; ctx; ctx = ctx->prev)
237 if (STAT_ID_EQ (*st, ctx->id))
238 break;
239 return ctx;
240}
241
242const char *gconf_preprocessor = NULL;
243static gl_list_t include_path;
244static gl_list_t std_include_path;
245