]> granicus.if.org Git - flex/commitdiff
More work on tables serialization.
authorJohn Millaway <john43@users.sourceforge.net>
Mon, 19 Aug 2002 21:56:33 +0000 (21:56 +0000)
committerJohn Millaway <john43@users.sourceforge.net>
Mon, 19 Aug 2002 21:56:33 +0000 (21:56 +0000)
Makefile.am
configure.in
flex.skl
flexdef.h
tables_shared.h [new file with mode: 0644]

index ac1a762947a90457cf3581d5bcc072a8be549405..61b0fc1e89385f5fd499740d2da296371b9f0c40 100644 (file)
@@ -74,7 +74,8 @@ noinst_HEADERS = \
        flexdef.h \
        version.h \
        options.h \
-       scanopt.h
+       scanopt.h \
+       tables_shared.h
 
 include_HEADERS = \
        FlexLexer.h
index bc23d8ec149022112a2a97f4f0207d8a310cb5df..66f3fa6cacbc58680d9a54bd80c34d0d62aa51c6 100644 (file)
@@ -42,7 +42,7 @@ AC_C_CONST
 AC_TYPE_SIZE_T
 AC_HEADER_STDC
 AC_CHECK_HEADERS(string.h malloc.h sys/types.h unistd.h stdbool.h)
-AC_CHECK_HEADERS(cunistd)
+AC_CHECK_HEADERS(cunistd netinet/in.h)
 
 AC_CONFIG_FILES(
 Makefile
index 916f85ccd72c5772be00a6d60337d12d0a82bb88..debc996abb2fdc6bdb75dc5c51cc2b535580aa41 100644 (file)
--- a/flex.skl
+++ b/flex.skl
@@ -744,17 +744,7 @@ static int yy_top_state YY_PARAMS(( YY_PROTO_ONLY_ARG ));
 #endif
 
 %t Tables API Structures and Prototypes
-
-/* Load tables from a file descriptor. */
-//int yytables_read YY_PARAMS((int fd, const char * tbl_name  YY_PROTO_LAST_ARG));
-
-/* Load tables from a file stream. */
-int yytables_fread YY_PARAMS((FILE* fp, const char * tbl_name  YY_PROTO_LAST_ARG));
-
-/* Load tables from given bytes. */
-//int yytables_bread YY_PARAMS((void* bytes, const char * tbl_name  YY_PROTO_LAST_ARG));
-
-
+m4_include(`tables_shared.h')
 %t End of Tables API Structures and Prototypes
 
 /* Default declaration of generated scanner - a define so the user can
index a8a8ea963d1dd650995c032f7b21a29dd2f06d9a..8bfff42079ac53924e35b7a9c2e9b14b23695c67 100644 (file)
--- a/flexdef.h
+++ b/flexdef.h
@@ -35,6 +35,7 @@
 #define FLEXDEF_H 1
 
 #include <stdio.h>
+#include <stdint.h>
 #include <ctype.h>
 #include <limits.h>
 #include <setjmp.h>
 
 #define unspecified -1
 
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
 
 /* Special chk[] values marking the slots taking by end-of-buffer and action
  * numbers.
@@ -1088,4 +1092,7 @@ extern jmp_buf flex_main_jmp_buf;
 /* Removes all \n and \r chars from tail of str. returns str. */
 extern char* chomp(char* str);
 
+/* Tables serialization API declarations. */
+#include "tables_shared.h"
+
 #endif /* not defined FLEXDEF_H */
diff --git a/tables_shared.h b/tables_shared.h
new file mode 100644 (file)
index 0000000..eec13e0
--- /dev/null
@@ -0,0 +1,103 @@
+/*  tables_shared.h - tables serialization header
+ *
+ *  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.
+ */
+\f
+/* This file is meant to be included in both the skeleton and the actual
+ * flex code (hence the name "_shared").
+ */
+
+/* Structures and prototypes for serializing flex tables.  The
+ * binary format is documented in the manual.
+ *
+ * Design considerations:
+ *
+ *  -  The format allows many tables per file.
+ *  -  The tables can be streamed.
+ *  -  All data is stored in network byte order.
+ *  -  We do not hinder future unicode support.
+ *  -  We can lookup tables by name.
+ */
+
+/** Magic number for serialized format. */
+#define YYTBL_MAGIC 0xF13C57B1
+
+/** Possible values for t_id field. Each one corresponds to a
+ *  scanner table of the same name.
+ */
+enum yytbl_id
+{
+    YYT_ID_ACCEPT = 0x01,
+    YYT_ID_BASE   = 0x02,
+    YYT_ID_CHK    = 0x03,
+    YYT_ID_DEF    = 0x04,
+    YYT_ID_EC     = 0x05,
+    YYT_ID_META   = 0x06,
+    YYT_ID_NUL_TRANS = 0x07,
+    YYT_ID_NXT = 0x08,                  /**< may be 2 dimensional array */
+    YYT_ID_RULE_CAN_MATCH_EOL = 0x09,
+    YYT_ID_START_STATE_LIST = 0x0A,     /**< array of pointers */
+    YYT_ID_TRANSITION = 0x0B            /**< array of structs */
+};
+
+/** bit flags for t_flags field of struct yytbl_data */
+enum yytbl_flags
+{
+    YYT_DATA8  = 0x01,      /**< data is an array of type int8 */
+    YYT_DATA16 = 0x02,      /**< data is an array of type int16 */
+    YYT_DATA32 = 0x04,      /**< data is an array of type int32 */
+    YYT_PTRANS = 0x08,      /**< data is a list of indexes of entries
+                                 into the expanded `yy_transition'
+                                 array. See notes in manual. */
+};
+
+/* The serialized tables header. */
+struct yytbl_hdr
+{
+  uint32_t  th_magic;       /**< Must be 0xF13C57B1 (comes from "Flex Table") */
+  uint32_t  th_hsize;       /**< Size of this header in bytes. */
+  uint32_t  th_ssize;       /**< Size of this dataset, in bytes, including header. */
+  uint16_t  th_flags;       /**< Currently unused, must be 0 */
+  char*     th_version;     /**< Flex version string. NUL terminated. */
+  char*     th_name;        /**< The name of this table set. NUL terminated. */
+};
+
+/** A single serialized table */
+struct yytbl_data
+{
+  enum yytbl_id t_id;       /**< table identifier */
+  uint16_t      t_flags;    /**< how to interpret this data */
+  uint32_t      t_hilen;    /**< num elements in highest dimension array */
+  uint32_t      t_lolen;    /**< num elements in lowest dimension array */
+  void*         t_data;     /**< table data */
+};
+