<commit_before>#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <memcached.h>
#include "client_options.h"

static int opt_verbose;
static int opt_displayflag;
static char *opt_servers;

struct memcached_st *parse_opt_servers (struct memcached_st *m,
					char *opt_servers)
{
  char *s, *hostname;
  unsigned int portnum;
  while (s = strsep(&opt_servers, ",")) {
    hostname = strsep(&s, ":");
    portnum = atoi(s);
    memcached_server_add(m, hostname, portnum);
  }
  return m;
}

int main(int argc, char *argv[])
{
  memcached_st *memc;
  char *string;
  size_t string_length;
  uint16_t  flags;
  memcached_return rc;
  unsigned int x;

  static struct option long_options[] =
    {
      {"version", no_argument, NULL, OPT_VERSION},
      {"help", no_argument, NULL, OPT_HELP},
      {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
      {"debug", no_argument, &opt_verbose, OPT_DEBUG},
      {"servers", required_argument, NULL, OPT_SERVERS},
      {"flag", no_argument, &opt_displayflag, OPT_FLAG},
      {0, 0, 0, 0},
    };
  int option_index = 0;
  int option_rv;

  while (1) 
  {
    option_rv = getopt_long(argc, argv, "", long_options, &option_index);
    if (option_rv == -1) break;
    switch (option_rv) {
    case 0:
      break;
    case OPT_VERSION: /* --version */
      printf("memcache tools, memcat, v1.0\n");
      exit(0);
      break;
    case OPT_HELP: /* --help */
      printf("useful help messages go here\n");
      exit(0);
      break;
    case OPT_SERVERS: /* --servers */
      opt_servers = strdup(optarg);
      break;
    case '?':
      /* getopt_long already printed an error message. */
      exit(1);
    default:
      abort();
    }
  }

  memc = malloc(sizeof(struct memcached_st));
  memcached_init(memc);
  memc= parse_opt_servers(memc, opt_servers);
  memc= memcached_init(memc);

  for (x= 1; x < argc; x++)
  {
    string= memcached_get(memc, argv[x], strlen(argv[x]),
                          &string_length, &flags, &rc);
    if (string) 
    {
      printf("%.*s\n", string_length, string);
      free(string);
    }
  }

  memcached_deinit(memc);

  return 0;
};<commit_msg>implement --flags for memcat, display flags instead of content<commit_after>#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <memcached.h>
#include "client_options.h"

static int opt_verbose;
static int opt_displayflag;
static char *opt_servers;

struct memcached_st *parse_opt_servers (struct memcached_st *m,
					char *opt_servers)
{
  char *s, *hostname;
  unsigned int portnum;
  while (s = strsep(&opt_servers, ",")) {
    hostname = strsep(&s, ":");
    portnum = atoi(s);
    memcached_server_add(m, hostname, portnum);
  }
  return m;
}

int main(int argc, char *argv[])
{
  memcached_st *memc;
  char *string;
  size_t string_length;
  uint16_t  flags;
  memcached_return rc;
  unsigned int x;

  static struct option long_options[] =
    {
      {"version", no_argument, NULL, OPT_VERSION},
      {"help", no_argument, NULL, OPT_HELP},
      {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
      {"debug", no_argument, &opt_verbose, OPT_DEBUG},
      {"servers", required_argument, NULL, OPT_SERVERS},
      {"flag", no_argument, &opt_displayflag, OPT_FLAG},
      {0, 0, 0, 0},
    };
  int option_index = 0;
  int option_rv;

  while (1) 
  {
    option_rv = getopt_long(argc, argv, "", long_options, &option_index);
    if (option_rv == -1) break;
    switch (option_rv) {
    case 0:
      break;
    case OPT_VERSION: /* --version */
      printf("memcache tools, memcat, v1.0\n");
      exit(0);
      break;
    case OPT_HELP: /* --help */
      printf("useful help messages go here\n");
      exit(0);
      break;
    case OPT_SERVERS: /* --servers */
      opt_servers = strdup(optarg);
      break;
    case '?':
      /* getopt_long already printed an error message. */
      exit(1);
    default:
      abort();
    }
  }

  memc = malloc(sizeof(struct memcached_st));
  memcached_init(memc);
  memc= parse_opt_servers(memc, opt_servers);
  memc= memcached_init(memc);

  for (x= 1; x < argc; x++)
  {
    string= memcached_get(memc, argv[x], strlen(argv[x]),
                          &string_length, &flags, &rc);
    if (rc == MEMCACHED_SUCCESS) {
      if (opt_displayflag) {
	printf("%d\n", flags);
      } else {
	if (string) 
	{
	  printf("%.*s\n", string_length, string);
	  free(string);
	}
      }
    }
  }

  memcached_deinit(memc);

  return 0;
};
{'fraction_non_alphanumeric': 0.1458006718924972, 'fraction_numerical': 0.00761478163493841, 'mean_word_length': 2.976847729296527, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2676349', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1619, 'n_words': 380}