%# listed and processed in misc.c.
%#
%# %# - A comment. The current line is ommited from the generated scanner.
+%# %push - Push the current state of the skel processing
+%# A push is typically followed by one of the commands below.
+%# %pop - Pop the state.
%# %c++-only - The following lines are printed for C++ scanners ONLY.
%# %c-only - The following lines are NOT printed for C++ scanners.
%# %c-or-c++ - The following lines are printed in BOTH C and C++ scanners.
%# %not-for-header - Begin code that should NOT appear in a ".h" file.
%# %ok-for-header - %c and %e are used for building a header file.
%# %tables-serialization-code-begin
-%# %tables-serialization-code-end
%#
%# All control-lines EXCEPT comment lines ("%#") will be inserted into
%# the generated scanner as a C-style comment. This is to aid those who
#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
+%push
%tables-serialization-code-begin
#include <netinet/in.h>
-%tables-serialization-code-end
+%pop
/* end standard C headers. */
%c++-only
/* begin standard C++ headers. */
%c-or-c++
#endif
+%push
%tables-serialization-code-begin structures and prototypes
m4_include(`tables_shared.h')
uint32_t bread; /**< bytes read since beginning of current tableset */
};
-%tables-serialization-code-end structures and prototypes
+/* end tables serialization structures and prototypes */
+%pop
%ok-for-header
/* Default declaration of generated scanner - a define so the user can
}
#endif
+%push
%tables-serialization-code-begin definitions
m4_include(`tables_shared.c')
return 0;
}
-%tables-serialization-code-end definitions
+/* end table serialization code definitions */
+%pop
#if YY_MAIN
int main YY_PARAMS((void));
bool *rule_has_nl, *ccl_has_nl;
int nlch = '\n';
-bool tablesext, tablestoggle, tablesverify, gentables;
+bool tablesext, tablesverify, gentables;
char *tablesfilename=0,*tablesname=0;
struct yytbl_writer tableswr;
prefix = "yy";
yyclass = 0;
use_read = use_stdout = false;
- tablesext = tablestoggle = tablesverify = false;
+ tablesext = tablesverify = false;
gentables = true;
tablesfilename = tablesname = NULL;
#define CMD_C_OR_CPP "%c-or-c++"
#define CMD_NOT_FOR_HEADER "%not-for-header"
#define CMD_OK_FOR_HEADER "%ok-for-header"
+#define CMD_PUSH "%push"
+#define CMD_POP "%pop"
+
+/* we allow the skeleton to push and pop. */
+struct sko_state {
+ bool dc; /**< do_copy */
+ bool tt; /**< tables_toggle */
+};
+static struct sko_state *sko_stack=0;
+static int sko_len=0,sko_sz=0;
+static void sko_push(bool dc, bool tt)
+{
+ if(!sko_stack){
+ sko_sz = 1;
+ sko_stack = (struct sko_state*)flex_alloc(sizeof(struct sko_state)*sko_sz);
+ sko_len = 0;
+ }
+ if(sko_len >= sko_sz){
+ sko_sz *= 2;
+ sko_stack = (struct sko_state*)flex_realloc(sko_stack,sizeof(struct sko_state)*sko_sz);
+ }
+
+ /* initialize to zero and push */
+ sko_stack[sko_len].dc = dc;
+ sko_stack[sko_len].tt = tt;
+ sko_len++;
+}
+static void sko_peek(bool *dc, bool* tt)
+{
+ if(sko_len <= 0)
+ flex_die("peek attempt when sko stack is empty");
+ if(dc)
+ *dc = sko_stack[sko_len-1].dc;
+ if(tt)
+ *tt = sko_stack[sko_len-1].tt;
+}
+static void sko_pop(bool* dc, bool *tt)
+{
+ sko_peek(dc,tt);
+ sko_len--;
+ if(sko_len < 0)
+ flex_die("popped too many times in skeleton.");
+}
/* Append "#define defname value\n" to the running buffer. */
void action_define (defname, value)
{
char buf_storage[MAXLINE];
char *buf = buf_storage;
- int do_copy = 1;
+ bool do_copy = true;
+ bool tablestoggle=false;
+
+ /* "reset" the state by clearing the buffer and pushing a '1' */
+ if(sko_len > 0)
+ sko_peek(&do_copy,&tablestoggle);
+ sko_len = 0;
+ sko_push(do_copy=true,tablestoggle);
+
/* Loop pulling lines either from the skelfile, if we're using
* one, or from the skel[] array.
/* %% is a break point for skelout() */
return;
}
+ else if (cmd_match (CMD_PUSH)){
+ sko_push(do_copy,tablestoggle);
+ out_str("/*(state = (%s,",do_copy?"true":"false");
+ out_str( "%s)*/\n",tablestoggle?"true":"false");
+ }
+ else if (cmd_match (CMD_POP)){
+ sko_pop(&do_copy,&tablestoggle);
+ out_str("/*(state = (%s,",do_copy?"true":"false");
+ out_str( "%s)*/\n",tablestoggle?"true":"false");
+ }
else if (cmd_match (CMD_TABLES_SER_BEGIN)) {
tablestoggle = true;
}
}
else if (cmd_match (CMD_C_OR_CPP)) {
/* %* for C and C++ */
- do_copy = 1;
+ do_copy = true;
}
else if (cmd_match (CMD_NOT_FOR_HEADER)) {
/* %c begin linkage-only (non-header) code. */
/* These are used by main.c, gen.c, etc.
* tablesext - if true, create external tables
- * tablestoggle - if true, output external tables code while processing skel
* tablesfilename - filename for external tables
* tablesname - name that goes in serialized data, e.g., "yytables"
* tableswr - writer for external tables
* tablesverify - true if tables-verify option specified
* gentables - true if we should spit out the normal C tables
*/
-extern bool tablesext, tablestoggle, tablesverify,gentables;
+extern bool tablesext, tablesverify,gentables;
extern char *tablesfilename, *tablesname;
extern struct yytbl_writer tableswr;