Ejemplo n.º 1
0
void
options_parse(int argc, char *argv[])
{
  char* tail_ptr;
  int c_opt;
  int option_index;
  int val;

  assert (argc>0);
  assert(argv);

  while(1){
    option_index = 0;
    
    c_opt = getopt_long(argc, argv, spd_short_options, spd_long_options,
			&option_index);

    if (c_opt == -1) break;

    switch(c_opt){
    case 'd': 
	SPD_SPK_MODE = MODE_DAEMON;
	break;
    case 's':
	SPD_SPK_MODE = MODE_SINGLE;
	break;
    case 'l':
	SPD_OPTION_SET_INT(LOG_LEVEL);
	break;
    case 'L':
	if (LOG_FILE_NAME != 0) free(LOG_FILE_NAME);
	LOG_FILE_NAME = (char*) strdup(optarg);
      break;
    case 'D':
	if (SPEAKUP_DEVICE != 0) free(SPEAKUP_DEVICE);
	SPEAKUP_DEVICE = (char*) strdup(optarg);
      break;
    case 'c':
	if (SPEAKUP_CODING != 0) free (SPEAKUP_CODING);
	SPEAKUP_CODING = (char*) strdup(optarg);
	break;
    case 'v':
	options_print_version();
	exit(0);
	break;
    case 'h':
	options_print_help(argv);
	exit(0);
	break;
    case 'p':
	PROBE_MODE = 1;
	break;
    default:
      printf("Error: Unrecognized option\n\n");
      options_print_help(argv);
      exit(1);
    }
  }
}
Ejemplo n.º 2
0
int main(int argc, const char * argv[]) {
    sm_set_program_name(argv[0]);

    const char*input_filename;
    const char*output_pattern_op;

    struct option* ops = options_allocate(3);
    options_string(ops, "in", &input_filename, "stdin", "input file (JSON)");
    options_string(ops, "out", &output_pattern_op, "./ld_split^02d.json", "output pattern; printf() pattern, but write '^' instead of '%'");

    if(!options_parse_args(ops, argc, argv)) {
        fprintf(stderr, "%s : splits a JSON file into many files."
                "\n\nOptions:\n", argv[0]);
        options_print_help(ops, stderr);
        return -1;
    }


    /* Substitute "$" with "%" */

    char output_pattern[256];
    strcpy(output_pattern, output_pattern_op);
    char *f = output_pattern;
    while(*f) {
        if(*f=='^') *f='%';
        f++;
    }

    fputs(output_pattern, stderr);

    FILE * input_stream = open_file_for_reading(input_filename);

    int count = 0;

    JO jo;
    while( (jo = json_read_stream(input_stream)) ) {
        char filename[1000];
        sprintf(filename, output_pattern, count);
        if(!count) {

        }

        sm_debug("Writing to file (%s) %s\n", output_pattern, filename);
        FILE * f = open_file_for_writing(filename);
        if(!f) return -1;
        fputs(json_object_to_json_string(jo), f);
        jo_free(jo);
        fclose(f);

        count++;
    }


    return 0;
}
Ejemplo n.º 3
0
int main(int argc, const char* argv[]) {
	sm_set_program_name(argv[0]);

	log2pdf_params p;
	
	lds_set_defaults(&(p.laser));
	ls_set_defaults(&(p.pose_path));
	
	p.laser.rays.draw = 0;
	p.laser.points.draw = 0;
	p.laser.normals.draw = 0;
	p.laser.countour.width = 0.1;
	p.pose_path.width = 0.1;
	p.pose_path.color = "#f00";
	
	options_banner(banner);
	struct option * ops = options_allocate(100);
	options_string(ops, "in", &p.input_filename, "stdin", "input file (Carmen or JSON)");
	options_string(ops, "out", &p.output_filename, "", "output file (if empty, input file + '.pdf')");
	options_double(ops, "padding", &p.padding, 0.2, "padding around bounding box (m)");
	options_double(ops, "dimension", &p.dimension, 500.0, "dimension of the image (points)");
	options_double(ops, "offset_theta_deg", &p.offset_theta_deg, 0.0, " rotate entire map by this angle (deg) ");

	options_string(ops, "use", &p.use, "estimate", "One in 'odometry','estimate','true_pose'");
	options_double(ops, "distance_xy", &p.distance_xy, 5.0, " Minimum distance between scans (m) ");
	options_double(ops, "distance_th_deg", &p.distance_th_deg, 45.0, " Minimum distance between scans (deg) ");
	options_double(ops, "start_pose_width", &p.start_pose_width, 0.4, "First pose | Circle width");
	lds_add_options(&(p.laser), ops, "laser_", "");
	ls_add_options(&(p.pose_path), ops, "path_", "");
	
	if(!options_parse_args(ops, argc, argv)) {
		sm_error("Could not parse arguments.\n");
		options_print_help(ops, stderr);
		return -1;
	}
	
	/* If out not specified */
	if(strlen(p.output_filename)==0) {
		char buf[PATH_MAX];
		sprintf(buf, "%s.pdf", p.input_filename);
		p.output_filename = my_strdup(buf);
/*		sm_info("Writing on file '%s'.\n", p.output_filename);*/
	}
	
	p.use_reference = ld_string_to_reference(p.use);
	if(Invalid == p.use_reference) {
		sm_error("Invalid reference '%s'. " 
			"Use one in 'odometry','estimate','true_pose'.\n", p.use);
		return -1;
	}
/*	sm_info("Using reference: %s.\n", ld_reference_to_string(p.use_reference));*/
	
	return !log2pdf(&p);
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {
  const char *appdir = fs_appdir();

  if (!fs_mkdir(appdir)) {
    LOG_FATAL("Failed to create app directory %s", appdir);
  }

  // load base options from config
  char config[PATH_MAX] = {0};
  snprintf(config, sizeof(config), "%s" PATH_SEPARATOR "config", appdir);
  options_read(config);

  // override options from the command line
  options_parse(&argc, &argv);

  if (OPTION_help) {
    options_print_help();
    return EXIT_SUCCESS;
  }

  if (!exception_handler_install()) {
    LOG_WARNING("Failed to initialize exception handler");
    return EXIT_FAILURE;
  }

  struct window *window = win_create();
  if (!window) {
    LOG_WARNING("Failed to initialize window");
    return EXIT_FAILURE;
  }

  const char *load = argc > 1 ? argv[1] : NULL;
  if (load && strstr(load, ".trace")) {
    struct tracer *tracer = tracer_create(window);
    tracer_run(tracer, load);
    tracer_destroy(tracer);
  } else {
    struct emu *emu = emu_create(window);
    emu_run(emu, load);
    emu_destroy(emu);
  }

  win_destroy(window);

  exception_handler_uninstall();

  // persist options for next run
  options_write(config);

  return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
int main(int argc, const char * argv[]) {
	sm_set_program_name(argv[0]);
	
	
	options_banner("ld_purify: Makes sure that the file format is valid. \n * Sets valid=0 if reading is outside interval ");
	
	struct ld_purify_params p;
	
	struct option* ops = options_allocate(20);
	options_double(ops, "threshold_min", &p.threshold_min, 0.01, 
		"Sets valid=0 if readings are less than this threshold.");
	options_double(ops, "threshold_max", &p.threshold_max, 79.0, 
		"Sets valid=0 if readings are more than this threshold.");
	
	options_string(ops, "in", &p.file_input, "stdin", "Input file ");
	options_string(ops, "out", &p.file_output, "stdout", "Output file ");
		
		
	if(!options_parse_args(ops, argc, argv)) {
		options_print_help(ops, stderr);
		return -1;
	}

	FILE * in = open_file_for_reading(p.file_input);
	if(!in) return -3;

	FILE * out = open_file_for_writing(p.file_output);
	if(!out) return -2;



	LDP ld; int count = -1;
	while( (ld = ld_from_json_stream(in))) {
		
		purify(ld, p.threshold_min, p.threshold_max);
		
		if(!ld_valid_fields(ld))  {
			sm_error("Wait, we didn't purify enough  (#%d in file)\n", count);
			continue;
		}
		
		ld_write_as_json(ld, out);
		ld_free(ld);
	}
	
	return 0;
}
Ejemplo n.º 6
0
int options_parse(int argc, char *argv[])
{
	char *tail_ptr;
	int c_opt;
	int option_index;
	int val;

	assert(argc > 0);
	assert(argv);

	while (1) {
		option_index = 0;

		c_opt = getopt_long(argc, argv, short_options, long_options,
				    &option_index);
		if (c_opt == -1)
			break;
		switch (c_opt) {
		case 'r':
			OPT_SET_INT(rate);
			break;
		case 'p':
			OPT_SET_INT(pitch);
			break;
		case 'R':
			OPT_SET_INT(pitch_range);
			break;
		case 'i':
			OPT_SET_INT(volume);
			break;
		case 'l':
			OPT_SET_STR(language);
			break;
		case 'o':
			OPT_SET_STR(output_module);
			break;
		case 'O':
			list_output_modules = 1;
			break;
		case 'I':
			OPT_SET_STR(sound_icon);
			break;
		case 't':
			OPT_SET_STR(voice_type);
			break;
		case 'L':
			list_synthesis_voices = 1;
			break;
		case 'y':
			OPT_SET_STR(synthesis_voice);
			break;
		case 'm':
			OPT_SET_STR(punctuation_mode);
			break;
		case 's':
			spelling = 1;
			break;
		case 'e':
			pipe_mode = 1;
			break;
		case 'P':
			OPT_SET_STR(priority);
			break;
		case 'x':
			ssml_mode = SPD_DATA_SSML;
			break;
		case 'N':
			OPT_SET_STR(application_name);
			break;
		case 'n':
			OPT_SET_STR(connection_name);
			break;
		case 'w':
			wait_till_end = 1;
			break;
		case 'S':
			stop_previous = 1;
			break;
		case 'C':
			cancel_previous = 1;
			break;
		case 'v':
			options_print_version(argv);
			exit(0);
			break;
		case 'h':
			options_print_help(argv);
			exit(0);
			break;
		default:
			printf(_("Unrecognized option\n"));
			options_print_help(argv);
			exit(1);
		}
	}
	return 0;
}
Ejemplo n.º 7
0
int main(int argc, const char ** argv) {
	sm_set_program_name(argv[0]);
	
	struct ld_exp_tro1_params p;
	
	options_banner(banner);
	
	struct option* ops = options_allocate(10);
	options_double(ops, "max_xy_error", &p.max_xy_error, 10.0, "Maximum error for x,y (m)");
	options_double(ops, "max_theta_error_deg", &p.max_theta_error_deg, 10.0, "Maximum error for orientation (deg)");
	options_int   (ops, "seed", &p.seed, 0, "Seed for random number generator (if 0, use GSL_RNG_SEED env. variable).");

	options_int(ops, "num_per_scan", &p.num_per_scan, 10, "Number of trials for each scan.");

	options_string(ops, "in", &p.file_input, "stdin", "Input file ");
	options_string(ops, "out1", &p.file_output1, "stdout", "Output file for first scan");
	options_string(ops, "out2", &p.file_output2, "stdout", "Output file for second scan");
	
	options_int(ops, "debug", &p.debug, 0, "Shows debug information");
	
	if(!options_parse_args(ops, argc, argv)) {
		options_print_help(ops, stderr);
		return -1;
	}
	
	sm_debug_write(p.debug);

	gsl_rng_env_setup();
	gsl_rng * rng = gsl_rng_alloc (gsl_rng_ranlxs0);
	if(p.seed != 0)
	gsl_rng_set(rng, (unsigned int) p.seed);
	
	/* Open the two output files (possibly the same one) */
	
	FILE * in = open_file_for_reading(p.file_input);
	if(!in) return -3;

	FILE * out1 = open_file_for_writing(p.file_output1);
	if(!out1) return -2;
	
	FILE * out2;
	if(!strcmp(p.file_output1, p.file_output2)) {
		out1 = out2;
	} else {
		out2 = open_file_for_writing(p.file_output2);
		if(!out2) return -2;
	}

	/* Read laser data from input file */
	LDP ld; int count=0;
	while( (ld = ld_read_smart(in))) {
		count++;
		if(!ld_valid_fields(ld))  {
			sm_error("Invalid laser data (#%d in file)\n", count);
			continue;
		}
		
		for(int n=0; n < p.num_per_scan; n++) {					
			ld->true_pose[0] = 0;
			ld->true_pose[1] = 0;
			ld->true_pose[2] = 0;
			
			ld->odometry[0] = 0;
			ld->odometry[1] = 0;
			ld->odometry[2] = 0;
			
			ld_write_as_json(ld, out1);

			ld->odometry[0] = 2*(gsl_rng_uniform(rng)-0.5) * p.max_xy_error;
			ld->odometry[1] = 2*(gsl_rng_uniform(rng)-0.5) * p.max_xy_error;
			ld->odometry[2] = 2*(gsl_rng_uniform(rng)-0.5) * deg2rad(p.max_theta_error_deg);
			
			ld_write_as_json(ld, out2);
		}

		ld_free(ld);
	}
	
	return 0;
}
Ejemplo n.º 8
0
void options_parse(int argc, char *argv[])
{
	char *tail_ptr;
	int c_opt;
	int option_index;
	int val;
	int ret;

	char *tmpdir;
	char *debug_logfile_path;

	assert(argc > 0);
	assert(argv);

	while (1) {
		option_index = 0;

		c_opt =
		    getopt_long(argc, argv, spd_short_options, spd_long_options,
				&option_index);
		if (c_opt == -1)
			break;
		switch (c_opt) {
		case 'd':
			spd_mode = SPD_MODE_DAEMON;
			break;
		case 's':
			spd_mode = SPD_MODE_SINGLE;
			break;
		case 'l':
			SPD_OPTION_SET_INT(log_level);
			break;
		case 'L':
			SPD_OPTION_SET_STR(log_dir);
			SpeechdOptions.log_dir_set = 1;
			break;
		case 'c':
			SPD_OPTION_SET_STR(communication_method);
			SpeechdOptions.communication_method_set = 1;
			break;
		case 'S':
			SPD_OPTION_SET_STR(socket_path);
			SpeechdOptions.socket_path_set = 1;
			break;
		case 'p':
			SPD_OPTION_SET_INT(port);
			break;
		case 'a':
			SpeechdOptions.spawn = TRUE;
			break;
		case 'P':
			SPD_OPTION_SET_STR(pid_file);
			break;
		case 'C':
			SPD_OPTION_SET_STR(conf_dir);
			break;
		case 'v':
			options_print_version();
			exit(0);
			break;
		case 'D':
			tmpdir = g_strdup(getenv("TMPDIR"));
			if (!tmpdir)
				tmpdir = g_strdup("/tmp");
			SpeechdOptions.debug_destination =
			    g_strdup_printf("%s/speechd-debug", tmpdir);
			g_free(tmpdir);

			ret = mkdir(SpeechdOptions.debug_destination, S_IRWXU);
			if (ret) {
				MSG(1,
				    "Can't create additional debug destination in %s, reason %d-%s",
				    SpeechdOptions.debug_destination, errno,
				    strerror(errno));
				if (errno == EEXIST) {
					MSG(1,
					    "Debugging directory %s already exists, please delete it first",
					    SpeechdOptions.debug_destination);
				}
				exit(1);
			}

			debug_logfile_path =
			    g_strdup_printf("%s/speech-dispatcher.log",
					    SpeechdOptions.debug_destination);
			/* Open logfile for writing */
			debug_logfile = fopen(debug_logfile_path, "wx");
			g_free(debug_logfile_path);
			if (debug_logfile == NULL) {
				MSG(1,
				    "Error: can't open additional debug logging file %s [%d-%s]!\n",
				    debug_logfile_path, errno, strerror(errno));
				exit(1);
			}
			SpeechdOptions.debug = 1;
			break;
		case 'h':
			options_print_help(argv);
			exit(0);
			break;
		default:
			MSG(2, "Unrecognized option\n");
			options_print_help(argv);
			exit(1);
		}
	}
}
Ejemplo n.º 9
0
int main(int argc, const char * argv[]) {
	sm_set_program_name(argv[0]);

	const char *in_filename;
	const char *ref_filename;
	const char *out_filename;
	const char *ref_field_string; ld_reference ref_field;
	const char *out_field_string; ld_reference out_field;

	struct option* ops = options_allocate(15);
	options_string(ops, "in", &in_filename, "stdin", "scan matching log");
	options_string(ops, "ref", &ref_filename, "ref.log", "slam log");
	options_string(ops, "out", &out_filename, "stdout", "output file");

	options_string(ops, "ref_field", &ref_field_string, "estimate", "What field to find in ref.");
	options_string(ops, "out_field", &out_field_string, "true_pose", "What field to copy to.");
		
	if(!options_parse_args(ops, argc, argv)) {
		fprintf(stderr, " This program works on two logs: A and B. "
		"For each scan in A, the program searches for the scan in B having the same timestamp. "
		"Then, the true_pose field in B is copied to the scan form A, and it is written to the output.\n");
		options_print_help(ops, stderr);
		return -1;
	}
	
	ref_field = ld_string_to_reference(ref_field_string);
	out_field = ld_string_to_reference(out_field_string);
	
	
	FILE * in_stream  = open_file_for_reading(in_filename);
	FILE * ref_stream = open_file_for_reading(ref_filename);
	FILE * out_stream = open_file_for_writing(out_filename);
	
	if(!in_stream || !ref_stream || !out_stream) return -1;

	LDP ld_in;
	while((ld_in = ld_read_smart(in_stream))) {
		int matched = 0;
		while(1) {
			LDP ld_ref = ld_read_smart(ref_stream);
			if(!ld_ref) break;
			if(same_scan(ld_in, ld_ref)) {
				matched = 1;
				const double *ref_pose = ld_get_reference_pose(ld_ref, ref_field);
				double *out_pose = ld_get_reference_pose_silent(ld_in, out_field);
				copy_d(ref_pose, 3, out_pose);
				ld_write_as_json(ld_in, out_stream);
				fputs("\n", out_stream);
				break;
			}
			ld_free(ld_ref);
		}

		if(!matched) {
			sm_error("Could not match %s. \n", short_desc(ld_in));
			if(feof(ref_stream)) {
				sm_error("..because ref stream has ended.\n");
				break;
			}
			continue;
		}
	
		ld_free(ld_in);
	}
	
	return 0;
}
Ejemplo n.º 10
0
int main(int argc, const char*argv[]) {
	sm_set_program_name(argv[0]);
	
	struct sm_params params;
	struct sm_result result;
	
	struct option* ops = options_allocate(100);
	options_string(ops, "in", &p.file_in, "stdin", "Input file ");
	options_string(ops, "out", &p.file_out, "stdout", "Output file ");
	options_string(ops, "out_stats", &p.file_out_stats, "", "Output file (stats) ");
	options_string(ops, "file_jj", &p.file_jj, "",
		"File for journaling -- if left empty, journal not open.");
	options_int(ops, "algo", &p.algo, 0, "Which algorithm to use (0:(pl)ICP 1:gpm-stripped 2:HSM) ");
	
	options_int(ops, "debug", &p.debug, 0, "Shows debug information");
	options_int(ops, "recover_from_error", &p.recover_from_error, 0, "If true, tries to recover from an ICP matching error");
	
	
	p.format = 0;
/*	options_int(ops, "format", &p.format, 0,
		"Output format (0: log in JSON format, 1: log in Carmen format (not implemented))");*/
	
	sm_options(&params, ops);
	if(!options_parse_args(ops, argc, argv)) {
		fprintf(stderr, "\n\nUsage:\n");
		options_print_help(ops, stderr);
		return -1;
	}

	sm_debug_write(p.debug);

	/* Open input and output files */
	
	FILE * file_in = open_file_for_reading(p.file_in);
	if(!file_in) return -1;
	FILE * file_out = open_file_for_writing(p.file_out);
	if(!file_out) return -1;
	
	if(strcmp(p.file_jj, "")) {
		FILE * jj = open_file_for_writing(p.file_jj);
		if(!jj) return -1;
		jj_set_stream(jj);
	}
	
	FILE * file_out_stats = 0;
	if(strcmp(p.file_out_stats, "")) {
		file_out_stats = open_file_for_writing(p.file_out_stats);
		if(!file_out_stats) return -1;
	}
	
	/* Read first scan */
	LDP laser_ref;
	if(!(laser_ref = ld_read_smart(file_in))) {
		sm_error("Could not read first scan.\n");
		return -1;
	}
	if(!ld_valid_fields(laser_ref))  {
		sm_error("Invalid laser data in first scan.\n");
		return -2;
	}
	
	
	/* For the first scan, set estimate = odometry */
	copy_d(laser_ref->odometry, 3, laser_ref->estimate);
	
	spit(laser_ref, file_out);
	int count=-1;
	LDP laser_sens;
	while( (laser_sens = ld_read_smart(file_in)) ) {
		
		count++;
		if(!ld_valid_fields(laser_sens))  {
			sm_error("Invalid laser data in (#%d in file).\n", count);
			return -(count+2);
		}
		
		params.laser_ref  = laser_ref;
		params.laser_sens = laser_sens;

		/* Set first guess as the difference in odometry */
		
		if(	any_nan(params.laser_ref->odometry,3) ||  
			any_nan(params.laser_sens->odometry,3) ) {
				sm_error("The 'odometry' field is set to NaN so I don't know how to get an initial guess. I usually use the difference in the odometry fields to obtain the initial guess.\n");
				sm_error("  laser_ref->odometry = %s \n",  friendly_pose(params.laser_ref->odometry) );
				sm_error("  laser_sens->odometry = %s \n", friendly_pose(params.laser_sens->odometry) );
				sm_error(" I will quit it here. \n");
				return -3;
		}
		
		double odometry[3];
		pose_diff_d(laser_sens->odometry, laser_ref->odometry, odometry);
		double ominus_laser[3], temp[3];
		ominus_d(params.laser, ominus_laser);
		oplus_d(ominus_laser, odometry, temp);
		oplus_d(temp, params.laser, params.first_guess);
		
		/* Do the actual work */
		switch(p.algo) {
			case(0):
				sm_icp(&params, &result); break;
			case(1):
				sm_gpm(&params, &result); break;
			case(2):
				sm_hsm(&params, &result); break;
			default:
				sm_error("Unknown algorithm to run: %d.\n",p.algo);
				return -1;
		}
		
		if(!result.valid){
			if(p.recover_from_error) {
				sm_info("One ICP matching failed. Because you passed  -recover_from_error, I will try to recover."
				" Note, however, that this might not be good in some cases. \n");
				sm_info("The recover is that the displacement is set to 0. No result stats is output. \n");
				
				/* For the first scan, set estimate = odometry */
				copy_d(laser_ref->estimate, 3, laser_sens->estimate);
				
				ld_free(laser_ref); laser_ref = laser_sens;
				
			} else {
				sm_error("One ICP matching failed. Because I process recursively, I will stop here.\n");
				sm_error("Use the option -recover_from_error if you want to try to recover.\n");
				ld_free(laser_ref);
				return 2;
			}
		} else {
		
			/* Add the result to the previous estimate */
			oplus_d(laser_ref->estimate, result.x, laser_sens->estimate);

			/* Write the corrected log */
			spit(laser_sens, file_out);

			/* Write the statistics (if required) */
			if(file_out_stats) {
				JO jo = result_to_json(&params, &result);
				fputs(jo_to_string(jo), file_out_stats);
				fputs("\n", file_out_stats);
				jo_free(jo);
			}

			ld_free(laser_ref); laser_ref = laser_sens;
		}
	}
	ld_free(laser_ref);
	
	return 0;
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
	ERR_VALUE ret = ERR_INTERNAL_ERROR;

	utils_allocator_init(omp_get_num_procs());
	omp_init_lock(&_readCoverageLock);
#ifdef _MSC_VER
	uint64_t startTime = GetTickCount64();
#endif
	ret = options_module_init(37);
	if (ret == ERR_SUCCESS) {
		ret = _init_default_values();
		if (ret == ERR_SUCCESS) {
			ret = options_parse_command_line(argc - 2, argv + 2);
			if (ret == ERR_SUCCESS) {
				PROGRAM_OPTIONS po;
				PROGRAM_STATISTICS st;

				memset(&st, 0, sizeof(st));
				ret = _capture_program_options(&po);
				if (ret == ERR_SUCCESS) {
					omp_set_num_threads(po.OMPThreads);
					const char *cmd = argv[1];
					if (strncmp(cmd, "help", sizeof("help")) == 0) {
						options_print_help();
					} else if (strncmp(cmd, "repair", sizeof("repair")) == 0) {
						size_t refSeqLen = 0;
						FASTA_FILE seqFile;
						char *rsFasta = NULL;

						ret = fasta_load(po.RefSeqFile, &seqFile);
						if (ret == ERR_SUCCESS) {
							ret = fasta_read_seq(&seqFile, &rsFasta, &refSeqLen);
							po.ReferenceSequence = rsFasta;
							if (ret != ERR_SUCCESS)
								fasta_free(&seqFile);
						}

						if (ret == ERR_SUCCESS) {
							ret = utils_calloc(omp_get_num_procs(), sizeof(PUTILS_LOOKASIDE), &_vertexLAs);
							if (ret == ERR_SUCCESS)
								ret = utils_calloc(omp_get_num_procs(), sizeof(PUTILS_LOOKASIDE), &_edgeLAs);

							if (ret == ERR_SUCCESS) {
								ret = utils_calloc(omp_get_num_procs(), sizeof(GEN_ARRAY_ONE_READ), &po.ReadSubArrays);
								if (ret == ERR_SUCCESS) {
									const size_t numThreads = omp_get_num_procs();
									for (size_t i = 0; i < numThreads; ++i) {
										dym_array_init_ONE_READ(po.ReadSubArrays + i, 140);
										_vertexLAs[i] = NULL;
										_edgeLAs[i] = NULL;
									}

									size_t regionCount = 0;
									PACTIVE_REGION regions = NULL;

									ret = input_refseq_to_regions(po.ReferenceSequence, refSeqLen, &regions, &regionCount);
									if (ret == ERR_SUCCESS) {
										const ACTIVE_REGION *pa = NULL;

										pa = regions;
										for (size_t i = 0; i < regionCount; ++i) {
											if (pa->Type == artValid && pa->Length >= po.RegionLength)
												_activeRegionCount += (pa->Length / po.TestStep);

											++pa;
										}

										_activeRegionProcessed = 0;
										pa = regions;
										for (size_t i = 0; i < regionCount; ++i) {
											if (pa->Type == artValid && pa->Length >= po.RegionLength)
												repair_reads_in_parallel(pa, &po);
													
											++pa;
										}

										input_free_regions(regions, regionCount);
									}

									PONE_READ r = po.Reads;
									for (size_t i = 0; i < po.ReadCount; ++i) {
										if (r->NumberOfFixes * 100 / r->ReadSequenceLen <= po.ParseOptions.ReadMaxErrorRate) {
											read_quality_encode(r);
											read_write_sam(stdout, r);
											read_quality_decode(r);
										}

										++r;
									}

									utils_free(rsFasta);
									int i = 0;
#pragma omp parallel for shared (po)
									for (i = 0; i < numThreads; ++i)
										dym_array_finit_ONE_READ(po.ReadSubArrays + i);

									utils_free(po.ReadSubArrays);
								}
							}

							utils_free(_edgeLAs);
							utils_free(_vertexLAs);
							fasta_free(&seqFile);
						}
					} else if (strncmp(cmd, "rfreq", sizeof("rfreq")) == 0) {
						kmer_freq_distribution(&po, po.KMerSize, po.Reads, po.ReadCount);
					} else if (strncmp(cmd, "call", sizeof("call")) == 0) {
						fprintf(stderr, "K-mer size:                 %u\n", po.KMerSize);
						fprintf(stderr, "Active region length:       %u\n", po.RegionLength);
						fprintf(stderr, "Reference:                  %s\n", po.RefSeqFile);
						fprintf(stderr, "Reads:                      %u\n", po.ReadCount);
						fprintf(stderr, "Read coverage threshold:    %u\n", po.Threshold);
						fprintf(stderr, "Min. read position quality: %u\n", po.ReadPosQuality);
						fprintf(stderr, "OpenMP thread count:        %i\n", po.OMPThreads);
						fprintf(stderr, "Output VCF file:            %s\n", po.VCFFile);
						ret = paired_reads_init();
						if (ret == ERR_SUCCESS) {
							if (ret == ERR_SUCCESS) {
								size_t refSeqLen = 0;
								FASTA_FILE seqFile;
								char *rsFasta = NULL;

								ret = fasta_load(po.RefSeqFile, &seqFile);
								if (ret == ERR_SUCCESS) {
									ret = fasta_read_seq(&seqFile, &rsFasta, &refSeqLen);
									po.ReferenceSequence = rsFasta;
									if (ret != ERR_SUCCESS)
										fasta_free(&seqFile);
								}

								if (ret == ERR_SUCCESS) {
									po.VCFFileHandle = NULL;
									if (*po.VCFFile != '\0') {
										ret = utils_fopen(po.VCFFile, FOPEN_MODE_WRITE, &po.VCFFileHandle);
										if (ret == ERR_SUCCESS)
											dym_array_init_VARIANT_CALL(&po.VCArray, 140);
									}

									if (ret == ERR_SUCCESS) {
										ret = utils_calloc(omp_get_num_procs(), sizeof(PUTILS_LOOKASIDE), &_vertexLAs);
										if (ret == ERR_SUCCESS)
											ret = utils_calloc(omp_get_num_procs(), sizeof(PUTILS_LOOKASIDE), &_edgeLAs);
										
										ret = utils_calloc(omp_get_num_procs(), sizeof(GEN_ARRAY_VARIANT_CALL), &po.VCSubArrays);
										if (ret == ERR_SUCCESS) {
											ret = utils_calloc(omp_get_num_procs(), sizeof(GEN_ARRAY_ONE_READ), &po.ReadSubArrays);
											if (ret == ERR_SUCCESS) {
												const size_t numThreads = omp_get_num_procs();
												for (size_t i = 0; i < numThreads; ++i) {
													dym_array_init_VARIANT_CALL(po.VCSubArrays + i, 140);
													dym_array_init_ONE_READ(po.ReadSubArrays + i, 140);
													_vertexLAs[i] = NULL;
													_edgeLAs[i] = NULL;
												}

												size_t regionCount = 0;
												PACTIVE_REGION regions = NULL;

												ret = input_refseq_to_regions(po.ReferenceSequence, refSeqLen, &regions, &regionCount);
												if (ret == ERR_SUCCESS) {
													const ACTIVE_REGION *pa = NULL;

													pa = regions;
													for (size_t i = 0; i < regionCount; ++i) {
														if (pa->Type == artValid && pa->Length >= po.RegionLength)
															_activeRegionCount += (pa->Length / po.TestStep);

														++pa;
													}
														
													_activeRegionProcessed = 0;
													pa = regions;
													for (size_t i = 0; i < regionCount; ++i) {
														if (pa->Type == artValid && pa->Length >= po.RegionLength)
															process_active_region_in_parallel(pa, &po);
														
														++pa;
													}
														
													input_free_regions(regions, regionCount);
												}

												utils_free(rsFasta);
												ret = vc_array_merge(&po.VCArray, po.VCSubArrays, numThreads);
												int i = 0;
#pragma omp parallel for shared(po)
												for (i = 0; i <(int) numThreads; ++i) {
													dym_array_finit_ONE_READ(po.ReadSubArrays + i);
													vc_array_finit(po.VCSubArrays + i);
												}

												utils_free(po.ReadSubArrays);
											}

											utils_free(po.VCSubArrays);
										}

										utils_free(_edgeLAs);
										utils_free(_vertexLAs);

										if (po.VCFFileHandle != NULL) {
											if (ret == ERR_SUCCESS)
												vc_array_print(po.VCFFileHandle, &po.VCArray);

											vc_array_finit(&po.VCArray);
											utils_fclose(po.VCFFileHandle);
										}

									}

									fasta_free(&seqFile);
								}
							} else printf("fix_reads(): %u\n", ret);

							printf("Read coverage: %lf\n", _readBaseCount / _totalRegionLength );
							paired_reads_finit();
						}
					}
				}
			}
		}
	
		options_module_finit();
	}

#ifdef _MSC_VER
	uint64_t endTime = GetTickCount64();
	fprintf(stderr, "Time: %I64u s\n", (endTime - startTime) / 1000);
#endif
	omp_destroy_lock(&_readCoverageLock);

	return ret;
}
Ejemplo n.º 12
0
int main(int argc, char **argv) {
    SPDConnection *conn;
    SPDPriority spd_priority;
    int err;
    char *error;
    int msg_arg_required = 0;
    int ret;
    int option_ret;
    char *line;

    rate = -101;
    pitch = -101;
    volume = -101;
    language = NULL;
    voice_type = NULL;
    punctuation_mode = NULL;
    spelling = -2;
    ssml_mode = 0;
    wait_till_end = 0;
    stop_previous = 0;
    cancel_previous = 0;
    pipe_mode = 0;
    priority = NULL;
    application_name = NULL;
    connection_name = NULL;

    option_ret = options_parse(argc, argv);

    /* Check if the text to say or options are specified in the argument */
    msg_arg_required = (pipe_mode != 1) && (stop_previous != 1)
                       && (cancel_previous != 1);
    if ((optind >= argc) && msg_arg_required) {
        options_print_help(argv);
        return 1;
    }

    /* Open a connection to Speech Dispatcher */
    conn = spd_open2(application_name ? application_name : "spd-say",
                    connection_name ? connection_name : "main",
		     NULL, SPD_MODE_THREADED, NULL, 1, &error);
    if (conn == NULL){
      fprintf(stderr, "Failed to connect to Speech Dispatcher:\n%s\n", error);
      exit(1);
    }

    if (stop_previous) spd_stop_all(conn);
    if (cancel_previous) spd_cancel_all(conn);

    /* Set the desired parameters */

    if (language != NULL)
        if(spd_set_language(conn, language))
            printf("Invalid language!\n");

    if (output_module != NULL)
        if(spd_set_output_module(conn, output_module))
            printf("Invalid output module!\n");

    if (voice_type != NULL){
        if (!strcmp(voice_type, "male1")){
            if(spd_set_voice_type(conn, SPD_MALE1))
                printf("Can't set this voice!\n");
        }
        else if(!strcmp(voice_type, "male2")){
            if(spd_set_voice_type(conn, SPD_MALE2))
                printf("Can't set this voice!\n");
        }
        else if(!strcmp(voice_type, "male3")){
            if(spd_set_voice_type(conn, SPD_MALE3))
            printf("Can't set this voice!\n");
        }
        else if(!strcmp(voice_type, "female1")){
            if(spd_set_voice_type(conn, SPD_FEMALE1))
                printf("Can't set this voice!\n");
        }
        else if(!strcmp(voice_type, "female2")){
            if(spd_set_voice_type(conn, SPD_FEMALE2))
                printf("Can't set this voice!\n");
        }
        else if(!strcmp(voice_type, "female3")){
            if(spd_set_voice_type(conn, SPD_FEMALE3))
                printf("Can't set this voice!\n");
        }
        else if(!strcmp(voice_type, "child_male")){
            if(spd_set_voice_type(conn, SPD_CHILD_MALE))
                printf("Can't set this voice!\n");
        }
        else if(!strcmp(voice_type, "child_female")){
            if(spd_set_voice_type(conn, SPD_CHILD_FEMALE))
                printf("Can't set this voice!\n");
        }else{
            printf("Invalid voice\n");
        }
    }

    if (ssml_mode)
        if(spd_execute_command(conn, "SET SELF SSML_MODE ON"))
            printf("Failed to set SSML mode.\n");

    if (rate != -101)
        if(spd_set_voice_rate(conn, rate))
            printf("Invalid rate!\n");

    if (pitch != -101)
        if(spd_set_voice_pitch(conn, pitch))
            printf("Invalid pitch!\n");

    if (volume != -101)
        if(spd_set_volume(conn, volume))
            printf("Invalid volume!\n");

    if (spelling == 1)
        if(spd_set_spelling(conn, SPD_SPELL_ON))
            printf("Can't set spelling to on!\n");

    if (punctuation_mode != NULL){
        if (!strcmp(punctuation_mode, "none")){
            if(spd_set_punctuation(conn, SPD_PUNCT_NONE))
                printf("Can't set this punctuation mode!\n");
        }
        else if(!strcmp(punctuation_mode, "some")){
            if(spd_set_punctuation(conn, SPD_PUNCT_SOME))
                printf("Can't set this punctuation mode!\n");
        }
        else if(!strcmp(punctuation_mode, "all")){
            if(spd_set_punctuation(conn, SPD_PUNCT_ALL))
                printf("Can't set this punctuation mode!\n");
        }else{
            printf("Invalid punctuation mode.\n");
        }
    }

    /* Set default priority... */
    if (1 == pipe_mode)
        spd_priority = SPD_MESSAGE;
    else
        spd_priority = SPD_TEXT;
    /* ...and look if it wasn't overriden */
    if (priority != NULL){
        if (!strcmp(priority, "important")) spd_priority = SPD_IMPORTANT;
        else if (!strcmp(priority, "message")) spd_priority = SPD_MESSAGE;
        else if (!strcmp(priority, "text")) spd_priority = SPD_TEXT;
        else if (!strcmp(priority, "notification")) spd_priority = SPD_NOTIFICATION;
        else if (!strcmp(priority, "progress")) spd_priority = SPD_PROGRESS;
        else{
            printf("Invalid priority.\n");
        }
    }

    if (wait_till_end){
        ret = sem_init(&semaphore, 0, 0);
        if (ret < 0){
            fprintf(stderr, "Can't initialize semaphore: %s", strerror(errno));
            return 0;
        }

        /* Notify when the message is canceled or the speech terminates */
        conn->callback_end = end_of_speech;
        conn->callback_cancel = end_of_speech;
        spd_set_notification_on(conn, SPD_END);
        spd_set_notification_on(conn, SPD_CANCEL);
    }

    /* In pipe mode, read from stdin, write to stdout, and also to Speech Dispatcher. */
    if (pipe_mode == 1) {
        line = (char *) malloc( MAX_LINELEN );
        while (NULL != fgets(line, MAX_LINELEN, stdin)) {
            fputs(line, stdout);
            if (0 == strncmp(line, "!-!", 3)) {
                /* Remove EOL */
                line[strlen(line)-1] = 0;
                spd_execute_command(conn, line + 3);
            } else {
                spd_say(conn, spd_priority, line);
                if (wait_till_end) sem_wait(&semaphore);
            }
        }
        free(line);

    } else {
        /* Say the message with priority "text" */
        /* Or do nothing in case of -C or -S with no message. */
        if (optind < argc) {
	  err = spd_sayf(conn, spd_priority, (char*) argv[optind]);
	  if (err == -1){
	    fprintf(stderr, "Speech Dispatcher failed to say message");
	    exit(1);
	  }

          /* Wait till the callback is called */
          if (wait_till_end) sem_wait(&semaphore);
        }
    }

    /* Close the connection */
    spd_close(conn);

    return 0;
}
Ejemplo n.º 13
0
int main(int argc, char **argv) {
  struct gengetopt_args_info args_info;
  struct hostent *host;
  char hostname[USERURLSIZE];
  int numargs;
  int ret = -1;
  int i;

  options_init();

  memset(&args_info, 0, sizeof(args_info));

  if (cmdline_parser2(argc, argv, &args_info, 1, 1, 1) != 0) {
    log_err(0, "Failed to parse command line options");
    goto end_processing;
  }
  
  if (args_info.version_given) {
    options_print_version();
    exit(2);
  }

  if (args_info.help_given) {
    options_print_help();
    exit(2);
  }

  if (cmdline_parser_configfile(args_info.conf_arg ? 
				args_info.conf_arg : 
				DEFCHILLICONF, 
				&args_info, 0, 0, 0)) {
    log_err(0, "Failed to parse configuration file: %s!", 
	    args_info.conf_arg);
    if (!args_info.forgiving_flag)
      goto end_processing;
  }

  /* Get the system default DNS entries */
  if (res_init()) {
    log_err(0, "Failed to update system DNS settings (res_init()!");
    goto end_processing;
  }

  /* Handle each option */
  _options.initialized = 1;

  if (args_info.debug_flag) 
    _options.debug = args_info.debugfacility_arg;
  else 
    _options.debug = 0;

  /* pass-throughs */
  memset(_options.pass_throughs, 0, sizeof(_options.pass_throughs));
  _options.num_pass_throughs = 0;

  /** simple configuration parameters **/
  _options.layer3 = args_info.layer3_flag;
#if(_debug_ && !defined(ENABLE_LAYER3))
  if (_options.layer3) 
    log_warn(0, "layer3 not implemented. build with --enable-layer3");
#endif
  _options.uid = args_info.uid_arg;
  _options.gid = args_info.gid_arg;
  _options.mtu = args_info.mtu_arg;
  _options.usetap = args_info.usetap_flag;
  _options.noarpentries = args_info.noarpentries_flag;
#if(_debug_ && !defined(ENABLE_TAP))
  if (_options.noarpentries) 
    log_warn(0, "tap not implemented. build with --enable-tap");
#endif
#if(_debug_ && !defined(ENABLE_TAP))
  if (_options.usetap) 
    log_warn(0, "tap not implemented. build with --enable-tap");
#endif
  _options.foreground = args_info.fg_flag;
  _options.interval = args_info.interval_arg;
  _options.lease = args_info.lease_arg;
  _options.leaseplus = args_info.leaseplus_arg;
  _options.dhcpstart = args_info.dhcpstart_arg;
  _options.dhcpend = args_info.dhcpend_arg;
  _options.eapolenable = args_info.eapolenable_flag;
#if(_debug_ && !defined(ENABLE_EAPOL))
  if (_options.eapolenable) 
    log_warn(0, "EAPOL not implemented. build with --enable-eapol");
#endif
  _options.swapoctets = args_info.swapoctets_flag;
  _options.logfacility = args_info.logfacility_arg;
  _options.chillixml = args_info.chillixml_flag;
  _options.macauth = args_info.macauth_flag;
  _options.macreauth = args_info.macreauth_flag;
  _options.macauthdeny = args_info.macauthdeny_flag;
  _options.uamport = args_info.uamport_arg;
#ifdef ENABLE_UAMUIPORT
  _options.uamuiport = args_info.uamuiport_arg;
#endif
  _options.macallowlocal = args_info.macallowlocal_flag;
  _options.strictmacauth = args_info.strictmacauth_flag;
  _options.strictdhcp = args_info.strictdhcp_flag;
  _options.no_wispr1 = args_info.nowispr1_flag;
  _options.no_wispr2 = args_info.nowispr2_flag;
  _options.wpaguests = args_info.wpaguests_flag;
  _options.openidauth = args_info.openidauth_flag;
  _options.challengetimeout = args_info.challengetimeout_arg;
  _options.challengetimeout2 = args_info.challengetimeout2_arg;
  _options.defsessiontimeout = args_info.defsessiontimeout_arg;
  _options.definteriminterval = args_info.definteriminterval_arg;
  _options.defbandwidthmaxdown = args_info.defbandwidthmaxdown_arg;
  _options.defbandwidthmaxup = args_info.defbandwidthmaxup_arg;
  _options.defidletimeout = args_info.defidletimeout_arg;
  _options.radiusnasporttype = args_info.radiusnasporttype_arg;
  _options.radiusauthport = args_info.radiusauthport_arg;
  _options.radiusacctport = args_info.radiusacctport_arg;
  _options.coaport = args_info.coaport_arg;
  _options.coanoipcheck = args_info.coanoipcheck_flag;
  _options.radiustimeout = args_info.radiustimeout_arg;
  _options.radiusretry = args_info.radiusretry_arg;
  _options.radiusretrysec = args_info.radiusretrysec_arg;
#ifdef ENABLE_RADPROXY
  _options.proxyport = args_info.proxyport_arg;
  _options.proxymacaccept = args_info.proxymacaccept_flag;
  _options.proxyonacct = args_info.proxyonacct_flag;
#endif
#if(_debug_ && !defined(ENABLE_RADPROXY))
  if (args_info.proxyport_arg)
    log_err(0,"radproxy not implemented. build with --enable-radproxy");
#endif
  _options.txqlen = args_info.txqlen_arg;
  _options.ringsize = args_info.ringsize_arg;
  _options.sndbuf = args_info.sndbuf_arg;
  _options.rcvbuf = args_info.rcvbuf_arg;
  _options.childmax = args_info.childmax_arg;
  _options.postauth_proxyport = args_info.postauthproxyport_arg;
  _options.pap_always_ok = args_info.papalwaysok_flag;
  _options.mschapv2 = args_info.mschapv2_flag;
  _options.acct_update = args_info.acctupdate_flag;
  _options.dhcpradius = args_info.dhcpradius_flag;
  _options.dhcp_broadcast = args_info.dhcpbroadcast_flag;
  _options.dhcpgwport = args_info.dhcpgatewayport_arg;
  _options.noc2c = args_info.noc2c_flag;
  _options.tcpwin = args_info.tcpwin_arg;
  _options.tcpmss = args_info.tcpmss_arg;
  _options.max_clients = args_info.maxclients_arg;
  _options.radiusqsize = args_info.radiusqsize_arg;
  _options.dhcphashsize = args_info.dhcphashsize_arg;
  _options.uamdomain_ttl = args_info.uamdomainttl_arg;
  _options.seskeepalive = args_info.seskeepalive_flag;
  _options.uamallowpost = args_info.uamallowpost_flag;
  _options.redir = args_info.redir_flag;
  _options.redirurl = args_info.redirurl_flag;
  _options.statusfilesave = args_info.statusfilesave_flag;
  _options.dhcpnotidle = args_info.dhcpnotidle_flag;
#if(_debug_ && !defined(ENABLE_CHILLIREDIR))
  if (_options.redir) 
    log_err(0, "chilli_redir not implemented. build with --enable-chilliredir");
#endif
  _options.redirssl = args_info.redirssl_flag;
  _options.uamuissl = args_info.uamuissl_flag;
  _options.domaindnslocal = args_info.domaindnslocal_flag;
  _options.framedservice = args_info.framedservice_flag;
  _options.radsec = args_info.radsec_flag;
#if(_debug_ && !defined(ENABLE_CHILLIRADSEC))
  if (_options.radsec) 
    log_err(0, "chilli_radsec not implemented. build with --enable-chilliradsec");
#endif
  _options.noradallow = args_info.noradallow_flag;
  _options.peerid = args_info.peerid_arg;
#if(_debug_ && !defined(ENABLE_CLUSTER))
  if (_options.peerid) 
    log_err(0, "clustering not implemented. build with --enable-cluster");
#endif
  _options.redirdnsreq = args_info.redirdnsreq_flag;
#if(_debug_ && !defined(ENABLE_REDIRDNSREQ))
  if (_options.redirdnsreq) 
    log_err(0, "redirdnsreq not implemented. build with --enable-redirdnsreq");
#endif

#ifdef ENABLE_IPV6
  _options.ipv6 = args_info.ipv6_flag;
  _options.ipv6only = args_info.ipv6only_flag;
#endif

#ifdef ENABLE_LEAKYBUCKET
  _options.scalewin = args_info.scalewin_flag;
  _options.bwbucketupsize = args_info.bwbucketupsize_arg;
  _options.bwbucketdnsize = args_info.bwbucketdnsize_arg;
  _options.bwbucketminsize = args_info.bwbucketminsize_arg;
#endif

#ifdef ENABLE_PROXYVSA
  _options.vlanlocation = args_info.vlanlocation_flag;
  _options.location_stop_start = args_info.locationstopstart_flag;
  _options.location_copy_called = args_info.locationcopycalled_flag;
  _options.location_immediate_update = args_info.locationimmediateupdate_flag;
  _options.location_option_82 = args_info.locationopt82_flag;
  if (args_info.proxylocattr_given) {
    for (numargs = 0; numargs < args_info.proxylocattr_given 
	   && numargs < PROXYVSA_ATTR_CNT; ++numargs)  {
      unsigned int i[2];

      switch (sscanf(args_info.proxylocattr_arg[numargs], 
		     "%u,%u", &i[0], &i[1])) {
      case 0:
	log_err(0, "invalid input %s", args_info.proxylocattr_arg[numargs]);
	break;
      case 1:
	_options.proxy_loc[numargs].attr = i[0];
	break;
      case 2:
	_options.proxy_loc[numargs].attr_vsa = i[0];
	_options.proxy_loc[numargs].attr = i[1];
	break;
      }
      
      log_dbg("Proxy location attr %d %d", 
	      (int)_options.proxy_loc[numargs].attr_vsa, 
	      (int)_options.proxy_loc[numargs].attr);
    }
  }
#endif

  if (args_info.dhcpgateway_arg &&
      !inet_aton(args_info.dhcpgateway_arg, &_options.dhcpgwip)) {
    log_err(0, "Invalid DHCP gateway IP address: %s!", args_info.dhcpgateway_arg);
    if (!args_info.forgiving_flag)
      goto end_processing;
  }

  if (args_info.dhcprelayagent_arg &&
      !inet_aton(args_info.dhcprelayagent_arg, &_options.dhcprelayip)) {
    log_err(0, "Invalid DHCP gateway relay IP address: %s!", args_info.dhcprelayagent_arg);
    if (!args_info.forgiving_flag)
      goto end_processing;
  }

  _options.dhcpif = STRDUP(args_info.dhcpif_arg);

#ifdef ENABLE_MULTILAN
  for (numargs = 0; numargs < args_info.moreif_given &&
	 numargs < MAX_MOREIF; ++numargs) {
    char *nif = STRDUP(args_info.moreif_arg[numargs]);
    char *vln = strchr(nif, '/');
    _options.moreif[numargs].dhcpif = nif;
    if (vln) {
      if (strlen(vln) > 1) 
	_options.moreif[numargs].vlan = vln + 1;
      *vln = 0;
    } else {
      vln = strchr(nif, '.');
      if (vln && strlen(vln) > 1) 
	_options.moreif[numargs].vlan = vln + 1;
    }
  }
#endif

  if (!args_info.radiussecret_arg) {
    log_err(0, "radiussecret must be specified!");
    if (!args_info.forgiving_flag)
      goto end_processing;
  }

  if (!args_info.nexthop_arg) {
    memset(_options.nexthop, 0, PKT_ETH_ALEN);
    _options.has_nexthop = 0;
  }
  else {
    unsigned int temp[PKT_ETH_ALEN];
    char macstr[RADIUS_ATTR_VLEN];
    int macstrlen;
    int	i;

    if ((macstrlen = strlen(args_info.nexthop_arg)) >= (RADIUS_ATTR_VLEN-1)) {
      log_err(0, "MAC address too long");
      if (!args_info.forgiving_flag)
	goto end_processing;
    }

    memcpy(macstr, args_info.nexthop_arg, macstrlen);
    macstr[macstrlen] = 0;

    /* Replace anything but hex with space */
    for (i=0; i<macstrlen; i++) 
      if (!isxdigit((int) macstr[i])) 
	macstr[i] = 0x20;

    if (sscanf (macstr, "%2x %2x %2x %2x %2x %2x", 
		&temp[0], &temp[1], &temp[2], 
		&temp[3], &temp[4], &temp[5]) != 6) {
      log_err(0, "MAC conversion failed!");
      return -1;
    }
    
    for (i = 0; i < PKT_ETH_ALEN; i++) 
      _options.nexthop[i] = temp[i];

    _options.has_nexthop = 1;
  }

  if (!args_info.dhcpmac_arg) {
    memset(_options.dhcpmac, 0, PKT_ETH_ALEN);
    _options.dhcpusemac = 0;
    _options.dhcpmacset = 0;
  }
  else {
    unsigned int temp[PKT_ETH_ALEN];
    char macstr[RADIUS_ATTR_VLEN];
    int macstrlen;
    int	i;

    if ((macstrlen = strlen(args_info.dhcpmac_arg)) >= (RADIUS_ATTR_VLEN-1)) {
      log_err(0, "MAC address too long");
      if (!args_info.forgiving_flag)
	goto end_processing;
    }

    memcpy(macstr, args_info.dhcpmac_arg, macstrlen);
    macstr[macstrlen] = 0;

    /* Replace anything but hex with space */
    for (i=0; i<macstrlen; i++) 
      if (!isxdigit((int) macstr[i])) 
	macstr[i] = 0x20;

    if (sscanf (macstr, "%2x %2x %2x %2x %2x %2x", 
		&temp[0], &temp[1], &temp[2], 
		&temp[3], &temp[4], &temp[5]) != 6) {
      log_err(0, "MAC conversion failed!");
      return -1;
    }
    
    for (i = 0; i < PKT_ETH_ALEN; i++) 
      _options.dhcpmac[i] = temp[i];

    _options.dhcpusemac = 1;
    _options.dhcpmacset = args_info.dhcpmacset_flag;
  }

  if (args_info.net_arg) {
    if (option_aton(&_options.net, &_options.mask, args_info.net_arg, 0)) {
      log_err(0, "Invalid network address: %s!", args_info.net_arg);
      if (!args_info.forgiving_flag)
	goto end_processing;
    }
    if (!args_info.uamlisten_arg) {
      _options.uamlisten.s_addr = htonl(ntohl(_options.net.s_addr)+1);
    }
    else if (!inet_aton(args_info.uamlisten_arg, &_options.uamlisten)) {
      log_err(0, "Invalid UAM IP address: %s!", args_info.uamlisten_arg);
      if (!args_info.forgiving_flag)
	goto end_processing;
    }
    if (!args_info.dhcplisten_arg) {
      _options.dhcplisten.s_addr = _options.uamlisten.s_addr;
    }
    else if (!inet_aton(args_info.dhcplisten_arg, &_options.dhcplisten)) {
      log_err(0, "Invalid DHCP IP address: %s!", args_info.dhcplisten_arg);
      if (!args_info.forgiving_flag)
	goto end_processing;
    }
  }
  else {
    log_err(0, "Network address must be specified ('net' parameter)!");
    if (!args_info.forgiving_flag)
      goto end_processing;
  }

  log_dbg("DHCP Listen: %s", inet_ntoa(_options.dhcplisten));
  log_dbg("UAM Listen: %s", inet_ntoa(_options.uamlisten));

  if (!args_info.uamserver_arg) {
    log_err(0, "WARNING: No uamserver defiend!");
  }

  if (args_info.uamserver_arg) {
    int uamserverport=80;

    if (_options.debug & DEBUG_CONF) {
      log_dbg("Uamserver: %s\n", args_info.uamserver_arg);
    }

    if (get_urlparts(args_info.uamserver_arg, hostname, USERURLSIZE, 
		     &uamserverport, 0)) {
      log_err(0, "Failed to parse uamserver: %s!", args_info.uamserver_arg);
      if (!args_info.forgiving_flag)
	goto end_processing;
    }

    if (!args_info.uamaliasname_arg ||
	strncmp(args_info.uamaliasname_arg, hostname, 
		strlen(args_info.uamaliasname_arg))) {
      if (!(host = gethostbyname(hostname))) {
	log_err(0, "Could not resolve IP address of uamserver: %s!", 
		args_info.uamserver_arg);
      }
      else {
	int j = 0;
	pass_through pt;

	memset(&pt, 0, sizeof(pt));
	pt.port = uamserverport;
	pt.mask.s_addr = ~0;

	while (host->h_addr_list[j] != NULL) {
	  if (_options.debug & DEBUG_CONF) {
	    log_dbg("Uamserver IP address #%d: %s\n", j,
		    inet_ntoa(*(struct in_addr*) host->h_addr_list[j]));
	  }

	  pt.host.s_addr = ((struct in_addr*) host->h_addr_list[j++])->s_addr;

	  if (pass_through_add(_options.pass_throughs,
			       MAX_PASS_THROUGHS,
			       &_options.num_pass_throughs, &pt, 0
#ifdef HAVE_PATRICIA
			       , 0
#endif
			       ))
	    log_err(0, "Too many pass-throughs! skipped %s:%d",
		    inet_ntoa(pt.host), pt.port);
	}
      }
    }
  }

  _options.uamanydns = args_info.uamanydns_flag;
#ifdef ENABLE_UAMANYIP
  _options.uamanyip = args_info.uamanyip_flag;
  _options.uamnatanyip = args_info.uamnatanyip_flag;
#endif
  _options.dnsparanoia = args_info.dnsparanoia_flag;
  _options.radiusoriginalurl = args_info.radiusoriginalurl_flag;
  _options.routeonetone = args_info.routeonetone_flag;

#ifdef HAVE_PATRICIA
  _options.patricia = args_info.patricia_flag;
#endif

#ifdef ENABLE_GARDENACCOUNTING
  _options.nousergardendata = args_info.nousergardendata_flag;
  _options.uamgardendata = args_info.uamgardendata_flag;
  _options.uamotherdata = args_info.uamotherdata_flag;
#endif

  for (numargs = 0; numargs < args_info.uamallowed_given; ++numargs) {
    pass_throughs_from_string(_options.pass_throughs,
			      MAX_PASS_THROUGHS,
			      &_options.num_pass_throughs,  
			      args_info.uamallowed_arg[numargs], 0, 0
#ifdef HAVE_PATRICIA
			      , 0
#endif
);
  }

#ifdef ENABLE_DHCPOPT
  _options.dhcp_options_len = 0;
  for (numargs = 0; numargs < args_info.dhcpopt_given; ++numargs) {
    unsigned char binopt[128];
    int hex_length = strlen(args_info.dhcpopt_arg[numargs]);
    int bin_length = hex_length / 2;
    if (hex_length > 0 && (bin_length * 2) == hex_length &&
	bin_length < sizeof(binopt)) {
      log_dbg("DHCP Options %s", args_info.dhcpopt_arg[numargs]);
      if (redir_hextochar((unsigned char *)args_info.dhcpopt_arg[numargs],
			  hex_length, binopt, bin_length) == 0) {
	if (_options.dhcp_options_len + bin_length < 
	    sizeof(_options.dhcp_options)) {
	  memcpy(_options.dhcp_options + 
		 _options.dhcp_options_len, 
		 binopt, bin_length);
	  _options.dhcp_options_len += bin_length;
	} else {
	  log_dbg("No room for DHCP option %d", (int)binopt[0]);
	}
      } else {
	log_dbg("Bad DHCP option hex encoding");
      }
    } else {
      log_dbg("DHCP options are hex encoded binary");
    }
  }
#endif

#ifdef ENABLE_MODULES
  memset(_options.modules, 0, sizeof(_options.modules));
  for (numargs = 0; numargs < args_info.module_given; ++numargs) {
    if (numargs < MAX_MODULES) {
      char *n, *sc;
      int len, nlen;

      n = args_info.module_arg[numargs];
      len = strlen(n);
      sc = strchr(n, ';');
      if (!sc) sc = strchr(n, ':');
      nlen = sc ? (sc - n) : len;

      safe_snprintf(_options.modules[numargs].name, 
		    sizeof(_options.modules[numargs].name),
		    "%.*s", nlen, n);
      if (sc && len > (nlen + 1)) {
	safe_snprintf(_options.modules[numargs].conf, 
		      sizeof(_options.modules[numargs].conf),
		      "%.*s", len - nlen - 1, sc + 1);
      }
    }
  }
#endif

#ifdef ENABLE_CHILLIREDIR
  /*
  for (numargs = 0; numargs < MAX_REGEX_PASS_THROUGHS; ++numargs) {
    if (_options.regex_pass_throughs[numargs].re_host.allocated)
      regfree(&_options.regex_pass_throughs[numargs].re_host);
    if (_options.regex_pass_throughs[numargs].re_path.allocated)
      regfree(&_options.regex_pass_throughs[numargs].re_path);
    if (_options.regex_pass_throughs[numargs].re_qs.allocated)
      regfree(&_options.regex_pass_throughs[numargs].re_qs);
  }
  */
  
  memset(_options.regex_pass_throughs, 0, sizeof(_options.regex_pass_throughs));
  _options.regex_num_pass_throughs = 0;
  
  for (numargs = 0; numargs < args_info.uamregex_given; ++numargs) {
    regex_pass_throughs_from_string(_options.regex_pass_throughs,
				    MAX_REGEX_PASS_THROUGHS,
				    &_options.regex_num_pass_throughs,  
				    args_info.uamregex_arg[numargs], 0);
  }
#endif

  for (numargs = 0; numargs < MAX_UAM_DOMAINS; ++numargs) {
    if (_options.uamdomains[numargs])
      free(_options.uamdomains[numargs]);
    _options.uamdomains[numargs] = 0;
  }

  if (args_info.uamdomain_given) {
    for (numargs = 0, i=0; 
	 numargs < args_info.uamdomain_given && i < MAX_UAM_DOMAINS; 
	 ++numargs) {
      char *tb = args_info.uamdomain_arg[numargs];
      char *tok, *str, *ptr;
      for (str = tb ; i < MAX_UAM_DOMAINS; str = NULL) {
	tok = strtok_r(str, ",", &ptr);
	if (!tok) break;
	log_dbg("uamdomain %s", tok);
	_options.uamdomains[i++] = STRDUP(tok);
      }
    }
  }

  _options.allowdyn = 1;
  
#ifdef ENABLE_UAMANYIP
  _options.autostatip = args_info.autostatip_arg;
  if (_options.autostatip)
    _options.uamanyip = 1;
#endif
  
  if (args_info.nodynip_flag) {
    _options.allowdyn = 0;
  } else {
    if (!args_info.dynip_arg) {
      _options.dynip = STRDUP(args_info.net_arg);
    }
    else {
      struct in_addr addr;
      struct in_addr mask;
      _options.dynip = STRDUP(args_info.dynip_arg);
      if (option_aton(&addr, &mask, _options.dynip, 0)) {
	log_err(0, "Failed to parse dynamic IP address pool!");
	if (!args_info.forgiving_flag)
	  goto end_processing;
      }
    }
  }
  
  /* statip */
  if (args_info.statip_arg) {
    struct in_addr addr;
    struct in_addr mask;
    _options.statip = STRDUP(args_info.statip_arg);
    if (option_aton(&addr, &mask, _options.statip, 0)) {
      log_err(0, "Failed to parse static IP address pool!");
      return -1;
    }
    _options.allowstat = 1;
  } else {
    _options.allowstat = 0;
  }

#ifdef ENABLE_UAMANYIP
  if (args_info.uamnatanyipex_arg) {
    if (option_aton(&_options.uamnatanyipex_addr, 
		    &_options.uamnatanyipex_mask, 
		    args_info.uamnatanyipex_arg, 0)) {
      log_err(0, "Failed to parse uamnatanyipex network!");
      return -1;
    }
  }
  if (args_info.uamanyipex_arg) {
    if (option_aton(&_options.uamanyipex_addr, 
		    &_options.uamanyipex_mask, 
		    args_info.uamanyipex_arg, 0)) {
      log_err(0, "Failed to parse uamanyipex network!");
      return -1;
    }
  }
#endif
  
  if (args_info.dns1_arg) {
    if (!inet_aton(args_info.dns1_arg, &_options.dns1)) {
      log_err(0,"Invalid primary DNS address: %s!", 
	      args_info.dns1_arg);
      if (!args_info.forgiving_flag)
	goto end_processing;
    }
  }
  else if (_res.nscount >= 1) {
    _options.dns1 = _res.nsaddr_list[0].sin_addr;
  }
  else {
    _options.dns1.s_addr = 0;
  }

  if (args_info.dns2_arg) {
    if (!inet_aton(args_info.dns2_arg, &_options.dns2)) {
      log_err(0,"Invalid secondary DNS address: %s!", 
	      args_info.dns1_arg);
      if (!args_info.forgiving_flag)
	goto end_processing;
    }
  }
  else if (_res.nscount >= 2) {
    _options.dns2 = _res.nsaddr_list[1].sin_addr;
  }
  else {
    _options.dns2.s_addr = _options.dns1.s_addr;
  }


  /* If no listen option is specified listen to any local port    */
  /* Do hostname lookup to translate hostname to IP address       */
  if (args_info.radiuslisten_arg) {
    if (!(host = gethostbyname(args_info.radiuslisten_arg))) {
      log_err(0, "Invalid listening address: %s! [%s]", 
	      args_info.radiuslisten_arg, strerror(errno));
      if (!args_info.forgiving_flag)
	goto end_processing;
    }
    else {
      memcpy(&_options.radiuslisten.s_addr, host->h_addr, host->h_length);
    }
  }
  else {
    _options.radiuslisten.s_addr = htonl(INADDR_ANY);
  }

#ifdef ENABLE_NETNAT
  if (args_info.natip_arg) {
    if (!(host = gethostbyname(args_info.natip_arg))) {
      log_warn(0, "Invalid natip address: %s! [%s]", 
	       args_info.natip_arg, strerror(errno));
    }
    else {
      memcpy(&_options.natip.s_addr, host->h_addr, host->h_length);
    }
  }
#endif

  if (args_info.uamlogoutip_arg) {
    if (!(host = gethostbyname(args_info.uamlogoutip_arg))) {
      log_warn(0, "Invalid uamlogoutup address: %s! [%s]", 
	       args_info.uamlogoutip_arg, strerror(errno));
    }
    else {
      memcpy(&_options.uamlogout.s_addr, host->h_addr, host->h_length);
    }
  }

  if (args_info.uamaliasip_arg) {
    if (!(host = gethostbyname(args_info.uamaliasip_arg))) {
      log_warn(0, "Invalid uamaliasip address: %s! [%s]", 
	       args_info.uamlogoutip_arg, strerror(errno));
    }
    else {
      memcpy(&_options.uamalias.s_addr, host->h_addr, host->h_length);
    }
  }

  if (args_info.postauthproxy_arg) {
    if (!(host = gethostbyname(args_info.postauthproxy_arg))) {
      log_warn(0, "Invalid postauthproxy address: %s! [%s]", 
	       args_info.postauthproxy_arg, strerror(errno));
    }
    else {
      memcpy(&_options.postauth_proxyip.s_addr, host->h_addr, host->h_length);
    }
  }

  /* If no option is specified terminate                          */
  /* Do hostname lookup to translate hostname to IP address       */
  if (args_info.radiusserver1_arg) {
    if (!(host = gethostbyname(args_info.radiusserver1_arg))) {
      log_err(0, "Invalid radiusserver1 address: %s! [%s]", 
	      args_info.radiusserver1_arg, strerror(errno));
      if (!args_info.forgiving_flag)
	goto end_processing;
    }
    else {
      memcpy(&_options.radiusserver1.s_addr, host->h_addr, host->h_length);
    }
  }
  else {
    log_err(0,"No radiusserver1 address given!");
    if (!args_info.forgiving_flag)
      goto end_processing;
  }

  /* radiusserver2 */
  /* If no option is specified terminate                          */
  /* Do hostname lookup to translate hostname to IP address       */
  if (args_info.radiusserver2_arg) {
    if (!(host = gethostbyname(args_info.radiusserver2_arg))) {
      log_err(0, "Invalid radiusserver2 address: %s! [%s]", 
	      args_info.radiusserver2_arg, strerror(errno));
      if (!args_info.forgiving_flag)
	goto end_processing;
    }
    else {
      memcpy(&_options.radiusserver2.s_addr, host->h_addr, host->h_length);
    }
  }
  else {
    _options.radiusserver2.s_addr = 0;
  }

  /* If no listen option is specified listen to any local port    */
  /* Do hostname lookup to translate hostname to IP address       */
  if (args_info.proxylisten_arg) {
#ifdef ENABLE_RADPROXY
    if (!(host = gethostbyname(args_info.proxylisten_arg))) {
      log_err(0, "Invalid listening address: %s! [%s]", 
	      args_info.proxylisten_arg, strerror(errno));
      if (!args_info.forgiving_flag)
	goto end_processing;
    }
    else {
      memcpy(&_options.proxylisten.s_addr, host->h_addr, host->h_length);
    }
  }
  else {
    _options.proxylisten.s_addr = htonl(INADDR_ANY);
#elif (_debug_)
    log_warn(0,"radproxy not implemented. build with --enable-radproxy");
#endif
  }
  
  /* Store proxyclient as in_addr net and mask                       */
  if (args_info.proxyclient_arg) {
#ifdef ENABLE_RADPROXY
    if(option_aton(&_options.proxyaddr, &_options.proxymask, 
		   args_info.proxyclient_arg, 0)) {
      log_err(0,"Invalid proxy client address: %s!", args_info.proxyclient_arg);
      if (!args_info.forgiving_flag)
	goto end_processing;
    }
  }
  else {
    _options.proxyaddr.s_addr = ~0; /* Let nobody through */
    _options.proxymask.s_addr = 0; 
#elif (_debug_)
    log_warn(0,"radproxy not implemented. build with --enable-radproxy");
#endif
  }

  memset(_options.macok, 0, sizeof(_options.macok));
  _options.macoklen = 0;

  for (numargs = 0; numargs < args_info.macallowed_given; ++numargs) {

    char *p1 = NULL;
    char *p2 = NULL;
    char *p3 = malloc(strlen(args_info.macallowed_arg[numargs])+1);
    int i;

    unsigned int mac[6];

    log_dbg("Macallowed #%d: %s", numargs, args_info.macallowed_arg[numargs]);

    strcpy(p3, args_info.macallowed_arg[numargs]);
    p1 = p3;
    if ((p2 = strchr(p1, ','))) {
      *p2 = '\0';
    }
    while (p1) {
      if (_options.macoklen>=MACOK_MAX) {
	log_err(0,"Too many addresses in macallowed %s!",
		args_info.macallowed_arg);
      }
      else {
	/* Replace anything but hex and comma with space */
	for (i=0; i<strlen(p1); i++) 
	  if (!isxdigit((int) p1[i])) p1[i] = 0x20;
      
	if (sscanf (p1, "%2x %2x %2x %2x %2x %2x",
		    &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 6) {
	  log_err(0, "Failed to convert macallowed option to MAC Address");
	}
	else {

	  log_dbg("Macallowed address #%d: %.2X-%.2X-%.2X-%.2X-%.2X-%.2X", 
		  _options.macoklen,
		  mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

	  for (i = 0; i < 6; i++)
	    _options.macok[_options.macoklen][i] = (unsigned char) mac[i]; 

	  _options.macoklen++;
	}
      }
      
      if (p2) {
	p1 = p2+1;
	if ((p2 = strchr(p1, ','))) {
	  *p2 = 0;
	}
      }
      else {
	p1 = NULL;
      }
    }
    free(p3);
  }

  /** string parameters **/
#ifdef HAVE_SSL
  _options.sslkeyfile = STRDUP(args_info.sslkeyfile_arg);
  _options.sslkeypass = STRDUP(args_info.sslkeypass_arg);
  _options.sslcertfile = STRDUP(args_info.sslcertfile_arg);
  _options.sslcafile = STRDUP(args_info.sslcafile_arg);
#endif

#ifdef USING_IPC_UNIX
  _options.unixipc = STRDUP(args_info.unixipc_arg);
#endif

#ifdef HAVE_NETFILTER_COOVA
  _options.kname = STRDUP(args_info.kname_arg);
#endif

#ifdef ENABLE_DNSLOG
  _options.dnslog = STRDUP(args_info.dnslog_arg);
#else
  if (args_info.dnslog_arg)
    log_err(0, "option dnslog given when no support built-in");
#endif

#ifdef ENABLE_IPWHITELIST
  _options.ipwhitelist = STRDUP(args_info.ipwhitelist_arg);
#else
  if (args_info.ipwhitelist_arg)
    log_err(0, "option ipwhitelist given when no support built-in");
#endif

#ifdef ENABLE_UAMDOMAINFILE
  _options.uamdomainfile = STRDUP(args_info.uamdomainfile_arg);
#else
  if (args_info.uamdomainfile_arg)
    log_err(0, "option uamdomainfile given when no support built-in");
#endif

#ifdef ENABLE_MODULES
  _options.moddir = STRDUP(args_info.moddir_arg);
#else
  if (args_info.moddir_arg)
    log_err(0, "option moddir given when no support built-in");
#endif
  
#ifdef ENABLE_RADPROXY
  if (!args_info.proxysecret_arg) {
    _options.proxysecret = STRDUP(args_info.radiussecret_arg);
  }
  else {
    _options.proxysecret = STRDUP(args_info.proxysecret_arg);
  }
#endif

#ifdef ENABLE_REDIRINJECT
  _options.inject = STRDUP(args_info.inject_arg);
  _options.inject_ext = STRDUP(args_info.injectext_arg);
  _options.inject_wispr = args_info.injectwispr_flag;
#endif

#ifdef ENABLE_EXTADMVSA
  if (args_info.extadmvsa_given) {
    for (numargs = 0; numargs < args_info.extadmvsa_given 
	   && numargs < EXTADMVSA_ATTR_CNT; ++numargs)  {
      int len = strlen(args_info.extadmvsa_arg[numargs]);
      if (len > 0 && len < 256) {
	unsigned int i[2];
	char s[256];
	
	if (sscanf(args_info.extadmvsa_arg[numargs], 
		   "%u,%u:%s", &i[0], &i[1], s) == 3) {
	  char *idx = strchr(s, ':');
	  _options.extadmvsa[numargs].attr_vsa = i[0];
	  _options.extadmvsa[numargs].attr = i[1];
	  if (idx) *idx = 0;
	  safe_strncpy(_options.extadmvsa[numargs].script, 
		       s, sizeof(_options.extadmvsa[numargs].script)-1);
	  if (idx) {
	    safe_strncpy(_options.extadmvsa[numargs].data, 
			 idx + 1, sizeof(_options.extadmvsa[numargs].data)-1);
	  }
	} else if (sscanf(args_info.extadmvsa_arg[numargs], 
			  "%u:%s", &i[0], s) == 2) {
	  char *idx = strchr(s, ':');
	  _options.extadmvsa[numargs].attr = i[0];
	  if (idx) *idx = 0;
	  safe_strncpy(_options.extadmvsa[numargs].script, 
		       s, sizeof(_options.extadmvsa[numargs].script)-1);
	  if (idx) {
	    safe_strncpy(_options.extadmvsa[numargs].data, 
			 idx + 1, sizeof(_options.extadmvsa[numargs].data)-1);
	  }
	} else {
	  log_err(0, "invalid input %s", args_info.extadmvsa_arg[numargs]);
	}
      }

      log_dbg("Extended admin-user attr (%d/%d) data=%s script=%s", 
	      (int)_options.extadmvsa[numargs].attr_vsa, 
	      (int)_options.extadmvsa[numargs].attr,
	      _options.extadmvsa[numargs].data,
	      _options.extadmvsa[numargs].script);
    }
  }
#endif

  _options.peerkey = STRDUP(args_info.peerkey_arg);
  _options.routeif = STRDUP(args_info.routeif_arg);
  _options.wwwdir = STRDUP(args_info.wwwdir_arg);
  _options.wwwbin = STRDUP(args_info.wwwbin_arg);
  _options.uamui = STRDUP(args_info.uamui_arg);
  _options.localusers = STRDUP(args_info.localusers_arg);
  _options.uamurl = STRDUP(args_info.uamserver_arg);
  _options.uamaaaurl = STRDUP(args_info.uamaaaurl_arg);
  _options.uamhomepage = STRDUP(args_info.uamhomepage_arg);
  _options.wisprlogin = STRDUP(args_info.wisprlogin_arg);
  _options.uamsecret = STRDUP(args_info.uamsecret_arg);
  _options.macsuffix = STRDUP(args_info.macsuffix_arg);
  _options.macpasswd = STRDUP(args_info.macpasswd_arg);
  _options.adminuser = STRDUP(args_info.adminuser_arg);
  _options.adminpasswd = STRDUP(args_info.adminpasswd_arg);
  _options.adminupdatefile = STRDUP(args_info.adminupdatefile_arg);
  _options.rtmonfile = STRDUP(args_info.rtmonfile_arg);
  _options.ssid = STRDUP(args_info.ssid_arg);
  _options.vlan = STRDUP(args_info.vlan_arg);
  _options.nasmac = STRDUP(args_info.nasmac_arg);
  _options.nasip = STRDUP(args_info.nasip_arg);
  _options.tundev = STRDUP(args_info.tundev_arg);
  _options.radiusnasid = STRDUP(args_info.radiusnasid_arg);
  _options.radiuslocationid = STRDUP(args_info.radiuslocationid_arg);
  _options.radiuslocationname = STRDUP(args_info.radiuslocationname_arg);
  _options.locationname = STRDUP(args_info.locationname_arg);
  _options.radiussecret = STRDUP(args_info.radiussecret_arg);
#ifdef ENABLE_LARGELIMITS
  /*_options.radiusacctsecret = STRDUP(args_info.radiusacctsecret_arg);
    _options.radiusadmsecret = STRDUP(args_info.radiusadmsecret_arg);*/
#endif
  _options.cmdsocket = STRDUP(args_info.cmdsocket_arg);
  _options.cmdsocketport = args_info.cmdsocketport_arg;
  _options.domain = STRDUP(args_info.domain_arg);
  _options.ipup = STRDUP(args_info.ipup_arg);
  _options.ipdown = STRDUP(args_info.ipdown_arg);
  _options.conup = STRDUP(args_info.conup_arg);
  _options.condown = STRDUP(args_info.condown_arg);
  _options.macup = STRDUP(args_info.macup_arg);
  _options.macdown = STRDUP(args_info.macdown_arg);
  _options.pidfile = STRDUP(args_info.pidfile_arg);
  _options.statedir = STRDUP(args_info.statedir_arg);
  _options.usestatusfile = STRDUP(args_info.usestatusfile_arg);
  _options.uamaliasname = STRDUP(args_info.uamaliasname_arg);
  _options.uamhostname = STRDUP(args_info.uamhostname_arg);
  _options.binconfig = STRDUP(args_info.bin_arg);
  _options.ethers = STRDUP(args_info.ethers_arg);
#ifdef ENABLE_IEEE8021Q
  _options.ieee8021q = args_info.ieee8021q_flag;
  _options.ieee8021q_only = args_info.only8021q_flag;
  _options.vlanupdate = STRDUP(args_info.vlanupdate_arg);
#endif
#ifdef ENABLE_PROXYVSA
  _options.locationupdate = STRDUP(args_info.locationupdate_arg);
#endif
#ifdef EX_OPT_MAIN
#include EX_OPT_MAIN
#endif

  ret = 0;

  if (_options.binconfig) { /* save out the configuration */
    bstring bt = bfromcstr("");
    int ok = options_save(_options.binconfig, bt);
    if (!ok) log_err(0, "could not save configuration options!");
    bdestroy(bt);
  }

  if (args_info.reload_flag) {
    if (execl(SBINDIR "/chilli_query", "chilli_query", 
	      args_info.cmdsocket_arg, "reload", (char *) 0) != 0) {
      log_err(errno, "execl() did not return 0!");
      exit(2);
    }
  }

 end_processing:
  cmdline_parser_free (&args_info);

  return ret;
}
Ejemplo n.º 14
0
int main(int argc, const char * argv[]) {
	sm_set_program_name(argv[0]);
	
	options_banner("ld_noise: Adds noise to readings in a scan");
	
	struct ld_noise_params p;
	
	struct option* ops = options_allocate(20);
	options_double(ops, "discretization", &p.discretization, 0.0, 
		"Size of discretization (disabled if 0)");
	options_double(ops, "sigma", &p.sigma, 0.0, 
		"Std deviation of gaussian noise (disabled if 0)");
	options_int(ops, "lambertian", &p.lambertian, 0, 
		"Use lambertian model cov = sigma^2 / cos(beta^2) where beta is the incidence. Need have alpha or true_alpha.");
	options_int(ops, "seed", &p.seed, 0, 
		"Seed for random number generator (if 0, use GSL_RNG_SEED env. variable).");
	options_string(ops, "in", &p.file_input, "stdin", "Input file ");
	options_string(ops, "out", &p.file_output, "stdout", "Output file ");
		
		
	if(!options_parse_args(ops, argc, argv)) {
		fprintf(stderr, "A simple program for adding noise to sensor scans.\n\nUsage:\n");
		options_print_help(ops, stderr);
		return -1;
	}

	FILE * in = open_file_for_reading(p.file_input);
	if(!in) return -3;

	FILE * out = open_file_for_writing(p.file_output);
	if(!out) return -2;


	gsl_rng_env_setup();
	gsl_rng * rng = gsl_rng_alloc (gsl_rng_ranlxs0);
	if(p.seed != 0)
	gsl_rng_set(rng, (unsigned int) p.seed);

	LDP ld; int count = 0;
	while( (ld = ld_from_json_stream(in))) {
		if(!ld_valid_fields(ld))  {
			sm_error("Invalid laser data (#%d in file)\n", count);
			continue;
		}
		
		int i;
		for(i=0;i<ld->nrays;i++) {
			if(!ld->valid[i]) continue;
			
			double * reading = ld->readings + i;
			if(p.sigma > 0) {
				double add_sigma = p.sigma;
				
				if(p.lambertian) {

					int have_alpha = 0;
					double alpha = 0;
					if(!is_nan(ld->true_alpha[i])) {
						alpha = ld->true_alpha[i];
						have_alpha = 1;
					} else if(ld->alpha_valid[i]) {
						alpha = ld->alpha[i];;
						have_alpha = 1;
					} else have_alpha = 0;

					if(have_alpha) {
						/* Recall that alpha points outside the surface */
						double beta = (alpha+M_PI) - ld->theta[i];
					    add_sigma = p.sigma / cos(beta);
					} else {
						sm_error("Because lambertian is active, I need either true_alpha[] or alpha[]");
						ld_write_as_json(ld, stderr);
						return -1;
					}
					
				} 
				
			   *reading += gsl_ran_gaussian(rng, add_sigma);
				
				if(is_nan(ld->readings_sigma[i])) {
					ld->readings_sigma[i] = add_sigma;
				} else {
					ld->readings_sigma[i] = sqrt(square(add_sigma) + square(ld->readings_sigma[i]));
				}
			}
			if(p.discretization > 0)
				*reading -= fmod(*reading , p.discretization);
		}
	
		ld_write_as_json(ld, out);
		ld_free(ld);
	}
	
	return 0;
}
Ejemplo n.º 15
0
Archivo: say.c Proyecto: razr/opentts
int main(int argc, char **argv)
{
	SPDConnection *conn;
	SPDPriority spd_priority;
	int err;
	int ret;
	int msg_arg_required = 0;
	int option_ret;
	char *line;

	/* init i18n support */
	setlocale(LC_ALL,"");
	bindtextdomain(GETTEXT_PACKAGE,LOCALEDIR);
	textdomain(GETTEXT_PACKAGE);

	language = NULL;
	voice_type = NULL;
	punctuation_mode = NULL;
	wait_till_end = 0;
	stop_previous = 0;
	cancel_previous = 0;
	pipe_mode = 0;
	priority = NULL;
	application_name = NULL;
	connection_name = NULL;

	option_ret = options_parse(argc, argv);

	/* Check if the text to say or options are specified in the argument */
	msg_arg_required = (pipe_mode != 1) && (stop_previous != 1)
	    && (cancel_previous != 1) && (list_synthesis_voices != 1)
	    && (list_output_modules != 1);
	if ((optind >= argc) && msg_arg_required) {
		/*
		 * We require a message on the command-line, but there
		 * are no arguments.
		 */
		options_print_help(argv);
		return 1;
	}

	/* Open a connection to openttsd */
	conn = spd_open(application_name ? application_name : "otts-say",
			connection_name ? connection_name : "main",
			NULL, SPD_MODE_THREADED);
	if (conn == NULL)
		FATAL("openttsd failed to open");

	if (stop_previous)
		spd_stop_all(conn);
	if (cancel_previous)
		spd_cancel_all(conn);

	/* Set the desired parameters */

	if (language != NULL)
		if (spd_set_language(conn, language))
			printf(_("Invalid language!\n"));

	if (output_module != NULL)
		if (spd_set_output_module(conn, output_module))
			printf(_("Invalid output module!\n"));

	if (list_output_modules) {
		char **list;
		int i;

		list = spd_list_modules(conn);

		if (list != NULL) {
			printf (_("OUTPUT MODULES\n"));
			for (i = 0; list[i]; i++) {
				printf ("%s\n",list[i]);
			}
		} else {
			printf(_("Output modules not found.\n"));
		}
	}

	if (voice_type != NULL) {
		if (!strcmp(voice_type, "male1")) {
			if (spd_set_voice_type(conn, SPD_MALE1))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "male2")) {
			if (spd_set_voice_type(conn, SPD_MALE2))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "male3")) {
			if (spd_set_voice_type(conn, SPD_MALE3))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "female1")) {
			if (spd_set_voice_type(conn, SPD_FEMALE1))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "female2")) {
			if (spd_set_voice_type(conn, SPD_FEMALE2))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "female3")) {
			if (spd_set_voice_type(conn, SPD_FEMALE3))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "child_male")) {
			if (spd_set_voice_type(conn, SPD_CHILD_MALE))
				printf("Can't set this voice!\n");
		} else if (!strcmp(voice_type, "child_female")) {
			if (spd_set_voice_type(conn, SPD_CHILD_FEMALE))
				printf("Can't set this voice!\n");
		} else {
			printf("Invalid voice\n");
		}
	}

	if (list_synthesis_voices) {
		SPDVoice **list;
		int i;

		list = spd_list_synthesis_voices(conn);
		if (list != NULL) {
			printf ("%25s%25s%25s\n","NAME", "LANGUAGE", "VARIANT");
			for (i = 0; list[i]; i++) {
				printf ("%25s%25s%25s\n",
					list[i]->name,
					list[i]->language,
					list[i]->variant);
			}
		} else {
			printf(_("Failed to get voice list.\n"));
		}
	}

	if (synthesis_voice != NULL)
		if (spd_set_synthesis_voice(conn, synthesis_voice))
			printf(_("Failed to set synthesis voice!\n"));

	if (data_mode != SPD_DATA_TEXT)
		if (spd_set_data_mode(conn, data_mode))
			printf(_("Failed to set SSML mode.\n"));

	if (rate != OTTS_VOICE_RATE_DEFAULT)
		if (spd_set_voice_rate(conn, rate))
			printf(_("Invalid rate!\n"));

	if (pitch != OTTS_VOICE_PITCH_DEFAULT)
		if (spd_set_voice_pitch(conn, pitch))
			printf(_("Invalid pitch!\n"));

	if (volume != OTTS_VOICE_VOLUME_DEFAULT)
		if (spd_set_volume(conn, volume))
			printf(_("Invalid volume!\n"));

	if (spelling != SPD_SPELL_OFF)
		if (spd_set_spelling(conn, spelling))
			printf(_("Can't enable spelling!\n"));

	if (punctuation_mode != NULL) {
		if (!strcmp(punctuation_mode, "none")) {
			if (spd_set_punctuation(conn, SPD_PUNCT_NONE))
				printf("Can't set this punctuation mode!\n");
		} else if (!strcmp(punctuation_mode, "some")) {
			if (spd_set_punctuation(conn, SPD_PUNCT_SOME))
				printf("Can't set this punctuation mode!\n");
		} else if (!strcmp(punctuation_mode, "all")) {
			if (spd_set_punctuation(conn, SPD_PUNCT_ALL))
				printf("Can't set this punctuation mode!\n");
		} else {
			printf("Invalid punctuation mode.\n");
		}
	}

	/* Set default priority... */
	if (pipe_mode == 1)
		spd_priority = SPD_MESSAGE;
	else
		spd_priority = SPD_TEXT;
	/* ...and be sure it wasn't overridden */
	if (priority != NULL) {
		if (!strcmp(priority, "important"))
			spd_priority = SPD_IMPORTANT;
		else if (!strcmp(priority, "message"))
			spd_priority = SPD_MESSAGE;
		else if (!strcmp(priority, "text"))
			spd_priority = SPD_TEXT;
		else if (!strcmp(priority, "notification"))
			spd_priority = SPD_NOTIFICATION;
		else if (!strcmp(priority, "progress"))
			spd_priority = SPD_PROGRESS;
		else {
			printf(_("Invalid priority.\n"));
		}
	}

	if (wait_till_end) {
		ret = sem_init(&semaphore, 0, 0);
		if (ret < 0) {
			fprintf(stderr, "Can't initialize semaphore: %s",
				strerror(errno));
			return 0;
		}

		/* Notify when the message is canceled or the speech terminates */
		conn->callback_end = end_of_speech;
		conn->callback_cancel = end_of_speech;
		spd_set_notification_on(conn, SPD_END);
		spd_set_notification_on(conn, SPD_CANCEL);
	}

	/* In pipe mode, read from stdin, write to stdout, and also to openttsd. */
	if (pipe_mode == 1) {
		line = (char *)malloc(MAX_LINELEN);
		while (fgets(line, MAX_LINELEN, stdin) != NULL) {
			fputs(line, stdout);
			if (strncmp(line, "!-!", 3) == 0) {
				/* Remove EOL */
				line[strlen(line) - 1] = 0;
				spd_execute_command(conn, line + 3);
			} else {
				spd_say(conn, spd_priority, line);
				if (wait_till_end)
					sem_wait(&semaphore);
			}
		}
		free(line);
	} else {
		/* Say the message with priority "text" */
		/* Or do nothing in case of -C or -S with no message. */
		if (optind < argc) {
			err = spd_sayf(conn, spd_priority, (char *)argv[optind]);
			if (err == -1)
				FATAL("openttsd failed to say message");

			/* Wait till the callback is called */
			if (wait_till_end)
				sem_wait(&semaphore);
		}
	}

	/* Close the connection */
	spd_close(conn);

	return 0;
}