示例#1
0
/*
 * Register several long options. options is a string of long options,
 * separated by commas or whitespace. This nukes options!
 */
static void add_long_options(char *options)
{
	int arg_opt;
	char *tokptr = strtok(options, ", \t\n");
	while (tokptr) {
		arg_opt = no_argument;
		if (strlen(tokptr) > 0) {
			if (tokptr[strlen(tokptr) - 1] == ':') {
				if (tokptr[strlen(tokptr) - 2] == ':') {
					tokptr[strlen(tokptr) - 2] = '\0';
					arg_opt = optional_argument;
				} else {
					tokptr[strlen(tokptr) - 1] = '\0';
					arg_opt = required_argument;
				}
				if (strlen(tokptr) == 0)
					parse_error(_
						    ("empty long option after "
						     "-l or --long argument"));
			}
			add_longopt(tokptr, arg_opt);
		}
		tokptr = strtok(NULL, ", \t\n");
	}
}
示例#2
0
/*
 * Register several long options. options is a string of long options,
 * separated by commas or whitespace.
 * This nukes options!
 */
void add_long_options(char *options)
{
        int arg_opt, tlen;
        char *tokptr=strtok(options,", \t\n");
        while (tokptr) {
                arg_opt=no_argument;
		tlen=strlen(tokptr);
                if (tlen > 0) {
                        if (tokptr[tlen-1] == ':') {
                                if (tlen > 1 && tokptr[tlen-2] == ':') {
                                        tokptr[tlen-2]='\0';
					tlen -= 2;
                                        arg_opt=optional_argument;
                                } else {
                                        tokptr[tlen-1]='\0';
					tlen -= 1;
                                        arg_opt=required_argument;
                                }
                                if (tlen == 0)
                                        error_msg("empty long option after -l or --long argument");
                        }
                        add_longopt(tokptr,arg_opt);
                }
                tokptr=strtok(NULL,", \t\n");
        }
}