Example #1
0
error_t miaoDetectParser (int key, char *arg, struct argp_state *state) {
	miaoDetectArgs *args = (miaoDetectArgs*) state->input;
	switch (key) {
		case LOW_K_KEY:
			args->lowK = atoi(arg);
			return 0;
		case HIGH_K_KEY:
			args->highK = atoi(arg);
			return 0;
		case ARGP_KEY_ARG: // A non-option key - the audio file or output file
			switch (state->arg_num) {
				case 0: args->audioFile = arg; break;
				default: argp_usage(state);
			}
			return 0;
		case ARGP_KEY_END: // End of non-options - check to make sure we have the audio file and ks are valid
			if (!args->audioFile)
				argp_usage(state);
			if (args->lowK == -1 || args->highK == -1)
				argp_usage(state);
			if (args->lowK > args->highK)
				argp_error(state, "incorrect order for k values");
			if (args->lowK < 1 || args->lowK > 79)
				argp_error(state, "invalid lower k - try 1-79");
			if (args->highK < 1 || args->highK > 79)
				argp_error(state, "invalid upper k - try 1-79");
			return 0;
		default:
			return ARGP_ERR_UNKNOWN;
	}
}
Example #2
0
/* Parse a single option. */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
    /* Get the input argument from argp_parse, which we
     know is a pointer to our arguments structure. */
    struct arguments *arguments = state->input;
    switch (key)
        {
        case 'v':
            arguments->verbose = 1;
            break;


        case ARGP_KEY_ARG:
            if (state->arg_num >= 3)
            /* Too many arguments. */
            argp_usage (state);
            arguments->args[state->arg_num] = arg;
            break;

        case ARGP_KEY_END:
            if (state->arg_num < 2)
            /* Not enough arguments. */
            argp_usage (state);
            break;

        default:
            return ARGP_ERR_UNKNOWN;
        }
    return 0;
}
Example #3
0
static int parse_options (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;
  switch (key){
  case 'h': arguments->header_file = arg; break;
  case 'c': arguments->implementation_file = arg; break;
  case 'i': arguments->from_file = arg; break;
  case ARGP_KEY_ARG:
    if (arguments->input_size == MY_INPUT_SIZE) {
      /* Too many arguments. */
      argp_usage (state);
    }
    arguments->input[state->arg_num] = arg;
    arguments->input_size++;
    break;
  case ARGP_KEY_END:
    if ((!arguments->header_file ||
         !arguments->implementation_file) &&
        !arguments->from_file){
      /* Not enough arguments. */
      argp_usage (state);
    }
    break;
  default: return ARGP_ERR_UNKNOWN;
  }
  return 0;
}
Example #4
0
static error_t parse_opt_rm(int key, char *arg, struct argp_state *state)
{
    struct arguments *args = state->input;

    switch (key) {
        case 'n':
            if (!arg || args->rm_name)
                argp_usage(state);
            if (strlen(arg) > DISK_NAME_LEN) {
                printf("Argument too long\n");
                argp_usage(state);
            }
            args->rm_name = arg;
            args->arg_num++;
            break;
        case ARGP_KEY_ARG:
            if (args->arg_num > 1)
                argp_usage(state);
            if (arg) {
                args->rm_name = arg;
                args->arg_num++;
            }
            break;
        case ARGP_KEY_END:
            if (args->arg_num < 1)
                argp_usage(state);
            break;
        default:
            return ARGP_ERR_UNKNOWN;
    }

    return 0;
}
Example #5
0
static error_t parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;
  struct list_elem *base = arguments->include_files;
  struct list_elem *e;

  switch (key)
    {
    case 'i':
      e = (struct list_elem *) calloc(1, sizeof(e));
      e->string = arg;
      while(base->has_next) base = base->next;
      base->next = e;
      base->has_next = 1;
      break;
    case 'd':  
      // parsley_set_debug_mode(1);
      break;
    case 'o':
      arguments->output_file = arg;
      break;
    case ARGP_KEY_ARG:
      if (state->arg_num >= 1) argp_usage (state);
      arguments->parsley = arg;
      break;
    case ARGP_KEY_END:
      if (state->arg_num < 1) argp_usage (state);
      break;
    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}
Example #6
0
/* Define argument parser */
static error_t argp_parser(int key, char *arg, struct argp_state *state) {
  struct arguments *arguments = state->input;

  switch (key) {
  case ARGP_KEY_ARG:
    switch(state->arg_num) {
    case 0:
      arguments->bif_filename = arg;
      break;
    case 1:
      arguments->bin_filename = arg;
      break;
    default:
      argp_usage(state);
    }
    break;
  case ARGP_KEY_END:
    if (state->arg_num < 2)
      argp_usage (state);
    break;
  default:
    return ARGP_ERR_UNKNOWN;
  }
  return 0;
}
Example #7
0
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
	struct arguments *arguments = state->input;

	switch (key) {
	case 'l':
		arguments->action = LIST;
	break;
	case 0x101:
		arguments->action = SHOW_JOURNALD_CURSOR;
	break;
	case 0x102:
		arguments->action = SAVE_JOURNALD_CURSOR;
		arguments->action_arg.journald_cursor = arg;
	break;
	case ARGP_KEY_ARG:
		if (state->arg_num >= 1)
			argp_usage (state);
		arguments->filename = arg;
	break;
	case ARGP_KEY_END:
		if (state->arg_num < 1)
			argp_usage (state);
	break;
	default:
		return ARGP_ERR_UNKNOWN;
	}
	return 0;
}
Example #8
0
static error_t parse_opt(int key, char* arg, struct argp_state *state)
{
	struct arg_info* info = (struct arg_info*) state->input;

	switch(key)
	{
		case 'b':	info->bot = true;		break;
		case 'd':	info->showDebug = true;		break;
		case 's':	info->stream_names = true;		break;

		case ARGP_KEY_ARG:
			if (state->arg_num >= 2)
				argp_usage(state);

			state->arg_num == 0 ? info->arg1 = arg : info->arg2 = arg;
			break;

		case ARGP_KEY_END:
			if (state->arg_num < 1)
				argp_usage(state);

			break;

		default:
			return ARGP_ERR_UNKNOWN;
	}

	return 0;
}
Example #9
0
static error_t parse_options (int key, char *arg, struct argp_state *state)
{
    struct arguments *arguments = (struct arguments*)(state->input);
    switch (key){
        case 'c': arguments->costs_file = arg; break;
        case 'm': arguments->mem = true; break;
        case 'r': arguments->reg = true; break;
        case 's': arguments->stat = true; break;    
        case 'p': arguments->prog = true; break;
        case 'd': arguments->debug = true; break;
        case 'f': arguments->fp = atoi(arg); break;
        case 't': arguments->mem_size = atoi(arg); break;
        case ARGP_KEY_ARG:
            if (state->arg_num >= 1)        //Argumentos excessivos
                argp_usage (state);

            arguments->iloc_file = arg;

            break;
        case ARGP_KEY_END:
            if (state->arg_num < 1)         // Argumentos insuficientes
                  argp_usage (state);
            break;
        default: return ARGP_ERR_UNKNOWN;
    }
    return 0;
}
Example #10
0
error_t parse_opt (int key, char *arg, struct argp_state *state) {
	struct arguments *arguments = state->input;
	switch (key) {
		case 'q':
			arguments->quiet = 1;
		break;
		case 's':
			arguments->silent = 1;
		break;
		case 'v':
			arguments->verbose = 1;
		break;
		case 'r':
			arguments->random = 1;
		break;
		case 'w':
			arguments->weapon = arg;
		break;
		case ARGP_KEY_ARG:
			if (state->arg_num >= NUM_ARGS)
			// Too many arguments.
			argp_usage (state);
			arguments->args[state->arg_num] = arg;
		break;
		case ARGP_KEY_END:
			if (state->arg_num < NUM_ARGS)
			// Not enough arguments.
			argp_usage (state);
		break;
		default:
			return ARGP_ERR_UNKNOWN;
	}

	return 0;
}
Example #11
0
static error_t _parse_opt (int key, char *arg, struct argp_state *state) {

  args_t *args;

  args = state->input;

  switch(key) {
    
    case 'm': args->meta    = 1; break;
    case 'l': args->labels  = 1; break;
    case 'g': args->graph   = 1; break;
    case 'w': args->weights = 1; break;
    case 'd': args->dists   = 1; break;
      
    case ARGP_KEY_ARG:
      if (state->arg_num == 0) args->input = arg;
      else argp_usage(state);
      break;

    case ARGP_KEY_END:
      if (state->arg_num != 1) argp_usage(state);
      break; 
      
    default:
      return ARGP_ERR_UNKNOWN;

  }
  
  return 0;
}
Example #12
0
static error_t
parse_opt(int key, char *arg, struct argp_state *state)
{
    switch (key) {
    case 'w':
        workers = atoi(arg);
        break;
    case 'v':
        verbose = 1;
        break;
    case 1:
        no_reachable = 1;
        break;
    case 2:
        check_results = 1;
        break;
    case ARGP_KEY_ARG:
        if (state->arg_num == 0) model_filename = arg;
        if (state->arg_num == 1) bdd_filename = arg;
        if (state->arg_num >= 2) argp_usage(state);
        break; 
    case ARGP_KEY_END:
        if (state->arg_num < 2) argp_usage(state);
        break;
    default:
        return ARGP_ERR_UNKNOWN;
    }
    return 0;
}
Example #13
0
static error_t _parse_opt(int key, char *arg, struct argp_state *state) {

  args_t *a = state->input;

  switch(key) {

    case 't':
      if      (!strcmp(arg, "lol"))  a->type = FILE_RADATOOLS;
      else if (!strcmp(arg, "tree")) a->type = FILE_INFOMAP;
      else                           argp_usage(state);
      break;

    case 'c':
      a->connfile = arg;
      break;

    case ARGP_KEY_ARG:
      if      (state->arg_num == 0) a->input  = arg;
      else if (state->arg_num == 1) a->output = arg;
      else                          argp_usage(state);
      break;

    case ARGP_KEY_END:
      if (state->arg_num < 1) argp_usage(state);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
  }

  return 0;
}
Example #14
0
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
    struct wem_arguments *arguments = state->input;
    switch(key) {
        case 's':
            arguments->config.mode = SERVER_MODE;
            break;
        case 'c':
            arguments->config.mode = CLIENT_MODE;
            break;
        case 'd':
            arguments->config.daemon = 1;
            break;
        case 'f':
            arguments->config_file = arg;
            break;
        case 'v':
            arguments->config.log_level = VERBOSE;
            break;
       
        case ARGP_KEY_ARG:
            if (state->arg_num >= 2)
                argp_usage(state);
            
            arguments->args[state->arg_num] = arg;
            break;
        /*case ARGP_KEY_END:*/
            if (state->arg_num < 2)
                 argp_usage(state); 
            break;

        default:
            return ARGP_ERR_UNKNOWN;
    }
    return (0);
}
Example #15
0
/* parser for individual options - fills in a struct cmdline_args */
static error_t parse_option(int key, char *arg, struct argp_state *state)
{
  /* get a shorthand to the command line argument structure, part of state */
  struct cmdline_args *arguments=state->input;

  switch (key) {
  case 'r':
    if (arg==NULL)
      arguments->repeat=-1;
    else
      arguments->repeat=strtol(arg, NULL, 10);
    break;

  case ARGP_KEY_ARG: /* handle argument (not option) */
    switch (state->arg_num) {
    case 0:
      arguments->msg=arg;
      break;

    case 1:
      arguments->server=arg;
      break;

    case 2:
      arguments->port=tr_parse_port(arg); /* optional */
      if (arguments->port < 0) {
        switch(-(arguments->port)) {
          case ERANGE:
            printf("\nError parsing port (%s): port must be an integer in the range 1 - 65535\n\n", arg);
            break;

          default:
            printf("\nError parsing port (%s): %s\n\n", arg, strerror(-arguments->port));
            break;
        }
        argp_usage(state);
      }
      break;

    default:
      /* too many arguments */
      argp_usage(state);
    }
    break;

  case ARGP_KEY_END: /* no more arguments */
    if (state->arg_num < 2) {
      /* not enough arguments encountered */
      argp_usage(state);
    }
    break;

  default:
    return ARGP_ERR_UNKNOWN;
  }

  return 0; /* success */
}
Example #16
0
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
    struct config *arguments = (struct config*)state->input;
    switch (key) {
        case 'v':
            arguments->verbosity = DEBUG_V;
            break;
        case 'q':
            arguments->verbosity = ERR_V;
            break;
        case 't':
            arguments->threads = atoi(arg);
            break;
        case 'l':
            arguments->dont_run = true;
            break;
        case 'c':
            arguments->compositor = atoi(arg);
            if (arguments->compositor > compositors_count - 1) {
                argp_usage(state);
            }
            break;
        case 'g':
            arguments->greyscale = true;
            break;
        case 'd':
            arguments->darken = atoi(arg);
            break;
        case 'p':
            arguments->preserve = true;
            break;
        case 'x':
            arguments->x = atoi(arg);
            break;
        case 'f':
            arguments->framerate = atoi(arg);
            break;
        case ARGP_KEY_ARG:
            if (state->arg_num == 0) {
                arguments->input = arg;
            } else if (state->arg_num == 1) {
                arguments->output = arg;
            } else {
                argp_usage(state);
            }
            break;
        case ARGP_KEY_END:
            if (state->arg_num < 2 && !arguments->dont_run) {
                argp_usage(state);
            }
            break;
        default:
            return ARGP_ERR_UNKNOWN;
    }
    return 0;
};
Example #17
0
/* Define argument parser */
static error_t argp_parser(int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;

  switch (key) {
  case 'v':
    arguments->verbose = 1;
    break;
  case 'q':
    arguments->quiet = 1;
    break;
  case 'c':
    arguments->channel_info = 1;
    break;
  case 'o':
    arguments->rgb_dump_filename = arg;
    break;
  case 's':
    arguments->show_syncs = 1;
    break;
  case 'a':
    arguments->align_output = 1;
    break;
  case '1':
    arguments->one_frame = 1;
    arguments->align_output = 1;
    break;
  case 'r':
    arguments->show_resolution = 1;
    break;
  case 'R':
    arguments->show_resolution_blanks = 1;
    break;
  case 't':
    arguments->show_resolution_total = 1;
    break;
  case ARGP_KEY_ARG:
    switch(state->arg_num) {
    case 0:
      arguments->tmds_dump_filename = arg;
      break;
    default:
      argp_usage(state);
    }
    break;
  case ARGP_KEY_END:
    if (state->arg_num < 1)
      argp_usage (state);
    break;
  default:
    return ARGP_ERR_UNKNOWN;
  }
  return 0;
}
Example #18
0
/* Parse a single option. */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  /* Get the input argument from argp_parse, which we
     know is a pointer to our arguments structure. */
  struct arguments *arguments = state->input;

  switch (key)
    {
    case 'q': case 's':
      arguments->silent = 1;
      break;
    case 'v':
      arguments->verbose = 1;
      break;
    case 'h':
      arguments->hardware = 1;
      break;
    case 'k':
        key_f = arg;
        break;
    case 'j':
      if (NULL == (arguments->input_file = fopen (arg, "r")))
          argp_usage (state);

      break;
    case 'd':
      arguments->display = arg;
      break;

    case 'a':
        arguments->alg = jwa2enum (arg);
        break;

    case ARGP_KEY_ARG:
      if (state->arg_num >= NUM_ARGS)
        /* Too many arguments. */
        argp_usage (state);

      arguments->args[state->arg_num] = arg;

      break;

    case ARGP_KEY_END:
      if (state->arg_num < NUM_ARGS)
        /* Not enough arguments. */
        argp_usage (state);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}
Example #19
0
static error_t parse_opt(int key,char *arg,struct argp_state *state){
  switch(key){
    case 'a':a->focus=AF;break;
    case 'b':a->delay=atof(arg);break;
    case 'c':a->min=MIN_FAST;
             a->max=MAX_FAST;
             a->border=BORDER_FAST;
             break;
    case 'd':a->dummy=1;break;        
    case 'f':a->focal=atof(arg);break;
    case 'g':a->file=arg;break;
    case 'h':a->height=atof(arg);break;
    case 'l':a->load=arg;break;
    case 'm':a->shutter=0;break;
    case 'o':a->overlap=atof(arg);break;
    case 'q':a->level=L_NONE;break;
    case 's':a->speed=atof(arg);break;
    case 'v':a->level=atoi(arg);break;
    case 'w':a->width=atof(arg);break;
    case 'x':a->vwidth=atof(arg);break;
    case 'y':a->vheight=atof(arg);break;
    case 'z':a->min=MIN_SLOW;
             a->max=MAX_SLOW;
             a->border=BORDER_SLOW;
             break;
    case ARGP_KEY_ARG:
        if(state->arg_num==0){
                 if(!strcmp(arg,"test"))   a->action=ACT_TEST;
            else if(!strcmp(arg,"virtual"))a->action=ACT_VIRTUAL;
            else if(!strcmp(arg,"sphere")) a->action=ACT_SPHERE;
            else if(!strcmp(arg,"slave"))  a->action=ACT_SLAVE;
            else if(!strcmp(arg,"35"))     a->action=ACT_35;
            else if(!strcmp(arg,"6x45"))   a->action=ACT_6x45;
            else if(!strcmp(arg,"45x6"))   a->action=ACT_45x6;
            else if(!strcmp(arg,"6x6"))    a->action=ACT_6x6;
            else if(!strcmp(arg,"6x7"))    a->action=ACT_6x7;
            else if(!strcmp(arg,"7x6"))    a->action=ACT_7x6;
            else if(!strcmp(arg,"6x8"))    a->action=ACT_6x8;
            else if(!strcmp(arg,"8x6"))    a->action=ACT_8x6;
            else if(!strcmp(arg,"6x9"))    a->action=ACT_6x9;
            else if(!strcmp(arg,"9x6"))    a->action=ACT_9x6;
            else if(!strcmp(arg,"6x17"))   a->action=ACT_6x17;
            else if(!strcmp(arg,"17x6"))   a->action=ACT_17x6;
            else if(!strcmp(arg,"xxx"))    a->action=ACT_XXX;
            else argp_usage(state);//error("Invalid Action.");
        }
        if(state->arg_num>0)argp_usage(state);break;
    case ARGP_KEY_END:
        if(state->arg_num<1)argp_usage(state);break;
    default:
        return ARGP_ERR_UNKNOWN;
    }
  return 0;
}
Example #20
0
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
  /* Get the input argument from argp_parse, which we
    know is a pointer to our arguments structure. */
  struct arguments *arguments = state->input;

  switch (key){
  case 'a':
    arguments->adaptive = 1;
    break;
  case 'v':
    arguments->verbose = 1;
    break;
  case 's':
    arguments->silent = 1;
    break;
  case 'b':
    arguments->batch = 1;
    arguments->silent = 1;
    break;
  case 'f':
    arguments->infile = arg;
    arguments->batch = 1;
    arguments->silent = 1;
    break;
  case 'n':
    arguments->devnull = 1;
    break;

  case ARGP_KEY_ARG:
    if (state->arg_num == 0) {
      arguments->host = arg;
    } else if (state->arg_num == 1) {
      errno = 0;
      arguments->port = (int)strtol(arg,NULL,0);
      if (errno == ERANGE) { /* Not a number? or number too big? */
        argp_usage(state);
      }
    } else {
      argp_usage(state);
    }
    break;
    
  case ARGP_KEY_END:
    if (state->arg_num < 2)
      /* Not enough arguments */
      argp_usage(state);
    break;

  default:
    return ARGP_ERR_UNKNOWN;
  }
  return 0;
}
Example #21
0
/* the function which parses command line options */
error_t parse_opt (int key, char* arg, struct argp_state* state) {

    /* get the input argument from argp_parse */
    struct arguments *arguments = state->input;

    /* switch on the command line option that was passed in */
    switch (key) {
        case 'p':
            /* set the palette option */
            arguments->palette = 1;
            break;

        case 't':
            /* set the tileize option */
            arguments->tileize = 1;

        case 'o':
            /* the output file name is set */
            arguments->output_file_name = arg;
            break;

        case 'c':
            /* the colorkey is set */
            arguments->colorkey = arg;
            break;

            /* we got a file name */
        case ARGP_KEY_ARG:
            if (state->arg_num > 1) {
                /* too many arguments */
                fprintf(stderr, "Error: Only one file name can be given!\n");
                argp_usage(state);
            }

            /* save it as an argument */
            arguments->input_file_name = arg;
            break;

            /* we hit the end of the arguments */
        case ARGP_KEY_END:
            if (state->arg_num < 1) {
                /* not enough arguments */
                fprintf(stderr, "Error: Must pass an input file name!\n");
                argp_usage(state);
            }
            break;

            /* some other kind of thing happended */
        default:
            return ARGP_ERR_UNKNOWN;
    }
    return 0;
}
Example #22
0
static error_t
config_parse_opt(int key, char *arg, struct argp_state *state) 
{
    switch (key) {
        case ARGP_KEY_ARG:
            source_fn = arg;
            break;
        case 'o':
            out_fn = arg;
            break;
        case 's':
            chunk_size = to_int(arg);
            break;
        case 'I':
            max_index = to_int(arg);
            break;
        case 'L':
            max_run_length = to_int(arg);
            break;
        case 'V':
            verbose = true;
            break;
        case ARGP_KEY_FINI:
            if (source_fn == NULL) {
                fprintf(stderr, "you must specify an output pattern\n");
                argp_usage(state);
            }
            if (out_fn == NULL) {
                fprintf(stderr, "missing required argument \"output\"\n");
                argp_usage(state);
            }
            if (chunk_size < 0) {
                fprintf(stderr, "chunk-size must be positive (got %d)\n", chunk_size);
                argp_usage(state);
            }
            if (max_index <= 0 || max_run_length <= 0) {
                fprintf(stderr, "both max-index and max-run-length must be greater than 0 (got %d, %d)\n", max_index, max_run_length);
                argp_usage(state);
            }
            int ibits = (int) ceil(log2((double) max_index + 1));
            int lbits = (int) ceil(log2((double) max_run_length));
            if (ibits + lbits > 8) {
                fprintf(stderr, "the sum of the bits required for a max-run-length of %d (%d) and a max-index of %d (%d) are > 8\n", max_run_length, lbits, max_index, ibits);
                argp_usage(state);
            }
            index_shift = lbits;
            break;
        default:
            break;
    }

    return EXIT_SUCCESS;
}
/* Parse a single option. */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
    /* Get the input argument from argp_parse, which we
       know is a pointer to our arguments structure. */
    struct arguments *arguments = state->input;

    switch (key)
    {
    case 'v':
        arguments->verbose = 1;
        break;
    case ARGP_KEY_ARG:
        if (state->arg_num >= 1) {
            /* Too many arguments. */
            argp_usage (state);
        }
        else if (arguments->region == NULL) {
            arguments->region = arg;
        }
        break;

    case ARGP_KEY_END:
        if (state->arg_num < 1) {
            /* Not enough arguments. */
            argp_usage (state);
        }
        else if (arguments->region == NULL) {
            argp_failure(state, 1, 0, "ERROR, region not defined!");
        }
        else if (
            strcmp(arguments->region,"Ama") != 0 &&
            strcmp(arguments->region,"Aus") != 0 &&
            strcmp(arguments->region,"Ber") != 0 &&
            strcmp(arguments->region,"CAm") != 0 &&
            strcmp(arguments->region,"ChJ") != 0 &&
            strcmp(arguments->region,"Eur") != 0 &&
            strcmp(arguments->region,"Ind") != 0 &&
            strcmp(arguments->region,"NAf") != 0 &&
            strcmp(arguments->region,"NAm") != 0 &&
            strcmp(arguments->region,"SAf") != 0 &&
            strcmp(arguments->region,"SAm") != 0 &&
            strcmp(arguments->region,"SAs") != 0) {
            argp_failure(state, 1, 0, "ERROR, inputted region not defined!");
        }
        break;

    default:
        return ARGP_ERR_UNKNOWN;
    }
    return 0;
}
Example #24
0
/* parser for individual options - fills in a struct cmdline_args */
static error_t parse_option(int key, char *arg, struct argp_state *state)
{
  /* get a shorthand to the command line argument structure, part of state */
  struct cmdline_args *arguments=state->input;

  switch (key) {
  case ARGP_KEY_ARG: /* handle argument (not option) */
    switch (state->arg_num) {
    case 0:
      arguments->server=arg;
      break;

    case 1:
      arguments->rp_realm=arg;
      break;

    case 2:
      arguments->target_realm=arg;
      break;

    case 3:
      arguments->community=arg;
      break;

    case 4:
      arguments->port=strtol(arg, NULL, 10); /* optional */
      break;

    default:
      /* too many arguments */
      argp_usage(state);
    }
    break;

  case ARGP_KEY_END: /* no more arguments */
    if (state->arg_num < 4) {
      /* not enough arguments encountered */
      argp_usage(state);
    }
    break;

  case 'v':
    print_version_info();
    exit(0);

  default:
    return ARGP_ERR_UNKNOWN;
  }

  return 0; /* success */
}
Example #25
0
static error_t parse_opt_io(int key, char *arg, struct argp_state *state)
{
    struct arguments *args = state->input;

    switch (key) {
        case 'b':
            args->io_blkid = atoi(arg);
            if (args->io_blkid < 0)
                argp_usage(state);
            args->arg_num++;
            args->io_flag |= IOARGB; 
            break;
        case 'n':
            strcpy(args->io_tgt,arg);
            args->arg_num++;
            args->io_flag |= IOARGN;
            break;
        case 's':
            args->io_pgstart = atoi(arg);
            if (args->io_pgstart < 0)
                argp_usage(state);
            args->arg_num++;
            args->io_flag |= IOARGS;
            break;
        case 'p':
            args->io_nrpages = atoi(arg);
            if (args->io_nrpages < 0)
                argp_usage(state);
            args->arg_num++;
            args->io_flag |= IOARGP;
            break;
        case 'v':
            args->arg_num++;
            args->io_flag |= IOARGV;
            break;
        case ARGP_KEY_ARG:
            if (args->arg_num > 5)
                argp_usage(state);
            break;
        case ARGP_KEY_END:
            if (args->arg_num < 2 || (!args->io_flag & IOARGB) 
                                  || (!args->io_flag & IOARGN))
                argp_usage(state);
            break;
        default:
            return ARGP_ERR_UNKNOWN;
    }

    return 0;
}
Example #26
0
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
	switch (key) {
	case 'd':
		train_mode = 1;
		break;
		
	case 'D':
		device_dump_mode = 1;
		break;
		
	case 'c':
		configfile = arg;
		break;
		
	case 'f':
		foreground = 1;
		break;
		
	case 'q':
		sepuku = 1;
		break;
		
	case 'v':
		verbose++;
		break;

	case ARGP_KEY_ARG:
		if ((numdevs + 1) >= MAX_EVDEV) {
			fprintf (stderr, "%s: too many devices listed (maximum %d)\n",
				 progname, MAX_EVDEV);
			argp_usage (state);
		} else devnames [numdevs++] = arg;

		break;

	case ARGP_KEY_END:
		if ((numdevs < 1) && (sepuku == 0)) {
			fprintf (stderr, "%s: no devices specified.\n", progname);
			argp_usage (state);
		}
		break;

	default:
		return ARGP_ERR_UNKNOWN;
	}
	
	return 0;
}
Example #27
0
/* command parser for GNU argp - see GNU docs for more info */
error_t cmd_parser(int key, char *arg, struct argp_state *state)
{
    settings_t *setup = (settings_t *)state->input;

    switch ( key )
    {
        case 't': /* set new records threshold for logging */
            {
                char *inval;
                setup->new_data_thresh = strtol(arg, &inval, 0);
                if ( inval == arg )
                    argp_usage(state);
            }
            break;

        case 's': /* set sleep time (given in milliseconds) */
            {
                char *inval;
                setup->poll_sleep = millis_to_timespec(strtol(arg, &inval, 0));
                if ( inval == arg )
                    argp_usage(state);
            }
            break;

        case 'm': /* set ms_per_sample */
            {
                char *inval;
                setup->ms_per_sample = strtol(arg, &inval, 0);
                if ( inval == arg )
                    argp_usage(state);
            }
            break;

        case ARGP_KEY_ARG:
            {
                if ( state->arg_num == 0 )
                    setup->outfile = arg;
                else
                    argp_usage(state);
            }
            break;

        default:
            return ARGP_ERR_UNKNOWN;
    }

    return 0;
}
Example #28
0
static error_t _parse_opt (int key, char *arg, struct argp_state *state) {

  args_t *args;

  args = state->input;

  switch (key) {
    case 'f': args->labelf     = arg;                break;
    case 'm': args->maskf      = arg;                break;
    case 's': args->hdrmsg     = arg;                break;
    case 'p': args->corrtype   = CORRTYPE_PEARSON;   break;
    case 'c': args->corrtype   = CORRTYPE_COHERENCE; break;
    case 't': args->sampletime = atof(arg);          break;
    case 'l':
      args->lothresval = atof(arg);
      args->lothres    = &(args->lothresval);
      break;
    case 'h':
      args->hithresval = atof(arg);
      args->hithres    = &(args->hithresval);
      break; 
      
    case 'i':
      if (args->ninclbls < MAX_LABELS) 
        args->inclbls[(args->ninclbls)++] = atof(arg);
      break;
      
    case 'e':
      if (args->nexclbls < MAX_LABELS) 
        args->exclbls[(args->nexclbls)++] = atof(arg);
      break;

    case ARGP_KEY_ARG:
      if      (state->arg_num == 0) args->input  = arg;
      else if (state->arg_num == 1) args->output = arg;
      else                          argp_usage(state);
      break;

    case ARGP_KEY_END:
      if (state->arg_num < 2) argp_usage(state);
      break;

    default:
      return ARGP_ERR_UNKNOWN; 
  }
  
  return 0;
}
Example #29
0
/** \brief Argument parser for argp.
 *
 * \note See argp parser documentation for detailed information about the
 *  structure and functionality of function.
 */
static error_t parse_arguments(int key, char *arg, struct argp_state *state)
{
  switch (key)
    {
    case 'c': setenv("PNMPI_CONF", arg, 1); break;
    case 'm': setenv("PNMPI_LIB_PATH", arg, 1); break;
    case 'q':
    case 's':
      setenv("PNMPI_BE_SILENT", "1", 1);
      break;

    /* If we have parsed all options, iterate through all non-options in argv.
     * If at there are no non-options in our arguments (argv), the user
     * specified no utility to call, so we'll print the argp usage here, which
     * will exit pnmpize immediatly after printing the usage message. */
    case ARGP_KEY_END:
      if (state->arg_num == 0)
        argp_usage(state);
      break;

    default: return ARGP_ERR_UNKNOWN;
    }

  return 0;
}
Example #30
0
static error_t
argp_parser (int key, char *arg, struct argp_state *state)
{
  /* Get the input argument from argp_parse, which we
     know is a pointer to our arguments structure. */
  struct arguments *arguments = state->input;

  switch (key)
    {
    case 'v':
      arguments->verbose = 1;
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num == 0)
	arguments->filename = xstrdup (arg);
      else
	{
	  /* Too many arguments. */
	  fprintf (stderr, _("Unknown extra argument `%s'."), arg);
	  fprintf (stderr, "\n");
	  argp_usage (state);
	}
      break;
    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}