Updated Version status. Updated all command line tools to return error
[awesomized/libmemcached] / src / memcat.c
index 1c9082f55a886a101f60f7517e19de37e0571786..7d2c14db13ca48b3b0d170037b520747d4bea3ab 100644 (file)
@@ -1,9 +1,10 @@
 #include <stdio.h>
+#include <inttypes.h>
+#include <string.h>
 #include <unistd.h>
 #include <getopt.h>
 #include <memcached.h>
 
-#include "client_options.h"
 #include "utilities.h"
 
 #define PROGRAM_NAME "memcat"
@@ -15,14 +16,15 @@ void options_parse(int argc, char *argv[]);
 
 static int opt_verbose= 0;
 static int opt_displayflag= 0;
-static char *opt_servers;
+static char *opt_servers= NULL;
+static char *opt_hash= NULL;
 
 int main(int argc, char *argv[])
 {
   memcached_st *memc;
   char *string;
   size_t string_length;
-  uint16_t flags;
+  uint32_t flags;
   memcached_return rc;
   memcached_server_st *servers;
 
@@ -35,10 +37,14 @@ int main(int argc, char *argv[])
     if ((temp= getenv("MEMCACHED_SERVERS")))
       opt_servers= strdup(temp);
     else
+    {
+      fprintf(stderr, "No Servers provided\n");
       exit(1);
+    }
   }
 
   memc= memcached_create(NULL);
+  process_hash_option(memc, opt_hash);
 
   servers= memcached_servers_parse(opt_servers);
 
@@ -68,15 +74,21 @@ int main(int argc, char *argv[])
     }
     else if (rc != MEMCACHED_NOTFOUND)
     {
-      fprintf(stderr, "memcat: %s: memcache error %s\n", 
+      fprintf(stderr, "memcat: %s: memcache error %s", 
               argv[optind], memcached_strerror(memc, rc));
+      if (memc->cached_errno)
+       fprintf(stderr, " system error %s", strerror(memc->cached_errno));
+      fprintf(stderr, "\n");
     }
     optind++;
   }
 
   memcached_free(memc);
 
-  free(opt_servers);
+  if (opt_servers)
+    free(opt_servers);
+  if (opt_hash)
+    free(opt_hash);
 
   return 0;
 }
@@ -100,6 +112,7 @@ void options_parse(int argc, char *argv[])
       {"debug", no_argument, &opt_verbose, OPT_DEBUG},
       {"servers", required_argument, NULL, OPT_SERVERS},
       {"flag", no_argument, &opt_displayflag, OPT_FLAG},
+      {"hash", required_argument, NULL, OPT_HASH},
       {0, 0, 0, 0},
     };
 
@@ -126,6 +139,9 @@ void options_parse(int argc, char *argv[])
     case OPT_SERVERS: /* --servers or -s */
       opt_servers= strdup(optarg);
       break;
+    case OPT_HASH:
+      opt_hash= strdup(optarg);
+      break;
     case '?':
       /* getopt_long already printed an error message. */
       exit(1);