Exemplo 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);
    }
  }
}
Exemplo n.º 2
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);
		}
	}
}