<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <string.h>
#include <stdarg.h>

#include <dlfcn.h>
#include <syslog.h>
#include <sys/types.h>
#include <unistd.h>

#include <checksum.h>
#include <proc_info.h>

#define EXPORT __attribute__((visibility("default")))

// Runtime options
static int debug = 0;
static int max_errors = 10;
static int print_to_syslog = 0;

// Other pieces of state
static int init_done = 0;
static ProcMap *maps = 0;
static char *proc_name = 0;
static char *proc_cmdline = 0;
static size_t nmaps = 0;
static int num_errors = 0;
static long proc_pid = -1;


static void fini() {
  if(maps)
    free(maps);
  if(proc_cmdline)
    free(proc_cmdline);
  if(proc_name)
    free(proc_name);
}

static void init() {
  const char *opts;
  if((opts = getenv("SORTCHECK_OPTIONS"))) {
    char *opts_ = strdup(opts);

    char *cur;
    for(cur = opts_; *cur; ) {
      // SORTCHECK_OPTIONS is a colon-separated list of assignments

      const char *name = cur;

      char *assign = strchr(cur, '=');
      if(!assign)
        break;
      *assign = 0;

      char *value = assign + 1;

      char *end = strchr(value, ':');
      if(end)
        *end = 0;
      cur = end ? end + 1 : value + strlen(value);

      if(0 == strcmp(name, "debug")) {
        debug = atoi(value);
      } else if(0 == strcmp(name, "print_to_syslog")) {
        print_to_syslog = atoi(value);;
	openlog("", 0, LOG_USER);
      } else if(0 == strcmp(name, "max_errors")) {
        max_errors = atoi(value);
      } else {
        fprintf(stderr, "sortcheck: unknown option '%s'\n", name);<commit_msg>Die on invalid options.<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <string.h>
#include <stdarg.h>

#include <dlfcn.h>
#include <syslog.h>
#include <sys/types.h>
#include <unistd.h>

#include <checksum.h>
#include <proc_info.h>

#define EXPORT __attribute__((visibility("default")))

// Runtime options
static int debug = 0;
static int max_errors = 10;
static int print_to_syslog = 0;

// Other pieces of state
static int init_done = 0;
static ProcMap *maps = 0;
static char *proc_name = 0;
static char *proc_cmdline = 0;
static size_t nmaps = 0;
static int num_errors = 0;
static long proc_pid = -1;

static void fini() {
  if(maps)
    free(maps);
  if(proc_cmdline)
    free(proc_cmdline);
  if(proc_name)
    free(proc_name);
}

static void init() {
  const char *opts;
  if((opts = getenv("SORTCHECK_OPTIONS"))) {
    char *opts_ = strdup(opts);

    char *cur;
    for(cur = opts_; *cur; ) {
      // SORTCHECK_OPTIONS is a colon-separated list of assignments

      const char *name = cur;

      char *assign = strchr(cur, '=');
      if(!assign) {
        fprintf(stderr, "sortcheck: missing '=' in '%s'\n", cur);
        exit(1);
      }
      *assign = 0;

      char *value = assign + 1;

      char *end = strchr(value, ':');
      if(end)
        *end = 0;
      cur = end ? end + 1 : value + strlen(value);

      if(0 == strcmp(name, "debug")) {
        debug = atoi(value);
      } else if(0 == strcmp(name, "print_to_syslog")) {
        print_to_syslog = atoi(value);;
	openlog("", 0, LOG_USER);
      } else if(0 == strcmp(name, "max_errors")) {
        max_errors = atoi(value);
      } else {
        fprintf(stderr, "sortcheck: unknown option '%s'\n", name);
{'fraction_non_alphanumeric': 0.15411868910540302, 'fraction_numerical': 0.011514614703277236, 'mean_word_length': 3.0526315789473686, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '1155111', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1227, 'n_words': 326}