Merge in all of the new parser work.
authorBrian Aker <brian@tangent.org>
Fri, 18 Mar 2011 10:43:48 +0000 (03:43 -0700)
committerBrian Aker <brian@tangent.org>
Fri, 18 Mar 2011 10:43:48 +0000 (03:43 -0700)
21 files changed:
.bzrignore
Makefile.am
clients/include.am
clients/memparse.cc [new file with mode: 0644]
configure.ac
libmemcached/behavior.c
libmemcached/constants.h
libmemcached/include.am
libmemcached/memcached.c
libmemcached/memcached.h
libmemcached/options.cc [new file with mode: 0644]
libmemcached/options.h [new file with mode: 0644]
libmemcached/options/include.am [new file with mode: 0644]
libmemcached/options/lex_string.h [new file with mode: 0644]
libmemcached/options/parser.yy [new file with mode: 0644]
libmemcached/options/scanner.l [new file with mode: 0644]
libmemcached/options/server.h [new file with mode: 0644]
libmemcached/options/string.h [new file with mode: 0644]
libmemcached/options/symbol.h [new file with mode: 0644]
libmemcached/options/type.h [new file with mode: 0644]
m4/pandora_warnings.m4

index 87578c4bc01c3468780834952bfb83eb0bd25a10..e7ff2911aa8964063c72901bc0cd7ed1c8b03a95 100644 (file)
@@ -1,6 +1,7 @@
 *.exe
 *.lo
 *.pop
+*.rpm
 */*.l[oa]
 */*/*.l[oa]
 */*/.deps
@@ -40,6 +41,7 @@ config/ltmain.sh
 config/missing
 config/pandora_vc_revinfo
 config/plugin.ac
+config/top.h
 configure
 docs/*.[13]
 docs/*.html
@@ -73,7 +75,16 @@ libmemcached-?.??/
 libmemcached.pop
 libmemcached/configure.h
 libmemcached/dtrace_probes.h
+libmemcached/generated_probes.h
 libmemcached/memcached_configure.h
+libmemcached/options/parser.cc
+libmemcached/options/parser.h
+libmemcached/options/parser.output
+libmemcached/options/parsers.cc
+libmemcached/options/parsers.h
+libmemcached/options/parsers.output
+libmemcached/options/scanner.cc
+libmemcached/options/scanner.h
 libmemcached_examples.pop
 libmemcachedutil.pop
 libtool
@@ -185,5 +196,4 @@ tests/testhashkit
 tests/testplus
 tests/testudp
 unittests/unittests
-config/top.h
-libmemcached/generated_probes.h
+clients/memparse
index 31585120cae1d8ff2ec87602823017247202e72e..7a09b51f35a9fff850a171aa7e13cc33eb20430e 100644 (file)
@@ -15,6 +15,7 @@ nobase_include_HEADERS =
 check_PROGRAMS =
 EXTRA_HEADERS =
 BUILT_SOURCES=
+DISTCLEANFILES=
 EXTRA_DIST= \
            ${srcdir}/m4/pandora_*.m4 \
            .quickly \
index a709e38df6c979e6f28a4657e500a8a4b6bfd6b7..f7503754649028eb6ae48ef96911e808dcb2bade 100644 (file)
@@ -18,6 +18,7 @@ bin_PROGRAMS+= \
        clients/memdump \
        clients/memerror \
        clients/memflush \
+       clients/memparse \
        clients/memrm \
        clients/memstat
 
@@ -50,6 +51,9 @@ clients_libgenexec_la_SOURCES= clients/generator.c clients/execute.c
 clients_memcat_SOURCES= clients/memcat.c
 clients_memcat_LDADD= $(CLIENTS_LDADDS)
 
+clients_memparse_SOURCES= clients/memparse.cc
+clients_memparse_LDADD= $(CLIENTS_LDADDS)
+
 clients_memcp_SOURCES= clients/memcp.c
 clients_memcp_LDADD= $(CLIENTS_LDADDS)
 
diff --git a/clients/memparse.cc b/clients/memparse.cc
new file mode 100644 (file)
index 0000000..50eedfc
--- /dev/null
@@ -0,0 +1,66 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * 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.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <config.h>
+
+#include <iostream>
+
+#include <libmemcached/memcached.h>
+
+int main(int argc, char *argv[])
+{
+
+  if (argc != 2)
+  {
+    std::cerr << "Wrong number of arguments" << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  memcached_st *memc;
+
+  memc= memcached_create(NULL);
+
+  memcached_return_t rc= memcached_parse_options(memc, argv[1], strlen(argv[1]));
+
+  if (rc != MEMCACHED_SUCCESS)
+  {
+    std::cerr << "Failed to parse options" << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  return EXIT_SUCCESS;
+}
index c3b4300f7a23fce36d8e51050d1b94efff08615c..2af6cae1032aaeb296f0355119b63c8ebccb6723 100644 (file)
@@ -1,5 +1,6 @@
 #!/usr/bin/env bash
-# libmemcached
+# LibmemcacheD
+# Copyright (C) 2011 Data Differential, http://datadifferential.com/
 # Copyright (C) 2006-2010 Brian Aker, Monty Taylor, Trond Norbye
 # All rights reserved.
 #
@@ -12,6 +13,8 @@ AC_CONFIG_SRCDIR([libmemcached/memcached.c])
 AC_CONFIG_AUX_DIR(config)
 
 PANDORA_CANONICAL_TARGET(no-vc-changelog)
+AC_CHECK_PROGS([YACC], ['bison'], [:])
+AC_CHECK_PROGS([LEX], ['flex'], [:])
 
 #shared library versioning
 MEMCACHED_UTIL_LIBRARY_VERSION=1:0:0
index f88f0a771c1f556d926a20322cfb776da7f46789..da111351bee3a942c43f643e4f9861557478639c 100644 (file)
@@ -227,6 +227,9 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr,
         }
       }
       break;
+  case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE:
+    ptr->flags.load_from_file= set_flag(data);
+    break;
   case MEMCACHED_BEHAVIOR_MAX:
   default:
     /* Shouldn't get here */
@@ -382,6 +385,8 @@ uint64_t memcached_behavior_get(memcached_st *ptr,
     return ptr->flags.cork;
   case MEMCACHED_BEHAVIOR_TCP_KEEPALIVE:
     return ptr->flags.tcp_keepalive;
+  case MEMCACHED_BEHAVIOR_LOAD_FROM_FILE:
+    return ptr->flags.load_from_file;
   case MEMCACHED_BEHAVIOR_MAX:
   default:
     WATCHPOINT_ASSERT(0); /* Programming mistake if it gets this far */
index b12a3890ff62a6cafcf7e4a57d158ef1863d0084..00abb7bf2d16ff6f71f7c4801b1ca60a55f9d977 100644 (file)
@@ -121,6 +121,7 @@ typedef enum {
   MEMCACHED_BEHAVIOR_CORK,
   MEMCACHED_BEHAVIOR_TCP_KEEPALIVE,
   MEMCACHED_BEHAVIOR_TCP_KEEPIDLE,
+  MEMCACHED_BEHAVIOR_LOAD_FROM_FILE,
   MEMCACHED_BEHAVIOR_MAX
 } memcached_behavior_t;
 
index 7d4841f8fb03a8273727b5eb97a4158ae863bb48..75bcf6005e97042e94c03890820800fbb6dbc6c8 100644 (file)
@@ -2,6 +2,10 @@
 # included from Top Level Makefile.am
 # All paths should be given relative to the root
 
+libmemcached_libmemcached_la_SOURCES =
+
+include libmemcached/options/include.am
+
 EXTRA_DIST+= \
             libmemcached/configure.h.in \
             libmemcached/libmemcached_probes.d \
@@ -38,6 +42,7 @@ nobase_include_HEADERS+= \
                         libmemcached/memcached.h \
                         libmemcached/memcached.hpp \
                         libmemcached/memcached/protocol_binary.h \
+                        libmemcached/options.h \
                         libmemcached/parse.h \
                          libmemcached/platform.h \
                         libmemcached/protocol/cache.h \
@@ -84,7 +89,7 @@ libmemcached_libmemcachedinternal_la_SOURCES= \
 
 lib_LTLIBRARIES+= libmemcached/libmemcached.la
 libmemcached_libmemcached_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION}
-libmemcached_libmemcached_la_SOURCES = \
+libmemcached_libmemcached_la_SOURCES+= \
                                       libmemcached/allocators.c \
                                       libmemcached/analyze.c \
                                       libmemcached/auto.c \
@@ -98,6 +103,7 @@ libmemcached_libmemcached_la_SOURCES = \
                                       libmemcached/flush_buffers.c \
                                       libmemcached/get.c \
                                       libmemcached/hash.c \
+                                      libmemcached/options.cc \
                                       libmemcached/hosts.c \
                                       libmemcached/io.c \
                                       libmemcached/key.c \
@@ -115,6 +121,8 @@ libmemcached_libmemcached_la_SOURCES = \
                                       libmemcached/verbosity.c \
                                       libmemcached/version.c
 
+libmemcached/options.cc: libmemcached/options/parser.h
+
 
 libmemcached_libmemcached_la_DEPENDENCIES= libmemcached/libmemcachedcallbacks.la libmemcached/libmemcachedinternal.la libhashkit/libhashkitinc.la
 libmemcached_libmemcached_la_LIBADD= $(LIBM) libmemcached/libmemcachedcallbacks.la libmemcached/libmemcachedinternal.la libhashkit/libhashkitinc.la
index 81895afab67b19102b9e4418ee1890663cf4128c..b0333569ec7fe8f45fe943a16d210b8d70eb502c 100644 (file)
@@ -34,7 +34,9 @@ static const memcached_st global_copy= {
     .use_sort_hosts= false,
     .use_udp= false,
     .verify_key= false,
-    .tcp_keepalive= false
+    .tcp_keepalive= false,
+    .load_from_file= false
+
   }
 };
 
index c099d76e2b984f56e0b0e826149b457e13af8201..56a5a78f7777d7e642c525fd31d72828371d7293 100644 (file)
@@ -43,6 +43,7 @@
 #include <libmemcached/flush_buffers.h>
 #include <libmemcached/get.h>
 #include <libmemcached/hash.h>
+#include <libmemcached/options.h>
 #include <libmemcached/parse.h>
 #include <libmemcached/quit.h>
 #include <libmemcached/result.h>
@@ -82,6 +83,7 @@ struct memcached_st {
     bool use_udp:1;
     bool verify_key:1;
     bool tcp_keepalive:1;
+    bool load_from_file:1;
   } flags;
   memcached_server_distribution_t distribution;
   hashkit_st hashkit;
diff --git a/libmemcached/options.cc b/libmemcached/options.cc
new file mode 100644 (file)
index 0000000..1bf2ffa
--- /dev/null
@@ -0,0 +1,71 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * 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.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "common.h"
+
+#include <libmemcached/options/parser.h>
+#include <libmemcached/options/scanner.h>
+
+int libmemcached_parse(type_st *, yyscan_t *);
+
+memcached_return_t memcached_parse_options(memcached_st *self, char const *option_string, size_t length)
+{
+  type_st pp;
+
+  memset(&pp, 0, sizeof(type_st));
+
+  pp.buf= option_string;
+  pp.memc= self;
+  pp.length= length;
+  libmemcached_lex_init(&pp.yyscanner);
+  libmemcached_set_extra(&pp, pp.yyscanner);
+  bool success= libmemcached_parse(&pp, pp.yyscanner)  == 0;
+  libmemcached_lex_destroy(pp.yyscanner);
+
+  if (not success)
+    return MEMCACHED_INVALID_ARGUMENTS;
+
+  return MEMCACHED_SUCCESS;
+}
+
+memcached_return_t memcached_parse_file_options(memcached_st *ptr, const char *filename)
+{
+  (void)ptr;
+  (void)filename;
+
+  return MEMCACHED_SUCCESS;
+}
diff --git a/libmemcached/options.h b/libmemcached/options.h
new file mode 100644 (file)
index 0000000..a235154
--- /dev/null
@@ -0,0 +1,52 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * 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.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+LIBMEMCACHED_API
+  memcached_return_t memcached_parse_options(memcached_st *ptr, const char *option_string, size_t length);
+
+LIBMEMCACHED_API
+  memcached_return_t memcached_parse_file_options(memcached_st *ptr, const char *filename);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/libmemcached/options/include.am b/libmemcached/options/include.am
new file mode 100644 (file)
index 0000000..2e60573
--- /dev/null
@@ -0,0 +1,37 @@
+# vim:ft=automake
+# included from Top Level Makefile.am
+# All paths should be given relative to the root
+
+DISTCLEANFILES+= \
+                libmemcached/options/parser.output \
+                libmemcached/options/parser.cc \
+                libmemcached/options/parser.h \
+                libmemcached/options/scanner.cc \
+                libmemcached/options/scanner.h
+
+EXTRA_DIST+= \
+            libmemcached/options/scanner.l \
+            libmemcached/options/parser.yy
+
+noinst_HEADERS+= \
+                libmemcached/options/parser.h \
+                libmemcached/options/scanner.h \
+                libmemcached/options/server.h \
+                libmemcached/options/string.h \
+                libmemcached/options/symbol.h \
+                libmemcached/options/type.h
+
+libmemcached_libmemcached_la_SOURCES+= \
+                                      libmemcached/options/parser.cc \
+                                      libmemcached/options/scanner.cc
+
+libmemcached/options/parser.h: libmemcached/options/parser.cc
+
+libmemcached/options/parser.cc: libmemcached/options/parser.yy libmemcached/options/scanner.l libmemcached/options/scanner.h
+       $(AM_V_YACC)$(am__skipyacc) $(YACC) $(YLFLAGS) $(AM_YFLAGS) -o $@ $<
+
+libmemcached/options/scanner.h: libmemcached/options/scanner.cc
+
+libmemcached/options/scanner.cc: libmemcached/options/scanner.l libmemcached/options/parser.yy
+       $(AM_V_GEN)$(LEX) $<
+
diff --git a/libmemcached/options/lex_string.h b/libmemcached/options/lex_string.h
new file mode 100644 (file)
index 0000000..991acba
--- /dev/null
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <stdlib.h>
+#include <iostream>
+
+struct string_t
+{
+  const char *c_str;
+  size_t length;
+};
+
+inline std::ostream& operator<<(std::ostream& output, const string_t& arg)
+{
+  output << arg.c_str;
+  return output;
+}
diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy
new file mode 100644 (file)
index 0000000..ae7e6d5
--- /dev/null
@@ -0,0 +1,141 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * 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.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+%{
+
+#include <stdint.h>
+#include <iostream>
+
+#include <libmemcached/options/type.h>
+#include <libmemcached/options/string.h>
+#include <libmemcached/options/symbol.h>
+
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#include <libmemcached/options/scanner.h>
+
+inline int libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner, const char *str)
+{
+  std::cerr << str << std::endl;
+  return 0;
+}
+
+
+%}
+
+%error-verbose
+%debug
+%defines
+%expect 0
+%output "libmemcached/options/parser.cc"
+%defines "libmemcached/options/parser.h"
+%lex-param { yyscan_t *scanner }
+%name-prefix="libmemcached_"
+%parse-param { type_st *parser }
+%parse-param { yyscan_t *scanner }
+%locations
+%pure-parser
+%require "2.2"
+%start statement
+%verbose
+
+%token EQ
+%token SERVER
+%token SERVERS
+%token TCPNODELAY
+%token UNKNOWN
+%token VERIFY_KEY
+%token COMMA
+
+%token <number> NUMBER
+%token <number> FLOAT
+%token <string> IDENTIFIER
+%token <string> SERVER_WITH_PORT
+
+%type <server> server
+
+%%
+
+statement:
+          expression
+          { }
+        | statement expression
+          { }
+        ;
+
+
+expression:
+          SERVER EQ server
+          { 
+            (void) memcached_server_add(parser->memc, $3.c_str, $3.port);
+          }
+        | SERVERS EQ server_list
+          { }
+        | TCPNODELAY
+          {
+            memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true);
+          }
+        | VERIFY_KEY
+          {
+            memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_VERIFY_KEY, true);
+          }
+        ;
+
+server_list:
+          server
+          {
+            (void) memcached_server_add(parser->memc, $1.c_str, $1.port);
+          }
+        | server_list COMMA server
+          {
+            (void) memcached_server_add(parser->memc, $3.c_str, $3.port);
+          }
+        ;
+
+server:
+          SERVER_WITH_PORT NUMBER
+          {
+            $$.c_str= $1.c_str;
+            $$.length= $1.length;
+            $$.port= $2;
+          }
+        | IDENTIFIER
+          {
+            $$.c_str= $1.c_str;
+            $$.length= $1.length;
+            $$.port= 80;
+          }
+        ;
diff --git a/libmemcached/options/scanner.l b/libmemcached/options/scanner.l
new file mode 100644 (file)
index 0000000..e11fcf4
--- /dev/null
@@ -0,0 +1,89 @@
+
+%top{
+
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#pragma GCC diagnostic ignored "-fpermissive"
+
+#include <libmemcached/options/parser.h>
+#include <libmemcached/options/string.h>
+#include <libmemcached/options/symbol.h>
+#include <libmemcached/options/type.h>
+
+}
+
+
+%{
+#include <cstdlib>
+#include <cstring>
+
+#define PARAM yyget_extra(yyscanner)
+
+static void get_lex_chars(char* buffer, int& result, int max_size, struct type_st *parser)
+{
+  if (parser->pos >= parser->length)
+  {
+    result = YY_NULL;
+  }
+  else
+  {
+    result = parser->length - parser->pos;
+    result > (int)max_size ? result = max_size : 0;
+    memcpy(buffer, parser->buf + parser->pos, result);
+    parser->pos += result;
+  }
+}
+
+
+#define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
+
+%}
+
+%option bison-locations
+%option bison-bridge
+%option case-insensitive
+%option debug
+%option nounput
+%option noyywrap
+%option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
+%option perf-report
+%option prefix="libmemcached_"
+%option reentrant
+
+%%
+
+[=] { return EQ; }
+[,] { return COMMA; }
+
+[0-9]+ { yylval->number = atoi(yytext); return (NUMBER); }
+
+([0-9]*.[0-9]+) { yylval->double_number = atof(yytext); return (FLOAT); }
+
+[ \t\r\n] ; /* skip whitespace */
+
+"--SERVER"                 { return SERVER; }
+"--SERVERS"                 { return SERVERS; }
+"--TCP_NODELAY"                 { return TCPNODELAY; }
+"--TCP-NODELAY"                 { return TCPNODELAY; }
+"--VERIFY_KEY"                 { return VERIFY_KEY; }
+"--VERIFY-KEY"                 { return VERIFY_KEY; }
+
+[A-Za-z][A-Za-z0-9_]*[:]    { 
+                              yylval->string.c_str = yytext;
+                              yylval->string.length = yyleng;
+                              return SERVER_WITH_PORT;
+                            }
+
+[A-Za-z][A-Za-z0-9_]*   { 
+                          yylval->string.c_str = yytext;
+                          yylval->string.length = yyleng;
+                          return IDENTIFIER;
+                        }
+[-] ;
+
+.                     {
+                        std::cerr << "Near " <<  yytext << std::endl;
+                        return UNKNOWN;
+                      }
+
+%%
diff --git a/libmemcached/options/server.h b/libmemcached/options/server.h
new file mode 100644 (file)
index 0000000..af6e0f3
--- /dev/null
@@ -0,0 +1,56 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * 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.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#include <cstdlib>
+#include <iostream>
+#include <arpa/inet.h>
+
+struct server_t
+{
+  const char *c_str;
+  size_t length;
+  in_port_t port;
+};
+
+inline std::ostream& operator<<(std::ostream& output, const server_t& arg)
+{
+  output.write(arg.c_str, arg.length);
+  output << ':' << arg.port;
+  return output;
+}
diff --git a/libmemcached/options/string.h b/libmemcached/options/string.h
new file mode 100644 (file)
index 0000000..82d60ac
--- /dev/null
@@ -0,0 +1,53 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * 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.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#include <cstdlib>
+#include <iostream>
+
+struct string_t
+{
+  const char *c_str;
+  size_t length;
+};
+
+inline std::ostream& operator<<(std::ostream& output, const string_t& arg)
+{
+  output.write(arg.c_str, arg.length);
+  return output;
+}
diff --git a/libmemcached/options/symbol.h b/libmemcached/options/symbol.h
new file mode 100644 (file)
index 0000000..508dacb
--- /dev/null
@@ -0,0 +1,51 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * 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.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#include <libmemcached/options/string.h>
+#include <libmemcached/options/server.h>
+
+union YYSTYPE
+{
+  long long number;  
+  string_t string;
+  server_t server;
+  double double_number;
+};
+
+typedef union YYSTYPE YYSTYPE;
diff --git a/libmemcached/options/type.h b/libmemcached/options/type.h
new file mode 100644 (file)
index 0000000..aa73acf
--- /dev/null
@@ -0,0 +1,49 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * 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.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#include <libmemcached/memcached.h>
+
+struct type_st
+{
+  void *yyscanner;
+  char *buf;
+  int pos;
+  int length;
+  memcached_st *memc;
+}; 
index 30ff3434359ae28c601d506d2961db1bc5cdcc71..7ef435ff23b329d257b15407fe776cc51aabebd1 100644 (file)
@@ -129,7 +129,7 @@ AC_DEFUN([PANDORA_WARNINGS],[
       m4_if(PW_LESS_WARNINGS,[no],[
         BASE_WARNINGS_FULL="${W_CONVERSION} -Wstrict-aliasing"
         CC_WARNINGS_FULL="-Wswitch-default -Wswitch-enum -Wwrite-strings"
-        CXX_WARNINGS_FULL="-Weffc++ -Wold-style-cast"
+        CXX_WARNINGS_FULL=""
         NO_OLD_STYLE_CAST="-Wno-old-style-cast"
         NO_EFF_CXX="-Wno-effc++"
       ],[