]> The Tcpdump Group git mirrors - libpcap/commitdiff
Older versions of Flex (e.g., 2.5.2, which at least one user had) dump
authorguy <guy>
Thu, 13 Jul 2000 06:51:56 +0000 (06:51 +0000)
committerguy <guy>
Thu, 13 Jul 2000 06:51:56 +0000 (06:51 +0000)
core if the YY_FLUSH_BUFFER macro is called when there's no current
buffer (e.g., before any scanning has been done).

So, instead, when using Flex, we use "yy_scan_string()" to specify that
the scanner should read from the filter expression string, rather than
defining our own YY_INPUT macro, and we add a "lex_cleanup()" routine,
called after parsing is complete, to delete the buffer allocated by
"yy_scan_string()", which arranges that, when we next hand the scanner a
string, it doesn't then return to the parser cruft left over from the
previous parse.

gencode.c
gencode.h
scanner.l

index 6eab6ced4f0847b3d9d9e14b816df09ddddf4574..cf78df8ce2e5381c96963a700549958513ae9471 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -21,7 +21,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.113 2000-07-11 00:37:04 assar Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.114 2000-07-13 06:51:56 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -276,6 +276,7 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
        root = NULL;
        bpf_pcap = p;
        if (setjmp(top_ctx)) {
        root = NULL;
        bpf_pcap = p;
        if (setjmp(top_ctx)) {
+               lex_cleanup();
                freechunks();
                return (-1);
        }
                freechunks();
                return (-1);
        }
index c458911a133527ba97741604df47b0124ee7c698..51c0e66d98fe7b75923a00a836593b52ca3bd147 100644 (file)
--- a/gencode.h
+++ b/gencode.h
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.40 2000-07-11 00:37:07 assar Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.41 2000-07-13 06:51:56 guy Exp $ (LBL)
  */
 
 /* Address qualifiers. */
  */
 
 /* Address qualifiers. */
@@ -186,6 +186,7 @@ char *sdup(const char *);
 struct bpf_insn *icode_to_fcode(struct block *, int *);
 int pcap_parse(void);
 void lex_init(char *);
 struct bpf_insn *icode_to_fcode(struct block *, int *);
 int pcap_parse(void);
 void lex_init(char *);
+void lex_cleanup(void);
 void sappend(struct slist *, struct slist *);
 
 /* XXX */
 void sappend(struct slist *, struct slist *);
 
 /* XXX */
index c6d789b5a185676129806da2ebe97393dd3f8bf9..1090b65d05487c882ef24b41a65d1d4980088320 100644 (file)
--- a/scanner.l
+++ b/scanner.l
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.64 2000-07-11 00:37:08 assar Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/scanner.l,v 1.65 2000-07-13 06:51:57 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -59,22 +59,10 @@ static inline int xdtoi(int);
 
 #ifdef FLEX_SCANNER
 #define YY_NO_UNPUT
 
 #ifdef FLEX_SCANNER
 #define YY_NO_UNPUT
-#undef YY_INPUT
-#define YY_INPUT(buf, result, max)\
- {\
-       char *src = in_buffer;\
-       int i;\
-\
-       if (*src == 0)\
-               result = YY_NULL;\
-       else {\
-               for (i = 0; *src && i < max; ++i)\
-                       buf[i] = *src++;\
-               in_buffer += i;\
-               result = i;\
-       }\
- }
+static YY_BUFFER_STATE in_buffer;
 #else
 #else
+static char *in_buffer;
+
 #undef getc
 #define getc(fp)  (*in_buffer == 0 ? EOF : *in_buffer++)
 #endif
 #undef getc
 #define getc(fp)  (*in_buffer == 0 ? EOF : *in_buffer++)
 #endif
@@ -82,8 +70,6 @@ static inline int xdtoi(int);
 #define yylval pcap_lval
 extern YYSTYPE yylval;
 
 #define yylval pcap_lval
 extern YYSTYPE yylval;
 
-static char *in_buffer;
-
 %}
 
 N              ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
 %}
 
 N              ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
@@ -272,13 +258,23 @@ void
 lex_init(buf)
        char *buf;
 {
 lex_init(buf)
        char *buf;
 {
+#ifdef FLEX_SCANNER
+       in_buffer = yy_scan_string(buf);
+#else
        in_buffer = buf;
        in_buffer = buf;
+#endif
+}
+
+/*
+ * Do any cleanup necessary after parsing.
+ */
+void
+lex_cleanup()
+{
 #ifdef FLEX_SCANNER
 #ifdef FLEX_SCANNER
-       /*
-        * Flush the scanner's input buffer, so that there's no cruft
-        * left over from a previous parse.
-        */
-       YY_FLUSH_BUFFER;
+       if (in_buffer != NULL)
+               yy_delete_buffer(in_buffer);
+       in_buffer = NULL;
 #endif
 }
 
 #endif
 }
 
@@ -331,4 +327,3 @@ stoi(s)
 
        return n;
 }
 
        return n;
 }
-