<commit_before>/*
 * Copyright © 2009, 2010 CNRS, INRIA, Université Bordeaux 1
 * Copyright © 2009 Cisco Systems, Inc.  All rights reserved.
 * See COPYING in top-level directory.
 */

#include <private/config.h>
#include <hwloc.h>

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <assert.h>

extern void usage(const char *name, FILE *where);

static __inline void
hwloc_utils_input_format_usage(FILE *where)
{
#ifdef HWLOC_HAVE_XML
  fprintf (where, "   --input <XML file>\n");
  fprintf (where, "   -i <XML file>         Read topology from XML file <path>\n");
#endif
#ifdef HWLOC_LINUX_SYS
  fprintf (where, "   --input <directory>\n");
  fprintf (where, "   -i <directory>        Read topology from chroot containing the /proc and /sys\n"
		  "                         of another system\n");
#endif
  fprintf (where, "   --input \"n:2 2\"\n");
  fprintf (where, "   -i \"n:2 2\"            Simulate a fake hierarchy, here with 2 NUMA nodes of 2\n"
                  "                         processors\n");
  fprintf (where, "   --input-format <format>\n");
  fprintf (where, "   --if <format>         Enforce input format among "
#ifdef HWLOC_HAVE_XML
	   "xml, "
#endif
#ifdef HWLOC_LINUX_SYS
	   "fsroot, "
#endif
	   "synthetic\n");
}

enum hwloc_utils_input_format {
  HWLOC_UTILS_INPUT_DEFAULT,
  HWLOC_UTILS_INPUT_XML,
  HWLOC_UTILS_INPUT_FSROOT,
  HWLOC_UTILS_INPUT_SYNTHETIC
};

static __inline enum hwloc_utils_input_format
hwloc_utils_parse_input_format(const char *name, const char *callname)
{
  if (!strncasecmp(name, "default", 3))
    return HWLOC_UTILS_INPUT_DEFAULT;
  else if (!strncasecmp(name, "xml", 1))
    return HWLOC_UTILS_INPUT_XML;
  else if (!strncasecmp(name, "fsroot", 1))
    return HWLOC_UTILS_INPUT_FSROOT;
  else if (!strncasecmp(name, "synthetic", 1))
    return HWLOC_UTILS_INPUT_SYNTHETIC;

  fprintf(stderr, "input format `%s' not supported\n", name);
  usage(callname, stderr);
  exit(EXIT_FAILURE);
}

static __inline int
hwloc_utils_lookup_input_option(char *argv[], int argc, int *consumed_opts,
				char **inputp, enum hwloc_utils_input_format *input_formatp,
				const char *callname)
{
  if (!strcmp (argv[0], "--input")
	       || !strcmp (argv[0], "-i")) {
    if (argc <= 1) {
      usage (callname, stderr);
      exit(EXIT_FAILURE);
    }
    *inputp = argv[1];
    *consumed_opts = 1;
    return 1;
  }
  else if (!strcmp (argv[0], "--input-format")
	   || !strcmp (argv[0], "--if")) {
    if (argc <= 1) {
      usage (callname, stderr);
      exit(EXIT_FAILURE);
    }
    *input_formatp = hwloc_utils_parse_input_format (argv[1], callname);
    *consumed_opts = 1;
    return 1;
  }

  /* backward compat with 1.0 */
  else if (!strcmp (argv[0], "--synthetic")) {
    if (argc <= 1) {
      usage (callname, stderr);
      exit(EXIT_FAILURE);
    }
    *inputp = argv[1];
    *input_formatp = HWLOC_UTILS_INPUT_SYNTHETIC;<commit_msg>utils: if -i gets an empty input name, reset to NULL<commit_after>/*
 * Copyright © 2009, 2010 CNRS, INRIA, Université Bordeaux 1
 * Copyright © 2009 Cisco Systems, Inc.  All rights reserved.
 * See COPYING in top-level directory.
 */

#include <private/config.h>
#include <hwloc.h>

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <assert.h>

extern void usage(const char *name, FILE *where);

static __inline void
hwloc_utils_input_format_usage(FILE *where)
{
#ifdef HWLOC_HAVE_XML
  fprintf (where, "   --input <XML file>\n");
  fprintf (where, "   -i <XML file>         Read topology from XML file <path>\n");
#endif
#ifdef HWLOC_LINUX_SYS
  fprintf (where, "   --input <directory>\n");
  fprintf (where, "   -i <directory>        Read topology from chroot containing the /proc and /sys\n"
		  "                         of another system\n");
#endif
  fprintf (where, "   --input \"n:2 2\"\n");
  fprintf (where, "   -i \"n:2 2\"            Simulate a fake hierarchy, here with 2 NUMA nodes of 2\n"
                  "                         processors\n");
  fprintf (where, "   --input-format <format>\n");
  fprintf (where, "   --if <format>         Enforce input format among "
#ifdef HWLOC_HAVE_XML
	   "xml, "
#endif
#ifdef HWLOC_LINUX_SYS
	   "fsroot, "
#endif
	   "synthetic\n");
}

enum hwloc_utils_input_format {
  HWLOC_UTILS_INPUT_DEFAULT,
  HWLOC_UTILS_INPUT_XML,
  HWLOC_UTILS_INPUT_FSROOT,
  HWLOC_UTILS_INPUT_SYNTHETIC
};

static __inline enum hwloc_utils_input_format
hwloc_utils_parse_input_format(const char *name, const char *callname)
{
  if (!strncasecmp(name, "default", 3))
    return HWLOC_UTILS_INPUT_DEFAULT;
  else if (!strncasecmp(name, "xml", 1))
    return HWLOC_UTILS_INPUT_XML;
  else if (!strncasecmp(name, "fsroot", 1))
    return HWLOC_UTILS_INPUT_FSROOT;
  else if (!strncasecmp(name, "synthetic", 1))
    return HWLOC_UTILS_INPUT_SYNTHETIC;

  fprintf(stderr, "input format `%s' not supported\n", name);
  usage(callname, stderr);
  exit(EXIT_FAILURE);
}

static __inline int
hwloc_utils_lookup_input_option(char *argv[], int argc, int *consumed_opts,
				char **inputp, enum hwloc_utils_input_format *input_formatp,
				const char *callname)
{
  if (!strcmp (argv[0], "--input")
	       || !strcmp (argv[0], "-i")) {
    if (argc <= 1) {
      usage (callname, stderr);
      exit(EXIT_FAILURE);
    }
    if (strlen(argv[1]))
      *inputp = argv[1];
    else
      *inputp = NULL;
    *consumed_opts = 1;
    return 1;
  }
  else if (!strcmp (argv[0], "--input-format")
	   || !strcmp (argv[0], "--if")) {
    if (argc <= 1) {
      usage (callname, stderr);
      exit(EXIT_FAILURE);
    }
    *input_formatp = hwloc_utils_parse_input_format (argv[1], callname);
    *consumed_opts = 1;
    return 1;
  }

  /* backward compat with 1.0 */
  else if (!strcmp (argv[0], "--synthetic")) {
    if (argc <= 1) {
      usage (callname, stderr);
      exit(EXIT_FAILURE);
    }
    *inputp = argv[1];
    *input_formatp = HWLOC_UTILS_INPUT_SYNTHETIC;
{'fraction_non_alphanumeric': 0.13775766716943189, 'fraction_numerical': 0.013574660633484163, 'mean_word_length': 3.1734265734265734, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '290857', 'n_tokens_mistral': 2277, 'n_tokens_neox': 2192, 'n_words': 550}