summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/Makefile.am2
-rw-r--r--src/format.c269
-rw-r--r--src/grecs-gram.y1086
-rw-r--r--src/grecs-lex.l579
-rw-r--r--src/grecs.h180
-rw-r--r--src/list.c177
-rw-r--r--src/preproc.c1050
-rw-r--r--src/text.c36
8 files changed, 1631 insertions, 1748 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2f35f52..759716b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,3 +34,3 @@ INCLUDES = -I$(srcdir) @GRECS_INCLUDES@
AM_YFLAGS = -dtv
-AM_LFLAGS = -dvp
+AM_LFLAGS = -d
# Use a modified ylwrap implementation that understands the --prefix option.
diff --git a/src/format.c b/src/format.c
index a1aa67d..fc6c8d6 100644
--- a/src/format.c
+++ b/src/format.c
@@ -28,42 +28,41 @@ grecs_data_type_string (enum grecs_data_type type)
{
- switch (type)
- {
- case grecs_type_void:
- return "void";
+ switch (type) {
+ case grecs_type_void:
+ return "void";
- case grecs_type_string:
- return "string";
-
- case grecs_type_short:
- case grecs_type_ushort:
- case grecs_type_int:
- case grecs_type_uint:
- case grecs_type_long:
- case grecs_type_ulong:
- case grecs_type_size:
- /*FIXME case grecs_type_off:*/
- return "number";
-
- case grecs_type_time:
- return "time";
-
- case grecs_type_bool:
- return "boolean";
-
- case grecs_type_ipv4:
- return "IPv4";
-
- case grecs_type_cidr:
- return "CIDR";
-
- case grecs_type_host:
- return "hostname";
-
- case grecs_type_sockaddr:
- return "sock-addr";
-
- case grecs_type_section:
- return "section";
- }
- return "UNKNOWN?";
+ case grecs_type_string:
+ return "string";
+
+ case grecs_type_short:
+ case grecs_type_ushort:
+ case grecs_type_int:
+ case grecs_type_uint:
+ case grecs_type_long:
+ case grecs_type_ulong:
+ case grecs_type_size:
+ /*FIXME case grecs_type_off:*/
+ return "number";
+
+ case grecs_type_time:
+ return "time";
+
+ case grecs_type_bool:
+ return "boolean";
+
+ case grecs_type_ipv4:
+ return "IPv4";
+
+ case grecs_type_cidr:
+ return "CIDR";
+
+ case grecs_type_host:
+ return "hostname";
+
+ case grecs_type_sockaddr:
+ return "sock-addr";
+
+ case grecs_type_section:
+ return "section";
+ }
+ return "UNKNOWN?";
}
@@ -71,6 +70,6 @@ grecs_data_type_string (enum grecs_data_type type)
static void
-format_level (FILE *stream, unsigned level)
+format_level(FILE *stream, unsigned level)
{
- while (level--)
- fprintf (stream, " ");
+ while (level--)
+ fprintf(stream, " ");
}
@@ -78,49 +77,43 @@ format_level (FILE *stream, unsigned level)
void
-grecs_format_docstring (FILE *stream, const char *docstring, unsigned level)
+grecs_format_docstring(FILE *stream, const char *docstring, unsigned level)
{
- size_t len = strlen (docstring);
- int width = 78 - level * 2;
-
- if (width < 0)
- {
- width = 78;
- level = 0;
- }
-
- while (len)
- {
- size_t seglen;
- const char *p;
-
- for (seglen = 0, p = docstring; p < docstring + width && *p; p++)
- {
- if (*p == '\n')
- {
- seglen = p - docstring;
- break;
- }
- if (isspace (*p))
- seglen = p - docstring;
+ size_t len = strlen(docstring);
+ int width = 78 - level * 2;
+
+ if (width < 0) {
+ width = 78;
+ level = 0;
}
- if (seglen == 0 || *p == 0)
- seglen = p - docstring;
-
- format_level (stream, level);
- fprintf (stream, "# ");
- fwrite (docstring, seglen, 1, stream);
- fputc ('\n', stream);
- len -= seglen;
- docstring += seglen;
- if (*docstring == '\n')
- {
- docstring++;
- len--;
+
+ while (len) {
+ size_t seglen;
+ const char *p;
+
+ for (seglen = 0, p = docstring; p < docstring + width && *p;
+ p++) {
+ if (*p == '\n') {
+ seglen = p - docstring;
+ break;
+ }
+ if (isspace(*p))
+ seglen = p - docstring;
+ }
+ if (seglen == 0 || *p == 0)
+ seglen = p - docstring;
+
+ format_level(stream, level);
+ fprintf(stream, "# ");
+ fwrite(docstring, seglen, 1, stream);
+ fputc('\n', stream);
+ len -= seglen;
+ docstring += seglen;
+ if (*docstring == '\n') {
+ docstring++;
+ len--;
+ } else
+ while (*docstring && isspace(*docstring)) {
+ docstring++;
+ len--;
+ }
}
- else
- while (*docstring && isspace (*docstring))
- {
- docstring++;
- len--;
- }
- }
}
@@ -128,30 +121,31 @@ grecs_format_docstring (FILE *stream, const char *docstring, unsigned level)
void
-grecs_format_simple_statement (FILE *stream, struct grecs_keyword *kwp,
- unsigned level)
+grecs_format_simple_statement(FILE *stream, struct grecs_keyword *kwp,
+ unsigned level)
{
- const char *argstr;
-
- if (kwp->docstring)
- grecs_format_docstring (stream, kwp->docstring, level);
- format_level (stream, level);
-
- if (kwp->argname)
- argstr = kwp->argname;
- else
- argstr = N_("arg");
-
- if (strchr ("<[", argstr[0]))
- fprintf (stream, "%s %s;\n", kwp->ident, gettext (argstr));
- else if (strchr (argstr, ':'))
- fprintf (stream, "%s <%s>;\n", kwp->ident, gettext (argstr));
- else
- {
- fprintf (stream, "%s <%s: ", kwp->ident, gettext (argstr));
- if (GRECS_IS_LIST (kwp->type))
- fprintf (stream, "list of %s",
- gettext (grecs_data_type_string (GRECS_TYPE (kwp->type))));
- else
- fprintf (stream, "%s", gettext (grecs_data_type_string (kwp->type)));
- fprintf (stream, ">;\n");
- }
+ const char *argstr;
+
+ if (kwp->docstring)
+ grecs_format_docstring(stream, kwp->docstring, level);
+ format_level(stream, level);
+
+ if (kwp->argname)
+ argstr = kwp->argname;
+ else
+ argstr = N_("arg");
+
+ if (strchr("<[", argstr[0]))
+ fprintf(stream, "%s %s;\n", kwp->ident, gettext(argstr));
+ else if (strchr (argstr, ':'))
+ fprintf (stream, "%s <%s>;\n", kwp->ident, gettext(argstr));
+ else {
+ fprintf(stream, "%s <%s: ", kwp->ident, gettext(argstr));
+ if (GRECS_IS_LIST(kwp->type))
+ fprintf(stream, "list of %s",
+ gettext(grecs_data_type_string(
+ GRECS_TYPE (kwp->type))));
+ else
+ fprintf(stream, "%s",
+ gettext(grecs_data_type_string(kwp->type)));
+ fprintf(stream, ">;\n");
+ }
}
@@ -159,15 +153,15 @@ grecs_format_simple_statement (FILE *stream, struct grecs_keyword *kwp,
void
-grecs_format_block_statement (FILE *stream, struct grecs_keyword *kwp,
- unsigned level)
+grecs_format_block_statement(FILE *stream, struct grecs_keyword *kwp,
+ unsigned level)
{
- if (kwp->docstring)
- grecs_format_docstring (stream, kwp->docstring, level);
- format_level (stream, level);
- fprintf (stream, "%s", kwp->ident);
- if (kwp->argname)
- fprintf (stream, " <%s>", gettext (kwp->argname));
- fprintf (stream, " {\n");
- grecs_format_statement_array (stream, kwp->kwd, 0, level + 1);
- format_level (stream, level);
- fprintf (stream, "}\n");
+ if (kwp->docstring)
+ grecs_format_docstring(stream, kwp->docstring, level);
+ format_level(stream, level);
+ fprintf(stream, "%s", kwp->ident);
+ if (kwp->argname)
+ fprintf(stream, " <%s>", gettext(kwp->argname));
+ fprintf(stream, " {\n");
+ grecs_format_statement_array(stream, kwp->kwd, 0, level + 1);
+ format_level(stream, level);
+ fprintf(stream, "}\n");
}
@@ -175,15 +169,16 @@ grecs_format_block_statement (FILE *stream, struct grecs_keyword *kwp,
void
-grecs_format_statement_array (FILE *stream, struct grecs_keyword *kwp,
- unsigned n,
- unsigned level)
+grecs_format_statement_array(FILE *stream, struct grecs_keyword *kwp,
+ unsigned n,
+ unsigned level)
{
- for (; kwp->ident; kwp++, n++)
- {
- if (n)
- fputc ('\n', stream);
- if (kwp->type == grecs_type_section)
- grecs_format_block_statement (stream, kwp, level);
- else
- grecs_format_simple_statement (stream, kwp, level);
- }
+ for (; kwp->ident; kwp++, n++) {
+ if (n)
+ fputc('\n', stream);
+ if (kwp->type == grecs_type_section)
+ grecs_format_block_statement(stream, kwp, level);
+ else
+ grecs_format_simple_statement(stream, kwp, level);
+ }
}
+
+
diff --git a/src/grecs-gram.y b/src/grecs-gram.y
index 0edea13..f65e2dd 100644
--- a/src/grecs-gram.y
+++ b/src/grecs-gram.y
@@ -49,9 +49,9 @@ int grecs_default_port = 0;
-static void *target_ptr (struct grecs_keyword *kwp, char *base);
-static void stmt_begin (struct grecs_keyword *kwp, grecs_value_t tag);
-static void stmt_end (struct grecs_keyword *kwp);
-static struct grecs_keyword *find_keyword (const char *ident);
+static void *target_ptr(struct grecs_keyword *kwp, char *base);
+static void stmt_begin(struct grecs_keyword *kwp, grecs_value_t tag);
+static void stmt_end(struct grecs_keyword *kwp);
+static struct grecs_keyword *find_keyword(const char *ident);
-static void process_ident (struct grecs_keyword *kwp, grecs_value_t *value);
-static struct grecs_list *simple_list_create (int dispose);
+static void process_ident(struct grecs_keyword *kwp, grecs_value_t *value);
+static struct grecs_list *simple_list_create(int dispose);
%}
@@ -87,3 +87,3 @@ simple : ident vallist ';'
{
- process_ident($1, &$2);
+ process_ident($1, &$2);
}
@@ -93,3 +93,3 @@ block : ident tag { stmt_begin($<kw>1, $<value>2); } '{' stmtlist '}' opt_sc
{
- stmt_end($1);
+ stmt_end($1);
}
@@ -99,5 +99,6 @@ ident : IDENT
{
- $$ = find_keyword($1);
- if (!$$)
- grecs_error(&grecs_current_locus, 0, _("Unknown keyword"));
+ $$ = find_keyword($1);
+ if (!$$)
+ grecs_error(&grecs_current_locus, 0,
+ _("Unknown keyword"));
}
@@ -107,4 +108,4 @@ tag : /* empty */
{
- $$.type = GRECS_TYPE_STRING;
- $$.v.string = NULL;
+ $$.type = GRECS_TYPE_STRING;
+ $$.v.string = NULL;
}
@@ -115,20 +116,18 @@ vallist : vlist
{
- size_t n;
-
- if ((n = grecs_list_size ($1)) == 1)
- {
- $$ = *(grecs_value_t *)grecs_list_index ($1, 0);
- }
- else
- {
- size_t i;
- struct grecs_list_entry *ep;
+ size_t n;
+
+ if ((n = grecs_list_size($1)) == 1) {
+ $$ = *(grecs_value_t *)grecs_list_index($1, 0);
+ } else {
+ size_t i;
+ struct grecs_list_entry *ep;
- $$.type = GRECS_TYPE_ARRAY;
- $$.v.arg.c = n;
- $$.v.arg.v = grecs_malloc (n * sizeof ($$.v.arg.v[0]));
- for (i = 0, ep = $1->head; ep; i++, ep = ep->next)
- $$.v.arg.v[i] = *(grecs_value_t *)ep->data;
- }
- grecs_list_free ($1);
+ $$.type = GRECS_TYPE_ARRAY;
+ $$.v.arg.c = n;
+ $$.v.arg.v = grecs_malloc(n *
+ sizeof($$.v.arg.v[0]));
+ for (i = 0, ep = $1->head; ep; i++, ep = ep->next)
+ $$.v.arg.v[i] = *(grecs_value_t *)ep->data;
+ }
+ grecs_list_free($1);
}
@@ -138,4 +137,4 @@ vlist : value
{
- $$ = simple_list_create (0);
- grecs_list_append ($$, grecs_value_dup (&$1));
+ $$ = simple_list_create(0);
+ grecs_list_append($$, grecs_value_dup(&$1));
}
@@ -143,3 +142,3 @@ vlist : value
{
- grecs_list_append ($1, grecs_value_dup (&$2));
+ grecs_list_append($1, grecs_value_dup(&$2));
}
@@ -149,4 +148,4 @@ value : string
{
- $$.type = GRECS_TYPE_STRING;
- $$.v.string = $1;
+ $$.type = GRECS_TYPE_STRING;
+ $$.v.string = $1;
}
@@ -154,4 +153,4 @@ value : string
{
- $$.type = GRECS_TYPE_LIST;
- $$.v.list = $1;
+ $$.type = GRECS_TYPE_LIST;
+ $$.v.list = $1;
}
@@ -159,4 +158,4 @@ value : string
{
- $$.type = GRECS_TYPE_STRING;
- $$.v.string = $1;
+ $$.type = GRECS_TYPE_STRING;
+ $$.v.string = $1;
}
@@ -171,10 +170,10 @@ slist : slist0
{
- struct grecs_list_entry *ep;
- const void *p;
-
- grecs_line_begin ();
- for (ep = $1->head; ep; ep = ep->next)
- grecs_line_add (ep->data, strlen (ep->data));
- $$ = grecs_line_finish ();
- grecs_list_free ($1);
+ struct grecs_list_entry *ep;
+ const void *p;
+
+ grecs_line_begin();
+ for (ep = $1->head; ep; ep = ep->next)
+ grecs_line_add(ep->data, strlen(ep->data));
+ $$ = grecs_line_finish();
+ grecs_list_free($1);
}
@@ -184,4 +183,4 @@ slist0 : QSTRING
{
- $$ = simple_list_create (0);
- grecs_list_append ($$, $1);
+ $$ = simple_list_create(0);
+ grecs_list_append($$, $1);
}
@@ -189,4 +188,4 @@ slist0 : QSTRING
{
- grecs_list_append ($1, $2);
- $$ = $1;
+ grecs_list_append($1, $2);
+ $$ = $1;
}
@@ -196,3 +195,3 @@ list : '(' ')'
{
- $$ = NULL;
+ $$ = NULL;
}
@@ -200,3 +199,3 @@ list : '(' ')'
{
- $$ = $2;
+ $$ = $2;
}
@@ -204,3 +203,3 @@ list : '(' ')'
{
- $$ = $2;
+ $$ = $2;
}
@@ -210,4 +209,4 @@ values : value
{
- $$ = simple_list_create (0);
- grecs_list_append ($$, grecs_value_dup (&$1));
+ $$ = simple_list_create(0);
+ grecs_list_append($$, grecs_value_dup(&$1));
}
@@ -215,4 +214,4 @@ values : value
{
- grecs_list_append ($1, grecs_value_dup (&$3));
- $$ = $1;
+ grecs_list_append($1, grecs_value_dup(&$3));
+ $$ = $1;
}
@@ -229,4 +228,4 @@ yyerror(char *s)
{
- grecs_error (&grecs_current_locus, 0, "%s", s);
- return 0;
+ grecs_error(&grecs_current_locus, 0, "%s", s);
+ return 0;
}
@@ -234,5 +233,5 @@ yyerror(char *s)
static void
-listel_dispose (void *el)
+listel_dispose(void *el)
{
- free (el);
+ free(el);
}
@@ -240,8 +239,8 @@ listel_dispose (void *el)
static struct grecs_list *
-simple_list_create (int dispose)
+simple_list_create(int dispose)
{
- struct grecs_list *lp = grecs_list_create ();
- if (dispose)
- lp->free_entry = listel_dispose;
- return lp;
+ struct grecs_list *lp = grecs_list_create();
+ if (dispose)
+ lp->free_entry = listel_dispose;
+ return lp;
}
@@ -249,57 +248,49 @@ simple_list_create (int dispose)
int
-grecs_vasprintf (char **pbuf, size_t *psize, const char *fmt, va_list ap)
+grecs_vasprintf(char **pbuf, size_t *psize, const char *fmt, va_list ap)
{
- char *buf = *pbuf;
- size_t buflen = *psize;
- int rc = 0;
+ char *buf = *pbuf;
+ size_t buflen = *psize;
+ int rc = 0;
- if (!buf)
- {
- if (buflen == 0)
- buflen = 512; /* Initial allocation */
+ if (!buf) {
+ if (buflen == 0)
+ buflen = 512; /* Initial allocation */
- buf = calloc (1, buflen);
- if (buf == NULL)
- return ENOMEM;
- }
-
- for (;;)
- {
- ssize_t n = vsnprintf (buf, buflen, fmt, ap);
- if (n < 0 || n >= buflen || !memchr (buf, '\0', n + 1))
- {
- char *newbuf;
- size_t newlen = buflen * 2;
- if (newlen < buflen)
- {
- rc = ENOMEM;
- break;
- }
- newbuf = realloc (buf, newlen);
- if (newbuf == NULL)
- {
- rc = ENOMEM;
- break;
- }
- buflen = newlen;
- buf = newbuf;
+ buf = calloc(1, buflen);
+ if (buf == NULL)
+ return ENOMEM;
}
- else
- break;
- }
-
- if (rc)
- {
- if (!*pbuf)
- {
- /* We made first allocation, now free it */
- free (buf);
- buf = NULL;
- buflen = 0;
+
+ for (;;) {
+ ssize_t n = vsnprintf(buf, buflen, fmt, ap);
+ if (n < 0 || n >= buflen || !memchr(buf, '\0', n + 1)) {
+ char *newbuf;
+ size_t newlen = buflen * 2;
+ if (newlen < buflen) {
+ rc = ENOMEM;
+ break;
+ }
+ newbuf = realloc(buf, newlen);
+ if (newbuf == NULL) {
+ rc = ENOMEM;
+ break;
+ }
+ buflen = newlen;
+ buf = newbuf;
+ } else
+ break;
}
- }
- *pbuf = buf;
- *psize = buflen;
- return rc;
+ if (rc) {
+ if (!*pbuf) {
+ /* We made first allocation, now free it */
+ free(buf);
+ buf = NULL;
+ buflen = 0;
+ }
+ }
+
+ *pbuf = buf;
+ *psize = buflen;
+ return rc;
}
@@ -307,11 +298,11 @@ grecs_vasprintf (char **pbuf, size_t *psize, const char *fmt, va_list ap)
int
-grecs_asprintf (char **pbuf, size_t *psize, const char *fmt, ...)
+grecs_asprintf(char **pbuf, size_t *psize, const char *fmt, ...)
{
- int rc;
- va_list ap;
-
- va_start (ap, fmt);
- rc = grecs_vasprintf (pbuf, psize, fmt, ap);
- va_end (ap);
- return rc;
+ int rc;
+ va_list ap;
+
+ va_start(ap, fmt);
+ rc = grecs_vasprintf(pbuf, psize, fmt, ap);
+ va_end(ap);
+ return rc;
}
@@ -319,14 +310,14 @@ grecs_asprintf (char **pbuf, size_t *psize, const char *fmt, ...)
void
-grecs_warning (grecs_locus_t *locus, int errcode, const char *fmt, ...)
+grecs_warning(grecs_locus_t *locus, int errcode, const char *fmt, ...)
{
- va_list ap;
- char *buf = NULL;
- size_t size = 0;
-
- va_start (ap, fmt);
- if (grecs_vasprintf (&buf, &size, fmt, ap))
- grecs_alloc_die ();
- va_end (ap);
- grecs_print_diag (locus, 0, errcode, buf);
- free(buf);
+ va_list ap;
+ char *buf = NULL;
+ size_t size = 0;
+
+ va_start(ap, fmt);
+ if (grecs_vasprintf(&buf, &size, fmt, ap))
+ grecs_alloc_die();
+ va_end(ap);
+ grecs_print_diag(locus, 0, errcode, buf);
+ free(buf);
}
@@ -334,15 +325,15 @@ grecs_warning (grecs_locus_t *locus, int errcode, const char *fmt, ...)
void
-grecs_error (grecs_locus_t *locus, int errcode, const char *fmt, ...)
+grecs_error(grecs_locus_t *locus, int errcode, const char *fmt, ...)
{
- va_list ap;
- char *buf = NULL;
- size_t size = 0;
-
- va_start (ap, fmt);
- if (grecs_vasprintf (&buf, &size, fmt, ap))
- grecs_alloc_die ();
- va_end (ap);
- grecs_print_diag (locus, 1, errcode, buf);
- free (buf);
- grecs_error_count++;
+ va_list ap;
+ char *buf = NULL;
+ size_t size = 0;
+
+ va_start(ap, fmt);
+ if (grecs_vasprintf(&buf, &size, fmt, ap))
+ grecs_alloc_die();
+ va_end(ap);
+ grecs_print_diag(locus, 1, errcode, buf);
+ free(buf);
+ grecs_error_count++;
}
@@ -350,5 +341,5 @@ grecs_error (grecs_locus_t *locus, int errcode, const char *fmt, ...)
void
-grecs_set_keywords (struct grecs_keyword *kwd)
+grecs_set_keywords(struct grecs_keyword *kwd)
{
- config_keywords.kwd = kwd;
+ config_keywords.kwd = kwd;
}
@@ -356,18 +347,17 @@ grecs_set_keywords (struct grecs_keyword *kwd)
int
-grecs_parse (const char *name)
+grecs_parse(const char *name)
{
- int rc;
- if (grecs_lex_begin (name))
- return 1;
- cursect = &config_keywords;
- if (sections)
- {
- grecs_list_free (sections);
- sections = NULL;
- }
- rc = yyparse ();
- grecs_lex_end ();
- if (grecs_error_count)
- rc = 1;
- return rc;
+ int rc;
+ if (grecs_lex_begin(name))
+ return 1;
+ cursect = &config_keywords;
+ if (sections) {
+ grecs_list_free(sections);
+ sections = NULL;
+ }
+ rc = yyparse();
+ grecs_lex_end();
+ if (grecs_error_count)
+ rc = 1;
+ return rc;
}
@@ -375,5 +365,5 @@ grecs_parse (const char *name)
void
-grecs_gram_trace (int n)
+grecs_gram_trace(int n)
{
- yydebug = n;
+ yydebug = n;
}
@@ -383,10 +373,10 @@ grecs_gram_trace (int n)
static void *
-target_ptr (struct grecs_keyword *kwp, char *base)
+target_ptr(struct grecs_keyword *kwp, char *base)
{
- if (kwp->varptr)
- base = (char*) kwp->varptr + kwp->offset;
- else if (base)
- base += kwp->offset;
-
- return base;
+ if (kwp->varptr)
+ base = (char*) kwp->varptr + kwp->offset;
+ else if (base)
+ base += kwp->offset;
+
+ return base;
}
@@ -394,3 +384,3 @@ target_ptr (struct grecs_keyword *kwp, char *base)
static int
-fake_callback (enum grecs_callback_command cmd,
+fake_callback(enum grecs_callback_command cmd,
grecs_locus_t *locus,
@@ -400,3 +390,3 @@ fake_callback (enum grecs_callback_command cmd,
{
- return 0;
+ return 0;
}
@@ -404,11 +394,11 @@ fake_callback (enum grecs_callback_command cmd,
static struct grecs_keyword fake = {
- "*",
- NULL,
- NULL,
- grecs_type_void,
- NULL,
- 0,
- fake_callback,
- NULL,
- &fake
+ "*",
+ NULL,
+ NULL,
+ grecs_type_void,
+ NULL,
+ 0,
+ fake_callback,
+ NULL,
+ &fake
};
@@ -416,23 +406,22 @@ static struct grecs_keyword fake = {
static void
-stmt_begin (struct grecs_keyword *kwp, grecs_value_t tag)
+stmt_begin(struct grecs_keyword *kwp, grecs_value_t tag)
{
- void *target;
-
- if (!sections)
- sections = grecs_list_create ();
- grecs_list_push (sections, cursect);
- if (kwp)
- {
- target = target_ptr (kwp, CURRENT_BASE);
- cursect = kwp;
- if (kwp->callback && kwp->callback (grecs_callback_section_begin,
- &grecs_current_locus, /* FIXME */
- target,
- &tag,
- &kwp->callback_data))
- cursect = &fake;
- }
- else
- /* install "ignore-all" section */
- cursect = kwp;
+ void *target;
+
+ if (!sections)
+ sections = grecs_list_create();
+ grecs_list_push(sections, cursect);
+ if (kwp) {
+ target = target_ptr(kwp, CURRENT_BASE);
+ cursect = kwp;
+ if (kwp->callback &&
+ kwp->callback(grecs_callback_section_begin,
+ &grecs_current_locus, /* FIXME */
+ target,
+ &tag,
+ &kwp->callback_data))
+ cursect = &fake;
+ } else
+ /* install "ignore-all" section */
+ cursect = kwp;
}
@@ -440,23 +429,21 @@ stmt_begin (struct grecs_keyword *kwp, grecs_value_t tag)
static void
-stmt_end (struct grecs_keyword *kwp)
+stmt_end(struct grecs_keyword *kwp)
{
- grecs_callback_fn callback = NULL;
- void *dataptr = NULL;
-
- if (cursect && cursect->callback)
- {
- callback = cursect->callback;
- dataptr = &cursect->callback_data;
- }
-
- cursect = (struct grecs_keyword *) grecs_list_pop (sections);
- if (!cursect)
- abort ();
- if (callback)
- callback (grecs_callback_section_end,
- &grecs_current_locus, /* FIXME */
- kwp ? target_ptr (kwp, CURRENT_BASE) : NULL,
- NULL,
- dataptr);
+ grecs_callback_fn callback = NULL;
+ void *dataptr = NULL;
+
+ if (cursect && cursect->callback) {
+ callback = cursect->callback;
+ dataptr = &cursect->callback_data;
+ }
+ cursect = (struct grecs_keyword *) grecs_list_pop(sections);
+ if (!cursect)
+ abort();
+ if (callback)
+ callback(grecs_callback_section_end,
+ &grecs_current_locus, /* FIXME */
+ kwp ? target_ptr(kwp, CURRENT_BASE) : NULL,
+ NULL,
+ dataptr);
}
@@ -464,17 +451,14 @@ stmt_end (struct grecs_keyword *kwp)
static struct grecs_keyword *
-find_keyword (const char *ident)
+find_keyword(const char *ident)
{
- struct grecs_keyword *kwp;
+ struct grecs_keyword *kwp;
- if (cursect && cursect != &fake)
- {
- for (kwp = cursect->kwd; kwp->ident; kwp++)
- if (strcmp (kwp->ident, ident) == 0)
- return kwp;
- }
- else
- {
- return &fake;
- }
- return NULL;
+ if (cursect && cursect != &fake) {
+ for (kwp = cursect->kwd; kwp->ident; kwp++)
+ if (strcmp(kwp->ident, ident) == 0)
+ return kwp;
+ } else {
+ return &fake;
+ }
+ return NULL;
}
@@ -482,20 +466,21 @@ find_keyword (const char *ident)
static int
-string_to_bool (const char *string, int *pval, grecs_locus_t *locus)
+string_to_bool(const char *string, int *pval, grecs_locus_t *locus)
{
- if (strcmp (string, "yes") == 0
- || strcmp (string, "true") == 0
- || strcmp (string, "t") == 0
- || strcmp (string, "1") == 0)
- *pval = 1;
- else if (strcmp (string, "no") == 0
- || strcmp (string, "false") == 0
- || strcmp (string, "nil") == 0
- || strcmp (string, "0") == 0)
- *pval = 0;
- else
- {
- grecs_error (locus, 0, _("%s: not a valid boolean value"), string);
- return 1;
- }
- return 0;
+ if (strcmp(string, "yes") == 0
+ || strcmp(string, "true") == 0
+ || strcmp(string, "t") == 0
+ || strcmp(string, "1") == 0)
+ *pval = 1;
+ else if (strcmp(string, "no") == 0
+ || strcmp(string, "false") == 0
+ || strcmp(string, "nil") == 0
+ || strcmp(string, "0") == 0)
+ *pval = 0;
+ else {
+ grecs_error(locus, 0,
+ _("%s: not a valid boolean value"),
+ string);
+ return 1;
+ }
+ return 0;
}
@@ -503,14 +488,13 @@ string_to_bool (const char *string, int *pval, grecs_locus_t *locus)
static int
-string_to_host (struct in_addr *in, const char *string, grecs_locus_t *locus)
+string_to_host(struct in_addr *in, const char *string, grecs_locus_t *locus)
{
- if (inet_aton (string, in) == 0)
- {
- struct hostent *hp;
-
- hp = gethostbyname (string);
- if (hp == NULL)
- return 1;
- memcpy (in, hp->h_addr, sizeof (struct in_addr));
- }
- return 0;
+ if (inet_aton(string, in) == 0) {
+ struct hostent *hp;
+
+ hp = gethostbyname(string);
+ if (hp == NULL)
+ return 1;
+ memcpy(in, hp->h_addr, sizeof(struct in_addr));
+ }
+ return 0;
}
@@ -518,87 +502,78 @@ string_to_host (struct in_addr *in, const char *string, grecs_locus_t *locus)
static int
-string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
+string_to_sockaddr(struct grecs_sockaddr *sp, const char *string,
grecs_locus_t *locus)
{
- if (string[0] == '/')
- {
- struct sockaddr_un s_un;
- if (strlen (string) >= sizeof (s_un.sun_path))
- {
- grecs_error (locus, 0, _("%s: UNIX socket name too long"), string);
- return 1;
- }
- s_un.sun_family = AF_UNIX;
- strcpy (s_un.sun_path, string);
- sp->len = sizeof (s_un);
- sp->sa = grecs_malloc (sp->len);
- memcpy (sp->sa, &s_un, sp->len);
- }
- else
- {
- char *p = strchr (string, ':');
- size_t len;
- struct sockaddr_in sa;
-
- sa.sin_family = AF_INET;
- if (p)
- len = p - string;
- else
- len = strlen (string);
-
- if (len == 0)
- sa.sin_addr.s_addr = INADDR_ANY;
- else
- {
- char *host = grecs_malloc (len + 1);
- memcpy (host, string, len);
- host[len] = 0;
-
- if (string_to_host (&sa.sin_addr, host, locus))
- {
- grecs_error (locus, 0,
- _("%s: not a valid IP address or hostname"),
- host);
- free (host);
- return 1;
- }
- free (host);
- }
-
- if (p)
- {
- struct servent *serv;
-
- p++;
- serv = getservbyname (p, "tcp");
- if (serv != NULL)
- sa.sin_port = serv->s_port;
- else
- {
- unsigned long l;
- char *q;
-
- /* Not in services, maybe a number? */
- l = strtoul (p, &q, 0);
-
- if (*q || l > USHRT_MAX)
- {
- grecs_error (locus, 0,
- _("%s: not a valid port number"), p);
- return 1;
+ if (string[0] == '/') {
+ struct sockaddr_un s_un;
+ if (strlen(string) >= sizeof(s_un.sun_path)) {
+ grecs_error(locus, 0,
+ _("%s: UNIX socket name too long"),
+ string);
+ return 1;
}
- sa.sin_port = htons (l);
- }
- }
- else if (grecs_default_port)
- sa.sin_port = grecs_default_port;
- else
- {
- grecs_error (locus, 0, _("missing port number"));
- return 1;
+ s_un.sun_family = AF_UNIX;
+ strcpy(s_un.sun_path, string);
+ sp->len = sizeof(s_un);
+ sp->sa = grecs_malloc(sp->len);
+ memcpy(sp->sa, &s_un, sp->len);
+ } else {
+ char *p = strchr(string, ':');
+ size_t len;
+ struct sockaddr_in sa;
+
+ sa.sin_family = AF_INET;
+ if (p)
+ len = p - string;
+ else
+ len = strlen(string);
+
+ if (len == 0)
+ sa.sin_addr.s_addr = INADDR_ANY;
+ else {
+ char *host = grecs_malloc(len + 1);
+ memcpy(host, string, len);
+ host[len] = 0;
+
+ if (string_to_host(&sa.sin_addr, host, locus)) {
+ grecs_error(locus, 0,
+ _("%s: not a valid IP address or hostname"),
+ host);
+ free(host);
+ return 1;
+ }
+ free(host);
+ }
+
+ if (p) {
+ struct servent *serv;
+
+ p++;
+ serv = getservbyname(p, "tcp");
+ if (serv != NULL)
+ sa.sin_port = serv->s_port;
+ else {
+ unsigned long l;
+ char *q;
+
+ /* Not in services, maybe a number? */
+ l = strtoul(p, &q, 0);
+
+ if (*q || l > USHRT_MAX) {
+ grecs_error(locus, 0,
+ _("%s: not a valid port number"), p);
+ return 1;
+ }
+ sa.sin_port = htons(l);
+ }
+ } else if (grecs_default_port)
+ sa.sin_port = grecs_default_port;
+ else {
+ grecs_error(locus, 0, _("missing port number"));
+ return 1;
+ }
+ sp->len = sizeof(sa);
+ sp->sa = grecs_malloc(sp->len);
+ memcpy(sp->sa, &sa, sp->len);
}
- sp->len = sizeof (sa);
- sp->sa = grecs_malloc (sp->len);
- memcpy (sp->sa, &sa, sp->len);
- }
- return 0;
+ return 0;
}
@@ -614,11 +589,11 @@ string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
# define TYPE_MINIMUM(t) \
- ((t) (! TYPE_SIGNED (t) \
+ ((t) (! TYPE_SIGNED(t) \
? (t) 0 \
- : TYPE_SIGNED_MAGNITUDE (t) \
+ : TYPE_SIGNED_MAGNITUDE(t) \
? ~ (t) 0 \
- : ~ TYPE_MAXIMUM (t)))
+ : ~ TYPE_MAXIMUM(t)))
# define TYPE_MAXIMUM(t) \
- ((t) (! TYPE_SIGNED (t) \
+ ((t) (! TYPE_SIGNED(t) \
? (t) -1 \
- : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
+ : ((((t) 1 << (sizeof(t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
# define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
@@ -644,3 +619,3 @@ string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
{ \
- grecs_error (loc, 0, _("numeric overflow")); \
+ grecs_error(loc, 0, _("numeric overflow")); \
return 1; \
@@ -649,3 +624,3 @@ string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
{ \
- grecs_error (loc, 0, _("value out of allowed range")); \
+ grecs_error(loc, 0, _("value out of allowed range")); \
return 1; \
@@ -674,3 +649,3 @@ string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
base = 10; \
- STRTONUM (s, type, base, res, limit, loc); \
+ STRTONUM(s, type, base, res, limit, loc); \
}
@@ -681,6 +656,6 @@ string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
const char *s = str; \
- STRxTONUM (s, type, tmpres, 0, loc); \
+ STRxTONUM(s, type, tmpres, 0, loc); \
if (*s) \
{ \
- grecs_error (loc, 0, _("not a number (stopped near `%s')"), \
+ grecs_error(loc, 0, _("not a number (stopped near `%s')"), \
s); \
@@ -702,3 +677,3 @@ string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
s++; \
- limit = TYPE_MINIMUM (type); \
+ limit = TYPE_MINIMUM(type); \
limit = - limit; \
@@ -708,6 +683,6 @@ string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
sign = 0; \
- limit = TYPE_MAXIMUM (type); \
+ limit = TYPE_MAXIMUM(type); \
} \
\
- STRxTONUM (s, unsigned type, tmpres, limit, loc); \
+ STRxTONUM(s, unsigned type, tmpres, limit, loc); \
if (*s) \
@@ -722,85 +697,85 @@ string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
int
-grecs_string_convert (void *target, enum grecs_data_type type,
+grecs_string_convert(void *target, enum grecs_data_type type,
const char *string, grecs_locus_t *locus)
{
- switch (type)
- {
- case grecs_type_void:
- abort ();
-
- case grecs_type_string:
- *(const char**)target = string;
- break;
+ switch (type) {
+ case grecs_type_void:
+ abort();
- case grecs_type_short:
- GETUNUM (string, short, *(short*)target, locus);
- break;
+ case grecs_type_string:
+ *(const char**)target = string;
+ break;
- case grecs_type_ushort:
- GETUNUM (string, unsigned short, *(unsigned short*)target, locus);
- break;
+ case grecs_type_short:
+ GETUNUM(string, short, *(short*)target, locus);
+ break;
- case grecs_type_bool:
- return string_to_bool (string, (int*)target, locus);
+ case grecs_type_ushort:
+ GETUNUM(string, unsigned short, *(unsigned short*)target, locus);
+ break;
- case grecs_type_int:
- GETSNUM (string, int, *(int*)target, locus);
- break;
+ case grecs_type_bool:
+ return string_to_bool(string, (int*)target, locus);
- case grecs_type_uint:
- GETUNUM (string, unsigned int, *(unsigned int*)target, locus);
- break;
+ case grecs_type_int:
+ GETSNUM(string, int, *(int*)target, locus);
+ break;
- case grecs_type_long:
- GETSNUM (string, long, *(long*)target, locus);
- break;
+ case grecs_type_uint:
+ GETUNUM(string, unsigned int, *(unsigned int*)target, locus);
+ break;
+
+ case grecs_type_long:
+ GETSNUM(string, long, *(long*)target, locus);
+ break;
- case grecs_type_ulong:
- GETUNUM (string, unsigned long, *(unsigned long*)target, locus);
- break;
+ case grecs_type_ulong:
+ GETUNUM(string, unsigned long, *(unsigned long*)target, locus);
+ break;
- case grecs_type_size:
- GETUNUM (string, size_t, *(size_t*)target, locus);
- break;
- /*FIXME
- case grecs_type_off:
- GETSNUM (string, off_t, *(off_t*)target, locus);
- break;
- */
- case grecs_type_time:
- /*FIXME: Use getdate */
- GETUNUM (string, time_t, *(time_t*)target, locus);
- break;
-
- case grecs_type_ipv4:
- if (inet_aton (string, (struct in_addr *)target))
- {
- grecs_error (locus, 0, _("%s: not a valid IP address"), string);
- return 1;
- }
- break;
-
- case grecs_type_host:
- if (string_to_host ((struct in_addr *)target, string, locus))
- {
- grecs_error (locus, 0,
- _("%s: not a valid IP address or hostname"), string);
- return 1;
+ case grecs_type_size:
+ GETUNUM(string, size_t, *(size_t*)target, locus);
+ break;
+ /*FIXME
+ case grecs_type_off:
+ GETSNUM(string, off_t, *(off_t*)target, locus);
+ break;
+ */
+ case grecs_type_time:
+ /*FIXME: Use getdate */
+ GETUNUM(string, time_t, *(time_t*)target, locus);
+ break;
+
+ case grecs_type_ipv4:
+ if (inet_aton(string, (struct in_addr *)target)) {
+ grecs_error(locus, 0, _("%s: not a valid IP address"),
+ string);
+ return 1;
}
- break;
+ break;
+
+ case grecs_type_host:
+ if (string_to_host((struct in_addr *)target, string, locus)) {
+ grecs_error(locus, 0,
+ _("%s: not a valid IP address or hostname"),
+ string);
+ return 1;
+ }
+ break;
- case grecs_type_sockaddr:
- return string_to_sockaddr ((struct grecs_sockaddr *)target, string,
- locus);
+ case grecs_type_sockaddr:
+ return string_to_sockaddr((struct grecs_sockaddr *)target, string,
+ locus);
/* FIXME: */
- case grecs_type_cidr:
- grecs_error (locus, 0, _("INTERNAL ERROR at %s:%d"), __FILE__, __LINE__);
- abort();
+ case grecs_type_cidr:
+ grecs_error(locus, 0,
+ _("INTERNAL ERROR at %s:%d"), __FILE__, __LINE__);
+ abort();
- case grecs_type_section:
- grecs_error (locus, 0,
- _("invalid use of block statement"));
- return 1;
- }
+ case grecs_type_section:
+ grecs_error(locus, 0,
+ _("invalid use of block statement"));
+ return 1;
+ }
return 0;
@@ -810,4 +785,4 @@ struct grecs_prop
{
- size_t size;
- int (*cmp) (const void *, const void *);
+ size_t size;
+ int (*cmp)(const void *, const void *);
};
@@ -815,5 +790,5 @@ struct grecs_prop
static int
-string_cmp (const void *elt1, const void *elt2)
+string_cmp(const void *elt1, const void *elt2)
{
- return strcmp ((const char *)elt1, (const char *)elt2);
+ return strcmp((const char *)elt1,(const char *)elt2);
}
@@ -824,5 +799,5 @@ string_cmp (const void *elt1, const void *elt2)
static int \
- NUMCMP(type) (const void *elt1, const void *elt2) \
+ NUMCMP(type)(const void *elt1, const void *elt2) \
{ \
- return memcmp (elt1, elt2, sizeof (ctype)); \
+ return memcmp(elt1, elt2, sizeof(ctype)); \
}
@@ -840,141 +815,130 @@ __DECL_NUMCMP(grecs_sockaddr, struct grecs_sockaddr)
struct grecs_prop grecs_prop_tab[] = {
- { 0, NULL }, /* grecs_type_void */
- { sizeof (char*), string_cmp }, /* grecs_type_string */
- { sizeof (short), NUMCMP (short) }, /* grecs_type_short */
- { sizeof (unsigned short), NUMCMP (short) }, /* grecs_type_ushort */
- { sizeof (int), NUMCMP (int) }, /* grecs_type_int */
- { sizeof (unsigned int), NUMCMP (int) }, /* grecs_type_uint */
- { sizeof (long), NUMCMP (long) }, /* grecs_type_long */
- { sizeof (unsigned long), NUMCMP (long) }, /* grecs_type_ulong */
- { sizeof (size_t), NUMCMP (size_t) }, /* grecs_type_size */
+ { 0, NULL }, /* grecs_type_void */
+ { sizeof(char*), string_cmp }, /* grecs_type_string */
+ { sizeof(short), NUMCMP(short) }, /* grecs_type_short */
+ { sizeof(unsigned short), NUMCMP(short) }, /* grecs_type_ushort */
+ { sizeof(int), NUMCMP(int) }, /* grecs_type_int */
+ { sizeof(unsigned int), NUMCMP(int) }, /* grecs_type_uint */
+ { sizeof(long), NUMCMP(long) }, /* grecs_type_long */
+ { sizeof(unsigned long), NUMCMP(long) }, /* grecs_type_ulong */
+ { sizeof(size_t), NUMCMP(size_t) }, /* grecs_type_size */
#if 0
- FIXME
- { sizeof (off_t), NUMCMP (off_t) }, /* grecs_type_off */
+ FIXME
+ { sizeof(off_t), NUMCMP(off_t) }, /* grecs_type_off */
#endif
- { sizeof (time_t), NUMCMP (time_t) }, /* grecs_type_time */
- { sizeof (int), NUMCMP (int) }, /* grecs_type_bool */
- { sizeof (struct in_addr), NUMCMP (in_addr) }, /* grecs_type_ipv4 */
- { 0, NULL }, /* FIXME: grecs_type_cidr */
- { sizeof (struct in_addr), NUMCMP (in_addr) }, /* grecs_type_host */
- { sizeof (struct grecs_sockaddr), NUMCMP (grecs_sockaddr) },
- /* grecs_type_sockaddr */
- { 0, NULL } /* grecs_type_section */
+ { sizeof(time_t), NUMCMP(time_t) }, /* grecs_type_time */
+ { sizeof(int), NUMCMP(int) }, /* grecs_type_bool */
+ { sizeof(struct in_addr), NUMCMP(in_addr) }, /* grecs_type_ipv4 */
+ { 0, NULL }, /* FIXME: grecs_type_cidr */
+ { sizeof(struct in_addr), NUMCMP(in_addr) }, /* grecs_type_host */
+ { sizeof(struct grecs_sockaddr), NUMCMP(grecs_sockaddr) },
+ /* grecs_type_sockaddr */
+ { 0, NULL } /* grecs_type_section */
};
#define grecs_prop_count \
- (sizeof (grecs_prop_tab) / sizeof (grecs_prop_tab[0]))
+ (sizeof(grecs_prop_tab) / sizeof(grecs_prop_tab[0]))
void
-grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value,
+grecs_process_ident(struct grecs_keyword *kwp, grecs_value_t *value,
void *base, grecs_locus_t *locus)
{
- void *target;
+ void *target;
- if (!kwp)
- return;
-
- target = target_ptr (kwp, (char *) base);
-
- if (kwp->callback)
- kwp->callback (grecs_callback_set_value,
- locus,
- target,
- value,
- &kwp->callback_data);
- else if (value->type == GRECS_TYPE_ARRAY)
- {
- grecs_error (locus, 0,
- _("too many arguments to `%s'; missing semicolon?"),
- kwp->ident);
- return;
- }
- else if (value->type == GRECS_TYPE_LIST)
- {
- if (GRECS_IS_LIST (kwp->type))
- {
- struct grecs_list_entry *ep;
- enum grecs_data_type type = GRECS_TYPE (kwp->type);
- int num = 1;
- struct grecs_list *list;
- size_t size;
-
- if (type >= grecs_prop_count
- || (size = grecs_prop_tab[type].size) == 0)
- {
- grecs_error (locus, 0,
- _("INTERNAL ERROR at %s:%d: "
- "unhandled data type %d"),
- __FILE__, __LINE__, type);
- abort ();
- }
-
- list = grecs_list_create ();
- list->cmp = grecs_prop_tab[type].cmp;
-
- for (ep = value->v.list->head; ep; ep = ep->next)
- {
- const grecs_value_t *vp = ep->data;
-
- if (vp->type != GRECS_TYPE_STRING)
- grecs_error (locus, 0,
+ if (!kwp)
+ return;
+
+ target = target_ptr(kwp, (char *) base);
+
+ if (kwp->callback)
+ kwp->callback(grecs_callback_set_value,
+ locus,
+ target,
+ value,
+ &kwp->callback_data);
+ else if (value->type == GRECS_TYPE_ARRAY) {
+ grecs_error(locus, 0,
+ _("too many arguments to `%s'; missing semicolon?"),
+ kwp->ident);
+ return;
+ } else if (value->type == GRECS_TYPE_LIST) {
+ if (GRECS_IS_LIST(kwp->type)) {
+ struct grecs_list_entry *ep;
+ enum grecs_data_type type = GRECS_TYPE(kwp->type);
+ int num = 1;
+ struct grecs_list *list;
+ size_t size;
+
+ if (type >= grecs_prop_count
+ || (size = grecs_prop_tab[type].size) == 0) {
+ grecs_error(locus, 0,
+ _("INTERNAL ERROR at %s:%d: "
+ "unhandled data type %d"),
+ __FILE__, __LINE__, type);
+ abort();
+ }
+
+ list = grecs_list_create();
+ list->cmp = grecs_prop_tab[type].cmp;
+
+ for (ep = value->v.list->head; ep; ep = ep->next) {
+ const grecs_value_t *vp = ep->data;
+
+ if (vp->type != GRECS_TYPE_STRING)
+ grecs_error(locus, 0,
_("%s: incompatible data type in list item #%d"),
- kwp->ident, num);
- else if (type == grecs_type_string)
- grecs_list_append (list, (void*) vp->v.string);
- else
- {
- void *ptr = grecs_malloc (size);
- if (grecs_string_convert (ptr, type, vp->v.string,
- locus) == 0)
- grecs_list_append (list, ptr);
- else
- free (ptr);
+ kwp->ident, num);
+ else if (type == grecs_type_string)
+ grecs_list_append(list,
+ (void*) vp->v.string);
+ else {
+ void *ptr = grecs_malloc(size);
+ if (grecs_string_convert(ptr,
+ type,
+ vp->v.string,
+ locus) == 0)
+ grecs_list_append(list, ptr);
+ else
+ free(ptr);
+ }
+ }
+ *(struct grecs_list**)target = list;
+ } else {
+ grecs_error(locus, 0,
+ _("incompatible data type for `%s'"),
+ kwp->ident);
+ return;
}
- }
- *(struct grecs_list**)target = list;
- }
- else
- {
- grecs_error (locus, 0,
- _("incompatible data type for `%s'"),
- kwp->ident);
- return;
- }
- }
- else if (GRECS_IS_LIST (kwp->type))
- {
- struct grecs_list *list;
- enum grecs_data_type type = GRECS_TYPE (kwp->type);
- size_t size;
- void *ptr;
+ } else if (GRECS_IS_LIST(kwp->type)) {
+ struct grecs_list *list;
+ enum grecs_data_type type = GRECS_TYPE(kwp->type);
+ size_t size;
+ void *ptr;
- if (type >= grecs_prop_count
- || (size = grecs_prop_tab[type].size) == 0)
- {
- grecs_error (locus, 0,
- _("INTERNAL ERROR at %s:%d: unhandled data type %d"),
- __FILE__, __LINE__, type);
- abort();
- }
-
- list = grecs_list_create ();
- list->cmp = grecs_prop_tab[type].cmp;
- list->free_entry = listel_dispose;
- if (type == grecs_type_string)
- grecs_list_append (list, value->v.string);
- else
- {
- ptr = grecs_malloc (size);
- if (grecs_string_convert (ptr, type, value->v.string, locus))
- {
- free (ptr);
- grecs_list_free (list);
- return;
- }
- grecs_list_append (list, ptr);
- }
- *(struct grecs_list**)target = list;
- }
- else
- grecs_string_convert (target, GRECS_TYPE (kwp->type), value->v.string,
- locus);
+ if (type >= grecs_prop_count
+ || (size = grecs_prop_tab[type].size) == 0) {
+ grecs_error(locus, 0,
+ _("INTERNAL ERROR at %s:%d: unhandled data type %d"),
+ __FILE__, __LINE__, type);
+ abort();
+ }
+
+ list = grecs_list_create();
+ list->cmp = grecs_prop_tab[type].cmp;
+ list->free_entry = listel_dispose;
+ if (type == grecs_type_string)
+ grecs_list_append(list, value->v.string);
+ else {
+ ptr = grecs_malloc(size);
+ if (grecs_string_convert(ptr, type, value->v.string, locus)) {
+ free(ptr);
+ grecs_list_free(list);
+ return;
+ }
+ grecs_list_append(list, ptr);
+ }
+ *(struct grecs_list**)target = list;
+ } else
+ grecs_string_convert(target, GRECS_TYPE(kwp->type),
+ value->v.string,
+ locus);
}
@@ -982,5 +946,5 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value,
static void
-process_ident (struct grecs_keyword *kwp, grecs_value_t *value)
+process_ident(struct grecs_keyword *kwp, grecs_value_t *value)
{
- grecs_process_ident (kwp, value, CURRENT_BASE, &grecs_current_locus);
+ grecs_process_ident(kwp, value, CURRENT_BASE, &grecs_current_locus);
}
diff --git a/src/grecs-lex.l b/src/grecs-lex.l
index baf85de..9c01e0d 100644
--- a/src/grecs-lex.l
+++ b/src/grecs-lex.l
@@ -36,3 +36,3 @@ static size_t multiline_delimiter_len;
static int multiline_unescape; /* Unescape here-document contents */
-static int (*char_to_strip) (char); /* Strip matching characters of each
+static int (*char_to_strip)(char); /* Strip matching characters of each
here-document line */
@@ -52,11 +52,11 @@ static struct grecs_list *string_list;
-static void multiline_begin (char *);
-static void multiline_add (char *);
-static char *multiline_strip_tabs (char *text);
-static void line_add_unescape_last (char *text, size_t len);
-static int ident (void);
-static int isemptystr (int off);
+static void multiline_begin(char *);
+static void multiline_add(char *);
+static char *multiline_strip_tabs(char *text);
+static void line_add_unescape_last(char *text, size_t len);
+static int ident(void);
+static int isemptystr(int off);
-static void parse_line (char *text, grecs_locus_t *ploc, size_t *pxlines);
-static void parse_line_cpp (char *text, grecs_locus_t *ploc, size_t *pxlines);
+static void parse_line(char *text, grecs_locus_t *ploc, size_t *pxlines);
+static void parse_line_cpp(char *text, grecs_locus_t *ploc, size_t *pxlines);
@@ -67,3 +67,3 @@ static void parse_line_cpp (char *text, grecs_locus_t *ploc, size_t *pxlines);
if (grecs_preprocessor) \
- result = fread (buf, 1, max_size, yyin); \
+ result = fread(buf, 1, max_size, yyin); \
else \
@@ -71,3 +71,3 @@ static void parse_line_cpp (char *text, grecs_locus_t *ploc, size_t *pxlines);
} \
- while (0)
+ while(0)
@@ -84,3 +84,3 @@ P [1-9][0-9]*
/* C-style comments */
-"/*" BEGIN (COMMENT);
+"/*" BEGIN(COMMENT);
<COMMENT>[^*\n]* /* eat anything that's not a '*' */
@@ -88,8 +88,8 @@ P [1-9][0-9]*
<COMMENT>\n ++grecs_current_locus.line;
-<COMMENT>"*"+"/" BEGIN (INITIAL);
+<COMMENT>"*"+"/" BEGIN(INITIAL);
/* Line directive */
-^[ \t]*#[ \t]*{P}[ \t]+\".*\".*\n { parse_line_cpp (yytext,
+^[ \t]*#[ \t]*{P}[ \t]+\".*\".*\n { parse_line_cpp(yytext,
&grecs_current_locus,
&xlines); }
-^[ \t]*#[ \t]*line[ \t].*\n { parse_line (yytext, &grecs_current_locus,
+^[ \t]*#[ \t]*line[ \t].*\n { parse_line(yytext, &grecs_current_locus,
&xlines); }
@@ -101,23 +101,23 @@ P [1-9][0-9]*
/* Identifiers */
-<INITIAL>{ID} return ident ();
+<INITIAL>{ID} return ident();
/* Strings */
-[a-zA-Z0-9_\.\*/:@-]+ { grecs_line_begin ();
- grecs_line_add (yytext, yyleng);
- yylval.string = grecs_line_finish ();
- return STRING; }
+[a-zA-Z0-9_\.\*/:@-]+ { grecs_line_begin();
+ grecs_line_add(yytext, yyleng);
+ yylval.string = grecs_line_finish();
+ return STRING; }
/* Quoted strings */
-\"[^\\"\n]*\" { grecs_line_begin ();
- grecs_line_add (yytext + 1, yyleng - 2);
- yylval.string = grecs_line_finish ();
+\"[^\\"\n]*\" { grecs_line_begin();
+ grecs_line_add(yytext + 1, yyleng - 2);
+ yylval.string = grecs_line_finish();
return QSTRING; }
\"[^\\"\n]*\\. |
-\"[^\\"\n]*\\\n { BEGIN (STR);
- grecs_line_begin ();
- line_add_unescape_last (yytext + 1, yyleng - 1); }
+\"[^\\"\n]*\\\n { BEGIN(STR);
+ grecs_line_begin();
+ line_add_unescape_last(yytext + 1, yyleng - 1); }
<STR>[^\\"\n]*\\. |
-<STR>\"[^\\"\n]*\\\n { line_add_unescape_last (yytext, yyleng); }
+<STR>\"[^\\"\n]*\\\n { line_add_unescape_last(yytext, yyleng); }
<STR>[^\\"\n]*\" { BEGIN(INITIAL);
if (yyleng > 1)
- grecs_line_add (yytext, yyleng - 1);
- yylval.string = grecs_line_finish ();
+ grecs_line_add(yytext, yyleng - 1);
+ yylval.string = grecs_line_finish();
return QSTRING; }
@@ -130,4 +130,4 @@ P [1-9][0-9]*
"<<"(-" "?)?\"{ID}\"[ \t]*\n {
- BEGIN (ML);
- multiline_begin (yytext+2);
+ BEGIN(ML);
+ multiline_begin(yytext+2);
grecs_current_locus.line++; }
@@ -135,15 +135,14 @@ P [1-9][0-9]*
<ML>^"#line ".*\n { grecs_current_locus.line++; }
-<ML>.*\n { char *p = multiline_strip_tabs (yytext);
+<ML>.*\n { char *p = multiline_strip_tabs(yytext);
- if (!strncmp (p, multiline_delimiter, multiline_delimiter_len)
- && isemptystr (p + multiline_delimiter_len - yytext))
- {
- free (multiline_delimiter);
- multiline_delimiter = NULL;
- BEGIN (INITIAL);
- yylval.string = grecs_line_finish ();
- return MSTRING;
- }
+ if (!strncmp(p, multiline_delimiter, multiline_delimiter_len)
+ && isemptystr(p + multiline_delimiter_len - yytext)) {
+ free(multiline_delimiter);
+ multiline_delimiter = NULL;
+ BEGIN(INITIAL);
+ yylval.string = grecs_line_finish();
+ return MSTRING;
+ }
grecs_current_locus.line++;
- multiline_add (p); }
+ multiline_add(p); }
{WS} ;
@@ -152,6 +151,7 @@ P [1-9][0-9]*
[,;{}()] return yytext[0];
-. { if (isascii (yytext[0]) && isprint (yytext[0]))
- grecs_error (&grecs_current_locus, 0, _("stray character %c"), yytext[0]);
+. { if (isascii(yytext[0]) && isprint(yytext[0]))
+ grecs_error(&grecs_current_locus, 0,
+ _("stray character %c"), yytext[0]);
else
- grecs_error (&grecs_current_locus, 0, _("stray character \\%03o"),
+ grecs_error(&grecs_current_locus, 0, _("stray character \\%03o"),
(unsigned char) yytext[0]); }
@@ -162,10 +162,10 @@ pid_t grecs_preproc_pid;
int
-yywrap ()
+yywrap()
{
- if (yyin)
- grecs_preproc_extrn_shutdown (grecs_preproc_pid);
- else
- grecs_preproc_done ();
- grecs_current_locus.file = NULL;
- return 1;
+ if (yyin)
+ grecs_preproc_extrn_shutdown(grecs_preproc_pid);
+ else
+ grecs_preproc_done();
+ grecs_current_locus.file = NULL;
+ return 1;
}
@@ -173,5 +173,5 @@ yywrap ()
static void
-line_acc_free_entry (void *ptr)
+line_acc_free_entry(void *ptr)
{
- free (ptr);
+ free(ptr);
}
@@ -179,36 +179,32 @@ line_acc_free_entry (void *ptr)
int
-grecs_lex_begin (const char *name)
+grecs_lex_begin(const char *name)
{
- if (yy_flex_debug > 0)
- yy_flex_debug = 0;
+ if (yy_flex_debug > 0)
+ yy_flex_debug = 0;
- line_acc = grecs_list_create ();
- line_acc->free_entry = line_acc_free_entry;
- string_list = grecs_list_create ();
-
- if (grecs_preprocessor)
- {
- int fd;
+ line_acc = grecs_list_create();
+ line_acc->free_entry = line_acc_free_entry;
+ string_list = grecs_list_create();
- fd = open (name, O_RDONLY);
- if (fd == -1)
- {
- grecs_error (NULL, errno, _("Cannot open `%s'"), name);
- return 1;
- }
- close (fd);
-
- yyin = grecs_preproc_extrn_start (name, &grecs_preproc_pid);
- if (!yyin)
- {
- grecs_error (NULL, errno,
- _("Unable to start external preprocessor `%s'"),
- grecs_preprocessor);
- return 1;
- }
- }
- else
- return grecs_preproc_init (name);
-
- return 0;
+ if (grecs_preprocessor) {
+ int fd;
+
+ fd = open(name, O_RDONLY);
+ if (fd == -1) {
+ grecs_error(NULL, errno, _("Cannot open `%s'"), name);
+ return 1;
+ }
+ close(fd);
+
+ yyin = grecs_preproc_extrn_start(name, &grecs_preproc_pid);
+ if (!yyin) {
+ grecs_error(NULL, errno,
+ _("Unable to start external preprocessor `%s'"),
+ grecs_preprocessor);
+ return 1;
+ }
+ } else
+ return grecs_preproc_init(name);
+
+ return 0;
}
@@ -216,3 +212,3 @@ grecs_lex_begin (const char *name)
void
-grecs_lex_end ()
+grecs_lex_end()
{
@@ -221,16 +217,15 @@ grecs_lex_end ()
static int
-isemptystr (int off)
+isemptystr(int off)
{
- for (; yytext[off] && isspace (yytext[off]); off++)
- ;
- if (yytext[off] == ';')
- {
- int i;
- for (i = off + 1; yytext[i]; i++)
- if (!isspace (yytext[i]))
- return 0;
- yyless (off);
- return 1;
- }
- return yytext[off] == 0;
+ for (; yytext[off] && isspace(yytext[off]); off++)
+ ;
+ if (yytext[off] == ';') {
+ int i;
+ for (i = off + 1; yytext[i]; i++)
+ if (!isspace(yytext[i]))
+ return 0;
+ yyless(off);
+ return 1;
+ }
+ return yytext[off] == 0;
}
@@ -238,8 +233,8 @@ isemptystr (int off)
char *
-multiline_strip_tabs (char *text)
+multiline_strip_tabs(char *text)
{
- if (char_to_strip)
- for (; *text && char_to_strip (*text); text++)
- ;
- return text;
+ if (char_to_strip)
+ for (; *text && char_to_strip(*text); text++)
+ ;
+ return text;
}
@@ -247,14 +242,13 @@ multiline_strip_tabs (char *text)
static int
-unquote_char (int c)
+unquote_char(int c)
{
- static char quote_transtab[] = "\\\\\"\"a\ab\bf\fn\nr\rt\tv\v";
-
- char *p;
-
- for (p = quote_transtab; *p; p += 2)
- {
- if (*p == c)
- return p[1];
- }
- return -1;
+ static char quote_transtab[] = "\\\\\"\"a\ab\bf\fn\nr\rt\tv\v";
+
+ char *p;
+
+ for (p = quote_transtab; *p; p += 2) {
+ if (*p == c)
+ return p[1];
+ }
+ return -1;
}
@@ -263,3 +257,3 @@ struct line_acc_entry
{
- size_t size;
+ size_t size;
};
@@ -268,10 +262,10 @@ struct line_acc_entry
static void
-line_acc_add_string (const char *str, size_t len)
+line_acc_add_string(const char *str, size_t len)
{
- struct line_acc_entry *ent = grecs_malloc (sizeof (*ent) + len + 1);
- char *p = line_acc_ptr (ent);
- memcpy (p, str, len);
- p[len] = 0;
- ent->size = len;
- grecs_list_append (line_acc, ent);
+ struct line_acc_entry *ent = grecs_malloc(sizeof(*ent) + len + 1);
+ char *p = line_acc_ptr(ent);
+ memcpy(p, str, len);
+ p[len] = 0;
+ ent->size = len;
+ grecs_list_append(line_acc, ent);
}
@@ -279,6 +273,6 @@ line_acc_add_string (const char *str, size_t len)
static void
-line_acc_add_char (int c)
+line_acc_add_char(int c)
{
- char t = c;
- line_acc_add_string (&t, 1);
+ char t = c;
+ line_acc_add_string(&t, 1);
}
@@ -286,17 +280,15 @@ line_acc_add_char (int c)
static void
-list_acc_unescape_char (int c)
+list_acc_unescape_char(int c)
{
- if (c != '\n')
- {
- int t = unquote_char (c);
- if (t != -1)
- line_acc_add_char (t);
- else
- {
- grecs_warning(&grecs_current_locus, 0,
- _("unknown escape sequence '\\%c'"),
- c);
- line_acc_add_char (c);
+ if (c != '\n') {
+ int t = unquote_char(c);
+ if (t != -1)
+ line_acc_add_char(t);
+ else {
+ grecs_warning(&grecs_current_locus, 0,
+ _("unknown escape sequence '\\%c'"),
+ c);
+ line_acc_add_char(c);
+ }
}
- }
}
@@ -304,5 +296,5 @@ list_acc_unescape_char (int c)
void
-grecs_line_add (const char *text, size_t len)
+grecs_line_add(const char *text, size_t len)
{
- line_acc_add_string (text, len);
+ line_acc_add_string(text, len);
}
@@ -311,6 +303,6 @@ grecs_line_add (const char *text, size_t len)
static void
-line_add_unescape_last (char *text, size_t len)
+line_add_unescape_last(char *text, size_t len)
{
- line_acc_add_string (text, len - 2);
- list_acc_unescape_char (text[len - 1]);
+ line_acc_add_string(text, len - 2);
+ list_acc_unescape_char(text[len - 1]);
}
@@ -318,19 +310,14 @@ line_add_unescape_last (char *text, size_t len)
static void
-multiline_add (char *s)
+multiline_add(char *s)
{
- if (multiline_unescape)
- {
- for (; *s; s++)
- {
- if (*s == '\\')
- {
- list_acc_unescape_char (s[1]);
- ++s;
- }
- else
- line_acc_add_char (*s);
- }
- }
- else
- grecs_line_add (s, strlen (s));
+ if (multiline_unescape) {
+ for (; *s; s++) {
+ if (*s == '\\') {
+ list_acc_unescape_char(s[1]);
+ ++s;
+ } else
+ line_acc_add_char(*s);
+ }
+ } else
+ grecs_line_add(s, strlen(s));
}
@@ -338,3 +325,3 @@ multiline_add (char *s)
void
-grecs_line_begin ()
+grecs_line_begin()
{
@@ -344,5 +331,5 @@ grecs_line_begin ()
static int
-is_tab (char c)
+is_tab(char c)
{
- return c == '\t';
+ return c == '\t';
}
@@ -350,5 +337,5 @@ is_tab (char c)
static int
-is_ws (char c)
+is_ws(char c)
{
- return c == '\t' || c == ' ';
+ return c == '\t' || c == ' ';
}
@@ -356,42 +343,33 @@ is_ws (char c)
void
-multiline_begin (char *p)
+multiline_begin(char *p)
{
- if (*p == '-')
- {
- if (*++p == ' ')
- {
- char_to_strip = is_ws;
- p++;
- }
- else
- char_to_strip = is_tab;
- }
- else
- char_to_strip = NULL;
- if (*p == '\\')
- {
- p++;
- multiline_unescape = 0;
- }
- else if (*p == '"')
- {
- char *q;
+ if (*p == '-') {
+ if (*++p == ' ') {
+ char_to_strip = is_ws;
+ p++;
+ } else
+ char_to_strip = is_tab;
+ } else
+ char_to_strip = NULL;
+ if (*p == '\\') {
+ p++;
+ multiline_unescape = 0;
+ } else if (*p == '"') {
+ char *q;
- p++;
- multiline_unescape = 0;
- q = strchr (p, '"');
- multiline_delimiter_len = q - p;
- }
- else
- {
- multiline_delimiter_len = strcspn (p, " \t");
- multiline_unescape = 1;
- }
-
- /* Remove trailing newline */
- multiline_delimiter_len--;
- multiline_delimiter = grecs_malloc (multiline_delimiter_len + 1);
- memcpy (multiline_delimiter, p, multiline_delimiter_len);
- multiline_delimiter[multiline_delimiter_len] = 0;
- grecs_line_begin ();
+ p++;
+ multiline_unescape = 0;
+ q = strchr(p, '"');
+ multiline_delimiter_len = q - p;
+ } else {
+ multiline_delimiter_len = strcspn(p, " \t");
+ multiline_unescape = 1;
+ }
+
+ /* Remove trailing newline */
+ multiline_delimiter_len--;
+ multiline_delimiter = grecs_malloc(multiline_delimiter_len + 1);
+ memcpy(multiline_delimiter, p, multiline_delimiter_len);
+ multiline_delimiter[multiline_delimiter_len] = 0;
+ grecs_line_begin();
}
@@ -399,26 +377,24 @@ multiline_begin (char *p)
char *
-grecs_line_finish ()
+grecs_line_finish()
{
- struct grecs_list_entry *ep;
- size_t size = 0;
- char *str, *p;
-
- for (ep = line_acc->head; ep; ep = ep->next)
- {
- struct line_acc_entry *ent = ep->data;
- size += ent->size;
- }
-
- str = grecs_malloc (size + 1);
- grecs_list_append (string_list, str);
- for (ep = line_acc->head, p = str; ep; ep = ep->next)
- {
- struct line_acc_entry *ent = ep->data;
- char *str = line_acc_ptr (ent);
- memcpy (p, str, ent->size);
- p += ent->size;
- }
- *p = 0;
- grecs_list_clear (line_acc);
- return str;
+ struct grecs_list_entry *ep;
+ size_t size = 0;
+ char *str, *p;
+
+ for (ep = line_acc->head; ep; ep = ep->next) {
+ struct line_acc_entry *ent = ep->data;
+ size += ent->size;
+ }
+
+ str = grecs_malloc(size + 1);
+ grecs_list_append(string_list, str);
+ for (ep = line_acc->head, p = str; ep; ep = ep->next) {
+ struct line_acc_entry *ent = ep->data;
+ char *str = line_acc_ptr(ent);
+ memcpy(p, str, ent->size);
+ p += ent->size;
+ }
+ *p = 0;
+ grecs_list_clear(line_acc);
+ return str;
}
@@ -426,17 +402,17 @@ grecs_line_finish ()
static int
-ident ()
+ident()
{
- char *p;
- char *str;
- size_t len;
+ char *p;
+ char *str;
+ size_t len;
- for (p = yytext; *p && isspace (*p); p++)
- ;
-
- len = strlen (p);
- str = grecs_malloc (len + 1);
- strcpy (str, p);
- grecs_list_append (string_list, str);
- yylval.string = str;
- return IDENT;
+ for (p = yytext; *p && isspace(*p); p++)
+ ;
+
+ len = strlen(p);
+ str = grecs_malloc(len + 1);
+ strcpy(str, p);
+ grecs_list_append(string_list, str);
+ yylval.string = str;
+ return IDENT;
}
@@ -444,5 +420,5 @@ ident ()
void
-grecs_lex_trace (int n)
+grecs_lex_trace(int n)
{
- yy_flex_debug = -n;
+ yy_flex_debug = -n;
}
@@ -450,8 +426,8 @@ grecs_lex_trace (int n)
grecs_value_t *
-grecs_value_dup (grecs_value_t *input)
+grecs_value_dup(grecs_value_t *input)
{
- grecs_value_t *ptr = grecs_malloc (sizeof (*ptr));
- grecs_list_append (string_list, ptr);
- *ptr = *input;
- return ptr;
+ grecs_value_t *ptr = grecs_malloc(sizeof(*ptr));
+ grecs_list_append(string_list, ptr);
+ *ptr = *input;
+ return ptr;
}
@@ -460,14 +436,13 @@ grecs_value_dup (grecs_value_t *input)
static int
-assign_locus (grecs_locus_t *ploc, char *name, char *line, size_t *pxlines)
+assign_locus(grecs_locus_t *ploc, char *name, char *line, size_t *pxlines)
{
- char *p;
-
- if (name)
- {
- if (pxlines && (!ploc->file || strcmp(name, ploc->file)))
- *pxlines = 0;
- ploc->file = grecs_install_text (name);
- }
- ploc->line = strtoul (line, &p, 10) - (pxlines ? *pxlines : 0);
- return *p != 0;
+ char *p;
+
+ if (name) {
+ if (pxlines && (!ploc->file || strcmp(name, ploc->file)))
+ *pxlines = 0;
+ ploc->file = grecs_install_text(name);
+ }
+ ploc->line = strtoul(line, &p, 10) - (pxlines ? *pxlines : 0);
+ return *p != 0;
}
@@ -475,34 +450,34 @@ assign_locus (grecs_locus_t *ploc, char *name, char *line, size_t *pxlines)
static void
-parse_line (char *text, grecs_locus_t *ploc, size_t *pxlines)
+parse_line(char *text, grecs_locus_t *ploc, size_t *pxlines)
{
- int rc = 1;
- struct wordsplit ws;
-
- if (wordsplit (text, &ws, WRDSF_DEFFLAGS))
- grecs_error (ploc, 0, _("cannot parse #line line"));
- else
- {
- if (ws.ws_wordc == 2)
- rc = assign_locus (ploc, NULL, ws.ws_wordv[1], pxlines);
- else if (ws.ws_wordc == 3)
- rc = assign_locus (ploc, ws.ws_wordv[2], ws.ws_wordv[1], pxlines);
- else if (ws.ws_wordc == 4)
- {
- rc = assign_locus (ploc, ws.ws_wordv[2], ws.ws_wordv[1], 0);
- if (rc == 0)
- {
- char *p;
- unsigned long x = strtoul (ws.ws_wordv[3], &p, 10);
- rc = *p != 0;
- if (rc == 0)
- *pxlines = x;
- }
- }
- else
- grecs_error (ploc, 0, _("invalid #line statement"));
+ int rc = 1;
+ struct wordsplit ws;
+
+ if (wordsplit(text, &ws, WRDSF_DEFFLAGS))
+ grecs_error(ploc, 0, _("cannot parse #line line"));
+ else {
+ if (ws.ws_wordc == 2)
+ rc = assign_locus(ploc, NULL,
+ ws.ws_wordv[1], pxlines);
+ else if (ws.ws_wordc == 3)
+ rc = assign_locus(ploc, ws.ws_wordv[2],
+ ws.ws_wordv[1], pxlines);
+ else if (ws.ws_wordc == 4) {
+ rc = assign_locus(ploc, ws.ws_wordv[2],
+ ws.ws_wordv[1], 0);
+ if (rc == 0) {
+ char *p;
+ unsigned long x = strtoul(ws.ws_wordv[3],
+ &p, 10);
+ rc = *p != 0;
+ if (rc == 0)
+ *pxlines = x;
+ }
+ } else
+ grecs_error(ploc, 0, _("invalid #line statement"));
- if (rc)
- grecs_error (ploc, 0, _("malformed #line statement"));
- wordsplit_free (&ws);
- }
+ if (rc)
+ grecs_error(ploc, 0, _("malformed #line statement"));
+ wordsplit_free(&ws);
+ }
}
@@ -510,19 +485,17 @@ parse_line (char *text, grecs_locus_t *ploc, size_t *pxlines)
static void
-parse_line_cpp (char *text, grecs_locus_t *ploc, size_t *pxlines)
+parse_line_cpp(char *text, grecs_locus_t *ploc, size_t *pxlines)
{
- struct wordsplit ws;
-
- if (wordsplit (text, &ws, WRDSF_DEFFLAGS))
- {
- grecs_error (ploc, 0, _("cannot parse #line line"));
- return;
- }
- else if (ws.ws_wordc < 3)
- grecs_error (ploc, 0, _("invalid #line statement"));
- else
- {
- if (assign_locus (ploc, ws.ws_wordv[2], ws.ws_wordv[1], pxlines))
- grecs_error (ploc, 0, _("malformed #line statement"));
- }
- wordsplit_free (&ws);
+ struct wordsplit ws;
+
+ if (wordsplit(text, &ws, WRDSF_DEFFLAGS)) {
+ grecs_error(ploc, 0, _("cannot parse #line line"));
+ return;
+ } else if (ws.ws_wordc < 3)
+ grecs_error(ploc, 0, _("invalid #line statement"));
+ else {
+ if (assign_locus(ploc, ws.ws_wordv[2],
+ ws.ws_wordv[1], pxlines))
+ grecs_error(ploc, 0, _("malformed #line statement"));
+ }
+ wordsplit_free(&ws);
}
diff --git a/src/grecs.h b/src/grecs.h
index ec98979..5769736 100644
--- a/src/grecs.h
+++ b/src/grecs.h
@@ -30,3 +30,3 @@
#ifndef _
-# define _(msgid) gettext (msgid)
+# define _(msgid) gettext(msgid)
#endif
@@ -37,4 +37,4 @@
typedef struct {
- char *file;
- int line;
+ char *file;
+ int line;
} grecs_locus_t;
@@ -44,19 +44,19 @@ extern grecs_locus_t grecs_locus;
enum grecs_data_type {
- grecs_type_void,
- grecs_type_string,
- grecs_type_short,
- grecs_type_ushort,
- grecs_type_int,
- grecs_type_uint,
- grecs_type_long,
- grecs_type_ulong,
- grecs_type_size,
+ grecs_type_void,
+ grecs_type_string,
+ grecs_type_short,
+ grecs_type_ushort,
+ grecs_type_int,
+ grecs_type_uint,
+ grecs_type_long,
+ grecs_type_ulong,
+ grecs_type_size,
/* grecs_type_off,*/
- grecs_type_time,
- grecs_type_bool,
- grecs_type_ipv4,
- grecs_type_cidr,
- grecs_type_host,
- grecs_type_sockaddr,
- grecs_type_section
+ grecs_type_time,
+ grecs_type_bool,
+ grecs_type_ipv4,
+ grecs_type_cidr,
+ grecs_type_host,
+ grecs_type_sockaddr,
+ grecs_type_section
};
@@ -69,5 +69,5 @@ enum grecs_data_type {
enum grecs_callback_command {
- grecs_callback_section_begin,
- grecs_callback_section_end,
- grecs_callback_set_value
+ grecs_callback_section_begin,
+ grecs_callback_section_end,
+ grecs_callback_set_value
};
@@ -91,31 +91,31 @@ struct grecs_list {
typedef struct grecs_value {
- int type;
- union {
- struct grecs_list *list;
- const char *string;
- struct {
- size_t c;
- struct grecs_value *v;
- } arg;
- } v;
+ int type;
+ union {
+ struct grecs_list *list;
+ const char *string;
+ struct {
+ size_t c;
+ struct grecs_value *v;
+ } arg;
+ } v;
} grecs_value_t;
-typedef int (*grecs_callback_fn) (
- enum grecs_callback_command cmd,
- grecs_locus_t * /* locus */,
- void * /* varptr */,
- grecs_value_t * /* value */,
- void * /* cb_data */
- );
+typedef int (*grecs_callback_fn)(
+ enum grecs_callback_command cmd,
+ grecs_locus_t * /* locus */,
+ void * /* varptr */,
+ grecs_value_t * /* value */,
+ void * /* cb_data */
+ );
struct grecs_keyword {
- const char *ident;
- const char *argname;
- const char *docstring;
- enum grecs_data_type type;
- void *varptr;
- size_t offset;
- grecs_callback_fn callback;
- void *callback_data;
- struct grecs_keyword *kwd;
+ const char *ident;
+ const char *argname;
+ const char *docstring;
+ enum grecs_data_type type;
+ void *varptr;
+ size_t offset;
+ grecs_callback_fn callback;
+ void *callback_data;
+ struct grecs_keyword *kwd;
};
@@ -123,4 +123,4 @@ struct grecs_keyword {
struct grecs_sockaddr {
- int len;
- struct sockaddr *sa;
+ int len;
+ struct sockaddr *sa;
};
@@ -129,3 +129,3 @@ extern void *(*grecs_malloc_fun)(size_t size);
extern void *(*grecs_realloc_fun)(void *ptr, size_t size);
-extern void (*grecs_alloc_die_fun) (void);
+extern void (*grecs_alloc_die_fun)(void);
@@ -148,3 +148,3 @@ void grecs_set_keywords(struct grecs_keyword *kwd);
void grecs_gram_trace(int n);
-void grecs_lex_trace (int n);
+void grecs_lex_trace(int n);
@@ -152,14 +152,14 @@ int grecs_lex_begin(const char*);
void grecs_lex_end(void);
-int grecs_parse (const char *name);
+int grecs_parse(const char *name);
-void grecs_line_begin (void);
-void grecs_line_add (const char *text, size_t len);
-char *grecs_line_finish (void);
+void grecs_line_begin(void);
+void grecs_line_add(const char *text, size_t len);
+char *grecs_line_finish(void);
-extern int grecs_string_convert (void *target, enum grecs_data_type type,
- const char *string, grecs_locus_t *locus);
-extern void grecs_process_ident (struct grecs_keyword *kwp,
- grecs_value_t *value,
- void *base,
- grecs_locus_t *locus);
+extern int grecs_string_convert(void *target, enum grecs_data_type type,
+ const char *string, grecs_locus_t *locus);
+extern void grecs_process_ident(struct grecs_keyword *kwp,
+ grecs_value_t *value,
+ void *base,
+ grecs_locus_t *locus);
@@ -171,27 +171,27 @@ extern const char *grecs_preprocessor;
extern int grecs_log_to_stderr;
-extern void (*grecs_log_setup_hook) ();
+extern void (*grecs_log_setup_hook)();
-size_t grecs_preproc_fill_buffer (char *buf, size_t size);
-void grecs_preproc_add_include_dir (char *dir);
-int grecs_preproc_init (const char *name);
-void grecs_preproc_done (void);
-int grecs_preproc_run (const char *config_file, const char *extpp);
+size_t grecs_preproc_fill_buffer(char *buf, size_t size);
+void grecs_preproc_add_include_dir(char *dir);
+int grecs_preproc_init(const char *name);
+void grecs_preproc_done(void);
+int grecs_preproc_run(const char *config_file, const char *extpp);
-FILE *grecs_preproc_extrn_start (const char *file, pid_t *ppid);
-void grecs_preproc_extrn_shutdown (pid_t pid);
+FILE *grecs_preproc_extrn_start(const char *file, pid_t *ppid);
+void grecs_preproc_extrn_shutdown(pid_t pid);
-char *grecs_install_text (const char *str);
-void grecs_destroy_text (void);
+char *grecs_install_text(const char *str);
+void grecs_destroy_text(void);
-void grecs_include_path_setup (const char *dir, ...);
-void grecs_include_path_setup_v (char **dirs);
+void grecs_include_path_setup(const char *dir, ...);
+void grecs_include_path_setup_v(char **dirs);
-const char *grecs_data_type_string (enum grecs_data_type type);
-void grecs_format_docstring (FILE *stream, const char *docstring,
+const char *grecs_data_type_string(enum grecs_data_type type);
+void grecs_format_docstring(FILE *stream, const char *docstring,
unsigned level);
-void grecs_format_simple_statement (FILE *stream, struct grecs_keyword *kwp,
+void grecs_format_simple_statement(FILE *stream, struct grecs_keyword *kwp,
unsigned level);
-void grecs_format_block_statement (FILE *stream, struct grecs_keyword *kwp,
+void grecs_format_block_statement(FILE *stream, struct grecs_keyword *kwp,
unsigned level);
-void grecs_format_statement_array (FILE *stream, struct grecs_keyword *kwp,
+void grecs_format_statement_array(FILE *stream, struct grecs_keyword *kwp,
unsigned n,
@@ -200,15 +200,15 @@ void grecs_format_statement_array (FILE *stream, struct grecs_keyword *kwp,
-struct grecs_list *grecs_list_create (void);
-size_t grecs_list_size (struct grecs_list *lp);
-void grecs_list_append (struct grecs_list *lp, void *val);
-void grecs_list_push (struct grecs_list *lp, void *val);
-void *grecs_list_pop (struct grecs_list *lp);
-void *grecs_list_locate (struct grecs_list *lp, void *data);
-void *grecs_list_index (struct grecs_list *lp, size_t idx);
-void *grecs_list_remove_tail (struct grecs_list *lp);
-void grecs_list_clear (struct grecs_list *lp);
-void grecs_list_free (struct grecs_list *lp);
+struct grecs_list *grecs_list_create(void);
+size_t grecs_list_size(struct grecs_list *lp);
+void grecs_list_append(struct grecs_list *lp, void *val);
+void grecs_list_push(struct grecs_list *lp, void *val);
+void *grecs_list_pop(struct grecs_list *lp);
+void *grecs_list_locate(struct grecs_list *lp, void *data);
+void *grecs_list_index(struct grecs_list *lp, size_t idx);
+void *grecs_list_remove_tail(struct grecs_list *lp);
+void grecs_list_clear(struct grecs_list *lp);
+void grecs_list_free(struct grecs_list *lp);
-int grecs_vasprintf (char **pbuf, size_t *psize, const char *fmt, va_list ap);
-int grecs_asprintf (char **pbuf, size_t *psize, const char *fmt, ...);
+int grecs_vasprintf(char **pbuf, size_t *psize, const char *fmt, va_list ap);
+int grecs_asprintf(char **pbuf, size_t *psize, const char *fmt, ...);
diff --git a/src/list.c b/src/list.c
index 4a5d3f6..7d7f934 100644
--- a/src/list.c
+++ b/src/list.c
@@ -25,7 +25,7 @@
struct grecs_list *
-grecs_list_create ()
+grecs_list_create()
{
- struct grecs_list *lp = grecs_malloc (sizeof (*lp));
- memset (lp, 0, sizeof (*lp));
- return lp;
+ struct grecs_list *lp = grecs_malloc(sizeof(*lp));
+ memset(lp, 0, sizeof(*lp));
+ return lp;
}
@@ -33,5 +33,5 @@ grecs_list_create ()
size_t
-grecs_list_size (struct grecs_list *lp)
+grecs_list_size(struct grecs_list *lp)
{
- return lp ? lp->count : 0;
+ return lp ? lp->count : 0;
}
@@ -39,13 +39,13 @@ grecs_list_size (struct grecs_list *lp)
void
-grecs_list_append (struct grecs_list *lp, void *val)
+grecs_list_append(struct grecs_list *lp, void *val)
{
- struct grecs_list_entry *ep = grecs_malloc (sizeof (*ep));
- ep->data = val;
- ep->next = NULL;
- if (lp->tail)
- lp->tail->next = ep;
- else
- lp->head = ep;
- lp->tail = ep;
- lp->count++;
+ struct grecs_list_entry *ep = grecs_malloc(sizeof(*ep));
+ ep->data = val;
+ ep->next = NULL;
+ if (lp->tail)
+ lp->tail->next = ep;
+ else
+ lp->head = ep;
+ lp->tail = ep;
+ lp->count++;
}
@@ -53,9 +53,9 @@ grecs_list_append (struct grecs_list *lp, void *val)
void
-grecs_list_push (struct grecs_list *lp, void *val)
+grecs_list_push(struct grecs_list *lp, void *val)
{
- struct grecs_list_entry *ep = grecs_malloc (sizeof (*ep));
- ep->data = val;
- ep->next = lp->head;
- lp->head = ep;
- lp->count++;
+ struct grecs_list_entry *ep = grecs_malloc(sizeof(*ep));
+ ep->data = val;
+ ep->next = lp->head;
+ lp->head = ep;
+ lp->count++;
}
@@ -63,18 +63,16 @@ grecs_list_push (struct grecs_list *lp, void *val)
void *
-grecs_list_pop (struct grecs_list *lp)
+grecs_list_pop(struct grecs_list *lp)
{
- void *data;
- struct grecs_list_entry *ep = lp->head;
- if (ep)
- {
- data = ep->data;
- lp->head = ep->next;
- if (!lp->head)
- lp->tail = NULL;
- lp->count--;
- free (ep);
- }
- else
- data = NULL;
- return data;
+ void *data;
+ struct grecs_list_entry *ep = lp->head;
+ if (ep) {
+ data = ep->data;
+ lp->head = ep->next;
+ if (!lp->head)
+ lp->tail = NULL;
+ lp->count--;
+ free (ep);
+ } else
+ data = NULL;
+ return data;
}
@@ -82,16 +80,15 @@ grecs_list_pop (struct grecs_list *lp)
void
-grecs_list_clear (struct grecs_list *lp)
+grecs_list_clear(struct grecs_list *lp)
{
- struct grecs_list_entry *ep = lp->head;
-
- while (ep)
- {
- struct grecs_list_entry *next = ep->next;
- if (lp->free_entry)
- lp->free_entry (ep->data);
- free (ep);
- ep = next;
- }
- lp->head = lp->tail = NULL;
- lp->count = 0;
+ struct grecs_list_entry *ep = lp->head;
+
+ while (ep) {
+ struct grecs_list_entry *next = ep->next;
+ if (lp->free_entry)
+ lp->free_entry(ep->data);
+ free(ep);
+ ep = next;
+ }
+ lp->head = lp->tail = NULL;
+ lp->count = 0;
}
@@ -99,6 +96,6 @@ grecs_list_clear (struct grecs_list *lp)
void
-grecs_list_free (struct grecs_list *lp)
+grecs_list_free(struct grecs_list *lp)
{
- grecs_list_clear (lp);
- free (lp);
+ grecs_list_clear(lp);
+ free(lp);
}
@@ -106,5 +103,5 @@ grecs_list_free (struct grecs_list *lp)
static int
-_ptrcmp (const void *a, const void *b)
+_ptrcmp(const void *a, const void *b)
{
- return a != b;
+ return a != b;
}
@@ -112,13 +109,12 @@ _ptrcmp (const void *a, const void *b)
void *
-grecs_list_locate (struct grecs_list *lp, void *data)
+grecs_list_locate(struct grecs_list *lp, void *data)
{
- struct grecs_list_entry *ep;
- int (*cmp)(const void *, const void *) = lp->cmp ? lp->cmp : _ptrcmp;
-
- for (ep = lp->head; ep; ep = ep->next)
- {
- if (cmp (ep->data, data) == 0)
- return ep->data;
- }
- return NULL;
+ struct grecs_list_entry *ep;
+ int (*cmp)(const void *, const void *) = lp->cmp ? lp->cmp : _ptrcmp;
+
+ for (ep = lp->head; ep; ep = ep->next) {
+ if (cmp(ep->data, data) == 0)
+ return ep->data;
+ }
+ return NULL;
}
@@ -126,9 +122,9 @@ grecs_list_locate (struct grecs_list *lp, void *data)
void *
-grecs_list_index (struct grecs_list *lp, size_t idx)
+grecs_list_index(struct grecs_list *lp, size_t idx)
{
- struct grecs_list_entry *ep;
-
- for (ep = lp->head; ep && idx; ep = ep->next, idx--)
- ;
- return ep ? ep->data : NULL;
+ struct grecs_list_entry *ep;
+
+ for (ep = lp->head; ep && idx; ep = ep->next, idx--)
+ ;
+ return ep ? ep->data : NULL;
}
@@ -136,26 +132,23 @@ grecs_list_index (struct grecs_list *lp, size_t idx)
void *
-grecs_list_remove_tail (struct grecs_list *lp)
+grecs_list_remove_tail(struct grecs_list *lp)
{
- void *data;
+ void *data;
- if (!lp->head)
- return NULL;
- data = lp->tail;
- if (lp->head == lp->tail)
- {
- free (lp->tail);
- lp->head = lp->tail = NULL;
- lp->count = 0;
- }
- else
- {
- struct grecs_list_entry *ep;
+ if (!lp->head)
+ return NULL;
+ data = lp->tail;
+ if (lp->head == lp->tail) {
+ free(lp->tail);
+ lp->head = lp->tail = NULL;
+ lp->count = 0;
+ } else {
+ struct grecs_list_entry *ep;
- for (ep = lp->head; ep->next != lp->tail; ep = ep->next)
- ;
- free (lp->tail);
- ep->next = NULL;
- lp->tail = ep;
- }
- return data;
+ for (ep = lp->head; ep->next != lp->tail; ep = ep->next)
+ ;
+ free(lp->tail);
+ ep->next = NULL;
+ lp->tail = ep;
+ }
+ return data;
}
diff --git a/src/preproc.c b/src/preproc.c
index 7ea9442..06924c1 100644
--- a/src/preproc.c
+++ b/src/preproc.c
@@ -36,16 +36,14 @@ void (*grecs_log_setup_hook) () = NULL;
-struct input_file_ident
-{
- ino_t i_node;
- dev_t device;
+struct input_file_ident {
+ ino_t i_node;
+ dev_t device;
};
-struct buffer_ctx
-{
- struct buffer_ctx *prev; /* Pointer to previous context */
- grecs_locus_t locus; /* Current input location */
- size_t namelen; /* Length of the file name */
- size_t xlines; /* Number of #line directives output so far */
- struct input_file_ident id;
- FILE *infile;
+struct buffer_ctx {
+ struct buffer_ctx *prev; /* Pointer to previous context */
+ grecs_locus_t locus; /* Current input location */
+ size_t namelen; /* Length of the file name */
+ size_t xlines; /* Number of #line directives output so far */
+ struct input_file_ident id;
+ FILE *infile;
};
@@ -71,59 +69,49 @@ static int parse_include (const char *text, int once);
static ssize_t
-pp_getline (char **pbuf, size_t *psize, FILE *fp)
+pp_getline(char **pbuf, size_t *psize, FILE *fp)
{
- char *buf = *pbuf;
- size_t size = *psize;
- ssize_t off = 0;
+ char *buf = *pbuf;
+ size_t size = *psize;
+ ssize_t off = 0;
- do
- {
- size_t len;
-
- if (off == size - 1)
- {
- if (!buf)
- {
- size = 1;
- buf = grecs_malloc (size);
- }
- else
- {
- size_t nsize = 2 * size;
- if (nsize < size)
- grecs_alloc_die ();
- buf = grecs_realloc (buf, nsize);
- size = nsize;
- }
- }
- if (!fgets (buf + off, size - off, fp))
- {
- if (off == 0)
- off = -1;
- break;
+ do {
+ if (off == size - 1) {
+ if (!buf) {
+ size = 1;
+ buf = grecs_malloc(size);
+ } else {
+ size_t nsize = 2 * size;
+ if (nsize < size)
+ grecs_alloc_die();
+ buf = grecs_realloc(buf, nsize);
+ size = nsize;
+ }
+ }
+ if (!fgets(buf + off, size - off, fp)) {
+ if (off == 0)
+ off = -1;
+ break;
+ }
+ off += strlen(buf + off);
}
- off += strlen (buf + off);
- }
- while (buf[off - 1] != '\n');
+ while (buf[off - 1] != '\n');
- *pbuf = buf;
- *psize = size;
- return off;
+ *pbuf = buf;
+ *psize = size;
+ return off;
}
-
static void
-putback (const char *str)
+putback(const char *str)
{
- size_t len;
-
- if (!*str)
- return;
- len = strlen (str) + 1;
- if (len > putback_max)
- {
- putback_max = len;
- putback_buffer = grecs_realloc (putback_buffer, putback_max);
- }
- strcpy (putback_buffer, str);
- putback_size = len - 1;
+ size_t len;
+
+ if (!*str)
+ return;
+ len = strlen(str) + 1;
+ if (len > putback_max) {
+ putback_max = len;
+ putback_buffer = grecs_realloc(putback_buffer, putback_max);
+ }
+ strcpy(putback_buffer, str);
+ putback_size = len - 1;
}
@@ -131,28 +119,28 @@ putback (const char *str)
static void
-pp_line_stmt ()
+pp_line_stmt()
{
- size_t ls_size;
- size_t pb_size;
-
- if (grecs_asprintf (&linebufbase, &linebufsize, "#line %lu \"%s\" %lu\n",
- (unsigned long) LOCUS.line,
- LOCUS.file, (unsigned long) context_stack->xlines))
- grecs_alloc_die ();
-
- ls_size = strlen (linebufbase);
- pb_size = putback_size + ls_size + 1;
-
- if (pb_size > putback_max)
- {
- putback_max = pb_size;
- putback_buffer = grecs_realloc (putback_buffer, putback_max);
- }
-
- context_stack->xlines++;
- strcpy (putback_buffer + putback_size, linebufbase);
- putback_size += ls_size;
+ size_t ls_size;
+ size_t pb_size;
+
+ if (grecs_asprintf(&linebufbase, &linebufsize,
+ "#line %lu \"%s\" %lu\n",
+ (unsigned long) LOCUS.line,
+ LOCUS.file, (unsigned long) context_stack->xlines))
+ grecs_alloc_die();
+
+ ls_size = strlen(linebufbase);
+ pb_size = putback_size + ls_size + 1;
+
+ if (pb_size > putback_max) {
+ putback_max = pb_size;
+ putback_buffer = grecs_realloc(putback_buffer, putback_max);
+ }
+
+ context_stack->xlines++;
+ strcpy(putback_buffer + putback_size, linebufbase);
+ putback_size += ls_size;
}
-#define STRMATCH(p, len, s) (len >= sizeof(s) \
- && memcmp (p, s, sizeof(s) - 1) == 0 \
+#define STRMATCH(p, len, s) (len >= sizeof(s) \
+ && memcmp(p, s, sizeof(s) - 1) == 0 \
&& isspace(p[sizeof(s) - 1]))
@@ -160,26 +148,22 @@ pp_line_stmt ()
static int
-next_line ()
+next_line()
{
- ssize_t rc;
-
- do
- {
- if (putback_size)
- {
- if (putback_size + 1 > bufsize)
- {
- bufsize = putback_size + 1;
- linebuf = grecs_realloc (linebuf, bufsize);
- }
- strcpy (linebuf, putback_buffer);
- rc = putback_size;
- putback_size = 0;
- }
- else if (!context_stack)
- return 0;
- else
- rc = pp_getline (&linebuf, &bufsize, INFILE);
- }
- while (rc == -1 && pop_source () == 0);
- return rc;
+ ssize_t rc;
+
+ do {
+ if (putback_size) {
+ if (putback_size + 1 > bufsize) {
+ bufsize = putback_size + 1;
+ linebuf = grecs_realloc(linebuf, bufsize);
+ }
+ strcpy(linebuf, putback_buffer);
+ rc = putback_size;
+ putback_size = 0;
+ }
+ else if (!context_stack)
+ return 0;
+ else
+ rc = pp_getline(&linebuf, &bufsize, INFILE);
+ } while (rc == -1 && pop_source() == 0);
+ return rc;
}
@@ -187,55 +171,48 @@ next_line ()
size_t
-grecs_preproc_fill_buffer (char *buf, size_t size)
+grecs_preproc_fill_buffer(char *buf, size_t size)
{
- size_t bufsize = size;
-
- while (next_line () > 0)
- {
- char *p;
- size_t len;
- int is_line = 0;
-
- for (p = linebuf; *p && isspace (*p); p++)
- ;
- if (*p == '#')
- {
- size_t l;
- for (p++; *p && isspace (*p); p++)
- ;
- l = strlen (p);
- if (STRMATCH (p, l, "include_once"))
- {
- if (parse_include (linebuf, 1))
- putback ("/*include_once*/\n");
- continue;
- }
- else if (STRMATCH (p, l, "include"))
- {
- if (parse_include (linebuf, 0))
- putback ("/*include*/\n");
- continue;
- }
- else if (STRMATCH (p, l, "line"))
- is_line = 1;
- }
-
- len = strlen (linebuf);
-
- if (len > size)
- len = size;
+ size_t bufsize = size;
+
+ while (next_line() > 0) {
+ char *p;
+ size_t len;
+ int is_line = 0;
+
+ for (p = linebuf; *p && isspace(*p); p++)
+ ;
+ if (*p == '#') {
+ size_t l;
+ for (p++; *p && isspace(*p); p++)
+ ;
+ l = strlen(p);
+ if (STRMATCH(p, l, "include_once")) {
+ if (parse_include(linebuf, 1))
+ putback("/*include_once*/\n");
+ continue;
+ } else if (STRMATCH(p, l, "include")) {
+ if (parse_include(linebuf, 0))
+ putback("/*include*/\n");
+ continue;
+ } else if (STRMATCH(p, l, "line"))
+ is_line = 1;
+ }
- memcpy (buf, linebuf, len);
- buf += len;
- size -= len;
+ len = strlen(linebuf);
+
+ if (len > size)
+ len = size;
+
+ memcpy(buf, linebuf, len);
+ buf += len;
+ size -= len;
+
+ if (size == 0) {
+ putback(linebuf + len);
+ break;
+ }
- if (size == 0)
- {
- putback (linebuf + len);
- break;
+ if (!is_line && len > 0 && linebuf[len - 1] == '\n')
+ LOCUS.line++;
}
-
- if (!is_line && len > 0 && linebuf[len - 1] == '\n')
- LOCUS.line++;
- }
- return bufsize - size;
+ return bufsize - size;
}
@@ -246,13 +223,13 @@ grecs_preproc_fill_buffer (char *buf, size_t size)
static struct buffer_ctx *
-ctx_lookup (struct stat *st)
+ctx_lookup(struct stat *st)
{
- struct buffer_ctx *ctx;
+ struct buffer_ctx *ctx;
- if (!context_stack)
- return NULL;
+ if (!context_stack)
+ return NULL;
- for (ctx = context_stack->prev; ctx; ctx = ctx->prev)
- if (STAT_ID_EQ (*st, ctx->id))
- break;
- return ctx;
+ for (ctx = context_stack->prev; ctx; ctx = ctx->prev)
+ if (STAT_ID_EQ(*st, ctx->id))
+ break;
+ return ctx;
}
@@ -263,9 +240,8 @@ static struct grecs_list *std_include_path;
-struct file_data
-{
- const char *name;
- size_t namelen;
- char *buf;
- size_t buflen;
- int found;
+struct file_data {
+ const char *name;
+ size_t namelen;
+ char *buf;
+ size_t buflen;
+ int found;
};
@@ -273,21 +249,25 @@ struct file_data
static int
-pp_list_find (struct grecs_list *list, struct file_data *dptr)
+pp_list_find(struct grecs_list *list, struct file_data *dptr)
{
- struct grecs_list_entry *ep;
-
- for (ep = list->head; !dptr->found && ep; ep = ep->next)
- {
- const char *dir = ep->data;
- size_t size = strlen (dir) + 1 + dptr->namelen + 1;
- if (size > dptr->buflen)
- {
- dptr->buflen = size;
- dptr->buf = grecs_realloc (dptr->buf, dptr->buflen);
+ struct grecs_list_entry *ep;
+
+ for (ep = list->head; !dptr->found && ep; ep = ep->next) {
+ const char *dir = ep->data;
+ size_t size = strlen (dir) + 1 + dptr->namelen + 1;
+ if (size > dptr->buflen) {
+ dptr->buflen = size;
+ dptr->buf = grecs_realloc(dptr->buf, dptr->buflen);
+ }
+ strcpy(dptr->buf, dir);
+ strcat(dptr->buf, "/");
+ strcat(dptr->buf, dptr->name);
+ dptr->found = access(dptr->buf, F_OK) == 0;
}
- strcpy (dptr->buf, dir);
- strcat (dptr->buf, "/");
- strcat (dptr->buf, dptr->name);
- dptr->found = access (dptr->buf, F_OK) == 0;
- }
- return dptr->found;
+ return dptr->found;
+}
+
+static void
+incl_free(void *data)
+{
+ free(data);
}
@@ -295,14 +275,17 @@ pp_list_find (struct grecs_list *list, struct file_data *dptr)
void
-grecs_include_path_setup_v (char **dirs)
+grecs_include_path_setup_v(char **dirs)
{
- if (!include_path)
- include_path = grecs_list_create ();
- std_include_path = grecs_list_create ();
- if (dirs)
- {
- int i;
- for (i = 0; dirs[i]; i++)
- /* FIXME: Element never freed */
- grecs_list_append (std_include_path, grecs_strdup (dirs[i]));
- }
+ if (!include_path) {
+ include_path = grecs_list_create();
+ include_path->free_entry = incl_free;
+ }
+ std_include_path = grecs_list_create();
+ std_include_path->free_entry = incl_free;
+ if (dirs) {
+ int i;
+ for (i = 0; dirs[i]; i++)
+ /* FIXME: Element never freed */
+ grecs_list_append(std_include_path,
+ grecs_strdup(dirs[i]));
+ }
}
@@ -310,30 +293,28 @@ grecs_include_path_setup_v (char **dirs)
void
-grecs_include_path_setup (const char *dir, ...)
+grecs_include_path_setup(const char *dir, ...)
{
- const char *p;
- char **argv = NULL;
- size_t argc = 0;
- size_t argi = 0;
- va_list ap;
-
- va_start (ap, dir);
- p = dir;
- while (1)
- {
- if (argi == argc)
- {
- if (argc == 0)
- argc = 16;
- else
- argc += 16;
- argv = grecs_realloc (argv, argc * sizeof (argv[0]));
+ const char *p;
+ char **argv = NULL;
+ size_t argc = 0;
+ size_t argi = 0;
+ va_list ap;
+
+ va_start(ap, dir);
+ p = dir;
+ while (1) {
+ if (argi == argc) {
+ if (argc == 0)
+ argc = 16;
+ else
+ argc += 16;
+ argv = grecs_realloc(argv, argc * sizeof(argv[0]));
+ }
+ argv[argi++] = (char*) p;
+ if (!p)
+ break;
+ p = va_arg(ap, const char*);
}
- argv[argi++] = (char*) p;
- if (!p)
- break;
- p = va_arg (ap, const char*);
- }
- grecs_include_path_setup_v (argv);
- free (argv);
- va_end (ap);
+ grecs_include_path_setup_v(argv);
+ free(argv);
+ va_end(ap);
}
@@ -341,7 +322,9 @@ grecs_include_path_setup (const char *dir, ...)
void
-grecs_preproc_add_include_dir (char *dir)
+grecs_preproc_add_include_dir(char *dir)
{
- if (!include_path)
- include_path = grecs_list_create ();
- grecs_list_append (include_path, dir);
+ if (!include_path) {
+ include_path = grecs_list_create();
+ include_path->free_entry = incl_free;
+ }
+ grecs_list_append(include_path, grecs_strdup(dir));
}
@@ -352,6 +335,6 @@ static struct grecs_symtab *incl_sources;
static unsigned
-incl_hasher (void *data, unsigned long n_buckets)
+incl_hasher(void *data, unsigned long n_buckets)
{
- const struct input_file_ident *id = data;
- return (id->i_node + id->device) % n_buckets;
+ const struct input_file_ident *id = data;
+ return (id->i_node + id->device) % n_buckets;
}
@@ -360,13 +343,7 @@ incl_hasher (void *data, unsigned long n_buckets)
static int
-incl_compare (void const *data1, void const *data2)
+incl_compare(void const *data1, void const *data2)
{
- const struct input_file_ident *id1 = data1;
- const struct input_file_ident *id2 = data2;
- return !(id1->device == id2->device && id1->i_node == id2->i_node);
-}
-
-static void
-incl_free (void *data)
-{
- free (data);
+ const struct input_file_ident *id1 = data1;
+ const struct input_file_ident *id2 = data2;
+ return !(id1->device == id2->device && id1->i_node == id2->i_node);
}
@@ -374,24 +351,24 @@ incl_free (void *data)
static int
-source_lookup (struct stat *st)
+source_lookup(struct stat *st)
{
- struct input_file_ident key;
- int install = 1;
-
- if (!incl_sources)
- {
- incl_sources = grecs_symtab_create(sizeof (struct input_file_ident),
- incl_hasher,
- incl_compare,
- NULL,
- NULL,/*FIXME: alloc*/
- NULL);
- if (!incl_sources)
- grecs_alloc_die ();
- }
+ struct input_file_ident key;
+ int install = 1;
- key.i_node = st->st_ino;
- key.device = st->st_dev;
- if (!grecs_symtab_lookup_or_install(incl_sources, &key, &install))
- grecs_alloc_die ();
- return !install;
+ if (!incl_sources) {
+ incl_sources = grecs_symtab_create(
+ sizeof(struct input_file_ident),
+ incl_hasher,
+ incl_compare,
+ NULL,
+ NULL,/*FIXME: alloc*/
+ NULL);
+ if (!incl_sources)
+ grecs_alloc_die();
+ }
+
+ key.i_node = st->st_ino;
+ key.device = st->st_dev;
+ if (!grecs_symtab_lookup_or_install(incl_sources, &key, &install))
+ grecs_alloc_die();
+ return !install;
}
@@ -400,102 +377,97 @@ source_lookup (struct stat *st)
static int
-push_source (const char *name, int once)
+push_source(const char *name, int once)
{
- FILE *fp;
- struct buffer_ctx *ctx;
- struct stat st;
- int rc = stat (name, &st);
-
- if (context_stack)
- {
- if (rc)
- {
- grecs_error (&LOCUS, errno, _("Cannot stat `%s'"), name);
- return 1;
- }
+ FILE *fp;
+ struct buffer_ctx *ctx;
+ struct stat st;
+ int rc = stat(name, &st);
+
+ if (context_stack) {
+ if (rc) {
+ grecs_error(&LOCUS, errno,
+ _("Cannot stat `%s'"), name);
+ return 1;
+ }
- if (LOCUS.file && STAT_ID_EQ (st, context_stack->id))
- {
- grecs_error (&LOCUS, 0, _("Recursive inclusion"));
- return 1;
+ if (LOCUS.file && STAT_ID_EQ(st, context_stack->id)) {
+ grecs_error(&LOCUS, 0, _("Recursive inclusion"));
+ return 1;
+ }
+
+ if ((ctx = ctx_lookup(&st))) {
+ grecs_error(&LOCUS, 0, _("Recursive inclusion"));
+ if (ctx->prev)
+ grecs_error(&ctx->prev->locus, 0,
+ _("`%s' already included here"),
+ name);
+ else
+ grecs_error(&LOCUS, 0,
+ _("`%s' already included at top level"),
+ name);
+ return 1;
+ }
+ } else if (rc) {
+ grecs_error(NULL, errno, _("Cannot stat `%s'"), name);
+ return 1;
}
- if ((ctx = ctx_lookup (&st)))
- {
- grecs_error (&LOCUS, 0, _("Recursive inclusion"));
- if (ctx->prev)
- grecs_error (&ctx->prev->locus, 0,
- _("`%s' already included here"), name);
- else
- grecs_error (&LOCUS, 0,
- _("`%s' already included at top level"), name);
- return 1;
+ if (once && source_lookup(&st))
+ return -1;
+
+ fp = fopen(name, "r");
+ if (!fp) {
+ grecs_error(&LOCUS, errno, _("Cannot open `%s'"), name);
+ return 1;
}
- }
- else if (rc)
- {
- grecs_error (NULL, errno, _("Cannot stat `%s'"), name);
- return 1;
- }
-
- if (once && source_lookup (&st))
- return -1;
-
- fp = fopen (name, "r");
- if (!fp)
- {
- grecs_error (&LOCUS, errno, _("Cannot open `%s'"), name);
- return 1;
- }
-
- /* Push current context */
- ctx = grecs_malloc (sizeof (*ctx));
- ctx->locus.file = grecs_install_text (name);
- ctx->locus.line = 1;
- ctx->xlines = 0;
- ctx->namelen = strlen (ctx->locus.file);
- ctx->id.i_node = st.st_ino;
- ctx->id.device = st.st_dev;
- ctx->infile = fp;
- ctx->prev = context_stack;
- context_stack = ctx;
-
- if (yy_grecs_flex_debug)
- fprintf (stderr, "Processing file `%s'\n", name);
-
- pp_line_stmt ();
-
- return 0;
-}
-static int
-pop_source ()
-{
- struct buffer_ctx *ctx;
+ /* Push current context */
+ ctx = grecs_malloc(sizeof(*ctx));
+ ctx->locus.file = grecs_install_text(name);
+ ctx->locus.line = 1;
+ ctx->xlines = 0;
+ ctx->namelen = strlen(ctx->locus.file);
+ ctx->id.i_node = st.st_ino;
+ ctx->id.device = st.st_dev;
+ ctx->infile = fp;
+ ctx->prev = context_stack;
+ context_stack = ctx;
- if (!context_stack)
- return 1;
+ if (yy_grecs_flex_debug)
+ fprintf (stderr, "Processing file `%s'\n", name);
- fclose (INFILE);
+ pp_line_stmt();
- /* Restore previous context */
- ctx = context_stack->prev;
- free (context_stack);
- context_stack = ctx;
+ return 0;
+}
- if (!context_stack)
- {
- if (yy_grecs_flex_debug)
- fprintf (stderr, "End of input\n");
- return 1;
- }
+static int
+pop_source()
+{
+ struct buffer_ctx *ctx;
+
+ if (!context_stack)
+ return 1;
+
+ fclose(INFILE);
+
+ /* Restore previous context */
+ ctx = context_stack->prev;
+ free(context_stack);
+ context_stack = ctx;
+
+ if (!context_stack) {
+ if (yy_grecs_flex_debug)
+ fprintf (stderr, "End of input\n");
+ return 1;
+ }
- LOCUS.line++;
+ LOCUS.line++;
- if (yy_grecs_flex_debug)
- fprintf (stderr, "Resuming file `%s' at line %lu\n",
- LOCUS.file, (unsigned long) LOCUS.line);
+ if (yy_grecs_flex_debug)
+ fprintf (stderr, "Resuming file `%s' at line %lu\n",
+ LOCUS.file, (unsigned long) LOCUS.line);
- pp_line_stmt ();
+ pp_line_stmt();
- return 0;
+ return 0;
}
@@ -503,37 +475,34 @@ pop_source ()
static int
-try_file (const char *name, int allow_cwd, int err_not_found, char **newp)
+try_file(const char *name, int allow_cwd, int err_not_found, char **newp)
{
- static char *cwd = ".";
- struct file_data fd;
-
- fd.name = name;
- fd.namelen = strlen (name);
- fd.buf = NULL;
- fd.buflen = 0;
- fd.found = 0;
-
- if (!include_path)
- grecs_include_path_setup (NULL);
- if (allow_cwd)
- {
- grecs_list_append (include_path, cwd);
- pp_list_find (include_path, &fd);
- grecs_list_remove_tail (include_path);
- }
- else
- pp_list_find (include_path, &fd);
-
- if (!fd.found)
- {
- pp_list_find (std_include_path, &fd);
-
- if (!fd.found && err_not_found)
- {
- grecs_error (&LOCUS, 0, _("%s: No such file or directory"), name);
- *newp = NULL;
+ static char *cwd = ".";
+ struct file_data fd;
+
+ fd.name = name;
+ fd.namelen = strlen(name);
+ fd.buf = NULL;
+ fd.buflen = 0;
+ fd.found = 0;
+
+ if (!include_path)
+ grecs_include_path_setup(NULL);
+ if (allow_cwd) {
+ grecs_list_append(include_path, cwd);
+ pp_list_find(include_path, &fd);
+ grecs_list_remove_tail(include_path);
+ } else
+ pp_list_find(include_path, &fd);
+
+ if (!fd.found) {
+ pp_list_find(std_include_path, &fd);
+
+ if (!fd.found && err_not_found) {
+ grecs_error(&LOCUS, 0,
+ _("%s: No such file or directory"), name);
+ *newp = NULL;
+ }
}
- }
- if (fd.found)
- *newp = fd.buf;
- return fd.found;
+ if (fd.found)
+ *newp = fd.buf;
+ return fd.found;
}
@@ -541,42 +510,38 @@ try_file (const char *name, int allow_cwd, int err_not_found, char **newp)
static int
-parse_include (const char *text, int once)
+parse_include(const char *text, int once)
{
- struct wordsplit ws;
- char *tmp = NULL;
- char *p = NULL;
- int rc = 1;
-
- if (wordsplit (text, &ws, WRDSF_DEFFLAGS))
- grecs_error (&LOCUS, 0, _("Cannot parse include line"));
- else if (ws.ws_wordc != 2)
- {
- wordsplit_free (&ws);
- grecs_error (&LOCUS, 0, _("invalid include statement"));
- }
- else
- {
- size_t len;
- int allow_cwd;
-
- p = ws.ws_wordv[1];
- len = strlen (p);
-
- if (p[0] == '<' && p[len - 1] == '>')
- {
- allow_cwd = 0;
- p[len - 1] = 0;
- p++;
+ struct wordsplit ws;
+ char *tmp = NULL;
+ char *p = NULL;
+ int rc = 1;
+
+ if (wordsplit(text, &ws, WRDSF_DEFFLAGS))
+ grecs_error(&LOCUS, 0, _("Cannot parse include line"));
+ else if (ws.ws_wordc != 2) {
+ wordsplit_free(&ws);
+ grecs_error(&LOCUS, 0, _("invalid include statement"));
+ } else {
+ size_t len;
+ int allow_cwd;
+
+ p = ws.ws_wordv[1];
+ len = strlen (p);
+
+ if (p[0] == '<' && p[len - 1] == '>') {
+ allow_cwd = 0;
+ p[len - 1] = 0;
+ p++;
+ }
+ else
+ allow_cwd = 1;
+
+ if (p[0] != '/' && try_file(p, allow_cwd, 1, &tmp))
+ p = tmp;
}
- else
- allow_cwd = 1;
-
- if (p[0] != '/' && try_file (p, allow_cwd, 1, &tmp))
- p = tmp;
- }
- if (p)
- rc = push_source (p, once);
- free (tmp);
- wordsplit_free (&ws);
- return rc;
+ if (p)
+ rc = push_source(p, once);
+ free(tmp);
+ wordsplit_free(&ws);
+ return rc;
}
@@ -584,5 +549,5 @@ parse_include (const char *text, int once)
int
-grecs_preproc_init (const char *name)
+grecs_preproc_init(const char *name)
{
- return push_source (name, 0);
+ return push_source(name, 0);
}
@@ -590,8 +555,8 @@ grecs_preproc_init (const char *name)
void
-grecs_preproc_done ()
+grecs_preproc_done()
{
- grecs_symtab_free (incl_sources);
- free (linebuf);
- free (putback_buffer);
- free (linebufbase);
+ grecs_symtab_free(incl_sources);
+ free(linebuf);
+ free(putback_buffer);
+ free(linebufbase);
}
@@ -599,44 +564,42 @@ grecs_preproc_done ()
int
-grecs_preproc_run (const char *config_file, const char *extpp)
+grecs_preproc_run(const char *config_file, const char *extpp)
{
- size_t i;
- char buffer[512];
-
- if (grecs_preproc_init (config_file))
- return 1;
- if (extpp)
- {
- FILE *outfile;
- char *setup_file;
- char *cmd;
-
- if (try_file ("pp-setup", 1, 0, &setup_file))
- {
- asprintf (&cmd, "%s %s -", extpp, setup_file);
- free (setup_file);
- }
- else
- cmd = grecs_strdup (extpp);
- /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", cmd);*/
- outfile = popen (cmd, "w");
- if (!outfile)
- {
- grecs_error (NULL, errno,
- _("Unable to start external preprocessor `%s'"), cmd);
- free (cmd);
- return 1;
- }
+ size_t i;
+ char buffer[512];
+
+ if (grecs_preproc_init(config_file))
+ return 1;
+ if (extpp) {
+ FILE *outfile;
+ char *setup_file;
+ char *cmd = NULL;
+
+ if (try_file("pp-setup", 1, 0, &setup_file)) {
+ size_t size = 0;
+ if (grecs_asprintf(&cmd, &size,
+ "%s %s -", extpp, setup_file))
+ grecs_alloc_die();
+ free(setup_file);
+ } else
+ cmd = grecs_strdup (extpp);
+ /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", cmd);*/
+ outfile = popen(cmd, "w");
+ if (!outfile){
+ grecs_error(NULL, errno,
+ _("Unable to start external preprocessor `%s'"),
+ cmd);
+ free(cmd);
+ return 1;
+ }
- while ((i = grecs_preproc_fill_buffer (buffer, sizeof buffer)))
- fwrite (buffer, 1, i, outfile);
- pclose (outfile);
- free (cmd);
- }
- else
- {
- while ((i = grecs_preproc_fill_buffer (buffer, sizeof buffer)))
- fwrite (buffer, 1, i, stdout);
- }
- grecs_preproc_done ();
- return 0;
+ while ((i = grecs_preproc_fill_buffer(buffer, sizeof buffer)))
+ fwrite(buffer, 1, i, outfile);
+ pclose(outfile);
+ free(cmd);
+ } else {
+ while ((i = grecs_preproc_fill_buffer(buffer, sizeof buffer)))
+ fwrite(buffer, 1, i, stdout);
+ }
+ grecs_preproc_done();
+ return 0;
}
@@ -644,86 +607,81 @@ grecs_preproc_run (const char *config_file, const char *extpp)
FILE *
-grecs_preproc_extrn_start (const char *file_name, pid_t *ppid)
+grecs_preproc_extrn_start(const char *file_name, pid_t *ppid)
{
- int pout[2];
- pid_t pid;
- int i;
- FILE *fp = NULL;
-
- /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", ppcmd);*/
-
- pipe (pout);
- switch (pid = fork ())
- {
- /* The child branch. */
- case 0:
- if (pout[1] != 1)
- {
- close (1);
- dup2 (pout[1], 1);
- }
+ int pout[2];
+ pid_t pid;
+ int i;
+ FILE *fp = NULL;
+
+ /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", ppcmd);*/
+
+ pipe(pout);
+ switch (pid = fork()) {
+ /* The child branch. */
+ case 0:
+ if (pout[1] != 1) {
+ close(1);
+ dup2(pout[1], 1);
+ }
- /* Close unneeded descripitors */
- for (i = getdtablesize (); i > 2; i--)
- close (i);
+ /* Close unneeded descripitors */
+ for (i = getdtablesize(); i > 2; i--)
+ close(i);
- if (!grecs_log_to_stderr)
- {
- int p[2];
- char *buf = NULL;
- size_t size = 0;
- FILE *fp;
+ if (!grecs_log_to_stderr) {
+ int p[2];
+ char *buf = NULL;
+ size_t size = 0;
+ FILE *fp;
- signal (SIGCHLD, SIG_DFL);
- pipe (p);
- switch (pid = fork ())
- {
- /* Grandchild */
- case 0:
- if (p[1] != 2)
- {
- close (2);
- dup2 (p[1], 2);
+ signal(SIGCHLD, SIG_DFL);
+ pipe(p);
+ switch (pid = fork()) {
+ /* Grandchild */
+ case 0:
+ if (p[1] != 2) {
+ close(2);
+ dup2(p[1], 2);
+ }
+ close(p[0]);
+
+ if (grecs_preproc_run(file_name,
+ grecs_preprocessor))
+ exit(127);
+ exit(0);
+
+ case -1:
+ /* Fork failed */
+ if (grecs_log_setup_hook)
+ grecs_log_setup_hook();
+ grecs_error(NULL, errno, _("Cannot run `%s'"),
+ grecs_preprocessor);
+ exit(127);
+
+ default:
+ /* Sub-master */
+ close (p[1]);
+ fp = fdopen(p[0], "r");
+ if (grecs_log_setup_hook)
+ grecs_log_setup_hook();
+ while (pp_getline(&buf, &size, fp) > 0)
+ grecs_error(NULL, 0, "%s", buf);
+ }
+ } else {
+ grecs_preproc_run(file_name, grecs_preprocessor);
}
- close (p[0]);
-
- if (grecs_preproc_run (file_name, grecs_preprocessor))
- exit (127);
- exit (0);
-
- case -1:
- /* Fork failed */
- if (grecs_log_setup_hook)
- grecs_log_setup_hook ();
- grecs_error (NULL, errno, _("Cannot run `%s'"),
- grecs_preprocessor);
- exit (127);
-
- default:
- /* Sub-master */
- close (p[1]);
- fp = fdopen (p[0], "r");
- if (grecs_log_setup_hook)
- grecs_log_setup_hook ();
- while (pp_getline (&buf, &size, fp) > 0)
- grecs_error (NULL, 0, "%s", buf);
- }
- }
- else
- {
- grecs_preproc_run (file_name, grecs_preprocessor);
+ exit (0);
+
+ case -1:
+ /* Fork failed */
+ grecs_error(NULL, errno, _("Cannot run `%s'"),
+ grecs_preprocessor);
+ break;
+
+ default:
+ close(pout[1]);
+ fp = fdopen(pout[0], "r");
+ break;
}
- exit (0);
-
- case -1:
- /* Fork failed */
- grecs_error (NULL, errno, _("Cannot run `%s'"), grecs_preprocessor);
- break;
-
- default:
- close (pout[1]);
- fp = fdopen (pout[0], "r");
- break;
- }
- *ppid = pid;
- return fp;
+ *ppid = pid;
+ return fp;
}
@@ -731,6 +689,6 @@ grecs_preproc_extrn_start (const char *file_name, pid_t *ppid)
void
-grecs_preproc_extrn_shutdown (pid_t pid)
+grecs_preproc_extrn_shutdown(pid_t pid)
{
- int status;
- waitpid (pid, &status, 0);
+ int status;
+ waitpid(pid, &status, 0);
}
diff --git a/src/text.c b/src/text.c
index 6b8b905..ecb694b 100644
--- a/src/text.c
+++ b/src/text.c
@@ -26,20 +26,20 @@ static struct grecs_symtab *text_table;
char *
-grecs_install_text (const char *str)
+grecs_install_text(const char *str)
{
- struct grecs_syment key;
- struct grecs_syment *ent;
- int install = 1;
-
- if (!text_table)
- {
- text_table = grecs_symtab_create_default(sizeof(struct grecs_syment));
- if (!text_table)
- grecs_alloc_die ();
- }
+ struct grecs_syment key;
+ struct grecs_syment *ent;
+ int install = 1;
+
+ if (!text_table) {
+ text_table = grecs_symtab_create_default(
+ sizeof(struct grecs_syment));
+ if (!text_table)
+ grecs_alloc_die();
+ }
- key.name = (char*) str;
- ent = grecs_symtab_lookup_or_install (text_table, &key, &install);
- if (!ent)
- grecs_alloc_die ();
- return ent->name;
+ key.name = (char*) str;
+ ent = grecs_symtab_lookup_or_install(text_table, &key, &install);
+ if (!ent)
+ grecs_alloc_die();
+ return ent->name;
}
@@ -47,5 +47,5 @@ grecs_install_text (const char *str)
void
-grecs_destroy_text ()
+grecs_destroy_text()
{
- grecs_symtab_free (text_table);
+ grecs_symtab_free(text_table);
}

Return to:

Send suggestions and report system problems to the System administrator.