Example #1
0
int main(void)
{
	cfg_t *acfg, *bcfg;
	cfg_t *sec;

	acfg = create_config();
	fail_unless(cfg_parse(acfg, SRC_DIR "/a.conf") == 0);

	bcfg = create_config();
	fail_unless(cfg_parse(bcfg, SRC_DIR "/b.conf") == 0);

	sec = cfg_getnsec(acfg, "sec", 0);
	fail_unless(sec != 0);
	fail_unless(cfg_size(acfg, "sec") == 1);
	fail_unless(strcmp(cfg_title(sec), "acfg") == 0);
	fail_unless(cfg_getint(sec, "a") == 5);
	fail_unless(cfg_getint(sec, "b") == 2);

	sec = cfg_getnsec(bcfg, "sec", 0);
	fail_unless(sec != 0);
	fail_unless(cfg_size(bcfg, "sec") == 1);
	fail_unless(strcmp(cfg_title(sec), "bcfg") == 0);
	fail_unless(cfg_getint(sec, "a") == 1);
	fail_unless(cfg_getint(sec, "b") == 9);

	cfg_free(acfg);
	cfg_free(bcfg);

	return 0;
}
Example #2
0
File: conf.c Project: leevon/rhizel
static struct cfg_obj *create_obj(struct cfg_section *sec_head, char *name, char *value)
{
    struct cfg_obj *p = calloc(1, sizeof(struct cfg_obj));

    if (p == NULL)
    {
        cfg_free(sec_head);

        return NULL;
    }

    if ((p->name = strdup(name)) == NULL)
    {
        cfg_free(sec_head);

        return NULL;
    }

    if ((p->value = strdup(value)) == NULL)
    {
        cfg_free(sec_head);

        return NULL;
    }

    return p;
}
Example #3
0
int main(void)
{
	FILE *fp;
	char *param;
	cfg_t *cfg = cfg_init(opts, CFGF_NONE);

	fail_unless(cfg);

	/* set a string parameter to a string including a quote character
	 */
	cfg_setstr(cfg, "parameter", "text \" with quotes and \\");

	/* print the config to a temporary file
	 */
	fp = tmpfile();
	fail_unless(fp);
	cfg_print(cfg, fp);
	cfg_free(cfg);

	/* read it back, we expect 'parameter' to include a quote character
	 */
	rewind(fp);
	cfg = cfg_init(opts, CFGF_NONE);
	fail_unless(cfg);
	fail_unless(cfg_parse_fp(cfg, fp) == CFG_SUCCESS);
	fail_unless(fclose(fp) == 0);

	param = cfg_getstr(cfg, "parameter");
	fail_unless(param);

	fail_unless(strcmp(param, "text \" with quotes and \\") == 0);
	cfg_free(cfg);

	return 0;
}
Example #4
0
/* initiate configuration reload */
void
main_loop_reload_config_initiate(void)
{
  if (main_loop_is_terminating())
    return;

  service_management_publish_status("Reloading configuration");

  if (main_loop_new_config)
    {
      /* This block is entered only if this function is reentered before
       * main_loop_reload_config_apply() would be called.  In that case we
       * drop the previously parsed configuration and start over again to
       * ensure that the contents of the running configuration matches the
       * contents of the file at the time the SIGHUP signal was received.
       */
      cfg_free(main_loop_new_config);
      main_loop_new_config = NULL;
    }

  main_loop_old_config = current_configuration;
  app_pre_config_loaded();
  main_loop_new_config = cfg_new(0);
  if (!cfg_read_config(main_loop_new_config, resolvedConfigurablePaths.cfgfilename, FALSE, NULL))
    {
      cfg_free(main_loop_new_config);
      main_loop_new_config = NULL;
      main_loop_old_config = NULL;
      msg_error("Error parsing configuration",
                evt_tag_str(EVT_TAG_FILENAME, resolvedConfigurablePaths.cfgfilename));
      service_management_publish_status("Error parsing new configuration, using the old config");
      return;
    }
  main_loop_worker_sync_call(main_loop_reload_config_apply);
}
Example #5
0
/* called to apply the new configuration once all I/O worker threads have finished */
static void
main_loop_reload_config_apply(void)
{
  if (main_loop_is_terminating())
    {
      if (main_loop_new_config)
        {
          cfg_free(main_loop_new_config);
          main_loop_new_config = NULL;
        }
      return;
    }
  main_loop_old_config->persist = persist_config_new();
  cfg_deinit(main_loop_old_config);
  cfg_persist_config_move(main_loop_old_config, main_loop_new_config);

  if (cfg_init(main_loop_new_config))
    {
      msg_verbose("New configuration initialized");
      persist_config_free(main_loop_new_config->persist);
      main_loop_new_config->persist = NULL;
      cfg_free(main_loop_old_config);
      current_configuration = main_loop_new_config;
      service_management_clear_status();
    }
  else
    {
      msg_error("Error initializing new configuration, reverting to old config");
      service_management_publish_status("Error initializing new configuration, using the old config");
      cfg_persist_config_move(main_loop_new_config, main_loop_old_config);
      cfg_deinit(main_loop_new_config);
      if (!cfg_init(main_loop_old_config))
        {
          /* hmm. hmmm, error reinitializing old configuration, we're hosed.
           * Best is to kill ourselves in the hope that the supervisor
           * restarts us.
           */
          kill(getpid(), SIGQUIT);
          g_assert_not_reached();
        }
      persist_config_free(main_loop_old_config->persist);
      main_loop_old_config->persist = NULL;
      cfg_free(main_loop_new_config);
      current_configuration = main_loop_old_config;
      goto finish;
    }

  /* this is already running with the new config in place */
  app_post_config_loaded();
  msg_notice("Configuration reload request received, reloading configuration");

 finish:
  main_loop_new_config = NULL;
  main_loop_old_config = NULL;

  return;
}
Example #6
0
/*
* Destructor
*/
Settings::~Settings(void) {
	TelldusCore::MutexLocker locker(&mutex);
	if (d->cfg > 0) {
		cfg_free(d->cfg);
	}
	if (d->var_cfg > 0) {
		cfg_free(d->var_cfg);
	}
	delete d;
}
Example #7
0
RBTree *import_database()
{
  ProgressPtr process_file;
  FilePathList *list;
  char path[80];
  RBTree *tree;
  
  tree = malloc(sizeof(RBTree));
  list = malloc(sizeof(FilePathList));
  
  // For each file indicated by the file specified by argument, it will parse
  // its content, searching for words, and it will store them in the global
  // structure.
  process_file = ^(FilePathItem *item, int total_files){
      HashList hl;
      int result;

      printf("Reading file [%s] with id [%d/%d]\n", item->path, item->id + 1, total_files);
      
      hl_initialize(&hl, HASH_LIST_SIZE);
      
      result = create_local_structure(&hl, item->path);
      if ( result == 0 )
      {
          update_global_structure(tree, &hl, item->id);
          hl_free(&hl);
      }
  };
  
  cfg_init(list);

  printf("Mode multifil\n");

  printf("Nom del fitxer de configuraciĆ³: ");
  scanf("%s", path);
  flush();
  
  cfg_import_config(path, list);
  //cfg_print(list);

  if ( list->size == 0 )
  {
    cfg_free(list);
    free(tree);
    return NULL;
  }

  initTree(tree, list->size);
  cfg_mt_iterate(list, process_file, 32);
  
  cfg_free(list);

  return tree;
}
Example #8
0
BOOL saveConfFile(user_input_data *user_dat)
{
    FILE *U2Mconf_file = fopen(cfg_filename, "w");

    if (!U2Mconf_file) return FALSE;

    cfg_opt_t email_opts[] = {
        CFG_STR("From", user_dat->FROM, CFGF_NONE),
        CFG_STR("To", user_dat->TO, CFGF_NONE),
        CFG_STR("Cc", user_dat->CC, CFGF_NONE),
        CFG_STR("Subject", user_dat->SUBJECT, CFGF_NONE),
        CFG_STR("Body", user_dat->BODY, CFGF_NONE),
        CFG_STR("Password", user_dat->pass, CFGF_NONE),
        CFG_STR("SMTP_server", user_dat->SMTP_SERVER, CFGF_NONE),
        CFG_INT("Port_number", (int)user_dat->PORT, CFGF_NONE),
        CFG_END()
    };

    cfg_t *U2MConf = cfg_init(email_opts, CFGF_NONE);
    cfg_print(U2MConf, U2Mconf_file);

    fclose(U2Mconf_file);
    cfg_free(U2MConf);

    return TRUE;
}
Example #9
0
static struct cfg *cfg_parse(const struct cfg_string *str, size_t *current, enum cfg_status *status) 
{
    struct cfg *cfg=NULL;
    //int beg_found=0;

    struct cfg_field *field=NULL;
    size_t end=0;
    if (!str) {
        *status = CFG_READ_ERROR;
        goto _cfg_parse_bail;
    }

    // beginning { is optional for overall config, but not sub-configs
    if (CFG_CFG_BEG == str->data[*current]) {
        (*current) += 1;
    }
    cfg = cfg_new();
    while (1) {
        *current = find_nonwhite(str, *current, status);
        if (*status) { // EOF OK here
            *status=CFG_SUCCESS;
            break;
        }
        if (str->data[*current] == CFG_CFG_END) {
            break;
        }

        field=cfg_get_field(str, (*current), &end, status);
        if (CFG_FOUND_END == (*status)) {
            // just found end of config, break out
            *status=CFG_SUCCESS;
            break;
        }
        if (*status) {
            // an error occured
            break;
        }
        if (!field) {
            // probably natural end of file found
            break;
        }


        cfg_append(cfg,field);

        if (str->data[end] == CFG_CFG_END) {
            *current = end;
            break;
        }

        // skip past either the last letter, end quote, end array delim, etc.
        (*current) = end+1;
    }

_cfg_parse_bail:
    if (*status) {
        cfg=cfg_free(cfg);
    }
    return cfg;
};
Example #10
0
int main(void)
{
	static cfg_opt_t section_opts[] = {
		CFG_STR("prop", 0, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_SEC("section", section_opts, CFGF_TITLE | CFGF_MULTI),
		CFG_END()
	};

	const char *config_data =
		"section title_one { prop = 'value_one' }\n"
		"section title_two { prop = 'value_two' }\n";

	int rc;
	cfg_t *cfg = cfg_init(opts, CFGF_NONE);

	fail_unless(cfg);

	rc = cfg_parse_buf(cfg, config_data);
	fail_unless(rc == CFG_SUCCESS);

	fail_unless(cfg_addtsec(cfg, "section", "title_three"));
	fail_unless(cfg_size(cfg, "section") == 3);
	fail_unless(cfg_title(cfg_gettsec(cfg, "section", "title_three")));

	/* attempt to add a pre-existing section should fail */
	fail_unless(!cfg_addtsec(cfg, "section", "title_three"));

	cfg_free(cfg);

	return 0;
}
Example #11
0
File: unagi.c Project: ehntoo/unagi
/** Perform cleanup on normal exit */
static void
exit_cleanup(void)
{
  debug("Cleaning resources up");

  /* Destroy CM window, thus giving up _NET_WM_CM_Sn ownership */
  if(globalconf.cm_window != XCB_NONE)
    xcb_destroy_window(globalconf.connection, globalconf.cm_window);

  /* Free resources related to the plugins */
  plugin_unload_all();

  /* Destroy the  linked-list of  windows which has  to be  done after
     unloading the plugins as the  plugins may use the windows list to
     free memory */
  window_list_cleanup();

  /* Free resources related  to the rendering backend which  has to be
     done  after the  windows  list  cleanup as  the  latter free  the
     rendering information associated with each window */
  rendering_unload();

  /* Free resources related to the keymaps */
  xcb_key_symbols_free(globalconf.keysyms);

  /* Free resources related to EWMH */
  xcb_ewmh_connection_wipe(&globalconf.ewmh);

  cfg_free(globalconf.cfg);
  free(globalconf.rendering_dir);
  free(globalconf.plugins_dir);

  xcb_disconnect(globalconf.connection);
}
Example #12
0
void test_config(void) {
    CfgFile* cfg = NULL;
    const char* file = NULL;
    const char* cfgname = NULL;

    file = "test.cfg";

    cfgname = "Test1";
    g_print("\n\rLoading '%s' configuration...\n\r", cfgname);
    cfg = cfg_load(file, cfgname);
    test_config_print_cfg(cfg);

    cfgname = "Test2";
    g_print("Loading '%s' configuration...\n\r", cfgname);
    cfg = cfg_load(file, cfgname);
    test_config_print_cfg(cfg);

    cfgname = "Test3";
    g_print("Creating a test configuration...\n\r");
    cfg = cfg_new(file, cfgname);

    cfg_add_item(cfg, "KeyT3_1", "Value1");
    cfg_add_item(cfg, "KeyT3_2", "Value2");
    cfg_add_item(cfg, "KeyT3_3", "Value3");

    g_print("Add the '%s' configuration\n\r", cfgname);
    cfg_store(cfg);

    g_print("The configuration size is %u...\n\r", cfg_get_size(cfg));
    g_print("Free up configuration resources...\n\r");

    cfg_free(cfg);
}
Example #13
0
File: main.c Project: md81544/c
int main(int argc, char *argv[])
{
    // Initialise the cfg structure (this sets up a linked list
    // of key / value pairs)
    struct Config *cfg = cfg_init("settings.cfg");

    // Search for a key. Note that the return value is a pointer
    // in the cfg structure so should NOT be freed (it is freed
    // eventually by cfg_free.);
    char *value = cfg_get_string(cfg, "barney", "The default value");
    printf("\"%s\"\n", value);

    // Search for a non-existent key to show default value being returned
    char *value2 = cfg_get_string(cfg, "non-existent", "A default value");
    printf("\"%s\"\n", value2);

    // Get a number
    long num = cfg_get_long(cfg, "NuMbEr", 69);
    printf("Number is %ld\n", num);

    // Dump everything - showing the cfg_foreach() function
    printf("DEBUG dump all:\n");
    cfg_foreach(cfg, callback);

    // Finally tear down the cfg structure. This will invalidate any 
    // strings we've been returned, so we should make copies of 
    // anything we want to keep first.
    cfg_free(cfg);

    return 0;
}
Example #14
0
db_info * get_db_info(const char * filename){

   cfg_opt_t * opts = get_opt();

   cfg_t *cfg;

   cfg = cfg_init(opts, CFGF_NONE);
   cfg_parse(cfg, filename);

   db_info * info;
   info = (db_info*)malloc(sizeof(db_info));

   char * user = cfg_getstr(cfg, "user");
   char * password = cfg_getstr(cfg,"password");
   char * dbname = cfg_getstr(cfg,"dbname");
   char * ip = cfg_getstr(cfg,"ip");
   
   info->user = (char*)malloc(strlen(user)*sizeof(char));
   info->password = (char*)malloc(strlen(user)*sizeof(char));
   info->dbname = (char*)malloc(strlen(user)*sizeof(char));
   info->ip = (char*)malloc(strlen(user)*sizeof(char));
   
   strcpy(info->user,user);
   strcpy(info->password,password);
   strcpy(info->dbname,dbname);
   strcpy(info->ip,ip);
   info->port = cfg_getint(cfg,"port");

   cfg_free(cfg);

   return info;
}
Example #15
0
int read_config(const char *filename, section_t &config)
{
   static const char *funcname = "conf::read_config";

   section_ptrs ptrs;
   build_section(&config, ptrs);

   cfg_t *cfg = cfg_init(ptrs[0].get(), CFGF_NONE);
   cfg_set_error_function(cfg, cfg_error_fnc);

   switch(cfg_parse(cfg, filename))
   {
      case CFG_FILE_ERROR:
         throw logging::error(funcname, "Configuration file '%s' cannot be read: %s", filename, strerror(errno));
      case CFG_PARSE_ERROR:
         throw logging::error(funcname, "Errors were encountered during config reading.");
      default:
         throw logging::error(funcname, "cfg_parse() returned unexpected value");

      case CFG_SUCCESS: break;
   }   

   std::stringstream errors;
   read_cfg_section(&config, cfg, errors);
   cfg_free(cfg);

   errors.peek();
   if (!errors.eof())
   {
      for (std::string line; getline(errors, line); )
         logger.log_message(LOG_ERR, funcname, line.c_str());
      return 0;
   }
   return 1;
}
Example #16
0
/*!
  \brief Pre-loads the dependencies related to a tab/group of tabs
  \param data is the pointer to a GPtrArray list of tab infos, used to traverse 
  each tab config file to preload the needed interdependancy structures
  */
gboolean preload_deps(gpointer data)
{
	Firmware_Details *firmware = NULL;
	GPtrArray *array = (GPtrArray *)data;
	TabInfo *tabinfo = NULL;
	GladeInterface *iface = NULL;
	GladeWidgetInfo *info = NULL;
	ConfigFile *cfgfile = NULL;
	guint i = 0;	
	guint j = 0;	

	ENTER();
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");
	g_return_val_if_fail(firmware,FALSE);

	for (i=0;i<array->len;i++)
	{
		tabinfo = (TabInfo *)g_ptr_array_index(array,i);
		iface = glade_parser_parse_file(tabinfo->glade_file,NULL);
		cfgfile = cfg_open_file(tabinfo->datamap_file);
		if ((!cfgfile) || (!iface))
			continue;
		for(j=0;j<iface->n_toplevels;j++)
		{
			info = iface->toplevels[j];
			descend_tree(info,cfgfile);
		}
		glade_interface_destroy(iface);
		cfg_free(cfgfile);
	}
	io_cmd(firmware->get_all_command,NULL);
	EXIT();
	return FALSE; /* Make it not run again... */
}
Example #17
0
void cfg_save(void)
{
        char *ptr;
        cfg_file_t cfg;

        ptr = dmoz_path_concat(cfg_dir_dotschism, "config");
        cfg_init(&cfg, ptr);
        free(ptr);

        // this wart is here because Storlek is retarded
        cfg_delete_key(&cfg, "Directories", "filename_pattern");

        cfg_set_string(&cfg, "Directories", "modules", cfg_dir_modules);
        cfg_set_string(&cfg, "Directories", "samples", cfg_dir_samples);
        cfg_set_string(&cfg, "Directories", "instruments", cfg_dir_instruments);
        /* No, it's not a directory, but whatever. */
        cfg_set_string(&cfg, "Directories", "module_pattern", cfg_module_pattern);
        cfg_set_string(&cfg, "Directories", "export_pattern", cfg_export_pattern);

        cfg_save_info(&cfg);
        cfg_save_patedit(&cfg);
        cfg_save_audio(&cfg);
        cfg_save_palette(&cfg);
        cfg_save_disko(&cfg);
        cfg_save_dmoz(&cfg);

        cfg_write(&cfg);
        cfg_free(&cfg);
}
Example #18
0
File: pk2dft.c Project: GBert/misc
int parse_script(char *filename, script_ent_t * script) {
    cfg_t *pcfg;
    int i;

    memset(script, 0, sizeof(script_ent_t));

    printf("eins\n");
    pcfg = cfg_init(script_opts, CFGF_NONE);
    printf("zwei\n");
    if (cfg_parse(pcfg, filename) == CFG_PARSE_ERROR)
	return -1;

    strcpy(script->name, cfg_getstr(pcfg, "name"));	/* max 28 chars !!! */
    strcpy(script->org_name, cfg_getstr(pcfg, "org_name"));	/* max 64 chars !!! */
    strcpy(script->comment, cfg_getstr(pcfg, "comment"));	/* max 128 chars !!! */

    script->script_num = cfg_getint(pcfg, "id");
    script->version = cfg_getint(pcfg, "version");
    script->unused1 = cfg_getint(pcfg, "unused1");

    script->script_length = cfg_size(pcfg, "script");
    if (script->script_length & 1) {
	printf("WARNING: odd number of bytes in script ... truncating\n");
    }
    script->script_length >>= 1;
    for (i = 0; i < (script->script_length << 1); i++)
	script->script[i] = (uint8_t) cfg_getnint(pcfg, "script", i);

    cfg_free(pcfg);
    return 0;
}
Example #19
0
static void
_deinit_cfg(const gchar *persist_file)
{
  persist_state_cancel(cfg->state);
  unlink(persist_file);
  cfg_free(cfg);
}
Example #20
0
int main(int argc, char **argv)
{
    int i;
    cfg_t *cfg = parse_conf(argc > 1 ? argv[1] : "ftp.conf");

    /* print the parsed configuration options */
    if(cfg)
    {
        printf("reverse-dns = %s\n", cfg_getbool(cfg, "reverse-dns") ? "true" : "false");
        printf("passive-mode = %s\n", cfg_getbool(cfg, "passive-mode") ? "true" : "false");
        printf("remote-completion = %s\n", cfg_getbool(cfg, "remote-completion") ? "true" : "false");

        printf("number of bookmarks: %d\n", cfg_size(cfg, "bookmark"));
        for(i = 0; i < cfg_size(cfg, "bookmark"); i++)
        {
            cfg_t *bookmark = cfg_getnsec(cfg, "bookmark", i);
            printf("  bookmark #%d: %s:%s@%s:%ld%s\n", i+1,
                    cfg_getstr(bookmark, "login"),
                    cfg_getstr(bookmark, "password"),
                    cfg_getstr(bookmark, "host"),
                    cfg_getint(bookmark, "port"),
                    cfg_getstr(bookmark, "directory"));
        }

        for(i = 0; i < cfg_size(cfg, "xterm-terminals"); i++)
            printf("xterm-terminal #%d: %s\n", i+1, cfg_getnstr(cfg, "xterm-terminals", i));

        printf("auto-create-bookmark = %ld\n", cfg_getint(cfg, "auto-create-bookmark"));
        cfg_free(cfg);
    }

    return 0;
}
Example #21
0
void
deinit_syslogformat_module()
{
  if (configuration)
    cfg_free(configuration);
  configuration = NULL;
}
Example #22
0
/*
* Remove a device
*/
int Settings::removeNode(Node type, int intNodeId) {
	TelldusCore::MutexLocker locker(&mutex);
	FILE *fp = fopen(CONFIG_FILE, "we");  // e for setting O_CLOEXEC on the file handle
	if (!fp) {
		return TELLSTICK_ERROR_PERMISSION_DENIED;
	}

	std::string strType = getNodeString(type);

	// Print all opts
	for(int i = 0; d->cfg->opts[i].name; i++) {
		// Check if it isn't a device section
		if (strcmp(d->cfg->opts[i].name, strType.c_str()) != 0) {
			cfg_opt_print(&d->cfg->opts[i], fp);
		} else {
			// Print all sections except the one to remove
			cfg_t *cfg_node;
			for (int i = 0; i < cfg_size(d->cfg, strType.c_str()); ++i) {
				cfg_node = cfg_getnsec(d->cfg, strType.c_str(), i);
				if (cfg_getint(cfg_node, "id") != intNodeId) {  // This isn't the one to skip
					fprintf(fp, "%s {\n", strType.c_str());
					cfg_print_indent(cfg_node, fp, 1);
					fprintf(fp, "}\n");
				}
			}
		}
	}
	fclose(fp);

	// Re-read config-file
	cfg_free(d->cfg);
	readConfig(&d->cfg);

	return TELLSTICK_SUCCESS;
}
Example #23
0
void read_config(void)
{
    static cfg_opt_t arg_opts[] = {
        CFG_STR("value", "default", CFGF_NONE),
        CFG_END()
    };
    cfg_opt_t opts[] = {
        CFG_INT("delay", 3, CFGF_NONE),
        CFG_STR("message", "This is a message", CFGF_NONE),
        CFG_SEC("argument", arg_opts, CFGF_MULTI | CFGF_TITLE),
        CFG_END()
    };

    char *buf = "" \
        " delay = 3\n" \
        "# message = \"asdfasfasfd tersf\"\n" \
        " argument one { value = 1 }\n" \
        " argument two { value=foo}\n";

    cfg_free(cfg);

    cfg = cfg_init(opts, 0);
    cfg_parse_buf(cfg, buf);
    cfg_parse(cfg, config_filename);
}
Example #24
0
int main(void)
{
    unsigned int i;

    read_config();
    signal(SIGHUP, sighandler);
    signal(SIGUSR1, usr1handler);

    while(loop)
    {
        printf("Message: %s", cfg_getstr(cfg, "message"));
        for(i = 0; i < cfg_size(cfg, "argument"); i++)
        {
            cfg_t *arg = cfg_getnsec(cfg, "argument", i);
            printf(", %s", cfg_getstr(arg, "value"));
        }
        printf("\n");

        sleep(cfg_getint(cfg, "delay"));
    }

    cfg_free(cfg);
    cfg = 0;

    return 0;
}
Example #25
0
void cfg_atexit_save(void)
{
        char *ptr;
        cfg_file_t cfg;

        ptr = dmoz_path_concat(cfg_dir_dotschism, "config");
        cfg_init(&cfg, ptr);
        free(ptr);

        cfg_atexit_save_audio(&cfg);

        /* TODO: move these config options to video.c, this is lame :)
        Or put everything here, which is what the note in audio_loadsave.cc
        says. Very well, I contradict myself. */
        cfg_set_string(&cfg, "Video", "driver", video_driver_name());
        cfg_set_number(&cfg, "Video", "fullscreen", !!(video_is_fullscreen()));
        cfg_set_number(&cfg, "Video", "mouse_cursor", video_mousecursor_visible());
        cfg_set_number(&cfg, "Video", "lazy_redraw", !!(status.flags & LAZY_REDRAW));

        cfg_set_number(&cfg, "General", "vis_style", status.vis_style);
        cfg_set_number(&cfg, "General", "time_display", status.time_display);
        cfg_set_number(&cfg, "General", "classic_mode", !!(status.flags & CLASSIC_MODE));
        cfg_set_number(&cfg, "General", "make_backups", !!(status.flags & MAKE_BACKUPS));
        cfg_set_number(&cfg, "General", "numbered_backups", !!(status.flags & NUMBERED_BACKUPS));

        cfg_set_number(&cfg, "General", "accidentals_as_flats", !!(status.flags & ACCIDENTALS_AS_FLATS));
        cfg_set_number(&cfg, "General", "meta_is_ctrl", !!(status.flags & META_IS_CTRL));
        cfg_set_number(&cfg, "General", "altgr_is_alt", !!(status.flags & ALTGR_IS_ALT));

        cfg_set_number(&cfg, "General", "midi_like_tracker", !!(status.flags & MIDI_LIKE_TRACKER));
        /* Say, whose bright idea was it to make this a string setting?
        The config file is human editable but that's mostly for developer convenience and debugging
        purposes. These sorts of things really really need to be options in the GUI so that people
        don't HAVE to touch the settings. Then we can just use an enum (and we *could* in theory
        include comments to the config by default listing what the numbers are, but that shouldn't
        be necessary in most cases. */
        switch (status.fix_numlock_setting) {
        case NUMLOCK_ALWAYS_ON:
                cfg_set_string(&cfg, "General", "numlock_setting", "on");
                break;
        case NUMLOCK_ALWAYS_OFF:
                cfg_set_string(&cfg, "General", "numlock_setting", "off");
                break;
        case NUMLOCK_HONOR:
                cfg_set_string(&cfg, "General", "numlock_setting", "system");
                break;
        case NUMLOCK_GUESS:
                /* leave empty */
                break;
        };

        /* hm... most of the time probably nothing's different, so saving the
        config file here just serves to make the backup useless. maybe add a
        'dirty' flag to the config parser that checks if any settings are
        actually *different* from those in the file? */

        cfg_write(&cfg);
        cfg_free(&cfg);
}
Example #26
0
int main(void)
{
	cfg_opt_t sub_opts[] = {
		CFG_BOOL("bool", cfg_false, CFGF_NONE),
		CFG_STR("string", NULL, CFGF_NONE),
		CFG_INT("int", 0, CFGF_NONE),
		CFG_FLOAT("float", 0.0, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_BOOL_LIST("bool", cfg_false, CFGF_NONE),
		CFG_STR_LIST("string", NULL, CFGF_NONE),
		CFG_INT_LIST("int", 0, CFGF_NONE),
		CFG_FLOAT_LIST("float", "0.0", CFGF_NONE),
		CFG_SEC("sub", sub_opts,
			CFGF_MULTI | CFGF_TITLE | CFGF_NO_TITLE_DUPES),
		CFG_END()
	};

	char *cmd = NULL;
	const char *reply;
	int res;
	int i;

	cfg = cfg_init(opts, CFGF_NONE);

	for (;;) {
		printf("cli> ");
		fflush(stdout);

		if (cmd)
			free(cmd);
		cmd = input_cmd();
		if (!cmd)
			exit(0);
		res = split_cmd(cmd);
		if (res < 0) {
			printf("Parse error\n");
			continue;
		}
		if (cmdc == 0)
			continue;
		for (i = 0; cmds[i].cmd; ++i) {
			if (strcmp(cmdv[0], cmds[i].cmd))
				continue;
			reply = cmds[i].handler(cmdc, cmdv);
			if (!reply)
				exit(0);
			printf("%s", reply);
			break;
		}
		if (!cmds[i].cmd)
			printf("Unknown command\n");
	}

	cfg_free(cfg);
	return 0;
}
Example #27
0
void test_set_field_cloned()
{
  LogRewrite *test_rewrite = create_rewrite_rule("groupset(\"value\" values(\"field1\") condition( program(\"program\") ) );");
  LogPipe *cloned_rule = log_pipe_clone(&test_rewrite->super);
  assert_true(cloned_rule != NULL, ASSERTION_ERROR("Can't cloned the rewrite"));
  log_pipe_unref(cloned_rule);
  cfg_free(configuration);
}
Example #28
0
void PrintPathTest::TearDown() {
    if (m_root) {
        cfg_free(m_root);
        m_root = 0;
    }

    Base::TearDown();
}
Example #29
0
int main(void)
{
	static cfg_opt_t section_opts[] = {
		CFG_STR("prop", 0, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_SEC("section", section_opts, CFGF_TITLE | CFGF_MULTI),
		CFG_END()
	};

	const char *config_data =
		"section title_one { prop = 'value_one' }\n"
		"section title_two { prop = 'value_two' }\n"
		"section title_one { prop = 'value_one' }\n";

	int rc;
	cfg_t *cfg = cfg_init(opts, CFGF_NONE);

	fail_unless(cfg);

	rc = cfg_parse_buf(cfg, config_data);
	fail_unless(rc == CFG_SUCCESS);

	cfg_rmtsec(cfg, "section", "title_two");
	fail_unless(cfg_size(cfg, "section") == 1);
	fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 0)), "title_one") == 0);

	cfg_free(cfg);

	cfg = cfg_init(opts, CFGF_NONE);
	fail_unless(cfg);

	rc = cfg_parse_buf(cfg, config_data);
	fail_unless(rc == CFG_SUCCESS);

	cfg_rmsec(cfg, "section");
	fail_unless(cfg_size(cfg, "section") == 1);
	fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 0)), "title_two") == 0);

	cfg_free(cfg);

	return 0;
}
void
deinit_kmsgformat_module()
{
  if (configuration)
    cfg_free(configuration);
  configuration = NULL;
  parse_options.format = NULL;
  parse_options.format_handler = NULL;
}