Some basic auto{conf,make} stuff..
authorFlorian Forster <sifnfors@faui02h.informatik.uni-erlangen.de>
Wed, 7 Feb 2007 14:52:46 +0000 (15:52 +0100)
committerFlorian Forster <sifnfors@faui02h.informatik.uni-erlangen.de>
Wed, 7 Feb 2007 14:52:46 +0000 (15:52 +0100)
configure.ac [new file with mode: 0644]
src/Makefile.am [new file with mode: 0644]
src/oconfig.c
src/parser.y

diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..feedfa7
--- /dev/null
@@ -0,0 +1,30 @@
+AC_INIT(liboconfig, 3.11.0)
+AC_CONFIG_SRCDIR(src/oconfig.c)
+AC_CONFIG_HEADERS(src/config.h)
+AM_INIT_AUTOMAKE(dist-bzip2)
+AC_LANG(C)
+
+AC_PREFIX_DEFAULT("/opt/liboconfig")
+
+#
+# Checks for programs.
+#
+AC_PROG_CC
+AC_PROG_CPP
+AC_PROG_INSTALL
+AC_PROG_LN_S
+AC_PROG_MAKE_SET
+
+dnl configure libtool
+AC_DISABLE_STATIC
+AC_LIBLTDL_CONVENIENCE
+AC_SUBST(LTDLINCL)
+AC_SUBST(LIBLTDL)
+AC_LIBTOOL_DLOPEN
+AC_PROG_LIBTOOL
+AC_PROG_LEX
+AC_PROG_YACC
+#AC_PROG_RANLIB
+AC_CONFIG_SUBDIRS(libltdl)
+
+AC_OUTPUT(Makefile src/Makefile)
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644 (file)
index 0000000..fca1ccc
--- /dev/null
@@ -0,0 +1,16 @@
+AUTOMAKE_OPTIONS = foreign no-dependencies
+
+BUILT_SOURCES = scanner.h parser.h
+CLEANFILES = scanner.h scanner.c parser.h parser.c
+
+AM_YFLAGS = -d
+
+include_HEADERS = oconfig.h
+lib_LTLIBRARIES = liboconfig.la
+
+liboconfig_la_SOURCES = oconfig.c oconfig.h parser.l parser.y
+
+scanner.h: parser.l parser.h
+       $(LEX) -o scanner.c --header-file=scanner.h parser.l
+
+parser.h: parser.y
index 6ba77a0..e1c1b54 100644 (file)
 
 #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);
index 82e89a9..ca0844e 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "oconfig.h"
+#include "scanner.h"
 
 struct statement_list_s
 {
@@ -51,6 +52,7 @@ static void dump_ci (oconfig_item_t *ci, int shift);
 %type <ci> option
 %type <ci> statement
 %type <sl> statement_list
+%type <ci> entire_file
 
 %%
 string:
@@ -163,33 +165,12 @@ statement_list:
 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);