<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "chplio.h"
#include "chplmem.h"
#include "chplrt.h"
#include "config.h"
#include "error.h"


#define HASHSIZE 101

typedef struct _configVarType { /* table entry */
  char* varName;
  char* moduleName;
  char* defaultValue;
  char* setValue;

  struct _configVarType* nextInBucket;
  struct _configVarType* nextInstalled;
} configVarType;


/* hash table */
static configVarType* configVarTable[HASHSIZE]; 
static configVarType* firstInTable = NULL;
static configVarType* lastInTable = NULL;


typedef struct _argType {
  int isSingleArg;
  char* input;

  struct _argType* next;
} argType;


/* config var list */
static argType* firstArg = NULL;
static argType* lastArg = NULL;

void addToConfigList(char* currentArg, int isSingleArg) {
  char* description = _glom_strings(2, "argument list entry for ", currentArg);
  argType* arg = (argType*) _chpl_calloc(1, sizeof(argType), description);
  _chpl_free(description);

  arg->isSingleArg = isSingleArg;
  arg->input = string_copy(currentArg);
  
  if (firstArg == NULL) {
    firstArg = arg;
  } else {
    lastArg->next = arg;
  }
  lastArg = arg;
}


int askedToParseArgs(void) {
  int answer = 0;
  if (firstArg != NULL) {
    answer = 1;
  }
  return answer;
}


static void parseModVarName(char* modVarName, char** moduleName, 
                            char** varName) {
  char* dot = strrchr(modVarName, '.');
  if (dot) {
    *dot = '\0';
    *moduleName = modVarName;
    *varName = dot + 1;
  } else {
    *moduleName = "";
    *varName = modVarName;
  }
}


/* This function parses a config var of type string, and sets its value in 
   the hash table.  
*/
static int aParsedString(FILE* argFile, char* setConfigBuffer) {
  char* equalsSign = strchr(setConfigBuffer, '=');
  int stringLength = strlen(setConfigBuffer);
  char firstChar;
  char* value;
  char lastChar;
  char* moduleName;
  char* varName;

  if (!equalsSign || !(equalsSign + 1)) {
    return 0;
  }

  firstChar = equalsSign[1];
  if ((firstChar != '"') && (firstChar != '\'')) {
    return 0;
  }

  value = equalsSign + 2;
  *equalsSign = '\0';
  lastChar = setConfigBuffer[stringLength - 1];

  parseModVarName(setConfigBuffer, &moduleName, &varName);
  
  if ((firstChar != lastChar) || (strlen(value) == 0)) {
    char nextChar = fgetc(argFile);
    do {
      switch (nextChar) {
      case EOF:
        {
          char* message = _glom_strings(2, "Found end of file while reading "
                                        "string: ", equalsSign + 1);
          setConfigBuffer[stringLength] = '\0';
          printError(message);
          break;
        }
      case '\n':
        {
          char* message = _glom_strings(2, "Found newline while reading "
                                        "string: ", equalsSign + 1);
          setConfigBuffer[stringLength] = '\0';
          printError(message);
          break;
        }
      default:
        {
          if (stringLength >= _default_string_length - 1) {
            char dsl[1024];
            char* message;
            sprintf(dsl, "%d", _default_string_length);
            message = _glom_strings(2, "String exceeds the maximum "
                                          "string length of ", dsl);<commit_msg>Fixed a small bug in the runtime code that I introduced with my C++ to C changes.<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "chplio.h"
#include "chplmem.h"
#include "chplrt.h"
#include "config.h"
#include "error.h"


#define HASHSIZE 101

typedef struct _configVarType { /* table entry */
  char* varName;
  char* moduleName;
  char* defaultValue;
  char* setValue;

  struct _configVarType* nextInBucket;
  struct _configVarType* nextInstalled;
} configVarType;


/* hash table */
static configVarType* configVarTable[HASHSIZE]; 
static configVarType* firstInTable = NULL;
static configVarType* lastInTable = NULL;


typedef struct _argType {
  int isSingleArg;
  char* input;

  struct _argType* next;
} argType;


/* config var list */
static argType* firstArg = NULL;
static argType* lastArg = NULL;

void addToConfigList(char* currentArg, int isSingleArg) {
  char* description = _glom_strings(2, "argument list entry for ", currentArg);
  argType* arg = (argType*) _chpl_calloc(1, sizeof(argType), description);
  _chpl_free(description);

  arg->isSingleArg = isSingleArg;
  arg->input = string_copy(currentArg);
  
  if (firstArg == NULL) {
    firstArg = arg;
  } else {
    lastArg->next = arg;
  }
  lastArg = arg;
}


int askedToParseArgs(void) {
  int answer = 0;
  if (firstArg != NULL) {
    answer = 1;
  }
  return answer;
}


static void parseModVarName(char* modVarName, char** moduleName, 
                            char** varName) {
  char* dot = strrchr(modVarName, '.');
  if (dot) {
    *dot = '\0';
    *moduleName = modVarName;
    *varName = dot + 1;
  } else {
    *moduleName = "";
    *varName = modVarName;
  }
}


/* This function parses a config var of type string, and sets its value in 
   the hash table.  
*/
static int aParsedString(FILE* argFile, char* setConfigBuffer) {
  char* equalsSign = strchr(setConfigBuffer, '=');
  int stringLength = strlen(setConfigBuffer);
  char firstChar;
  char* value;
  char lastChar;
  char* moduleName;
  char* varName;

  if (!equalsSign || !(equalsSign + 1)) {
    return 0;
  }

  firstChar = equalsSign[1];
  if ((firstChar != '"') && (firstChar != '\'')) {
    return 0;
  }

  value = equalsSign + 2;
  *equalsSign = '\0';
  lastChar = setConfigBuffer[stringLength - 1];

  parseModVarName(setConfigBuffer, &moduleName, &varName);
  
  if ((firstChar != lastChar) || (strlen(value) == 0)) {
    char nextChar = fgetc(argFile);
    do {
      switch (nextChar) {
      case EOF:
        {
          setConfigBuffer[stringLength] = '\0';
          char* message = _glom_strings(2, "Found end of file while reading "
                                        "string: ", equalsSign + 1);
          printError(message);
          break;
        }
      case '\n':
        {
          setConfigBuffer[stringLength] = '\0';
          char* message = _glom_strings(2, "Found newline while reading "
                                        "string: ", equalsSign + 1);
          printError(message);
          break;
        }
      default:
        {
          if (stringLength >= _default_string_length - 1) {
            char dsl[1024];
            char* message;
            sprintf(dsl, "%d", _default_string_length);
            message = _glom_strings(2, "String exceeds the maximum "
                                          "string length of ", dsl);
{'fraction_non_alphanumeric': 0.12267825044937088, 'fraction_numerical': 0.008687837028160575, 'mean_word_length': 2.5667735042735043, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '769312', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2107, 'n_words': 563}