Exemplo n.º 1
0
Arquivo: conf.c Projeto: 95ulisse/tinc
void read_config_options(avl_tree_t *config_tree, const char *prefix) {
	list_node_t *node, *next;
	size_t prefix_len = prefix ? strlen(prefix) : 0;

	for(node = cmdline_conf->tail; node; node = next) {
		config_t *orig_cfg, *cfg = (config_t *)node->data;
		next = node->prev;

		if(!prefix) {
			if(strchr(cfg->variable, '.'))
				continue;
			node->data = NULL;
			list_unlink_node(cmdline_conf, node);
		} else {
			if(strncmp(prefix, cfg->variable, prefix_len) ||
			   cfg->variable[prefix_len] != '.')
				continue;
			/* Because host configuration is parsed again when
			   reconnecting, nodes must not be freed when a prefix
			   is given. */
			orig_cfg = cfg;
			cfg = new_config();
			cfg->variable = xstrdup(orig_cfg->variable + prefix_len + 1);
			cfg->value = xstrdup(orig_cfg->value);
			cfg->file = NULL;
			cfg->line = orig_cfg->line;
		}
		config_add(config_tree, cfg);
	}
}
Exemplo n.º 2
0
bool node_write_devclass(meshlink_handle_t *mesh, node_t *n) {

	if(n->devclass < 0 || n->devclass > _DEV_CLASS_MAX)
		return false;

	bool result = false;

	splay_tree_t *config_tree;
	init_configuration(&config_tree);

	// ignore read errors; in case the file does not exist we will create it
	read_host_config(mesh, config_tree, n->name);

	config_t* cnf = lookup_config(config_tree, "DeviceClass");

	if(!cnf)
	{
		cnf = new_config();
		cnf->variable = xstrdup("DeviceClass");
		config_add(config_tree, cnf);
	}

	set_config_int(cnf, n->devclass);

	if(!write_host_config(mesh, config_tree, n->name))
		goto fail;

	result = true;

fail:
	exit_configuration(&config_tree);
	return result;
}
Exemplo n.º 3
0
std::vector<ConfigFile> Config::GetAllConfigsInFolder(const std::string path, const std::string ext)
{
	namespace fs = std::experimental::filesystem;

	std::vector<ConfigFile> config_files;

	if (fs::exists(path) && fs::is_directory(path))
	{
		for (auto it = fs::recursive_directory_iterator(path); it != fs::recursive_directory_iterator(); it++)
		{
			if (fs::is_regular_file(*it) && it->path().extension() == ext)
			{
				std::string fPath = path + it->path().filename().string();

				std::string tmp_f_name = it->path().filename().string();
				size_t pos = tmp_f_name.find(".");
				std::string fName = (std::string::npos == pos) ? tmp_f_name : tmp_f_name.substr(0, pos);

				ConfigFile new_config(fName, fPath);
				config_files.emplace_back(new_config);
			}
		}
	}
	return config_files;
}
Exemplo n.º 4
0
SortedList<T, Pred>::SortedList(const SortedList<T, Pred> &rhs) throw(SortedListException)
	:size_(0)
{
	if (rhs.shareAllocator_)
	{
		shareAllocator_ = true;
		freeAllocator_ = false;
		objAllocator_ = rhs.objAllocator_;
	}
	else
	{
		shareAllocator_ = false;
		OAConfig new_config(true); // Use CPP mem manager.
		objAllocator_ = createAllocator(new_config);
	}

	sorter_ = rhs.sorter_;

	// Build dummy head and tail nodes.
/*	head_ = allocNode();
	tail_ = allocNode();*/

	head_ = createNode(0);
	tail_ = createNode(0);

	// Everything's good, link'em.
	head_->Prev = NULL;
	head_->Next = tail_;

	tail_->Prev = head_;
	tail_->Next = NULL;

	copyNodes(rhs);
}
Exemplo n.º 5
0
std::vector<Config> GetConfigs(const char* directory)
{
	std::vector<Config> configs;

	DIR* dir;
	dirent* pdir;

	dir = opendir(directory);

	while ((pdir = readdir(dir)))
	{
		if (pdir->d_type == DT_DIR && strcmp(pdir->d_name, ".") != 0 && strcmp(pdir->d_name, "..") != 0)
		{
			pstring config_path;
			config_path << directory << pdir->d_name;

			if (DoesConform(config_path.c_str()))
			{
				Config new_config(pdir->d_name, config_path.c_str());
				configs.push_back(new_config);
			}
		}
	}

	return configs;
}
// executes (loops over) a Lambda expression: tries to run to termination,
// or returns after having emitted further remote lookup/reduction requests
// the return val is a buffer with the result stack's (concatenated) content
struct ccnl_buf_s*
Krivine_reduction(struct ccnl_relay_s *ccnl, char *expression,
                  int start_locally,
                  struct configuration_s **config,
                  struct ccnl_prefix_s *prefix, int suite)
{
    int steps = 0, halt = 0, restart = 1;
    int len = strlen("CLOSURE(HALT);RESOLVENAME()") + strlen(expression) + 1;
    char *dummybuf;

    DEBUGMSG(TRACE, "Krivine_reduction()\n");

    if (!*config && strlen(expression) == 0)
        return 0;
    dummybuf = ccnl_malloc(2000);
    if (!*config) {
        char *prog;
        struct environment_s *global_dict = NULL;

        prog = ccnl_malloc(len*sizeof(char));
        sprintf(prog, "CLOSURE(HALT);RESOLVENAME(%s)", expression);
        setup_global_environment(&global_dict);
        DEBUGMSG(DEBUG, "PREFIX %s\n", ccnl_prefix_to_path(prefix));
        *config = new_config(ccnl, prog, global_dict,
                             start_locally,
                             prefix, ccnl->km->configid, suite);
        DBL_LINKED_LIST_ADD(ccnl->km->configuration_list, (*config));
        restart = 0;
        --ccnl->km->configid;
    }
    DEBUGMSG(INFO, "Prog: %s\n", (*config)->prog);

    while ((*config)->prog && !halt) {
        char *oldprog = (*config)->prog;
        steps++;
        DEBUGMSG(DEBUG, "Step %d (%d/%d): %s\n", steps,
                 stack_len((*config)->argument_stack),
                 stack_len((*config)->result_stack), (*config)->prog);
        (*config)->prog = ZAM_term(ccnl, *config, &halt, dummybuf, &restart);
        ccnl_free(oldprog);
    }
    ccnl_free(dummybuf);

    if (halt < 0) { //HALT < 0 means pause computation
        DEBUGMSG(INFO,"Pause computation: %d\n", -(*config)->configid);
        return NULL;
    }

    //HALT > 0 means computation finished
    DEBUGMSG(INFO, "end-of-computation (%d/%d)\n",
             stack_len((*config)->argument_stack),
             stack_len((*config)->result_stack));
/*
    print_argument_stack((*config)->argument_stack);
    print_result_stack((*config)->result_stack);
*/

    return Krivine_exportResultStack(ccnl, *config);
}
Exemplo n.º 7
0
static void load_config_file(config_holder_t *config_holder) {
	TSFile fh;
	struct stat s;

	config_t *newconfig, *oldconfig;
	TSCont free_cont;

	configReloadRequests++;
	lastReloadRequest = time(NULL);

	// check date
	if (stat(config_holder->config_path, &s) < 0) {
		TSDebug(PLUGIN_TAG, "Could not stat %s", config_holder->config_path);
		if(config_holder->config) {
			return;
		}
	} else {
		TSDebug(PLUGIN_TAG, "s.st_mtime=%lu, last_load=%lu", s.st_mtime, config_holder->last_load);
		if (s.st_mtime < config_holder->last_load) {
			return;
		}
	}

	TSDebug(PLUGIN_TAG, "Opening config file: %s", config_holder->config_path);
	fh = TSfopen(config_holder->config_path, "r");

	if (!fh) {
		TSError("[%s] Unable to open config: %s.\n",
				PLUGIN_TAG, config_holder->config_path);
		if(config_holder->config) {
			return;
		}
	}

	newconfig = 0;
	newconfig = new_config(fh);
	if(newconfig) {
		configReloads++;
		lastReload = lastReloadRequest;
		config_holder->last_load = lastReloadRequest;
		config_t ** confp = &(config_holder->config);
		oldconfig = __sync_lock_test_and_set(confp, newconfig);
		if (oldconfig) {
			TSDebug(PLUGIN_TAG, "scheduling free: %p (%p)", oldconfig, newconfig);
			free_cont = TSContCreate(free_handler, NULL);
			TSContDataSet(free_cont, (void *) oldconfig);
			TSContSchedule(free_cont, FREE_TMOUT, TS_THREAD_POOL_TASK);
		}
	}
	if(fh)
		TSfclose(fh);
	return;
}
Exemplo n.º 8
0
config_t copy_config(config_t other){
    if(other == NULL){
        
        return NULL;
    }
    config_t r = new_config(other->size);
    int i = 0;
    for(;i< other->size; i++){
        r->map[i] = copy_entry(other->map[i]);
    }
    return r;
}
Exemplo n.º 9
0
void load_config(void)
{
     struct stat sfile;
     int load_context;
     char *rcpath;

     load_context = error_new_context(_("Error loading configfile"), NULL);

     rcpath = filename_config(load_context);
     if(!rcpath) {
	  error_flush(load_context);
	  return;
     }

     /* no config file is fine */
     if(stat(rcpath, &sfile) == -1 || !sfile.st_size) {
	  error_flush(load_context);
	  /* If there is no configuration file, we start with the
	     current configuration file version */
	  config->config_version = CURRENT_CONFIG_VERSION;
	  config->asked_version = CURRENT_CONFIG_VERSION;
	  g_free(rcpath);
	  return;
     }

     /* refuse to read config file if world readable (bind passwords) */
     if( ((sfile.st_mode & ~S_IFMT) & (S_IRWXG|S_IRWXO)) != 0 ) {
	  error_push(load_context,
		     _("%s is group and/or world readable or writeable.\n"
		       "This file can contain passwords in cleartext,\n"
		       "and is recommended to have mode 0600.\n\n"
		       "Continuing with default settings...\n"),
		     rcpath);
	  error_flush(load_context);
	  g_free(rcpath);
	  return;
     }

     config = process_rcfile_XML(load_context, rcpath);
/*      printf("config = %08lx\n", config); */
/*      process_rcfile(rcfile) */

     g_free(rcpath);

     if (config == NULL) {
	  error_push(load_context, 
		     _("No valid configuration found. Using default (empty) configuration"));

	  config = new_config();
     }

     error_flush(load_context);
}
Exemplo n.º 10
0
void MOS6510::SetState(MOS6510State *s)
{
	a = s->a;
	x = s->x;
	y = s->y;
	
	n_flag = s->p & 0x80;
	v_flag = s->p & 0x40;
	d_flag = s->p & 0x08;
	i_flag = s->p & 0x04;
	z_flag = !(s->p & 0x02);
	c_flag = s->p & 0x01;
	
	if(ThePrefs.SingleCycleEmulation)
	{
		ddr = s->ddr;
		pr = s->pr;
	}
	else
	{
		ram[0] = s->ddr;
		ram[1] = s->pr;
	}
	new_config();
	ar = s->ar;
	ar2 = s->ar2;
	state = s->state;
	op = s->op;
	rdbuf = s->rdbuf;
	
	basic_in = s->basic_in;
	kernal_in = s->kernal_in;
	char_in = s->char_in;
	io_in = s->io_in;
	
	if(ThePrefs.SingleCycleEmulation)
		pcSC = s->pc;
	else {
		jump(s->pc);
	}
    
	sp = s->sp & 0xff;
	
	interrupt.intr[INT_VICIRQ] = s->intr[INT_VICIRQ];
	interrupt.intr[INT_CIAIRQ] = s->intr[INT_CIAIRQ];
	interrupt.intr[INT_NMI] = s->intr[INT_NMI];
	interrupt.intr[INT_RESET] = s->intr[INT_RESET];
	nmi_state = s->nmi_state;
	dfff_byte = s->dfff_byte;
}
Exemplo n.º 11
0
int client_main(config_t *cfg){
    int mode;
    
    mode = get_menu();                              //モード選択はループの最後に行う
    while(1){
        if ( mode == CLIENT_GET ){                  //ファイル取得
            if ( cfg->host[0] == '\0' ){
                printf("接続先が登録されていません。\nEnterキーでメニューに戻ります。\n");
                fflush(stdin);
                getc(stdin);
                mode = get_menu();
                continue;
            }
            if ( client_receive_transmission(cfg) == ERROR_CONNECT ){
                printf("サーバに接続できませんでした。\n接続先の受信プログラムが起動していない可能性があります。\nEnterキーでもう一度接続を試みます。\n");
                fflush(stdin);
                getc(stdin);
                continue;
            }
        } else if ( mode == CLIENT_CONFIG ){
            if ( cfg->host[0] == '\0' ){            //接続先がないので入力させる
                printf("接続先を入力し、Enterキーを押してください。\n>>");
                new_config(cfg);
                config_load(cfg);
            } else {                                //接続先を表示し、入力を求める。
                printf("現在設定されている接続先は%sです。\n上書きしない場合は、Enterキーのみを入力してください。\n上書きする場合は接続先を入力し、Enterキーを入力してください。\n>>",cfg->host);
                new_config(cfg);
                config_load(cfg);
            }
        } else if ( mode == CLIENT_EXIT ){          //終了
            exit(0);
        }
        mode = get_menu();
    }
    return NO_ERROR;
}
Exemplo n.º 12
0
struct config *
copy_config (struct config *old)
{
  struct config *c = new_config ();

  memcpy (c, old, sizeof *c);

  /* Need to deep copy strings and string lists. */
  if (c->server)
    c->server = strdup (c->server);
  if (c->username)
    c->username = strdup (c->username);
  if (c->password)
    c->password = strdup (c->password);
  if (c->identity_url)
    c->identity_url = strdup (c->identity_url);
  if (c->identity_file)
    c->identity_file = strdup (c->identity_file);
  if (c->guestname)
    c->guestname = strdup (c->guestname);
  if (c->disks)
    c->disks = guestfs_int_copy_string_list (c->disks);
  if (c->removable)
    c->removable = guestfs_int_copy_string_list (c->removable);
  if (c->interfaces)
    c->interfaces = guestfs_int_copy_string_list (c->interfaces);
  if (c->network_map)
    c->network_map = guestfs_int_copy_string_list (c->network_map);
  if (c->output)
    c->output = strdup (c->output);
  if (c->output_connection)
    c->output_connection = strdup (c->output_connection);
  if (c->output_format)
    c->output_format = strdup (c->output_format);
  if (c->output_storage)
    c->output_storage = strdup (c->output_storage);

  return c;
}
Exemplo n.º 13
0
SortedList<T, Pred>::SortedList(Pred sorter, ObjectAllocator *Allocator, bool SharedAllocator)
:objAllocator_(Allocator), sorter_(sorter), shareAllocator_(SharedAllocator), head_(NULL), tail_(NULL), size_(0)
{
	// Let's get a working allocator...
	if (objAllocator_ == NULL)
	{
		OAConfig new_config(true); // Use CPP builtin mem manager.

		try
		{
			objAllocator_ = createAllocator(new_config);
		}
		catch(OAException &)
		{
			throw(SortedListException(SortedListException::E_NO_MEMORY, "List Constructor: Out of memory!"));
		}
	}
	else
	{
		freeAllocator_ = false;
	}

	// Now to set up initial dummy head and tail nodes.
	// Note that both head and tail will have garbage data in all fields aside
	// from their Next and Prev pointers! Accessing that data will result
	// in undefined behavior!
/*	head_ = allocNode();
	tail_ = allocNode(); */

	head_ = createNode(0);
	tail_ = createNode(0);

	// Everything's good, link'em.
	head_->Prev = NULL;
	head_->Next = tail_;

	tail_->Prev = head_;
	tail_->Next = NULL;
}
Exemplo n.º 14
0
Arquivo: conf.c Projeto: 95ulisse/tinc
config_t *parse_config_line(char *line, const char *fname, int lineno) {
	config_t *cfg;
	int len;
	char *variable, *value, *eol;
	variable = value = line;

	eol = line + strlen(line);
	while(strchr("\t ", *--eol))
		*eol = '\0';

	len = strcspn(value, "\t =");
	value += len;
	value += strspn(value, "\t ");
	if(*value == '=') {
		value++;
		value += strspn(value, "\t ");
	}
	variable[len] = '\0';

	if(!*value) {
		const char err[] = "No value for variable";
		if (fname)
			logger(LOG_ERR, "%s `%s' on line %d while reading config file %s",
				err, variable, lineno, fname);
		else
			logger(LOG_ERR, "%s `%s' in command line option %d",
				err, variable, lineno);
		return NULL;
	}

	cfg = new_config();
	cfg->variable = xstrdup(variable);
	cfg->value = xstrdup(value);
	cfg->file = fname ? xstrdup(fname) : NULL;
	cfg->line = lineno;

	return cfg;
}
extern "C" ASPELL_EXPORT  Config * new_aspell_config()
{
  return new_config();
}
Exemplo n.º 16
0
int
main (int argc, char *argv[])
{
  gboolean gui_possible;
  int c;
  int option_index;
  char **cmdline = NULL;
  int cmdline_source = 0;
  struct config *config = new_config ();

  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEBASEDIR);
  textdomain (PACKAGE);

  /* There is some raciness between slow devices being discovered by
   * the kernel and udev and virt-p2v running.  This is a partial
   * workaround, but a real fix involves handling hotplug events
   * (possible in GUI mode, not easy in kernel mode).
   */
  udevadm_settle ();

#if ! GLIB_CHECK_VERSION(2,32,0)
  /* In glib2 < 2.32 you had to call g_thread_init().  In later glib2
   * that is not required and should not be called.
   */
  if (glib_check_version (2, 32, 0) != NULL) /* This checks < 2.32 */
    g_thread_init (NULL);
#endif
  gdk_threads_init ();
  gdk_threads_enter ();
  gui_possible = gtk_init_check (&argc, &argv);

  for (;;) {
    c = getopt_long (argc, argv, options, long_options, &option_index);
    if (c == -1) break;

    switch (c) {
    case 0:			/* options which are long only */
      if (STREQ (long_options[option_index].name, "long-options")) {
        display_long_options (long_options);
      }
      else if (STREQ (long_options[option_index].name, "short-options")) {
        display_short_options (options);
      }
      else if (STREQ (long_options[option_index].name, "cmdline")) {
        cmdline = parse_cmdline_string (optarg);
        cmdline_source = CMDLINE_SOURCE_COMMAND_LINE;
      }
      else
        error (EXIT_FAILURE, 0,
               _("unknown long option: %s (%d)"),
               long_options[option_index].name, option_index);
      break;

    case 'v':
      config->verbose = 1;
      break;

    case 'V':
      printf ("%s %s\n", guestfs_int_program_name, PACKAGE_VERSION_FULL);
      exit (EXIT_SUCCESS);

    case HELP_OPTION:
      usage (EXIT_SUCCESS);

    default:
      usage (EXIT_FAILURE);
    }
  }

  if (optind != argc) {
    fprintf (stderr, _("%s: unused arguments on the command line\n"),
             guestfs_int_program_name);
    usage (EXIT_FAILURE);
  }

  set_config_defaults (config);

  /* Parse /proc/cmdline (if it exists) or use the --cmdline parameter
   * to initialize the configuration.  This allows defaults to be pass
   * using the kernel command line, with additional GUI configuration
   * later.
   */
  if (cmdline == NULL) {
    cmdline = parse_proc_cmdline ();
    if (cmdline != NULL)
      cmdline_source = CMDLINE_SOURCE_PROC_CMDLINE;
  }

  if (cmdline)
    update_config_from_kernel_cmdline (config, cmdline);

  /* If p2v.server exists, then we use the non-interactive kernel
   * conversion.  Otherwise we run the GUI.
   */
  if (config->server != NULL)
    kernel_conversion (config, cmdline, cmdline_source);
  else {
    if (!gui_possible)
      error (EXIT_FAILURE, 0,
             _("gtk_init_check returned false, indicating that\n"
               "a GUI is not possible on this host.  Check X11, $DISPLAY etc."));
    gui_conversion (config);
  }

  guestfs_int_free_string_list (cmdline);

  exit (EXIT_SUCCESS);
}
Exemplo n.º 17
0
int
main (int argc, char *argv[])
{
  gboolean gui_possible;
  int c;
  int option_index;
  char **cmdline = NULL;
  int cmdline_source = 0;
  struct config *config = new_config ();

  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEBASEDIR);
  textdomain (PACKAGE);

#if ! GLIB_CHECK_VERSION(2,32,0)
  /* In glib2 < 2.32 you had to call g_thread_init().  In later glib2
   * that is not required and should not be called.
   */
  if (glib_check_version (2, 32, 0) != NULL) /* This checks < 2.32 */
    g_thread_init (NULL);
#endif
  gdk_threads_init ();
  gdk_threads_enter ();
  gui_possible = gtk_init_check (&argc, &argv);

  for (;;) {
    c = getopt_long (argc, argv, options, long_options, &option_index);
    if (c == -1) break;

    switch (c) {
    case 0:			/* options which are long only */
      if (STREQ (long_options[option_index].name, "long-options")) {
        display_long_options (long_options);
      }
      else if (STREQ (long_options[option_index].name, "short-options")) {
        display_short_options (options);
      }
      else if (STREQ (long_options[option_index].name, "cmdline")) {
        cmdline = parse_cmdline_string (optarg);
        cmdline_source = CMDLINE_SOURCE_COMMAND_LINE;
      }
      else {
        fprintf (stderr, _("%s: unknown long option: %s (%d)\n"),
                 guestfs_int_program_name, long_options[option_index].name, option_index);
        exit (EXIT_FAILURE);
      }
      break;

    case 'v':
      config->verbose = 1;
      break;

    case 'V':
      printf ("%s %s%s\n",
              guestfs_int_program_name,
              PACKAGE_VERSION, PACKAGE_VERSION_EXTRA);
      exit (EXIT_SUCCESS);

    case HELP_OPTION:
      usage (EXIT_SUCCESS);

    default:
      usage (EXIT_FAILURE);
    }
  }

  if (optind != argc) {
    fprintf (stderr, _("%s: unused arguments on the command line\n"),
             guestfs_int_program_name);
    usage (EXIT_FAILURE);
  }

  set_config_defaults (config);

  /* If /proc/cmdline exists and contains "p2v.server=" then we enable
   * non-interactive configuration.
   * If /proc/cmdline contains p2v.debug then we enable verbose mode
   * even for interactive configuration.
   */
  if (cmdline == NULL) {
    cmdline = parse_proc_cmdline ();
    if (cmdline == NULL)
      goto gui;
    cmdline_source = CMDLINE_SOURCE_PROC_CMDLINE;
  }

  if (get_cmdline_key (cmdline, "p2v.debug") != NULL)
    config->verbose = 1;

  if (get_cmdline_key (cmdline, "p2v.server") != NULL)
    kernel_configuration (config, cmdline, cmdline_source);
  else {
  gui:
    if (!gui_possible) {
      fprintf (stderr,
               _("%s: gtk_init_check returned false, indicating that\n"
                 "a GUI is not possible on this host.  Check X11, $DISPLAY etc.\n"),
               guestfs_int_program_name);
      exit (EXIT_FAILURE);
    }
    gui_application (config);
  }

  guestfs_int_free_string_list (cmdline);

  exit (EXIT_SUCCESS);
}
Exemplo n.º 18
0
  PosibErr<Config *> find_word_list(Config * c) 
  {
    Config * config = new_config();
    RET_ON_ERR(config->read_in_settings(c));
    String dict_name;

    if (config->have("master")) {
      dict_name = config->retrieve("master");

    } else {

      ////////////////////////////////////////////////////////////////////
      //
      // Give first preference to an exact match for the language-country
      // code, then give preference to those in the alternate code list
      // in the order they are presented, then if there is no match
      // look for one for just language.  If that fails give up.
      // Once the best matching code is found, try to find a matching
      // variety if one exists, other wise look for one with no variety.
      //

      BetterList b_code;
      //BetterList b_jargon;
      BetterVariety b_variety;
      BetterList b_module;
      BetterSize b_size;
      Better * better[4] = {&b_code,&b_variety,&b_module,&b_size};
      const DictInfo * best = 0;

      //
      // retrieve and normalize code
      //
      const char * p;
      String code;
      PosibErr<String> str = config->retrieve("lang");
      p = str.data.c_str();
      while (asc_isalpha(*p))
        code += asc_tolower(*p++);
      String lang = code;
      bool have_country = false;
      if (*p == '-' || *p == '_') {
        ++p;
        have_country = true;
        code += '_'; 
        while (asc_isalpha(*p))
          code += asc_toupper(*p++);
      }
  
      //
      // Retrieve acceptable code search orders
      //
      String lang_country_list;
      if (have_country) {
        lang_country_list = code;
        lang_country_list += ' ';
      }
      String lang_only_list = lang;
      lang_only_list += ' ';

      // read retrieve lang_country_list and lang_only_list from file(s)
      // FIXME: Write Me

      //
      split_string_list(b_code.list, lang_country_list);
      split_string_list(b_code.list, lang_only_list);
      b_code.init();

      //
      // Retrieve Variety
      // 
      config->retrieve_list("variety", &b_variety.list);
      if (b_variety.list.empty() && config->have("jargon")) 
        b_variety.list.add(config->retrieve("jargon"));
      b_variety.init();
      str.data.clear();

      //
      // Retrieve module list
      //
      if (config->have("module"))
        b_module.list.add(config->retrieve("module"));
      else if (config->have("module-search-order"))
        config->retrieve_list("module-search-order", &b_module.list);
      {
        StackPtr<ModuleInfoEnumeration> els(get_module_info_list(config)->elements());
        const ModuleInfo * entry;
        while ( (entry = els->next()) != 0)
          b_module.list.add(entry->name);
      }
      b_module.init();

      //
      // Retrieve size
      //
      str = config->retrieve("size");
      p = str.data.c_str();
      if (p[0] == '+' || p[0] == '-' || p[0] == '<' || p[0] == '>') {
        b_size.req_type = p[0];
        ++p;
      } else {
        b_size.req_type = '+';
      }
      if (!asc_isdigit(p[0]) || !asc_isdigit(p[1]) || p[2] != '\0')
        abort(); //FIXME: create an error condition here
      b_size.requested = atoi(p);
      b_size.init();

      //
      // 
      //

      const DictInfoList * dlist = get_dict_info_list(config);
      DictInfoEnumeration * dels = dlist->elements();
      const DictInfo * entry;

      while ( (entry = dels->next()) != 0) {

        b_code  .cur = entry->code;
        b_module.cur = entry->module->name;

        b_variety.cur = entry->variety;
    
        b_size.cur_str = entry->size_str;
        b_size.cur     = entry->size;

        //
        // check to see if we got a better match than the current
        // best_match if any
        //

        IsBetter is_better = SameMatch;
        for (int i = 0; i != 4; ++i)
          is_better = better[i]->better_match(is_better);
    
        if (is_better == BetterMatch) {
          for (int i = 0; i != 4; ++i)
            better[i]->set_best_from_cur();
          best = entry;
        }
      }

      delete dels;

      //
      // set config to best match
      //
      if (best != 0) {
        String main_wl,flags;
        PosibErrBase ret = get_dict_file_name(best, main_wl, flags);
        if (ret.has_err()) {
          delete config;
          return ret;
        }
        dict_name = best->name;
        config->replace("lang", b_code.best);
        config->replace("language-tag", b_code.best);
        config->replace("master", main_wl.c_str());
        config->replace("master-flags", flags.c_str());
        config->replace("module", b_module.best);
        config->replace("jargon", b_variety.best);
        config->replace("clear-variety", "");
        unsigned p;
        for (const char * c = b_module.best; *c != '\0'; c += p) {
          p = strcspn(c, "-");
          config->replace("add-variety", String(c, p));
        }
        config->replace("size", b_size.best_str);
      } else {
        delete config;
        return make_err(no_wordlist_for_lang, code);
      }
    }

    const StringMap * dict_aliases = get_dict_aliases(config);
    const char * val = dict_aliases->lookup(dict_name);
    if (val) config->replace("master", val);
    return config;
  }
Exemplo n.º 19
0
extern "C" Config * new_aspell_config()
{
  return new_config();
}
Exemplo n.º 20
0
static void gq_configS(struct parser_context *ctx,
		       struct tagstack_entry *e)
{
    e->data = new_config();
    e->free_data = (free_func) free_config;
}
Exemplo n.º 21
0
config_t init_config(){
 //TODO: in a c++ implementation this all can be done automatically 
 //using a hashmap
    config_t conf = new_config(N_CONFIG_VARIABLES);
   
    config_t uspace = new_config(N_USPACE_VARS);
            
    uspace = update_entry(
        USPACE_BASE,
	    new_entry_int(50176, "BASE"),
	    uspace);
	
	uspace = update_entry(
	    USPACE_WR, 
	    new_entry_int(0, "WR"),
	    uspace);
	    
	uspace = update_entry(
	    USPACE_RD, 
	    new_entry_int(8, "RD"),
	    uspace);
	
	config_t subdev = new_config(N_SUBDEV_VARS);
	
    subdev = update_entry(
        SUBDEV_IN,
	    new_entry_int(0, "IN"),
	    subdev);
	    
	subdev = update_entry(
	    SUBDEV_OUT,
	    new_entry_int(1, "OUT"),
	    subdev);
	    
    subdev = update_entry(
        SUBDEV_ADC, 
	    new_entry_int(2, "ADC"),
	    subdev);
	    
	subdev = update_entry(
	    SUBDEV_DAC, 
	    new_entry_int(3, "DAC"),
	    subdev);
	
	config_t comedi = new_config(N_COMEDI_VARS);
	
	comedi = update_entry(
	    COMEDI_FILE,
	    new_entry_int(0, "FILE"),
	    comedi);
	    
	comedi = update_entry(
	    COMEDI_SUBDEV, 
	    new_entry_map(subdev, "SUBDEV"),
	    comedi);
    
    config_t sim = new_config(N_SIM_VARS);
    
    sim = update_entry(
        SIM_INPUT,
        new_entry_str("sim.in", "INPUT"), 
        sim);
        
    sim = update_entry(
        SIM_OUTPUT,
        new_entry_str("sim.out", "OUTPUT"),
        sim);    

    conf = update_entry(
        CONFIG_STEP,
        new_entry_int(1, "STEP"),
        conf);
    
    conf = update_entry(
        CONFIG_PIPE,
        new_entry_str("plcpipe", "PIPE"),
        conf);
    
    conf = update_entry(
        CONFIG_HW,
        new_entry_str("STDI/O", "HW"),
        conf);
        
    conf = update_entry(
        CONFIG_USPACE,
        new_entry_map(uspace, "USPACE"),
        conf);
    
    conf = update_entry(
        CONFIG_COMEDI,
        new_entry_map(comedi, "COMEDI"),
        conf);
    
    conf = update_entry(
        CONFIG_SIM,
        new_entry_map(sim, "SIM"),
        conf);

   /*******************************************/
    conf = update_entry(
        CONFIG_TIMER,
        new_entry_seq(new_sequence(4), "TIMERS"),
        conf);
    
    conf = update_entry(
        CONFIG_PULSE,
        new_entry_seq(new_sequence(4), "PULSES"),
        conf);
        
    conf = update_entry(
        CONFIG_MREG,
        new_entry_seq(new_sequence(4), "MREG"),
        conf);
        
    conf = update_entry(
        CONFIG_MVAR,
        new_entry_seq(new_sequence(4), "MVAR"),
        conf);
    
    conf = update_entry(
        CONFIG_DI,
        new_entry_seq(new_sequence(8), "DI"),
        conf);
 
    conf = update_entry(
        CONFIG_DQ,
        new_entry_seq(new_sequence(8), "DQ"),
        conf);
    
    conf = update_entry(
        CONFIG_AI,
        new_entry_seq(new_sequence(8), "AI"),
        conf);
    
    conf = update_entry(
        CONFIG_AQ,
        new_entry_seq(new_sequence(8), "AQ"),
        conf);

    conf = update_entry(
        CONFIG_PROGRAM,
        new_entry_seq(new_sequence(2), "PROGRAM"),
        conf);

    return conf;
}