Exemplo n.º 1
0
static UTOX_SAVE *utox_load_config(void) {
    UTOX_SAVE *save = calloc(1, sizeof(UTOX_SAVE) + proxy_address_size + 1);

    if (!save) {
        LOG_ERR("Settings", "Unable to calloc for UTOX_SAVE.");
        return NULL;
    }

    char *config_path = utox_get_filepath(config_file_name);

    if (!config_path) {
        LOG_ERR("Settings", "Unable to get %s path.", config_file_name);
        free(save);
        return NULL;
    }

    if (!ini_browse(config_parser, save, config_path)) {
        LOG_ERR("Settings", "Unable to parse %s.", config_file_name);
        free(config_path);
        free(save);
        return NULL;
    }

    free(config_path);

    return save;
}
Exemplo n.º 2
0
int sp_init() {
	if ((sp_config.status == SP_ERROR)) {
		return 0;
	}
	/* read config. files and fill sp_config */
	ini_browse(IniCallback, NULL, SP_CONFFILE);
	if (param_count < MANDATORY_PARAMS_NUMBER) {
		error ("sp_init: missing config file or missing mandatory parameter in configfile");
		sp_config.status = SP_ERROR;
		return 0;
	}
	sp_config.status = SP_INITED;
	return 1;
}
Exemplo n.º 3
0
bool RBConfig::initialize(std::string configFile)
{
	instance();
	_cfg->config.clear();
	trickster = &_cfg->config;

	if (0 == ini_browse((INI_CALLBACK)addToDictionary, NULL, configFile.c_str()))
		return false;

	//Will crash if a string doesn't appear!
	version    = _cfg->gets("GameVersion");
	tilesize   = _cfg->geti("TileSize");
	msperframe = _cfg->geti("MSPerFrame");
	magic = _cfg->getb("Magic");
	continuous_input = _cfg->getb("ContinuousInput");

	return true;
}
Exemplo n.º 4
0
int main(void)
{
  char str[100];
  long n;
  int s, k;
  char section[50];

  /* string reading */
  n = ini_gets("first", "string", "dummy", str, sizearray(str), inifile);
  assert(n==4 && strcmp(str,"noot")==0);
  n = ini_gets("second", "string", "dummy", str, sizearray(str), inifile);
  assert(n==4 && strcmp(str,"mies")==0);
  n = ini_gets("first", "undefined", "dummy", str, sizearray(str), inifile);
  assert(n==5 && strcmp(str,"dummy")==0);
  /* ----- */
  n = ini_gets("", "string", "dummy", str, sizearray(str), inifile2);
  assert(n==4 && strcmp(str,"noot")==0);
  n = ini_gets(NULL, "string", "dummy", str, sizearray(str), inifile2);
  assert(n==4 && strcmp(str,"noot")==0);
  /* ----- */
  printf("1. String reading tests passed\n");

  /* value reading */
  n = ini_getl("first", "val", -1, inifile);
  assert(n==1);
  n = ini_getl("second", "val", -1, inifile);
  assert(n==2);
  n = ini_getl("first", "undefined", -1, inifile);
  assert(n==-1);
  /* ----- */
  n = ini_getl(NULL, "val", -1, inifile2);
  assert(n==1);
  /* ----- */
  printf("2. Value reading tests passed\n");

  /* string writing */
  n = ini_puts("first", "alt", "flagged as \"correct\"", inifile);
  assert(n==1);
  n = ini_gets("first", "alt", "dummy", str, sizearray(str), inifile);
  assert(n==20 && strcmp(str,"flagged as \"correct\"")==0);
  /* ----- */
  n = ini_puts("second", "alt", "correct", inifile);
  assert(n==1);
  n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
  assert(n==7 && strcmp(str,"correct")==0);
  /* ----- */
  n = ini_puts("third", "test", "correct", inifile);
  assert(n==1);
  n = ini_gets("third", "test", "dummy", str, sizearray(str), inifile);
  assert(n==7 && strcmp(str,"correct")==0);
  /* ----- */
  n = ini_puts("second", "alt", "overwrite", inifile);
  assert(n==1);
  n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
  assert(n==9 && strcmp(str,"overwrite")==0);
  /* ----- */
  n = ini_puts(NULL, "alt", "correct", inifile2);
  assert(n==1);
  n = ini_gets(NULL, "alt", "dummy", str, sizearray(str), inifile2);
  assert(n==7 && strcmp(str,"correct")==0);
  /* ----- */
  printf("3. String writing tests passed\n");

  /* section/key enumeration */
  printf("4. Section/key enumertion, file contents follows\n");
  for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) {
    printf("    [%s]\n", section);
    for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) {
      printf("\t%s\n", str);
    } /* for */
  } /* for */

  /* browsing through the file */
  printf("5. browse through all settings, file contents follows\n");
  ini_browse(Callback, NULL, inifile);

  /* string deletion */
  n = ini_puts("first", "alt", NULL, inifile);
  assert(n==1);
  n = ini_puts("second", "alt", NULL, inifile);
  assert(n==1);
  n = ini_puts("third", NULL, NULL, inifile);
  assert(n==1);
  /* ----- */
  n = ini_puts(NULL, "alt", NULL, inifile2);
  assert(n==1);
  printf("6. String deletion tests passed\n");

  return 0;
}
Exemplo n.º 5
0
int main (int argc, char *argv[]) {
  char databuf[BUFFER_SIZE];
  char *section, *name, *inifn;
  int nBoolValue = FALSE, bFlagBool = FALSE, bFlagDump = FALSE;
  int firstArgIndex = 1;
  char* const DEFAULT_VALUE = "";

  application_init(argc, argv, arg_c, arg_v, &databuf, BUFFER_SIZE);

  if (argc <= 1) {
    show_error(STR_ERR_NOT_ENOUGH_ARGS);
    return show_usage( THIS_APP_FILENAME );
  }

  bFlagBool = (check_arg_flag_bool(1) ? TRUE : FALSE);
  bFlagDump = (check_arg_flag(1, FLAG_DUMP) ? TRUE : FALSE);

  if (argc == 2) {
    if (bFlagBool==TRUE)
      return show_error(STR_ERR_NOT_ENOUGH_ARGS);
    if (bFlagDump)
      return show_error(STR_ERR_NO_FILE_NAME);

    if (check_arg_flag(1, FLAG_VERSION))
      return show_version(APP_TITLE, INI_TOOLS_VERSION);

    if (check_arg_flag(1, FLAG_HELP))
      return show_help( THIS_APP_FILENAME );
  }


  firstArgIndex = 1;  //first arg is index 1,
  if (bFlagBool || bFlagDump)
    firstArgIndex++;  //unless -b|-d is passed

  //--- start dump file processing ---
  if (bFlagDump) {
    inifn   = argv[firstArgIndex];
    if (strcmp(inifn, "-")==0)
      inifn = "/dev/stdin";
    if (!file_exist(inifn))
      return show_error(STR_ERR_FILE_NOT_FOUND);
    if (!file_readable(inifn))
      return show_error_fmt(STR_ERR_FMT_FILE_NOT_READABLE, basename(inifn));

    char * sectionName = NULL;
    if (argc == 4) {
      sectionName = argv[3];
      if (!ini_section_exists(inifn, sectionName))
        return show_error_fmt(STR_ERR_FMT_SECTION_NOT_FOUND, sectionName);
    }

    //dump either the entire ini file or specified [section] keys
    ini_browse(browsecb, sectionName, inifn);
    if (lastSection!="")
      free(lastSection);
    return EXIT_SUCCESS;
  }
  //--- end dump file processing ---


  // --- start error checking ---
  if (argc <= firstArgIndex)
    return show_error(STR_ERR_NO_SECTION_NAME);
  if (argc <= firstArgIndex+1)
    return show_error(STR_ERR_NO_KEY_NAME);
  if (argc <= firstArgIndex+2)
    return show_error(STR_ERR_NO_FILE_NAME);
  // --- end error checking ---

  section = argv[firstArgIndex+0];
  name    = argv[firstArgIndex+1];
  inifn   = argv[firstArgIndex+2];
  if (strcmp(inifn, "-")==0)
    inifn = "/dev/stdin";

  // -- start sanity checking --
  if (!file_exist(inifn))
    return show_error(STR_ERR_FILE_NOT_FOUND);

  if ((file_exist(inifn) && !file_readable(inifn)) )
    return show_error_fmt(STR_ERR_FMT_FILE_NOT_READABLE, basename(inifn));

  if (!valid_section_name(section))
    return show_error(STR_ERR_INVALID_SECTION_NAME);

  if (!valid_key_name(name))
    return show_error(STR_ERR_INVALID_KEY_NAME);
  // -- end sanity checking --

  ini_gets(section, name, DEFAULT_VALUE, databuf, sizeof(databuf), inifn);

  if (bFlagBool) {
    nBoolValue = FALSE; //default value
    if (is_bool_str_true(databuf))
      nBoolValue = TRUE;
    if (is_bool_str_false(databuf))
      nBoolValue = FALSE;
    sprintf(databuf,"%d", nBoolValue);
  }

  printf("%s", databuf);
  return EXIT_SUCCESS;
}
Exemplo n.º 6
0
int TestMiniIni(void) {
  char str[100];
  long n;
  int s, k;
  char section[50];

  /* string reading */
  n = ini_gets("first", "string", "dummy", str, sizearray(str), inifile);
  Check(n==4 && UTIL1_strcmp(str,"noot")==0);
  n = ini_gets("second", "string", "dummy", str, sizearray(str), inifile);
  Check(n==4 && UTIL1_strcmp(str,"mies")==0);
  n = ini_gets("first", "undefined", "dummy", str, sizearray(str), inifile);
  Check(n==5 && UTIL1_strcmp(str,"dummy")==0);
  /* ----- */
  n = ini_gets("", "string", "dummy", str, sizearray(str), inifile2);
  Check(n==4 && UTIL1_strcmp(str,"noot")==0);
  n = ini_gets(NULL, "string", "dummy", str, sizearray(str), inifile2);
  Check(n==4 && UTIL1_strcmp(str,"noot")==0);
  /* ----- */
  SHELL_SendString((unsigned char*)"1. String reading tests passed\n");

  /* value reading */
  n = ini_getl("first", "val", -1, inifile);
  Check(n==1);
  n = ini_getl("second", "val", -1, inifile);
  Check(n==2);
  n = ini_getl("first", "undefined", -1, inifile);
  Check(n==-1);
  /* ----- */
  n = ini_getl(NULL, "val", -1, inifile2);
  Check(n==1);
  /* ----- */
  SHELL_SendString((unsigned char*)"2. Value reading tests passed\n");

  /* string writing */
  n = ini_puts("first", "alt", "flagged as \"correct\"", inifile);
  Check(n==1);
  n = ini_gets("first", "alt", "dummy", str, sizearray(str), inifile);
  Check(n==20 && UTIL1_strcmp(str,"flagged as \"correct\"")==0);
  /* ----- */
  n = ini_puts("second", "alt", "correct", inifile);
  Check(n==1);
  n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
  Check(n==7 && UTIL1_strcmp(str,"correct")==0);
  /* ----- */
  n = ini_puts("third", "test", "correct", inifile);
  Check(n==1);
  n = ini_gets("third", "test", "dummy", str, sizearray(str), inifile);
  Check(n==7 && UTIL1_strcmp(str,"correct")==0);
  /* ----- */
  n = ini_puts("second", "alt", "overwrite", inifile);
  Check(n==1);
  n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
  Check(n==9 && UTIL1_strcmp(str,"overwrite")==0);
  /* ----- */
  n = ini_puts(NULL, "alt", "correct", inifile2);
  Check(n==1);
  n = ini_gets(NULL, "alt", "dummy", str, sizearray(str), inifile2);
  Check(n==7 && UTIL1_strcmp(str,"correct")==0);
  /* ----- */
  SHELL_SendString((unsigned char*)"3. String writing tests passed\n");

  /* section/key enumeration */
  SHELL_SendString((unsigned char*)"4. Section/key enumeration, file contents follows\n");
  for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) {
    SHELL_SendString((unsigned char*)"    [");
    SHELL_SendString((unsigned char*)section);
    SHELL_SendString((unsigned char*)"]\r\n");
    for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) {
      SHELL_SendString((unsigned char*)"\t");
      SHELL_SendString((unsigned char*)str);
      SHELL_SendString((unsigned char*)"\r\n");
    } /* for */
  } /* for */

  /* browsing through the file */
  SHELL_SendString((unsigned char*)"5. browse through all settings, file contents follows\n");
  ini_browse(Callback, NULL, inifile);

  /* string deletion */
  n = ini_puts("first", "alt", NULL, inifile);
  Check(n==1);
  n = ini_puts("second", "alt", NULL, inifile);
  Check(n==1);
  n = ini_puts("third", NULL, NULL, inifile);
  Check(n==1);
  /* ----- */
  n = ini_puts(NULL, "alt", NULL, inifile2);
  Check(n==1);
  SHELL_SendString((unsigned char*)"6. String deletion tests passed\n");

  return 0;
}