From: Florian Forster Date: Sun, 11 Feb 2007 16:52:49 +0000 (+0100) Subject: src/oconfig.[ch]: Implemented a first version. X-Git-Tag: liboconfig-0.1.0~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5c7aa9c49ae9928ea26c4baa50d92bbbd16d5b64;p=liboconfig.git src/oconfig.[ch]: Implemented a first version. --- diff --git a/src/oconfig.c b/src/oconfig.c index e1c1b54..f8d1849 100644 --- a/src/oconfig.c +++ b/src/oconfig.c @@ -1,10 +1,10 @@ /** - * octo's object oriented config library. - * Copyright (C) 2006 Florian octo Forster + * oconfig - src/oconfig.c + * Copyright (C) 2006,2007 Florian octo Forster * * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2, as published - * by the Free Software Foundation. + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -20,11 +20,53 @@ #include #include #include +#include #include "oconfig.h" -oconfig_item_t *oconfig_parse_fh (FILE *fh); -oconfig_item_t *oconfig_parse_file (const char *file); +/* Functions provided by the scanner */ +void yyset_in (FILE *); + +oconfig_item_t *ci_root; + +oconfig_item_t *oconfig_parse_fh (FILE *fh) +{ + int status; + oconfig_item_t *ret; + + yyset_in (fh); + + status = yyparse (); + if (status != 0) + { + fprintf (stderr, "yyparse returned error #%i\n", status); + return (NULL); + } + + ret = ci_root; + ci_root = NULL; + yyset_in ((FILE *) 0); + + return (ret); +} /* oconfig_item_t *oconfig_parse_fh */ + +oconfig_item_t *oconfig_parse_file (const char *file) +{ + FILE *fh; + oconfig_item_t *ret; + + fh = fopen (file, "r"); + if (fh == NULL) + { + fprintf (stderr, "fopen (%s) failed: %s\n", file, strerror (errno)); + return (NULL); + } + + ret = oconfig_parse_fh (fh); + fclose (fh); + + return (ret); +} /* oconfig_item_t *oconfig_parse_file */ void oconfig_free (oconfig_item_t *ci) { diff --git a/src/oconfig.h b/src/oconfig.h index 29a6429..e6e53e2 100644 --- a/src/oconfig.h +++ b/src/oconfig.h @@ -44,13 +44,13 @@ struct oconfig_item_s; typedef struct oconfig_item_s oconfig_item_t; struct oconfig_item_s { - char *key; - oconfig_value_t *values; - int values_num; + char *key; + oconfig_value_t *values; + int values_num; - oconfig_item_t *parent; - oconfig_item_t *children; - int children_num; + oconfig_item_t *parent; + oconfig_item_t *children; + int children_num; }; /*