コード例 #1
0
arg_parse(char *str, arg_info *entry)
#endif
{
    int length = 0;

    if (arg_count (*entry) == P_ONE_ARG) {
	char **store = (char **) arg_result_ptr (*entry);

	length = put_one_arg (arg_result_type (*entry), str, store,
		arg_prefix (*entry), arg_string (*entry));

    } /* if (arg_count == P_ONE_ARG) */
      else { /* Must be a table of arguments */
	char **store = (char **) arg_result_ptr (*entry);

	if (store) {
	    while (*store)
		store++;

	    length = put_one_arg(arg_result_type (*entry), str, store++,
		    arg_prefix (*entry), arg_string (*entry));

	    *store = (char *) NULL;
	} /* if (store) */
    } /* else */

    return length;
} /* arg_parse */
コード例 #2
0
/* Return a textual representation of the reg */
static char *
get_field (unsigned long instr, unsigned long mask, unsigned short low, unsigned type)
{
    char tmpstr[25];
    int x = (int)((instr >> low) & mask);

    if (mask+1 == 1<<26) {
	x <<= 2;
    }

    if (arg_prefix(type)[0])
	sprintf (tmpstr, "%c%d", *arg_prefix(type), x);
    else
	sprintf (tmpstr, "0x%x", (unsigned)x);

    return (strdup (tmpstr));
}
コード例 #3
0
match(char *norm_input, char *low_input, arg_info *entry, boolean use_prefix)
#endif
{
    char *norm_prefix = arg_prefix (*entry);
    char *norm_string = arg_string (*entry);
    boolean prefix_match = FALSE, string_match = FALSE;
    int result = 0;

/* Buffers for the lowercased versions of the strings being compared.
   These are used when the switch is to be case insensitive */

    static char low_prefix[MAX_INPUT_SIZE];
    static char low_string[MAX_INPUT_SIZE];
    int prefix_length = strlen (norm_prefix);
    int string_length = strlen (norm_string);

/* Pointers for the required strings (lowered or nonlowered) */

    register char *input, *prefix, *string;

/* FUNCTION BODY */

/* Use the appropriate strings to handle case sensitivity */

    if (arg_flags (*entry) & P_CASE_INSENSITIVE) {
	input = low_input;
	prefix = lower_string (low_prefix, norm_prefix);
	string = lower_string (low_string, norm_string);
    } else {
	input = norm_input;
	prefix = norm_prefix;
	string = norm_string;
    } /* else */

/* First, check the string formed by concatenating the prefix onto the
   switch string, but only when the prefix is not being ignored */

    if (use_prefix && prefix != NULL && *prefix != '\0')
	 prefix_match = (strncmp (input, prefix, prefix_length) == 0) &&
		(strncmp (input + prefix_length, string, string_length) == 0);

/* Next, check just the switch string, if that's allowed */

    if (!use_prefix && (arg_flags (*entry) & P_REQUIRED_PREFIX) == 0)
	string_match = strncmp (input, string, string_length) == 0;

    if (prefix_match)
	result = prefix_length + string_length;
    else if (string_match)
	result = string_length;

    return result;
} /* match */