From 0b91d61cb2c8ea26ac273c7189a4481846ea969d Mon Sep 17 00:00:00 2001 From: John Millaway Date: Mon, 27 Mar 2006 19:00:17 +0000 Subject: Added configure check for assert.h. Added scanner flags stack. --- Makefile.am | 3 +++ configure.in | 1 + flexdef.h | 30 +++++++++++++++++++++++++-- scanflags.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 scanflags.c diff --git a/Makefile.am b/Makefile.am index 8d7cef8..21165be 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,6 +51,7 @@ flex_SOURCES = \ ccl.c \ dfa.c \ ecs.c \ + scanflags.c \ gen.c \ main.c \ misc.c \ @@ -152,6 +153,7 @@ buf.o: buf.c flexdef.h flexint.h ccl.o: ccl.c flexdef.h flexint.h dfa.o: dfa.c flexdef.h flexint.h tables.h tables_shared.h ecs.o: ecs.c flexdef.h flexint.h +scanflags.o: scanflags.c flexdef.h flexint.h gen.o: gen.c flexdef.h flexint.h tables.h tables_shared.h libmain.o: libmain.c libyywrap.o: libyywrap.c @@ -197,6 +199,7 @@ indentfiles = \ ccl.c \ dfa.c \ ecs.c \ + scanflags.c \ filter.c \ flexdef.h \ gen.c \ diff --git a/configure.in b/configure.in index ddf7426..03fc350 100644 --- a/configure.in +++ b/configure.in @@ -84,6 +84,7 @@ AC_CHECK_HEADERS( sys/wait.h sys/params.h) AC_CHECK_HEADERS(cunistd) AC_CHECK_HEADERS(locale.h libintl.h) AC_CHECK_HEADERS(regex.h) +AC_CHECK_HEADERS(assert.h) dnl checks for types diff --git a/flexdef.h b/flexdef.h index 7e38602..3005dcf 100644 --- a/flexdef.h +++ b/flexdef.h @@ -48,6 +48,12 @@ #include #include #endif +#ifdef HAVE_ASSERT_H +#include +#else +#define assert(Pred) +#endif + #ifdef HAVE_LIMITS_H #include #endif @@ -257,7 +263,7 @@ /* The percentage the number of homogeneous out-transitions of a state * must be of the number of total out-transitions of the state in order - * that the state's transition table is first compared with a potential + * that the state's transition table is first compared with a potential * template of the most common out-transition instead of with the first * proto in the proto queue. */ @@ -410,7 +416,7 @@ extern int yymore_really_used, reject_really_used; * use_stdout - the -t flag * input_files - array holding names of input files * num_input_files - size of input_files array - * program_name - name with which program was invoked + * program_name - name with which program was invoked * * action_array - array to hold the rule actions * action_size - size of action_array @@ -1180,4 +1186,24 @@ int regmatch_len (regmatch_t * m); int regmatch_strtol (regmatch_t * m, const char *src, char **endptr, int base); bool regmatch_empty (regmatch_t * m); +/* From "scanflags.h" */ +typedef unsigned int scanflags_t; +extern scanflags_t* _sf_stk; +extern size_t _sf_n, _sf_max; /**< stack of scanner flags. */ +#define _SF_CASE_INS 0x0001 +#define _SF_DOT_ALL 0x0002 +#define _SF_SKIP_WS 0x0004 + +#define sf_top() (_sf_stk[sf_n]) +#define sf_case_ins() (sf_top() & _SF_CASE_INS) +#define sf_dot_all() (sf_top() & _SF_DOT_ALL) +#define sf_skip_ws() (sf_top() & _SF_SKIP_WS) +#define sf_set_case_ins(X) ((X) ? (sf_top() |= _SF_CASE_INS) : (sf_top() &= ~_SF_CASE_INS)) +#define sf_set_dot_all(X) ((X) ? (sf_top() |= _SF_DOT_ALL) : (sf_top() &= ~_SF_DOT_ALL)) +#define sf_set_skip_ws(X) ((X) ? (sf_top() |= _SF_SKIP_WS) : (sf_top() &= ~_SF_SKIP_WS)) + +extern void sf_push(void); +extern void sf_pop(void); + + #endif /* not defined FLEXDEF_H */ diff --git a/scanflags.c b/scanflags.c new file mode 100644 index 0000000..503ade0 --- /dev/null +++ b/scanflags.c @@ -0,0 +1,66 @@ +/* scanflags - flags used by scanning. */ + +/* Copyright (c) 1990 The Regents of the University of California. */ +/* All rights reserved. */ + +/* This code is derived from software contributed to Berkeley by */ +/* Vern Paxson. */ + +/* The United States Government has rights in this work pursuant */ +/* to contract no. DE-AC03-76SF00098 between the United States */ +/* Department of Energy and the University of California. */ + +/* This file is part of flex. */ + +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted provided that the following conditions */ +/* are met: */ + +/* 1. Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* 2. Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ + +/* Neither the name of the University nor the names of its contributors */ +/* may be used to endorse or promote products derived from this software */ +/* without specific prior written permission. */ + +/* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ +/* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ +/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ +/* PURPOSE. */ + +#include "flexdef.h" + +scanflags_t* _sf_stk = NULL; +size_t _sf_n=0, _sf_max=0; + +void +sf_push (void) +{ + if (_sf_n + 1 >= _sf_max) + _sf_stk = (scanflags_t*) flex_realloc ( (void*) _sf_stk, sizeof(scanflags_t) * (_sf_max += 32)); + + // copy the top element + _sf_stk[_sf_n + 1] = _sf_stk[_sf_n]; + ++_sf_n; +} + +void +sf_pop (void) +{ + assert(_sf_n > 0); + --_sf_n; +} + +/* one-time initialization. Should be called before any sf_ functions. */ +void +sf_init (void) +{ + assert(_sf_stk == NULL); + _sf_stk = (scanflags_t*) flex_alloc ( sizeof(scanflags_t) * (_sf_max = 32)); + _sf_stk[_sf_n] = 0; +} + +/* vim:set expandtab cindent tabstop=4 softtabstop=4 shiftwidth=4 textwidth=0: */ -- cgit v1.2.3