#include "oconfig.h"
-/*
- * private structures
- */
-struct oconfig_obj
-{
- oconfig_item_obj_t *items;
-};
+oconfig_item_t *oconfig_parse_fh (FILE *fh);
+oconfig_item_t *oconfig_parse_file (const char *file);
-struct oconfig_item_obj
+void oconfig_free (oconfig_item_t *ci)
{
- char *key;
- char *value;
+ int i;
- oconfig_item_obj_t *child;
- oconfig_item_obj_t *sibling;
-};
+ if (ci->values != NULL)
+ free (ci->values);
-/*
- * private functions
- */
-static oconfig_item_obj_t *oconfig_item_alloc (const char *key, const char *value)
-{
- oconfig_item_obj_t *ret;
-
- ret = calloc (1, sizeof (oconfig_item_obj_t));
-
- if ((ret->key = strdup (key)) == NULL)
- {
- free (ret);
- return (NULL);
- }
-
- if ((ret->value = strdup (value)) == NULL)
- {
- free (ret->key);
- free (ret);
- return (NULL);
- }
-
- return (ret);
-}
-
-static void oconfig_item_free (oconfig_item_obj_t *item)
-{
- /* This temporary variable is used to prevent endless loops. They
- * should not exist, but it doesn't cost much, so what the heck.. */
- oconfig_item_obj_t *temp;
-
- if (item->child != NULL)
- {
- temp = item->child;
- item->child = NULL;
- oconfig_item_free (temp);
- }
-
- if (item->sibling != NULL)
- {
- temp = item->sibling;
- item->sibling = NULL;
- oconfig_item_free (temp);
- }
-
- if (item->key != NULL)
- free (item->key);
-
- if (item->value != NULL)
- free (item->value);
-
- free (item);
-}
-
-static oconfig_item_obj_t *oconfig_item_parse_line (char *buffer)
-{
- char *key;
- char *value;
- size_t value_len;
-
- key = strtok (buffer, " \t\n\r");
- if (key == NULL)
- return (NULL);
-
- value = strtok (NULL, " \t\n\r");
- if (value == NULL)
- return (NULL);
-
- value_len = strlen (value);
- while (value_len > 0)
- {
- if ((value[value_len - 1] == ' ')
- || (value[value_len - 1] == '\t')
- || (value[value_len - 1] == '\n')
- || (value[value_len - 1] == '\r'))
- {
- value[value_len - 1] = '\0';
- value_len--;
- continue;
- }
-
- break;
- }
-
- if (value_len == 0)
- return (NULL);
-
- return (oconfig_item_alloc (key, value));
-}
-
-/*
- * constructor and destructor
- */
-oconfig_obj_t *oconfig_construct (const char *file)
-{
- oconfig_obj_t *ret;
-
- ret = calloc (1, sizeof (oconfig_obj_t));
-
- /* FIXME: Implement the actual functionality */
-
- return (ret);
-}
-
-void oconfig_destroy (oconfig_obj_t *obj)
-{
- assert (obj != NULL);
-
- if (obj->items != NULL)
- oconfig_item_free (obj->items);
-
- free (obj);
+ for (i = 0; i < ci->children_num; i++)
+ oconfig_free (ci->children + i);
}
/*
- * public methods
+ * vim:shiftwidth=2:tabstop=8:softtabstop=2
*/
-oconfig_item_obj_t *oconfig_item_get (oconfig_obj_t *obj);
-oconfig_item_obj_t *oconfig_item_get_child (oconfig_item_obj_t *item);
-oconfig_item_obj_t *oconfig_item_get_sibling (oconfig_item_obj_t *item);
-
-const char *oconfig_item_get_key (oconfig_item_obj_t *);
-size_t oconfig_item_get_value (oconfig_item_obj_t *, void *buffer, size_t *buffer_size);
#include <stdlib.h>
#include <string.h>
#include "oconfig.h"
+#include "scanner.h"
struct statement_list_s
{
%type <ci> option
%type <ci> statement
%type <sl> statement_list
+%type <ci> entire_file
%%
string:
entire_file:
statement_list
{
- int i;
- for (i = 0; i < $1.statement_num; i++)
- dump_ci ($1.statement + i, 0);
+ $$.children = $1.statement;
+ $$.children_num = $1.statement.num;
}
;
%%
-#include "lex.yy.c"
-
-/*
-void yyerror (char *s)
-{
- fprintf (stderr, "%s\n", s);
-}
-
-int yylex (void)
-{
- return (getc (stdin));
-}
-*/
-
-int main (int argc, char **argv)
-{
- yyparse ();
- return (0);
-}
-
static char *unquote (const char *orig)
{
char *ret = strdup (orig);