예제 #1
0
 bool find(const std::string& a_short, const std::string& a_long, T* a_val) const {
     auto setter = [=](const char* a) { if (a_val) *a_val = convert<T>(a); };
     for (int i=1; i < m_argc; ++i)
         if (match_opt(m_argc, m_argv, setter, a_short, i)
         ||  match_opt(m_argc, m_argv, setter, a_long,  i))
             return true;
     return false;
 }
예제 #2
0
static here_search_result_ctx *here_execute_search_program_step(
                                const char *buffer,
                                const char *buffer_end,
                                here_search_program_ctx *step) {
    here_search_result_ctx *search_result = NULL;
    switch (step->ctype) {
        case HERE_CTYPE_CMATCH:
            search_result = match_char(buffer, buffer_end, step);
            break;

        case HERE_CTYPE_END:
            search_result = match_end(buffer, buffer_end, step);
            break;

        case HERE_CTYPE_DOT:
            search_result = match_dot(buffer, buffer_end, step);
            break;

        case HERE_CTYPE_LIST:
            search_result = match_list(buffer, buffer_end, step);
            break;

        case HERE_CTYPE_OPTION:
            search_result = match_opt(buffer, buffer_end, step);
            break;

        default:
            //bypass duh!
            break;
    }
    return search_result;
}
예제 #3
0
int
fuse_opt_match(const struct fuse_opt *opts, const char *opt)
{
	const struct fuse_opt *this_opt = opts;

	if (opt == NULL || opt[0] == '\0')
		return (0);

	while (this_opt->templ) {
		if (match_opt(this_opt->templ, opt))
			return (1);
		this_opt++;
	}

	return (0);
}
예제 #4
0
void
tw_opt_parse(int *argc_p, char ***argv_p)
{
    int argc = *argc_p;
    char **argv = *argv_p;
    unsigned i;

    program = strrchr(argv[0], '/');
    if (program)
        program++;
    else
        program = argv[0];

    for (i = 0; opt_groups[i]; i++)
    {
        if (!(opt_groups[i])->type || is_empty(opt_groups[i]))
            continue;
        if (i >= ARRAY_SIZE(all_groups))
            tw_error(TW_LOC, "Too many tw_optdef arrays.");
        all_groups[i] = opt_groups[i];
    }
    all_groups[i++] = basic;
    all_groups[i] = NULL;

    while (argc > 1)
    {
        const char *s = argv[1];
        if (strncmp(s, "--", 2))
        {
            printf("Warning: found ill-formated argument: %s, stopping arg parsing here!! \n", s );
            break;
        }
        if (strcmp(s, "--"))
            match_opt(s);

        argc--;
        memmove(argv + 1, argv + 2, (argc - 1) * sizeof(*argv));

        if (!strcmp(s, "--"))
            break;
    }

    *argc_p = argc;
    *argv_p = argv;
}
예제 #5
0
 bool match(const std::string& a_short, const std::string& a_long, const Setter& a_fun) {
     return match_opt(m_argc, m_argv, a_fun, a_short, m_idx)
         || match_opt(m_argc, m_argv, a_fun, a_long,  m_idx);
 }
예제 #6
0
 bool match(const std::string& a_short, const std::string& a_long) {
     return match_opt(m_argc, m_argv, nullptr, a_short, m_idx)
         || match_opt(m_argc, m_argv, nullptr, a_long,  m_idx);
 }
예제 #7
0
파일: options.cpp 프로젝트: UCNA/gms
// ---------------------------------------------------------------------------
// ^FUNCTION: Options::parse_opt - parse an option
//
// ^SYNOPSIS:
//    int Options::parse_opt(iter, optarg)
//
// ^PARAMETERS:
//    OptIter & iter -- option iterator
//    const char * & optarg -- where to store any option-argument
//
// ^DESCRIPTION:
//    Parse the next option in iter (advancing as necessary).
//    Make sure we update the nextchar pointer along the way. Any option
//    we find should be returned and optarg should point to its argument.
//
// ^REQUIREMENTS:
//    - nextchar must point to the prospective option character
//
// ^SIDE-EFFECTS:
//    - iter is advanced when an argument completely parsed
//    - optarg is modified to point to any option argument
//    - if Options::QUIET is not set, error messages are printed on cerr
//
// ^RETURN-VALUE:
//    'c' if the -c option was matched (optarg points to its argument)
//    BADCHAR if the option is invalid (optarg points to the bad
//                                                   option-character).
//
// ^ALGORITHM:
//    It gets complicated -- follow the comments in the source.
// ^^-------------------------------------------------------------------------
int
Options::parse_opt(OptIter & iter, const char * & optarg) {
   listopt = NULLSTR;  // reset the list pointer

   if ((optvec == NULL) || (! *optvec))  return  Options::ENDOPTS;

      // Try to match a known option
   OptionSpec optspec = match_opt(*(nextchar++), (optctrls & Options::ANYCASE));

      // Check for an unknown option
   if (optspec.isNULL()) {
      // See if this was a long-option in disguise
      if (! (optctrls & Options::NOGUESSING)) {
         unsigned  save_ctrls = optctrls;
         const char * save_nextchar = nextchar;
         nextchar -= 1;
         optctrls |= (Options::QUIET | Options::NOGUESSING);
         int  optchar = parse_longopt(iter, optarg);
         optctrls = save_ctrls;
         if (optchar > 0) {
            return  optchar;
         } else {
            nextchar = save_nextchar;
         }
      }
      if (! (optctrls & Options::QUIET)) {
         cerr << cmdname << ": unknown option -"
              << *(nextchar - 1) << "." << endl ;
      }
      optarg = (nextchar - 1);  // record the bad option in optarg
      return  Options::BADCHAR;
   }

      // If no argument is taken, then leave now
   if (optspec.isNoArg()) {
      optarg = NULLSTR;
      return  optspec.OptChar();
   }

      // Check for argument in this arg
   if (*nextchar) {
      optarg = nextchar; // the argument is right here
      nextchar = NULLSTR;   // we've exhausted this arg
      if (optspec.isList())  listopt = optspec ;  // save the list-spec
      return  optspec.OptChar();
   }

      // Check for argument in next arg
   const char * nextarg = iter.curr();
   if ((nextarg != NULL)  &&
       (optspec.isValRequired() || (! isOption(optctrls, nextarg)))) {
      optarg = nextarg;    // the argument is here
      iter.next();         // end of arg - advance
      if (optspec.isList())  listopt = optspec ;  // save the list-spec
      return  optspec.OptChar();
   }

     // No argument given - if its required, thats an error
   optarg = NULLSTR;
   if (optspec.isValRequired() &&  !(optctrls & Options::QUIET)) {
      cerr << cmdname << ": argument required for -" << optspec.OptChar()
           << " option." << endl ;
   }
   return  optspec.OptChar();
}
예제 #8
0
static int cell_shutdown_load(int argc, char *argv[],
			      enum shutdown_load_mode mode)
{
	unsigned int images, id_args, arg_num, n;
	struct jailhouse_preload_image *image;
	struct jailhouse_cell_load *cell_load;
	struct jailhouse_cell_id cell_id;
	size_t size;
	int err, fd;
	char *endp;

	id_args = parse_cell_id(&cell_id, argc - 3, &argv[3]);
	arg_num = 3 + id_args;
	if (id_args == 0 || (mode == SHUTDOWN && arg_num != argc) ||
	    (mode == LOAD && arg_num == argc))
		help(argv[0], 1);

	images = 0;
	while (arg_num < argc) {
		images++;
		arg_num++;

		if (arg_num < argc &&
		    match_opt(argv[arg_num], "-a", "--address")) {
			if (arg_num + 1 >= argc)
				help(argv[0], 1);
			arg_num += 2;
		}
	}

	cell_load = malloc(sizeof(*cell_load) + sizeof(*image) * images);
	if (!cell_load) {
		fprintf(stderr, "insufficient memory\n");
		exit(1);
	}
	cell_load->cell_id = cell_id;
	cell_load->num_preload_images = images;

	arg_num = 3 + id_args;

	for (n = 0, image = cell_load->image; n < images; n++, image++) {
		image->source_address =
			(unsigned long)read_file(argv[arg_num++], &size);
		image->size = size;
		image->target_address = 0;

		if (arg_num < argc &&
		    match_opt(argv[arg_num], "-a", "--address")) {
			errno = 0;
			image->target_address =
				strtoll(argv[arg_num + 1], &endp, 0);
			if (errno != 0 || *endp != 0)
				help(argv[0], 1);
			arg_num += 2;
		}
	}

	fd = open_dev();

	err = ioctl(fd, JAILHOUSE_CELL_LOAD, cell_load);
	if (err)
		perror("JAILHOUSE_CELL_LOAD");

	close(fd);
	for (n = 0, image = cell_load->image; n < images; n++, image++)
		free((void *)(unsigned long)image->source_address);
	free(cell_load);

	return err;
}