From 5ae9df5218aafb784cd8f0d5d18df3f5a4606a88 Mon Sep 17 00:00:00 2001 From: Joel Winarske Date: Sun, 2 Sep 2018 14:04:05 -0700 Subject: [PATCH 1/8] first pass --- CMakeLists.txt | 34 + cmake/config.h.in | 264 ++++++++ cmake/flexdef.h | 1249 +++++++++++++++++++++++++++++++++++++ cmake/make_config_h.cmake | 234 +++++++ cmake/regex.h | 658 +++++++++++++++++++ cmake/swap.c | 20 + 6 files changed, 2459 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/config.h.in create mode 100644 cmake/flexdef.h create mode 100644 cmake/make_config_h.cmake create mode 100644 cmake/regex.h create mode 100644 cmake/swap.c diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..7720ba013 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR) + +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake") + +project(flex LANGUAGES C) + +include(make_config_h) + +option(ENABLE_NLS "Enable NLS" FALSE) +option(ENABLE_C_ALLOCA "Enable alloca.c" FALSE) + +# GNU M4 macro processor +# where vs which +if(NOT M4) + set(M4 "/usr/bin/m4") +endif() + +file(GLOB sources src/*.c) +include_directories(src) + +if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") + add_definitions(-D_GNU_SOURCE) +elseif (CMAKE_C_COMPILER_ID MATCHES "MSVC") + add_definitions(-D_CONSOLE -D_MBCS -D_CRT_SECURE_NO_WARNINGS) + list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/src/libmain.c) + list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/src/libyywrap.c) +endif() + +find_package(Threads REQUIRED) +if (CMAKE_USE_PTHREADS_INIT) + add_definitions(-DHAVE_PTHREAD) +endif (CMAKE_USE_PTHREADS_INIT) + +add_executable(flex ${sources}) diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 000000000..15ba185df --- /dev/null +++ b/cmake/config.h.in @@ -0,0 +1,264 @@ +/* src/config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP + systems. This function is required for `alloca.c' support on those systems. + */ +#cmakedefine CRAY_STACKSEG_END + +/* Define to 1 if using `alloca.c'. */ +#cmakedefine C_ALLOCA + +/* Define to 1 if translation of program messages to the user's native + language is requested. */ +#cmakedefine ENABLE_NLS @ENABLE_NLS@ + +/* Define to 1 if you have `alloca', as a function or macro. */ +#cmakedefine HAVE_ALLOCA + +/* Define to 1 if you have and it should be used (not on Ultrix). + */ +#cmakedefine HAVE_ALLOCA_H + +/* Define to 1 if you have the `available.' function. */ +#cmakedefine HAVE_AVAILABLE_ + +/* Define to 1 if you have the `by' function. */ +#cmakedefine HAVE_BY + +/* Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the + CoreFoundation framework. */ +#cmakedefine HAVE_CFLOCALECOPYCURRENT + +/* Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in + the CoreFoundation framework. */ +#cmakedefine HAVE_CFPREFERENCESCOPYAPPVALUE + +/* Define if the GNU dcgettext() function is already present or preinstalled. + */ +#cmakedefine HAVE_DCGETTEXT + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H + +/* Define to 1 if you have the `dnl' function. */ +#cmakedefine HAVE_DNL + +/* Define to 1 if you have the `dup2' function. */ +#cmakedefine HAVE_DUP2 + +/* Define to 1 if you have the `enabled' function. */ +#cmakedefine HAVE_ENABLED + +/* Define to 1 if you have the `fork' function. */ +#cmakedefine HAVE_FORK + +/* Define to 1 if you have the `function.' function. */ +#cmakedefine HAVE_FUNCTION_ + +/* Define if the GNU gettext() function is already present or preinstalled. */ +#cmakedefine HAVE_GETTEXT + +/* Define to 1 if you have the `have' function. */ +#cmakedefine HAVE_HAVE + +/* Define if you have the iconv() function and it works. */ +#cmakedefine HAVE_ICONV + +/* Define to 1 if you have the `if' function. */ +#cmakedefine HAVE_IF + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H + +/* Define to 1 if you have the `is' function. */ +#cmakedefine HAVE_IS + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIBINTL_H + +/* Define to 1 if you have the `m' library (-lm). */ +#cmakedefine HAVE_LIBM + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIMITS_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LOCALE_H + +/* Define to 1 if your system has a GNU libc compatible `malloc' function, and + to 0 otherwise. */ +#cmakedefine HAVE_MALLOC + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MALLOC_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H + +/* Define to 1 if you have the `memset' function. */ +#cmakedefine HAVE_MEMSET + +/* Define to 1 if you have the `Needed' function. */ +#cmakedefine HAVE_NEEDED + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETINET_IN_H + +/* Define to 1 if you have the `NLS' function. */ +#cmakedefine HAVE_NLS + +/* Define to 1 if you have the `not' function. */ +#cmakedefine HAVE_NOT + +/* Define to 1 if you have the `only' function. */ +#cmakedefine HAVE_ONLY + +/* Define to 1 if you have the `OpenBSD' function. */ +#cmakedefine HAVE_OPENBSD + +/* Define to 1 if you have the `pow' function. */ +#cmakedefine HAVE_POW + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PTHREAD_H + +/* Define to 1 if your system has a GNU libc compatible `realloc' function, + and to 0 otherwise. */ +#cmakedefine HAVE_REALLOC + +/* Define to 1 if you have the `reallocarray' function. */ +#cmakedefine HAVE_REALLOCARRAY + +/* Define to 1 if you have the `regcomp' function. */ +#cmakedefine HAVE_REGCOMP + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_REGEX_H + +/* Define to 1 if you have the `replacement' function. */ +#cmakedefine HAVE_REPLACEMENT + +/* Define to 1 if you have the `setlocale' function. */ +#cmakedefine HAVE_SETLOCALE + +/* Define to 1 if stdbool.h conforms to C99. */ +#cmakedefine HAVE_STDBOOL_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H + +/* Define to 1 if you have the `strcasecmp' function. */ +#cmakedefine HAVE_STRCASECMP + +/* Define to 1 if you have the `_stricmp' function. */ +#cmakedefine HAVE__STRICMP + +/* Define to 1 if you have the `strchr' function. */ +#cmakedefine HAVE_STRCHR + +/* Define to 1 if you have the `strdup' function. */ +#cmakedefine HAVE_STRDUP + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H + +/* Define to 1 if you have the `strtol' function. */ +#cmakedefine HAVE_STRTOL + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_WAIT_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H + +/* Define to 1 if you have the `Used' function. */ +#cmakedefine HAVE_USED + +/* Define to 1 if you have the `vfork' function. */ +#cmakedefine HAVE_VFORK + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_VFORK_H + +/* Define to 1 if you have the `We' function. */ +#cmakedefine HAVE_WE + +/* Define to 1 if `fork' works. */ +#cmakedefine HAVE_WORKING_FORK + +/* Define to 1 if `vfork' works. */ +#cmakedefine HAVE_WORKING_VFORK + +/* Define to 1 if the system has the type `_Bool'. */ +#cmakedefine HAVE__BOOL + +/* Define to the m4 executable name. */ +#cmakedefine M4 "@M4@" + +/* Name of package */ +#cmakedefine PACKAGE "@PACKAGE@" + +/* Define to the address where bug reports for this package should be sent. */ +#cmakedefine PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@" + +/* Define to the full name of this package. */ +#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" + +/* Define to the full name and version of this package. */ +#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" + +/* Define to the one symbol short name of this package. */ +#cmakedefine PACKAGE_TARNAME "@PACKAGE_TARNAME@" + +/* Define to the home page for this package. */ +#cmakedefine PACKAGE_URL "@PACKAGE_URL@" + +/* Define to the version of this package. */ +#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" + +/* If using the C implementation of alloca, define if you know the + direction of stack growth for your system; otherwise it will be + automatically deduced at runtime. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ +#cmakedefine STACK_DIRECTION @STACK_DIRECTION@ + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +#cmakedefine VERSION @VERSION@ + +/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a + `char[]'. */ +#cmakedefine YYTEXT_POINTER + +/* Define to empty if `const' does not conform to ANSI C. */ +#cmakedefine const + +/* Define to rpl_malloc if the replacement function should be used. */ +#cmakedefine malloc + +/* Define to `int' if does not define. */ +#cmakedefine pid_t @pid_t@ + +/* Define to rpl_realloc if the replacement function should be used. */ +#cmakedefine realloc + +/* Define to `unsigned int' if does not define. */ +#cmakedefine size_t @size_t@ + +/* Define as `fork' if `vfork' does not work. */ +#cmakedefine vfork diff --git a/cmake/flexdef.h b/cmake/flexdef.h new file mode 100644 index 000000000..2f354efb2 --- /dev/null +++ b/cmake/flexdef.h @@ -0,0 +1,1249 @@ + +/* flexdef - definitions file for flex */ + +/* 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. */ + +#ifndef FLEXDEF_H +#define FLEXDEF_H 1 + +#ifdef _MSC_VER + +#include "sys/stat.h" +#include +#include + +/* Avoid Windows.h - obviously only works for host builds... */ +uint32_t htonl(uint32_t x); +uint16_t htons(uint16_t x); + + +#include +#define close _close +#define dup2 _dup2 +#define dup _dup +#define fileno _fileno +#define fdopen _fdopen +#define unlink _unlink +#define strdup _strdup +#define isatty _isatty + +/* Stubs rfom sys/stat.h */ +#define S_IXUSR 0x0100 // Execute/search permission, owner. +#define S_ISREG(m) (1) + +/* Stubs from missing sys/wait.h */ +#ifdef _POSIX_SOURCE +#define _W_INT(i) (i) +#else +#define _W_INT(w) (*(int *)&(w)) /* convert union wait to int */ +#endif + +#define _WSTATUS(x) (_W_INT(x) & 0177) +#define WIFEXITED(x) (_WSTATUS(x) == 0) +#define WEXITSTATUS(x) (_W_INT(x) >> 8) + +// return program name... +#define _MAX_NODE _MAX_DIR + +#ifdef INT8_MIN +#undef INT8_MIN +#endif +#ifdef INT16_MIN +#undef INT16_MIN +#endif +#ifdef INT32_MIN +#undef INT32_MIN +#endif +#ifdef INT8_MAX +#undef INT8_MAX +#endif +#ifdef INT16_MAX +#undef INT16_MAX +#endif +#ifdef INT32_MAX +#undef INT32_MAX +#endif +#ifdef UINT8_MAX +#undef UINT8_MAX +#endif +#ifdef UINT16_MAX +#undef UINT16_MAX +#endif + + +#endif //_WIN32 + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#if defined(HAVE_LIBGEN_H) +#include /* for XPG version of basename(3) */ +#else +inline char *basename(char *path) { + char fname[ _MAX_FNAME ]; + _splitpath(path, NULL, NULL, fname, NULL); + char *tmp = strstr(path, fname); + tmp[strlen(fname)] = 0; + return tmp; +} +#endif +#include + +#ifdef HAVE_ASSERT_H +#include +#else +#define assert(Pred) +#endif + +#ifdef HAVE_LIMITS_H +#include +#endif +/* Required: dup() and dup2() in */ +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_SYS_PARAMS_H +#include +#endif +/* Required: stat() in */ +#include +/* Required: wait() in */ +#ifdef HAVE_SYS_WAIT_H +#include +#endif +#include +#include +/* Required: regcomp(), regexec() and regerror() in */ +#include +/* Required: strcasecmp() in */ +#ifdef HAVE_STRINGS_H +#include +#endif +#if defined(HAVE__STRICMP) && !defined(HAVE_STRCASECMP) +#define strcasecmp _stricmp +#endif +#ifdef HAVE_STDINT_H +#include +#endif +#include "flexint.h" + +/* We use gettext. So, when we write strings which should be translated, we mark them with _() */ +#ifdef ENABLE_NLS +#ifdef HAVE_LOCALE_H +#include +#endif /* HAVE_LOCALE_H */ +#include "gettext.h" +#define _(String) gettext (String) +#else +#define _(STRING) STRING +#endif /* ENABLE_NLS */ + +/* Always be prepared to generate an 8-bit scanner. */ +#define CSIZE 256 + +/* Size of input alphabet - should be size of ASCII set. */ +#ifndef DEFAULT_CSIZE +#define DEFAULT_CSIZE 128 +#endif + +/* Maximum line length we'll have to deal with. */ +#define MAXLINE 2048 + +#ifndef MIN +#define MIN(x,y) ((x) < (y) ? (x) : (y)) +#endif +#ifndef MAX +#define MAX(x,y) ((x) > (y) ? (x) : (y)) +#endif +#ifndef ABS +#define ABS(x) ((x) < 0 ? -(x) : (x)) +#endif + +/* Whether an integer is a power of two */ +#define is_power_of_2(n) ((n) > 0 && ((n) & ((n) - 1)) == 0) + +#define unspecified -1 + +/* Special chk[] values marking the slots taking by end-of-buffer and action + * numbers. + */ +#define EOB_POSITION -1 +#define ACTION_POSITION -2 + +/* Number of data items per line for -f output. */ +#define NUMDATAITEMS 10 + +/* Number of lines of data in -f output before inserting a blank line for + * readability. + */ +#define NUMDATALINES 10 + +/* transition_struct_out() definitions. */ +#define TRANS_STRUCT_PRINT_LENGTH 14 + +/* Returns true if an nfa state has an epsilon out-transition slot + * that can be used. This definition is currently not used. + */ +#define FREE_EPSILON(state) \ + (transchar[state] == SYM_EPSILON && \ + trans2[state] == NO_TRANSITION && \ + finalst[state] != state) + +/* Returns true if an nfa state has an epsilon out-transition character + * and both slots are free + */ +#define SUPER_FREE_EPSILON(state) \ + (transchar[state] == SYM_EPSILON && \ + trans1[state] == NO_TRANSITION) \ + +/* Maximum number of NFA states that can comprise a DFA state. It's real + * big because if there's a lot of rules, the initial state will have a + * huge epsilon closure. + */ +#define INITIAL_MAX_DFA_SIZE 750 +#define MAX_DFA_SIZE_INCREMENT 750 + + +/* A note on the following masks. They are used to mark accepting numbers + * as being special. As such, they implicitly limit the number of accepting + * numbers (i.e., rules) because if there are too many rules the rule numbers + * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 == + * 8192) so unlikely to actually cause any problems. A check is made in + * new_rule() to ensure that this limit is not reached. + */ + +/* Mask to mark a trailing context accepting number. */ +#define YY_TRAILING_MASK 0x2000 + +/* Mask to mark the accepting number of the "head" of a trailing context + * rule. + */ +#define YY_TRAILING_HEAD_MASK 0x4000 + +/* Maximum number of rules, as outlined in the above note. */ +#define MAX_RULE (YY_TRAILING_MASK - 1) + + +/* NIL must be 0. If not, its special meaning when making equivalence classes + * (it marks the representative of a given e.c.) will be unidentifiable. + */ +#define NIL 0 + +#define JAM -1 /* to mark a missing DFA transition */ +#define NO_TRANSITION NIL +#define UNIQUE -1 /* marks a symbol as an e.c. representative */ +#define INFINITE_REPEAT -1 /* for x{5,} constructions */ + +#define INITIAL_MAX_CCLS 100 /* max number of unique character classes */ +#define MAX_CCLS_INCREMENT 100 + +/* Size of table holding members of character classes. */ +#define INITIAL_MAX_CCL_TBL_SIZE 500 +#define MAX_CCL_TBL_SIZE_INCREMENT 250 + +#define INITIAL_MAX_RULES 100 /* default maximum number of rules */ +#define MAX_RULES_INCREMENT 100 + +#define INITIAL_MNS 2000 /* default maximum number of nfa states */ +#define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */ + +#define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */ +#define MAX_DFAS_INCREMENT 1000 + +#define JAMSTATE -32766 /* marks a reference to the state that always jams */ + +/* Maximum number of NFA states. */ +#define MAXIMUM_MNS 31999 +#define MAXIMUM_MNS_LONG 1999999999 + +/* Enough so that if it's subtracted from an NFA state number, the result + * is guaranteed to be negative. + */ +#define MARKER_DIFFERENCE (maximum_mns+2) + +/* Maximum number of nxt/chk pairs for non-templates. */ +#define INITIAL_MAX_XPAIRS 2000 +#define MAX_XPAIRS_INCREMENT 2000 + +/* Maximum number of nxt/chk pairs needed for templates. */ +#define INITIAL_MAX_TEMPLATE_XPAIRS 2500 +#define MAX_TEMPLATE_XPAIRS_INCREMENT 2500 + +#define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */ + +#define INITIAL_MAX_SCS 40 /* maximum number of start conditions */ +#define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */ + +#define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */ +#define SAME_TRANS -1 /* transition is the same as "default" entry for state */ + +/* The following percentages are used to tune table compression: + + * The percentage the number of out-transitions a state must be of the + * number of equivalence classes in order to be considered for table + * compaction by using protos. + */ +#define PROTO_SIZE_PERCENTAGE 15 + +/* 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 + * template of the most common out-transition instead of with the first + * proto in the proto queue. + */ +#define CHECK_COM_PERCENTAGE 50 + +/* The percentage the number of differences between a state's transition + * table and the proto it was first compared with must be of the total + * number of out-transitions of the state in order to keep the first + * proto as a good match and not search any further. + */ +#define FIRST_MATCH_DIFF_PERCENTAGE 10 + +/* The percentage the number of differences between a state's transition + * table and the most similar proto must be of the state's total number + * of out-transitions to use the proto as an acceptable close match. + */ +#define ACCEPTABLE_DIFF_PERCENTAGE 50 + +/* 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 + * to consider making a template from the state. + */ +#define TEMPLATE_SAME_PERCENTAGE 60 + +/* The percentage the number of differences between a state's transition + * table and the most similar proto must be of the state's total number + * of out-transitions to create a new proto from the state. + */ +#define NEW_PROTO_DIFF_PERCENTAGE 20 + +/* The percentage the total number of out-transitions of a state must be + * of the number of equivalence classes in order to consider trying to + * fit the transition table into "holes" inside the nxt/chk table. + */ +#define INTERIOR_FIT_PERCENTAGE 15 + +/* Size of region set aside to cache the complete transition table of + * protos on the proto queue to enable quick comparisons. + */ +#define PROT_SAVE_SIZE 2000 + +#define MSP 50 /* maximum number of saved protos (protos on the proto queue) */ + +/* Maximum number of out-transitions a state can have that we'll rummage + * around through the interior of the internal fast table looking for a + * spot for it. + */ +#define MAX_XTIONS_FULL_INTERIOR_FIT 4 + +/* Maximum number of rules which will be reported as being associated + * with a DFA state. + */ +#define MAX_ASSOC_RULES 100 + +/* Number that, if used to subscript an array, has a good chance of producing + * an error; should be small enough to fit into a short. + */ +#define BAD_SUBSCRIPT -32767 + +/* Absolute value of largest number that can be stored in a short, with a + * bit of slop thrown in for general paranoia. + */ +#define MAX_SHORT 32700 + + +/* Declarations for global variables. */ + + +/* Variables for flags: + * printstats - if true (-v), dump statistics + * syntaxerror - true if a syntax error has been found + * eofseen - true if we've seen an eof in the input file + * ddebug - if true (-d), make a "debug" scanner + * trace - if true (-T), trace processing + * nowarn - if true (-w), do not generate warnings + * spprdflt - if true (-s), suppress the default rule + * interactive - if true (-I), generate an interactive scanner + * lex_compat - if true (-l), maximize compatibility with AT&T lex + * posix_compat - if true (-X), maximize compatibility with POSIX lex + * do_yylineno - if true, generate code to maintain yylineno + * useecs - if true (-Ce flag), use equivalence classes + * fulltbl - if true (-Cf flag), don't compress the DFA state table + * usemecs - if true (-Cm flag), use meta-equivalence classes + * fullspd - if true (-F flag), use Jacobson method of table representation + * gen_line_dirs - if true (i.e., no -L flag), generate #line directives + * performance_report - if > 0 (i.e., -p flag), generate a report relating + * to scanner performance; if > 1 (-p -p), report on minor performance + * problems, too + * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file + * listing backing-up states + * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class; + * otherwise, a standard C scanner + * reentrant - if true (-R), generate a reentrant C scanner. + * bison_bridge_lval - if true (--bison-bridge), bison pure calling convention. + * bison_bridge_lloc - if true (--bison-locations), bison yylloc. + * long_align - if true (-Ca flag), favor long-word alignment. + * use_read - if true (-f, -F, or -Cr) then use read() for scanner input; + * otherwise, use fread(). + * yytext_is_array - if true (i.e., %array directive), then declare + * yytext as a array instead of a character pointer. Nice and inefficient. + * do_yywrap - do yywrap() processing on EOF. If false, EOF treated as + * "no more files". + * csize - size of character set for the scanner we're generating; + * 128 for 7-bit chars and 256 for 8-bit + * yymore_used - if true, yymore() is used in input rules + * reject - if true, generate back-up tables for REJECT macro + * real_reject - if true, scanner really uses REJECT (as opposed to just + * having "reject" set for variable trailing context) + * continued_action - true if this rule's action is to "fall through" to + * the next rule's action (i.e., the '|' action) + * in_rule - true if we're inside an individual rule, false if not. + * yymore_really_used - whether to treat yymore() as really used, regardless + * of what we think based on references to it in the user's actions. + * reject_really_used - same for REJECT + * trace_hex - use hexadecimal numbers in trace/debug outputs instead of octals + */ + +extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, + spprdflt; +extern int interactive, lex_compat, posix_compat, do_yylineno; +extern int useecs, fulltbl, usemecs, fullspd; +extern int gen_line_dirs, performance_report, backing_up_report; +extern int reentrant, bison_bridge_lval, bison_bridge_lloc; +extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap; +extern int csize; +extern int yymore_used, reject, real_reject, continued_action, in_rule; + +extern int yymore_really_used, reject_really_used; +extern int trace_hex; + +/* Variables used in the flex input routines: + * datapos - characters on current output line + * dataline - number of contiguous lines of data in current data + * statement. Used to generate readable -f output + * linenum - current input line number + * skelfile - the skeleton file + * skel - compiled-in skeleton array + * skel_ind - index into "skel" array, if skelfile is nil + * yyin - input file + * backing_up_file - file to summarize backing-up states to + * infilename - name of input file + * outfilename - name of output file + * headerfilename - name of the .h file to generate + * did_outfilename - whether outfilename was explicitly set + * prefix - the prefix used for externally visible names ("yy" by default) + * yyclass - yyFlexLexer subclass to use for YY_DECL + * do_stdinit - whether to initialize yyin/yyout to stdin/stdout + * 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 + * + * action_array - array to hold the rule actions + * action_size - size of action_array + * defs1_offset - index where the user's section 1 definitions start + * in action_array + * prolog_offset - index where the prolog starts in action_array + * action_offset - index where the non-prolog starts in action_array + * action_index - index where the next action should go, with respect + * to "action_array" + */ + +extern int datapos, dataline, linenum; +extern FILE *skelfile, *backing_up_file; +extern const char *skel[]; +extern int skel_ind; +extern char *infilename, *outfilename, *headerfilename; +extern int did_outfilename; +extern char *prefix, *yyclass, *extra_type; +extern int do_stdinit, use_stdout; +extern char **input_files; +extern int num_input_files; +extern char *program_name; + +extern char *action_array; +extern int action_size; +extern int defs1_offset, prolog_offset, action_offset, action_index; + + +/* Variables for stack of states having only one out-transition: + * onestate - state number + * onesym - transition symbol + * onenext - target state + * onedef - default base entry + * onesp - stack pointer + */ + +extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE]; +extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp; + + +/* Variables for nfa machine data: + * maximum_mns - maximal number of NFA states supported by tables + * current_mns - current maximum on number of NFA states + * num_rules - number of the last accepting state; also is number of + * rules created so far + * num_eof_rules - number of <> rules + * default_rule - number of the default rule + * current_max_rules - current maximum number of rules + * lastnfa - last nfa state number created + * firstst - physically the first state of a fragment + * lastst - last physical state of fragment + * finalst - last logical state of fragment + * transchar - transition character + * trans1 - transition state + * trans2 - 2nd transition state for epsilons + * accptnum - accepting number + * assoc_rule - rule associated with this NFA state (or 0 if none) + * state_type - a STATE_xxx type identifying whether the state is part + * of a normal rule, the leading state in a trailing context + * rule (i.e., the state which marks the transition from + * recognizing the text-to-be-matched to the beginning of + * the trailing context), or a subsequent state in a trailing + * context rule + * rule_type - a RULE_xxx type identifying whether this a ho-hum + * normal rule or one which has variable head & trailing + * context + * rule_linenum - line number associated with rule + * rule_useful - true if we've determined that the rule can be matched + * rule_has_nl - true if rule could possibly match a newline + * ccl_has_nl - true if current ccl could match a newline + * nlch - default eol char + */ + +extern int maximum_mns, current_mns, current_max_rules; +extern int num_rules, num_eof_rules, default_rule, lastnfa; +extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2; +extern int *accptnum, *assoc_rule, *state_type; +extern int *rule_type, *rule_linenum, *rule_useful; +extern bool *rule_has_nl, *ccl_has_nl; +extern int nlch; + +/* Different types of states; values are useful as masks, as well, for + * routines like check_trailing_context(). + */ +#define STATE_NORMAL 0x1 +#define STATE_TRAILING_CONTEXT 0x2 + +/* Global holding current type of state we're making. */ + +extern int current_state_type; + +/* Different types of rules. */ +#define RULE_NORMAL 0 +#define RULE_VARIABLE 1 + +/* True if the input rules include a rule with both variable-length head + * and trailing context, false otherwise. + */ +extern int variable_trailing_context_rules; + + +/* Variables for protos: + * numtemps - number of templates created + * numprots - number of protos created + * protprev - backlink to a more-recently used proto + * protnext - forward link to a less-recently used proto + * prottbl - base/def table entry for proto + * protcomst - common state of proto + * firstprot - number of the most recently used proto + * lastprot - number of the least recently used proto + * protsave contains the entire state array for protos + */ + +extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP]; +extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE]; + + +/* Variables for managing equivalence classes: + * numecs - number of equivalence classes + * nextecm - forward link of Equivalence Class members + * ecgroup - class number or backward link of EC members + * nummecs - number of meta-equivalence classes (used to compress + * templates) + * tecfwd - forward link of meta-equivalence classes members + * tecbck - backward link of MEC's + */ + +/* Reserve enough room in the equivalence class arrays so that we + * can use the CSIZE'th element to hold equivalence class information + * for the NUL character. Later we'll move this information into + * the 0th element. + */ +extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs; + +/* Meta-equivalence classes are indexed starting at 1, so it's possible + * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1 + * slots total (since the arrays are 0-based). nextecm[] and ecgroup[] + * don't require the extra position since they're indexed from 1 .. CSIZE - 1. + */ +extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1]; + + +/* Variables for start conditions: + * lastsc - last start condition created + * current_max_scs - current limit on number of start conditions + * scset - set of rules active in start condition + * scbol - set of rules active only at the beginning of line in a s.c. + * scxclu - true if start condition is exclusive + * sceof - true if start condition has EOF rule + * scname - start condition name + */ + +extern int lastsc, *scset, *scbol, *scxclu, *sceof; +extern int current_max_scs; +extern char **scname; + + +/* Variables for dfa machine data: + * current_max_dfa_size - current maximum number of NFA states in DFA + * current_max_xpairs - current maximum number of non-template xtion pairs + * current_max_template_xpairs - current maximum number of template pairs + * current_max_dfas - current maximum number DFA states + * lastdfa - last dfa state number created + * nxt - state to enter upon reading character + * chk - check value to see if "nxt" applies + * tnxt - internal nxt table for templates + * base - offset into "nxt" for given state + * def - where to go if "chk" disallows "nxt" entry + * nultrans - NUL transition for each state + * NUL_ec - equivalence class of the NUL character + * tblend - last "nxt/chk" table entry being used + * firstfree - first empty entry in "nxt/chk" table + * dss - nfa state set for each dfa + * dfasiz - size of nfa state set for each dfa + * dfaacc - accepting set for each dfa state (if using REJECT), or accepting + * number, if not + * accsiz - size of accepting set for each dfa state + * dhash - dfa state hash value + * numas - number of DFA accepting states created; note that this + * is not necessarily the same value as num_rules, which is the analogous + * value for the NFA + * numsnpairs - number of state/nextstate transition pairs + * jambase - position in base/def where the default jam table starts + * jamstate - state number corresponding to "jam" state + * end_of_buffer_state - end-of-buffer dfa state number + */ + +extern int current_max_dfa_size, current_max_xpairs; +extern int current_max_template_xpairs, current_max_dfas; +extern int lastdfa, *nxt, *chk, *tnxt; +extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, + *dfasiz; +extern union dfaacc_union { + int *dfaacc_set; + int dfaacc_state; +} *dfaacc; +extern int *accsiz, *dhash, numas; +extern int numsnpairs, jambase, jamstate; +extern int end_of_buffer_state; + +/* Variables for ccl information: + * lastccl - ccl index of the last created ccl + * current_maxccls - current limit on the maximum number of unique ccl's + * cclmap - maps a ccl index to its set pointer + * ccllen - gives the length of a ccl + * cclng - true for a given ccl if the ccl is negated + * cclreuse - counts how many times a ccl is re-used + * current_max_ccl_tbl_size - current limit on number of characters needed + * to represent the unique ccl's + * ccltbl - holds the characters in each ccl - indexed by cclmap + */ + +extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse; +extern int current_maxccls, current_max_ccl_tbl_size; +extern unsigned char *ccltbl; + + +/* Variables for miscellaneous information: + * nmstr - last NAME scanned by the scanner + * sectnum - section number currently being parsed + * nummt - number of empty nxt/chk table entries + * hshcol - number of hash collisions detected by snstods + * dfaeql - number of times a newly created dfa was equal to an old one + * numeps - number of epsilon NFA states created + * eps2 - number of epsilon states which have 2 out-transitions + * num_reallocs - number of times it was necessary to realloc() a group + * of arrays + * tmpuses - number of DFA states that chain to templates + * totnst - total number of NFA states used to make DFA states + * peakpairs - peak number of transition pairs we had to store internally + * numuniq - number of unique transitions + * numdup - number of duplicate transitions + * hshsave - number of hash collisions saved by checking number of states + * num_backing_up - number of DFA states requiring backing up + * bol_needed - whether scanner needs beginning-of-line recognition + */ + +extern char nmstr[MAXLINE]; +extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; +extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; +extern int num_backing_up, bol_needed; + +#ifndef HAVE_REALLOCARRAY +void *reallocarray(void *, size_t, size_t); +#endif + +void *allocate_array(int, size_t); +void *reallocate_array(void *, int, size_t); + +#define allocate_integer_array(size) \ + allocate_array(size, sizeof(int)) + +#define reallocate_integer_array(array,size) \ + reallocate_array((void *) array, size, sizeof(int)) + +#define allocate_bool_array(size) \ + allocate_array(size, sizeof(bool)) + +#define reallocate_bool_array(array,size) \ + reallocate_array((void *) array, size, sizeof(bool)) + +#define allocate_int_ptr_array(size) \ + allocate_array(size, sizeof(int *)) + +#define allocate_char_ptr_array(size) \ + allocate_array(size, sizeof(char *)) + +#define allocate_dfaacc_union(size) \ + allocate_array(size, sizeof(union dfaacc_union)) + +#define reallocate_int_ptr_array(array,size) \ + reallocate_array((void *) array, size, sizeof(int *)) + +#define reallocate_char_ptr_array(array,size) \ + reallocate_array((void *) array, size, sizeof(char *)) + +#define reallocate_dfaacc_union(array, size) \ + reallocate_array((void *) array, size, sizeof(union dfaacc_union)) + +#define allocate_character_array(size) \ + allocate_array( size, sizeof(char)) + +#define reallocate_character_array(array,size) \ + reallocate_array((void *) array, size, sizeof(char)) + +#define allocate_Character_array(size) \ + allocate_array(size, sizeof(unsigned char)) + +#define reallocate_Character_array(array,size) \ + reallocate_array((void *) array, size, sizeof(unsigned char)) + + +/* External functions that are cross-referenced among the flex source files. */ + + +/* from file ccl.c */ + +extern void ccladd(int, int); /* add a single character to a ccl */ +extern int cclinit(void); /* make an empty ccl */ +extern void cclnegate(int); /* negate a ccl */ +extern int ccl_set_diff (int a, int b); /* set difference of two ccls. */ +extern int ccl_set_union (int a, int b); /* set union of two ccls. */ + +/* List the members of a set of characters in CCL form. */ +extern void list_character_set(FILE *, int[]); + + +/* from file dfa.c */ + +/* Check a DFA state for backing up. */ +extern void check_for_backing_up(int, int[]); + +/* Check to see if NFA state set constitutes "dangerous" trailing context. */ +extern void check_trailing_context(int *, int, int *, int); + +/* Construct the epsilon closure of a set of ndfa states. */ +extern int *epsclosure(int *, int *, int[], int *, int *); + +/* Increase the maximum number of dfas. */ +extern void increase_max_dfas(void); + +extern void ntod(void); /* convert a ndfa to a dfa */ + +/* Converts a set of ndfa states into a dfa state. */ +extern int snstods(int[], int, int[], int, int, int *); + + +/* from file ecs.c */ + +/* Convert character classes to set of equivalence classes. */ +extern void ccl2ecl(void); + +/* Associate equivalence class numbers with class members. */ +extern int cre8ecs(int[], int[], int); + +/* Update equivalence classes based on character class transitions. */ +extern void mkeccl(unsigned char[], int, int[], int[], int, int); + +/* Create equivalence class for single character. */ +extern void mkechar(int, int[], int[]); + + +/* from file gen.c */ + +extern void do_indent(void); /* indent to the current level */ + +/* Generate the code to keep backing-up information. */ +extern void gen_backing_up(void); + +/* Generate the code to perform the backing up. */ +extern void gen_bu_action(void); + +/* Generate full speed compressed transition table. */ +extern void genctbl(void); + +/* Generate the code to find the action number. */ +extern void gen_find_action(void); + +extern void genftbl(void); /* generate full transition table */ + +/* Generate the code to find the next compressed-table state. */ +extern void gen_next_compressed_state(char *); + +/* Generate the code to find the next match. */ +extern void gen_next_match(void); + +/* Generate the code to find the next state. */ +extern void gen_next_state(int); + +/* Generate the code to make a NUL transition. */ +extern void gen_NUL_trans(void); + +/* Generate the code to find the start state. */ +extern void gen_start_state(void); + +/* Generate data statements for the transition tables. */ +extern void gentabs(void); + +/* Write out a formatted string at the current indentation level. */ +extern void indent_put2s(const char *, const char *); + +/* Write out a string + newline at the current indentation level. */ +extern void indent_puts(const char *); + +extern void make_tables(void); /* generate transition tables */ + + +/* from file main.c */ + +extern void check_options(void); +extern void flexend(int); +extern void usage(void); + + +/* from file misc.c */ + +/* Add a #define to the action file. */ +extern void action_define(const char *defname, int value); + +/* Add the given text to the stored actions. */ +extern void add_action(const char *new_text); + +/* True if a string is all lower case. */ +extern int all_lower(char *); + +/* True if a string is all upper case. */ +extern int all_upper(char *); + +/* Compare two integers for use by qsort. */ +extern int intcmp(const void *, const void *); + +/* Check a character to make sure it's in the expected range. */ +extern void check_char(int c); + +/* Replace upper-case letter to lower-case. */ +extern unsigned char clower(int); + +/* strdup() that fails fatally on allocation failures. */ +extern char *xstrdup(const char *); + +/* Compare two characters for use by qsort with '\0' sorting last. */ +extern int cclcmp(const void *, const void *); + +/* Finish up a block of data declarations. */ +extern void dataend(void); + +/* Flush generated data statements. */ +extern void dataflush(void); + +/* Report an error message and terminate. */ +extern void flexerror(const char *); + +/* Report a fatal error message and terminate. */ +extern void flexfatal(const char *); + +/* Report a fatal error with a pinpoint, and terminate */ +#if HAVE_DECL___FUNC__ +#define flex_die(msg) \ + do{ \ + fprintf (stderr,\ + _("%s: fatal internal error at %s:%d (%s): %s\n"),\ + program_name, __FILE__, (int)__LINE__,\ + __func__,msg);\ + FLEX_EXIT(1);\ + }while(0) +#else /* ! HAVE_DECL___FUNC__ */ +#define flex_die(msg) \ + do{ \ + fprintf (stderr,\ + _("%s: fatal internal error at %s:%d %s\n"),\ + program_name, __FILE__, (int)__LINE__,\ + msg);\ + FLEX_EXIT(1);\ + }while(0) +#endif /* ! HAVE_DECL___func__ */ + +/* Report an error message formatted */ +extern void lerr(const char *, ...) +#if defined(__GNUC__) && __GNUC__ >= 3 + __attribute__((__format__(__printf__, 1, 2))) +#endif +; + +/* Like lerr, but also exit after displaying message. */ +extern void lerr_fatal(const char *, ...) +#if defined(__GNUC__) && __GNUC__ >= 3 + __attribute__((__format__(__printf__, 1, 2))) +#endif +; + +/* Spit out a "#line" statement. */ +extern void line_directive_out(FILE *, int); + +/* Mark the current position in the action array as the end of the section 1 + * user defs. + */ +extern void mark_defs1(void); + +/* Mark the current position in the action array as the end of the prolog. */ +extern void mark_prolog(void); + +/* Generate a data statment for a two-dimensional array. */ +extern void mk2data(int); + +extern void mkdata(int); /* generate a data statement */ + +/* Return the integer represented by a string of digits. */ +extern int myctoi(const char *); + +/* Return character corresponding to escape sequence. */ +extern unsigned char myesc(unsigned char[]); + +/* Output a (possibly-formatted) string to the generated scanner. */ +extern void out(const char *); +extern void out_dec(const char *, int); +extern void out_dec2(const char *, int, int); +extern void out_hex(const char *, unsigned int); +extern void out_str(const char *, const char *); +extern void out_str3(const char *, const char *, const char *, const char *); +extern void out_str_dec(const char *, const char *, int); +extern void outc(int); +extern void outn(const char *); +extern void out_m4_define(const char* def, const char* val); + +/* Return a printable version of the given character, which might be + * 8-bit. + */ +extern char *readable_form(int); + +/* Write out one section of the skeleton file. */ +extern void skelout(void); + +/* Output a yy_trans_info structure. */ +extern void transition_struct_out(int, int); + +/* Only needed when using certain broken versions of bison to build parse.c. */ +extern void *yy_flex_xmalloc(int); + + +/* from file nfa.c */ + +/* Add an accepting state to a machine. */ +extern void add_accept(int, int); + +/* Make a given number of copies of a singleton machine. */ +extern int copysingl(int, int); + +/* Debugging routine to write out an nfa. */ +extern void dumpnfa(int); + +/* Finish up the processing for a rule. */ +extern void finish_rule(int, int, int, int, int); + +/* Connect two machines together. */ +extern int link_machines(int, int); + +/* Mark each "beginning" state in a machine as being a "normal" (i.e., + * not trailing context associated) state. + */ +extern void mark_beginning_as_normal(int); + +/* Make a machine that branches to two machines. */ +extern int mkbranch(int, int); + +extern int mkclos(int); /* convert a machine into a closure */ +extern int mkopt(int); /* make a machine optional */ + +/* Make a machine that matches either one of two machines. */ +extern int mkor(int, int); + +/* Convert a machine into a positive closure. */ +extern int mkposcl(int); + +extern int mkrep(int, int, int); /* make a replicated machine */ + +/* Create a state with a transition on a given symbol. */ +extern int mkstate(int); + +extern void new_rule(void); /* initialize for a new rule */ + + +/* from file parse.y */ + +/* Build the "<>" action for the active start conditions. */ +extern void build_eof_action(void); + +/* Write out a message formatted with one string, pinpointing its location. */ +extern void format_pinpoint_message(const char *, const char *); + +/* Write out a message, pinpointing its location. */ +extern void pinpoint_message(const char *); + +/* Write out a warning, pinpointing it at the given line. */ +extern void line_warning(const char *, int); + +/* Write out a message, pinpointing it at the given line. */ +extern void line_pinpoint(const char *, int); + +/* Report a formatted syntax error. */ +extern void format_synerr(const char *, const char *); +extern void synerr(const char *); /* report a syntax error */ +extern void format_warn(const char *, const char *); +extern void lwarn(const char *); /* report a warning */ +extern void yyerror(const char *); /* report a parse error */ +extern int yyparse(void); /* the YACC parser */ + + +/* from file scan.l */ + +/* The Flex-generated scanner for flex. */ +extern int flexscan(void); + +/* Open the given file (if NULL, stdin) for scanning. */ +extern void set_input_file(char *); + + +/* from file sym.c */ + +/* Save the text of a character class. */ +extern void cclinstal(char[], int); + +/* Lookup the number associated with character class. */ +extern int ccllookup(char[]); + +extern void ndinstal(const char *, char[]); /* install a name definition */ +extern char *ndlookup(const char *); /* lookup a name definition */ + +/* Increase maximum number of SC's. */ +extern void scextend(void); +extern void scinstal(const char *, int); /* make a start condition */ + +/* Lookup the number associated with a start condition. */ +extern int sclookup(const char *); + + +/* from file tblcmp.c */ + +/* Build table entries for dfa state. */ +extern void bldtbl(int[], int, int, int, int); + +extern void cmptmps(void); /* compress template table entries */ +extern void expand_nxt_chk(void); /* increase nxt/chk arrays */ + +/* Finds a space in the table for a state to be placed. */ +extern int find_table_space(int *, int); +extern void inittbl(void); /* initialize transition tables */ + +/* Make the default, "jam" table entries. */ +extern void mkdeftbl(void); + +/* Create table entries for a state (or state fragment) which has + * only one out-transition. + */ +extern void mk1tbl(int, int, int, int); + +/* Place a state into full speed transition table. */ +extern void place_state(int *, int, int); + +/* Save states with only one out-transition to be processed later. */ +extern void stack1(int, int, int, int); + + +/* from file yylex.c */ + +extern int yylex(void); + +/* A growable array. See buf.c. */ +struct Buf { + void *elts; /* elements. */ + int nelts; /* number of elements. */ + size_t elt_size; /* in bytes. */ + int nmax; /* max capacity of elements. */ +}; + +extern void buf_init(struct Buf * buf, size_t elem_size); +extern void buf_destroy(struct Buf * buf); +extern struct Buf *buf_append(struct Buf * buf, const void *ptr, int n_elem); +extern struct Buf *buf_concat(struct Buf* dest, const struct Buf* src); +extern struct Buf *buf_strappend(struct Buf *, const char *str); +extern struct Buf *buf_strnappend(struct Buf *, const char *str, int nchars); +extern struct Buf *buf_strdefine(struct Buf * buf, const char *str, const char *def); +extern struct Buf *buf_prints(struct Buf *buf, const char *fmt, const char* s); +extern struct Buf *buf_m4_define(struct Buf *buf, const char* def, const char* val); +extern struct Buf *buf_m4_undefine(struct Buf *buf, const char* def); +extern struct Buf *buf_print_strings(struct Buf * buf, FILE* out); +extern struct Buf *buf_linedir(struct Buf *buf, const char* filename, int lineno); + +extern struct Buf userdef_buf; /* a string buffer for #define's generated by user-options on cmd line. */ +extern struct Buf defs_buf; /* a char* buffer to save #define'd some symbols generated by flex. */ +extern struct Buf yydmap_buf; /* a string buffer to hold yydmap elements */ +extern struct Buf m4defs_buf; /* Holds m4 definitions. */ +extern struct Buf top_buf; /* contains %top code. String buffer. */ +extern bool no_section3_escape; /* True if the undocumented option --unsafe-no-m4-sect3-escape was passed */ + +/* For blocking out code from the header file. */ +#define OUT_BEGIN_CODE() outn("m4_ifdef( [[M4_YY_IN_HEADER]],,[[m4_dnl") +#define OUT_END_CODE() outn("]])") + +/* For setjmp/longjmp (instead of calling exit(2)). Linkage in main.c */ +extern jmp_buf flex_main_jmp_buf; + +#define FLEX_EXIT(status) longjmp(flex_main_jmp_buf,(status)+1) + +/* Removes all \n and \r chars from tail of str. returns str. */ +extern char *chomp (char *str); + +/* ctype functions forced to return boolean */ +#define b_isalnum(c) (isalnum(c)?true:false) +#define b_isalpha(c) (isalpha(c)?true:false) +#define b_isascii(c) (isascii(c)?true:false) +#define b_isblank(c) (isblank(c)?true:false) +#define b_iscntrl(c) (iscntrl(c)?true:false) +#define b_isdigit(c) (isdigit(c)?true:false) +#define b_isgraph(c) (isgraph(c)?true:false) +#define b_islower(c) (islower(c)?true:false) +#define b_isprint(c) (isprint(c)?true:false) +#define b_ispunct(c) (ispunct(c)?true:false) +#define b_isspace(c) (isspace(c)?true:false) +#define b_isupper(c) (isupper(c)?true:false) +#define b_isxdigit(c) (isxdigit(c)?true:false) + +/* return true if char is uppercase or lowercase. */ +bool has_case(int c); + +/* Change case of character if possible. */ +int reverse_case(int c); + +/* return false if [c1-c2] is ambiguous for a caseless scanner. */ +bool range_covers_case (int c1, int c2); + +/* + * From "filter.c" + */ + +/** A single stdio filter to execute. + * The filter may be external, such as "sed", or it + * may be internal, as a function call. + */ +struct filter { + int (*filter_func)(struct filter*); /**< internal filter function */ + void * extra; /**< extra data passed to filter_func */ + int argc; /**< arg count */ + const char ** argv; /**< arg vector, \0-terminated */ + struct filter * next; /**< next filter or NULL */ +}; + +/* output filter chain */ +extern struct filter * output_chain; +extern struct filter *filter_create_ext (struct filter * chain, const char *cmd, ...); +struct filter *filter_create_int(struct filter *chain, + int (*filter_func) (struct filter *), + void *extra); +extern bool filter_apply_chain(struct filter * chain); +extern int filter_truncate(struct filter * chain, int max_len); +extern int filter_tee_header(struct filter *chain); +extern int filter_fix_linedirs(struct filter *chain); + + +/* + * From "regex.c" + */ +extern regex_t regex_linedir, regex_blank_line; +bool flex_init_regex(void); +void flex_regcomp(regex_t *preg, const char *regex, int cflags); +char *regmatch_dup (regmatch_t * m, const char *src); +char *regmatch_cpy (regmatch_t * m, char *dest, const char *src); +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_top_ix, _sf_max; /**< stack of scanner flags. */ +#define _SF_CASE_INS ((scanflags_t) 0x0001) +#define _SF_DOT_ALL ((scanflags_t) 0x0002) +#define _SF_SKIP_WS ((scanflags_t) 0x0004) +#define sf_top() (_sf_stk[_sf_top_ix]) +#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_init(void); +extern void sf_push(void); +extern void sf_pop(void); + +#endif /* not defined FLEXDEF_H */ diff --git a/cmake/make_config_h.cmake b/cmake/make_config_h.cmake new file mode 100644 index 000000000..e1e50d8ca --- /dev/null +++ b/cmake/make_config_h.cmake @@ -0,0 +1,234 @@ +include(CheckIncludeFiles) +include(CheckFunctionExists) +include(CheckLibraryExists) +include(CheckTypeSize) +include(CheckPrototypeDefinition) + + +check_include_files(dlfcn.h HAVE_DLFCN_H) +check_include_files(stdint.h HAVE_STDINT_H) +check_include_files(stddef.h HAVE_STDDEF_H) +check_include_files(inttypes.h HAVE_INITTYPES_H) +check_include_files(stdlib.h HAVE_STDLIB_H) +check_include_files(strings.h HAVE_STRINGS_H) +check_include_files(string.h HAVE_STRING_H) + +if(HAVE_DLFCN_H AND HAVE_STDINT_H AND HAVE_STDDEF_H AND HAVE_INITTYPES_H AND + HAVE_STDLIB_H AND HAVE_STRINGS_H AND HAVE_STRING_H ) + check_prototype_exists(memchr string.h memchrExists) + if(memchrExists) + check_prototype_exists(free stdlib.h freeExists) + if(freeExists) + message(STATUS "ANSI C header files - found") + set(STDC_HEADERS 1 CACHE INTERNAL "System has ANSI C header files") + #set(HAVE_STRINGS_H 1) + #set(HAVE_STRING_H 1) + #set(HAVE_STDLIB_H 1) + #set(HAVE_STDDEF_H 1) + #set(HAVE_STDINT_H 1) + #set(HAVE_INTTYPES_H 1) + #set(HAVE_DLFCN_H 1) + endif(freeExists) + endif(memchrExists) +endif() + + + +check_function_exists(alloca HAVE_ALLOCA) +check_include_files(alloca.h HAVE_ALLOCA_H_CHECK) +if(ENABLE_C_ALLOCA AND HAVE_ALLOCA_H_CHECK) + set(HAVE_ALLOCA_H TRUE) + if(NOT STACK_DIRECTION) + set(STACK_DIRECTION 0) # auto - direction of growth unknown + endif() +endif() + +check_function_exists("available." HAVE_AVAILABLE_) +check_function_exists(by HAVE_BY) + +if(APPLE) + check_function_exists(CFLocaleCopyCurrent HAVE_CFLOCALECOPYCURRENT) + check_function_exists(CFPreferencesCopyAppValue HAVE_CFPREFERENCESCOPYAPPVALUE) +endif() + +check_function_exists(dcgettext HAVE_DCGETTEXT) +check_function_exists(dnl HAVE_DNL) +check_function_exists(dup2 HAVE_DUP2) +check_function_exists(enabled HAVE_ENABLED) +check_function_exists(fork HAVE_FORK) +check_function_exists(function. HAVE_FUNCTION_) +check_function_exists(gettext HAVE_GETTEXT) +check_function_exists(have HAVE_HAVE) +check_function_exists(iconv HAVE_ICONV) +check_function_exists(if HAVE_IF) +check_function_exists(is HAVE_IS) +check_include_files(libintl.h HAVE_LIBINTL_H) +check_library_exists(m log10 "" HAVE_LIBM) +check_include_files(limits.h HAVE_LIMITS_H) +check_include_files(locale.h HAVE_LOCALE_H) +check_function_exists(malloc HAVE_MALLOC) +check_include_files(malloc.h HAVE_MALLOC_H) +check_include_files(memory.h HAVE_MEMORY_H) +check_function_exists(memset HAVE_MEMSET) +check_function_exists(Needed HAVE_NEEDED) +check_include_files(netinet/in.h HAVE_NETINET_IN_H) +check_include_files("arpa/inet.h" HAVE_ARPA_INET_H) +if(NOT HAVE_ARPA_INET_H) + configure_file(${CMAKE_SOURCE_DIR}/cmake/swap.c ${CMAKE_SOURCE_DIR}/src/swap.c COPYONLY) +endif() +check_function_exists(NLS HAVE_NLS) +check_function_exists("not" HAVE_NOT) +check_function_exists(only HAVE_ONLY) +check_function_exists(OpenBSD HAVE_OPENBSD) +check_function_exists(pow HAVE_POW) +check_include_files(pthread.h HAVE_PTHREAD) +check_function_exists(realloc HAVE_REALLOC) +check_function_exists(reallocarray HAVE_REALLOCARRAY) +check_function_exists(regcomp HAVE_REGCOMP) +check_include_files(regex.h HAVE_REGEX_H) +if(NOT HAVE_REGX_H) + #add_definitions(-D_LIBC) + configure_file(${CMAKE_SOURCE_DIR}/cmake/regex.h ${CMAKE_SOURCE_DIR}/src/regex.h COPYONLY) + #configure_file(${CMAKE_SOURCE_DIR}/cmake/regex.c ${CMAKE_SOURCE_DIR}/src/regex.c COPYONLY) +endif() +check_function_exists(replacement HAVE_REPLACEMENT) +check_function_exists(setlocale HAVE_SETLOCALE) +check_include_files(stdbool.h HAVE_STDBOOL_H) +check_function_exists(strcasecmp HAVE_STRCASECMP) +check_function_exists(_stricmp HAVE__STRICMP) +check_function_exists(strchr HAVE_STRCHR) +check_function_exists(strdup HAVE_STRDUP) +check_function_exists(strtol HAVE_STRTOL) +check_include_files("sys/stat.h" HAVE_SYS_STAT_H) +check_include_files("sys/types.h" HAVE_SYS_TYPES_H) +check_include_files("sys/wait.h" HAVE_SYS_WAIT_H) +check_include_files(unistd.h HAVE_UNISTD_H) +if(NOT HAVE_UNISTD_H) + add_definitions(-DYY_NO_UNISTD_H) +endif() +check_function_exists(Used HAVE_USED) +check_function_exists(vfork HAVE_VFORK) +check_include_files(vfork.h HAVE_VFORK_H) +check_function_exists(We HAVE_WE) + +# Define to 1 if `fork' works. +set(HAVE_WORKING_FORK FALSE) + +# Define to 1 if `vfork' works. +set(HAVE_WORKING_VFORK FALSE) + +check_type_size(_Bool HAVE__BOOL_SIZE) +if(HAVE__BOOL_SIZE) + set(HAVE__BOOL 1) +else() + set(HAVE__BOOL 0) +endif() + + +# Define to the m4 executable name. +set(M4 "/usr/bin/m4") + + +# Parse package info from configure.ac +file(STRINGS "configure.ac" flex_ACINIT_LINE LIMIT_COUNT 1 REGEX "^AC_INIT") + +#Before: "AC_INIT([the fast lexical analyser generator],[2.6.4],[flex-help@lists.sourceforge.net],[flex])" +string(REPLACE "(" "_" flex_ACINIT_LINE ${flex_ACINIT_LINE}) +string(REPLACE ")" "_" flex_ACINIT_LINE ${flex_ACINIT_LINE}) +string(REPLACE "[" "_" flex_ACINIT_LINE ${flex_ACINIT_LINE}) +string(REPLACE "]" "_" flex_ACINIT_LINE ${flex_ACINIT_LINE}) +#After: "AC_INIT__the fast lexical analyser generator_,_2.6.4_,_flex-help@lists.sourceforge.net_,_flex__" + +# Parse name +string(REGEX REPLACE "^AC_INIT__([^_]+).*$" "\\1" flex_PACKAGE_NAME "${flex_ACINIT_LINE}") +MESSAGE(STATUS "PACAKGE_NAME=${flex_PACKAGE_NAME}") + +# Parse version string +string(REGEX REPLACE "^AC_INIT__${flex_PACKAGE_NAME}_,_([^_]+).*$" "\\1" flex_VERSION_STRING "${flex_ACINIT_LINE}") +string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\1" + flex_VERSION_MAJOR "${flex_VERSION_STRING}") +string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\2" + flex_VERSION_MINOR "${flex_VERSION_STRING}") +string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\3" + flex_VERSION_PATCH "${flex_VERSION_STRING}") + +# Package version +set(flex_VERSION "${flex_VERSION_MAJOR}.${flex_VERSION_MINOR}.${flex_VERSION_PATCH}") + +# Name of package +set(PACKAGE "flex") + +# Define to the address where bug reports for this package should be sent. +set(PACKAGE_BUGREPORT ${flex_BUGREPORT_STRING}) +MESSAGE(STATUS "PACKAGE_BUGREPORT=${PACKAGE_BUGREPORT}") + +# Define to the full name of this package. +set(PACKAGE_NAME ${flex_NAME}) +MESSAGE(STATUS "PACKAGE_NAME=${PACKAGE_NAME}") + +# Define to the full name and version of this package. +set(PACKAGE_STRING "") + +# Define to the one symbol short name of this package. +set(PACKAGE_TARNAME "") + +# Define to the home page for this package. +set(PACKAGE_URL "") + +# Define to the version of this package. +set(PACKAGE_VERSION ${flex_VERSION}) +MESSAGE(STATUS "PACKAGE_VERSION=${PACKAGE_VERSION}") + +# If using the C implementation of alloca, define if you know the +# direction of stack growth for your system; otherwise it will be +# automatically deduced at runtime. +# STACK_DIRECTION > 0 => grows toward higher addresses +# STACK_DIRECTION < 0 => grows toward lower addresses +# STACK_DIRECTION = 0 => direction of growth unknown +#cmakedefine STACK_DIRECTION + + +# Version number of package +set(VERSION "\"${flex_VERSION_MAJOR}.${flex_VERSION_MINOR}.${flex_VERSION_PATCH}\";") + +# Define to 1 if `lex' declares `yytext' as a `char *' by default, not a `char[]'. +#cmakedefine YYTEXT_POINTER + +# Define to empty if `const' does not conform to ANSI C. +#cmakedefine const + +# Define to rpl_malloc if the replacement function should be used. +#cmakedefine malloc + +# Define to `int' if does not define. +check_type_size(pid_t PID_T_TYPE_SIZE) +if(NOT PID_T_TYPE_SIZE) + MESSAGE(STATUS "Setting pid_t to int") + set(pid_t "int") +endif() + +# Define to rpl_realloc if the replacement function should be used. +#cmakedefine realloc + +# Define to `unsigned int' if does not define. +check_type_size(size_t SIZE_T_TYPE_SIZE) +if(NOT SIZE_T_TYPE_SIZE) + MESSAGE(STATUS "Setting size_t to unsigned int") + set(size_t "unsigned int") +endif() + +# Define as `fork' if `vfork' does not work. +#cmakedefine vfork + +check_include_files(libgen.h HAVE_LIBGEN_H) +check_include_files(assert.h HAVE_ASSERT_H) + +include(TestBigEndian) +test_big_endian(HOST_IS_BIG_ENDIAN) +if(NOT HOST_IS_BIG_ENDIAN) + add_definitions(-DHOST_IS_LITTLE_ENDIAN) +endif() + + +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/config.h.in ${CMAKE_SOURCE_DIR}/src/config.h @ONLY) +add_definitions(-DHAVE_CONFIG_H) \ No newline at end of file diff --git a/cmake/regex.h b/cmake/regex.h new file mode 100644 index 000000000..a1d884f54 --- /dev/null +++ b/cmake/regex.h @@ -0,0 +1,658 @@ +/* Definitions for data structures and routines for the regular + expression library. + Copyright (C) 1985, 1989-2018 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, see + . */ + +#ifndef _REGEX_H +#define _REGEX_H 1 + +#include + +/* Allow the use in C++ code. */ +#ifdef __cplusplus +extern "C" { +#endif + +/* Define __USE_GNU to declare GNU extensions that violate the + POSIX name space rules. */ +#ifdef _GNU_SOURCE +# define __USE_GNU 1 +#endif + +#ifdef _REGEX_LARGE_OFFSETS + +/* Use types and values that are wide enough to represent signed and + unsigned byte offsets in memory. This currently works only when + the regex code is used outside of the GNU C library; it is not yet + supported within glibc itself, and glibc users should not define + _REGEX_LARGE_OFFSETS. */ + +/* The type of object sizes. */ +typedef size_t __re_size_t; + +/* The type of object sizes, in places where the traditional code + uses unsigned long int. */ +typedef size_t __re_long_size_t; + +#else + +/* The traditional GNU regex implementation mishandles strings longer + than INT_MAX. */ +typedef unsigned int __re_size_t; +typedef unsigned long int __re_long_size_t; + +#endif + +/* The following two types have to be signed and unsigned integer type + wide enough to hold a value of a pointer. For most ANSI compilers + ptrdiff_t and size_t should be likely OK. Still size of these two + types is 2 for Microsoft C. Ugh... */ +typedef long int s_reg_t; +typedef unsigned long int active_reg_t; + +/* The following bits are used to determine the regexp syntax we + recognize. The set/not-set meanings are chosen so that Emacs syntax + remains the value 0. The bits are given in alphabetical order, and + the definitions shifted by one from the previous bit; thus, when we + add or remove a bit, only one other definition need change. */ +typedef unsigned long int reg_syntax_t; + +#ifdef __USE_GNU +/* If this bit is not set, then \ inside a bracket expression is literal. + If set, then such a \ quotes the following character. */ +# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) + +/* If this bit is not set, then + and ? are operators, and \+ and \? are + literals. + If set, then \+ and \? are operators and + and ? are literals. */ +# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) + +/* If this bit is set, then character classes are supported. They are: + [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], + [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. + If not set, then character classes are not supported. */ +# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) + +/* If this bit is set, then ^ and $ are always anchors (outside bracket + expressions, of course). + If this bit is not set, then it depends: + ^ is an anchor if it is at the beginning of a regular + expression or after an open-group or an alternation operator; + $ is an anchor if it is at the end of a regular expression, or + before a close-group or an alternation operator. + + This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because + POSIX draft 11.2 says that * etc. in leading positions is undefined. + We already implemented a previous draft which made those constructs + invalid, though, so we haven't changed the code back. */ +# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) + +/* If this bit is set, then special characters are always special + regardless of where they are in the pattern. + If this bit is not set, then special characters are special only in + some contexts; otherwise they are ordinary. Specifically, + * + ? and intervals are only special when not after the beginning, + open-group, or alternation operator. */ +# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) + +/* If this bit is set, then *, +, ?, and { cannot be first in an re or + immediately after an alternation or begin-group operator. */ +# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) + +/* If this bit is set, then . matches newline. + If not set, then it doesn't. */ +# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) + +/* If this bit is set, then . doesn't match NUL. + If not set, then it does. */ +# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) + +/* If this bit is set, nonmatching lists [^...] do not match newline. + If not set, they do. */ +# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) + +/* If this bit is set, either \{...\} or {...} defines an + interval, depending on RE_NO_BK_BRACES. + If not set, \{, \}, {, and } are literals. */ +# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) + +/* If this bit is set, +, ? and | aren't recognized as operators. + If not set, they are. */ +# define RE_LIMITED_OPS (RE_INTERVALS << 1) + +/* If this bit is set, newline is an alternation operator. + If not set, newline is literal. */ +# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) + +/* If this bit is set, then '{...}' defines an interval, and \{ and \} + are literals. + If not set, then '\{...\}' defines an interval. */ +# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) + +/* If this bit is set, (...) defines a group, and \( and \) are literals. + If not set, \(...\) defines a group, and ( and ) are literals. */ +# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) + +/* If this bit is set, then \ matches . + If not set, then \ is a back-reference. */ +# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) + +/* If this bit is set, then | is an alternation operator, and \| is literal. + If not set, then \| is an alternation operator, and | is literal. */ +# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) + +/* If this bit is set, then an ending range point collating higher + than the starting range point, as in [z-a], is invalid. + If not set, then when ending range point collates higher than the + starting range point, the range is ignored. */ +# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) + +/* If this bit is set, then an unmatched ) is ordinary. + If not set, then an unmatched ) is invalid. */ +# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) + +/* If this bit is set, succeed as soon as we match the whole pattern, + without further backtracking. */ +# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) + +/* If this bit is set, do not process the GNU regex operators. + If not set, then the GNU regex operators are recognized. */ +# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) + +/* If this bit is set, turn on internal regex debugging. + If not set, and debugging was on, turn it off. + This only works if regex.c is compiled -DDEBUG. + We define this bit always, so that all that's needed to turn on + debugging is to recompile regex.c; the calling code can always have + this bit set, and it won't affect anything in the normal case. */ +# define RE_DEBUG (RE_NO_GNU_OPS << 1) + +/* If this bit is set, a syntactically invalid interval is treated as + a string of ordinary characters. For example, the ERE 'a{1' is + treated as 'a\{1'. */ +# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1) + +/* If this bit is set, then ignore case when matching. + If not set, then case is significant. */ +# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1) + +/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only + for ^, because it is difficult to scan the regex backwards to find + whether ^ should be special. */ +# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1) + +/* If this bit is set, then \{ cannot be first in a regex or + immediately after an alternation, open-group or \} operator. */ +# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1) + +/* If this bit is set, then no_sub will be set to 1 during + re_compile_pattern. */ +# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1) +#endif + +/* This global variable defines the particular regexp syntax to use (for + some interfaces). When a regexp is compiled, the syntax used is + stored in the pattern buffer, so changing this does not affect + already-compiled regexps. */ +extern reg_syntax_t re_syntax_options; + +#ifdef __USE_GNU +/* Define combinations of the above bits for the standard possibilities. + (The [[[ comments delimit what gets put into the Texinfo file, so + don't delete them!) */ +/* [[[begin syntaxes]]] */ +# define RE_SYNTAX_EMACS 0 + +# define RE_SYNTAX_AWK \ + (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ + | RE_NO_BK_PARENS | RE_NO_BK_REFS \ + | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ + | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CHAR_CLASSES \ + | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) + +# define RE_SYNTAX_GNU_AWK \ + ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ + | RE_INVALID_INTERVAL_ORD) \ + & ~(RE_DOT_NOT_NULL | RE_CONTEXT_INDEP_OPS \ + | RE_CONTEXT_INVALID_OPS )) + +# define RE_SYNTAX_POSIX_AWK \ + (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ + | RE_INTERVALS | RE_NO_GNU_OPS \ + | RE_INVALID_INTERVAL_ORD) + +# define RE_SYNTAX_GREP \ + ((RE_SYNTAX_POSIX_BASIC | RE_NEWLINE_ALT) \ + & ~(RE_CONTEXT_INVALID_DUP | RE_DOT_NOT_NULL)) + +# define RE_SYNTAX_EGREP \ + ((RE_SYNTAX_POSIX_EXTENDED | RE_INVALID_INTERVAL_ORD | RE_NEWLINE_ALT) \ + & ~(RE_CONTEXT_INVALID_OPS | RE_DOT_NOT_NULL)) + +/* POSIX grep -E behavior is no longer incompatible with GNU. */ +# define RE_SYNTAX_POSIX_EGREP \ + RE_SYNTAX_EGREP + +/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ +# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC + +# define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC + +/* Syntax bits common to both basic and extended POSIX regex syntax. */ +# define _RE_SYNTAX_POSIX_COMMON \ + (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ + | RE_INTERVALS | RE_NO_EMPTY_RANGES) + +# define RE_SYNTAX_POSIX_BASIC \ + (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP) + +/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes + RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this + isn't minimal, since other operators, such as \`, aren't disabled. */ +# define RE_SYNTAX_POSIX_MINIMAL_BASIC \ + (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) + +# define RE_SYNTAX_POSIX_EXTENDED \ + (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ + | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ + | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) + +/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is + removed and RE_NO_BK_REFS is added. */ +# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ + (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ + | RE_NO_BK_PARENS | RE_NO_BK_REFS \ + | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) +/* [[[end syntaxes]]] */ + +/* Maximum number of duplicates an interval can allow. POSIX-conforming + systems might define this in , but we want our + value, so remove any previous define. */ +# ifdef _REGEX_INCLUDE_LIMITS_H +# include +# endif +# ifdef RE_DUP_MAX +# undef RE_DUP_MAX +# endif + +/* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored + the counter as a 2-byte signed integer. This is no longer true, so + RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to + ((SIZE_MAX - 9) / 10) if _REGEX_LARGE_OFFSETS is defined. + However, there would be a huge performance problem if someone + actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains + its historical value. */ +# define RE_DUP_MAX (0x7fff) +#endif + + +/* POSIX 'cflags' bits (i.e., information for 'regcomp'). */ + +/* If this bit is set, then use extended regular expression syntax. + If not set, then use basic regular expression syntax. */ +#define REG_EXTENDED 1 + +/* If this bit is set, then ignore case when matching. + If not set, then case is significant. */ +#define REG_ICASE (1 << 1) + +/* If this bit is set, then anchors do not match at newline + characters in the string. + If not set, then anchors do match at newlines. */ +#define REG_NEWLINE (1 << 2) + +/* If this bit is set, then report only success or fail in regexec. + If not set, then returns differ between not matching and errors. */ +#define REG_NOSUB (1 << 3) + + +/* POSIX 'eflags' bits (i.e., information for regexec). */ + +/* If this bit is set, then the beginning-of-line operator doesn't match + the beginning of the string (presumably because it's not the + beginning of a line). + If not set, then the beginning-of-line operator does match the + beginning of the string. */ +#define REG_NOTBOL 1 + +/* Like REG_NOTBOL, except for the end-of-line. */ +#define REG_NOTEOL (1 << 1) + +/* Use PMATCH[0] to delimit the start and end of the search in the + buffer. */ +#define REG_STARTEND (1 << 2) + + +/* If any error codes are removed, changed, or added, update the + '__re_error_msgid' table in regcomp.c. */ + +typedef enum +{ + _REG_ENOSYS = -1, /* This will never happen for this implementation. */ + _REG_NOERROR = 0, /* Success. */ + _REG_NOMATCH, /* Didn't find a match (for regexec). */ + + /* POSIX regcomp return error codes. (In the order listed in the + standard.) */ + _REG_BADPAT, /* Invalid pattern. */ + _REG_ECOLLATE, /* Invalid collating element. */ + _REG_ECTYPE, /* Invalid character class name. */ + _REG_EESCAPE, /* Trailing backslash. */ + _REG_ESUBREG, /* Invalid back reference. */ + _REG_EBRACK, /* Unmatched left bracket. */ + _REG_EPAREN, /* Parenthesis imbalance. */ + _REG_EBRACE, /* Unmatched \{. */ + _REG_BADBR, /* Invalid contents of \{\}. */ + _REG_ERANGE, /* Invalid range end. */ + _REG_ESPACE, /* Ran out of memory. */ + _REG_BADRPT, /* No preceding re for repetition op. */ + + /* Error codes we've added. */ + _REG_EEND, /* Premature end. */ + _REG_ESIZE, /* Too large (e.g., repeat count too large). */ + _REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ +} reg_errcode_t; + +#if defined _XOPEN_SOURCE || defined __USE_XOPEN2K +# define REG_ENOSYS _REG_ENOSYS +#endif +#define REG_NOERROR _REG_NOERROR +#define REG_NOMATCH _REG_NOMATCH +#define REG_BADPAT _REG_BADPAT +#define REG_ECOLLATE _REG_ECOLLATE +#define REG_ECTYPE _REG_ECTYPE +#define REG_EESCAPE _REG_EESCAPE +#define REG_ESUBREG _REG_ESUBREG +#define REG_EBRACK _REG_EBRACK +#define REG_EPAREN _REG_EPAREN +#define REG_EBRACE _REG_EBRACE +#define REG_BADBR _REG_BADBR +#define REG_ERANGE _REG_ERANGE +#define REG_ESPACE _REG_ESPACE +#define REG_BADRPT _REG_BADRPT +#define REG_EEND _REG_EEND +#define REG_ESIZE _REG_ESIZE +#define REG_ERPAREN _REG_ERPAREN + +/* This data structure represents a compiled pattern. Before calling + the pattern compiler, the fields 'buffer', 'allocated', 'fastmap', + and 'translate' can be set. After the pattern has been compiled, + the fields 're_nsub', 'not_bol' and 'not_eol' are available. All + other fields are private to the regex routines. */ + +#ifndef RE_TRANSLATE_TYPE +# define __RE_TRANSLATE_TYPE unsigned char * +# ifdef __USE_GNU +# define RE_TRANSLATE_TYPE __RE_TRANSLATE_TYPE +# endif +#endif + +#ifdef __USE_GNU +# define __REPB_PREFIX(name) name +#else +# define __REPB_PREFIX(name) __##name +#endif + +struct re_pattern_buffer +{ + /* Space that holds the compiled pattern. The type + 'struct re_dfa_t' is private and is not declared here. */ + struct re_dfa_t *__REPB_PREFIX(buffer); + + /* Number of bytes to which 'buffer' points. */ + __re_long_size_t __REPB_PREFIX(allocated); + + /* Number of bytes actually used in 'buffer'. */ + __re_long_size_t __REPB_PREFIX(used); + + /* Syntax setting with which the pattern was compiled. */ + reg_syntax_t __REPB_PREFIX(syntax); + + /* Pointer to a fastmap, if any, otherwise zero. re_search uses the + fastmap, if there is one, to skip over impossible starting points + for matches. */ + char *__REPB_PREFIX(fastmap); + + /* Either a translate table to apply to all characters before + comparing them, or zero for no translation. The translation is + applied to a pattern when it is compiled and to a string when it + is matched. */ + __RE_TRANSLATE_TYPE __REPB_PREFIX(translate); + + /* Number of subexpressions found by the compiler. */ + size_t re_nsub; + + /* Zero if this pattern cannot match the empty string, one else. + Well, in truth it's used only in 're_search_2', to see whether or + not we should use the fastmap, so we don't set this absolutely + perfectly; see 're_compile_fastmap' (the "duplicate" case). */ + unsigned __REPB_PREFIX(can_be_null) : 1; + + /* If REGS_UNALLOCATED, allocate space in the 'regs' structure + for 'max (RE_NREGS, re_nsub + 1)' groups. + If REGS_REALLOCATE, reallocate space if necessary. + If REGS_FIXED, use what's there. */ +#ifdef __USE_GNU +# define REGS_UNALLOCATED 0 +# define REGS_REALLOCATE 1 +# define REGS_FIXED 2 +#endif + unsigned __REPB_PREFIX(regs_allocated) : 2; + + /* Set to zero when 're_compile_pattern' compiles a pattern; set to + one by 're_compile_fastmap' if it updates the fastmap. */ + unsigned __REPB_PREFIX(fastmap_accurate) : 1; + + /* If set, 're_match_2' does not return information about + subexpressions. */ + unsigned __REPB_PREFIX(no_sub) : 1; + + /* If set, a beginning-of-line anchor doesn't match at the beginning + of the string. */ + unsigned __REPB_PREFIX(not_bol) : 1; + + /* Similarly for an end-of-line anchor. */ + unsigned __REPB_PREFIX(not_eol) : 1; + + /* If true, an anchor at a newline matches. */ + unsigned __REPB_PREFIX(newline_anchor) : 1; +}; + +typedef struct re_pattern_buffer regex_t; + +/* Type for byte offsets within the string. POSIX mandates this. */ +#ifdef _REGEX_LARGE_OFFSETS +/* POSIX 1003.1-2008 requires that regoff_t be at least as wide as + ptrdiff_t and ssize_t. We don't know of any hosts where ptrdiff_t + is wider than ssize_t, so ssize_t is safe. ptrdiff_t is not + visible here, so use ssize_t. */ +typedef ssize_t regoff_t; +#else +/* The traditional GNU regex implementation mishandles strings longer + than INT_MAX. */ +typedef int regoff_t; +#endif + + +#ifdef __USE_GNU +/* This is the structure we store register match data in. See + regex.texinfo for a full description of what registers match. */ +struct re_registers +{ + __re_size_t num_regs; + regoff_t *start; + regoff_t *end; +}; + + +/* If 'regs_allocated' is REGS_UNALLOCATED in the pattern buffer, + 're_match_2' returns information about at least this many registers + the first time a 'regs' structure is passed. */ +# ifndef RE_NREGS +# define RE_NREGS 30 +# endif +#endif + + +/* POSIX specification for registers. Aside from the different names than + 're_registers', POSIX uses an array of structures, instead of a + structure of arrays. */ +typedef struct +{ + regoff_t rm_so; /* Byte offset from string's start to substring's start. */ + regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ +} regmatch_t; + +/* Declarations for routines. */ + +#ifdef __USE_GNU +/* Sets the current default syntax to SYNTAX, and return the old syntax. + You can also simply assign to the 're_syntax_options' variable. */ +extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); + +/* Compile the regular expression PATTERN, with length LENGTH + and syntax given by the global 're_syntax_options', into the buffer + BUFFER. Return NULL if successful, and an error string if not. + + To free the allocated storage, you must call 'regfree' on BUFFER. + Note that the translate table must either have been initialized by + 'regcomp', with a malloc'ed value, or set to NULL before calling + 'regfree'. */ +extern const char *re_compile_pattern (const char *__pattern, size_t __length, + struct re_pattern_buffer *__buffer); + + +/* Compile a fastmap for the compiled pattern in BUFFER; used to + accelerate searches. Return 0 if successful and -2 if was an + internal error. */ +extern int re_compile_fastmap (struct re_pattern_buffer *__buffer); + + +/* Search in the string STRING (with length LENGTH) for the pattern + compiled into BUFFER. Start searching at position START, for RANGE + characters. Return the starting position of the match, -1 for no + match, or -2 for an internal error. Also return register + information in REGS (if REGS and BUFFER->no_sub are nonzero). */ +extern regoff_t re_search (struct re_pattern_buffer *__buffer, + const char *__String, regoff_t __length, + regoff_t __start, regoff_t __range, + struct re_registers *__regs); + + +/* Like 're_search', but search in the concatenation of STRING1 and + STRING2. Also, stop searching at index START + STOP. */ +extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer, + const char *__string1, regoff_t __length1, + const char *__string2, regoff_t __length2, + regoff_t __start, regoff_t __range, + struct re_registers *__regs, + regoff_t __stop); + + +/* Like 're_search', but return how many characters in STRING the regexp + in BUFFER matched, starting at position START. */ +extern regoff_t re_match (struct re_pattern_buffer *__buffer, + const char *__String, regoff_t __length, + regoff_t __start, struct re_registers *__regs); + + +/* Relates to 're_match' as 're_search_2' relates to 're_search'. */ +extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer, + const char *__string1, regoff_t __length1, + const char *__string2, regoff_t __length2, + regoff_t __start, struct re_registers *__regs, + regoff_t __stop); + + +/* Set REGS to hold NUM_REGS registers, storing them in STARTS and + ENDS. Subsequent matches using BUFFER and REGS will use this memory + for recording register information. STARTS and ENDS must be + allocated with malloc, and must each be at least 'NUM_REGS * sizeof + (regoff_t)' bytes long. + + If NUM_REGS == 0, then subsequent matches should allocate their own + register data. + + Unless this function is called, the first search or match using + BUFFER will allocate its own register data, without + freeing the old data. */ +extern void re_set_registers (struct re_pattern_buffer *__buffer, + struct re_registers *__regs, + __re_size_t __num_regs, + regoff_t *__starts, regoff_t *__ends); +#endif /* Use GNU */ + +#if defined _REGEX_RE_COMP || (defined _LIBC && defined __USE_MISC) +# ifndef _CRAY +/* 4.2 bsd compatibility. */ +extern char *re_comp (const char *); +extern int re_exec (const char *); +# endif +#endif + +/* For plain 'restrict', use glibc's __restrict if defined. + Otherwise, GCC 2.95 and later have "__restrict"; C99 compilers have + "restrict", and "configure" may have defined "restrict". + Other compilers use __restrict, __restrict__, and _Restrict, and + 'configure' might #define 'restrict' to those words, so pick a + different name. */ +#ifndef _Restrict_ +# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) +# define _Restrict_ __restrict +# elif 199901L <= __STDC_VERSION__ || defined restrict +# define _Restrict_ restrict +# else +# define _Restrict_ +# endif +#endif +/* For [restrict], use glibc's __restrict_arr if available. + Otherwise, GCC 3.1 (not in C++ mode) and C99 support [restrict]. */ +#ifndef _Restrict_arr_ +# ifdef __restrict_arr +# define _Restrict_arr_ __restrict_arr +# elif ((199901L <= __STDC_VERSION__ || 3 < __GNUC__ + (1 <= __GNUC_MINOR__)) \ + && !defined __GNUG__) +# define _Restrict_arr_ _Restrict_ +# else +# define _Restrict_arr_ +# endif +#endif + +/* POSIX compatibility. */ +extern int regcomp (regex_t *_Restrict_ __preg, + const char *_Restrict_ __pattern, + int __cflags); + +extern int regexec (const regex_t *_Restrict_ __preg, + const char *_Restrict_ __String, size_t __nmatch, + regmatch_t __pmatch[_Restrict_arr_], + int __eflags); + +extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg, + char *_Restrict_ __errbuf, size_t __errbuf_size); + +extern void regfree (regex_t *__preg); + + +#ifdef __cplusplus +} +#endif /* C++ */ + +#endif /* regex.h */ \ No newline at end of file diff --git a/cmake/swap.c b/cmake/swap.c new file mode 100644 index 000000000..7f0b693fd --- /dev/null +++ b/cmake/swap.c @@ -0,0 +1,20 @@ +#include + +uint32_t htonl(uint32_t x) +{ +#if HOST_IS_LITTLE_ENDIAN + uint8_t *s = (uint8_t *)&x; + return (uint32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); +#else + return x; +#endif +} +uint16_t htons(uint16_t x) +{ +#if HOST_IS_LITTLE_ENDIAN + uint8_t *s = (uint8_t *)&x; + return (uint16_t)(s[0] << 8 | s[1]); +#else + return x; +#endif +} From 66fa050a8d5a04df47dc643559fd912b5d228fc0 Mon Sep 17 00:00:00 2001 From: Joel Winarske Date: Sun, 2 Sep 2018 16:56:23 -0700 Subject: [PATCH 2/8] Linux builds --- CMakeLists.txt | 79 ++++++++++++++++++++++++++++++++------- cmake/config.h.in | 2 +- cmake/make_config_h.cmake | 38 ++++++++----------- 3 files changed, 81 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7720ba013..31d69b063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,31 +4,82 @@ set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake") project(flex LANGUAGES C) +# Create config.h include(make_config_h) +# Build options option(ENABLE_NLS "Enable NLS" FALSE) option(ENABLE_C_ALLOCA "Enable alloca.c" FALSE) -# GNU M4 macro processor -# where vs which -if(NOT M4) - set(M4 "/usr/bin/m4") -endif() +# Locate M4 path if not set +if(NOT M4_PATH) + if(UNIX OR APPLE) + set(SEARCH_CMD which) + elseif(MINGW OR CYGWIN OR WIN32) + set(SEARCH_CMD where) + endif() -file(GLOB sources src/*.c) -include_directories(src) + execute_process( + COMMAND ${SEARCH_CMD} m4 + OUTPUT_VARIABLE M4_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endif() +MESSAGE(STATUS "Using M4: ${M4_PATH}") +# compiler specifics if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") add_definitions(-D_GNU_SOURCE) elseif (CMAKE_C_COMPILER_ID MATCHES "MSVC") add_definitions(-D_CONSOLE -D_MBCS -D_CRT_SECURE_NO_WARNINGS) - list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/src/libmain.c) - list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/src/libyywrap.c) endif() -find_package(Threads REQUIRED) -if (CMAKE_USE_PTHREADS_INIT) - add_definitions(-DHAVE_PTHREAD) -endif (CMAKE_USE_PTHREADS_INIT) +# generate parse.c +include(FindBISON) +bison_target(parse src/parse.y ${CMAKE_BINARY_DIR}/gen/parse.c) + +# generate scan.c +include(FindFLEX) +FLEX_TARGET(scan src/scan.l ${CMAKE_BINARY_DIR}/gen/scan.c) + +# generate skel.c +string(REPLACE ";" "" STRIPPED_VERSION "${VERSION}") +include(FindUnixCommands) +if(BASH) +add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/gen/skel.c + COMMAND ${BASH} -c "${CMAKE_SOURCE_DIR}/src/mkskel.sh ${CMAKE_SOURCE_DIR}/src ${M4_PATH} ${STRIPPED_VERSION}>skel.c" + DEPENDS ${CMAKE_SOURCE_DIR}/src/mkskel.sh + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gen + COMMENT "[m4][flex.skl] Creating skel.c" +) +# TODO make this step target generic via CMake script +endif() -add_executable(flex ${sources}) +set(GENERATED_SOURCES + ${BISON_parse_OUTPUT_SOURCE} ${FLEX_scan_OUTPUTS} + ${CMAKE_BINARY_DIR}/gen/skel.c +) + +# inlcude files +include_directories(src) +include_directories(${CMAKE_BINARY_DIR}/gen) + +# source files +set(sources + src/buf.c src/ccl.c src/dfa.c src/ecs.c + src/scanflags.c src/filter.c src/flexdef.h + src/gen.c src/misc.c src/nfa.c + src/options.c src/options.h src/regex.c + src/scanopt.c src/scanopt.h src/sym.c + src/tables.c src/tables.h + src/tables_shared.c src/tables_shared.h + src/tblcmp.c src/yylex.c +) + +# command line +add_executable(flex ${sources} src/main.c ${GENERATED_SOURCES}) +install(TARGETS flex DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) + if(UNIX AND NOT ANDROID) + target_link_libraries(flex -lm ${CMAKE_THREAD_LIBS_INIT}) +endif() diff --git a/cmake/config.h.in b/cmake/config.h.in index 15ba185df..647cf5bd3 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -205,7 +205,7 @@ #cmakedefine HAVE__BOOL /* Define to the m4 executable name. */ -#cmakedefine M4 "@M4@" +#define M4 "@M4_PATH@" /* Name of package */ #cmakedefine PACKAGE "@PACKAGE@" diff --git a/cmake/make_config_h.cmake b/cmake/make_config_h.cmake index e1e50d8ca..6289b2d06 100644 --- a/cmake/make_config_h.cmake +++ b/cmake/make_config_h.cmake @@ -15,25 +15,17 @@ check_include_files(string.h HAVE_STRING_H) if(HAVE_DLFCN_H AND HAVE_STDINT_H AND HAVE_STDDEF_H AND HAVE_INITTYPES_H AND HAVE_STDLIB_H AND HAVE_STRINGS_H AND HAVE_STRING_H ) - check_prototype_exists(memchr string.h memchrExists) - if(memchrExists) - check_prototype_exists(free stdlib.h freeExists) - if(freeExists) - message(STATUS "ANSI C header files - found") - set(STDC_HEADERS 1 CACHE INTERNAL "System has ANSI C header files") - #set(HAVE_STRINGS_H 1) - #set(HAVE_STRING_H 1) - #set(HAVE_STDLIB_H 1) - #set(HAVE_STDDEF_H 1) - #set(HAVE_STDINT_H 1) - #set(HAVE_INTTYPES_H 1) - #set(HAVE_DLFCN_H 1) - endif(freeExists) - endif(memchrExists) + check_function_exists(memchr string.h memchrExists) + if(memchrExists) + check_function_exists(free freeExists) + if(freeExists) + message(STATUS "ANSI C header files - found") + set(STDC_HEADERS 1 CACHE INTERNAL "System has ANSI C header files") + endif(freeExists) + endif(memchrExists) endif() - check_function_exists(alloca HAVE_ALLOCA) check_include_files(alloca.h HAVE_ALLOCA_H_CHECK) if(ENABLE_C_ALLOCA AND HAVE_ALLOCA_H_CHECK) @@ -82,11 +74,15 @@ check_function_exists(only HAVE_ONLY) check_function_exists(OpenBSD HAVE_OPENBSD) check_function_exists(pow HAVE_POW) check_include_files(pthread.h HAVE_PTHREAD) +find_package(Threads REQUIRED) +if (CMAKE_USE_PTHREADS_INIT) + add_definitions(-DHAVE_PTHREAD) +endif (CMAKE_USE_PTHREADS_INIT) check_function_exists(realloc HAVE_REALLOC) check_function_exists(reallocarray HAVE_REALLOCARRAY) check_function_exists(regcomp HAVE_REGCOMP) check_include_files(regex.h HAVE_REGEX_H) -if(NOT HAVE_REGX_H) +if(NOT HAVE_REGEX_H) #add_definitions(-D_LIBC) configure_file(${CMAKE_SOURCE_DIR}/cmake/regex.h ${CMAKE_SOURCE_DIR}/src/regex.h COPYONLY) #configure_file(${CMAKE_SOURCE_DIR}/cmake/regex.c ${CMAKE_SOURCE_DIR}/src/regex.c COPYONLY) @@ -125,10 +121,6 @@ else() endif() -# Define to the m4 executable name. -set(M4 "/usr/bin/m4") - - # Parse package info from configure.ac file(STRINGS "configure.ac" flex_ACINIT_LINE LIMIT_COUNT 1 REGEX "^AC_INIT") @@ -230,5 +222,5 @@ if(NOT HOST_IS_BIG_ENDIAN) endif() -CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/config.h.in ${CMAKE_SOURCE_DIR}/src/config.h @ONLY) -add_definitions(-DHAVE_CONFIG_H) \ No newline at end of file +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/config.h.in ${CMAKE_BINARY_DIR}/gen/config.h @ONLY) +add_definitions(-DHAVE_CONFIG_H) From c88ec121b97a182c8487fa85ce96d082389ca5c0 Mon Sep 17 00:00:00 2001 From: Joel Winarske Date: Sun, 2 Sep 2018 17:06:59 -0700 Subject: [PATCH 3/8] add build option for malloc, realloc shims --- CMakeLists.txt | 5 +++++ cmake/config.h.in | 2 +- cmake/make_config_h.cmake | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31d69b063..83cebe48d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ include(make_config_h) # Build options option(ENABLE_NLS "Enable NLS" FALSE) option(ENABLE_C_ALLOCA "Enable alloca.c" FALSE) +option(ENABLE_MEM_SHIM "Replacement malloc, realloc" FALSE) # Locate M4 path if not set if(NOT M4_PATH) @@ -77,6 +78,10 @@ set(sources src/tblcmp.c src/yylex.c ) +if(ENABLE_MEM_SHIM) + list(APPEND sources lib/malloc.c lib/realloc.c) +endif() + # command line add_executable(flex ${sources} src/main.c ${GENERATED_SOURCES}) install(TARGETS flex DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/cmake/config.h.in b/cmake/config.h.in index 647cf5bd3..4f7df13a3 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -249,7 +249,7 @@ #cmakedefine const /* Define to rpl_malloc if the replacement function should be used. */ -#cmakedefine malloc +#cmakedefine malloc @malloc@ /* Define to `int' if does not define. */ #cmakedefine pid_t @pid_t@ diff --git a/cmake/make_config_h.cmake b/cmake/make_config_h.cmake index 6289b2d06..76c58648e 100644 --- a/cmake/make_config_h.cmake +++ b/cmake/make_config_h.cmake @@ -190,7 +190,9 @@ set(VERSION "\"${flex_VERSION_MAJOR}.${flex_VERSION_MINOR}.${flex_VERSION_PATCH} #cmakedefine const # Define to rpl_malloc if the replacement function should be used. -#cmakedefine malloc +if(ENABLE_MEM_SHIM) + set(malloc rpl_malloc) +endif() # Define to `int' if does not define. check_type_size(pid_t PID_T_TYPE_SIZE) From 8c3664776433d1eafc82345de638044505da8bc0 Mon Sep 17 00:00:00 2001 From: Joel Winarske Date: Sun, 2 Sep 2018 21:38:15 -0700 Subject: [PATCH 4/8] Travis CMake --- .travis.yml | 89 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 09cb04148..ddb58f894 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,73 @@ language: c -compiler: - - gcc +matrix: + include: + - env: test="Original" + + os: linux + dist: trusty + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - autoconf + - bison + - gcc-6 + - help2man + - lzip + - texinfo + - texlive + + compiler: gcc + script: ./autogen.sh && ./configure && make && make check && make distcheck + before_script: + - ./.travis/install-gettext.sh + - ./.travis/install-automake.sh + - export PATH=$HOME/bin:$PATH + + - env: test="x64 4.8.4 (CMake gcc)" + os: linux + dist: trusty + compiler: gcc + before_script: + - mkdir gcc_rel && cd gcc_rel + - cmake .. + script: make + + - env: test="x64 5.0 (CMake clang)" + os: linux + dist: trusty + compiler: clang + before_script: + - mkdir clang_rel && cd clang_rel + - cmake .. + script: make + + - env: test="x64 5.0 (CMake clang - Ninja) Debug" + os: linux + dist: trusty + compiler: clang + before_script: + - mkdir clang_ninja_dbg && cd clang_ninja_dbg + - cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug + script: ninja addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - autoconf - - bison - - gcc-6 - - help2man - - lzip - - texinfo - - texlive - -before_script: - - ./.travis/install-gettext.sh - - ./.travis/install-automake.sh - - export PATH=$HOME/bin:$PATH - -script: ./autogen.sh && ./configure && make && make check && make distcheck + + apt: + packages: + - autoconf + - bison + - gcc-6 + - help2man + - lzip + - texinfo + - texlive + - automake + - libtool + - m4 + - cmake + - ninja-build + sources: + - ubuntu-toolchain-r-test From 9f3718610136bbf799cd625132877daddd0d8be2 Mon Sep 17 00:00:00 2001 From: Joel Winarske Date: Sun, 2 Sep 2018 23:32:58 -0700 Subject: [PATCH 5/8] libfl && installation --- .travis.yml | 28 +++++++++++++-------------- CMakeLists.txt | 39 ++++++++++++++++++++++++++++++++++---- cmake/FlexConfig.cmake.in | 8 ++++++++ cmake/libfl.pc.in | 9 +++++++++ cmake/make_config_h.cmake | 4 +++- cmake/make_uninstall.cmake | 19 +++++++++++++++++++ 6 files changed, 87 insertions(+), 20 deletions(-) create mode 100644 cmake/FlexConfig.cmake.in create mode 100644 cmake/libfl.pc.in create mode 100644 cmake/make_uninstall.cmake diff --git a/.travis.yml b/.travis.yml index ddb58f894..d608984dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,19 +6,6 @@ matrix: os: linux dist: trusty - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - autoconf - - bison - - gcc-6 - - help2man - - lzip - - texinfo - - texlive - compiler: gcc script: ./autogen.sh && ./configure && make && make check && make distcheck before_script: @@ -35,7 +22,7 @@ matrix: - cmake .. script: make - - env: test="x64 5.0 (CMake clang)" + - env: test="x64 (CMake clang)" os: linux dist: trusty compiler: clang @@ -44,7 +31,7 @@ matrix: - cmake .. script: make - - env: test="x64 5.0 (CMake clang - Ninja) Debug" + - env: test="x64 (CMake clang - Ninja) Debug" os: linux dist: trusty compiler: clang @@ -53,6 +40,17 @@ matrix: - cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug script: ninja + - env: test="x64 (CMake clang - Ninja) Install / Uninstall" + os: linux + dist: trusty + compiler: clang + before_script: + - mkdir clang_ninja && cd clang_ninja + - cmake .. -GNinja -DCMAKE_INSTALL_PREFIX=./out + script: + - ninja install + - ninja uninstall + addons: apt: diff --git a/CMakeLists.txt b/CMakeLists.txt index 83cebe48d..dc4859a97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake") +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Relase) +endif() + project(flex LANGUAGES C) # Create config.h @@ -58,7 +62,8 @@ add_custom_command( endif() set(GENERATED_SOURCES - ${BISON_parse_OUTPUT_SOURCE} ${FLEX_scan_OUTPUTS} + ${BISON_parse_OUTPUT_SOURCE} + ${FLEX_scan_OUTPUTS} ${CMAKE_BINARY_DIR}/gen/skel.c ) @@ -84,7 +89,33 @@ endif() # command line add_executable(flex ${sources} src/main.c ${GENERATED_SOURCES}) -install(TARGETS flex DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) - if(UNIX AND NOT ANDROID) - target_link_libraries(flex -lm ${CMAKE_THREAD_LIBS_INIT}) +add_library(fl SHARED ${sources} ${GENERATED_SOURCES}) +if(UNIX AND NOT ANDROID) + target_link_libraries(flex -lm ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(fl -lm ${CMAKE_THREAD_LIBS_INIT}) endif() + +# Installation +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +install(TARGETS flex DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(TARGETS fl DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +# pkgconfig +configure_file(${CMAKE_SOURCE_DIR}/cmake/libfl.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libfl.pc @ONLY) +#file(MAKE_DIRECTORY ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libfl.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + +# CMake +configure_package_config_file(cmake/FlexConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FlexConfigVersion.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/flex/cmake) + +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FlexConfigVersion.cmake + VERSION ${PACKAGE_VERSION} COMPATIBILITY ExactVersion) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FlexConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/flex/cmake ) + +# uninstall +add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/cmake/make_uninstall.cmake") \ No newline at end of file diff --git a/cmake/FlexConfig.cmake.in b/cmake/FlexConfig.cmake.in new file mode 100644 index 000000000..a16ad3145 --- /dev/null +++ b/cmake/FlexConfig.cmake.in @@ -0,0 +1,8 @@ +set(FLEX_VERSION @PACKAGE_VERSION@) +... +@PACKAGE_INIT@ +... +set_and_check(FLEX_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(FLEX_SYSCONFIG_DIR "@PACKAGE_SYSCONFIG_INSTALL_DIR@") + +check_required_components(Foo) diff --git a/cmake/libfl.pc.in b/cmake/libfl.pc.in new file mode 100644 index 000000000..cc163f68f --- /dev/null +++ b/cmake/libfl.pc.in @@ -0,0 +1,9 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib + +Name: libfl +Description: Flex (the fast lexical analyzer) support library +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -lfl + diff --git a/cmake/make_config_h.cmake b/cmake/make_config_h.cmake index 76c58648e..37f52aca2 100644 --- a/cmake/make_config_h.cmake +++ b/cmake/make_config_h.cmake @@ -145,10 +145,11 @@ string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\3" flex_VERSION_PATCH "${flex_VERSION_STRING}") # Package version -set(flex_VERSION "${flex_VERSION_MAJOR}.${flex_VERSION_MINOR}.${flex_VERSION_PATCH}") +set(flex_VERSION ${flex_VERSION_MAJOR}.${flex_VERSION_MINOR}.${flex_VERSION_PATCH}) # Name of package set(PACKAGE "flex") +MESSAGE(STATUS "PACKAGE=${PACKAGE}") # Define to the address where bug reports for this package should be sent. set(PACKAGE_BUGREPORT ${flex_BUGREPORT_STRING}) @@ -169,6 +170,7 @@ set(PACKAGE_URL "") # Define to the version of this package. set(PACKAGE_VERSION ${flex_VERSION}) +set(PROJECT_VERSION ${flex_VERSION}) MESSAGE(STATUS "PACKAGE_VERSION=${PACKAGE_VERSION}") # If using the C implementation of alloca, define if you know the diff --git a/cmake/make_uninstall.cmake b/cmake/make_uninstall.cmake new file mode 100644 index 000000000..451614ee7 --- /dev/null +++ b/cmake/make_uninstall.cmake @@ -0,0 +1,19 @@ + +if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: ${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt") +endif() + +file(READ "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt" files) +string(REGEX REPLACE "[\r\n]" ";" files "${files}") + +foreach(file ${files}) + message(STATUS "Uninstalling ${file}") + if(EXISTS "${file}") + file(REMOVE ${file}) + if (EXISTS "${file}") + message(FATAL_ERROR "Problem when removing ${file}, please check your permissions") + endif() + else() + message(STATUS "File ${file} does not exist.") + endif() +endforeach() From 5287816d2abfc56534f8ae9d2a8037d66b1e2d80 Mon Sep 17 00:00:00 2001 From: Joel Winarske Date: Sun, 2 Sep 2018 23:57:15 -0700 Subject: [PATCH 6/8] add pkgconfig dep libs && cleanup --- CMakeLists.txt | 6 +++--- cmake/FlexConfig.cmake.in | 2 +- cmake/libfl.pc.in | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc4859a97..22208a013 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,8 +91,9 @@ endif() add_executable(flex ${sources} src/main.c ${GENERATED_SOURCES}) add_library(fl SHARED ${sources} ${GENERATED_SOURCES}) if(UNIX AND NOT ANDROID) - target_link_libraries(flex -lm ${CMAKE_THREAD_LIBS_INIT}) - target_link_libraries(fl -lm ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(flex -lm) + target_link_libraries(fl -lm) + set(PKGCONFIG_LIBS "-lm -lc") endif() # Installation @@ -104,7 +105,6 @@ install(TARGETS fl DESTINATION ${CMAKE_INSTALL_LIBDIR}) # pkgconfig configure_file(${CMAKE_SOURCE_DIR}/cmake/libfl.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libfl.pc @ONLY) -#file(MAKE_DIRECTORY ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libfl.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) # CMake diff --git a/cmake/FlexConfig.cmake.in b/cmake/FlexConfig.cmake.in index a16ad3145..eaf5fd734 100644 --- a/cmake/FlexConfig.cmake.in +++ b/cmake/FlexConfig.cmake.in @@ -5,4 +5,4 @@ set(FLEX_VERSION @PACKAGE_VERSION@) set_and_check(FLEX_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") set_and_check(FLEX_SYSCONFIG_DIR "@PACKAGE_SYSCONFIG_INSTALL_DIR@") -check_required_components(Foo) +check_required_components(flex) diff --git a/cmake/libfl.pc.in b/cmake/libfl.pc.in index cc163f68f..4ab3681b9 100644 --- a/cmake/libfl.pc.in +++ b/cmake/libfl.pc.in @@ -5,5 +5,5 @@ libdir=${exec_prefix}/lib Name: libfl Description: Flex (the fast lexical analyzer) support library Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -lfl +Libs: -L${libdir} -lfl @PKGCONFIG_LIBS@ From ac64e0ce80711801e97e5b74b5a3033d51b505bc Mon Sep 17 00:00:00 2001 From: Joel Winarske Date: Tue, 4 Sep 2018 21:57:06 -0700 Subject: [PATCH 7/8] Cleanup --- CMakeLists.txt | 10 +- cmake/flexdef.h | 1249 ------------------------------------- cmake/libfl.pc.in | 9 - cmake/make_config_h.cmake | 9 - cmake/regex.h | 658 ------------------- cmake/swap.c | 20 - 6 files changed, 8 insertions(+), 1947 deletions(-) delete mode 100644 cmake/flexdef.h delete mode 100644 cmake/libfl.pc.in delete mode 100644 cmake/regex.h delete mode 100644 cmake/swap.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 22208a013..516a313f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,9 @@ include(make_config_h) # Build options option(ENABLE_NLS "Enable NLS" FALSE) +if(ENABLE_NLS) + add_definitions(-DENABLE_NLS -DYYENABLE_NLS) +endif() option(ENABLE_C_ALLOCA "Enable alloca.c" FALSE) option(ENABLE_MEM_SHIM "Replacement malloc, realloc" FALSE) @@ -104,7 +107,10 @@ install(TARGETS flex DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS fl DESTINATION ${CMAKE_INSTALL_LIBDIR}) # pkgconfig -configure_file(${CMAKE_SOURCE_DIR}/cmake/libfl.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libfl.pc @ONLY) +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix "\${prefix}") +set(libdir "\${exec_prefix}/lib") +configure_file(${CMAKE_SOURCE_DIR}/src/libfl.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libfl.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libfl.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) # CMake @@ -118,4 +124,4 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FlexConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/flex/cmake ) # uninstall -add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/cmake/make_uninstall.cmake") \ No newline at end of file +add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/cmake/make_uninstall.cmake") diff --git a/cmake/flexdef.h b/cmake/flexdef.h deleted file mode 100644 index 2f354efb2..000000000 --- a/cmake/flexdef.h +++ /dev/null @@ -1,1249 +0,0 @@ - -/* flexdef - definitions file for flex */ - -/* 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. */ - -#ifndef FLEXDEF_H -#define FLEXDEF_H 1 - -#ifdef _MSC_VER - -#include "sys/stat.h" -#include -#include - -/* Avoid Windows.h - obviously only works for host builds... */ -uint32_t htonl(uint32_t x); -uint16_t htons(uint16_t x); - - -#include -#define close _close -#define dup2 _dup2 -#define dup _dup -#define fileno _fileno -#define fdopen _fdopen -#define unlink _unlink -#define strdup _strdup -#define isatty _isatty - -/* Stubs rfom sys/stat.h */ -#define S_IXUSR 0x0100 // Execute/search permission, owner. -#define S_ISREG(m) (1) - -/* Stubs from missing sys/wait.h */ -#ifdef _POSIX_SOURCE -#define _W_INT(i) (i) -#else -#define _W_INT(w) (*(int *)&(w)) /* convert union wait to int */ -#endif - -#define _WSTATUS(x) (_W_INT(x) & 0177) -#define WIFEXITED(x) (_WSTATUS(x) == 0) -#define WEXITSTATUS(x) (_W_INT(x) >> 8) - -// return program name... -#define _MAX_NODE _MAX_DIR - -#ifdef INT8_MIN -#undef INT8_MIN -#endif -#ifdef INT16_MIN -#undef INT16_MIN -#endif -#ifdef INT32_MIN -#undef INT32_MIN -#endif -#ifdef INT8_MAX -#undef INT8_MAX -#endif -#ifdef INT16_MAX -#undef INT16_MAX -#endif -#ifdef INT32_MAX -#undef INT32_MAX -#endif -#ifdef UINT8_MAX -#undef UINT8_MAX -#endif -#ifdef UINT16_MAX -#undef UINT16_MAX -#endif - - -#endif //_WIN32 - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#if defined(HAVE_LIBGEN_H) -#include /* for XPG version of basename(3) */ -#else -inline char *basename(char *path) { - char fname[ _MAX_FNAME ]; - _splitpath(path, NULL, NULL, fname, NULL); - char *tmp = strstr(path, fname); - tmp[strlen(fname)] = 0; - return tmp; -} -#endif -#include - -#ifdef HAVE_ASSERT_H -#include -#else -#define assert(Pred) -#endif - -#ifdef HAVE_LIMITS_H -#include -#endif -/* Required: dup() and dup2() in */ -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_NETINET_IN_H -#include -#endif -#ifdef HAVE_SYS_PARAMS_H -#include -#endif -/* Required: stat() in */ -#include -/* Required: wait() in */ -#ifdef HAVE_SYS_WAIT_H -#include -#endif -#include -#include -/* Required: regcomp(), regexec() and regerror() in */ -#include -/* Required: strcasecmp() in */ -#ifdef HAVE_STRINGS_H -#include -#endif -#if defined(HAVE__STRICMP) && !defined(HAVE_STRCASECMP) -#define strcasecmp _stricmp -#endif -#ifdef HAVE_STDINT_H -#include -#endif -#include "flexint.h" - -/* We use gettext. So, when we write strings which should be translated, we mark them with _() */ -#ifdef ENABLE_NLS -#ifdef HAVE_LOCALE_H -#include -#endif /* HAVE_LOCALE_H */ -#include "gettext.h" -#define _(String) gettext (String) -#else -#define _(STRING) STRING -#endif /* ENABLE_NLS */ - -/* Always be prepared to generate an 8-bit scanner. */ -#define CSIZE 256 - -/* Size of input alphabet - should be size of ASCII set. */ -#ifndef DEFAULT_CSIZE -#define DEFAULT_CSIZE 128 -#endif - -/* Maximum line length we'll have to deal with. */ -#define MAXLINE 2048 - -#ifndef MIN -#define MIN(x,y) ((x) < (y) ? (x) : (y)) -#endif -#ifndef MAX -#define MAX(x,y) ((x) > (y) ? (x) : (y)) -#endif -#ifndef ABS -#define ABS(x) ((x) < 0 ? -(x) : (x)) -#endif - -/* Whether an integer is a power of two */ -#define is_power_of_2(n) ((n) > 0 && ((n) & ((n) - 1)) == 0) - -#define unspecified -1 - -/* Special chk[] values marking the slots taking by end-of-buffer and action - * numbers. - */ -#define EOB_POSITION -1 -#define ACTION_POSITION -2 - -/* Number of data items per line for -f output. */ -#define NUMDATAITEMS 10 - -/* Number of lines of data in -f output before inserting a blank line for - * readability. - */ -#define NUMDATALINES 10 - -/* transition_struct_out() definitions. */ -#define TRANS_STRUCT_PRINT_LENGTH 14 - -/* Returns true if an nfa state has an epsilon out-transition slot - * that can be used. This definition is currently not used. - */ -#define FREE_EPSILON(state) \ - (transchar[state] == SYM_EPSILON && \ - trans2[state] == NO_TRANSITION && \ - finalst[state] != state) - -/* Returns true if an nfa state has an epsilon out-transition character - * and both slots are free - */ -#define SUPER_FREE_EPSILON(state) \ - (transchar[state] == SYM_EPSILON && \ - trans1[state] == NO_TRANSITION) \ - -/* Maximum number of NFA states that can comprise a DFA state. It's real - * big because if there's a lot of rules, the initial state will have a - * huge epsilon closure. - */ -#define INITIAL_MAX_DFA_SIZE 750 -#define MAX_DFA_SIZE_INCREMENT 750 - - -/* A note on the following masks. They are used to mark accepting numbers - * as being special. As such, they implicitly limit the number of accepting - * numbers (i.e., rules) because if there are too many rules the rule numbers - * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 == - * 8192) so unlikely to actually cause any problems. A check is made in - * new_rule() to ensure that this limit is not reached. - */ - -/* Mask to mark a trailing context accepting number. */ -#define YY_TRAILING_MASK 0x2000 - -/* Mask to mark the accepting number of the "head" of a trailing context - * rule. - */ -#define YY_TRAILING_HEAD_MASK 0x4000 - -/* Maximum number of rules, as outlined in the above note. */ -#define MAX_RULE (YY_TRAILING_MASK - 1) - - -/* NIL must be 0. If not, its special meaning when making equivalence classes - * (it marks the representative of a given e.c.) will be unidentifiable. - */ -#define NIL 0 - -#define JAM -1 /* to mark a missing DFA transition */ -#define NO_TRANSITION NIL -#define UNIQUE -1 /* marks a symbol as an e.c. representative */ -#define INFINITE_REPEAT -1 /* for x{5,} constructions */ - -#define INITIAL_MAX_CCLS 100 /* max number of unique character classes */ -#define MAX_CCLS_INCREMENT 100 - -/* Size of table holding members of character classes. */ -#define INITIAL_MAX_CCL_TBL_SIZE 500 -#define MAX_CCL_TBL_SIZE_INCREMENT 250 - -#define INITIAL_MAX_RULES 100 /* default maximum number of rules */ -#define MAX_RULES_INCREMENT 100 - -#define INITIAL_MNS 2000 /* default maximum number of nfa states */ -#define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */ - -#define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */ -#define MAX_DFAS_INCREMENT 1000 - -#define JAMSTATE -32766 /* marks a reference to the state that always jams */ - -/* Maximum number of NFA states. */ -#define MAXIMUM_MNS 31999 -#define MAXIMUM_MNS_LONG 1999999999 - -/* Enough so that if it's subtracted from an NFA state number, the result - * is guaranteed to be negative. - */ -#define MARKER_DIFFERENCE (maximum_mns+2) - -/* Maximum number of nxt/chk pairs for non-templates. */ -#define INITIAL_MAX_XPAIRS 2000 -#define MAX_XPAIRS_INCREMENT 2000 - -/* Maximum number of nxt/chk pairs needed for templates. */ -#define INITIAL_MAX_TEMPLATE_XPAIRS 2500 -#define MAX_TEMPLATE_XPAIRS_INCREMENT 2500 - -#define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */ - -#define INITIAL_MAX_SCS 40 /* maximum number of start conditions */ -#define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */ - -#define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */ -#define SAME_TRANS -1 /* transition is the same as "default" entry for state */ - -/* The following percentages are used to tune table compression: - - * The percentage the number of out-transitions a state must be of the - * number of equivalence classes in order to be considered for table - * compaction by using protos. - */ -#define PROTO_SIZE_PERCENTAGE 15 - -/* 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 - * template of the most common out-transition instead of with the first - * proto in the proto queue. - */ -#define CHECK_COM_PERCENTAGE 50 - -/* The percentage the number of differences between a state's transition - * table and the proto it was first compared with must be of the total - * number of out-transitions of the state in order to keep the first - * proto as a good match and not search any further. - */ -#define FIRST_MATCH_DIFF_PERCENTAGE 10 - -/* The percentage the number of differences between a state's transition - * table and the most similar proto must be of the state's total number - * of out-transitions to use the proto as an acceptable close match. - */ -#define ACCEPTABLE_DIFF_PERCENTAGE 50 - -/* 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 - * to consider making a template from the state. - */ -#define TEMPLATE_SAME_PERCENTAGE 60 - -/* The percentage the number of differences between a state's transition - * table and the most similar proto must be of the state's total number - * of out-transitions to create a new proto from the state. - */ -#define NEW_PROTO_DIFF_PERCENTAGE 20 - -/* The percentage the total number of out-transitions of a state must be - * of the number of equivalence classes in order to consider trying to - * fit the transition table into "holes" inside the nxt/chk table. - */ -#define INTERIOR_FIT_PERCENTAGE 15 - -/* Size of region set aside to cache the complete transition table of - * protos on the proto queue to enable quick comparisons. - */ -#define PROT_SAVE_SIZE 2000 - -#define MSP 50 /* maximum number of saved protos (protos on the proto queue) */ - -/* Maximum number of out-transitions a state can have that we'll rummage - * around through the interior of the internal fast table looking for a - * spot for it. - */ -#define MAX_XTIONS_FULL_INTERIOR_FIT 4 - -/* Maximum number of rules which will be reported as being associated - * with a DFA state. - */ -#define MAX_ASSOC_RULES 100 - -/* Number that, if used to subscript an array, has a good chance of producing - * an error; should be small enough to fit into a short. - */ -#define BAD_SUBSCRIPT -32767 - -/* Absolute value of largest number that can be stored in a short, with a - * bit of slop thrown in for general paranoia. - */ -#define MAX_SHORT 32700 - - -/* Declarations for global variables. */ - - -/* Variables for flags: - * printstats - if true (-v), dump statistics - * syntaxerror - true if a syntax error has been found - * eofseen - true if we've seen an eof in the input file - * ddebug - if true (-d), make a "debug" scanner - * trace - if true (-T), trace processing - * nowarn - if true (-w), do not generate warnings - * spprdflt - if true (-s), suppress the default rule - * interactive - if true (-I), generate an interactive scanner - * lex_compat - if true (-l), maximize compatibility with AT&T lex - * posix_compat - if true (-X), maximize compatibility with POSIX lex - * do_yylineno - if true, generate code to maintain yylineno - * useecs - if true (-Ce flag), use equivalence classes - * fulltbl - if true (-Cf flag), don't compress the DFA state table - * usemecs - if true (-Cm flag), use meta-equivalence classes - * fullspd - if true (-F flag), use Jacobson method of table representation - * gen_line_dirs - if true (i.e., no -L flag), generate #line directives - * performance_report - if > 0 (i.e., -p flag), generate a report relating - * to scanner performance; if > 1 (-p -p), report on minor performance - * problems, too - * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file - * listing backing-up states - * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class; - * otherwise, a standard C scanner - * reentrant - if true (-R), generate a reentrant C scanner. - * bison_bridge_lval - if true (--bison-bridge), bison pure calling convention. - * bison_bridge_lloc - if true (--bison-locations), bison yylloc. - * long_align - if true (-Ca flag), favor long-word alignment. - * use_read - if true (-f, -F, or -Cr) then use read() for scanner input; - * otherwise, use fread(). - * yytext_is_array - if true (i.e., %array directive), then declare - * yytext as a array instead of a character pointer. Nice and inefficient. - * do_yywrap - do yywrap() processing on EOF. If false, EOF treated as - * "no more files". - * csize - size of character set for the scanner we're generating; - * 128 for 7-bit chars and 256 for 8-bit - * yymore_used - if true, yymore() is used in input rules - * reject - if true, generate back-up tables for REJECT macro - * real_reject - if true, scanner really uses REJECT (as opposed to just - * having "reject" set for variable trailing context) - * continued_action - true if this rule's action is to "fall through" to - * the next rule's action (i.e., the '|' action) - * in_rule - true if we're inside an individual rule, false if not. - * yymore_really_used - whether to treat yymore() as really used, regardless - * of what we think based on references to it in the user's actions. - * reject_really_used - same for REJECT - * trace_hex - use hexadecimal numbers in trace/debug outputs instead of octals - */ - -extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, - spprdflt; -extern int interactive, lex_compat, posix_compat, do_yylineno; -extern int useecs, fulltbl, usemecs, fullspd; -extern int gen_line_dirs, performance_report, backing_up_report; -extern int reentrant, bison_bridge_lval, bison_bridge_lloc; -extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap; -extern int csize; -extern int yymore_used, reject, real_reject, continued_action, in_rule; - -extern int yymore_really_used, reject_really_used; -extern int trace_hex; - -/* Variables used in the flex input routines: - * datapos - characters on current output line - * dataline - number of contiguous lines of data in current data - * statement. Used to generate readable -f output - * linenum - current input line number - * skelfile - the skeleton file - * skel - compiled-in skeleton array - * skel_ind - index into "skel" array, if skelfile is nil - * yyin - input file - * backing_up_file - file to summarize backing-up states to - * infilename - name of input file - * outfilename - name of output file - * headerfilename - name of the .h file to generate - * did_outfilename - whether outfilename was explicitly set - * prefix - the prefix used for externally visible names ("yy" by default) - * yyclass - yyFlexLexer subclass to use for YY_DECL - * do_stdinit - whether to initialize yyin/yyout to stdin/stdout - * 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 - * - * action_array - array to hold the rule actions - * action_size - size of action_array - * defs1_offset - index where the user's section 1 definitions start - * in action_array - * prolog_offset - index where the prolog starts in action_array - * action_offset - index where the non-prolog starts in action_array - * action_index - index where the next action should go, with respect - * to "action_array" - */ - -extern int datapos, dataline, linenum; -extern FILE *skelfile, *backing_up_file; -extern const char *skel[]; -extern int skel_ind; -extern char *infilename, *outfilename, *headerfilename; -extern int did_outfilename; -extern char *prefix, *yyclass, *extra_type; -extern int do_stdinit, use_stdout; -extern char **input_files; -extern int num_input_files; -extern char *program_name; - -extern char *action_array; -extern int action_size; -extern int defs1_offset, prolog_offset, action_offset, action_index; - - -/* Variables for stack of states having only one out-transition: - * onestate - state number - * onesym - transition symbol - * onenext - target state - * onedef - default base entry - * onesp - stack pointer - */ - -extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE]; -extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp; - - -/* Variables for nfa machine data: - * maximum_mns - maximal number of NFA states supported by tables - * current_mns - current maximum on number of NFA states - * num_rules - number of the last accepting state; also is number of - * rules created so far - * num_eof_rules - number of <> rules - * default_rule - number of the default rule - * current_max_rules - current maximum number of rules - * lastnfa - last nfa state number created - * firstst - physically the first state of a fragment - * lastst - last physical state of fragment - * finalst - last logical state of fragment - * transchar - transition character - * trans1 - transition state - * trans2 - 2nd transition state for epsilons - * accptnum - accepting number - * assoc_rule - rule associated with this NFA state (or 0 if none) - * state_type - a STATE_xxx type identifying whether the state is part - * of a normal rule, the leading state in a trailing context - * rule (i.e., the state which marks the transition from - * recognizing the text-to-be-matched to the beginning of - * the trailing context), or a subsequent state in a trailing - * context rule - * rule_type - a RULE_xxx type identifying whether this a ho-hum - * normal rule or one which has variable head & trailing - * context - * rule_linenum - line number associated with rule - * rule_useful - true if we've determined that the rule can be matched - * rule_has_nl - true if rule could possibly match a newline - * ccl_has_nl - true if current ccl could match a newline - * nlch - default eol char - */ - -extern int maximum_mns, current_mns, current_max_rules; -extern int num_rules, num_eof_rules, default_rule, lastnfa; -extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2; -extern int *accptnum, *assoc_rule, *state_type; -extern int *rule_type, *rule_linenum, *rule_useful; -extern bool *rule_has_nl, *ccl_has_nl; -extern int nlch; - -/* Different types of states; values are useful as masks, as well, for - * routines like check_trailing_context(). - */ -#define STATE_NORMAL 0x1 -#define STATE_TRAILING_CONTEXT 0x2 - -/* Global holding current type of state we're making. */ - -extern int current_state_type; - -/* Different types of rules. */ -#define RULE_NORMAL 0 -#define RULE_VARIABLE 1 - -/* True if the input rules include a rule with both variable-length head - * and trailing context, false otherwise. - */ -extern int variable_trailing_context_rules; - - -/* Variables for protos: - * numtemps - number of templates created - * numprots - number of protos created - * protprev - backlink to a more-recently used proto - * protnext - forward link to a less-recently used proto - * prottbl - base/def table entry for proto - * protcomst - common state of proto - * firstprot - number of the most recently used proto - * lastprot - number of the least recently used proto - * protsave contains the entire state array for protos - */ - -extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP]; -extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE]; - - -/* Variables for managing equivalence classes: - * numecs - number of equivalence classes - * nextecm - forward link of Equivalence Class members - * ecgroup - class number or backward link of EC members - * nummecs - number of meta-equivalence classes (used to compress - * templates) - * tecfwd - forward link of meta-equivalence classes members - * tecbck - backward link of MEC's - */ - -/* Reserve enough room in the equivalence class arrays so that we - * can use the CSIZE'th element to hold equivalence class information - * for the NUL character. Later we'll move this information into - * the 0th element. - */ -extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs; - -/* Meta-equivalence classes are indexed starting at 1, so it's possible - * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1 - * slots total (since the arrays are 0-based). nextecm[] and ecgroup[] - * don't require the extra position since they're indexed from 1 .. CSIZE - 1. - */ -extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1]; - - -/* Variables for start conditions: - * lastsc - last start condition created - * current_max_scs - current limit on number of start conditions - * scset - set of rules active in start condition - * scbol - set of rules active only at the beginning of line in a s.c. - * scxclu - true if start condition is exclusive - * sceof - true if start condition has EOF rule - * scname - start condition name - */ - -extern int lastsc, *scset, *scbol, *scxclu, *sceof; -extern int current_max_scs; -extern char **scname; - - -/* Variables for dfa machine data: - * current_max_dfa_size - current maximum number of NFA states in DFA - * current_max_xpairs - current maximum number of non-template xtion pairs - * current_max_template_xpairs - current maximum number of template pairs - * current_max_dfas - current maximum number DFA states - * lastdfa - last dfa state number created - * nxt - state to enter upon reading character - * chk - check value to see if "nxt" applies - * tnxt - internal nxt table for templates - * base - offset into "nxt" for given state - * def - where to go if "chk" disallows "nxt" entry - * nultrans - NUL transition for each state - * NUL_ec - equivalence class of the NUL character - * tblend - last "nxt/chk" table entry being used - * firstfree - first empty entry in "nxt/chk" table - * dss - nfa state set for each dfa - * dfasiz - size of nfa state set for each dfa - * dfaacc - accepting set for each dfa state (if using REJECT), or accepting - * number, if not - * accsiz - size of accepting set for each dfa state - * dhash - dfa state hash value - * numas - number of DFA accepting states created; note that this - * is not necessarily the same value as num_rules, which is the analogous - * value for the NFA - * numsnpairs - number of state/nextstate transition pairs - * jambase - position in base/def where the default jam table starts - * jamstate - state number corresponding to "jam" state - * end_of_buffer_state - end-of-buffer dfa state number - */ - -extern int current_max_dfa_size, current_max_xpairs; -extern int current_max_template_xpairs, current_max_dfas; -extern int lastdfa, *nxt, *chk, *tnxt; -extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, - *dfasiz; -extern union dfaacc_union { - int *dfaacc_set; - int dfaacc_state; -} *dfaacc; -extern int *accsiz, *dhash, numas; -extern int numsnpairs, jambase, jamstate; -extern int end_of_buffer_state; - -/* Variables for ccl information: - * lastccl - ccl index of the last created ccl - * current_maxccls - current limit on the maximum number of unique ccl's - * cclmap - maps a ccl index to its set pointer - * ccllen - gives the length of a ccl - * cclng - true for a given ccl if the ccl is negated - * cclreuse - counts how many times a ccl is re-used - * current_max_ccl_tbl_size - current limit on number of characters needed - * to represent the unique ccl's - * ccltbl - holds the characters in each ccl - indexed by cclmap - */ - -extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse; -extern int current_maxccls, current_max_ccl_tbl_size; -extern unsigned char *ccltbl; - - -/* Variables for miscellaneous information: - * nmstr - last NAME scanned by the scanner - * sectnum - section number currently being parsed - * nummt - number of empty nxt/chk table entries - * hshcol - number of hash collisions detected by snstods - * dfaeql - number of times a newly created dfa was equal to an old one - * numeps - number of epsilon NFA states created - * eps2 - number of epsilon states which have 2 out-transitions - * num_reallocs - number of times it was necessary to realloc() a group - * of arrays - * tmpuses - number of DFA states that chain to templates - * totnst - total number of NFA states used to make DFA states - * peakpairs - peak number of transition pairs we had to store internally - * numuniq - number of unique transitions - * numdup - number of duplicate transitions - * hshsave - number of hash collisions saved by checking number of states - * num_backing_up - number of DFA states requiring backing up - * bol_needed - whether scanner needs beginning-of-line recognition - */ - -extern char nmstr[MAXLINE]; -extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; -extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; -extern int num_backing_up, bol_needed; - -#ifndef HAVE_REALLOCARRAY -void *reallocarray(void *, size_t, size_t); -#endif - -void *allocate_array(int, size_t); -void *reallocate_array(void *, int, size_t); - -#define allocate_integer_array(size) \ - allocate_array(size, sizeof(int)) - -#define reallocate_integer_array(array,size) \ - reallocate_array((void *) array, size, sizeof(int)) - -#define allocate_bool_array(size) \ - allocate_array(size, sizeof(bool)) - -#define reallocate_bool_array(array,size) \ - reallocate_array((void *) array, size, sizeof(bool)) - -#define allocate_int_ptr_array(size) \ - allocate_array(size, sizeof(int *)) - -#define allocate_char_ptr_array(size) \ - allocate_array(size, sizeof(char *)) - -#define allocate_dfaacc_union(size) \ - allocate_array(size, sizeof(union dfaacc_union)) - -#define reallocate_int_ptr_array(array,size) \ - reallocate_array((void *) array, size, sizeof(int *)) - -#define reallocate_char_ptr_array(array,size) \ - reallocate_array((void *) array, size, sizeof(char *)) - -#define reallocate_dfaacc_union(array, size) \ - reallocate_array((void *) array, size, sizeof(union dfaacc_union)) - -#define allocate_character_array(size) \ - allocate_array( size, sizeof(char)) - -#define reallocate_character_array(array,size) \ - reallocate_array((void *) array, size, sizeof(char)) - -#define allocate_Character_array(size) \ - allocate_array(size, sizeof(unsigned char)) - -#define reallocate_Character_array(array,size) \ - reallocate_array((void *) array, size, sizeof(unsigned char)) - - -/* External functions that are cross-referenced among the flex source files. */ - - -/* from file ccl.c */ - -extern void ccladd(int, int); /* add a single character to a ccl */ -extern int cclinit(void); /* make an empty ccl */ -extern void cclnegate(int); /* negate a ccl */ -extern int ccl_set_diff (int a, int b); /* set difference of two ccls. */ -extern int ccl_set_union (int a, int b); /* set union of two ccls. */ - -/* List the members of a set of characters in CCL form. */ -extern void list_character_set(FILE *, int[]); - - -/* from file dfa.c */ - -/* Check a DFA state for backing up. */ -extern void check_for_backing_up(int, int[]); - -/* Check to see if NFA state set constitutes "dangerous" trailing context. */ -extern void check_trailing_context(int *, int, int *, int); - -/* Construct the epsilon closure of a set of ndfa states. */ -extern int *epsclosure(int *, int *, int[], int *, int *); - -/* Increase the maximum number of dfas. */ -extern void increase_max_dfas(void); - -extern void ntod(void); /* convert a ndfa to a dfa */ - -/* Converts a set of ndfa states into a dfa state. */ -extern int snstods(int[], int, int[], int, int, int *); - - -/* from file ecs.c */ - -/* Convert character classes to set of equivalence classes. */ -extern void ccl2ecl(void); - -/* Associate equivalence class numbers with class members. */ -extern int cre8ecs(int[], int[], int); - -/* Update equivalence classes based on character class transitions. */ -extern void mkeccl(unsigned char[], int, int[], int[], int, int); - -/* Create equivalence class for single character. */ -extern void mkechar(int, int[], int[]); - - -/* from file gen.c */ - -extern void do_indent(void); /* indent to the current level */ - -/* Generate the code to keep backing-up information. */ -extern void gen_backing_up(void); - -/* Generate the code to perform the backing up. */ -extern void gen_bu_action(void); - -/* Generate full speed compressed transition table. */ -extern void genctbl(void); - -/* Generate the code to find the action number. */ -extern void gen_find_action(void); - -extern void genftbl(void); /* generate full transition table */ - -/* Generate the code to find the next compressed-table state. */ -extern void gen_next_compressed_state(char *); - -/* Generate the code to find the next match. */ -extern void gen_next_match(void); - -/* Generate the code to find the next state. */ -extern void gen_next_state(int); - -/* Generate the code to make a NUL transition. */ -extern void gen_NUL_trans(void); - -/* Generate the code to find the start state. */ -extern void gen_start_state(void); - -/* Generate data statements for the transition tables. */ -extern void gentabs(void); - -/* Write out a formatted string at the current indentation level. */ -extern void indent_put2s(const char *, const char *); - -/* Write out a string + newline at the current indentation level. */ -extern void indent_puts(const char *); - -extern void make_tables(void); /* generate transition tables */ - - -/* from file main.c */ - -extern void check_options(void); -extern void flexend(int); -extern void usage(void); - - -/* from file misc.c */ - -/* Add a #define to the action file. */ -extern void action_define(const char *defname, int value); - -/* Add the given text to the stored actions. */ -extern void add_action(const char *new_text); - -/* True if a string is all lower case. */ -extern int all_lower(char *); - -/* True if a string is all upper case. */ -extern int all_upper(char *); - -/* Compare two integers for use by qsort. */ -extern int intcmp(const void *, const void *); - -/* Check a character to make sure it's in the expected range. */ -extern void check_char(int c); - -/* Replace upper-case letter to lower-case. */ -extern unsigned char clower(int); - -/* strdup() that fails fatally on allocation failures. */ -extern char *xstrdup(const char *); - -/* Compare two characters for use by qsort with '\0' sorting last. */ -extern int cclcmp(const void *, const void *); - -/* Finish up a block of data declarations. */ -extern void dataend(void); - -/* Flush generated data statements. */ -extern void dataflush(void); - -/* Report an error message and terminate. */ -extern void flexerror(const char *); - -/* Report a fatal error message and terminate. */ -extern void flexfatal(const char *); - -/* Report a fatal error with a pinpoint, and terminate */ -#if HAVE_DECL___FUNC__ -#define flex_die(msg) \ - do{ \ - fprintf (stderr,\ - _("%s: fatal internal error at %s:%d (%s): %s\n"),\ - program_name, __FILE__, (int)__LINE__,\ - __func__,msg);\ - FLEX_EXIT(1);\ - }while(0) -#else /* ! HAVE_DECL___FUNC__ */ -#define flex_die(msg) \ - do{ \ - fprintf (stderr,\ - _("%s: fatal internal error at %s:%d %s\n"),\ - program_name, __FILE__, (int)__LINE__,\ - msg);\ - FLEX_EXIT(1);\ - }while(0) -#endif /* ! HAVE_DECL___func__ */ - -/* Report an error message formatted */ -extern void lerr(const char *, ...) -#if defined(__GNUC__) && __GNUC__ >= 3 - __attribute__((__format__(__printf__, 1, 2))) -#endif -; - -/* Like lerr, but also exit after displaying message. */ -extern void lerr_fatal(const char *, ...) -#if defined(__GNUC__) && __GNUC__ >= 3 - __attribute__((__format__(__printf__, 1, 2))) -#endif -; - -/* Spit out a "#line" statement. */ -extern void line_directive_out(FILE *, int); - -/* Mark the current position in the action array as the end of the section 1 - * user defs. - */ -extern void mark_defs1(void); - -/* Mark the current position in the action array as the end of the prolog. */ -extern void mark_prolog(void); - -/* Generate a data statment for a two-dimensional array. */ -extern void mk2data(int); - -extern void mkdata(int); /* generate a data statement */ - -/* Return the integer represented by a string of digits. */ -extern int myctoi(const char *); - -/* Return character corresponding to escape sequence. */ -extern unsigned char myesc(unsigned char[]); - -/* Output a (possibly-formatted) string to the generated scanner. */ -extern void out(const char *); -extern void out_dec(const char *, int); -extern void out_dec2(const char *, int, int); -extern void out_hex(const char *, unsigned int); -extern void out_str(const char *, const char *); -extern void out_str3(const char *, const char *, const char *, const char *); -extern void out_str_dec(const char *, const char *, int); -extern void outc(int); -extern void outn(const char *); -extern void out_m4_define(const char* def, const char* val); - -/* Return a printable version of the given character, which might be - * 8-bit. - */ -extern char *readable_form(int); - -/* Write out one section of the skeleton file. */ -extern void skelout(void); - -/* Output a yy_trans_info structure. */ -extern void transition_struct_out(int, int); - -/* Only needed when using certain broken versions of bison to build parse.c. */ -extern void *yy_flex_xmalloc(int); - - -/* from file nfa.c */ - -/* Add an accepting state to a machine. */ -extern void add_accept(int, int); - -/* Make a given number of copies of a singleton machine. */ -extern int copysingl(int, int); - -/* Debugging routine to write out an nfa. */ -extern void dumpnfa(int); - -/* Finish up the processing for a rule. */ -extern void finish_rule(int, int, int, int, int); - -/* Connect two machines together. */ -extern int link_machines(int, int); - -/* Mark each "beginning" state in a machine as being a "normal" (i.e., - * not trailing context associated) state. - */ -extern void mark_beginning_as_normal(int); - -/* Make a machine that branches to two machines. */ -extern int mkbranch(int, int); - -extern int mkclos(int); /* convert a machine into a closure */ -extern int mkopt(int); /* make a machine optional */ - -/* Make a machine that matches either one of two machines. */ -extern int mkor(int, int); - -/* Convert a machine into a positive closure. */ -extern int mkposcl(int); - -extern int mkrep(int, int, int); /* make a replicated machine */ - -/* Create a state with a transition on a given symbol. */ -extern int mkstate(int); - -extern void new_rule(void); /* initialize for a new rule */ - - -/* from file parse.y */ - -/* Build the "<>" action for the active start conditions. */ -extern void build_eof_action(void); - -/* Write out a message formatted with one string, pinpointing its location. */ -extern void format_pinpoint_message(const char *, const char *); - -/* Write out a message, pinpointing its location. */ -extern void pinpoint_message(const char *); - -/* Write out a warning, pinpointing it at the given line. */ -extern void line_warning(const char *, int); - -/* Write out a message, pinpointing it at the given line. */ -extern void line_pinpoint(const char *, int); - -/* Report a formatted syntax error. */ -extern void format_synerr(const char *, const char *); -extern void synerr(const char *); /* report a syntax error */ -extern void format_warn(const char *, const char *); -extern void lwarn(const char *); /* report a warning */ -extern void yyerror(const char *); /* report a parse error */ -extern int yyparse(void); /* the YACC parser */ - - -/* from file scan.l */ - -/* The Flex-generated scanner for flex. */ -extern int flexscan(void); - -/* Open the given file (if NULL, stdin) for scanning. */ -extern void set_input_file(char *); - - -/* from file sym.c */ - -/* Save the text of a character class. */ -extern void cclinstal(char[], int); - -/* Lookup the number associated with character class. */ -extern int ccllookup(char[]); - -extern void ndinstal(const char *, char[]); /* install a name definition */ -extern char *ndlookup(const char *); /* lookup a name definition */ - -/* Increase maximum number of SC's. */ -extern void scextend(void); -extern void scinstal(const char *, int); /* make a start condition */ - -/* Lookup the number associated with a start condition. */ -extern int sclookup(const char *); - - -/* from file tblcmp.c */ - -/* Build table entries for dfa state. */ -extern void bldtbl(int[], int, int, int, int); - -extern void cmptmps(void); /* compress template table entries */ -extern void expand_nxt_chk(void); /* increase nxt/chk arrays */ - -/* Finds a space in the table for a state to be placed. */ -extern int find_table_space(int *, int); -extern void inittbl(void); /* initialize transition tables */ - -/* Make the default, "jam" table entries. */ -extern void mkdeftbl(void); - -/* Create table entries for a state (or state fragment) which has - * only one out-transition. - */ -extern void mk1tbl(int, int, int, int); - -/* Place a state into full speed transition table. */ -extern void place_state(int *, int, int); - -/* Save states with only one out-transition to be processed later. */ -extern void stack1(int, int, int, int); - - -/* from file yylex.c */ - -extern int yylex(void); - -/* A growable array. See buf.c. */ -struct Buf { - void *elts; /* elements. */ - int nelts; /* number of elements. */ - size_t elt_size; /* in bytes. */ - int nmax; /* max capacity of elements. */ -}; - -extern void buf_init(struct Buf * buf, size_t elem_size); -extern void buf_destroy(struct Buf * buf); -extern struct Buf *buf_append(struct Buf * buf, const void *ptr, int n_elem); -extern struct Buf *buf_concat(struct Buf* dest, const struct Buf* src); -extern struct Buf *buf_strappend(struct Buf *, const char *str); -extern struct Buf *buf_strnappend(struct Buf *, const char *str, int nchars); -extern struct Buf *buf_strdefine(struct Buf * buf, const char *str, const char *def); -extern struct Buf *buf_prints(struct Buf *buf, const char *fmt, const char* s); -extern struct Buf *buf_m4_define(struct Buf *buf, const char* def, const char* val); -extern struct Buf *buf_m4_undefine(struct Buf *buf, const char* def); -extern struct Buf *buf_print_strings(struct Buf * buf, FILE* out); -extern struct Buf *buf_linedir(struct Buf *buf, const char* filename, int lineno); - -extern struct Buf userdef_buf; /* a string buffer for #define's generated by user-options on cmd line. */ -extern struct Buf defs_buf; /* a char* buffer to save #define'd some symbols generated by flex. */ -extern struct Buf yydmap_buf; /* a string buffer to hold yydmap elements */ -extern struct Buf m4defs_buf; /* Holds m4 definitions. */ -extern struct Buf top_buf; /* contains %top code. String buffer. */ -extern bool no_section3_escape; /* True if the undocumented option --unsafe-no-m4-sect3-escape was passed */ - -/* For blocking out code from the header file. */ -#define OUT_BEGIN_CODE() outn("m4_ifdef( [[M4_YY_IN_HEADER]],,[[m4_dnl") -#define OUT_END_CODE() outn("]])") - -/* For setjmp/longjmp (instead of calling exit(2)). Linkage in main.c */ -extern jmp_buf flex_main_jmp_buf; - -#define FLEX_EXIT(status) longjmp(flex_main_jmp_buf,(status)+1) - -/* Removes all \n and \r chars from tail of str. returns str. */ -extern char *chomp (char *str); - -/* ctype functions forced to return boolean */ -#define b_isalnum(c) (isalnum(c)?true:false) -#define b_isalpha(c) (isalpha(c)?true:false) -#define b_isascii(c) (isascii(c)?true:false) -#define b_isblank(c) (isblank(c)?true:false) -#define b_iscntrl(c) (iscntrl(c)?true:false) -#define b_isdigit(c) (isdigit(c)?true:false) -#define b_isgraph(c) (isgraph(c)?true:false) -#define b_islower(c) (islower(c)?true:false) -#define b_isprint(c) (isprint(c)?true:false) -#define b_ispunct(c) (ispunct(c)?true:false) -#define b_isspace(c) (isspace(c)?true:false) -#define b_isupper(c) (isupper(c)?true:false) -#define b_isxdigit(c) (isxdigit(c)?true:false) - -/* return true if char is uppercase or lowercase. */ -bool has_case(int c); - -/* Change case of character if possible. */ -int reverse_case(int c); - -/* return false if [c1-c2] is ambiguous for a caseless scanner. */ -bool range_covers_case (int c1, int c2); - -/* - * From "filter.c" - */ - -/** A single stdio filter to execute. - * The filter may be external, such as "sed", or it - * may be internal, as a function call. - */ -struct filter { - int (*filter_func)(struct filter*); /**< internal filter function */ - void * extra; /**< extra data passed to filter_func */ - int argc; /**< arg count */ - const char ** argv; /**< arg vector, \0-terminated */ - struct filter * next; /**< next filter or NULL */ -}; - -/* output filter chain */ -extern struct filter * output_chain; -extern struct filter *filter_create_ext (struct filter * chain, const char *cmd, ...); -struct filter *filter_create_int(struct filter *chain, - int (*filter_func) (struct filter *), - void *extra); -extern bool filter_apply_chain(struct filter * chain); -extern int filter_truncate(struct filter * chain, int max_len); -extern int filter_tee_header(struct filter *chain); -extern int filter_fix_linedirs(struct filter *chain); - - -/* - * From "regex.c" - */ -extern regex_t regex_linedir, regex_blank_line; -bool flex_init_regex(void); -void flex_regcomp(regex_t *preg, const char *regex, int cflags); -char *regmatch_dup (regmatch_t * m, const char *src); -char *regmatch_cpy (regmatch_t * m, char *dest, const char *src); -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_top_ix, _sf_max; /**< stack of scanner flags. */ -#define _SF_CASE_INS ((scanflags_t) 0x0001) -#define _SF_DOT_ALL ((scanflags_t) 0x0002) -#define _SF_SKIP_WS ((scanflags_t) 0x0004) -#define sf_top() (_sf_stk[_sf_top_ix]) -#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_init(void); -extern void sf_push(void); -extern void sf_pop(void); - -#endif /* not defined FLEXDEF_H */ diff --git a/cmake/libfl.pc.in b/cmake/libfl.pc.in deleted file mode 100644 index 4ab3681b9..000000000 --- a/cmake/libfl.pc.in +++ /dev/null @@ -1,9 +0,0 @@ -prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=${prefix} -libdir=${exec_prefix}/lib - -Name: libfl -Description: Flex (the fast lexical analyzer) support library -Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -lfl @PKGCONFIG_LIBS@ - diff --git a/cmake/make_config_h.cmake b/cmake/make_config_h.cmake index 37f52aca2..1dad46437 100644 --- a/cmake/make_config_h.cmake +++ b/cmake/make_config_h.cmake @@ -64,10 +64,6 @@ check_include_files(memory.h HAVE_MEMORY_H) check_function_exists(memset HAVE_MEMSET) check_function_exists(Needed HAVE_NEEDED) check_include_files(netinet/in.h HAVE_NETINET_IN_H) -check_include_files("arpa/inet.h" HAVE_ARPA_INET_H) -if(NOT HAVE_ARPA_INET_H) - configure_file(${CMAKE_SOURCE_DIR}/cmake/swap.c ${CMAKE_SOURCE_DIR}/src/swap.c COPYONLY) -endif() check_function_exists(NLS HAVE_NLS) check_function_exists("not" HAVE_NOT) check_function_exists(only HAVE_ONLY) @@ -82,11 +78,6 @@ check_function_exists(realloc HAVE_REALLOC) check_function_exists(reallocarray HAVE_REALLOCARRAY) check_function_exists(regcomp HAVE_REGCOMP) check_include_files(regex.h HAVE_REGEX_H) -if(NOT HAVE_REGEX_H) - #add_definitions(-D_LIBC) - configure_file(${CMAKE_SOURCE_DIR}/cmake/regex.h ${CMAKE_SOURCE_DIR}/src/regex.h COPYONLY) - #configure_file(${CMAKE_SOURCE_DIR}/cmake/regex.c ${CMAKE_SOURCE_DIR}/src/regex.c COPYONLY) -endif() check_function_exists(replacement HAVE_REPLACEMENT) check_function_exists(setlocale HAVE_SETLOCALE) check_include_files(stdbool.h HAVE_STDBOOL_H) diff --git a/cmake/regex.h b/cmake/regex.h deleted file mode 100644 index a1d884f54..000000000 --- a/cmake/regex.h +++ /dev/null @@ -1,658 +0,0 @@ -/* Definitions for data structures and routines for the regular - expression library. - Copyright (C) 1985, 1989-2018 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, see - . */ - -#ifndef _REGEX_H -#define _REGEX_H 1 - -#include - -/* Allow the use in C++ code. */ -#ifdef __cplusplus -extern "C" { -#endif - -/* Define __USE_GNU to declare GNU extensions that violate the - POSIX name space rules. */ -#ifdef _GNU_SOURCE -# define __USE_GNU 1 -#endif - -#ifdef _REGEX_LARGE_OFFSETS - -/* Use types and values that are wide enough to represent signed and - unsigned byte offsets in memory. This currently works only when - the regex code is used outside of the GNU C library; it is not yet - supported within glibc itself, and glibc users should not define - _REGEX_LARGE_OFFSETS. */ - -/* The type of object sizes. */ -typedef size_t __re_size_t; - -/* The type of object sizes, in places where the traditional code - uses unsigned long int. */ -typedef size_t __re_long_size_t; - -#else - -/* The traditional GNU regex implementation mishandles strings longer - than INT_MAX. */ -typedef unsigned int __re_size_t; -typedef unsigned long int __re_long_size_t; - -#endif - -/* The following two types have to be signed and unsigned integer type - wide enough to hold a value of a pointer. For most ANSI compilers - ptrdiff_t and size_t should be likely OK. Still size of these two - types is 2 for Microsoft C. Ugh... */ -typedef long int s_reg_t; -typedef unsigned long int active_reg_t; - -/* The following bits are used to determine the regexp syntax we - recognize. The set/not-set meanings are chosen so that Emacs syntax - remains the value 0. The bits are given in alphabetical order, and - the definitions shifted by one from the previous bit; thus, when we - add or remove a bit, only one other definition need change. */ -typedef unsigned long int reg_syntax_t; - -#ifdef __USE_GNU -/* If this bit is not set, then \ inside a bracket expression is literal. - If set, then such a \ quotes the following character. */ -# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) - -/* If this bit is not set, then + and ? are operators, and \+ and \? are - literals. - If set, then \+ and \? are operators and + and ? are literals. */ -# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) - -/* If this bit is set, then character classes are supported. They are: - [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], - [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. - If not set, then character classes are not supported. */ -# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) - -/* If this bit is set, then ^ and $ are always anchors (outside bracket - expressions, of course). - If this bit is not set, then it depends: - ^ is an anchor if it is at the beginning of a regular - expression or after an open-group or an alternation operator; - $ is an anchor if it is at the end of a regular expression, or - before a close-group or an alternation operator. - - This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because - POSIX draft 11.2 says that * etc. in leading positions is undefined. - We already implemented a previous draft which made those constructs - invalid, though, so we haven't changed the code back. */ -# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) - -/* If this bit is set, then special characters are always special - regardless of where they are in the pattern. - If this bit is not set, then special characters are special only in - some contexts; otherwise they are ordinary. Specifically, - * + ? and intervals are only special when not after the beginning, - open-group, or alternation operator. */ -# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) - -/* If this bit is set, then *, +, ?, and { cannot be first in an re or - immediately after an alternation or begin-group operator. */ -# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) - -/* If this bit is set, then . matches newline. - If not set, then it doesn't. */ -# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) - -/* If this bit is set, then . doesn't match NUL. - If not set, then it does. */ -# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) - -/* If this bit is set, nonmatching lists [^...] do not match newline. - If not set, they do. */ -# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) - -/* If this bit is set, either \{...\} or {...} defines an - interval, depending on RE_NO_BK_BRACES. - If not set, \{, \}, {, and } are literals. */ -# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) - -/* If this bit is set, +, ? and | aren't recognized as operators. - If not set, they are. */ -# define RE_LIMITED_OPS (RE_INTERVALS << 1) - -/* If this bit is set, newline is an alternation operator. - If not set, newline is literal. */ -# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) - -/* If this bit is set, then '{...}' defines an interval, and \{ and \} - are literals. - If not set, then '\{...\}' defines an interval. */ -# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) - -/* If this bit is set, (...) defines a group, and \( and \) are literals. - If not set, \(...\) defines a group, and ( and ) are literals. */ -# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) - -/* If this bit is set, then \ matches . - If not set, then \ is a back-reference. */ -# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) - -/* If this bit is set, then | is an alternation operator, and \| is literal. - If not set, then \| is an alternation operator, and | is literal. */ -# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) - -/* If this bit is set, then an ending range point collating higher - than the starting range point, as in [z-a], is invalid. - If not set, then when ending range point collates higher than the - starting range point, the range is ignored. */ -# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) - -/* If this bit is set, then an unmatched ) is ordinary. - If not set, then an unmatched ) is invalid. */ -# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) - -/* If this bit is set, succeed as soon as we match the whole pattern, - without further backtracking. */ -# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) - -/* If this bit is set, do not process the GNU regex operators. - If not set, then the GNU regex operators are recognized. */ -# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) - -/* If this bit is set, turn on internal regex debugging. - If not set, and debugging was on, turn it off. - This only works if regex.c is compiled -DDEBUG. - We define this bit always, so that all that's needed to turn on - debugging is to recompile regex.c; the calling code can always have - this bit set, and it won't affect anything in the normal case. */ -# define RE_DEBUG (RE_NO_GNU_OPS << 1) - -/* If this bit is set, a syntactically invalid interval is treated as - a string of ordinary characters. For example, the ERE 'a{1' is - treated as 'a\{1'. */ -# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1) - -/* If this bit is set, then ignore case when matching. - If not set, then case is significant. */ -# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1) - -/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only - for ^, because it is difficult to scan the regex backwards to find - whether ^ should be special. */ -# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1) - -/* If this bit is set, then \{ cannot be first in a regex or - immediately after an alternation, open-group or \} operator. */ -# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1) - -/* If this bit is set, then no_sub will be set to 1 during - re_compile_pattern. */ -# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1) -#endif - -/* This global variable defines the particular regexp syntax to use (for - some interfaces). When a regexp is compiled, the syntax used is - stored in the pattern buffer, so changing this does not affect - already-compiled regexps. */ -extern reg_syntax_t re_syntax_options; - -#ifdef __USE_GNU -/* Define combinations of the above bits for the standard possibilities. - (The [[[ comments delimit what gets put into the Texinfo file, so - don't delete them!) */ -/* [[[begin syntaxes]]] */ -# define RE_SYNTAX_EMACS 0 - -# define RE_SYNTAX_AWK \ - (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ - | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CHAR_CLASSES \ - | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) - -# define RE_SYNTAX_GNU_AWK \ - ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ - | RE_INVALID_INTERVAL_ORD) \ - & ~(RE_DOT_NOT_NULL | RE_CONTEXT_INDEP_OPS \ - | RE_CONTEXT_INVALID_OPS )) - -# define RE_SYNTAX_POSIX_AWK \ - (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ - | RE_INTERVALS | RE_NO_GNU_OPS \ - | RE_INVALID_INTERVAL_ORD) - -# define RE_SYNTAX_GREP \ - ((RE_SYNTAX_POSIX_BASIC | RE_NEWLINE_ALT) \ - & ~(RE_CONTEXT_INVALID_DUP | RE_DOT_NOT_NULL)) - -# define RE_SYNTAX_EGREP \ - ((RE_SYNTAX_POSIX_EXTENDED | RE_INVALID_INTERVAL_ORD | RE_NEWLINE_ALT) \ - & ~(RE_CONTEXT_INVALID_OPS | RE_DOT_NOT_NULL)) - -/* POSIX grep -E behavior is no longer incompatible with GNU. */ -# define RE_SYNTAX_POSIX_EGREP \ - RE_SYNTAX_EGREP - -/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ -# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC - -# define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC - -/* Syntax bits common to both basic and extended POSIX regex syntax. */ -# define _RE_SYNTAX_POSIX_COMMON \ - (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ - | RE_INTERVALS | RE_NO_EMPTY_RANGES) - -# define RE_SYNTAX_POSIX_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP) - -/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes - RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this - isn't minimal, since other operators, such as \`, aren't disabled. */ -# define RE_SYNTAX_POSIX_MINIMAL_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) - -# define RE_SYNTAX_POSIX_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ - | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) - -/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is - removed and RE_NO_BK_REFS is added. */ -# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) -/* [[[end syntaxes]]] */ - -/* Maximum number of duplicates an interval can allow. POSIX-conforming - systems might define this in , but we want our - value, so remove any previous define. */ -# ifdef _REGEX_INCLUDE_LIMITS_H -# include -# endif -# ifdef RE_DUP_MAX -# undef RE_DUP_MAX -# endif - -/* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored - the counter as a 2-byte signed integer. This is no longer true, so - RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to - ((SIZE_MAX - 9) / 10) if _REGEX_LARGE_OFFSETS is defined. - However, there would be a huge performance problem if someone - actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains - its historical value. */ -# define RE_DUP_MAX (0x7fff) -#endif - - -/* POSIX 'cflags' bits (i.e., information for 'regcomp'). */ - -/* If this bit is set, then use extended regular expression syntax. - If not set, then use basic regular expression syntax. */ -#define REG_EXTENDED 1 - -/* If this bit is set, then ignore case when matching. - If not set, then case is significant. */ -#define REG_ICASE (1 << 1) - -/* If this bit is set, then anchors do not match at newline - characters in the string. - If not set, then anchors do match at newlines. */ -#define REG_NEWLINE (1 << 2) - -/* If this bit is set, then report only success or fail in regexec. - If not set, then returns differ between not matching and errors. */ -#define REG_NOSUB (1 << 3) - - -/* POSIX 'eflags' bits (i.e., information for regexec). */ - -/* If this bit is set, then the beginning-of-line operator doesn't match - the beginning of the string (presumably because it's not the - beginning of a line). - If not set, then the beginning-of-line operator does match the - beginning of the string. */ -#define REG_NOTBOL 1 - -/* Like REG_NOTBOL, except for the end-of-line. */ -#define REG_NOTEOL (1 << 1) - -/* Use PMATCH[0] to delimit the start and end of the search in the - buffer. */ -#define REG_STARTEND (1 << 2) - - -/* If any error codes are removed, changed, or added, update the - '__re_error_msgid' table in regcomp.c. */ - -typedef enum -{ - _REG_ENOSYS = -1, /* This will never happen for this implementation. */ - _REG_NOERROR = 0, /* Success. */ - _REG_NOMATCH, /* Didn't find a match (for regexec). */ - - /* POSIX regcomp return error codes. (In the order listed in the - standard.) */ - _REG_BADPAT, /* Invalid pattern. */ - _REG_ECOLLATE, /* Invalid collating element. */ - _REG_ECTYPE, /* Invalid character class name. */ - _REG_EESCAPE, /* Trailing backslash. */ - _REG_ESUBREG, /* Invalid back reference. */ - _REG_EBRACK, /* Unmatched left bracket. */ - _REG_EPAREN, /* Parenthesis imbalance. */ - _REG_EBRACE, /* Unmatched \{. */ - _REG_BADBR, /* Invalid contents of \{\}. */ - _REG_ERANGE, /* Invalid range end. */ - _REG_ESPACE, /* Ran out of memory. */ - _REG_BADRPT, /* No preceding re for repetition op. */ - - /* Error codes we've added. */ - _REG_EEND, /* Premature end. */ - _REG_ESIZE, /* Too large (e.g., repeat count too large). */ - _REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ -} reg_errcode_t; - -#if defined _XOPEN_SOURCE || defined __USE_XOPEN2K -# define REG_ENOSYS _REG_ENOSYS -#endif -#define REG_NOERROR _REG_NOERROR -#define REG_NOMATCH _REG_NOMATCH -#define REG_BADPAT _REG_BADPAT -#define REG_ECOLLATE _REG_ECOLLATE -#define REG_ECTYPE _REG_ECTYPE -#define REG_EESCAPE _REG_EESCAPE -#define REG_ESUBREG _REG_ESUBREG -#define REG_EBRACK _REG_EBRACK -#define REG_EPAREN _REG_EPAREN -#define REG_EBRACE _REG_EBRACE -#define REG_BADBR _REG_BADBR -#define REG_ERANGE _REG_ERANGE -#define REG_ESPACE _REG_ESPACE -#define REG_BADRPT _REG_BADRPT -#define REG_EEND _REG_EEND -#define REG_ESIZE _REG_ESIZE -#define REG_ERPAREN _REG_ERPAREN - -/* This data structure represents a compiled pattern. Before calling - the pattern compiler, the fields 'buffer', 'allocated', 'fastmap', - and 'translate' can be set. After the pattern has been compiled, - the fields 're_nsub', 'not_bol' and 'not_eol' are available. All - other fields are private to the regex routines. */ - -#ifndef RE_TRANSLATE_TYPE -# define __RE_TRANSLATE_TYPE unsigned char * -# ifdef __USE_GNU -# define RE_TRANSLATE_TYPE __RE_TRANSLATE_TYPE -# endif -#endif - -#ifdef __USE_GNU -# define __REPB_PREFIX(name) name -#else -# define __REPB_PREFIX(name) __##name -#endif - -struct re_pattern_buffer -{ - /* Space that holds the compiled pattern. The type - 'struct re_dfa_t' is private and is not declared here. */ - struct re_dfa_t *__REPB_PREFIX(buffer); - - /* Number of bytes to which 'buffer' points. */ - __re_long_size_t __REPB_PREFIX(allocated); - - /* Number of bytes actually used in 'buffer'. */ - __re_long_size_t __REPB_PREFIX(used); - - /* Syntax setting with which the pattern was compiled. */ - reg_syntax_t __REPB_PREFIX(syntax); - - /* Pointer to a fastmap, if any, otherwise zero. re_search uses the - fastmap, if there is one, to skip over impossible starting points - for matches. */ - char *__REPB_PREFIX(fastmap); - - /* Either a translate table to apply to all characters before - comparing them, or zero for no translation. The translation is - applied to a pattern when it is compiled and to a string when it - is matched. */ - __RE_TRANSLATE_TYPE __REPB_PREFIX(translate); - - /* Number of subexpressions found by the compiler. */ - size_t re_nsub; - - /* Zero if this pattern cannot match the empty string, one else. - Well, in truth it's used only in 're_search_2', to see whether or - not we should use the fastmap, so we don't set this absolutely - perfectly; see 're_compile_fastmap' (the "duplicate" case). */ - unsigned __REPB_PREFIX(can_be_null) : 1; - - /* If REGS_UNALLOCATED, allocate space in the 'regs' structure - for 'max (RE_NREGS, re_nsub + 1)' groups. - If REGS_REALLOCATE, reallocate space if necessary. - If REGS_FIXED, use what's there. */ -#ifdef __USE_GNU -# define REGS_UNALLOCATED 0 -# define REGS_REALLOCATE 1 -# define REGS_FIXED 2 -#endif - unsigned __REPB_PREFIX(regs_allocated) : 2; - - /* Set to zero when 're_compile_pattern' compiles a pattern; set to - one by 're_compile_fastmap' if it updates the fastmap. */ - unsigned __REPB_PREFIX(fastmap_accurate) : 1; - - /* If set, 're_match_2' does not return information about - subexpressions. */ - unsigned __REPB_PREFIX(no_sub) : 1; - - /* If set, a beginning-of-line anchor doesn't match at the beginning - of the string. */ - unsigned __REPB_PREFIX(not_bol) : 1; - - /* Similarly for an end-of-line anchor. */ - unsigned __REPB_PREFIX(not_eol) : 1; - - /* If true, an anchor at a newline matches. */ - unsigned __REPB_PREFIX(newline_anchor) : 1; -}; - -typedef struct re_pattern_buffer regex_t; - -/* Type for byte offsets within the string. POSIX mandates this. */ -#ifdef _REGEX_LARGE_OFFSETS -/* POSIX 1003.1-2008 requires that regoff_t be at least as wide as - ptrdiff_t and ssize_t. We don't know of any hosts where ptrdiff_t - is wider than ssize_t, so ssize_t is safe. ptrdiff_t is not - visible here, so use ssize_t. */ -typedef ssize_t regoff_t; -#else -/* The traditional GNU regex implementation mishandles strings longer - than INT_MAX. */ -typedef int regoff_t; -#endif - - -#ifdef __USE_GNU -/* This is the structure we store register match data in. See - regex.texinfo for a full description of what registers match. */ -struct re_registers -{ - __re_size_t num_regs; - regoff_t *start; - regoff_t *end; -}; - - -/* If 'regs_allocated' is REGS_UNALLOCATED in the pattern buffer, - 're_match_2' returns information about at least this many registers - the first time a 'regs' structure is passed. */ -# ifndef RE_NREGS -# define RE_NREGS 30 -# endif -#endif - - -/* POSIX specification for registers. Aside from the different names than - 're_registers', POSIX uses an array of structures, instead of a - structure of arrays. */ -typedef struct -{ - regoff_t rm_so; /* Byte offset from string's start to substring's start. */ - regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ -} regmatch_t; - -/* Declarations for routines. */ - -#ifdef __USE_GNU -/* Sets the current default syntax to SYNTAX, and return the old syntax. - You can also simply assign to the 're_syntax_options' variable. */ -extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); - -/* Compile the regular expression PATTERN, with length LENGTH - and syntax given by the global 're_syntax_options', into the buffer - BUFFER. Return NULL if successful, and an error string if not. - - To free the allocated storage, you must call 'regfree' on BUFFER. - Note that the translate table must either have been initialized by - 'regcomp', with a malloc'ed value, or set to NULL before calling - 'regfree'. */ -extern const char *re_compile_pattern (const char *__pattern, size_t __length, - struct re_pattern_buffer *__buffer); - - -/* Compile a fastmap for the compiled pattern in BUFFER; used to - accelerate searches. Return 0 if successful and -2 if was an - internal error. */ -extern int re_compile_fastmap (struct re_pattern_buffer *__buffer); - - -/* Search in the string STRING (with length LENGTH) for the pattern - compiled into BUFFER. Start searching at position START, for RANGE - characters. Return the starting position of the match, -1 for no - match, or -2 for an internal error. Also return register - information in REGS (if REGS and BUFFER->no_sub are nonzero). */ -extern regoff_t re_search (struct re_pattern_buffer *__buffer, - const char *__String, regoff_t __length, - regoff_t __start, regoff_t __range, - struct re_registers *__regs); - - -/* Like 're_search', but search in the concatenation of STRING1 and - STRING2. Also, stop searching at index START + STOP. */ -extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer, - const char *__string1, regoff_t __length1, - const char *__string2, regoff_t __length2, - regoff_t __start, regoff_t __range, - struct re_registers *__regs, - regoff_t __stop); - - -/* Like 're_search', but return how many characters in STRING the regexp - in BUFFER matched, starting at position START. */ -extern regoff_t re_match (struct re_pattern_buffer *__buffer, - const char *__String, regoff_t __length, - regoff_t __start, struct re_registers *__regs); - - -/* Relates to 're_match' as 're_search_2' relates to 're_search'. */ -extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer, - const char *__string1, regoff_t __length1, - const char *__string2, regoff_t __length2, - regoff_t __start, struct re_registers *__regs, - regoff_t __stop); - - -/* Set REGS to hold NUM_REGS registers, storing them in STARTS and - ENDS. Subsequent matches using BUFFER and REGS will use this memory - for recording register information. STARTS and ENDS must be - allocated with malloc, and must each be at least 'NUM_REGS * sizeof - (regoff_t)' bytes long. - - If NUM_REGS == 0, then subsequent matches should allocate their own - register data. - - Unless this function is called, the first search or match using - BUFFER will allocate its own register data, without - freeing the old data. */ -extern void re_set_registers (struct re_pattern_buffer *__buffer, - struct re_registers *__regs, - __re_size_t __num_regs, - regoff_t *__starts, regoff_t *__ends); -#endif /* Use GNU */ - -#if defined _REGEX_RE_COMP || (defined _LIBC && defined __USE_MISC) -# ifndef _CRAY -/* 4.2 bsd compatibility. */ -extern char *re_comp (const char *); -extern int re_exec (const char *); -# endif -#endif - -/* For plain 'restrict', use glibc's __restrict if defined. - Otherwise, GCC 2.95 and later have "__restrict"; C99 compilers have - "restrict", and "configure" may have defined "restrict". - Other compilers use __restrict, __restrict__, and _Restrict, and - 'configure' might #define 'restrict' to those words, so pick a - different name. */ -#ifndef _Restrict_ -# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) -# define _Restrict_ __restrict -# elif 199901L <= __STDC_VERSION__ || defined restrict -# define _Restrict_ restrict -# else -# define _Restrict_ -# endif -#endif -/* For [restrict], use glibc's __restrict_arr if available. - Otherwise, GCC 3.1 (not in C++ mode) and C99 support [restrict]. */ -#ifndef _Restrict_arr_ -# ifdef __restrict_arr -# define _Restrict_arr_ __restrict_arr -# elif ((199901L <= __STDC_VERSION__ || 3 < __GNUC__ + (1 <= __GNUC_MINOR__)) \ - && !defined __GNUG__) -# define _Restrict_arr_ _Restrict_ -# else -# define _Restrict_arr_ -# endif -#endif - -/* POSIX compatibility. */ -extern int regcomp (regex_t *_Restrict_ __preg, - const char *_Restrict_ __pattern, - int __cflags); - -extern int regexec (const regex_t *_Restrict_ __preg, - const char *_Restrict_ __String, size_t __nmatch, - regmatch_t __pmatch[_Restrict_arr_], - int __eflags); - -extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg, - char *_Restrict_ __errbuf, size_t __errbuf_size); - -extern void regfree (regex_t *__preg); - - -#ifdef __cplusplus -} -#endif /* C++ */ - -#endif /* regex.h */ \ No newline at end of file diff --git a/cmake/swap.c b/cmake/swap.c deleted file mode 100644 index 7f0b693fd..000000000 --- a/cmake/swap.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -uint32_t htonl(uint32_t x) -{ -#if HOST_IS_LITTLE_ENDIAN - uint8_t *s = (uint8_t *)&x; - return (uint32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); -#else - return x; -#endif -} -uint16_t htons(uint16_t x) -{ -#if HOST_IS_LITTLE_ENDIAN - uint8_t *s = (uint8_t *)&x; - return (uint16_t)(s[0] << 8 | s[1]); -#else - return x; -#endif -} From 2e4d0629fed0a64aa393d77a1c0f0130a8c1841a Mon Sep 17 00:00:00 2001 From: Joel Winarske Date: Tue, 4 Sep 2018 21:22:00 -0700 Subject: [PATCH 8/8] typo fix --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 516a313f6..2b5a6dad1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,8 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake") if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Relase) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: DEBUG, RELEASE, or MINSIZEREL." FORCE) + message(STATUS "No build type specified, defaulting to Release.") endif() project(flex LANGUAGES C)