aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-01 21:13:32 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-03 21:23:16 +0300
commit24ec67c9f6375d34d88e79981ed8abbe15a78169 (patch)
tree6e68b1b409b10b48581422df05cfac9caedb0af2
parentda56e338d346e358de864d18ca42f574305d8dfc (diff)
downloadgrecs-24ec67c9f6375d34d88e79981ed8abbe15a78169.tar.gz
grecs-24ec67c9f6375d34d88e79981ed8abbe15a78169.tar.bz2
Reindent all, except wordsplit, which is shared with MU.
-rw-r--r--src/Makefile.am2
-rw-r--r--src/format.c39
-rw-r--r--src/grecs-gram.y172
-rw-r--r--src/grecs-lex.l113
-rw-r--r--src/grecs.h0
-rw-r--r--src/list.c19
-rw-r--r--src/preproc.c222
-rw-r--r--src/text.c6
8 files changed, 228 insertions, 345 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2f35f52..759716b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,7 +32,7 @@ EXTRA_DIST=grecs-gram.h $(PP_SETUP_FILE)
INCLUDES = -I$(srcdir) @GRECS_INCLUDES@
AM_YFLAGS = -dtv
-AM_LFLAGS = -dvp
+AM_LFLAGS = -d
# Use a modified ylwrap implementation that understands the --prefix option.
YLWRAP = $(top_srcdir)/$(grex_topdir)grecs/build-aux/ylwrap --prefix yy_grecs
diff --git a/src/format.c b/src/format.c
index a1aa67d..fc6c8d6 100644
--- a/src/format.c
+++ b/src/format.c
@@ -26,8 +26,7 @@
const char *
grecs_data_type_string (enum grecs_data_type type)
{
- switch (type)
- {
+ switch (type) {
case grecs_type_void:
return "void";
@@ -81,21 +80,18 @@ grecs_format_docstring (FILE *stream, const char *docstring, unsigned level)
size_t len = strlen(docstring);
int width = 78 - level * 2;
- if (width < 0)
- {
+ if (width < 0) {
width = 78;
level = 0;
}
- while (len)
- {
+ while (len) {
size_t seglen;
const char *p;
- for (seglen = 0, p = docstring; p < docstring + width && *p; p++)
- {
- if (*p == '\n')
- {
+ for (seglen = 0, p = docstring; p < docstring + width && *p;
+ p++) {
+ if (*p == '\n') {
seglen = p - docstring;
break;
}
@@ -111,14 +107,11 @@ grecs_format_docstring (FILE *stream, const char *docstring, unsigned level)
fputc('\n', stream);
len -= seglen;
docstring += seglen;
- if (*docstring == '\n')
- {
+ if (*docstring == '\n') {
docstring++;
len--;
- }
- else
- while (*docstring && isspace (*docstring))
- {
+ } else
+ while (*docstring && isspace(*docstring)) {
docstring++;
len--;
}
@@ -144,14 +137,15 @@ grecs_format_simple_statement (FILE *stream, struct grecs_keyword *kwp,
fprintf(stream, "%s %s;\n", kwp->ident, gettext(argstr));
else if (strchr (argstr, ':'))
fprintf (stream, "%s <%s>;\n", kwp->ident, gettext(argstr));
- else
- {
+ 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))));
+ gettext(grecs_data_type_string(
+ GRECS_TYPE (kwp->type))));
else
- fprintf (stream, "%s", gettext (grecs_data_type_string (kwp->type)));
+ fprintf(stream, "%s",
+ gettext(grecs_data_type_string(kwp->type)));
fprintf(stream, ">;\n");
}
}
@@ -177,8 +171,7 @@ grecs_format_statement_array (FILE *stream, struct grecs_keyword *kwp,
unsigned n,
unsigned level)
{
- for (; kwp->ident; kwp++, n++)
- {
+ for (; kwp->ident; kwp++, n++) {
if (n)
fputc('\n', stream);
if (kwp->type == grecs_type_section)
@@ -187,3 +180,5 @@ grecs_format_statement_array (FILE *stream, struct grecs_keyword *kwp,
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
@@ -99,7 +99,8 @@ ident : IDENT
{
$$ = find_keyword($1);
if (!$$)
- grecs_error(&grecs_current_locus, 0, _("Unknown keyword"));
+ grecs_error(&grecs_current_locus, 0,
+ _("Unknown keyword"));
}
;
@@ -115,18 +116,16 @@ vallist : vlist
{
size_t n;
- if ((n = grecs_list_size ($1)) == 1)
- {
+ if ((n = grecs_list_size($1)) == 1) {
$$ = *(grecs_value_t *)grecs_list_index($1, 0);
- }
- else
- {
+ } 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]));
+ $$.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;
}
@@ -253,8 +252,7 @@ grecs_vasprintf (char **pbuf, size_t *psize, const char *fmt, va_list ap)
size_t buflen = *psize;
int rc = 0;
- if (!buf)
- {
+ if (!buf) {
if (buflen == 0)
buflen = 512; /* Initial allocation */
@@ -263,35 +261,28 @@ grecs_vasprintf (char **pbuf, size_t *psize, const char *fmt, va_list ap)
return ENOMEM;
}
- for (;;)
- {
+ for (;;) {
ssize_t n = vsnprintf(buf, buflen, fmt, ap);
- if (n < 0 || n >= buflen || !memchr (buf, '\0', n + 1))
- {
+ if (n < 0 || n >= buflen || !memchr(buf, '\0', n + 1)) {
char *newbuf;
size_t newlen = buflen * 2;
- if (newlen < buflen)
- {
+ if (newlen < buflen) {
rc = ENOMEM;
break;
}
newbuf = realloc(buf, newlen);
- if (newbuf == NULL)
- {
+ if (newbuf == NULL) {
rc = ENOMEM;
break;
}
buflen = newlen;
buf = newbuf;
- }
- else
+ } else
break;
}
- if (rc)
- {
- if (!*pbuf)
- {
+ if (rc) {
+ if (!*pbuf) {
/* We made first allocation, now free it */
free(buf);
buf = NULL;
@@ -360,8 +351,7 @@ grecs_parse (const char *name)
if (grecs_lex_begin(name))
return 1;
cursect = &config_keywords;
- if (sections)
- {
+ if (sections) {
grecs_list_free(sections);
sections = NULL;
}
@@ -421,18 +411,17 @@ stmt_begin (struct grecs_keyword *kwp, grecs_value_t tag)
if (!sections)
sections = grecs_list_create();
grecs_list_push(sections, cursect);
- if (kwp)
- {
+ if (kwp) {
target = target_ptr(kwp, CURRENT_BASE);
cursect = kwp;
- if (kwp->callback && kwp->callback (grecs_callback_section_begin,
+ if (kwp->callback &&
+ kwp->callback(grecs_callback_section_begin,
&grecs_current_locus, /* FIXME */
target,
&tag,
&kwp->callback_data))
cursect = &fake;
- }
- else
+ } else
/* install "ignore-all" section */
cursect = kwp;
}
@@ -443,8 +432,7 @@ stmt_end (struct grecs_keyword *kwp)
grecs_callback_fn callback = NULL;
void *dataptr = NULL;
- if (cursect && cursect->callback)
- {
+ if (cursect && cursect->callback) {
callback = cursect->callback;
dataptr = &cursect->callback_data;
}
@@ -458,7 +446,6 @@ stmt_end (struct grecs_keyword *kwp)
kwp ? target_ptr(kwp, CURRENT_BASE) : NULL,
NULL,
dataptr);
-
}
static struct grecs_keyword *
@@ -466,14 +453,11 @@ find_keyword (const char *ident)
{
struct grecs_keyword *kwp;
- if (cursect && cursect != &fake)
- {
+ if (cursect && cursect != &fake) {
for (kwp = cursect->kwd; kwp->ident; kwp++)
if (strcmp(kwp->ident, ident) == 0)
return kwp;
- }
- else
- {
+ } else {
return &fake;
}
return NULL;
@@ -492,9 +476,10 @@ string_to_bool (const char *string, int *pval, grecs_locus_t *locus)
|| strcmp(string, "nil") == 0
|| strcmp(string, "0") == 0)
*pval = 0;
- else
- {
- grecs_error (locus, 0, _("%s: not a valid boolean value"), string);
+ else {
+ grecs_error(locus, 0,
+ _("%s: not a valid boolean value"),
+ string);
return 1;
}
return 0;
@@ -503,8 +488,7 @@ 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)
{
- if (inet_aton (string, in) == 0)
- {
+ if (inet_aton(string, in) == 0) {
struct hostent *hp;
hp = gethostbyname(string);
@@ -519,12 +503,12 @@ static int
string_to_sockaddr(struct grecs_sockaddr *sp, const char *string,
grecs_locus_t *locus)
{
- if (string[0] == '/')
- {
+ 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);
+ 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;
@@ -532,9 +516,7 @@ string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
sp->len = sizeof(s_un);
sp->sa = grecs_malloc(sp->len);
memcpy(sp->sa, &s_un, sp->len);
- }
- else
- {
+ } else {
char *p = strchr(string, ':');
size_t len;
struct sockaddr_in sa;
@@ -547,14 +529,12 @@ string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
if (len == 0)
sa.sin_addr.s_addr = INADDR_ANY;
- else
- {
+ else {
char *host = grecs_malloc(len + 1);
memcpy(host, string, len);
host[len] = 0;
- if (string_to_host (&sa.sin_addr, host, locus))
- {
+ if (string_to_host(&sa.sin_addr, host, locus)) {
grecs_error(locus, 0,
_("%s: not a valid IP address or hostname"),
host);
@@ -564,35 +544,30 @@ string_to_sockaddr (struct grecs_sockaddr *sp, const char *string,
free(host);
}
- if (p)
- {
+ if (p) {
struct servent *serv;
p++;
serv = getservbyname(p, "tcp");
if (serv != NULL)
sa.sin_port = serv->s_port;
- else
- {
+ else {
unsigned long l;
char *q;
/* Not in services, maybe a number? */
l = strtoul(p, &q, 0);
- if (*q || l > USHRT_MAX)
- {
+ 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)
+ } else if (grecs_default_port)
sa.sin_port = grecs_default_port;
- else
- {
+ else {
grecs_error(locus, 0, _("missing port number"));
return 1;
}
@@ -723,8 +698,7 @@ int
grecs_string_convert(void *target, enum grecs_data_type type,
const char *string, grecs_locus_t *locus)
{
- switch (type)
- {
+ switch (type) {
case grecs_type_void:
abort();
@@ -773,18 +747,18 @@ grecs_string_convert (void *target, enum grecs_data_type type,
break;
case grecs_type_ipv4:
- if (inet_aton (string, (struct in_addr *)target))
- {
- grecs_error (locus, 0, _("%s: not a valid IP address"), string);
+ 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))
- {
+ if (string_to_host((struct in_addr *)target, string, locus)) {
grecs_error(locus, 0,
- _("%s: not a valid IP address or hostname"), string);
+ _("%s: not a valid IP address or hostname"),
+ string);
return 1;
}
break;
@@ -795,7 +769,8 @@ grecs_string_convert (void *target, enum grecs_data_type type,
/* FIXME: */
case grecs_type_cidr:
- grecs_error (locus, 0, _("INTERNAL ERROR at %s:%d"), __FILE__, __LINE__);
+ grecs_error(locus, 0,
+ _("INTERNAL ERROR at %s:%d"), __FILE__, __LINE__);
abort();
case grecs_type_section:
@@ -880,17 +855,13 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value,
target,
value,
&kwp->callback_data);
- else if (value->type == GRECS_TYPE_ARRAY)
- {
+ 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))
- {
+ } 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;
@@ -898,8 +869,7 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value,
size_t size;
if (type >= grecs_prop_count
- || (size = grecs_prop_tab[type].size) == 0)
- {
+ || (size = grecs_prop_tab[type].size) == 0) {
grecs_error(locus, 0,
_("INTERNAL ERROR at %s:%d: "
"unhandled data type %d"),
@@ -910,8 +880,7 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value,
list = grecs_list_create();
list->cmp = grecs_prop_tab[type].cmp;
- for (ep = value->v.list->head; ep; ep = ep->next)
- {
+ for (ep = value->v.list->head; ep; ep = ep->next) {
const grecs_value_t *vp = ep->data;
if (vp->type != GRECS_TYPE_STRING)
@@ -919,11 +888,13 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value,
_("%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
- {
+ grecs_list_append(list,
+ (void*) vp->v.string);
+ else {
void *ptr = grecs_malloc(size);
- if (grecs_string_convert (ptr, type, vp->v.string,
+ if (grecs_string_convert(ptr,
+ type,
+ vp->v.string,
locus) == 0)
grecs_list_append(list, ptr);
else
@@ -931,25 +902,20 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value,
}
}
*(struct grecs_list**)target = list;
- }
- else
- {
+ } else {
grecs_error(locus, 0,
_("incompatible data type for `%s'"),
kwp->ident);
return;
}
- }
- else if (GRECS_IS_LIST (kwp->type))
- {
+ } 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)
- {
+ || (size = grecs_prop_tab[type].size) == 0) {
grecs_error(locus, 0,
_("INTERNAL ERROR at %s:%d: unhandled data type %d"),
__FILE__, __LINE__, type);
@@ -961,11 +927,9 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value,
list->free_entry = listel_dispose;
if (type == grecs_type_string)
grecs_list_append(list, value->v.string);
- else
- {
+ else {
ptr = grecs_malloc(size);
- if (grecs_string_convert (ptr, type, value->v.string, locus))
- {
+ if (grecs_string_convert(ptr, type, value->v.string, locus)) {
free(ptr);
grecs_list_free(list);
return;
@@ -973,9 +937,9 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value,
grecs_list_append(list, ptr);
}
*(struct grecs_list**)target = list;
- }
- else
- grecs_string_convert (target, GRECS_TYPE (kwp->type), value->v.string,
+ } else
+ grecs_string_convert(target, GRECS_TYPE(kwp->type),
+ value->v.string,
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
@@ -136,8 +136,7 @@ P [1-9][0-9]*
<ML>.*\n { char *p = multiline_strip_tabs(yytext);
if (!strncmp(p, multiline_delimiter, multiline_delimiter_len)
- && isemptystr (p + multiline_delimiter_len - yytext))
- {
+ && isemptystr(p + multiline_delimiter_len - yytext)) {
free(multiline_delimiter);
multiline_delimiter = NULL;
BEGIN(INITIAL);
@@ -151,7 +150,8 @@ P [1-9][0-9]*
\n { grecs_current_locus.line++; }
[,;{}()] return yytext[0];
. { if (isascii(yytext[0]) && isprint(yytext[0]))
- grecs_error (&grecs_current_locus, 0, _("stray character %c"), yytext[0]);
+ grecs_error(&grecs_current_locus, 0,
+ _("stray character %c"), yytext[0]);
else
grecs_error(&grecs_current_locus, 0, _("stray character \\%03o"),
(unsigned char) yytext[0]); }
@@ -186,28 +186,24 @@ grecs_lex_begin (const char *name)
line_acc->free_entry = line_acc_free_entry;
string_list = grecs_list_create();
- if (grecs_preprocessor)
- {
+ if (grecs_preprocessor) {
int fd;
fd = open(name, O_RDONLY);
- if (fd == -1)
- {
+ 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)
- {
+ if (!yyin) {
grecs_error(NULL, errno,
_("Unable to start external preprocessor `%s'"),
grecs_preprocessor);
return 1;
}
- }
- else
+ } else
return grecs_preproc_init(name);
return 0;
@@ -223,8 +219,7 @@ isemptystr (int off)
{
for (; yytext[off] && isspace(yytext[off]); off++)
;
- if (yytext[off] == ';')
- {
+ if (yytext[off] == ';') {
int i;
for (i = off + 1; yytext[i]; i++)
if (!isspace(yytext[i]))
@@ -251,8 +246,7 @@ unquote_char (int c)
char *p;
- for (p = quote_transtab; *p; p += 2)
- {
+ for (p = quote_transtab; *p; p += 2) {
if (*p == c)
return p[1];
}
@@ -286,13 +280,11 @@ line_acc_add_char (int c)
static void
list_acc_unescape_char(int c)
{
- if (c != '\n')
- {
+ if (c != '\n') {
int t = unquote_char(c);
if (t != -1)
line_acc_add_char(t);
- else
- {
+ else {
grecs_warning(&grecs_current_locus, 0,
_("unknown escape sequence '\\%c'"),
c);
@@ -318,20 +310,15 @@ line_add_unescape_last (char *text, size_t len)
static void
multiline_add(char *s)
{
- if (multiline_unescape)
- {
- for (; *s; s++)
- {
- if (*s == '\\')
- {
+ if (multiline_unescape) {
+ for (; *s; s++) {
+ if (*s == '\\') {
list_acc_unescape_char(s[1]);
++s;
- }
- else
+ } else
line_acc_add_char(*s);
}
- }
- else
+ } else
grecs_line_add(s, strlen(s));
}
@@ -356,34 +343,25 @@ is_ws (char c)
void
multiline_begin(char *p)
{
- if (*p == '-')
- {
- if (*++p == ' ')
- {
+ if (*p == '-') {
+ if (*++p == ' ') {
char_to_strip = is_ws;
p++;
- }
- else
+ } else
char_to_strip = is_tab;
- }
- else
+ } else
char_to_strip = NULL;
- if (*p == '\\')
- {
+ if (*p == '\\') {
p++;
multiline_unescape = 0;
- }
- else if (*p == '"')
- {
+ } else if (*p == '"') {
char *q;
p++;
multiline_unescape = 0;
q = strchr(p, '"');
multiline_delimiter_len = q - p;
- }
- else
- {
+ } else {
multiline_delimiter_len = strcspn(p, " \t");
multiline_unescape = 1;
}
@@ -403,16 +381,14 @@ grecs_line_finish ()
size_t size = 0;
char *str, *p;
- for (ep = line_acc->head; ep; ep = ep->next)
- {
+ 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)
- {
+ 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);
@@ -462,8 +438,7 @@ assign_locus (grecs_locus_t *ploc, char *name, char *line, size_t *pxlines)
{
char *p;
- if (name)
- {
+ if (name) {
if (pxlines && (!ploc->file || strcmp(name, ploc->file)))
*pxlines = 0;
ploc->file = grecs_install_text(name);
@@ -480,25 +455,25 @@ parse_line (char *text, grecs_locus_t *ploc, size_t *pxlines)
if (wordsplit(text, &ws, WRDSF_DEFFLAGS))
grecs_error(ploc, 0, _("cannot parse #line line"));
- else
- {
+ else {
if (ws.ws_wordc == 2)
- rc = assign_locus (ploc, NULL, ws.ws_wordv[1], pxlines);
+ 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)
- {
+ 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);
+ unsigned long x = strtoul(ws.ws_wordv[3],
+ &p, 10);
rc = *p != 0;
if (rc == 0)
*pxlines = x;
}
- }
- else
+ } else
grecs_error(ploc, 0, _("invalid #line statement"));
if (rc)
@@ -512,16 +487,14 @@ parse_line_cpp (char *text, grecs_locus_t *ploc, size_t *pxlines)
{
struct wordsplit ws;
- if (wordsplit (text, &ws, WRDSF_DEFFLAGS))
- {
+ if (wordsplit(text, &ws, WRDSF_DEFFLAGS)) {
grecs_error(ploc, 0, _("cannot parse #line line"));
return;
- }
- else if (ws.ws_wordc < 3)
+ } 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))
+ 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
diff --git a/src/list.c b/src/list.c
index 4a5d3f6..7d7f934 100644
--- a/src/list.c
+++ b/src/list.c
@@ -65,16 +65,14 @@ grecs_list_pop (struct grecs_list *lp)
{
void *data;
struct grecs_list_entry *ep = lp->head;
- if (ep)
- {
+ if (ep) {
data = ep->data;
lp->head = ep->next;
if (!lp->head)
lp->tail = NULL;
lp->count--;
free (ep);
- }
- else
+ } else
data = NULL;
return data;
}
@@ -84,8 +82,7 @@ grecs_list_clear (struct grecs_list *lp)
{
struct grecs_list_entry *ep = lp->head;
- while (ep)
- {
+ while (ep) {
struct grecs_list_entry *next = ep->next;
if (lp->free_entry)
lp->free_entry(ep->data);
@@ -115,8 +112,7 @@ 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)
- {
+ for (ep = lp->head; ep; ep = ep->next) {
if (cmp(ep->data, data) == 0)
return ep->data;
}
@@ -141,14 +137,11 @@ grecs_list_remove_tail (struct grecs_list *lp)
if (!lp->head)
return NULL;
data = lp->tail;
- if (lp->head == lp->tail)
- {
+ if (lp->head == lp->tail) {
free(lp->tail);
lp->head = lp->tail = NULL;
lp->count = 0;
- }
- else
- {
+ } else {
struct grecs_list_entry *ep;
for (ep = lp->head; ep->next != lp->tail; ep = ep->next)
diff --git a/src/preproc.c b/src/preproc.c
index 7ea9442..06924c1 100644
--- a/src/preproc.c
+++ b/src/preproc.c
@@ -34,14 +34,12 @@
int grecs_log_to_stderr = 1;
void (*grecs_log_setup_hook) () = NULL;
-struct input_file_ident
-{
+struct input_file_ident {
ino_t i_node;
dev_t device;
};
-struct buffer_ctx
-{
+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 */
@@ -75,19 +73,12 @@ pp_getline (char **pbuf, size_t *psize, FILE *fp)
size_t size = *psize;
ssize_t off = 0;
- do
- {
- size_t len;
-
- if (off == size - 1)
- {
- if (!buf)
- {
+ do {
+ if (off == size - 1) {
+ if (!buf) {
size = 1;
buf = grecs_malloc(size);
- }
- else
- {
+ } else {
size_t nsize = 2 * size;
if (nsize < size)
grecs_alloc_die();
@@ -95,8 +86,7 @@ pp_getline (char **pbuf, size_t *psize, FILE *fp)
size = nsize;
}
}
- if (!fgets (buf + off, size - off, fp))
- {
+ if (!fgets(buf + off, size - off, fp)) {
if (off == 0)
off = -1;
break;
@@ -110,7 +100,6 @@ pp_getline (char **pbuf, size_t *psize, FILE *fp)
return off;
}
-
static void
putback(const char *str)
{
@@ -119,8 +108,7 @@ putback (const char *str)
if (!*str)
return;
len = strlen(str) + 1;
- if (len > putback_max)
- {
+ if (len > putback_max) {
putback_max = len;
putback_buffer = grecs_realloc(putback_buffer, putback_max);
}
@@ -134,7 +122,8 @@ pp_line_stmt ()
size_t ls_size;
size_t pb_size;
- if (grecs_asprintf (&linebufbase, &linebufsize, "#line %lu \"%s\" %lu\n",
+ if (grecs_asprintf(&linebufbase, &linebufsize,
+ "#line %lu \"%s\" %lu\n",
(unsigned long) LOCUS.line,
LOCUS.file, (unsigned long) context_stack->xlines))
grecs_alloc_die();
@@ -142,8 +131,7 @@ pp_line_stmt ()
ls_size = strlen(linebufbase);
pb_size = putback_size + ls_size + 1;
- if (pb_size > putback_max)
- {
+ if (pb_size > putback_max) {
putback_max = pb_size;
putback_buffer = grecs_realloc(putback_buffer, putback_max);
}
@@ -162,12 +150,9 @@ next_line ()
{
ssize_t rc;
- do
- {
- if (putback_size)
- {
- if (putback_size + 1 > bufsize)
- {
+ do {
+ if (putback_size) {
+ if (putback_size + 1 > bufsize) {
bufsize = putback_size + 1;
linebuf = grecs_realloc(linebuf, bufsize);
}
@@ -179,8 +164,7 @@ next_line ()
return 0;
else
rc = pp_getline(&linebuf, &bufsize, INFILE);
- }
- while (rc == -1 && pop_source () == 0);
+ } while (rc == -1 && pop_source() == 0);
return rc;
}
@@ -189,33 +173,27 @@ grecs_preproc_fill_buffer (char *buf, size_t size)
{
size_t bufsize = size;
- while (next_line () > 0)
- {
+ while (next_line() > 0) {
char *p;
size_t len;
int is_line = 0;
for (p = linebuf; *p && isspace(*p); p++)
;
- if (*p == '#')
- {
+ if (*p == '#') {
size_t l;
for (p++; *p && isspace(*p); p++)
;
l = strlen(p);
- if (STRMATCH (p, l, "include_once"))
- {
+ if (STRMATCH(p, l, "include_once")) {
if (parse_include(linebuf, 1))
putback("/*include_once*/\n");
continue;
- }
- else if (STRMATCH (p, l, "include"))
- {
+ } else if (STRMATCH(p, l, "include")) {
if (parse_include(linebuf, 0))
putback("/*include*/\n");
continue;
- }
- else if (STRMATCH (p, l, "line"))
+ } else if (STRMATCH(p, l, "line"))
is_line = 1;
}
@@ -228,8 +206,7 @@ grecs_preproc_fill_buffer (char *buf, size_t size)
buf += len;
size -= len;
- if (size == 0)
- {
+ if (size == 0) {
putback(linebuf + len);
break;
}
@@ -261,8 +238,7 @@ const char *grecs_preprocessor = NULL;
static struct grecs_list *include_path;
static struct grecs_list *std_include_path;
-struct file_data
-{
+struct file_data {
const char *name;
size_t namelen;
char *buf;
@@ -275,12 +251,10 @@ 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)
- {
+ 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)
- {
+ if (size > dptr->buflen) {
dptr->buflen = size;
dptr->buf = grecs_realloc(dptr->buf, dptr->buflen);
}
@@ -292,18 +266,27 @@ pp_list_find (struct grecs_list *list, struct file_data *dptr)
return dptr->found;
}
+static void
+incl_free(void *data)
+{
+ free(data);
+}
+
void
grecs_include_path_setup_v(char **dirs)
{
- if (!include_path)
+ if (!include_path) {
include_path = grecs_list_create();
+ include_path->free_entry = incl_free;
+ }
std_include_path = grecs_list_create();
- if (dirs)
- {
+ 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]));
+ grecs_list_append(std_include_path,
+ grecs_strdup(dirs[i]));
}
}
@@ -318,10 +301,8 @@ grecs_include_path_setup (const char *dir, ...)
va_start(ap, dir);
p = dir;
- while (1)
- {
- if (argi == argc)
- {
+ while (1) {
+ if (argi == argc) {
if (argc == 0)
argc = 16;
else
@@ -341,9 +322,11 @@ grecs_include_path_setup (const char *dir, ...)
void
grecs_preproc_add_include_dir(char *dir)
{
- if (!include_path)
+ if (!include_path) {
include_path = grecs_list_create();
- grecs_list_append (include_path, dir);
+ include_path->free_entry = incl_free;
+ }
+ grecs_list_append(include_path, grecs_strdup(dir));
}
static struct grecs_symtab *incl_sources;
@@ -365,21 +348,15 @@ incl_compare (void const *data1, void const *data2)
return !(id1->device == id2->device && id1->i_node == id2->i_node);
}
-static void
-incl_free (void *data)
-{
- free (data);
-}
-
static int
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),
+ if (!incl_sources) {
+ incl_sources = grecs_symtab_create(
+ sizeof(struct input_file_ident),
incl_hasher,
incl_compare,
NULL,
@@ -405,34 +382,31 @@ push_source (const char *name, int once)
struct stat st;
int rc = stat(name, &st);
- if (context_stack)
- {
- if (rc)
- {
- grecs_error (&LOCUS, errno, _("Cannot stat `%s'"), name);
+ 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))
- {
+ if (LOCUS.file && STAT_ID_EQ(st, context_stack->id)) {
grecs_error(&LOCUS, 0, _("Recursive inclusion"));
return 1;
}
- if ((ctx = ctx_lookup (&st)))
- {
+ if ((ctx = ctx_lookup(&st))) {
grecs_error(&LOCUS, 0, _("Recursive inclusion"));
if (ctx->prev)
grecs_error(&ctx->prev->locus, 0,
- _("`%s' already