Ejemplo n.º 1
0
static void
global_setup (void)
{
    setup_stack (&parse_stack, parse_stack_buffer,
                 sizeof (parse_stack_buffer));
    setup_display ();
    setup_sgf ();

    set_defaults();
    if (configfile_load(SETTINGS_FILENAME, config,
                        sizeof(config)/sizeof(*config),
                        SETTINGS_MIN_VERSION ) < 0)
    {
        /* If the loading failed, save a new config file (as the disk is
           already spinning) */

        /* set defaults again just in case (don't know if they can ever
         * be messed up by configfile_load, and it's basically free anyway)
         */
        set_defaults();

        configfile_save(SETTINGS_FILENAME, config,
                        sizeof(config)/sizeof(*config),
                        SETTINGS_VERSION);
    }
}
Ejemplo n.º 2
0
/*
 * main:
 * -----
 */
int main123(int argc, char **argv)
{
  time_t end_time;
  int raw = 0;
  int mono_from_stereo = 0;

  printf("Shine v1.08 19/06/03\n");

  time(&config.start_time);
  set_defaults();

  if (!parse_command(argc, argv, &raw, &mono_from_stereo))
    print_usage();

  wave_open(raw, mono_from_stereo); /* prints wave (input) configuration */

  check_config(); /* prints mpeg (output) configuration */

  printf("Encoding \"%s\" to \"%s\"\n", config.infile, config.outfile);

  L3_compress();

  wave_close();

  time(&end_time);
  end_time -= config.start_time;
  printf(" Finished in %2ld:%2ld:%2ld\n",
            end_time/3600,(end_time/60)%60,end_time%60);

  return 0;
}
int main(int argc, char **argv) {
  int num_iters;
#if (NUMTESTS > 0)
  int i;
  double time;
  double time_per;
#endif
  set_defaults();
  setup_indexing();
  load_default_data();
  /* Solve problem instance for the record. */
  settings.verbose = 1;
  num_iters = solve();
#ifndef ZERO_LIBRARY_MODE
#if (NUMTESTS > 0)
  /* Now solve multiple problem instances for timing purposes. */
  settings.verbose = 0;
  tic();
  for (i = 0; i < NUMTESTS; i++) {
    solve();
  }
  time = tocq();
  printf("Timed %d solves over %.3f seconds.\n", NUMTESTS, time);
  time_per = time / NUMTESTS;
  if (time_per > 1) {
    printf("Actual time taken per solve: %.3g s.\n", time_per);
  } else if (time_per > 1e-3) {
    printf("Actual time taken per solve: %.3g ms.\n", 1e3*time_per);
  } else {
    printf("Actual time taken per solve: %.3g us.\n", 1e6*time_per);
  }
#endif
#endif
  return 0;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
    int i;
    char buffer[MAXBUFSIZE];
    int done=0;

    set_defaults();
    handle_args(argc, argv, 0);
    srand(time(NULL));

    if(num_clients < 1)
        FATALERR("More than 1 node is required to run\n");

    // Capture exit signals to safetly close the program
    signal(SIGINT, signal_handler);
    signal(SIGTERM, signal_handler);
    signal(SIGABRT, signal_handler);

    // If there was no ip address set in the command line, listen for a broadcast from the server
    if(server_addr.sin_addr.s_addr == 0)
    {
        setup_listen_socket();
        obtain_server();
    }

    // Attempt to create a TCP connection to the server
    if(!connectTCP())
        QUIT();

    send_data();

    signal_handler(0);
}
Ejemplo n.º 5
0
int main(int argc, char** argv)
{
  set_defaults();

  parse_options(argc, argv);

  if (conf.help_flag) {
    print_help();
    exit(0);
  }

  check_conf();

  unsigned int arr_width = conf.width * conf.multiplier;
  unsigned int arr_height = conf.height * conf.multiplier;
  
  printf("Creating array size of %ux%u.\n", arr_width, arr_height);
  Array* arr = new_array(arr_width, arr_height);

  printf("Initializing with side temps of %f, %f, %f, %f.\n",
          conf.top_temp, conf.right_temp, conf.bottom_temp, conf.left_temp);
  initialize_array(arr, conf.top_temp, conf.right_temp, conf.bottom_temp, conf.left_temp);

  printf("Searching for temp balance with max iterations of %d.\n", conf.max_iters);
  double mean_temp = calculate_heatconduct(arr, conf.max_iters);

  printf("Mean temperature: %f\n", mean_temp);

  return 0;
}
Ejemplo n.º 6
0
static gboolean
read_config (GtkFileChooserSettings *settings,
	     GError **error)
{
  char *filename;
  char *contents;
  gsize contents_len;
  gboolean success;

  filename = get_config_filename ();

  success = g_file_get_contents (filename, &contents, &contents_len, error);
  g_free (filename);

  if (!success)
    {
      set_defaults (settings);
      return FALSE;
    }

  success = parse_config (settings, contents, error);

  g_free (contents);

  return success;
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: Glideh/jfrec
static AS3_Val init(void * self, AS3_Val args)
{
	void * ref;
	void * src;
	void * dest;
	
	AS3_ArrayValue(args, "AS3ValType, AS3ValType, AS3ValType", &ref, &src, &dest);
	
	flashErrorsRef = (AS3_Val)ref;
	
	config.wave.file	= funopen((void *)src, readByteArray, writeByteArray, seekByteArray, closeByteArray);
	config.wave.output	= funopen((void *)dest, readByteArray, writeByteArray, seekByteArray, closeByteArray);
	
	if (config.wave.file == NULL || config.wave.output == NULL) {
		ERROR("Unable to set bytes arrays");
	}
	
	wave_open();
	
	set_defaults();
    check_config();
		
	start_compress();
	
	return AS3_Int(1);
}
Ejemplo n.º 8
0
/*
 * Main MCA initialization.  
 */
int mca_base_open(void)
{
  int param_index;
  char *value;
  opal_output_stream_t lds;
  char hostname[64];

  if (!mca_base_opened) {
    mca_base_opened = true;
  } else {
    return OPAL_SUCCESS;
  }

  /* Register some params */
#if OMPI_WANT_HOME_CONFIG_FILES
  asprintf(&value, "%s%c%s"OPAL_PATH_SEP".openmpi"OPAL_PATH_SEP"components", opal_install_dirs.pkglibdir, OPAL_ENV_SEP, opal_home_directory() );
#else
# if defined(__WINDOWS__) && defined(_DEBUG) 
    asprintf(&value, "%s/debug", opal_install_dirs.pkglibdir);  
# else 
    asprintf(&value, "%s", opal_install_dirs.pkglibdir);  
# endif 
#endif

  mca_base_param_component_path = 
    mca_base_param_reg_string_name("mca", "component_path",
                                   "Path where to look for Open MPI and ORTE components", 
                                   false, false, value, NULL);
  free(value);
  param_index = mca_base_param_reg_string_name("mca", "verbose", 
                                               "Top-level verbosity parameter",
                                               false, false, NULL, NULL);

  mca_base_param_reg_int_name("mca", "component_show_load_errors", 
                              "Whether to show errors for components that failed to load or not", 
                              false, false, 1, NULL);

  mca_base_param_reg_int_name("mca", "component_disable_dlopen",
                              "Whether to attempt to disable opening dynamic components or not",
                              false, false, 0, NULL);

  /* What verbosity level do we want? */

  mca_base_param_lookup_string(param_index, &value);
  memset(&lds, 0, sizeof(lds));
  if (NULL != value) {
    parse_verbose(value, &lds);
    free(value);
  } else {
    set_defaults(&lds);
  }
  gethostname(hostname, 64);
  asprintf(&lds.lds_prefix, "[%s:%05d] ", hostname, getpid());
  opal_output_reopen(0, &lds);
  opal_output_verbose(5, 0, "mca: base: opening components");
  free(lds.lds_prefix);
  /* Open up the component repository */

  return mca_base_component_repository_init();
}
Ejemplo n.º 9
0
int sh_utmp_end ()
{
  struct log_user * user    = userlist;
  struct log_user * userold;

  SL_ENTER(_("sh_utmp_end"));
  while (user)
    {
      userold = user;
      user    = user->next;
      SH_FREE(userold);
    }
  userlist = NULL;
#ifdef HAVE_UTTYPE
  (void) sh_utmp_login_clean();
#endif
  /* Reset the flag, such that the module
   * can be re-enabled.
   */
  set_defaults();
  init_done          = 0;

#if defined(HAVE_PTHREAD)
  sh_inotify_remove(&inotify_watch);
#endif

  SL_RETURN( (0), _("sh_utmp_end"));
}
Ejemplo n.º 10
0
int
main(int argc, char *argv[])
{
  int result;
  struct fuse_args args = FUSE_ARGS_INIT(argc, argv);

  memset(&stormfs, 0, sizeof(struct stormfs));
  stormfs.progname = argv[0];
  stormfs.service = AMAZON;
  set_defaults();

  if(fuse_opt_parse(&args, &stormfs, stormfs_opts, stormfs_opt_proc) == -1) {
    fprintf(stderr, "%s: error parsing command-line options\n", stormfs.progname);
    exit(EXIT_FAILURE);
  }

  parse_config(stormfs.config);
  validate_config();
  if(stormfs.rrs)
    stormfs.storage_class = "REDUCED_REDUNDANCY";

  stormfs.virtual_url = stormfs_virtual_url(stormfs.url, stormfs.bucket);

  g_thread_init(NULL);
  result = stormfs_fuse_main(&args);

  fuse_opt_free_args(&args);

  return result;
}
Ejemplo n.º 11
0
void graphdefaults()
{
    set_defaults();

   for (int i = 0; i <= MAXCOLORS; i++) { 
   	current_palette.colors[i] = i;
   	BGIpalette[i] = BGIcolor[i];
    }
    SetPaletteEntries(hPalette, BG, MAXCOLORS+1, BGIpalette);
    RealizePalette(hdc[0]);

    SetTextColor(hdc[0], PALETTEINDEX(text_color+BG));
    SetTextColor(hdc[1], PALETTEINDEX(text_color+BG));
    SetBkColor(hdc[0], PALETTEINDEX(BG));
    SetBkColor(hdc[1], PALETTEINDEX(BG));

    SelectClipRgn(hdc[0], NULL);
    SelectClipRgn(hdc[1], NULL);
    SetViewportOrgEx(hdc[0], 0, 0, NULL);
    SetViewportOrgEx(hdc[1], 0, 0, NULL);

    SelectObject(hdc[0], hBrush[fill_settings.pattern]);
    SelectObject(hdc[1], hBrush[fill_settings.pattern]);

    moveto(0,0);
}
Ejemplo n.º 12
0
void save_subset(ImageInfo *ii)
{
    if (g_poly->n > 0) {
        if (crosshair_line > 0 && crosshair_samp > 0) {

            // clamp crosshair to image extent, if needed
            if (crosshair_line >= ii->meta->general->line_count)
                crosshair_line = ii->meta->general->line_count - 1;
            if (crosshair_samp >= ii->meta->general->sample_count)
                crosshair_samp = ii->meta->general->sample_count - 1;

            show_save_subset_window();
            set_defaults(ii);
            
            g_poly->show_extent = TRUE;
            fill_big(ii);

            update_save_subset_info();
        } else {
            asfPrintWarning("Can't save subset: No crosshair.\n");
        }
    } else {
        // shouldn't ever get in here...
        asfPrintWarning("Can't save subset: Polygon not defined.\n");
    }
}
Ejemplo n.º 13
0
int
edit_entry(kadm5_principal_ent_t ent, int *mask,
	   kadm5_principal_ent_t default_ent, int default_mask)
{

    set_defaults(ent, mask, default_ent, default_mask);

    if(edit_deltat ("Max ticket life", &ent->max_life, mask,
		    KADM5_MAX_LIFE) != 0)
	return 1;

    if(edit_deltat ("Max renewable life", &ent->max_renewable_life, mask,
		    KADM5_MAX_RLIFE) != 0)
	return 1;

    if(edit_timet ("Principal expiration time", &ent->princ_expire_time, mask,
		   KADM5_PRINC_EXPIRE_TIME) != 0)
	return 1;

    if(edit_timet ("Password expiration time", &ent->pw_expiration, mask,
		   KADM5_PW_EXPIRATION) != 0)
	return 1;

    if(edit_attributes ("Attributes", &ent->attributes, mask,
			KADM5_ATTRIBUTES) != 0)
	return 1;

    return 0;
}
JNIEXPORT void JNICALL Java_us_ihmc_commonWalkingControlModules_controlModules_nativeOptimization_CVXMomentumOptimizerWithGRFSmootherNative_initialize
  (JNIEnv * env, jclass jClass)
{
	set_defaults();
	setup_indexing();
	settings.verbose = 0;

	AByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.A, sizeof(double) * ASize));
    bByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.b, sizeof(double) * bSize));
    CByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.C, sizeof(double) * CSize));
    JsByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.Js, sizeof(double) * JsSize));
    psByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.ps, sizeof(double) * psSize));
    WsByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.Ws, sizeof(double) * WsSize));
    LambdaByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.Lambda, sizeof(double) * LambdaSize));
    QrhoByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.Qrho, sizeof(double) * QrhoSize));
    QphiByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.Qphi, sizeof(double) * QphiSize));
    cByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.c, sizeof(double) * cSize));
    rhoMinByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.rhoMin, sizeof(double) * rhoMinSize));
    phiMinByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.phiMin, sizeof(double) * phiMinSize));
    phiMaxByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.phiMax, sizeof(double) * phiMaxSize));
    WRhoByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.WRho, sizeof(double) * WRhoSize));
    WPhiByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.WPhi, sizeof(double) * WPhiSize));

    rhoPreviousByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.rhoPrevious, sizeof(double) * rhoPreviousSize));
    WRhoSmootherByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, params.WRhoSmoother, sizeof(double) * WRhoSmootherSize));

    rhoByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, vars.rho, sizeof(double) * rhoSize));
    phiByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, vars.phi, sizeof(double) * phiSize));
    vdByteBuffer = (*env)->NewGlobalRef(env, (*env)->NewDirectByteBuffer(env, vars.vd, sizeof(double) * vdSize));
}
Ejemplo n.º 15
0
int sh_utmp_reconf()
{
  set_defaults();
#if defined(HAVE_PTHREAD)
  sh_inotify_remove(&inotify_watch);
#endif
  return 0;
}
Ejemplo n.º 16
0
__attribute__((constructor)) static void _liblogfaf_init(void) {
    DBG(("liblogfaf: init()\n"));
    init_progname(&shared_data);
    init_hostname(&shared_data);
    init_connection(&shared_data);
    pthread_mutex_init(&shared_data.lock, NULL);
    set_defaults(&shared_data);
}
Ejemplo n.º 17
0
enigma_rotor_window::enigma_rotor_window(int pos_x, int pos_y, bool orient)
    : rotor_window_base(pos_x, pos_y)
{ 
    screw_orientation = orient;
    upper = new screw(0, 0, screw_orientation);
    lower = new screw(0, 0, !screw_orientation);
    set_defaults();
}
Ejemplo n.º 18
0
user_midi_bus::user_midi_bus (const std::string & name)
 :
    m_is_valid          (false),
    m_channel_count     (0),
    m_midi_bus_def      ()
{
    set_defaults();
    set_name(name);
}
Ejemplo n.º 19
0
//----TEventWindow class member definitions---------------------
TEventWindow::TEventWindow(pchar caption, TWin *parent, dword style)
//-----------------------------------------------------------------
{
  set_defaults();
  if (style) m_style |= style;
  create_window(caption, parent);
  get_dc()->set_text_align(TA_TOP | TA_LEFT);
  enable_resize(true);
}
Ejemplo n.º 20
0
	Sprite::Sprite(Renderer* renderer, const String& TextureFile) : Entity(renderer)
	{
		set_defaults();
		if (TextureFile.length() > 0)
		{
			ManagedResources::ManagedTexturePtr texture = m_renderer->resources().get_texture(TextureFile);
			change_texture(texture, true);
		}
	}
Ejemplo n.º 21
0
/* MAIN */
int main( int argc, char ** argv ) {
	struct opdis_options opts = {0}; // TODO: defaults
	struct job_options_t job_opts;

	set_defaults( &opts );

	argp_parse( &argp_cfg, argc, argv, 0, 0, &opts );

	if ( opts.list_arch ) {
		list_arch();
		return 0;
	}

	if ( opts.list_disasm_opt ) {
		list_disasm_opts();
		return 0;
	}

	if ( opts.list_syntax ) {
		list_syntax();
		return 0;
	}

	if ( opts.list_format ) {
		list_format();
		return 0;
	}

	if (! opts.jobs->num_items ) {
		/* if no jobs were requested, do a linear disasm of all */
		int i;
		for ( i = 0; i < opts.targets->num_items; i++ ) {
			job_list_add( opts.jobs, job_linear, "(default)", 
				      i + 1, 0, OPDIS_INVALID_ADDR, 0 );
		}
	}

	load_bfd_targets( & opts );

	if ( opts.dry_run ) {
		dry_run( & opts );
		return 0;
	}

	if (! opts.targets->num_items ) {
		fprintf( stderr, "No targets specified! Use -? for help.\n" );
		return 1;
	}

	configure_opdis( & opts );
	set_job_opts( &opts, &job_opts );
	job_list_perform_all( opts.jobs, &job_opts );

	output_disassembly( & opts );

	return 0;
}
Ejemplo n.º 22
0
void config_parser_t::initialize()
{
	if(initialized)
		return;

	init();
	set_defaults();
	build_table();
	initialized = 1;
}
Ejemplo n.º 23
0
std::unique_ptr<optparse::OptionParser> CreateParser(ParserOptions options)
{
  auto parser = std::make_unique<optparse::OptionParser>();
  parser->usage("usage: %prog [options]... [FILE]...").version(Common::scm_rev_str);

  parser->add_option("-u", "--user").action("store").help("User folder path");
  parser->add_option("-m", "--movie").action("store").help("Play a movie file");
  parser->add_option("-e", "--exec")
      .action("append")
      .metavar("<file>")
      .type("string")
      .help("Load the specified file");
  parser->add_option("-n", "--nand_title")
      .action("store")
      .metavar("<16-character ASCII title ID>")
      .type("string")
      .help("Launch a NAND title");
  parser->add_option("-C", "--config")
      .action("append")
      .metavar("<System>.<Section>.<Key>=<Value>")
      .type("string")
      .help("Set a configuration option");

  if (options == ParserOptions::IncludeGUIOptions)
  {
    parser->add_option("-d", "--debugger")
        .action("store_true")
        .help("Show the debugger pane and additional View menu options");
    parser->add_option("-l", "--logger").action("store_true").help("Open the logger");
    parser->add_option("-b", "--batch").action("store_true").help("Exit Dolphin with emulation");
    parser->add_option("-c", "--confirm").action("store_true").help("Set Confirm on Stop");
  }

  parser->set_defaults("video_backend", "");
  parser->set_defaults("audio_emulation", "");
  parser->add_option("-v", "--video_backend").action("store").help("Specify a video backend");
  parser->add_option("-a", "--audio_emulation")
      .choices({"HLE", "LLE"})
      .help("Choose audio emulation from [%choices]");

  return parser;
}
Ejemplo n.º 24
0
__attribute__((constructor)) static void _liblogfaf_init(void) {
    DBG(("liblogfaf: init()\n"));
    init_progname(&shared_data);
    init_hostname(&shared_data);
    init_connection(&shared_data);
    if (pthread_mutex_init(&shared_data.lock, NULL) != 0) {
        fprintf(stderr, "liblogfaf: pthread_mutex_init() failed\n");
        exit(1);
    }
    set_defaults(&shared_data);
}
Ejemplo n.º 25
0
static bool handle_flag_defaults(void) {
  if (flag_gid ||
      flag_base_dir ||
      flag_inactive != FLAG_NOT_SET ||
      flag_expiredate != FLAG_NOT_SET ||
      flag_shell) {
    return set_defaults();
  } else {
    return show_defaults();
  }
}
Ejemplo n.º 26
0
int glkunix_startup_code(glkunix_startup_t *data)
{
  set_defaults();
#ifdef USE_GARGLK_FEATURES
	garglk_set_program_name("Nitfol 0.5");
	garglk_set_program_info(
		"Nitfol 0.5 by Evin Robertson\n"
		"With countless patches by other people.\n");
#endif
  return parse_commands(data->argc, data->argv);
}
Ejemplo n.º 27
0
/* ------------------------------------------------------------- **
** Functions to read / parse the config file.
** ------------------------------------------------------------- */
int process_cmdline(int argc, char *argv[])
{
	int i;
	struct option_array *opt;
	sstr *arg;
	char *optp, *argp;

	set_defaults();
	if (argc <= 1)
		return 0;

	arg = sstr_init(0);

	i = 1;
	optp = argv[i] + 1;

	while (i < argc) {
		if (argv[i][0] != '-')
			usage(-1);
		opt = opts;
		if (*optp == '-')
			usage(-1);	/*?TODO longopts */
		else {
			while (opt->name != NULL && opt->cmdline != *optp)
				opt++;
			if (opt->name == NULL)
				usage(*optp);
			if (strlen(cmdline_set) < 99)
				cmdline_set[strlen(cmdline_set)] = *optp;
			if (opt->type == BOOL) {
				sstr_cpy2(arg, "yes");
				set_opt(opt, arg);
				if (*(++optp) == 0) {
					i++;
					optp = argv[i] + 1;
				}
			} else {
				argp = optp + 1;
				if (*argp == 0) {
					if (i >= argc - 1 ||
					    *(argp = argv[++i]) == '-')
						usage(*optp);

				}
				sstr_cpy2(arg, argp);
				set_opt(opt, arg);
				i++;
				optp = argv[i] + 1;
			}
		}
	}
	sstr_free(arg);
	return (0);
}
Ejemplo n.º 28
0
void PS2keyboard::run_bat() {
    Serial.print("Running keyboard Basic Assurance Test (BAT)...\n");
    set_led_numlock(true);
    set_led_capslock(true);
    set_led_scrolllock(true);
    set_defaults();
    enabled = true;
    delay(520);
    Serial.print("Keyboard BAT completed, sending success code...\n");
    cmd_success();
    Serial.print("Finished\n");
}
Ejemplo n.º 29
0
/* called by nol_daemon_launch(), return 0 on success */
const char *
slave_init_cb(void)
{
    char *s;
    int   sock;
    int   o = 1;

    openlog("mn-slaved", LOG_PID, LOG_DAEMON);
    set_defaults();

    if (!(srv.master_io.data = srv.m_nolp = nolp_create(&master_commands, 0)))
        return "nolp init failed";

    /* set up master login info */
    srv.master.sin_port        = htons(opt_vals.master_port);
    srv.master.sin_addr.s_addr = inet_addr(opt_vals.master_host);

    if ((s = strchr(opt_vals.listen, ':'))) {
        srv.addr.sin_port = htons(atoi(s+1));
        *s = '\0';
    } else
        srv.addr.sin_port = htons(NOL_SLAVE_DEFAULT_PORT);
    srv.addr.sin_addr.s_addr = inet_addr(opt_vals.listen);
    srv.addr.sin_family = AF_INET;
    sock = socket(PF_INET, SOCK_STREAM, 0);
    setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &o, sizeof(o));
    if (bind(sock, (struct sockaddr*)&srv.addr, sizeof srv.addr) == -1) {
        syslog(LOG_ERR, "could not bind to %s:%hd",
                inet_ntoa(srv.addr.sin_addr),
                ntohs(srv.addr.sin_port));
        return "bind() failed";
    }
    if (listen(sock, 1024) == -1) {
        syslog(LOG_ERR, "could not listen on %s:%hd",
                inet_ntoa(srv.addr.sin_addr),
                ntohs(srv.addr.sin_port));
        return "listen() failed";
    }

    if (!(srv.mysql = nol_s_dup_mysql_conn()))
        return "could not connect to mysql server";
    if (nol_s_master_connect() != 0)
        return "could not connect to master server";
    if (nol_s_master_login() != 0)
        return "logging in to master failed";

    srv.listen_sock = sock;

    if (opt_vals.exec_dir)
        chdir(opt_vals.exec_dir);

    return 0;
}
Ejemplo n.º 30
0
void Settings::load_settings (Glib::RefPtr<Gio::File> file)
{
  Glib::KeyFile cfg;

  set_defaults();

  try {
    if (!cfg.load_from_file (file->get_path())) {
      std::cout << "Failed to load settings from file '" << file->get_path() << "\n";
      return;
    }
  } catch (const Glib::KeyFileError &err) {
    std::cout << "Exception " << err.what() << " loading settings from file '" << file->get_path() << "\n";
    return;
  }

  std::cout << "parsing config from '" << file->get_path() << "\n";

  for (uint i = 0; i < G_N_ELEMENTS (settings); i++) {
    Glib::ustring group, key;

    if (!get_group_and_key (i, group, key))
      continue;

    if (!cfg.has_key (group, key))
      continue;

    // group & string ...
    switch (settings[i].type) {
    case T_BOOL:
      *PTR_BOOL(this, i) = cfg.get_boolean (group, key);
      break;
    case T_INT:
      *PTR_INT(this, i) = cfg.get_integer (group, key);
      break;
    case T_FLOAT:
    case T_COLOUR_MEMBER:
      *PTR_FLOAT(this, i) = cfg.get_double (group, key);
      break;
    case T_STRING:
      *PTR_STRING(this, i) = cfg.get_string (group, key);
      break;
    default:
      std::cerr << "corrupt setting type\n";
      break;
    }
  }

  GCode.m_impl->loadSettings (cfg);

  m_signal_visual_settings_changed.emit();
  m_signal_update_settings_gui.emit();
}