--- /dev/null
+#!/bin/sh
+
+invoke() {
+ echo "$@"
+ $@ || exit $?
+}
+
+# bison/flex make me crazy, all versions differ in subtle ways making it nearly
+# impossible to distribute .l/.y files and integrate them into the build system
+# so that they work everywhere. (All this ylwrap hackery from the automake guys
+# just failed for me again). So now we do it differently: We distribute the
+# generated C code and only people that actually change the .y and .l files
+# invoke this script manually!
+FLEX_FLAGS=
+# we use -l for win32 compilers
+BISON_FLAGS="-l -d"
+
+invoke bison $BISON_FLAGS -o lc_config_parser.c lc_config_parser.y
+invoke flex $FLEX_FLAGS -o lc_config_lexer.c lc_config_lexer.l
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "lc_common_t.h"
+#include "lc_defines.h"
+#include "lc_printf.h"
+
+/* Default appendable implementations */
+
+int lc_appendable_snwadd(lc_appendable_t *app, const char *str, size_t len,
+ unsigned int width, int left_just, char pad)
+{
+ int res = 0;
+ int i;
+ int to_pad = width - len;
+
+ /* If not left justified, pad left */
+ for(i = 0; !left_just && i < to_pad; ++i)
+ res += lc_appendable_chadd(app, pad);
+
+ /* Send the visible portion of the string to the output. */
+ res += lc_appendable_snadd(app, str, len);
+
+ /* If left justified, pad right. */
+ for(i = 0; left_just && i < to_pad; ++i)
+ res += lc_appendable_chadd(app, pad);
+
+ return res;
+}
+
+
+void lc_appendable_init(lc_appendable_t *env, const lc_appendable_funcs_t *app,
+ void *obj, size_t limit)
+{
+ env->obj = obj;
+ env->limit = limit;
+ env->written = 0;
+ env->app =app;
+
+ app->init(env);
+}
+
+static void default_init(UNUSED(lc_appendable_t *env))
+{
+}
+
+static void default_finish(UNUSED(lc_appendable_t *env))
+{
+}
+
+/*
+ * File appendable.
+ */
+
+static int file_snadd(lc_appendable_t *obj, const char *str, size_t n)
+{
+ obj->written += n;
+ fwrite(str, sizeof(char), n, obj->obj);
+ return n;
+}
+
+static int file_chadd(lc_appendable_t *obj, int ch)
+{
+ fputc(ch, obj->obj);
+ obj->written++;
+ return 1;
+}
+
+static lc_appendable_funcs_t app_file = {
+ default_init,
+ default_finish,
+ file_snadd,
+ file_chadd
+};
+
+const lc_appendable_funcs_t *lc_appendable_file = &app_file;
+
+
+/*
+ * String appendable.
+ */
+
+static void str_init(lc_appendable_t *obj)
+{
+ strncpy(obj->obj, "", obj->limit);
+}
+
+static int str_snadd(lc_appendable_t *obj, const char *str, size_t n)
+{
+ size_t to_write = LC_MIN(obj->limit - obj->written - 1, n);
+ char *tgt = obj->obj;
+ strncpy(tgt + obj->written, str, to_write);
+ obj->written += to_write;
+ return to_write;
+}
+
+static int str_chadd(lc_appendable_t *obj, int ch)
+{
+ if(obj->limit - obj->written > 1) {
+ char *tgt = obj->obj;
+ tgt[obj->written++] = (char) ch;
+ return 1;
+ }
+
+ return 0;
+}
+
+static void str_finish(lc_appendable_t *obj)
+{
+ char *str = obj->obj;
+ str[obj->written] = '\0';
+}
+
+static lc_appendable_funcs_t app_string = {
+ str_init,
+ str_finish,
+ str_snadd,
+ str_chadd
+};
+
+const lc_appendable_funcs_t *lc_appendable_string = &app_string;
+
+/*
+ * Obstack appendable
+ */
+
+static int obst_snadd(lc_appendable_t *obj, const char *str, size_t n)
+{
+ struct obstack *obst = obj->obj;
+ obj->written += n;
+ obstack_grow(obst, str, n);
+ return n;
+}
+
+static int obst_chadd(lc_appendable_t *obj, int ch)
+{
+ struct obstack *obst = obj->obj;
+ obstack_1grow(obst, (char) ch);
+ obj->written++;
+ return 1;
+}
+
+static lc_appendable_funcs_t app_obstack = {
+ default_init,
+ default_finish,
+ obst_snadd,
+ obst_chadd
+};
+
+const lc_appendable_funcs_t *lc_appendable_obstack = &app_obstack;
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+
+/**
+ * Something to which can be appended.
+ * @author Sebastian Hack
+ * @date 3.1.2005
+ */
+
+#ifndef _LIBCORE_APPENDABLE_H
+#define _LIBCORE_APPENDABLE_H
+
+#include <stddef.h>
+
+struct _lc_appendable_funcs_t;
+
+typedef struct _lc_appendable_t {
+ void *obj;
+ size_t written;
+ size_t limit;
+ const struct _lc_appendable_funcs_t *app;
+} lc_appendable_t;
+
+typedef struct _lc_appendable_funcs_t {
+ void (*init)(lc_appendable_t *obj);
+ void (*finish)(lc_appendable_t *obj);
+ int (*snadd)(lc_appendable_t *obj, const char *str, size_t len);
+ int (*chadd)(lc_appendable_t *obj, int ch);
+} lc_appendable_funcs_t;
+
+#define lc_appendable_snadd(obj,str,len) ((obj)->app->snadd(obj, str, len))
+#define lc_appendable_chadd(obj,ch) ((obj)->app->chadd(obj, ch))
+#define lc_appendable_finish(obj) ((obj)->app->finish(obj))
+
+extern void lc_appendable_init(lc_appendable_t *app, const lc_appendable_funcs_t *funcs,
+ void *obj, size_t limit);
+
+extern int lc_appendable_snwadd(lc_appendable_t *app, const char *str,
+ size_t len, unsigned int width, int left_just, char pad);
+
+extern const lc_appendable_funcs_t *lc_appendable_file;
+extern const lc_appendable_funcs_t *lc_appendable_string;
+extern const lc_appendable_funcs_t *lc_appendable_obstack;
+
+#endif
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef _COMMON_T_H
+#define _COMMON_T_H
+
+#include <obstack.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#define obstack_chunk_alloc malloc
+#define obstack_chunk_free free
+
+#define bcopy(src,dest,n) memcpy(dest,src,n)
+
+#include <libcore/lc_config.h>
+
+#define FUNCNAME LC_FUNCNAME
+#define UNUSED(x) LC_UNUSED(x)
+#define LONGLONG long /* LC_LONGLONG */
+#define LONGDOUBLE double /* LC_LONGDOUBLE */
+
+#ifdef LC_HAVE_C99
+#define HAVE_C99 LC_HAVE_C99
+#else /* LC_HAVE_C99 */
+
+#ifdef _WIN32
+/* Windows names for non-POSIX calls */
+#define snprintf _snprintf
+#define vsnprintf _vsnprintf
+#endif /* WIN32 */
+
+/* These both are not posix or ansi c but almost everywhere existent */
+
+/* Daniel: Why not just include stdio.h?
+extern int snprintf(char *buf, size_t size, const char *fmt, ...);
+extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
+*/
+
+#endif /* LC_HAVE_C99 */
+
+#endif /* _COMMON_T_H */
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+/**
+ * Central definitions for the libcore.
+ * @author Sebastian Hack
+ * @date 22.12.2004
+ */
+
+#ifndef _LC_CONFIG_H
+#define _LC_CONFIG_H
+
+#if defined(__STD_VERSION__) && __STD_VERSION >= 199901L
+#define LC_HAVE_C99 1
+#endif
+
+/* ISO C99 Standard stuff */
+#ifdef LC_HAVE_C99
+#define LC_INLINE inline
+#define LC_FUNCNAME __func__
+#define LC_UNUSED(x) x
+#define LC_LONGLONG long long
+#define LC_LONGDOUBLE long double
+
+/* definitions using GCC */
+#elif defined(__GNUC__)
+
+#define LC_INLINE __inline__
+#define LC_FUNCNAME __FUNCTION__
+#define LC_UNUSED(x) x __attribute__((__unused__))
+
+#ifdef __STRICT_ANSI__
+#define LC_LONGLONG long
+#define LC_LONGDOUBLE double
+#else
+#define LC_LONGLONG long long
+#define LC_LONGDOUBLE long double
+#endif
+
+#elif defined(_MSC_VER)
+
+#define LC_INLINE __inline
+#define LC_FUNCNAME "<unknown>"
+#define LC_UNUSED(x) x
+#define LC_LONGLONG __int64
+#define LC_LONGDOUBLE long double
+
+/* disable warning: 'foo' was declared deprecated, use 'bla' instead */
+/* of course MS had to make 'bla' incompatible to 'foo', so a simple */
+/* define will not work :-((( */
+#pragma warning( disable : 4996 )
+
+#ifdef _WIN32
+#define snprintf _snprintf
+#endif /* _WIN32 */
+
+#if _MSC_VER <= 1200
+typedef __int16 int16;
+typedef __int32 int32;
+typedef __int64 int64;
+typedef unsigned __int16 uint16;
+typedef unsigned __int32 uint32;
+typedef unsigned __int64 uint64;
+#endif /* _MSC_VER <= 1200 */
+
+/* default definitions */
+#else /* defined(_MSC_VER) */
+
+#define LC_INLINE
+#define LC_FUNCNAME "<unknown>"
+#define LC_UNUSED(x)
+#define LC_LONGLONG long
+#define LC_LONGDOUBLE double
+
+#endif
+
+#endif /* _LC_CONFIG_H */
--- /dev/null
+#line 2 "lc_config_lexer.c"
+
+#line 4 "lc_config_lexer.c"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 33
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_CONST
+
+#endif /* __STDC__ */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE _lc_opt_restart(_lc_opt_in )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+extern int _lc_opt_leng;
+
+extern FILE *_lc_opt_in, *_lc_opt_out;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up _lc_opt_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up _lc_opt_text again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef unsigned int yy_size_t;
+#endif
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via _lc_opt_restart()), so that the user can continue scanning by
+ * just pointing _lc_opt_in at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* Stack of input buffers. */
+static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
+static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
+static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+/* yy_hold_char holds the character lost when _lc_opt_text is formed. */
+static char yy_hold_char;
+static int yy_n_chars; /* number of characters read into yy_ch_buf */
+int _lc_opt_leng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 0; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow _lc_opt_wrap()'s to do buffer switches
+ * instead of setting up a fresh _lc_opt_in. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void _lc_opt_restart (FILE *input_file );
+void _lc_opt__switch_to_buffer (YY_BUFFER_STATE new_buffer );
+YY_BUFFER_STATE _lc_opt__create_buffer (FILE *file,int size );
+void _lc_opt__delete_buffer (YY_BUFFER_STATE b );
+void _lc_opt__flush_buffer (YY_BUFFER_STATE b );
+void _lc_opt_push_buffer_state (YY_BUFFER_STATE new_buffer );
+void _lc_opt_pop_buffer_state (void );
+
+static void _lc_opt_ensure_buffer_stack (void );
+static void _lc_opt__load_buffer_state (void );
+static void _lc_opt__init_buffer (YY_BUFFER_STATE b,FILE *file );
+
+#define YY_FLUSH_BUFFER _lc_opt__flush_buffer(YY_CURRENT_BUFFER )
+
+YY_BUFFER_STATE _lc_opt__scan_buffer (char *base,yy_size_t size );
+YY_BUFFER_STATE _lc_opt__scan_string (yyconst char *yy_str );
+YY_BUFFER_STATE _lc_opt__scan_bytes (yyconst char *bytes,int len );
+
+void *_lc_opt_alloc (yy_size_t );
+void *_lc_opt_realloc (void *,yy_size_t );
+void _lc_opt_free (void * );
+
+#define yy_new_buffer _lc_opt__create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ _lc_opt_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ _lc_opt__create_buffer(_lc_opt_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ _lc_opt_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ _lc_opt__create_buffer(_lc_opt_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+
+typedef unsigned char YY_CHAR;
+
+FILE *_lc_opt_in = (FILE *) 0, *_lc_opt_out = (FILE *) 0;
+
+typedef int yy_state_type;
+
+extern int _lc_opt_lineno;
+
+int _lc_opt_lineno = 1;
+
+extern char *_lc_opt_text;
+#define yytext_ptr _lc_opt_text
+
+static yy_state_type yy_get_previous_state (void );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
+static int yy_get_next_buffer (void );
+static void yy_fatal_error (yyconst char msg[] );
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up _lc_opt_text.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+ _lc_opt_leng = (size_t) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+ (yy_c_buf_p) = yy_cp;
+
+#define YY_NUM_RULES 28
+#define YY_END_OF_BUFFER 29
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[49] =
+ { 0,
+ 25, 25, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 29, 27, 25, 26, 5, 23, 24, 24,
+ 8, 7, 6, 4, 3, 4, 11, 12, 9, 10,
+ 14, 13, 22, 15, 22, 25, 23, 1, 5, 8,
+ 2, 21, 19, 20, 16, 17, 18, 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 4, 5, 6, 1, 1, 1, 1,
+ 1, 7, 1, 1, 1, 8, 9, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 11, 1, 1,
+ 11, 1, 1, 1, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 1, 12, 1, 1, 6, 1, 6, 13, 6, 6,
+
+ 6, 14, 6, 6, 6, 6, 6, 6, 6, 15,
+ 6, 6, 6, 16, 6, 17, 6, 6, 6, 6,
+ 6, 6, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[18] =
+ { 0,
+ 1, 1, 2, 1, 1, 3, 1, 1, 1, 3,
+ 1, 1, 3, 3, 3, 3, 3
+ } ;
+
+static yyconst flex_int16_t yy_base[56] =
+ { 0,
+ 0, 0, 62, 39, 15, 16, 21, 31, 38, 37,
+ 16, 17, 39, 67, 36, 67, 67, 0, 67, 23,
+ 35, 67, 67, 67, 67, 27, 67, 67, 67, 67,
+ 67, 67, 67, 67, 31, 29, 0, 67, 67, 25,
+ 67, 67, 67, 67, 67, 67, 67, 67, 48, 51,
+ 54, 57, 60, 23, 63
+ } ;
+
+static yyconst flex_int16_t yy_def[56] =
+ { 0,
+ 48, 1, 49, 49, 50, 50, 51, 51, 52, 52,
+ 53, 53, 48, 48, 48, 48, 48, 54, 48, 48,
+ 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
+ 48, 48, 48, 48, 55, 48, 54, 48, 48, 48,
+ 48, 48, 48, 48, 48, 48, 48, 0, 48, 48,
+ 48, 48, 48, 48, 48
+ } ;
+
+static yyconst flex_int16_t yy_nxt[85] =
+ { 0,
+ 14, 15, 16, 14, 17, 18, 14, 19, 20, 14,
+ 21, 14, 18, 18, 18, 18, 18, 25, 25, 34,
+ 34, 26, 26, 28, 29, 37, 40, 35, 35, 38,
+ 36, 39, 30, 28, 29, 41, 40, 36, 48, 32,
+ 32, 23, 30, 43, 44, 45, 46, 47, 22, 22,
+ 22, 24, 24, 24, 27, 27, 27, 31, 31, 31,
+ 33, 33, 33, 42, 23, 42, 13, 48, 48, 48,
+ 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
+ 48, 48, 48, 48
+ } ;
+
+static yyconst flex_int16_t yy_chk[85] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 5, 6, 11,
+ 12, 5, 6, 7, 7, 54, 40, 11, 12, 20,
+ 36, 20, 7, 8, 8, 26, 21, 15, 13, 10,
+ 9, 4, 8, 35, 35, 35, 35, 35, 49, 49,
+ 49, 50, 50, 50, 51, 51, 51, 52, 52, 52,
+ 53, 53, 53, 55, 3, 55, 48, 48, 48, 48,
+ 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
+ 48, 48, 48, 48
+ } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+extern int _lc_opt__flex_debug;
+int _lc_opt__flex_debug = 0;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *_lc_opt_text;
+#line 1 "lc_config_lexer.l"
+#line 5 "lc_config_lexer.l"
+
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#include <stdio.h>
+
+#include "lc_parser_t.h"
+#include "lc_config_parser.h"
+
+static int _lc_opt_wrap(void)
+{
+ return 1;
+}
+
+
+
+
+
+
+#line 522 "lc_config_lexer.c"
+
+#define INITIAL 0
+#define LINE_COMMENT 1
+#define BIG_COMMENT 2
+#define DAT 3
+#define DAT_CONT 4
+#define STR 5
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+static int yy_init_globals (void );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int _lc_opt_wrap (void );
+#else
+extern int _lc_opt_wrap (void );
+#endif
+#endif
+
+ static void yyunput (int c,char *buf_ptr );
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * );
+#endif
+
+#ifndef YY_NO_INPUT
+
+#ifdef __cplusplus
+static int yyinput (void );
+#else
+static int input (void );
+#endif
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO (void) fwrite( _lc_opt_text, _lc_opt_leng, 1, _lc_opt_out )
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( _lc_opt_in )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( _lc_opt_in ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, _lc_opt_in))==0 && ferror(_lc_opt_in)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(_lc_opt_in); \
+ } \
+ }\
+\
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int _lc_opt_lex (void);
+
+#define YY_DECL int _lc_opt_lex (void)
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after _lc_opt_text and _lc_opt_leng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+#line 53 "lc_config_lexer.l"
+
+
+#line 683 "lc_config_lexer.c"
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! _lc_opt_in )
+ _lc_opt_in = stdin;
+
+ if ( ! _lc_opt_out )
+ _lc_opt_out = stdout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ _lc_opt_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ _lc_opt__create_buffer(_lc_opt_in,YY_BUF_SIZE );
+ }
+
+ _lc_opt__load_buffer_state( );
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of _lc_opt_text. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = (yy_start);
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 49 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_base[yy_current_state] != 67 );
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if ( yy_act == 0 )
+ { /* have to back up */
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 55 "lc_config_lexer.l"
+{ BEGIN(BIG_COMMENT); }
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 56 "lc_config_lexer.l"
+{ BEGIN(INITIAL); }
+ YY_BREAK
+case 3:
+/* rule 3 can match eol */
+YY_RULE_SETUP
+#line 57 "lc_config_lexer.l"
+PMANGLE(linenr)++;
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 58 "lc_config_lexer.l"
+;
+ YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 60 "lc_config_lexer.l"
+{ BEGIN(LINE_COMMENT); }
+ YY_BREAK
+case 6:
+/* rule 6 can match eol */
+YY_RULE_SETUP
+#line 61 "lc_config_lexer.l"
+{ BEGIN(INITIAL); PMANGLE(linenr)++; }
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 62 "lc_config_lexer.l"
+;
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 65 "lc_config_lexer.l"
+{ BEGIN(DAT); }
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 66 "lc_config_lexer.l"
+{ BEGIN(STR); }
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 67 "lc_config_lexer.l"
+{ BEGIN(DAT_CONT); }
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 68 "lc_config_lexer.l"
+{ _lc_opt_add_to_data_char(PMANGLE(text)[0]); }
+ YY_BREAK
+case 12:
+/* rule 12 can match eol */
+YY_RULE_SETUP
+#line 69 "lc_config_lexer.l"
+{
+ BEGIN(INITIAL);
+ PMANGLE(linenr)++;
+ _lc_opt_add_to_data_char('\0');
+ return DATA;
+ }
+ YY_BREAK
+case 13:
+/* rule 13 can match eol */
+YY_RULE_SETUP
+#line 75 "lc_config_lexer.l"
+{ BEGIN(DAT); PMANGLE(linenr)++; }
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 76 "lc_config_lexer.l"
+;
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 79 "lc_config_lexer.l"
+{
+ BEGIN(INITIAL);
+ _lc_opt_add_to_data_char('\0');
+ return DATA;
+ }
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 85 "lc_config_lexer.l"
+_lc_opt_add_to_data_char('\n');
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 86 "lc_config_lexer.l"
+_lc_opt_add_to_data_char('\r');
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 87 "lc_config_lexer.l"
+_lc_opt_add_to_data_char('\t');
+ YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 88 "lc_config_lexer.l"
+_lc_opt_add_to_data_char('\b');
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 89 "lc_config_lexer.l"
+_lc_opt_add_to_data_char('\f');
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 90 "lc_config_lexer.l"
+_lc_opt_add_to_data_char(_lc_opt_text[1]);
+ YY_BREAK
+case 22:
+/* rule 22 can match eol */
+YY_RULE_SETUP
+#line 91 "lc_config_lexer.l"
+_lc_opt_add_to_data_char(_lc_opt_text[0]);
+ YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 93 "lc_config_lexer.l"
+{
+ PMANGLE(lval).text.str = PMANGLE(text);
+ PMANGLE(lval).text.len = PMANGLE(leng);
+ return IDENT;
+ }
+ YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 98 "lc_config_lexer.l"
+{ return SEP; }
+ YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 100 "lc_config_lexer.l"
+;
+ YY_BREAK
+case 26:
+/* rule 26 can match eol */
+YY_RULE_SETUP
+#line 101 "lc_config_lexer.l"
+PMANGLE(linenr)++;
+ YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 103 "lc_config_lexer.l"
+return _lc_opt_text[0];
+ YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 105 "lc_config_lexer.l"
+ECHO;
+ YY_BREAK
+#line 925 "lc_config_lexer.c"
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(LINE_COMMENT):
+case YY_STATE_EOF(BIG_COMMENT):
+case YY_STATE_EOF(DAT):
+case YY_STATE_EOF(DAT_CONT):
+case YY_STATE_EOF(STR):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed _lc_opt_in at a new source and called
+ * _lc_opt_lex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = _lc_opt_in;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = (yy_c_buf_p);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( _lc_opt_wrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * _lc_opt_text, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of _lc_opt_lex */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+static int yy_get_next_buffer (void)
+{
+ register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ register char *source = (yytext_ptr);
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ int num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ _lc_opt_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), (size_t) num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ _lc_opt_restart(_lc_opt_in );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ static yy_state_type yy_get_previous_state (void)
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+ yy_current_state = (yy_start);
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 49 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
+{
+ register int yy_is_jam;
+ register char *yy_cp = (yy_c_buf_p);
+
+ register YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 49 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 48);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+ static void yyunput (int c, register char * yy_bp )
+{
+ register char *yy_cp;
+
+ yy_cp = (yy_c_buf_p);
+
+ /* undo effects of setting up _lc_opt_text */
+ *yy_cp = (yy_hold_char);
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ { /* need to shift things up to make room */
+ /* +2 for EOB chars. */
+ register int number_to_move = (yy_n_chars) + 2;
+ register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
+ register char *source =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
+
+ while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ YY_FATAL_ERROR( "flex scanner push-back overflow" );
+ }
+
+ *--yy_cp = (char) c;
+
+ (yytext_ptr) = yy_bp;
+ (yy_hold_char) = *yy_cp;
+ (yy_c_buf_p) = yy_cp;
+}
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (void)
+#else
+ static int input (void)
+#endif
+
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ int offset = (yy_c_buf_p) - (yytext_ptr);
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ _lc_opt_restart(_lc_opt_in );
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( _lc_opt_wrap( ) )
+ return EOF;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve _lc_opt_text */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+ return c;
+}
+#endif /* ifndef YY_NO_INPUT */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ *
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void _lc_opt_restart (FILE * input_file )
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ _lc_opt_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ _lc_opt__create_buffer(_lc_opt_in,YY_BUF_SIZE );
+ }
+
+ _lc_opt__init_buffer(YY_CURRENT_BUFFER,input_file );
+ _lc_opt__load_buffer_state( );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+ void _lc_opt__switch_to_buffer (YY_BUFFER_STATE new_buffer )
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * _lc_opt_pop_buffer_state();
+ * _lc_opt_push_buffer_state(new_buffer);
+ */
+ _lc_opt_ensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ _lc_opt__load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (_lc_opt_wrap()) processing, but the only time this flag
+ * is looked at is after _lc_opt_wrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+static void _lc_opt__load_buffer_state (void)
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ _lc_opt_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE _lc_opt__create_buffer (FILE * file, int size )
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) _lc_opt_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in _lc_opt__create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) _lc_opt_alloc(b->yy_buf_size + 2 );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in _lc_opt__create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ _lc_opt__init_buffer(b,file );
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with _lc_opt__create_buffer()
+ *
+ */
+ void _lc_opt__delete_buffer (YY_BUFFER_STATE b )
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ _lc_opt_free((void *) b->yy_ch_buf );
+
+ _lc_opt_free((void *) b );
+}
+
+#ifndef __cplusplus
+extern int isatty (int );
+#endif /* __cplusplus */
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a _lc_opt_restart() or at EOF.
+ */
+ static void _lc_opt__init_buffer (YY_BUFFER_STATE b, FILE * file )
+
+{
+ int oerrno = errno;
+
+ _lc_opt__flush_buffer(b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then _lc_opt__init_buffer was _probably_
+ * called from _lc_opt_restart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+ void _lc_opt__flush_buffer (YY_BUFFER_STATE b )
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ _lc_opt__load_buffer_state( );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+void _lc_opt_push_buffer_state (YY_BUFFER_STATE new_buffer )
+{
+ if (new_buffer == NULL)
+ return;
+
+ _lc_opt_ensure_buffer_stack();
+
+ /* This block is copied from _lc_opt__switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from _lc_opt__switch_to_buffer. */
+ _lc_opt__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+void _lc_opt_pop_buffer_state (void)
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ _lc_opt__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ _lc_opt__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+static void _lc_opt_ensure_buffer_stack (void)
+{
+ int num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ (yy_buffer_stack) = (struct yy_buffer_state**)_lc_opt_alloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)_lc_opt_realloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE _lc_opt__scan_buffer (char * base, yy_size_t size )
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) _lc_opt_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in _lc_opt__scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ _lc_opt__switch_to_buffer(b );
+
+ return b;
+}
+
+/** Setup the input buffer state to scan a string. The next call to _lc_opt_lex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
+ *
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * _lc_opt__scan_bytes() instead.
+ */
+YY_BUFFER_STATE _lc_opt__scan_string (yyconst char * yystr )
+{
+
+ return _lc_opt__scan_bytes(yystr,strlen(yystr) );
+}
+
+/** Setup the input buffer state to scan the given bytes. The next call to _lc_opt_lex() will
+ * scan from a @e copy of @a bytes.
+ * @param bytes the byte buffer to scan
+ * @param len the number of bytes in the buffer pointed to by @a bytes.
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE _lc_opt__scan_bytes (yyconst char * yybytes, int _yybytes_len )
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = _yybytes_len + 2;
+ buf = (char *) _lc_opt_alloc(n );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in _lc_opt__scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = _lc_opt__scan_buffer(buf,n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in _lc_opt__scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+static void yy_fatal_error (yyconst char* msg )
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up _lc_opt_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ _lc_opt_text[_lc_opt_leng] = (yy_hold_char); \
+ (yy_c_buf_p) = _lc_opt_text + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ _lc_opt_leng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/** Get the current line number.
+ *
+ */
+int _lc_opt_get_lineno (void)
+{
+
+ return _lc_opt_lineno;
+}
+
+/** Get the input stream.
+ *
+ */
+FILE *_lc_opt_get_in (void)
+{
+ return _lc_opt_in;
+}
+
+/** Get the output stream.
+ *
+ */
+FILE *_lc_opt_get_out (void)
+{
+ return _lc_opt_out;
+}
+
+/** Get the length of the current token.
+ *
+ */
+int _lc_opt_get_leng (void)
+{
+ return _lc_opt_leng;
+}
+
+/** Get the current token.
+ *
+ */
+
+char *_lc_opt_get_text (void)
+{
+ return _lc_opt_text;
+}
+
+/** Set the current line number.
+ * @param line_number
+ *
+ */
+void _lc_opt_set_lineno (int line_number )
+{
+
+ _lc_opt_lineno = line_number;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ *
+ * @see _lc_opt__switch_to_buffer
+ */
+void _lc_opt_set_in (FILE * in_str )
+{
+ _lc_opt_in = in_str ;
+}
+
+void _lc_opt_set_out (FILE * out_str )
+{
+ _lc_opt_out = out_str ;
+}
+
+int _lc_opt_get_debug (void)
+{
+ return _lc_opt__flex_debug;
+}
+
+void _lc_opt_set_debug (int bdebug )
+{
+ _lc_opt__flex_debug = bdebug ;
+}
+
+static int yy_init_globals (void)
+{
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from _lc_opt_lex_destroy(), so don't allocate here.
+ */
+
+ (yy_buffer_stack) = 0;
+ (yy_buffer_stack_top) = 0;
+ (yy_buffer_stack_max) = 0;
+ (yy_c_buf_p) = (char *) 0;
+ (yy_init) = 0;
+ (yy_start) = 0;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ _lc_opt_in = stdin;
+ _lc_opt_out = stdout;
+#else
+ _lc_opt_in = (FILE *) 0;
+ _lc_opt_out = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * _lc_opt_lex_init()
+ */
+ return 0;
+}
+
+/* _lc_opt_lex_destroy is for both reentrant and non-reentrant scanners. */
+int _lc_opt_lex_destroy (void)
+{
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ _lc_opt__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ _lc_opt_pop_buffer_state();
+ }
+
+ /* Destroy the stack itself. */
+ _lc_opt_free((yy_buffer_stack) );
+ (yy_buffer_stack) = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * _lc_opt_lex() is called, initialization will occur. */
+ yy_init_globals( );
+
+ return 0;
+}
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
+{
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s )
+{
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *_lc_opt_alloc (yy_size_t size )
+{
+ return (void *) malloc( size );
+}
+
+void *_lc_opt_realloc (void * ptr, yy_size_t size )
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void _lc_opt_free (void * ptr )
+{
+ free( (char *) ptr ); /* see _lc_opt_realloc() for (char *) cast */
+}
+
+#define YYTABLES_NAME "yytables"
+
+#line 105 "lc_config_lexer.l"
--- /dev/null
+
+%option prefix="_lc_opt_"
+
+%{
+
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#include <stdio.h>
+
+#include "lc_parser_t.h"
+#include "lc_config_parser.h"
+
+static int _lc_opt_wrap(void)
+{
+ return 1;
+}
+
+%}
+
+num [0-9]+
+hexnum 0x[0-9a-fA-F]+
+idcharsbegin [a-zA-Z$_]
+idchars ({idcharsbegin}|[0-9])
+ident {idcharsbegin}{idchars}*
+ws [\t ]*
+nl \n
+
+%x LINE_COMMENT
+%x BIG_COMMENT
+%x DAT
+%x DAT_CONT
+%x STR
+
+
+%%
+
+"/*" { BEGIN(BIG_COMMENT); }
+<BIG_COMMENT>"*/" { BEGIN(INITIAL); }
+<BIG_COMMENT>\n PMANGLE(linenr)++;
+<BIG_COMMENT>. ;
+
+("#"|"//") { BEGIN(LINE_COMMENT); }
+<LINE_COMMENT>\n { BEGIN(INITIAL); PMANGLE(linenr)++; }
+<LINE_COMMENT>. ;
+
+
+<INITIAL>[=:]{ws} { BEGIN(DAT); }
+<DAT>\" { BEGIN(STR); }
+<DAT>\\ { BEGIN(DAT_CONT); }
+<DAT>. { _lc_opt_add_to_data_char(PMANGLE(text)[0]); }
+<DAT>\n {
+ BEGIN(INITIAL);
+ PMANGLE(linenr)++;
+ _lc_opt_add_to_data_char('\0');
+ return DATA;
+ }
+<DAT_CONT>\n { BEGIN(DAT); PMANGLE(linenr)++; }
+<DAT_CONT>. ;
+
+
+<STR>\" {
+ BEGIN(INITIAL);
+ _lc_opt_add_to_data_char('\0');
+ return DATA;
+ }
+
+<STR>\\n _lc_opt_add_to_data_char('\n');
+<STR>\\r _lc_opt_add_to_data_char('\r');
+<STR>\\t _lc_opt_add_to_data_char('\t');
+<STR>\\b _lc_opt_add_to_data_char('\b');
+<STR>\\f _lc_opt_add_to_data_char('\f');
+<STR>\\. _lc_opt_add_to_data_char(yytext[1]);
+<STR>[^\"] _lc_opt_add_to_data_char(yytext[0]);
+
+{ident} {
+ PMANGLE(lval).text.str = PMANGLE(text);
+ PMANGLE(lval).text.len = PMANGLE(leng);
+ return IDENT;
+ }
+[/.] { return SEP; }
+
+{ws} ;
+{nl} PMANGLE(linenr)++;
+
+. return yytext[0];
+
+%%
--- /dev/null
+/* A Bison parser, made by GNU Bison 2.3. */
+
+/* Skeleton implementation for Bison's Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+ simplifying the original so-called "semantic" parser. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+/* Identify Bison output. */
+#define YYBISON 1
+
+/* Bison version. */
+#define YYBISON_VERSION "2.3"
+
+/* Skeleton name. */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers. */
+#define YYPURE 0
+
+/* Using locations. */
+#define YYLSP_NEEDED 0
+
+/* Substitute the variable and function names. */
+#define yyparse _lc_opt_parse
+#define yylex _lc_opt_lex
+#define yyerror _lc_opt_error
+#define yylval _lc_opt_lval
+#define yychar _lc_opt_char
+#define yydebug _lc_opt_debug
+#define yynerrs _lc_opt_nerrs
+
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ SEP = 258,
+ DATA = 259,
+ IDENT = 260
+ };
+#endif
+/* Tokens. */
+#define SEP 258
+#define DATA 259
+#define IDENT 260
+
+
+
+
+/* Copy the first part of user declarations. */
+
+
+
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include <string.h>
+
+#include "lc_opts_t.h"
+#include "lc_parser_t.h"
+
+static void group_open(void);
+static void group_close(void);
+static void lc_opt_set(void);
+static void path_push(text_t text);
+
+void PMANGLE(error)(const char *str);
+int PMANGLE(linenr);
+
+
+
+/* Enabling traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+/* Enabling the token table. */
+#ifndef YYTOKEN_TABLE
+# define YYTOKEN_TABLE 0
+#endif
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+
+{
+ text_t text;
+ int num;
+}
+/* Line 187 of yacc.c. */
+
+ YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+/* Copy the second part of user declarations. */
+
+
+/* Line 216 of yacc.c. */
+
+
+#ifdef short
+# undef short
+#endif
+
+#ifdef YYTYPE_UINT8
+typedef YYTYPE_UINT8 yytype_uint8;
+#else
+typedef unsigned char yytype_uint8;
+#endif
+
+#ifdef YYTYPE_INT8
+typedef YYTYPE_INT8 yytype_int8;
+#elif (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+typedef signed char yytype_int8;
+#else
+typedef short int yytype_int8;
+#endif
+
+#ifdef YYTYPE_UINT16
+typedef YYTYPE_UINT16 yytype_uint16;
+#else
+typedef unsigned short int yytype_uint16;
+#endif
+
+#ifdef YYTYPE_INT16
+typedef YYTYPE_INT16 yytype_int16;
+#else
+typedef short int yytype_int16;
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+# define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+# define YYSIZE_T size_t
+# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# else
+# define YYSIZE_T unsigned int
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
+
+#ifndef YY_
+# if YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_(msgid) dgettext ("bison-runtime", msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(msgid) msgid
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(e) ((void) (e))
+#else
+# define YYUSE(e) /* empty */
+#endif
+
+/* Identity function, used to suppress warnings about constant conditions. */
+#ifndef lint
+# define YYID(n) (n)
+#else
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static int
+YYID (int i)
+#else
+static int
+YYID (i)
+ int i;
+#endif
+{
+ return i;
+}
+#endif
+
+#if ! defined yyoverflow || YYERROR_VERBOSE
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */
+
+# ifdef YYSTACK_USE_ALLOCA
+# if YYSTACK_USE_ALLOCA
+# ifdef __GNUC__
+# define YYSTACK_ALLOC __builtin_alloca
+# elif defined __BUILTIN_VA_ARG_INCR
+# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+# elif defined _AIX
+# define YYSTACK_ALLOC __alloca
+# elif defined _MSC_VER
+# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+# define alloca _alloca
+# else
+# define YYSTACK_ALLOC alloca
+# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef _STDLIB_H
+# define _STDLIB_H 1
+# endif
+# endif
+# endif
+# endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's `empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
+# ifndef YYSTACK_ALLOC_MAXIMUM
+ /* The OS might guarantee only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
+ to allow for a few compiler-allocated temporary stack slots. */
+# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
+# endif
+# else
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# ifndef YYSTACK_ALLOC_MAXIMUM
+# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
+# endif
+# if (defined __cplusplus && ! defined _STDLIB_H \
+ && ! ((defined YYMALLOC || defined malloc) \
+ && (defined YYFREE || defined free)))
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef _STDLIB_H
+# define _STDLIB_H 1
+# endif
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# ifndef YYFREE
+# define YYFREE free
+# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+void free (void *); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# endif
+#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
+
+
+#if (! defined yyoverflow \
+ && (! defined __cplusplus \
+ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ yytype_int16 yyss;
+ YYSTYPE yyvs;
+ };
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+# define YYSTACK_BYTES(N) \
+ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
+ + YYSTACK_GAP_MAXIMUM)
+
+/* Copy COUNT objects from FROM to TO. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined __GNUC__ && 1 < __GNUC__
+# define YYCOPY(To, From, Count) \
+ __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+# else
+# define YYCOPY(To, From, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (To)[yyi] = (From)[yyi]; \
+ } \
+ while (YYID (0))
+# endif
+# endif
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack) \
+ do \
+ { \
+ YYSIZE_T yynewbytes; \
+ YYCOPY (&yyptr->Stack, Stack, yysize); \
+ Stack = &yyptr->Stack; \
+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / sizeof (*yyptr); \
+ } \
+ while (YYID (0))
+
+#endif
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL 9
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST 8
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS 8
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS 9
+/* YYNRULES -- Number of rules. */
+#define YYNRULES 13
+/* YYNRULES -- Number of states. */
+#define YYNSTATES 18
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
+#define YYUNDEFTOK 2
+#define YYMAXUTOK 260
+
+#define YYTRANSLATE(YYX) \
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
+static const yytype_uint8 yytranslate[] =
+{
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 6, 2, 7, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
+ 5
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+ YYRHS. */
+static const yytype_uint8 yyprhs[] =
+{
+ 0, 0, 3, 5, 7, 9, 12, 14, 16, 17,
+ 18, 24, 27, 31
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+static const yytype_int8 yyrhs[] =
+{
+ 9, 0, -1, 12, -1, 13, -1, 15, -1, 11,
+ 10, -1, 10, -1, 11, -1, -1, -1, 16, 14,
+ 6, 12, 7, -1, 16, 4, -1, 16, 3, 5,
+ -1, 5, -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
+static const yytype_uint8 yyrline[] =
+{
+ 0, 50, 50, 52, 53, 56, 57, 60, 60, 62,
+ 62, 64, 66, 67
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ "$end", "error", "$undefined", "SEP", "DATA", "IDENT", "'{'", "'}'",
+ "$accept", "main", "decl", "decls", "dseq", "group", "@1", "option",
+ "path", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+ token YYLEX-NUM. */
+static const yytype_uint16 yytoknum[] =
+{
+ 0, 256, 257, 258, 259, 260, 123, 125
+};
+# endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
+static const yytype_uint8 yyr1[] =
+{
+ 0, 8, 9, 10, 10, 11, 11, 12, 12, 14,
+ 13, 15, 16, 16
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
+static const yytype_uint8 yyr2[] =
+{
+ 0, 2, 1, 1, 1, 2, 1, 1, 0, 0,
+ 5, 2, 3, 1
+};
+
+/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+ STATE-NUM when YYTABLE doesn't specify something else to do. Zero
+ means the default is an error. */
+static const yytype_uint8 yydefact[] =
+{
+ 8, 13, 0, 6, 7, 2, 3, 4, 9, 1,
+ 5, 0, 11, 0, 12, 8, 0, 10
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const yytype_int8 yydefgoto[] =
+{
+ -1, 2, 3, 4, 5, 6, 13, 7, 8
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+#define YYPACT_NINF -11
+static const yytype_int8 yypact[] =
+{
+ -2, -11, 2, -11, -2, -11, -11, -11, -3, -11,
+ -11, -1, -11, 0, -11, -2, 1, -11
+};
+
+/* YYPGOTO[NTERM-NUM]. */
+static const yytype_int8 yypgoto[] =
+{
+ -11, -11, 3, -11, -10, -11, -11, -11, -11
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule which
+ number is the opposite. If zero, do what YYDEFACT says.
+ If YYTABLE_NINF, syntax error. */
+#define YYTABLE_NINF -1
+static const yytype_uint8 yytable[] =
+{
+ 11, 12, 9, 1, 14, 16, 15, 10, 17
+};
+
+static const yytype_uint8 yycheck[] =
+{
+ 3, 4, 0, 5, 5, 15, 6, 4, 7
+};
+
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+static const yytype_uint8 yystos[] =
+{
+ 0, 5, 9, 10, 11, 12, 13, 15, 16, 0,
+ 10, 3, 4, 14, 5, 6, 12, 7
+};
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY (-2)
+#define YYEOF 0
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+
+
+/* Like YYERROR except do call yyerror. This remains here temporarily
+ to ease the transition to the new meaning of YYERROR, for GCC.
+ Once GCC version 2 has supplanted version 1, this can go. */
+
+#define YYFAIL goto yyerrlab
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY && yylen == 1) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ yytoken = YYTRANSLATE (yychar); \
+ YYPOPSTACK (1); \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror (YY_("syntax error: cannot back up")); \
+ YYERROR; \
+ } \
+while (YYID (0))
+
+
+#define YYTERROR 1
+#define YYERRCODE 256
+
+
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (YYID (N)) \
+ { \
+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
+ } \
+ else \
+ { \
+ (Current).first_line = (Current).last_line = \
+ YYRHSLOC (Rhs, 0).last_line; \
+ (Current).first_column = (Current).last_column = \
+ YYRHSLOC (Rhs, 0).last_column; \
+ } \
+ while (YYID (0))
+#endif
+
+
+/* YY_LOCATION_PRINT -- Print the location on the stream.
+ This macro was not mandated originally: define only if we know
+ we won't break user code: when these are the locations we know. */
+
+#ifndef YY_LOCATION_PRINT
+# if YYLTYPE_IS_TRIVIAL
+# define YY_LOCATION_PRINT(File, Loc) \
+ fprintf (File, "%d.%d-%d.%d", \
+ (Loc).first_line, (Loc).first_column, \
+ (Loc).last_line, (Loc).last_column)
+# else
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+# endif
+#endif
+
+
+/* YYLEX -- calling `yylex' with the right arguments. */
+
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (YYLEX_PARAM)
+#else
+# define YYLEX yylex ()
+#endif
+
+/* Enable debugging if requested. */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (YYID (0))
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yy_symbol_print (stderr, \
+ Type, Value); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (YYID (0))
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+#else
+static void
+yy_symbol_value_print (yyoutput, yytype, yyvaluep)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+#endif
+{
+ if (!yyvaluep)
+ return;
+# ifdef YYPRINT
+ if (yytype < YYNTOKENS)
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# else
+ YYUSE (yyoutput);
+# endif
+ switch (yytype)
+ {
+ default:
+ break;
+ }
+}
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
+#else
+static void
+yy_symbol_print (yyoutput, yytype, yyvaluep)
+ FILE *yyoutput;
+ int yytype;
+ YYSTYPE const * const yyvaluep;
+#endif
+{
+ if (yytype < YYNTOKENS)
+ YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+ else
+ YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+ yy_symbol_value_print (yyoutput, yytype, yyvaluep);
+ YYFPRINTF (yyoutput, ")");
+}
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
+#else
+static void
+yy_stack_print (bottom, top)
+ yytype_int16 *bottom;
+ yytype_int16 *top;
+#endif
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (; bottom <= top; ++bottom)
+ YYFPRINTF (stderr, " %d", *bottom);
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (YYID (0))
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
+#else
+static void
+yy_reduce_print (yyvsp, yyrule)
+ YYSTYPE *yyvsp;
+ int yyrule;
+#endif
+{
+ int yynrhs = yyr2[yyrule];
+ int yyi;
+ unsigned long int yylno = yyrline[yyrule];
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
+ yyrule - 1, yylno);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++)
+ {
+ fprintf (stderr, " $%d = ", yyi + 1);
+ yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
+ &(yyvsp[(yyi + 1) - (yynrhs)])
+ );
+ fprintf (stderr, "\n");
+ }
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (yyvsp, Rule); \
+} while (YYID (0))
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+\f
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+# if defined __GLIBC__ && defined _STRING_H
+# define yystrlen strlen
+# else
+/* Return the length of YYSTR. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static YYSIZE_T
+yystrlen (const char *yystr)
+#else
+static YYSIZE_T
+yystrlen (yystr)
+ const char *yystr;
+#endif
+{
+ YYSIZE_T yylen;
+ for (yylen = 0; yystr[yylen]; yylen++)
+ continue;
+ return yylen;
+}
+# endif
+# endif
+
+# ifndef yystpcpy
+# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static char *
+yystpcpy (char *yydest, const char *yysrc)
+#else
+static char *
+yystpcpy (yydest, yysrc)
+ char *yydest;
+ const char *yysrc;
+#endif
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+ quotes and backslashes, so that it's suitable for yyerror. The
+ heuristic is that double-quoting is unnecessary unless the string
+ contains an apostrophe, a comma, or backslash (other than
+ backslash-backslash). YYSTR is taken from yytname. If YYRES is
+ null, do not copy; instead, return the length of what the result
+ would have been. */
+static YYSIZE_T
+yytnamerr (char *yyres, const char *yystr)
+{
+ if (*yystr == '"')
+ {
+ YYSIZE_T yyn = 0;
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ /* Fall through. */
+ default:
+ if (yyres)
+ yyres[yyn] = *yyp;
+ yyn++;
+ break;
+
+ case '"':
+ if (yyres)
+ yyres[yyn] = '\0';
+ return yyn;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ if (! yyres)
+ return yystrlen (yystr);
+
+ return yystpcpy (yyres, yystr) - yyres;
+}
+# endif
+
+/* Copy into YYRESULT an error message about the unexpected token
+ YYCHAR while in state YYSTATE. Return the number of bytes copied,
+ including the terminating null byte. If YYRESULT is null, do not
+ copy anything; just return the number of bytes that would be
+ copied. As a special case, return 0 if an ordinary "syntax error"
+ message will do. Return YYSIZE_MAXIMUM if overflow occurs during
+ size calculation. */
+static YYSIZE_T
+yysyntax_error (char *yyresult, int yystate, int yychar)
+{
+ int yyn = yypact[yystate];
+
+ if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
+ return 0;
+ else
+ {
+ int yytype = YYTRANSLATE (yychar);
+ YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
+ YYSIZE_T yysize = yysize0;
+ YYSIZE_T yysize1;
+ int yysize_overflow = 0;
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ int yyx;
+
+# if 0
+ /* This is so xgettext sees the translatable formats that are
+ constructed on the fly. */
+ YY_("syntax error, unexpected %s");
+ YY_("syntax error, unexpected %s, expecting %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s");
+ YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
+# endif
+ char *yyfmt;
+ char const *yyf;
+ static char const yyunexpected[] = "syntax error, unexpected %s";
+ static char const yyexpecting[] = ", expecting %s";
+ static char const yyor[] = " or %s";
+ char yyformat[sizeof yyunexpected
+ + sizeof yyexpecting - 1
+ + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
+ * (sizeof yyor - 1))];
+ char const *yyprefix = yyexpecting;
+
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn + 1;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+ int yycount = 1;
+
+ yyarg[0] = yytname[yytype];
+ yyfmt = yystpcpy (yyformat, yyunexpected);
+
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+ {
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ yysize = yysize0;
+ yyformat[sizeof yyunexpected - 1] = '\0';
+ break;
+ }
+ yyarg[yycount++] = yytname[yyx];
+ yysize1 = yysize + yytnamerr (0, yytname[yyx]);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+ yyfmt = yystpcpy (yyfmt, yyprefix);
+ yyprefix = yyor;
+ }
+
+ yyf = YY_(yyformat);
+ yysize1 = yysize + yystrlen (yyf);
+ yysize_overflow |= (yysize1 < yysize);
+ yysize = yysize1;
+
+ if (yysize_overflow)
+ return YYSIZE_MAXIMUM;
+
+ if (yyresult)
+ {
+ /* Avoid sprintf, as that infringes on the user's name space.
+ Don't have undefined behavior even if the translation
+ produced a string with the wrong number of "%s"s. */
+ char *yyp = yyresult;
+ int yyi = 0;
+ while ((*yyp = *yyf) != '\0')
+ {
+ if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
+ {
+ yyp += yytnamerr (yyp, yyarg[yyi++]);
+ yyf += 2;
+ }
+ else
+ {
+ yyp++;
+ yyf++;
+ }
+ }
+ }
+ return yysize;
+ }
+}
+#endif /* YYERROR_VERBOSE */
+\f
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+/*ARGSUSED*/
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static void
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
+#else
+static void
+yydestruct (yymsg, yytype, yyvaluep)
+ const char *yymsg;
+ int yytype;
+ YYSTYPE *yyvaluep;
+#endif
+{
+ YYUSE (yyvaluep);
+
+ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+ switch (yytype)
+ {
+
+ default:
+ break;
+ }
+}
+\f
+
+/* Prevent warnings from -Wmissing-prototypes. */
+
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+
+
+/* The look-ahead symbol. */
+int yychar;
+
+/* The semantic value of the look-ahead symbol. */
+YYSTYPE yylval;
+
+/* Number of syntax errors so far. */
+int yynerrs;
+
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (void *YYPARSE_PARAM)
+#else
+int
+yyparse (YYPARSE_PARAM)
+ void *YYPARSE_PARAM;
+#endif
+#else /* ! YYPARSE_PARAM */
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+int
+yyparse (void)
+#else
+int
+yyparse ()
+
+#endif
+#endif
+{
+
+ int yystate;
+ int yyn;
+ int yyresult;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+ /* Look-ahead token as an internal (translated) token number. */
+ int yytoken = 0;
+#if YYERROR_VERBOSE
+ /* Buffer for error messages, and its allocated size. */
+ char yymsgbuf[128];
+ char *yymsg = yymsgbuf;
+ YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+#endif
+
+ /* Three stacks and their tools:
+ `yyss': related to states,
+ `yyvs': related to semantic values,
+ `yyls': related to locations.
+
+ Refer to the stacks thru separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ yytype_int16 yyssa[YYINITDEPTH];
+ yytype_int16 *yyss = yyssa;
+ yytype_int16 *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs = yyvsa;
+ YYSTYPE *yyvsp;
+
+
+
+#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
+
+ YYSIZE_T yystacksize = YYINITDEPTH;
+
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+
+
+ /* The number of symbols on the RHS of the reduced rule.
+ Keep to zero when no symbol should be popped. */
+ int yylen = 0;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ /* Initialize stack pointers.
+ Waste one element of value and location stack
+ so that they stay on the same level as the state stack.
+ The wasted elements are never initialized. */
+
+ yyssp = yyss;
+ yyvsp = yyvs;
+
+ goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+ yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here evens the stacks. */
+ yyssp++;
+
+ yysetstate:
+ *yyssp = yystate;
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ yytype_int16 *yyss1 = yyss;
+
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow (YY_("memory exhausted"),
+ &yyss1, yysize * sizeof (*yyssp),
+ &yyvs1, yysize * sizeof (*yyvsp),
+
+ &yystacksize);
+
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+ goto yyexhaustedlab;
+# else
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyexhaustedlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ yytype_int16 *yyss1 = yyss;
+ union yyalloc *yyptr =
+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+ if (! yyptr)
+ goto yyexhaustedlab;
+ YYSTACK_RELOCATE (yyss);
+ YYSTACK_RELOCATE (yyvs);
+
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
+
+
+ YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+ (unsigned long int) yystacksize));
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+ goto yybackup;
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+
+ /* Do appropriate processing given the current state. Read a
+ look-ahead token if we need one and don't already have one. */
+
+ /* First try to decide what to do without reference to look-ahead token. */
+ yyn = yypact[yystate];
+ if (yyn == YYPACT_NINF)
+ goto yydefault;
+
+ /* Not known => get a look-ahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = YYLEX;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yyn == 0 || yyn == YYTABLE_NINF)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ /* Shift the look-ahead token. */
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+
+ /* Discard the shifted token unless it is eof. */
+ if (yychar != YYEOF)
+ yychar = YYEMPTY;
+
+ yystate = yyn;
+ *++yyvsp = yylval;
+
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ `$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+
+ YY_REDUCE_PRINT (yyn);
+ switch (yyn)
+ {
+ case 9:
+
+ { group_open(); ;}
+ break;
+
+ case 10:
+
+ { group_close(); ;}
+ break;
+
+ case 11:
+
+ { lc_opt_set(); ;}
+ break;
+
+ case 12:
+
+ { path_push((yyvsp[(3) - (3)].text)); ;}
+ break;
+
+ case 13:
+
+ { path_push((yyvsp[(1) - (1)].text)); ;}
+ break;
+
+
+/* Line 1267 of yacc.c. */
+
+ default: break;
+ }
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
+
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+
+ *++yyvsp = yyval;
+
+
+ /* Now `shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
+
+ goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+#if ! YYERROR_VERBOSE
+ yyerror (YY_("syntax error"));
+#else
+ {
+ YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
+ if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
+ {
+ YYSIZE_T yyalloc = 2 * yysize;
+ if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
+ yyalloc = YYSTACK_ALLOC_MAXIMUM;
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+ yymsg = (char *) YYSTACK_ALLOC (yyalloc);
+ if (yymsg)
+ yymsg_alloc = yyalloc;
+ else
+ {
+ yymsg = yymsgbuf;
+ yymsg_alloc = sizeof yymsgbuf;
+ }
+ }
+
+ if (0 < yysize && yysize <= yymsg_alloc)
+ {
+ (void) yysyntax_error (yymsg, yystate, yychar);
+ yyerror (yymsg);
+ }
+ else
+ {
+ yyerror (YY_("syntax error"));
+ if (yysize != 0)
+ goto yyexhaustedlab;
+ }
+ }
+#endif
+ }
+
+
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse look-ahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == YYEOF)
+ YYABORT;
+ }
+ else
+ {
+ yydestruct ("Error: discarding",
+ yytoken, &yylval);
+ yychar = YYEMPTY;
+ }
+ }
+
+ /* Else will try to reuse look-ahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (/*CONSTCOND*/ 0)
+ goto yyerrorlab;
+
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYERROR. */
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (yyn != YYPACT_NINF)
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+
+ yydestruct ("Error: popping",
+ yystos[yystate], yyvsp);
+ YYPOPSTACK (1);
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }
+
+ if (yyn == YYFINAL)
+ YYACCEPT;
+
+ *++yyvsp = yylval;
+
+
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+#ifndef yyoverflow
+/*-------------------------------------------------.
+| yyexhaustedlab -- memory exhaustion comes here. |
+`-------------------------------------------------*/
+yyexhaustedlab:
+ yyerror (YY_("memory exhausted"));
+ yyresult = 2;
+ /* Fall through. */
+#endif
+
+yyreturn:
+ if (yychar != YYEOF && yychar != YYEMPTY)
+ yydestruct ("Cleanup: discarding lookahead",
+ yytoken, &yylval);
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYABORT or YYACCEPT. */
+ YYPOPSTACK (yylen);
+ YY_STACK_PRINT (yyss, yyssp);
+ while (yyssp != yyss)
+ {
+ yydestruct ("Cleanup: popping",
+ yystos[*yyssp], yyvsp);
+ YYPOPSTACK (1);
+ }
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif
+#if YYERROR_VERBOSE
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+#endif
+ /* Make sure YYID is used. */
+ return YYID (yyresult);
+}
+
+
+
+
+
+static lc_opt_error_handler_t *handler;
+static struct obstack obst;
+const char *optfilename = "";
+
+void PMANGLE(error)(const char *str)
+{
+ fprintf(stderr, "At line %d: %s\n", PMANGLE(linenr), str);
+}
+
+static const char *path_stack[128];
+static int path_sp = 0;
+
+static lc_opt_entry_t *grp_stack[128];
+static int grp_sp = 0;
+#define CURR_GRP (grp_stack[grp_sp - 1])
+
+void lc_opt_init_parser(const char *filename, lc_opt_error_handler_t *err_handler)
+{
+ PMANGLE(linenr) = 1;
+ obstack_init(&obst);
+ handler = err_handler;
+ optfilename = filename;
+ grp_stack[grp_sp++] = lc_opt_root_grp();
+}
+
+void _lc_opt_add_to_data_char(char c)
+{
+ obstack_1grow(&obst, c);
+}
+
+static void path_push(text_t text)
+{
+ obstack_grow0(&obst, text.str, text.len);
+ path_stack[path_sp++] = obstack_finish(&obst);
+}
+
+static void path_free(void)
+{
+ obstack_free(&obst, (void *) path_stack[0]);
+ path_sp = 0;
+}
+
+static void group_open(void)
+{
+ lc_opt_err_info_t err;
+ lc_opt_entry_t *grp = lc_opt_resolve_grp(CURR_GRP, path_stack, path_sp, &err);
+
+ path_free();
+
+ grp_stack[grp_sp++] = grp;
+}
+
+static void group_close(void)
+{
+ grp_sp--;
+}
+
+static void lc_opt_set(void)
+{
+ char *str = obstack_finish(&obst);
+
+ lc_opt_err_info_t err;
+ lc_opt_entry_t *opt = lc_opt_resolve_opt(CURR_GRP, path_stack, path_sp, &err);
+ lc_opt_raise_error(&err, handler, "At %s(%d): ", optfilename, PMANGLE(linenr));
+
+ lc_opt_occurs(opt, str, &err);
+ lc_opt_raise_error(&err, handler, "At %s(%d): ", optfilename, PMANGLE(linenr));
+
+ obstack_free(&obst, str);
+ path_free();
+}
--- /dev/null
+/* A Bison parser, made by GNU Bison 2.3. */
+
+/* Skeleton interface for Bison's Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+ SEP = 258,
+ DATA = 259,
+ IDENT = 260
+ };
+#endif
+/* Tokens. */
+#define SEP 258
+#define DATA 259
+#define IDENT 260
+
+
+
+
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+typedef union YYSTYPE
+
+{
+ text_t text;
+ int num;
+}
+/* Line 1489 of yacc.c. */
+
+ YYSTYPE;
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+extern YYSTYPE _lc_opt_lval;
--- /dev/null
+
+%name-prefix="_lc_opt_"
+
+%{
+
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include <string.h>
+
+#include "lc_opts_t.h"
+#include "lc_parser_t.h"
+
+static void group_open(void);
+static void group_close(void);
+static void lc_opt_set(void);
+static void path_push(text_t text);
+
+void PMANGLE(error)(const char *str);
+int PMANGLE(linenr);
+
+%}
+
+%union {
+ text_t text;
+ int num;
+}
+
+%token SEP DATA
+%token <text> IDENT
+
+%%
+
+main: dseq ;
+
+decl: group
+ | option
+ ;
+
+decls: decls decl
+ | decl
+ ;
+
+dseq: decls | ;
+
+group: path { group_open(); } '{' dseq '}' { group_close(); } ;
+
+option: path DATA { lc_opt_set(); } ;
+
+path: path SEP IDENT { path_push($3); }
+ | IDENT { path_push($1); }
+ ;
+
+%%
+
+static lc_opt_error_handler_t *handler;
+static struct obstack obst;
+const char *optfilename = "";
+
+void PMANGLE(error)(const char *str)
+{
+ fprintf(stderr, "At line %d: %s\n", PMANGLE(linenr), str);
+}
+
+static const char *path_stack[128];
+static int path_sp = 0;
+
+static lc_opt_entry_t *grp_stack[128];
+static int grp_sp = 0;
+#define CURR_GRP (grp_stack[grp_sp - 1])
+
+void lc_opt_init_parser(const char *filename, lc_opt_error_handler_t *err_handler)
+{
+ PMANGLE(linenr) = 1;
+ obstack_init(&obst);
+ handler = err_handler;
+ optfilename = filename;
+ grp_stack[grp_sp++] = lc_opt_root_grp();
+}
+
+void _lc_opt_add_to_data_char(char c)
+{
+ obstack_1grow(&obst, c);
+}
+
+static void path_push(text_t text)
+{
+ obstack_grow0(&obst, text.str, text.len);
+ path_stack[path_sp++] = obstack_finish(&obst);
+}
+
+static void path_free(void)
+{
+ obstack_free(&obst, (void *) path_stack[0]);
+ path_sp = 0;
+}
+
+static void group_open(void)
+{
+ lc_opt_err_info_t err;
+ lc_opt_entry_t *grp = lc_opt_resolve_grp(CURR_GRP, path_stack, path_sp, &err);
+
+ path_free();
+
+ grp_stack[grp_sp++] = grp;
+}
+
+static void group_close(void)
+{
+ grp_sp--;
+}
+
+static void lc_opt_set(void)
+{
+ char *str = obstack_finish(&obst);
+
+ lc_opt_err_info_t err;
+ lc_opt_entry_t *opt = lc_opt_resolve_opt(CURR_GRP, path_stack, path_sp, &err);
+ lc_opt_raise_error(&err, handler, "At %s(%d): ", optfilename, PMANGLE(linenr));
+
+ lc_opt_occurs(opt, str, &err);
+ lc_opt_raise_error(&err, handler, "At %s(%d): ", optfilename, PMANGLE(linenr));
+
+ obstack_free(&obst, str);
+ path_free();
+}
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+/**
+ * Some common defines.
+ * @author Sebastian Hack
+ * @date 22.12.2004
+ */
+
+#ifndef _LIBCORE_DEFINES_H
+#define _LIBCORE_DEFINES_H
+
+#define LC_ARRSIZE(x) (sizeof(x) / sizeof(x[0]))
+
+#define LC_MIN(x,y) ((x) < (y) ? (x) : (y))
+#define LC_MAX(x,y) ((x) > (y) ? (x) : (y))
+
+/** define a readable fourcc code */
+#define LC_FOURCC(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
+#define LC_FOURCC_STR(str) LC_FOURCC(str[0], str[1], str[2], str[3])
+
+#define LC_OFFSETOF(type,memb) ((char *) &((type *) 0)->memb - (char *) 0)
+
+#ifdef __GNUC__
+#define LC_ALIGNOF(type) __alignof__(type)
+#else
+#define LC_ALIGNOF(type) LC_OFFSETOF(struct { char c; type d; }, d)
+#endif
+
+#define LC_PTR2INT(x) (((char *)(x)) - (char *)0)
+#define LC_INT2PTR(x) (((char *)(x)) + (char *)0)
+
+#endif
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
+
+#if defined(__FreeBSD__)
+#include <stdlib.h>
+#elif defined(_WIN32)
+#include <malloc.h>
+#else
+#include <alloca.h>
+#endif
+
+/* Includes to determine user's home directory */
+#ifdef _WIN32
+#include <shlobj.h>
+#else
+#include <sys/types.h>
+#include <unistd.h>
+#include <pwd.h>
+#endif
+
+/* maximum length of a path. */
+#ifndef MAX_PATH
+#define MAX_PATH 2048
+#endif
+
+
+#include "lc_common_t.h"
+#include "lc_opts_t.h"
+#include "lc_opts_enum.h"
+#include "lc_parser_t.h"
+#include "hashptr.h"
+#include "lc_printf.h"
+
+#define ERR_STRING "In argument \"%s\": "
+
+#define OPT_DELIM '-'
+
+#define HELP_TEMPL "%-15s %-10s %-45s"
+#define HELP_TEMPL_VALS HELP_TEMPL " [%s] (%s)"
+
+static struct obstack obst;
+
+static void set_name(lc_opt_entry_t *ent, const char *name)
+{
+ ent->name = name;
+ ent->hash = HASH_STR(name, strlen(name));
+}
+
+#define entry_matches(ent,hash_val,str) \
+ ((ent)->hash == hash_val && strcmp((ent)->name, (str)) == 0)
+
+#define entries_equal(e1,e2) entry_matches(e1, (e2)->hash, (e2)->name)
+
+static lc_opt_err_info_t *set_error(lc_opt_err_info_t *err, int error, const char *arg)
+{
+ if(err) {
+ err->error = error;
+ err->msg = "";
+ err->arg = arg;
+ }
+
+ return err;
+}
+
+int lc_opt_raise_error(const lc_opt_err_info_t *err, lc_opt_error_handler_t *handler,
+ const char *fmt, ...)
+{
+ va_list args;
+ int res = 0;
+
+ va_start(args, fmt);
+ if(err && lc_opt_is_error(err)) {
+ res = 1;
+ if(handler) {
+ char buf[256];
+ vsnprintf(buf, sizeof(buf), fmt, args);
+ handler(buf, err);
+ }
+ }
+ va_end(args);
+
+ return res;
+}
+
+static lc_opt_entry_t *init_entry(lc_opt_entry_t *ent, lc_opt_entry_t *parent,
+ const char *name, const char *desc)
+{
+ const char *copied_name;
+ const char *copied_desc;
+
+ obstack_grow0(&obst, name, strlen(name));
+ copied_name = obstack_finish(&obst);
+ obstack_grow0(&obst, desc, strlen(desc));
+ copied_desc = obstack_finish(&obst);
+
+ memset(ent, 0, sizeof(*ent));
+ set_name(ent, copied_name);
+ ent->desc = copied_desc;
+ ent->parent = parent;
+ return ent;
+}
+
+static lc_opt_entry_t *init_grp(lc_opt_entry_t *ent, lc_opt_err_info_t *err)
+{
+ ent->is_grp = 1;
+ INIT_LIST_HEAD(&ent->v.grp.grps);
+ INIT_LIST_HEAD(&ent->v.grp.opts);
+
+ set_error(err, lc_opt_err_none, "");
+ if(ent->parent) {
+ if(ent->parent->is_grp)
+ list_add(&ent->list, &lc_get_grp_special(ent->parent)->grps);
+ else
+ set_error(err, lc_opt_err_grp_expected, ent->parent->name);
+ }
+
+ return ent;
+}
+
+static lc_opt_entry_t *init_opt(lc_opt_entry_t *ent,
+ lc_opt_type_t type,
+ void *val, size_t length,
+ lc_opt_callback_t *cb,
+ lc_opt_dump_t *dump,
+ lc_opt_dump_vals_t *dump_vals,
+ lc_opt_err_info_t *err)
+{
+ lc_opt_special_t *s = lc_get_opt_special(ent);
+
+ ent->is_grp = 0;
+ set_error(err, lc_opt_err_none, "");
+ list_add(&ent->list, &lc_get_grp_special(ent->parent)->opts);
+
+ s->type = type;
+ s->value = val;
+ s->cb = cb;
+ s->dump = dump;
+ s->dump_vals = dump_vals;
+ s->length = length;
+
+ return ent;
+}
+
+
+lc_opt_entry_t *lc_opt_root_grp(void)
+{
+ static lc_opt_entry_t root_group;
+ static int inited = 0;
+
+ if(!inited) {
+ obstack_init(&obst);
+ inited = 1;
+
+ init_entry(&root_group, NULL, "root", "The root node");
+ init_grp(&root_group, NULL);
+ }
+
+ return &root_group;
+}
+
+int lc_opt_grp_is_root(const lc_opt_entry_t *ent)
+{
+ return ent->parent == NULL;
+}
+
+static const char *get_type_name(lc_opt_type_t type)
+{
+ const char *res;
+
+#define XXX(t) case lc_opt_type_ ## t: res = #t; break
+ switch(type) {
+ XXX(enum);
+ XXX(bit);
+ XXX(int);
+ XXX(double);
+ XXX(boolean);
+ XXX(string);
+ case lc_opt_type_negbit: res = "bit"; break;
+ case lc_opt_type_negboolean: res = "boolean"; break;
+ default:
+ res = "<none>";
+ }
+#undef XXX
+
+ return res;
+}
+
+const char *lc_opt_get_type_name(const lc_opt_entry_t *ent)
+{
+ return get_type_name(lc_get_opt_special(ent)->type);
+}
+
+
+lc_opt_entry_t *lc_opt_find_grp(const lc_opt_entry_t *grp, const char *name, lc_opt_err_info_t *err);
+lc_opt_entry_t *lc_opt_find_opt(const lc_opt_entry_t *grp, const char *name, lc_opt_err_info_t *err);
+
+lc_opt_entry_t *lc_opt_get_grp(lc_opt_entry_t *parent, const char *name)
+{
+ lc_opt_entry_t *ent = lc_opt_find_grp(parent, name, NULL);
+
+ if(!ent) {
+ ent = obstack_alloc(&obst, sizeof(*ent));
+ init_entry(ent, parent, name, "");
+ init_grp(ent, NULL);
+ }
+
+ return ent;
+}
+
+lc_opt_entry_t *lc_opt_add_opt(lc_opt_entry_t *parent,
+ const char *name, const char *desc,
+ lc_opt_type_t type, void *value, size_t length,
+ lc_opt_callback_t *cb, lc_opt_dump_t *dump,
+ lc_opt_dump_vals_t *dump_vals,
+ lc_opt_err_info_t *err)
+{
+ lc_opt_entry_t *res = NULL;
+
+ if(parent->is_grp) {
+ lc_opt_entry_t *ent = lc_opt_find_opt(parent, name, NULL);
+
+ if(!ent) {
+ res = obstack_alloc(&obst, sizeof(*ent));
+ init_entry(res, parent, name, desc);
+ init_opt(res, type, value, length, cb, dump, dump_vals, err);
+ } else
+ set_error(err, lc_opt_err_opt_already_there, name);
+ } else
+ set_error(err, lc_opt_err_grp_expected, name);
+
+ return res;
+}
+
+
+static lc_opt_entry_t *lc_opt_find_ent(const struct list_head *head, const char *name,
+ int error_to_use, lc_opt_err_info_t *err)
+{
+ lc_opt_entry_t *ent, *found = NULL;
+ int error = error_to_use;
+ unsigned hash = HASH_STR(name, strlen(name));
+
+ if(!list_empty(head)) {
+ list_for_each_entry(lc_opt_entry_t, ent, head, list) {
+ if(entry_matches(ent, hash, name)) {
+ error = lc_opt_err_none;
+ found = ent;
+ break;
+ }
+ }
+ }
+
+ set_error(err, error, name);
+ return found;
+}
+
+lc_opt_entry_t *lc_opt_find_grp(const lc_opt_entry_t *grp, const char *name, lc_opt_err_info_t *err)
+{
+ return grp ? lc_opt_find_ent(&lc_get_grp_special(grp)->grps,
+ name, lc_opt_err_grp_not_found, err) : NULL;
+}
+
+lc_opt_entry_t *lc_opt_find_opt(const lc_opt_entry_t *grp, const char *name, lc_opt_err_info_t *err)
+{
+ return grp ? lc_opt_find_ent(&lc_get_grp_special(grp)->opts,
+ name, lc_opt_err_opt_not_found, err) : NULL;
+}
+
+static const lc_opt_entry_t *resolve_up_to_last(const lc_opt_entry_t *root,
+ const char * const *names, int pos, int n, lc_opt_err_info_t *err)
+{
+ lc_opt_entry_t *ent;
+
+ if(pos == n)
+ return root;
+
+ ent = lc_opt_find_grp(root, names[pos], err);
+ return ent ? resolve_up_to_last(ent, names, pos + 1, n, err) : NULL;
+}
+
+static const char *path_delim = "/.";
+
+static lc_opt_entry_t *resolve_up_to_last_str_rec(lc_opt_entry_t *from,
+ const char *path,
+ const char **last_name)
+{
+
+ lc_opt_entry_t *res = from;
+ size_t end = strcspn(path, path_delim);
+
+ if(path[end] != '\0') {
+ /* skip all delimiters */
+ size_t next = strspn(path + end, path_delim);
+
+ /* copy the part of the path into a buffer */
+ char *buf = malloc((end+1) * sizeof(buf[0]));
+ strncpy(buf, path, end);
+ buf[end] = '\0';
+
+ /* resolve the group and free */
+ from = lc_opt_get_grp(from, buf);
+ free(buf);
+
+ res = resolve_up_to_last_str_rec(from, path + end + next, last_name);
+ }
+
+ else if(last_name != NULL) {
+ *last_name = path;
+ }
+
+ return res;
+}
+
+static lc_opt_entry_t *resolve_up_to_last_str(lc_opt_entry_t *root, const char *path, const char **last_name)
+{
+ size_t next = strspn(path, path_delim);
+
+ /* if l != 0 we saw deliminators, so we resolve from the root */
+ if(next > 0)
+ root = lc_opt_root_grp();
+
+ return resolve_up_to_last_str_rec(root, path + next, last_name);
+}
+
+lc_opt_entry_t *lc_opt_resolve_grp(const lc_opt_entry_t *root,
+ const char * const *names, int n, lc_opt_err_info_t *err)
+{
+ const lc_opt_entry_t *grp = resolve_up_to_last(root, names, 0, n - 1, err);
+ return lc_opt_find_grp(grp, names[n - 1], err);
+}
+
+lc_opt_entry_t *lc_opt_resolve_opt(const lc_opt_entry_t *root,
+ const char * const *names, int n, lc_opt_err_info_t *err)
+{
+ const lc_opt_entry_t *grp = resolve_up_to_last(root, names, 0, n - 1, err);
+ return lc_opt_find_opt(grp, names[n - 1], err);
+}
+
+static char *strtolower(char *buf, size_t n, const char *str)
+{
+ unsigned i;
+ for(i = 0; i < n; ++i)
+ buf[i] = tolower(str[i]);
+ return buf;
+}
+
+int lc_opt_std_cb(UNUSED(const char *name), lc_opt_type_t type, void *data, size_t length, ...)
+{
+ va_list args;
+ int res = 0;
+ int integer;
+
+ va_start(args, length);
+
+ if(data) {
+ res = 1;
+ switch(type) {
+ case lc_opt_type_bit:
+ integer = va_arg(args, int);
+ if(integer)
+ *((int *) data) |= length;
+ else
+ *((int *) data) &= ~length;
+ break;
+
+ case lc_opt_type_negbit:
+ integer = va_arg(args, int);
+ if(integer)
+ *((int *) data) &= ~length;
+ else
+ *((int *) data) |= length;
+ break;
+
+ case lc_opt_type_boolean:
+ *((int *) data) = va_arg(args, int);
+ break;
+
+ case lc_opt_type_negboolean:
+ *((int *) data) = !va_arg(args, int);
+ break;
+
+ case lc_opt_type_string:
+ strncpy(data, va_arg(args, const char *), length);
+ break;
+
+ case lc_opt_type_int:
+ *((int *) data) = va_arg(args, int);
+ break;
+
+ case lc_opt_type_double:
+ *((double *) data) = va_arg(args, double);
+ break;
+ default:
+ res = 0;
+ }
+ }
+
+ va_end(args);
+ return res;
+}
+
+int lc_opt_std_dump(char *buf, size_t n, UNUSED(const char *name), lc_opt_type_t type, void *data, UNUSED(size_t length))
+{
+ int res;
+
+ if(data) {
+ switch(type) {
+ case lc_opt_type_bit:
+ case lc_opt_type_negbit:
+ res = snprintf(buf, n, "%x", *((int *) data));
+ break;
+ case lc_opt_type_boolean:
+ case lc_opt_type_negboolean:
+ res = snprintf(buf, n, "%s", *((int *) data) ? "true" : "false");
+ break;
+ case lc_opt_type_string:
+ strncpy(buf, data, n);
+ res = n;
+ break;
+ case lc_opt_type_int:
+ res = snprintf(buf, n, "%d", *((int *) data));
+ break;
+ case lc_opt_type_double:
+ res = snprintf(buf, n, "%g", *((double *) data));
+ break;
+ default:
+ strncpy(buf, "", n);
+ res = 0;
+ }
+ }
+
+ else {
+ strncpy(buf, "", n);
+ res = 0;
+ }
+
+ return res;
+}
+
+int lc_opt_bool_dump_vals(char *buf, size_t n, UNUSED(const char *name), UNUSED(lc_opt_type_t type), UNUSED(void *data), UNUSED(size_t length))
+{
+ strncpy(buf, "true, false", n);
+ return n;
+}
+
+int lc_opt_occurs(lc_opt_entry_t *opt, const char *value, lc_opt_err_info_t *err)
+{
+ static const struct {
+ const char *str;
+ int val;
+ } bool_strings[] = {
+ { "yes", 1 },
+ { "true", 1 },
+ { "on", 1 },
+ { "1", 1 },
+ { "no", 0 },
+ { "false", 0 },
+ { "off", 0 },
+ { "0", 0 },
+ };
+
+ unsigned i;
+ int error = lc_opt_err_illegal_format;
+ lc_opt_special_t *s = lc_get_opt_special(opt);
+ char buf[16];
+ union {
+ int integer;
+ double dbl;
+ } val_storage, *val = &val_storage;
+
+ if(!opt) {
+ set_error(err, lc_opt_err_opt_not_found, "");
+ return 0;
+ }
+
+ if(!s->cb) {
+ set_error(err, lc_opt_err_no_callback, "");
+ return 0;
+ }
+
+ s->is_set = 1;
+
+ switch(s->type) {
+ case lc_opt_type_int:
+ if(sscanf(value, "%i", (int *) val)) {
+ error = lc_opt_err_unknown_value;
+ if (s->cb(opt->name, s->type, s->value, s->length, val->integer))
+ error = lc_opt_err_none;
+ }
+ break;
+
+ case lc_opt_type_double:
+ if(sscanf(value, "%lf", (double *) val)) {
+ error = lc_opt_err_unknown_value;
+ if (s->cb(opt->name, s->type, s->value, s->length, val->dbl))
+ error = lc_opt_err_none;
+ }
+ break;
+
+ case lc_opt_type_boolean:
+ case lc_opt_type_negboolean:
+ case lc_opt_type_bit:
+ case lc_opt_type_negbit:
+ strtolower(buf, sizeof(buf), value);
+ for(i = 0; i < LC_ARRSIZE(bool_strings); ++i) {
+ if(strcmp(buf, bool_strings[i].str) == 0) {
+ val->integer = bool_strings[i].val;
+ error = lc_opt_err_none;
+ break;
+ }
+ }
+
+ if (error == lc_opt_err_none) {
+ error = lc_opt_err_unknown_value;
+ if (s->cb(opt->name, s->type, s->value, s->length, val->integer))
+ error = lc_opt_err_none;
+ }
+
+ break;
+
+ case lc_opt_type_string:
+ case lc_opt_type_enum:
+ error = lc_opt_err_unknown_value;
+ if (s->cb(opt->name, s->type, s->value, s->length, value))
+ error = lc_opt_err_none;
+ break;
+ }
+
+ set_error(err, error, value);
+ return error == lc_opt_err_none;
+}
+
+char *lc_opt_value_to_string(char *buf, size_t len, const lc_opt_entry_t *ent)
+{
+ const lc_opt_special_t *s = lc_get_opt_special(ent);
+ if(s->dump)
+ s->dump(buf, len, ent->name, s->type, s->value, s->length);
+ else
+ strncpy(buf, "<n/a>", len);
+
+ return buf;
+}
+
+char *lc_opt_values_to_string(char *buf, size_t len, const lc_opt_entry_t *ent)
+{
+ const lc_opt_special_t *s = lc_get_opt_special(ent);
+ if(s->dump_vals)
+ s->dump_vals(buf, len, ent->name, s->type, s->value, s->length);
+
+ return buf;
+}
+
+static lc_opt_entry_t *resolve_up_to_last_str(lc_opt_entry_t *root, const char *path, const char **last_name);
+
+int lc_opt_add_table(lc_opt_entry_t *root, const lc_opt_table_entry_t *table)
+{
+ int i, res = 0;
+ lc_opt_err_info_t err;
+
+ for(i = 0; table[i].name != NULL; ++i) {
+ const char *name;
+ const lc_opt_table_entry_t *tab = &table[i];
+ lc_opt_entry_t *grp = resolve_up_to_last_str(root, tab->name, &name);
+
+ lc_opt_add_opt(grp, name, tab->desc, tab->type, tab->value, tab->len, tab->cb, tab->dump, tab->dump_vals, &err);
+ if(err.error != lc_opt_err_none)
+ res = 1;
+ }
+
+ return res;
+}
+
+static void lc_opt_print_grp_path_rec(char *buf, size_t len, const lc_opt_entry_t *ent, char separator, lc_opt_entry_t *stop_ent)
+{
+ if (ent == stop_ent)
+ return;
+ if (!lc_opt_grp_is_root(ent)) {
+ size_t l;
+ lc_opt_print_grp_path_rec(buf, len, ent->parent, separator, stop_ent);
+ l = strlen(buf);
+ if (l > 0 && l < len-1) {
+ buf[l] = separator;
+ buf[l + 1] = '\0';
+ }
+ }
+
+ strncat(buf, ent->name, len);
+}
+
+static char *lc_opt_print_grp_path(char *buf, size_t len, const lc_opt_entry_t *ent, char separator, lc_opt_entry_t *stop_ent)
+{
+ if (len > 0)
+ buf[0] = '\0';
+ lc_opt_print_grp_path_rec(buf, len, ent, separator, stop_ent);
+ return buf;
+}
+
+/**
+ * dump the option tree.
+ * @param ent starting entity
+ * @param separator separator char
+ * @param stop_ent stop at this entity when dumping the name
+ * @param f output file
+ */
+static void lc_opt_print_help_rec(lc_opt_entry_t *ent, char separator, lc_opt_entry_t *stop_ent, FILE *f)
+{
+ lc_grp_special_t *s = lc_get_grp_special(ent);
+ char grp_name[512];
+ char value[256];
+ char values[256];
+ lc_opt_entry_t *e;
+
+ if(!list_empty(&s->opts)) {
+ lc_opt_print_grp_path(grp_name, sizeof(grp_name), ent, separator, stop_ent);
+ fputc('\n', f);
+ if (grp_name[0])
+ fprintf(f, "%s:\n", grp_name);
+
+ list_for_each_entry(lc_opt_entry_t, e, &s->opts, list) {
+ value[0] = '\0';
+ values[0] = '\0';
+ lc_opt_value_to_string(value, sizeof(value), e);
+ lc_opt_values_to_string(values, sizeof(values), e);
+ fprintf(f, HELP_TEMPL_VALS "\n", e->name, lc_opt_get_type_name(e), e->desc, value, values);
+ }
+ }
+
+ list_for_each_entry(lc_opt_entry_t, e, &s->grps, list) {
+ lc_opt_print_help_rec(e, separator, stop_ent, f);
+ }
+
+}
+
+void lc_opt_print_help(lc_opt_entry_t *ent, FILE *f)
+{
+ fprintf(f, HELP_TEMPL_VALS "\n", "option", "type", "description", "default", "possible options");
+ lc_opt_print_help_rec(ent, '.', NULL, f);
+}
+
+void lc_opt_print_help_for_entry(lc_opt_entry_t *ent, char separator, FILE *f)
+{
+ fprintf(f, HELP_TEMPL_VALS "\n", "option", "type", "description", "default", "possible options");
+ lc_opt_print_help_rec(ent, separator, ent, f);
+}
+
+
+static void indent(FILE *f, int n)
+{
+ int i;
+ for(i = 0; i < n; ++i)
+ fputc(' ', f);
+}
+
+static void lc_opt_print_tree_lc_opt_indent(lc_opt_entry_t *ent, FILE *f, int level)
+{
+ char buf[256];
+ lc_opt_special_t *s = lc_get_opt_special(ent);
+
+ indent(f, level);
+ fprintf(f, "%c%s(\"%s\"):%s = %s\n", s->is_set ? '+' : '-', ent->name,
+ ent->desc, lc_opt_get_type_name(ent), lc_opt_value_to_string(buf, sizeof(buf), ent));
+}
+
+static void lc_opt_print_tree_grp_indent(lc_opt_entry_t *ent, FILE *f, int level)
+{
+ lc_grp_special_t *s;
+
+ if(ent->is_grp) {
+ lc_opt_entry_t *e;
+
+ s = lc_get_grp_special(ent);
+ indent(f, level);
+ fprintf(f, "/%s\n", ent->name);
+
+ list_for_each_entry(lc_opt_entry_t, e, &s->grps, list) {
+ lc_opt_print_tree_grp_indent(e, f, level + 2);
+ }
+
+ list_for_each_entry(lc_opt_entry_t, e, &s->opts, list) {
+ lc_opt_print_tree_lc_opt_indent(e, f, level + 2);
+ }
+ }
+}
+
+void lc_opt_print_tree(lc_opt_entry_t *ent, FILE *f)
+{
+ lc_opt_print_tree_grp_indent(ent, f, 0);
+}
+
+
+void lc_opt_from_file(const char *filename, FILE *f, lc_opt_error_handler_t *handler)
+{
+ PMANGLE(in) = f;
+ lc_opt_init_parser(filename, handler);
+ PMANGLE(parse)();
+}
+
+int lc_opt_from_single_arg(const lc_opt_entry_t *root,
+ const char *opt_prefix,
+ const char *arg, lc_opt_error_handler_t *handler)
+{
+ const lc_opt_entry_t *grp = root;
+ int n = strlen(arg);
+ int n_prefix = opt_prefix ? strlen(opt_prefix) : 0;
+ int error = 0;
+ int ret = 0;
+
+ lc_opt_err_info_t err;
+ char *end, *buf;
+
+ if(n >= n_prefix && strncmp(opt_prefix, arg, n_prefix) == 0) {
+ arg = arg + n_prefix;
+
+ /*
+ * check, if the next character is a @.
+ * This means, that we want to read options
+ * from a file.
+ */
+ if(arg[0] == '@') {
+ size_t n = strcspn(&arg[1], " \t\n");
+ char *fname = alloca(n + 1);
+ FILE *f;
+
+ strncpy(fname, &arg[1], n);
+ if((f = fopen(fname, "rt")) != NULL) {
+ lc_opt_from_file(fname, f, handler);
+ fclose(f);
+ set_error(&err, lc_opt_err_none, NULL);
+ }
+
+ else
+ set_error(&err, lc_opt_err_file_not_found, arg);
+
+ return !lc_opt_raise_error(&err, handler, "Unable to open file: %s", fname);
+ }
+
+ /* find the next delimiter (the -) and extract the string up to
+ * there. */
+ end = strchr(arg, OPT_DELIM);
+ while(end != NULL) {
+ /*
+ * Copy the part of the option into the buffer and add the
+ * finalizing zero.
+ */
+ buf = obstack_copy0(&obst, arg, end - arg);
+
+ /* Resolve the group inside the group */
+ grp = lc_opt_find_grp(grp, buf, &err);
+ error = lc_opt_raise_error(&err, handler, ERR_STRING, arg);
+ if(error)
+ break;
+
+ /* Find the next option part delimiter. */
+ arg = end + 1;
+ end = strchr(arg, OPT_DELIM);
+ obstack_free(&obst, buf);
+ }
+
+ if(!error) {
+ lc_opt_entry_t *opt;
+
+ /*
+ * Now, we are at the last option part:
+ * --grp1-grp2-...-grpn-opt=value
+ * Check, for the = and evaluate the option string. If the = is
+ * missing, we should have a boolean option, but that is checked
+ * later.
+ */
+ end = strchr(arg, '=');
+ buf = obstack_copy0(&obst, arg, end ? end - arg : (int) strlen(arg));
+ opt = lc_opt_find_opt(grp, buf, &err);
+ error = lc_opt_raise_error(&err, handler, ERR_STRING, arg);
+
+ if(!error) {
+ /*
+ * Now evaluate the parameter of the option (the part after
+ * the =) if it was given.
+ */
+ arg = end ? end + 1 : "true";
+
+ /* Set the value of the option. */
+ lc_opt_occurs(opt, arg, &err);
+ ret = !lc_opt_raise_error(&err, handler, ERR_STRING, arg);
+ }
+ }
+ }
+
+ return ret;
+}
+
+int lc_opt_from_argv(const lc_opt_entry_t *root,
+ const char *opt_prefix,
+ int argc, const char *argv[],
+ lc_opt_error_handler_t *handler)
+{
+ int i;
+ int options_set = 0;
+
+ for(i = 0; i < argc; ++i) {
+ options_set |= lc_opt_from_single_arg(root, opt_prefix, argv[i], handler);
+ }
+
+ return options_set;
+}
+
+static int opt_arg_type(UNUSED(const lc_arg_occ_t *occ))
+{
+ return lc_arg_type_ptr;
+}
+
+static int opt_arg_emit(lc_appendable_t *app, const lc_arg_occ_t *occ, const lc_arg_value_t *arg)
+{
+ char buf[256];
+
+ lc_opt_entry_t *opt = arg->v_ptr;
+ const char *s = buf;
+ size_t res = 0;
+
+ switch(occ->conversion) {
+ case 'V':
+ lc_opt_value_to_string(buf, sizeof(buf), opt);
+ break;
+ case 'T':
+ s = lc_opt_get_type_name(opt);
+ break;
+ case 'D':
+ s = opt->desc;
+ break;
+ case 'O':
+ s = opt->name;
+ break;
+ default:
+ s = NULL;
+ }
+
+ if(s)
+ res = lc_appendable_snadd(app, s, strlen(s));
+
+ return res;
+}
+
+static const lc_arg_handler_t lc_opt_arg_handler = {
+ opt_arg_type,
+ opt_arg_emit
+};
+
+
+/* lc_printf facility for options */
+
+const lc_arg_env_t *lc_opt_get_arg_env(void)
+{
+ static lc_arg_env_t *env = NULL;
+
+ if(!env) {
+ env = lc_arg_new_env();
+
+ lc_arg_register(env, "opt:value", 'V', &lc_opt_arg_handler);
+ lc_arg_register(env, "opt:type", 'T', &lc_opt_arg_handler);
+ lc_arg_register(env, "opt:desc", 'D', &lc_opt_arg_handler);
+ lc_arg_register(env, "opt:name", 'O', &lc_opt_arg_handler);
+ }
+
+ return env;
+}
+
+static int lc_opts_default_error_handler(const char *prefix, const lc_opt_err_info_t *err)
+{
+ fprintf(stderr, "%s: %s; %s\n", prefix, err->msg, err->arg);
+ return 0;
+}
+
+void lc_opts_init(const char *ini_name, lc_opt_entry_t *root, const char *arg_prefix, int argc, const char **argv)
+{
+ FILE *f;
+ char path[MAX_PATH];
+ char local_ini_file[MAX_PATH];
+ char home_dir_ini_file[MAX_PATH];
+
+ /* <cmnt>.ini */
+ strncpy(local_ini_file, ini_name, sizeof(local_ini_file));
+ strncat(local_ini_file, ".ini", sizeof(local_ini_file));
+ local_ini_file[sizeof(local_ini_file) - 1] = '\0';
+ path[0] = '\0';
+
+#ifdef _WIN32
+#if _MSC_VER > 1200
+ /* ARG: need newer SDK to compile this */
+ SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, path);
+ strncat(path, "\\", sizeof(path));
+#endif
+ strncpy(home_dir_ini_file, local_ini_file, sizeof(home_dir_ini_file));
+ home_dir_ini_file[sizeof(home_dir_ini_file) - 1] = '\0';
+#else
+ strcpy(path, getpwuid(getuid())->pw_dir);
+ strncat(path, "/", sizeof(path));
+ /* .<cmnt>rc */
+ snprintf(home_dir_ini_file, sizeof(home_dir_ini_file), ".%src", ini_name);
+ home_dir_ini_file[sizeof(home_dir_ini_file) - 1] = '\0';
+#endif
+
+ strncat(path, home_dir_ini_file, sizeof(path));
+ path[sizeof(path) - 1] = '\0';
+
+ /* Process ini file in user's home. */
+ f = fopen(path, "rt");
+ if (f) {
+ lc_opt_from_file(path, f, lc_opts_default_error_handler);
+ fclose(f);
+ }
+
+ /* Process ini file in current directory. */
+ f = fopen(local_ini_file, "rt");
+ if (f) {
+ lc_opt_from_file(local_ini_file, f, lc_opts_default_error_handler);
+ fclose(f);
+ }
+
+ /* process arguments from the command line */
+ lc_opt_from_argv(root, arg_prefix, argc, argv, lc_opts_default_error_handler);
+}
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/*
+ Option management library.
+ This module can read (typed) options from a config file or
+ parse a command line. The options are managed in a tree structure.
+*/
+
+#ifndef _LC_OPTS_H
+#define _LC_OPTS_H
+
+#include <stdio.h>
+
+#include <libcore/lc_printf.h>
+
+/**
+ * The type of an option.
+ */
+typedef enum {
+ lc_opt_type_enum,
+ lc_opt_type_bit,
+ lc_opt_type_negbit,
+ lc_opt_type_boolean,
+ lc_opt_type_negboolean,
+ lc_opt_type_string,
+ lc_opt_type_int,
+ lc_opt_type_double
+} lc_opt_type_t;
+
+/**
+ * Error codes.
+ */
+typedef enum {
+ lc_opt_err_none = 0,
+ lc_opt_err_no_callback,
+ lc_opt_err_illegal_option_type,
+ lc_opt_err_illegal_format,
+ lc_opt_err_grp_not_found,
+ lc_opt_err_opt_not_found,
+ lc_opt_err_grp_expected,
+ lc_opt_err_opt_already_there,
+ lc_opt_err_file_not_found,
+ lc_opt_err_unknown_value
+} lc_opt_err_t;
+
+typedef struct {
+ int error;
+ const char *msg;
+ const char *arg;
+} lc_opt_err_info_t;
+
+#define lc_opt_is_error(err) ((err)->error != lc_opt_err_none)
+
+typedef struct _lc_opt_entry_t lc_opt_entry_t;
+
+typedef int (lc_opt_callback_t)(const char *name, lc_opt_type_t type, void *data, size_t length, ...);
+
+typedef int (lc_opt_dump_t)(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t length);
+
+typedef int (lc_opt_dump_vals_t)(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t length);
+
+typedef int (lc_opt_error_handler_t)(const char *prefix, const lc_opt_err_info_t *err);
+
+typedef struct {
+ const char *name; /**< The name of the option. */
+ const char *desc; /**< A description for the option. */
+ lc_opt_type_t type; /**< The type of the option (see enum). */
+ void *value; /**< A pointer to the area, where the value
+ of the option shall be put to. May be NULL. */
+
+ size_t len; /**< The amount of bytes available at the
+ location value points to. */
+ lc_opt_callback_t *cb; /**< A callback that is called, when the option is set.
+ This may never be NULL. */
+
+ lc_opt_dump_t *dump; /**< A function which is able to format the options value
+ into a string. May be NULL. */
+
+ lc_opt_dump_vals_t *dump_vals; /**< A function which is able to format the possible values
+ for this option into a string. May be NULL. */
+
+
+} lc_opt_table_entry_t;
+
+#define _LC_OPT_ENT(name, desc, type, value, len, cb, dump, dump_vals) \
+ { name, desc, type, value, len, cb, dump, dump_vals }
+
+#define LC_OPT_ENT_INT(name, desc, addr) \
+ _LC_OPT_ENT(name, desc, lc_opt_type_int, addr, 0, lc_opt_std_cb, lc_opt_std_dump, NULL)
+
+#define LC_OPT_ENT_DBL(name, desc, addr) \
+ _LC_OPT_ENT(name, desc, lc_opt_type_double, addr, 0, lc_opt_std_cb, lc_opt_std_dump, NULL)
+
+#define LC_OPT_ENT_BIT(name, desc, addr, mask) \
+ _LC_OPT_ENT(name, desc, lc_opt_type_bit, addr, mask, lc_opt_std_cb, lc_opt_std_dump, NULL)
+
+#define LC_OPT_ENT_NEGBIT(name, desc, addr, mask) \
+ _LC_OPT_ENT(name, desc, lc_opt_type_negbit, addr, mask, lc_opt_std_cb, lc_opt_std_dump, NULL)
+
+#define LC_OPT_ENT_BOOL(name, desc, addr) \
+ _LC_OPT_ENT(name, desc, lc_opt_type_boolean, addr, 0, lc_opt_std_cb, lc_opt_std_dump, lc_opt_bool_dump_vals)
+
+#define LC_OPT_ENT_NEGBOOL(name, desc, addr) \
+ _LC_OPT_ENT(name, desc, lc_opt_type_negboolean, addr, 0, lc_opt_std_cb, lc_opt_std_dump, lc_opt_bool_dump_vals)
+
+#define LC_OPT_ENT_STR(name, desc, buf, len) \
+ _LC_OPT_ENT(name, desc, lc_opt_type_string, buf, len, lc_opt_std_cb, lc_opt_std_dump, NULL)
+
+#define LC_OPT_ENT_CB(name, desc, type, data, len, cb, dump, dump_vals) \
+ _LC_OPT_ENT(name, desc, type, data, len, cb, dump, dump_vals)
+
+#define LC_OPT_LAST \
+ _LC_OPT_ENT(NULL, NULL, 0, NULL, 0, NULL, NULL, NULL)
+
+/**
+ * Get the root option group.
+ * @return The root option group.
+ */
+lc_opt_entry_t *lc_opt_root_grp(void);
+
+/**
+ * Check, if a group is the root group
+ * @param ent The entry to check for.
+ * @return 1, if the entry is the root group, 0 otherwise.
+ */
+int lc_opt_grp_is_root(const lc_opt_entry_t *ent);
+
+/**
+ * Get an option group.
+ * If the group is not already present, it is created.
+ * @param parent The parent group to look in.
+ * @param name The name of the group to lookup
+ * @return The already present or created group.
+ */
+lc_opt_entry_t *lc_opt_get_grp(lc_opt_entry_t *parent, const char *name);
+
+/**
+ * Add an option to a group.
+ * @param grp The group to add the option to.
+ * @param name The name of the option (must be unique inside the group).
+ * @param desc A description of the option.
+ * @param type The data type of the option (see lc_opt_type_*)
+ * @param value A pointer to the memory, where the value shall be stored.
+ * (May be NULL).
+ * @param length Amount of bytes available at the memory location
+ * indicated by @p value.
+ * @param cb A callback function to be called, as the option's value
+ * is set (may be NULL).
+ * @param err Error information to be set (may be NULL).
+ * @return The handle for the option.
+ */
+lc_opt_entry_t *lc_opt_add_opt(lc_opt_entry_t *grp,
+ const char *name,
+ const char *desc,
+ lc_opt_type_t type,
+ void *value, size_t length,
+ lc_opt_callback_t *cb,
+ lc_opt_dump_t *dump,
+ lc_opt_dump_vals_t *dump_vals,
+ lc_opt_err_info_t *err);
+
+int lc_opt_std_cb(const char *name, lc_opt_type_t type, void *data, size_t length, ...);
+
+int lc_opt_std_dump(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t length);
+
+int lc_opt_bool_dump_vals(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t length);
+
+#define lc_opt_add_opt_int(grp, name, desc, value, err) \
+ lc_opt_add_opt(grp, name, desc, lc_opt_type_int, value, 0, lc_opt_std_cb, lc_opt_std_dump, NULL, err)
+
+#define lc_opt_add_opt_double(grp, name, desc, value, err) \
+ lc_opt_add_opt(grp, name, desc, lc_opt_type_double, value, 0, lc_opt_std_cb, lc_opt_std_dump, NULL, err)
+
+#define lc_opt_add_opt_string(grp, name, desc, buf, len, err) \
+ lc_opt_add_opt(grp, name, desc, lc_opt_type_string, buf, len, lc_opt_std_cb, lc_opt_std_dump, NULL, err)
+
+#define lc_opt_add_opt_bit(grp, name, desc, value, mask, err) \
+ lc_opt_add_opt(grp, name, desc, lc_opt_type_bit, value, mask, lc_opt_std_cb, lc_opt_std_dump, NULL, err)
+
+
+/**
+ * Find a group inside another group.
+ * @param grp The group to search inside.
+ * @param name The name of the group you are looking for.
+ * @param err Error info (may be NULL).
+ * @return The group or NULL, if no such group can be found.
+ */
+lc_opt_entry_t *lc_opt_find_grp(const lc_opt_entry_t *grp, const char *name, lc_opt_err_info_t *err);
+
+/**
+ * Find an option inside another group.
+ * @param grp The group to search inside.
+ * @param name The name of the option you are looking for.
+ * @param err Error info (may be NULL).
+ * @return The group or NULL, if no such option can be found.
+ */
+lc_opt_entry_t *lc_opt_find_opt(const lc_opt_entry_t *grp, const char *name, lc_opt_err_info_t *err);
+
+/**
+ * Resolve a group.
+ * @param root The group to start resolving from.
+ * @param names A string array containing the path to the group.
+ * @param n Number of entries in @p names to consider.
+ * @param err Error information (may be NULL).
+ * @return The group or NULL, if none is found.
+ */
+lc_opt_entry_t *lc_opt_resolve_grp(const lc_opt_entry_t *root,
+ const char * const *names, int n, lc_opt_err_info_t *err);
+
+/**
+ * Resolve an option.
+ * @param root The group to start resolving from.
+ * @param names A string array containing the path to the option.
+ * @param n Number of entries in @p names to consider.
+ * @param err Error information (may be NULL).
+ * @return The option or NULL, if none is found.
+ */
+lc_opt_entry_t *lc_opt_resolve_opt(const lc_opt_entry_t *root,
+ const char * const *names, int n, lc_opt_err_info_t *err);
+
+/**
+ * Set the value of an option.
+ * @param opt The option to set.
+ * @param value The value of the option in a string representation.
+ * @param err Error information (may be NULL).
+ * @return 0, if an error occurred, 1 else.
+ */
+int lc_opt_occurs(lc_opt_entry_t *opt, const char *value, lc_opt_err_info_t *err);
+
+/**
+ * Convert the option to a string representation.
+ * @param buf The string buffer to put the string representation to.
+ * @param len The length of @p buf.
+ * @param ent The option to process.
+ * @return @p buf.
+ */
+char *lc_opt_value_to_string(char *buf, size_t len, const lc_opt_entry_t *ent);
+
+/**
+ * Get the name of the type of an option.
+ * @param ent The option.
+ * @return The name of the type of the option.
+ */
+const char *lc_opt_get_type_name(const lc_opt_entry_t *ent);
+
+/**
+ * Print the help screen for the given entity to the given file.
+ */
+void lc_opt_print_help(lc_opt_entry_t *ent, FILE *f);
+
+/**
+ * Print the help screen for the given entity to the given file.
+ * Use separator instead of '.' and ignore entities above ent,
+ * i.e. if ent is root.be and has option isa.mach, prints
+ * isa<separator>mach instead of root.be.isa.mach
+ */
+void lc_opt_print_help_for_entry(lc_opt_entry_t *ent, char separator, FILE *f);
+
+void lc_opt_print_tree(lc_opt_entry_t *ent, FILE *f);
+
+int lc_opt_add_table(lc_opt_entry_t *grp, const lc_opt_table_entry_t *table);
+
+void lc_opt_from_file(const char *filenmame, FILE *f, lc_opt_error_handler_t *handler);
+
+/**
+ * The same as lc_opt_from_single_arg() only for an array of arguments.
+ */
+int lc_opt_from_argv(const lc_opt_entry_t *root,
+ const char *opt_prefix,
+ int argc, const char *argv[],
+ lc_opt_error_handler_t *handler);
+
+/**
+ * Set options from a single (command line) argument.
+ * @param root The root group we start resolving from.
+ * @param opt_prefix The option prefix which shall be stripped of (mostly --).
+ * @param arg The command line argument itself.
+ * @param handler An error handler.
+ * @return 1, if the argument was set, 0 if not.
+ */
+int lc_opt_from_single_arg(const lc_opt_entry_t *grp,
+ const char *opt_prefix,
+ const char *arg,
+ lc_opt_error_handler_t *handler);
+
+/**
+ * Get printf environment for the option module.
+ * Currently implemented options are:
+ * %{opt:value} (%V) Value of an option.
+ * %{opt:type} (%T) Type of an option.
+ * %{opt:name} (%O) Name of an option.
+ * %{opt:desc} (%D) Description of an option.
+ * @return The option printf environment.
+ */
+const lc_arg_env_t *lc_opt_get_arg_env(void);
+
+/**
+ * Standard procedure for options initialization.
+ * @param cmnt_name Base name for the file.
+ * @param root The option's root.
+ * @param arg_prefix A prefix that is added to each option.
+ * @param argc Number of entries in @p argv.
+ * @param argv A stadard argument vector.
+ *
+ * This function tries to open a ini file in the user's homedir
+ * (On win32 this is \Documents and Settings\Application Data)
+ * which is called .<ini_name>rc (on win32 <ini_name>.ini)
+ *
+ * and an ini file in the current directory which is called <ini_name>.ini on
+ * both systems.
+ * Afterwards, the argument vectors are processed.
+ */
+void lc_opts_init(const char *ini_name, lc_opt_entry_t *root, const char *arg_prefix, int argc, const char **argv);
+
+#endif
--- /dev/null
+/**
+ * @file lc_opts_enum.c
+ * @date 24.11.2005
+ * @author Sebastian Hack
+ *
+ * Copyright (C) 2005 Universitaet Karlsruhe
+ * Released under the GPL
+ *
+ * Enum callback and dump implementation.
+ */
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+#if defined(__FreeBSD__)
+#include <stdlib.h>
+#elif defined(_WIN32)
+#include <malloc.h>
+#else
+#include <alloca.h>
+#endif
+
+#include "lc_opts_t.h"
+#include "lc_opts_enum.h"
+
+static const char *delim = " \t|,";
+
+#define DECL_CB(N, op) \
+int lc_opt_enum_ ## N ## _cb(LC_UNUSED(const char *name), LC_UNUSED(lc_opt_type_t type), void *data, size_t len, ...) \
+{ \
+ lc_opt_enum_ ## N ## _var_t *var = data; \
+ const lc_opt_enum_ ## N ## _items_t *items = var->items; \
+ \
+ va_list args; \
+ char *s, *tmp; \
+ size_t begin, end; \
+ const char *arg; \
+ int res = 0; \
+ \
+ va_start(args, len); \
+ arg = va_arg(args, const char *); \
+ va_end(args); \
+ \
+ end = strlen(arg); \
+ tmp = s = malloc((end + 1) * sizeof(arg[0])); \
+ strcpy(s, arg); \
+ s[end] = '\0'; \
+ \
+ end = 0; \
+ while(arg[end] != '\0') { \
+ unsigned int i; \
+ \
+ begin = end + strspn(arg + end, delim); \
+ end = begin + strcspn(arg + begin, delim); \
+ s = tmp + begin; \
+ s[end - begin] = '\0'; \
+ \
+ for(i = 0; items[i].name != NULL; ++i) { \
+ if(strcmp(s, items[i].name) == 0) { \
+ *var->value op items[i].value; \
+ res = 1; \
+ } \
+ } \
+ } \
+ free(tmp); \
+ return res; \
+} \
+
+DECL_CB(int, =)
+DECL_CB(mask, |=)
+DECL_CB(ptr, =)
+DECL_CB(const_ptr, =)
+DECL_CB(func_ptr, =)
+
+#define DECL_DUMP(T, N, cond) \
+int lc_opt_enum_ ## N ## _dump(char *buf, size_t n, LC_UNUSED(const char *name), LC_UNUSED(lc_opt_type_t type), void *data, LC_UNUSED(size_t len)) \
+{ \
+ lc_opt_enum_ ## N ## _var_t *var = data; \
+ const lc_opt_enum_ ## N ## _items_t *items = var->items; \
+ const char *prefix = ""; \
+ TYPE(value) = *var->value; \
+ int i; \
+ \
+ for(i = 0; items[i].name != NULL; ++i) { \
+ TYPE(item_value) = items[i].value; \
+ if(cond) { \
+ strncat(buf, prefix, n); \
+ strncat(buf, items[i].name, n); \
+ prefix = ", "; \
+ } \
+ } \
+ \
+ return strlen(buf); \
+} \
+
+
+#define DECL_DUMP_VALS(T, N) \
+int lc_opt_enum_ ## N ## _dump_vals(char *buf, size_t n, LC_UNUSED(const char *name), LC_UNUSED(lc_opt_type_t type), void *data, LC_UNUSED(size_t len)) \
+{ \
+ lc_opt_enum_ ## N ## _var_t *var = data; \
+ const lc_opt_enum_ ## N ## _items_t *items = var->items; \
+ const char *prefix = ""; \
+ int i; \
+ \
+ for(i = 0; items[i].name != NULL; ++i) { \
+ strncat(buf, prefix, n); \
+ strncat(buf, items[i].name, n); \
+ prefix = ", "; \
+ } \
+ \
+ return strlen(buf); \
+} \
+
+
+
+#define TYPE(x) int x
+DECL_DUMP(int, int, item_value == value)
+DECL_DUMP_VALS(int, int)
+#undef TYPE
+
+#define TYPE(x) unsigned x
+DECL_DUMP(unsigned, mask, (item_value & value) == item_value)
+DECL_DUMP_VALS(unsigned, mask)
+#undef TYPE
+
+#define TYPE(x) void *x
+DECL_DUMP(void *, ptr, item_value == value)
+DECL_DUMP_VALS(void *, ptr)
+#undef TYPE
+
+#define TYPE(x) const void *x
+DECL_DUMP(const void *, const_ptr, item_value == value)
+DECL_DUMP_VALS(const void *, const_ptr)
+#undef TYPE
+
+#define TYPE(x) int (*x)(void)
+DECL_DUMP(int (*)(void), func_ptr, item_value == value)
+DECL_DUMP_VALS(int (*)(void), func_ptr)
+#undef TYPE
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+ Option management library. Enum extensions.
+*/
+
+#ifndef _LC_OPTS_ENUM_T
+#define _LC_OPTS_ENUM_T
+
+#include <libcore/lc_opts.h>
+
+#define _LC_OPT_DECL_ENUM(T, N) \
+typedef struct { \
+ const char *name; \
+ T value; \
+} lc_opt_enum_ ## N ## _items_t; \
+ \
+typedef struct { \
+ T* value; \
+ const lc_opt_enum_ ## N ## _items_t *items; \
+} lc_opt_enum_ ## N ## _var_t; \
+\
+int lc_opt_enum_ ## N ## _cb(const char *name, lc_opt_type_t type, void *data, size_t len, ...); \
+int lc_opt_enum_ ## N ## _dump(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len); \
+int lc_opt_enum_ ## N ## _dump_vals(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len); \
+
+#define _LC_OPT_ENT_ENUM(N, name, desc, var) \
+ _LC_OPT_ENT(name, desc, lc_opt_type_enum, var, 0, lc_opt_enum_ ## N ## _cb, lc_opt_enum_ ## N ## _dump, lc_opt_enum_ ## N ## _dump_vals)
+
+_LC_OPT_DECL_ENUM(int, int)
+_LC_OPT_DECL_ENUM(unsigned, mask)
+_LC_OPT_DECL_ENUM(void *, ptr)
+_LC_OPT_DECL_ENUM(const void *, const_ptr)
+
+#define LC_OPT_ENT_ENUM_INT(name, desc, var) _LC_OPT_ENT_ENUM(int, name, desc, var)
+#define LC_OPT_ENT_ENUM_MASK(name, desc, var) _LC_OPT_ENT_ENUM(mask, name, desc, var)
+#define LC_OPT_ENT_ENUM_PTR(name, desc, var) _LC_OPT_ENT_ENUM(ptr, name, desc, var)
+#define LC_OPT_ENT_ENUM_CONST_PTR(name, desc, var) _LC_OPT_ENT_ENUM(const_ptr, name, desc, var)
+
+typedef struct {
+ const char *name;
+ int (*value)(void);
+} lc_opt_enum_func_ptr_items_t;
+
+typedef struct {
+ int (**value)(void);
+ const lc_opt_enum_func_ptr_items_t *items;
+} lc_opt_enum_func_ptr_var_t;
+
+#define LC_OPT_ENT_ENUM_FUNC_PTR(name, desc, var) _LC_OPT_ENT_ENUM(func_ptr, name, desc, var)
+
+int lc_opt_enum_func_ptr_cb(const char *name, lc_opt_type_t type, void *data, size_t len, ...);
+int lc_opt_enum_func_ptr_dump(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len);
+int lc_opt_enum_func_ptr_dump_vals(char *buf, size_t n, const char *name, lc_opt_type_t type, void *data, size_t len);
+
+#endif
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+
+#ifndef _OPTS_T_H
+#define _OPTS_T_H
+
+#include <stdlib.h>
+
+#include "lc_opts.h"
+#include "list.h"
+
+#include "lc_common_t.h"
+#include "lc_defines.h"
+
+typedef struct {
+ struct list_head opts;
+ struct list_head grps;
+} lc_grp_special_t;
+
+typedef struct {
+ lc_opt_type_t type;
+ lc_opt_callback_t *cb;
+ lc_opt_dump_t *dump;
+ lc_opt_dump_vals_t *dump_vals;
+ void *value;
+ size_t length;
+ unsigned is_set : 1;
+} lc_opt_special_t;
+
+struct _lc_opt_entry_t {
+ unsigned hash;
+ const char *name;
+ const char *desc;
+ struct _lc_opt_entry_t *parent;
+
+ unsigned is_grp : 1;
+
+ struct list_head list;
+
+ union {
+ lc_grp_special_t grp;
+ lc_opt_special_t opt;
+ } v;
+};
+
+#define lc_get_opt_special(ent) (&(ent)->v.opt)
+#define lc_get_grp_special(ent) (&(ent)->v.grp)
+
+int lc_opt_raise_error(const lc_opt_err_info_t *err,
+ lc_opt_error_handler_t *handler,
+ const char *fmt, ...);
+
+#endif
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+
+#ifndef _PARSER_T_H
+#define _PARSER_T_H
+
+#include "lc_opts_t.h"
+
+typedef struct {
+ const char *str;
+ int len;
+} text_t;
+
+void lc_opt_init_parser(const char *filename, lc_opt_error_handler_t *handler);
+
+void _lc_opt_add_to_data_char(char c);
+
+#define PPREFIX _lc_opt_
+#define PMANGLE(name) _lc_opt_ ## name
+
+extern FILE *PMANGLE(in);
+extern int PMANGLE(linenr);
+
+int PMANGLE(parse)(void);
+int PMANGLE(lex)(void);
+
+#endif
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+/**
+ * A customizable printf clone.
+ * @author Sebastian Hack
+ * @date 4.12.2005
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <stdarg.h>
+#include <string.h>
+#include <assert.h>
+#include <ctype.h>
+
+#include "lc_common_t.h"
+#include "xmalloc.h"
+#include "lc_printf.h"
+#include "lc_defines.h"
+#include "hashptr.h"
+#include "set.h"
+
+/* printf implementation */
+
+typedef struct _lc_arg_t {
+ struct _lc_arg_t *next;
+ const char *name;
+ char letter;
+ int lc_arg_type;
+ const lc_arg_handler_t *handler;
+} lc_arg_t;
+
+struct _lc_arg_env_t {
+ set *args; /**< Map for named arguments. */
+ lc_arg_t *lower[26]; /**< Map for lower conversion specifiers. */
+ lc_arg_t *upper[26]; /**< Map for upper conversion specifiers. */
+};
+
+/** The default argument environment. */
+static lc_arg_env_t *default_env = NULL;
+
+static INLINE lc_arg_env_t *_lc_arg_get_default_env(void)
+{
+ if(!default_env)
+ default_env = lc_arg_add_std(lc_arg_new_env());
+
+ return default_env;
+}
+
+lc_arg_env_t *lc_arg_get_default_env(void)
+{
+ return _lc_arg_get_default_env();
+}
+
+static int lc_arg_cmp(const void *p1, const void *p2, UNUSED(size_t size))
+{
+ const lc_arg_t *a1 = p1;
+ const lc_arg_t *a2 = p2;
+ return strcmp(a1->name, a2->name);
+}
+
+
+lc_arg_env_t *lc_arg_new_env(void)
+{
+ lc_arg_env_t *env = xmalloc(sizeof(*env));
+ memset(env, 0, sizeof(*env));
+ env->args = new_set(lc_arg_cmp, 16);
+ return env;
+}
+
+void lc_arg_free_env(lc_arg_env_t *env)
+{
+ del_set(env->args);
+ free(env);
+}
+
+int lc_arg_register(lc_arg_env_t *env, const char *name, char letter, const lc_arg_handler_t *handler)
+{
+ lc_arg_t arg;
+ lc_arg_t *ent;
+ int base = 0;
+ lc_arg_t **map = NULL;
+
+ arg.name = name;
+ arg.letter = letter;
+ arg.handler = handler;
+
+ if(isupper(letter)) {
+ map = env->upper;
+ base = 'A';
+ }
+ else if(islower(letter)) {
+ map = env->lower;
+ base = 'a';
+ }
+
+ ent = set_insert(env->args, &arg, sizeof(arg), HASH_STR(name, strlen(name)));
+
+ if(ent && base != 0)
+ map[letter - base] = ent;
+
+ return ent != NULL;
+}
+
+void lc_arg_unregister(UNUSED(lc_arg_env_t *env), UNUSED(const char *name))
+{
+}
+
+int lc_arg_append(lc_appendable_t *app, const lc_arg_occ_t *occ, const char *str, size_t len)
+{
+ char pad = ' ';
+
+ /* Set the padding to zero, if the zero is given and we are not left
+ * justified. (A minus ovverides the zero). See printf(3). */
+ if(!occ->flag_minus && occ->flag_zero)
+ pad = '0';
+
+ return lc_appendable_snwadd(app, str, len, LC_MAX(0, occ->width), occ->flag_minus, pad);
+}
+
+
+static int dispatch_snprintf(char *buf, size_t len, const char *fmt,
+ int lc_arg_type, const lc_arg_value_t *val)
+{
+ int res = 0;
+
+ switch(lc_arg_type) {
+#define LC_ARG_TYPE(type,name) \
+ case lc_arg_type_ ## name: res = snprintf(buf, len, fmt, val->v_ ## name); break;
+#include "lc_printf_arg_types.def"
+#undef LC_ARG_TYPE
+ }
+
+ return res;
+}
+
+static char *make_fmt(char *buf, size_t len, const lc_arg_occ_t *occ)
+{
+ char mod[64];
+ char prec[16];
+ char width[16];
+
+ prec[0] = '\0';
+ width[0] = '\0';
+
+ if(occ->precision > 0)
+ snprintf(prec, sizeof(prec), ".%d", occ->precision);
+
+ if(occ->width > 0)
+ snprintf(width, sizeof(width), "%d", occ->width);
+
+ assert(occ->modifier && "modifier must not be NULL");
+ strncpy(mod, occ->modifier, sizeof(mod) - 1);
+ mod[LC_MIN(sizeof(mod) - 1, occ->modifier_length)] = '\0';
+
+ snprintf(buf, len, "%%%s%s%s%s%s%s%s%s%c",
+ occ->flag_space ? "#" : "",
+ occ->flag_hash ? "#" : "",
+ occ->flag_plus ? "+" : "",
+ occ->flag_minus ? "-" : "",
+ occ->flag_zero ? "0" : "",
+ width, prec,
+ mod, occ->conversion);
+
+ return buf;
+}
+
+/*
+ * Standard argument handler.
+ */
+static int std_get_lc_arg_type(const lc_arg_occ_t *occ)
+{
+ int modlen = occ->modifier_length;
+ const char *mod = occ->modifier;
+ int res = -1;
+
+
+ /* check, if the type can be derived from the modifier */
+ if(modlen > 0) {
+ switch(mod[0]) {
+ case 'l':
+ res = modlen > 1 && mod[1] == 'l' ? lc_arg_type_long_long : lc_arg_type_long;
+ break;
+#define TYPE_CASE(letter,type) case letter: res = lc_arg_type_ ## type; break
+#if 0
+ TYPE_CASE('j', intmax_t);
+ TYPE_CASE('z', size_t);
+ TYPE_CASE('t', ptrdiff_t);
+#endif
+ TYPE_CASE('L', long_double);
+#undef TYPE_CASE
+ }
+ }
+
+ /* The type is given by the conversion specifier and cannot be
+ * determined from the modifier. */
+ if(res == -1) {
+ switch(occ->conversion) {
+ case 'e':
+ case 'E':
+ case 'f':
+ case 'F':
+ case 'g':
+ case 'G':
+ res = lc_arg_type_double;
+ break;
+ case 's':
+ case 'n':
+ case 'p':
+ res = lc_arg_type_ptr;
+ break;
+ default:
+ res = lc_arg_type_int;
+ }
+ }
+
+ return res;
+}
+
+static int std_emit(lc_appendable_t *app, const lc_arg_occ_t *occ, const lc_arg_value_t *val)
+{
+ char fmt[32];
+ int res = 0;
+
+ make_fmt(fmt, sizeof(fmt), occ);
+
+ switch(occ->conversion) {
+
+ /* Store the number of written characters in the given
+ * int pointer location */
+ case 'n':
+ {
+ int *num = val->v_ptr;
+ *num = app->written;
+ }
+ break;
+
+ /* strings are dumped directly, since they can get really big. A
+ * buffer of 128 letters for all other types should be enough. */
+ case 's':
+ {
+ const char *str = val->v_ptr;
+ res = lc_arg_append(app, occ, str, strlen(str));
+ }
+ break;
+
+ default:
+ {
+ int len = LC_MAX(128, occ->width + 1);
+ char *buf = malloc(len * sizeof(char));
+ res = dispatch_snprintf(buf, len, fmt, occ->lc_arg_type, val);
+ res = lc_appendable_snadd(app, buf, res);
+ free(buf);
+ }
+ }
+
+ return res;
+}
+
+static const lc_arg_handler_t std_handler = {
+ std_get_lc_arg_type,
+ std_emit
+};
+
+lc_arg_env_t *lc_arg_add_std(lc_arg_env_t *env)
+{
+ lc_arg_register(env, "std:c", 'c', &std_handler);
+ lc_arg_register(env, "std:i", 'i', &std_handler);
+ lc_arg_register(env, "std:d", 'd', &std_handler);
+ lc_arg_register(env, "std:o", 'o', &std_handler);
+ lc_arg_register(env, "std:u", 'u', &std_handler);
+ lc_arg_register(env, "std:x", 'x', &std_handler);
+ lc_arg_register(env, "std:X", 'X', &std_handler);
+
+ lc_arg_register(env, "std:e", 'e', &std_handler);
+ lc_arg_register(env, "std:E", 'E', &std_handler);
+ lc_arg_register(env, "std:f", 'f', &std_handler);
+ lc_arg_register(env, "std:F", 'F', &std_handler);
+ lc_arg_register(env, "std:g", 'g', &std_handler);
+ lc_arg_register(env, "std:G", 'G', &std_handler);
+
+ lc_arg_register(env, "std:s", 's', &std_handler);
+ lc_arg_register(env, "std:p", 'p', &std_handler);
+ lc_arg_register(env, "std:n", 'n', &std_handler);
+
+ return env;
+}
+
+static char *read_int(const char *s, int *value)
+{
+ char *endptr;
+ int res = (int) strtol(s, &endptr, 10);
+ *value = endptr == s ? -1 : res;
+ return endptr;
+}
+
+/* Generic printf() function. */
+
+int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt, va_list args)
+{
+ int res = 0;
+ const char *s;
+ const char *last = fmt + strlen(fmt);
+
+ /* Find the fisrt % */
+ s = strchr(fmt, '%');
+
+ /* Emit the text before the first % was found */
+ lc_appendable_snadd(app, fmt, (s ? s : last) - fmt);
+
+ while(s != NULL) {
+ lc_arg_occ_t occ;
+ lc_arg_value_t val;
+ const lc_arg_t *arg = NULL;
+ const char *old;
+ char ch;
+
+ /* We must be at a '%' */
+ assert(*s == '%');
+
+ /* Reset the occurrence structure */
+ memset(&occ, 0, sizeof(occ));
+
+ /* Eat all flags and set the corresponding flags in the occ struct */
+ for(++s; strchr("#0-+", *s); ++s) {
+ switch(*s) {
+ case '#':
+ occ.flag_hash = 1;
+ break;
+ case '0':
+ occ.flag_zero = 1;
+ break;
+ case '-':
+ occ.flag_minus = 1;
+ break;
+ case '+':
+ occ.flag_plus = 1;
+ break;
+ case ' ':
+ occ.flag_space = 1;
+ break;
+ }
+ }
+
+ /* Read the width if given */
+ s = read_int(s, &occ.width);
+
+ occ.precision = -1;
+
+ /* read the precision if given */
+ if(*s == '.') {
+ int val;
+ s = read_int(s + 1, &val);
+
+ /* Negative or lacking precision after a '.' is treated as
+ * precision 0. */
+ occ.precision = LC_MAX(0, val);
+ }
+
+ /*
+ * Now, we can either have:
+ * - a named argument like {node}
+ * - some modifiers followed by a conversion specifier
+ * - or some other character, which ends this format invalidly
+ */
+ ch = *s;
+ switch(ch) {
+ case '%':
+ s++;
+ res += lc_appendable_chadd(app, '%');
+ break;
+ case '{':
+ {
+ const char *named = ++s;
+
+ /* Read until the closing brace or end of the string. */
+ for(ch = *s; ch != '}' && ch != '\0'; ch = *++s);
+
+ if(s - named) {
+ int n = s - named;
+ char *name;
+ lc_arg_t tmp;
+
+ name = malloc(sizeof(char) * (n + 1));
+ memcpy(name, named, sizeof(char) * n);
+ name[n] = '\0';
+ tmp.name = name;
+
+ arg = set_find(env->args, &tmp, sizeof(tmp), HASH_STR(named, n));
+ occ.modifier = "";
+ occ.modifier_length = 0;
+
+ /* Set the conversion specifier of the occurrence to the
+ * letter specified in the argument description. */
+ if(arg)
+ occ.conversion = arg->letter;
+
+ free(name);
+
+ /* If we ended with a closing brace, move the current
+ * pointer after it, since it is not to be dumped. */
+ if(ch == '}')
+ s++;
+ }
+ }
+ break;
+
+ default:
+ {
+ const char *mod = s;
+
+ /* Read, as long there are letters */
+ while(isalpha(ch) && !arg) {
+ int base = 'a';
+ lc_arg_t * const *map = env->lower;
+
+ /* If uppercase, select the uppercase map from the environment */
+ if(isupper(ch)) {
+ base = 'A';
+ map = env->upper;
+ }
+
+ if(map[ch - base] != NULL) {
+ occ.modifier = s;
+ occ.modifier_length = s - mod;
+ occ.conversion = ch;
+ arg = map[ch - base];
+ }
+
+ ch = *++s;
+ }
+ }
+ }
+
+ /* Call the handler if an argument was determined */
+ if(arg != NULL && arg->handler != NULL) {
+ const lc_arg_handler_t *handler = arg->handler;
+
+ /* Let the handler determine the type of the argument based on the
+ * information gathered. */
+ occ.lc_arg_type = handler->get_lc_arg_type(&occ);
+
+ /* Store the value according to argument information */
+ switch(occ.lc_arg_type) {
+#define LC_ARG_TYPE(type,name) case lc_arg_type_ ## name: val.v_ ## name = va_arg(args, type); break;
+#include "lc_printf_arg_types.def"
+#undef LC_ARG_TYPE
+ }
+
+ /* Finally, call the handler. */
+ res += handler->emit(app, &occ, &val);
+ }
+
+ old = s;
+ s = strchr(s, '%');
+ res += lc_appendable_snadd(app, old, (s ? s : last) - old);
+ }
+
+ return res;
+}
+
+/* Convenience implementations */
+
+int lc_epprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt, ...)
+{
+ int res;
+ va_list args;
+ va_start(args, fmt);
+ res = lc_evpprintf(env, app, fmt, args);
+ va_end(args);
+ return res;
+}
+
+int lc_pprintf(lc_appendable_t *app, const char *fmt, ...)
+{
+ int res;
+ va_list args;
+ va_start(args, fmt);
+ res = lc_vpprintf(app, fmt, args);
+ va_end(args);
+ return res;
+}
+
+int lc_vpprintf(lc_appendable_t *app, const char *fmt, va_list args)
+{
+ return lc_evpprintf(_lc_arg_get_default_env(), app, fmt, args);
+}
+
+int lc_eprintf(const lc_arg_env_t *env, const char *fmt, ...)
+{
+ int res;
+ va_list args;
+ va_start(args, fmt);
+ res = lc_efprintf(env, stdout, fmt, args);
+ va_end(args);
+ return res;
+}
+
+int lc_esnprintf(const lc_arg_env_t *env, char *buf, size_t len, const char *fmt, ...)
+{
+ int res;
+ va_list args;
+ va_start(args, fmt);
+ res = lc_evsnprintf(env, buf, len, fmt, args);
+ va_end(args);
+ return res;
+}
+
+int lc_efprintf(const lc_arg_env_t *env, FILE *file, const char *fmt, ...)
+{
+ int res;
+ va_list args;
+ va_start(args, fmt);
+ res = lc_evfprintf(env, file, fmt, args);
+ va_end(args);
+ return res;
+}
+
+int lc_eoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt, ...)
+{
+ int res;
+ va_list args;
+ va_start(args, fmt);
+ res = lc_evoprintf(env, obst, fmt, args);
+ va_end(args);
+ return res;
+}
+
+int lc_evprintf(const lc_arg_env_t *env, const char *fmt, va_list args)
+{
+ return lc_evfprintf(env, stdout, fmt, args);
+}
+
+int lc_evsnprintf(const lc_arg_env_t *env, char *buf, size_t len, const char *fmt, va_list args)
+{
+ int res;
+ lc_appendable_t app;
+
+ lc_appendable_init(&app, lc_appendable_string, buf, len);
+ res = lc_evpprintf(env, &app, fmt, args);
+ lc_appendable_finish(&app);
+ return res;
+}
+
+int lc_evfprintf(const lc_arg_env_t *env, FILE *f, const char *fmt, va_list args)
+{
+ int res;
+ lc_appendable_t app;
+
+ lc_appendable_init(&app, lc_appendable_file, f, 0);
+ res = lc_evpprintf(env, &app, fmt, args);
+ lc_appendable_finish(&app);
+ return res;
+}
+
+int lc_evoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt, va_list args)
+{
+ int res;
+ lc_appendable_t app;
+
+ lc_appendable_init(&app, lc_appendable_obstack, obst, 0);
+ res = lc_evpprintf(env, &app, fmt, args);
+ lc_appendable_finish(&app);
+ return res;
+}
+
+
+int lc_printf(const char *fmt, ...)
+{
+ int res;
+ va_list args;
+ va_start(args, fmt);
+ res = lc_vprintf(fmt, args);
+ va_end(args);
+ return res;
+}
+
+int lc_snprintf(char *buf, size_t len, const char *fmt, ...)
+{
+ int res;
+ va_list args;
+ va_start(args, fmt);
+ res = lc_vsnprintf(buf, len, fmt, args);
+ va_end(args);
+ return res;
+}
+
+int lc_fprintf(FILE *f, const char *fmt, ...)
+{
+ int res;
+ va_list args;
+ va_start(args, fmt);
+ res = lc_vfprintf(f, fmt, args);
+ va_end(args);
+ return res;
+}
+
+int lc_oprintf(struct obstack *obst, const char *fmt, ...)
+{
+ int res;
+ va_list args;
+ va_start(args, fmt);
+ res = lc_voprintf(obst, fmt, args);
+ va_end(args);
+ return res;
+}
+
+
+int lc_vprintf(const char *fmt, va_list args)
+{
+ return lc_evprintf(_lc_arg_get_default_env(), fmt, args);
+}
+
+int lc_vsnprintf(char *buf, size_t len, const char *fmt, va_list args)
+{
+ return lc_evsnprintf(_lc_arg_get_default_env(), buf, len, fmt, args);
+}
+
+int lc_vfprintf(FILE *f, const char *fmt, va_list args)
+{
+ return lc_evfprintf(_lc_arg_get_default_env(), f, fmt, args);
+}
+
+int lc_voprintf(struct obstack *obst, const char *fmt, va_list args)
+{
+ return lc_evoprintf(_lc_arg_get_default_env(), obst, fmt, args);
+}
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+
+/**
+ * Flexible printf().
+ * @author Sebastian Hack
+ * @date 3.1.2005
+ */
+
+#ifndef _LIBCORE_XPRINTF_H
+#define _LIBCORE_XPRINTF_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <obstack.h>
+
+#include <libcore/lc_config.h>
+#include <libcore/lc_appendable.h>
+
+typedef struct _lc_arg_occ_t {
+ int width; /**< The width, or 0 if not given. */
+ int precision; /**< The precision, or 0 if not given */
+
+ const char *modifier; /**< A string of of modifiers preceding the
+ conversion specifier. Attention: This string is not
+ zero terminated. Use @c modifier_length to get the
+ number of valid chars in it. */
+ size_t modifier_length; /**< The number of valid chars in @c modifier. */
+ char conversion; /**< The conversion specifier. */
+ int lc_arg_type; /**< The type of the argument as determined by the
+ @c get_lc_arg_type member function of the handler. */
+
+ unsigned flag_hash : 1; /**< @c # flag was seen. */
+ unsigned flag_zero : 1; /**< @c 0 flag was seen. */
+ unsigned flag_minus : 1; /**< @c - flag was seen. */
+ unsigned flag_plus : 1; /**< @c + flag was seen. */
+ unsigned flag_space : 1; /**< A space flag was seen. */
+} lc_arg_occ_t;
+
+/**
+ * A value from the ... arguments of the printf function.
+ * Look at the file 'xprintf_lc_arg_types.def'. The second argument of the
+ * @c ARG_TYPE macro is the name of the union member preceded by $c v_
+ */
+typedef union {
+#define LC_ARG_TYPE(type,name) type v_ ## name;
+#include "lc_printf_arg_types.def"
+#undef LC_ARG_TYPE
+} lc_arg_value_t;
+
+enum {
+#define LC_ARG_TYPE(type,name) lc_arg_type_ ## name,
+#include "lc_printf_arg_types.def"
+#undef LC_ARG_TYPE
+ lc_arg_type_last
+};
+
+typedef struct _lc_arg_handler {
+ int (*get_lc_arg_type)(const lc_arg_occ_t *occ);
+ int (*emit)(lc_appendable_t *app, const lc_arg_occ_t *occ, const lc_arg_value_t *arg);
+} lc_arg_handler_t;
+
+typedef struct _lc_arg_env_t lc_arg_env_t;
+
+lc_arg_env_t *lc_arg_new_env(void);
+void lc_arg_free_env(lc_arg_env_t *env);
+lc_arg_env_t *lc_arg_get_default_env(void);
+
+int lc_arg_register(lc_arg_env_t *env, const char *name, char letter, const lc_arg_handler_t *handler);
+void lc_arg_unregister(lc_arg_env_t *env, const char *name);
+
+lc_arg_env_t *lc_arg_add_std(lc_arg_env_t *env);
+
+int lc_arg_append(lc_appendable_t *app, const lc_arg_occ_t *occ, const char *str, size_t len);
+
+int lc_epprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt, ...);
+int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt, va_list args);
+int lc_pprintf(lc_appendable_t *app, const char *fmt, ...);
+int lc_vpprintf(lc_appendable_t *app, const char *fmt, va_list args);
+
+int lc_eprintf(const lc_arg_env_t *env, const char *fmt, ...);
+int lc_esnprintf(const lc_arg_env_t *env, char *buf, size_t len, const char *fmt, ...);
+int lc_efprintf(const lc_arg_env_t *env, FILE *file, const char *fmt, ...);
+int lc_eoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt, ...);
+
+int lc_evprintf(const lc_arg_env_t *env, const char *fmt, va_list args);
+int lc_evsnprintf(const lc_arg_env_t *env, char *buf, size_t len, const char *fmt, va_list args);
+int lc_evfprintf(const lc_arg_env_t *env, FILE *f, const char *fmt, va_list args);
+int lc_evoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt, va_list args);
+
+int lc_printf(const char *fmt, ...);
+int lc_snprintf(char *buf, size_t len, const char *fmt, ...);
+int lc_fprintf(FILE *f, const char *fmt, ...);
+int lc_oprintf(struct obstack *obst, const char *fmt, ...);
+
+int lc_vprintf(const char *fmt, va_list args);
+int lc_vsnprintf(char *buf, size_t len, const char *fmt, va_list args);
+int lc_vfprintf(FILE *f, const char *fmt, va_list args);
+int lc_voprintf(struct obstack *obst, const char *fmt, va_list args);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _LIBCORE_XPRINTF_H */
--- /dev/null
+LC_ARG_TYPE(int, int)
+LC_ARG_TYPE(long, long)
+LC_ARG_TYPE(LC_LONGLONG, long_long)
+LC_ARG_TYPE(double, double)
+LC_ARG_TYPE(LC_LONGDOUBLE, long_double)
+LC_ARG_TYPE(void *, ptr)
--- /dev/null
+/*
+ libcore: library for basic data structures and algorithms.
+ Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+
+#include <ctype.h>
+#include "lc_opts_t.h"
+
+int lc_opt_type_scan(void *dest, lc_opt_type_t type, const char *str)
+{
+ static const char *fmts[] = {
+ "", "%s", "%i", "%f"
+ };
+
+ static const struct {
+ const char *str;
+ int val;
+ } bool_vals[] = {
+ { "true", 1 },
+ { "on", 1 },
+ { "yes", 1 },
+ { "false", 0 },
+ { "no", 0 },
+ { "off", 0 }
+ };
+
+ int res = 0;
+
+ switch(type) {
+ case lc_opt_type_int:
+ case lc_opt_type_double:
+ case lc_opt_type_string:
+ res = sscanf(str, fmts[type], dest);
+ break;
+ case lc_opt_type_boolean:
+ {
+ size_t i, n;
+ int *data = dest;
+ char buf[10];
+
+ strncpy(buf, str, sizeof(buf));
+ for(i = 0, n = strlen(buf); i < n; ++i)
+ buf[i] = tolower(buf[i]);
+
+ for(i = 0; i < LC_ARRSIZE(bool_vals); ++i) {
+ if(strcmp(buf, bool_vals[i].str) == 0) {
+ res = 1;
+ *data = bool_vals[i].val;
+ break;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ return res;
+}
+
+int lc_opt_type_print(char *buf, size_t n, lc_opt_type_t type, void *data)
+{
+ int res = 0;
+
+ switch(type) {
+ case lc_opt_type_int:
+ {
+ int i = *((int *) data);
+ res = snprintf(buf, n, "%d", i);
+ }
+ break;
+ case lc_opt_type_double:
+ {
+ double d = *((double *) data);
+ res = snprintf(buf, n, "%f", d);
+ }
+ break;
+ case lc_opt_type_string:
+ res = snprintf(buf, n, "%s", (const char*) data);
+ break;
+ case lc_opt_type_boolean:
+ res = snprintf(buf, n, "%s", *((int *) data) ? "yes" : "no");
+ break;
+ default:
+ res = 0;
+ }
+
+ return res;
+}
--- /dev/null
+This is an obstack implementation adapted from the glibc one. It should work on
+all ANSI C89 compliant environments.
--- /dev/null
+/* obstack.c - subroutines used implicitly by object stack macros
+ Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998,
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "obstack.h"
+
+/* NOTE BEFORE MODIFYING THIS FILE: This version number must be
+ incremented whenever callers compiled using an old obstack.h can no
+ longer properly call the functions in this obstack.c. */
+#define OBSTACK_INTERFACE_VERSION 1
+
+#include <stdio.h> /* Random thing to get __GNU_LIBRARY__. */
+#include <stddef.h>
+#include <stdint.h>
+
+/* Determine default alignment. */
+union fooround
+{
+ uintmax_t i;
+ long double d;
+ void *p;
+};
+struct fooalign
+{
+ char c;
+ union fooround u;
+};
+/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
+ But in fact it might be less smart and round addresses to as much as
+ DEFAULT_ROUNDING. So we prepare for it to do that. */
+enum
+ {
+ DEFAULT_ALIGNMENT = offsetof (struct fooalign, u),
+ DEFAULT_ROUNDING = sizeof (union fooround)
+ };
+
+/* When we copy a long block of data, this is the unit to do it with.
+ On some machines, copying successive ints does not work;
+ in such a case, redefine COPYING_UNIT to `long' (if that works)
+ or `char' as a last resort. */
+# ifndef COPYING_UNIT
+# define COPYING_UNIT int
+# endif
+
+
+/* The functions allocating more room by calling `obstack_chunk_alloc'
+ jump to the handler pointed to by `obstack_alloc_failed_handler'.
+ This can be set to a user defined function which should either
+ abort gracefully or use longjump - but shouldn't return. This
+ variable by default points to the internal function
+ `print_and_abort'. */
+static void print_and_abort (void);
+void (*obstack_alloc_failed_handler) (void) = print_and_abort;
+
+/* Exit value used when `print_and_abort' is used. */
+# include <stdlib.h>
+int obstack_exit_failure = EXIT_FAILURE;
+
+/* Define a macro that either calls functions with the traditional malloc/free
+ calling interface, or calls functions with the mmalloc/mfree interface
+ (that adds an extra first argument), based on the state of use_extra_arg.
+ For free, do not use ?:, since some compilers, like the MIPS compilers,
+ do not allow (expr) ? void : void. */
+
+# define CALL_CHUNKFUN(h, size) \
+ (((h) -> use_extra_arg) \
+ ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
+ : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size)))
+
+# define CALL_FREEFUN(h, old_chunk) \
+ do { \
+ if ((h) -> use_extra_arg) \
+ (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
+ else \
+ (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
+ } while (0)
+
+\f
+/* Initialize an obstack H for use. Specify chunk size SIZE (0 means default).
+ Objects start on multiples of ALIGNMENT (0 means use default).
+ CHUNKFUN is the function to use to allocate chunks,
+ and FREEFUN the function to free them.
+
+ Return nonzero if successful, calls obstack_alloc_failed_handler if
+ allocation fails. */
+
+int
+_obstack_begin (struct obstack *h,
+ int size, int alignment,
+ void *(*chunkfun) (long),
+ void (*freefun) (void *))
+{
+ register struct _obstack_chunk *chunk; /* points to new chunk */
+
+ if (alignment == 0)
+ alignment = DEFAULT_ALIGNMENT;
+ if (size == 0)
+ /* Default size is what GNU malloc can fit in a 4096-byte block. */
+ {
+ /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
+ Use the values for range checking, because if range checking is off,
+ the extra bytes won't be missed terribly, but if range checking is on
+ and we used a larger request, a whole extra 4096 bytes would be
+ allocated.
+
+ These number are irrelevant to the new GNU malloc. I suspect it is
+ less sensitive to the size of the request. */
+ int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
+ + 4 + DEFAULT_ROUNDING - 1)
+ & ~(DEFAULT_ROUNDING - 1));
+ size = 4096 - extra;
+ }
+
+ h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun;
+ h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
+ h->chunk_size = size;
+ h->alignment_mask = alignment - 1;
+ h->use_extra_arg = 0;
+
+ chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
+ if (!chunk)
+ (*obstack_alloc_failed_handler) ();
+ h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
+ alignment - 1);
+ h->chunk_limit = chunk->limit
+ = (char *) chunk + h->chunk_size;
+ chunk->prev = 0;
+ /* The initial chunk now contains no empty object. */
+ h->maybe_empty_object = 0;
+ h->alloc_failed = 0;
+ return 1;
+}
+
+int
+_obstack_begin_1 (struct obstack *h, int size, int alignment,
+ void *(*chunkfun) (void *, long),
+ void (*freefun) (void *, void *),
+ void *arg)
+{
+ register struct _obstack_chunk *chunk; /* points to new chunk */
+
+ if (alignment == 0)
+ alignment = DEFAULT_ALIGNMENT;
+ if (size == 0)
+ /* Default size is what GNU malloc can fit in a 4096-byte block. */
+ {
+ /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
+ Use the values for range checking, because if range checking is off,
+ the extra bytes won't be missed terribly, but if range checking is on
+ and we used a larger request, a whole extra 4096 bytes would be
+ allocated.
+
+ These number are irrelevant to the new GNU malloc. I suspect it is
+ less sensitive to the size of the request. */
+ int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
+ + 4 + DEFAULT_ROUNDING - 1)
+ & ~(DEFAULT_ROUNDING - 1));
+ size = 4096 - extra;
+ }
+
+ h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
+ h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
+ h->chunk_size = size;
+ h->alignment_mask = alignment - 1;
+ h->extra_arg = arg;
+ h->use_extra_arg = 1;
+
+ chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
+ if (!chunk)
+ (*obstack_alloc_failed_handler) ();
+ h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
+ alignment - 1);
+ h->chunk_limit = chunk->limit
+ = (char *) chunk + h->chunk_size;
+ chunk->prev = 0;
+ /* The initial chunk now contains no empty object. */
+ h->maybe_empty_object = 0;
+ h->alloc_failed = 0;
+ return 1;
+}
+
+/* Allocate a new current chunk for the obstack *H
+ on the assumption that LENGTH bytes need to be added
+ to the current object, or a new object of length LENGTH allocated.
+ Copies any partial object from the end of the old chunk
+ to the beginning of the new one. */
+
+void
+_obstack_newchunk (struct obstack *h, int length)
+{
+ register struct _obstack_chunk *old_chunk = h->chunk;
+ register struct _obstack_chunk *new_chunk;
+ register long new_size;
+ register long obj_size = h->next_free - h->object_base;
+ register long i;
+ long already;
+ char *object_base;
+
+ /* Compute size for new chunk. */
+ new_size = (obj_size + length) + (obj_size >> 3) + h->alignment_mask + 100;
+ if (new_size < h->chunk_size)
+ new_size = h->chunk_size;
+
+ /* Allocate and initialize the new chunk. */
+ new_chunk = CALL_CHUNKFUN (h, new_size);
+ if (!new_chunk)
+ (*obstack_alloc_failed_handler) ();
+ h->chunk = new_chunk;
+ new_chunk->prev = old_chunk;
+ new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;
+
+ /* Compute an aligned object_base in the new chunk */
+ object_base =
+ __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask);
+
+ /* Move the existing object to the new chunk.
+ Word at a time is fast and is safe if the object
+ is sufficiently aligned. */
+ if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT)
+ {
+ for (i = obj_size / sizeof (COPYING_UNIT) - 1;
+ i >= 0; i--)
+ ((COPYING_UNIT *)object_base)[i]
+ = ((COPYING_UNIT *)h->object_base)[i];
+ /* We used to copy the odd few remaining bytes as one extra COPYING_UNIT,
+ but that can cross a page boundary on a machine
+ which does not do strict alignment for COPYING_UNITS. */
+ already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT);
+ }
+ else
+ already = 0;
+ /* Copy remaining bytes one by one. */
+ for (i = already; i < obj_size; i++)
+ object_base[i] = h->object_base[i];
+
+ /* If the object just copied was the only data in OLD_CHUNK,
+ free that chunk and remove it from the chain.
+ But not if that chunk might contain an empty object. */
+ if (! h->maybe_empty_object
+ && (h->object_base
+ == __PTR_ALIGN ((char *) old_chunk, old_chunk->contents,
+ h->alignment_mask)))
+ {
+ new_chunk->prev = old_chunk->prev;
+ CALL_FREEFUN (h, old_chunk);
+ }
+
+ h->object_base = object_base;
+ h->next_free = h->object_base + obj_size;
+ /* The new chunk certainly contains no empty object yet. */
+ h->maybe_empty_object = 0;
+}
+
+/* Return nonzero if object OBJ has been allocated from obstack H.
+ This is here for debugging.
+ If you use it in a program, you are probably losing. */
+
+/* Suppress -Wmissing-prototypes warning. We don't want to declare this in
+ obstack.h because it is just for debugging. */
+int _obstack_allocated_p (struct obstack *h, void *obj);
+
+int
+_obstack_allocated_p (struct obstack *h, void *obj)
+{
+ register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */
+ register struct _obstack_chunk *plp; /* point to previous chunk if any */
+
+ lp = (h)->chunk;
+ /* We use >= rather than > since the object cannot be exactly at
+ the beginning of the chunk but might be an empty object exactly
+ at the end of an adjacent chunk. */
+ while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
+ {
+ plp = lp->prev;
+ lp = plp;
+ }
+ return lp != 0;
+}
+\f
+/* Free objects in obstack H, including OBJ and everything allocate
+ more recently than OBJ. If OBJ is zero, free everything in H. */
+
+# undef obstack_free
+
+void
+obstack_free (struct obstack *h, void *obj)
+{
+ register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */
+ register struct _obstack_chunk *plp; /* point to previous chunk if any */
+
+ lp = h->chunk;
+ /* We use >= because there cannot be an object at the beginning of a chunk.
+ But there can be an empty object at that address
+ at the end of another chunk. */
+ while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
+ {
+ plp = lp->prev;
+ CALL_FREEFUN (h, lp);
+ lp = plp;
+ /* If we switch chunks, we can't tell whether the new current
+ chunk contains an empty object, so assume that it may. */
+ h->maybe_empty_object = 1;
+ }
+ if (lp)
+ {
+ h->object_base = h->next_free = (char *) (obj);
+ h->chunk_limit = lp->limit;
+ h->chunk = lp;
+ }
+ else if (obj != 0)
+ /* obj is not in any of the chunks! */
+ abort ();
+}
+
+int
+_obstack_memory_used (struct obstack *h)
+{
+ register struct _obstack_chunk* lp;
+ register int nbytes = 0;
+
+ for (lp = h->chunk; lp != 0; lp = lp->prev)
+ {
+ nbytes += lp->limit - (char *) lp;
+ }
+ return nbytes;
+}
+
+static void
+__attribute__ ((noreturn))
+print_and_abort (void)
+{
+ /* Don't change any of these strings. Yes, it would be possible to add
+ the newline to the string and use fputs or so. But this must not
+ happen because the "memory exhausted" message appears in other places
+ like this and the translation should be reused instead of creating
+ a very similar string which requires a separate translation. */
+ fprintf (stderr, "%s\n", "memory exhausted");
+ exit (obstack_exit_failure);
+}
--- /dev/null
+/* obstack.h - object stack macros
+ Copyright (C) 1988-1994,1996-1999,2003,2004,2005
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+/* Summary:
+
+All the apparent functions defined here are macros. The idea
+is that you would use these pre-tested macros to solve a
+very specific set of problems, and they would run fast.
+Caution: no side-effects in arguments please!! They may be
+evaluated MANY times!!
+
+These macros operate a stack of objects. Each object starts life
+small, and may grow to maturity. (Consider building a word syllable
+by syllable.) An object can move while it is growing. Once it has
+been "finished" it never changes address again. So the "top of the
+stack" is typically an immature growing object, while the rest of the
+stack is of mature, fixed size and fixed address objects.
+
+These routines grab large chunks of memory, using a function you
+supply, called `obstack_chunk_alloc'. On occasion, they free chunks,
+by calling `obstack_chunk_free'. You must define them and declare
+them before using any obstack macros.
+
+Each independent stack is represented by a `struct obstack'.
+Each of the obstack macros expects a pointer to such a structure
+as the first argument.
+
+One motivation for this package is the problem of growing char strings
+in symbol tables. Unless you are "fascist pig with a read-only mind"
+--Gosper's immortal quote from HAKMEM item 154, out of context--you
+would not like to put any arbitrary upper limit on the length of your
+symbols.
+
+In practice this often means you will build many short symbols and a
+few long symbols. At the time you are reading a symbol you don't know
+how long it is. One traditional method is to read a symbol into a
+buffer, realloc()ating the buffer every time you try to read a symbol
+that is longer than the buffer. This is beaut, but you still will
+want to copy the symbol from the buffer to a more permanent
+symbol-table entry say about half the time.
+
+With obstacks, you can work differently. Use one obstack for all symbol
+names. As you read a symbol, grow the name in the obstack gradually.
+When the name is complete, finalize it. Then, if the symbol exists already,
+free the newly read name.
+
+The way we do this is to take a large chunk, allocating memory from
+low addresses. When you want to build a symbol in the chunk you just
+add chars above the current "high water mark" in the chunk. When you
+have finished adding chars, because you got to the end of the symbol,
+you know how long the chars are, and you can create a new object.
+Mostly the chars will not burst over the highest address of the chunk,
+because you would typically expect a chunk to be (say) 100 times as
+long as an average object.
+
+In case that isn't clear, when we have enough chars to make up
+the object, THEY ARE ALREADY CONTIGUOUS IN THE CHUNK (guaranteed)
+so we just point to it where it lies. No moving of chars is
+needed and this is the second win: potentially long strings need
+never be explicitly shuffled. Once an object is formed, it does not
+change its address during its lifetime.
+
+When the chars burst over a chunk boundary, we allocate a larger
+chunk, and then copy the partly formed object from the end of the old
+chunk to the beginning of the new larger chunk. We then carry on
+accreting characters to the end of the object as we normally would.
+
+A special macro is provided to add a single char at a time to a
+growing object. This allows the use of register variables, which
+break the ordinary 'growth' macro.
+
+Summary:
+ We allocate large chunks.
+ We carve out one object at a time from the current chunk.
+ Once carved, an object never moves.
+ We are free to append data of any size to the currently
+ growing object.
+ Exactly one object is growing in an obstack at any one time.
+ You can run one obstack per control block.
+ You may have as many control blocks as you dare.
+ Because of the way we do it, you can `unwind' an obstack
+ back to a previous state. (You may remove objects much
+ as you would with a stack.)
+*/
+
+
+/* Don't do the contents of this file more than once. */
+
+#ifndef _OBSTACK_H
+#define _OBSTACK_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+\f
+/* We need the type of a pointer subtraction. If __PTRDIFF_TYPE__ is
+ defined, as with GNU C, use that; that way we don't pollute the
+ namespace with <stddef.h>'s symbols. Otherwise, include <stddef.h>
+ and use ptrdiff_t. */
+
+#ifdef __PTRDIFF_TYPE__
+# define PTR_INT_TYPE __PTRDIFF_TYPE__
+#else
+# include <stddef.h>
+# define PTR_INT_TYPE ptrdiff_t
+#endif
+
+/* If B is the base of an object addressed by P, return the result of
+ aligning P to the next multiple of A + 1. B and P must be of type
+ char *. A + 1 must be a power of 2. */
+
+#define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
+
+/* Similiar to _BPTR_ALIGN (B, P, A), except optimize the common case
+ where pointers can be converted to integers, aligned as integers,
+ and converted back again. If PTR_INT_TYPE is narrower than a
+ pointer (e.g., the AS/400), play it safe and compute the alignment
+ relative to B. Otherwise, use the faster strategy of computing the
+ alignment relative to 0. */
+
+#define __PTR_ALIGN(B, P, A) \
+ __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \
+ P, A)
+
+#include <string.h>
+
+struct _obstack_chunk /* Lives at front of each chunk. */
+{
+ char *limit; /* 1 past end of this chunk */
+ struct _obstack_chunk *prev; /* address of prior chunk or NULL */
+ char contents[4]; /* objects begin here */
+};
+
+struct obstack /* control current object in current chunk */
+{
+ long chunk_size; /* preferred size to allocate chunks in */
+ struct _obstack_chunk *chunk; /* address of current struct obstack_chunk */
+ char *object_base; /* address of object we are building */
+ char *next_free; /* where to add next char to current object */
+ char *chunk_limit; /* address of char after current chunk */
+ union
+ {
+ PTR_INT_TYPE tempint;
+ void *tempptr;
+ } temp; /* Temporary for some macros. */
+ int alignment_mask; /* Mask of alignment for each object. */
+ /* These prototypes vary based on `use_extra_arg', and we use
+ casts to the prototypeless function type in all assignments,
+ but having prototypes here quiets -Wstrict-prototypes. */
+ struct _obstack_chunk *(*chunkfun) (void *, long);
+ void (*freefun) (void *, struct _obstack_chunk *);
+ void *extra_arg; /* first arg for chunk alloc/dealloc funcs */
+ unsigned use_extra_arg:1; /* chunk alloc/dealloc funcs take extra arg */
+ unsigned maybe_empty_object:1;/* There is a possibility that the current
+ chunk contains a zero-length object. This
+ prevents freeing the chunk if we allocate
+ a bigger chunk to replace it. */
+ unsigned alloc_failed:1; /* No longer used, as we now call the failed
+ handler on error, but retained for binary
+ compatibility. */
+};
+
+/* Declare the external functions we use; they are in obstack.c. */
+
+extern void _obstack_newchunk (struct obstack *, int);
+extern int _obstack_begin (struct obstack *, int, int,
+ void *(*) (long), void (*) (void *));
+extern int _obstack_begin_1 (struct obstack *, int, int,
+ void *(*) (void *, long),
+ void (*) (void *, void *), void *);
+extern int _obstack_memory_used (struct obstack *);
+
+void obstack_free (struct obstack *obstack, void *block);
+
+\f
+/* Error handler called when `obstack_chunk_alloc' failed to allocate
+ more memory. This can be set to a user defined function which
+ should either abort gracefully or use longjump - but shouldn't
+ return. The default action is to print a message and abort. */
+extern void (*obstack_alloc_failed_handler) (void);
+
+/* Exit value used when `print_and_abort' is used. */
+extern int obstack_exit_failure;
+\f
+/* Pointer to beginning of object being allocated or to be allocated next.
+ Note that this might not be the final address of the object
+ because a new chunk might be needed to hold the final size. */
+
+#define obstack_base(h) ((void *) (h)->object_base)
+
+/* Size for allocating ordinary chunks. */
+
+#define obstack_chunk_size(h) ((h)->chunk_size)
+
+/* Pointer to next byte not yet allocated in current chunk. */
+
+#define obstack_next_free(h) ((h)->next_free)
+
+/* Mask specifying low bits that should be clear in address of an object. */
+
+#define obstack_alignment_mask(h) ((h)->alignment_mask)
+
+/* To prevent prototype warnings provide complete argument list. */
+#define obstack_init(h) \
+ _obstack_begin ((h), 0, 0, \
+ (void *(*) (long)) obstack_chunk_alloc, \
+ (void (*) (void *)) obstack_chunk_free)
+
+#define obstack_begin(h, size) \
+ _obstack_begin ((h), (size), 0, \
+ (void *(*) (long)) obstack_chunk_alloc, \
+ (void (*) (void *)) obstack_chunk_free)
+
+#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
+ _obstack_begin ((h), (size), (alignment), \
+ (void *(*) (long)) (chunkfun), \
+ (void (*) (void *)) (freefun))
+
+#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
+ _obstack_begin_1 ((h), (size), (alignment), \
+ (void *(*) (void *, long)) (chunkfun), \
+ (void (*) (void *, void *)) (freefun), (arg))
+
+#define obstack_chunkfun(h, newchunkfun) \
+ ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))
+
+#define obstack_freefun(h, newfreefun) \
+ ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
+
+#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar))
+
+#define obstack_blank_fast(h,n) ((h)->next_free += (n))
+
+#define obstack_memory_used(h) _obstack_memory_used (h)
+\f
+#if defined __GNUC__ && defined __STDC__ && __STDC__
+/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
+ does not implement __extension__. But that compiler doesn't define
+ __GNUC_MINOR__. */
+# if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
+# define __extension__
+# endif
+
+/* For GNU C, if not -traditional,
+ we can define these macros to compute all args only once
+ without using a global variable.
+ Also, we can avoid using the `temp' slot, to make faster code. */
+
+# define obstack_object_size(OBSTACK) \
+ __extension__ \
+ ({ struct obstack const *__o = (OBSTACK); \
+ (unsigned) (__o->next_free - __o->object_base); })
+
+# define obstack_room(OBSTACK) \
+ __extension__ \
+ ({ struct obstack const *__o = (OBSTACK); \
+ (unsigned) (__o->chunk_limit - __o->next_free); })
+
+# define obstack_make_room(OBSTACK,length) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ int __len = (length); \
+ if (__o->chunk_limit - __o->next_free < __len) \
+ _obstack_newchunk (__o, __len); \
+ (void) 0; })
+
+# define obstack_empty_p(OBSTACK) \
+ __extension__ \
+ ({ struct obstack const *__o = (OBSTACK); \
+ (__o->chunk->prev == 0 \
+ && __o->next_free == __PTR_ALIGN ((char *) __o->chunk, \
+ __o->chunk->contents, \
+ __o->alignment_mask)); })
+
+# define obstack_grow(OBSTACK,where,length) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ int __len = (length); \
+ if (__o->next_free + __len > __o->chunk_limit) \
+ _obstack_newchunk (__o, __len); \
+ memcpy (__o->next_free, where, __len); \
+ __o->next_free += __len; \
+ (void) 0; })
+
+# define obstack_grow0(OBSTACK,where,length) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ int __len = (length); \
+ if (__o->next_free + __len + 1 > __o->chunk_limit) \
+ _obstack_newchunk (__o, __len + 1); \
+ memcpy (__o->next_free, where, __len); \
+ __o->next_free += __len; \
+ *(__o->next_free)++ = 0; \
+ (void) 0; })
+
+# define obstack_1grow(OBSTACK,datum) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ if (__o->next_free + 1 > __o->chunk_limit) \
+ _obstack_newchunk (__o, 1); \
+ obstack_1grow_fast (__o, datum); \
+ (void) 0; })
+
+/* These assume that the obstack alignment is good enough for pointers
+ or ints, and that the data added so far to the current object
+ shares that much alignment. */
+
+# define obstack_ptr_grow(OBSTACK,datum) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
+ _obstack_newchunk (__o, sizeof (void *)); \
+ obstack_ptr_grow_fast (__o, datum); }) \
+
+# define obstack_int_grow(OBSTACK,datum) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ if (__o->next_free + sizeof (int) > __o->chunk_limit) \
+ _obstack_newchunk (__o, sizeof (int)); \
+ obstack_int_grow_fast (__o, datum); })
+
+# define obstack_ptr_grow_fast(OBSTACK,aptr) \
+__extension__ \
+({ struct obstack *__o1 = (OBSTACK); \
+ *(const void **) __o1->next_free = (aptr); \
+ __o1->next_free += sizeof (const void *); \
+ (void) 0; })
+
+# define obstack_int_grow_fast(OBSTACK,aint) \
+__extension__ \
+({ struct obstack *__o1 = (OBSTACK); \
+ *(int *) __o1->next_free = (aint); \
+ __o1->next_free += sizeof (int); \
+ (void) 0; })
+
+# define obstack_blank(OBSTACK,length) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ int __len = (length); \
+ if (__o->chunk_limit - __o->next_free < __len) \
+ _obstack_newchunk (__o, __len); \
+ obstack_blank_fast (__o, __len); \
+ (void) 0; })
+
+# define obstack_alloc(OBSTACK,length) \
+__extension__ \
+({ struct obstack *__h = (OBSTACK); \
+ obstack_blank (__h, (length)); \
+ obstack_finish (__h); })
+
+# define obstack_copy(OBSTACK,where,length) \
+__extension__ \
+({ struct obstack *__h = (OBSTACK); \
+ obstack_grow (__h, (where), (length)); \
+ obstack_finish (__h); })
+
+# define obstack_copy0(OBSTACK,where,length) \
+__extension__ \
+({ struct obstack *__h = (OBSTACK); \
+ obstack_grow0 (__h, (where), (length)); \
+ obstack_finish (__h); })
+
+/* The local variable is named __o1 to avoid a name conflict
+ when obstack_blank is called. */
+# define obstack_finish(OBSTACK) \
+__extension__ \
+({ struct obstack *__o1 = (OBSTACK); \
+ void *__value = (void *) __o1->object_base; \
+ if (__o1->next_free == __value) \
+ __o1->maybe_empty_object = 1; \
+ __o1->next_free \
+ = __PTR_ALIGN (__o1->object_base, __o1->next_free, \
+ __o1->alignment_mask); \
+ if (__o1->next_free - (char *)__o1->chunk \
+ > __o1->chunk_limit - (char *)__o1->chunk) \
+ __o1->next_free = __o1->chunk_limit; \
+ __o1->object_base = __o1->next_free; \
+ __value; })
+
+# define obstack_free(OBSTACK, OBJ) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ void *__obj = (OBJ); \
+ if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \
+ __o->next_free = __o->object_base = (char *)__obj; \
+ else (obstack_free) (__o, __obj); })
+\f
+#else /* not __GNUC__ or not __STDC__ */
+
+# define obstack_object_size(h) \
+ (unsigned) ((h)->next_free - (h)->object_base)
+
+# define obstack_room(h) \
+ (unsigned) ((h)->chunk_limit - (h)->next_free)
+
+# define obstack_empty_p(h) \
+ ((h)->chunk->prev == 0 \
+ && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk, \
+ (h)->chunk->contents, \
+ (h)->alignment_mask))
+
+/* Note that the call to _obstack_newchunk is enclosed in (..., 0)
+ so that we can avoid having void expressions
+ in the arms of the conditional expression.
+ Casting the third operand to void was tried before,
+ but some compilers won't accept it. */
+
+# define obstack_make_room(h,length) \
+( (h)->temp.tempint = (length), \
+ (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0))
+
+# define obstack_grow(h,where,length) \
+( (h)->temp.tempint = (length), \
+ (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
+ memcpy ((h)->next_free, where, (h)->temp.tempint), \
+ (h)->next_free += (h)->temp.tempint)
+
+# define obstack_grow0(h,where,length) \
+( (h)->temp.tempint = (length), \
+ (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0), \
+ memcpy ((h)->next_free, where, (h)->temp.tempint), \
+ (h)->next_free += (h)->temp.tempint, \
+ *((h)->next_free)++ = 0)
+
+# define obstack_1grow(h,datum) \
+( (((h)->next_free + 1 > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), 1), 0) : 0), \
+ obstack_1grow_fast (h, datum))
+
+# define obstack_ptr_grow(h,datum) \
+( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \
+ obstack_ptr_grow_fast (h, datum))
+
+# define obstack_int_grow(h,datum) \
+( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \
+ obstack_int_grow_fast (h, datum))
+
+# define obstack_ptr_grow_fast(h,aptr) \
+ (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))
+
+# define obstack_int_grow_fast(h,aint) \
+ (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint))
+
+# define obstack_blank(h,length) \
+( (h)->temp.tempint = (length), \
+ (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint) \
+ ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
+ obstack_blank_fast (h, (h)->temp.tempint))
+
+# define obstack_alloc(h,length) \
+ (obstack_blank ((h), (length)), obstack_finish ((h)))
+
+# define obstack_copy(h,where,length) \
+ (obstack_grow ((h), (where), (length)), obstack_finish ((h)))
+
+# define obstack_copy0(h,where,length) \
+ (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
+
+# define obstack_finish(h) \
+( ((h)->next_free == (h)->object_base \
+ ? (((h)->maybe_empty_object = 1), 0) \
+ : 0), \
+ (h)->temp.tempptr = (h)->object_base, \
+ (h)->next_free \
+ = __PTR_ALIGN ((h)->object_base, (h)->next_free, \
+ (h)->alignment_mask), \
+ (((h)->next_free - (char *) (h)->chunk \
+ > (h)->chunk_limit - (char *) (h)->chunk) \
+ ? ((h)->next_free = (h)->chunk_limit) : 0), \
+ (h)->object_base = (h)->next_free, \
+ (h)->temp.tempptr)
+
+# define obstack_free(h,obj) \
+( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk, \
+ ((((h)->temp.tempint > 0 \
+ && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk)) \
+ ? (int) ((h)->next_free = (h)->object_base \
+ = (h)->temp.tempint + (char *) (h)->chunk) \
+ : (((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0)))
+
+#endif /* not __GNUC__ or not __STDC__ */
+
+#ifdef __cplusplus
+} /* C++ */
+#endif
+
+#endif /* obstack.h */
--- /dev/null
+#include <stdarg.h>
+#include <stdio.h>
+#include "obstack.h"
+
+#ifdef _WIN32
+#define vsnprintf _vsnprintf
+#endif
+
+int obstack_printf(struct obstack *obst, const char *fmt, ...)
+{
+ char buf[1024];
+ va_list ap;
+ int len;
+
+ va_start(ap, fmt);
+ len = vsnprintf(buf, sizeof(buf), fmt, ap);
+ obstack_grow(obst, buf, len);
+ va_end(ap);
+
+ return len;
+}