mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-12 22:11:29 +02:00
common: New function parse_compatibility_flags.
* common/miscellaneous.c (parse_compatibility_flags): New. * common/util.h (struct compatibility_flags_s): New. -- This is similar to parse_debug_flags but does not support specifying a value. This way we can more easily change the internal values or re-use them for other purposes.
This commit is contained in:
parent
dd600bbc84
commit
ce63eaa4f8
@ -712,3 +712,83 @@ parse_debug_flag (const char *string, unsigned int *debugvar,
|
|||||||
*debugvar |= result;
|
*debugvar |= result;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Parse an --comaptibility_flags style argument consisting of comma
|
||||||
|
* separated strings.
|
||||||
|
*
|
||||||
|
* Returns: 0 on success or -1 and ERRNO set on error. On success the
|
||||||
|
* supplied variable is updated by the parsed flags.
|
||||||
|
*
|
||||||
|
* If STRING is NULL the enabled flags are printed.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
parse_compatibility_flags (const char *string, unsigned int *flagvar,
|
||||||
|
const struct compatibility_flags_s *flags)
|
||||||
|
|
||||||
|
{
|
||||||
|
unsigned long result = 0;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
if (!string)
|
||||||
|
{
|
||||||
|
if (flagvar)
|
||||||
|
{
|
||||||
|
log_info ("enabled compatibility flags:");
|
||||||
|
for (i=0; flags[i].name; i++)
|
||||||
|
if ((*flagvar & flags[i].flag))
|
||||||
|
log_printf (" %s", flags[i].name);
|
||||||
|
log_printf ("\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (spacep (string))
|
||||||
|
string++;
|
||||||
|
|
||||||
|
if (!strcmp (string, "?") || !strcmp (string, "help"))
|
||||||
|
{
|
||||||
|
log_info ("available compatibility flags:\n");
|
||||||
|
for (i=0; flags[i].name; i++)
|
||||||
|
log_info (" %s\n", flags[i].name);
|
||||||
|
if (flags[i].flag != 77)
|
||||||
|
exit (0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char **words;
|
||||||
|
words = strtokenize (string, ",");
|
||||||
|
if (!words)
|
||||||
|
return -1;
|
||||||
|
for (i=0; words[i]; i++)
|
||||||
|
{
|
||||||
|
if (*words[i])
|
||||||
|
{
|
||||||
|
for (j=0; flags[j].name; j++)
|
||||||
|
if (!strcmp (words[i], flags[j].name))
|
||||||
|
{
|
||||||
|
result |= flags[j].flag;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!flags[j].name)
|
||||||
|
{
|
||||||
|
if (!strcmp (words[i], "none"))
|
||||||
|
{
|
||||||
|
*flagvar = 0;
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
else if (!strcmp (words[i], "all"))
|
||||||
|
result = ~0;
|
||||||
|
else
|
||||||
|
log_info ("unknown compatibility flag '%s' ignored\n",
|
||||||
|
words[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xfree (words);
|
||||||
|
}
|
||||||
|
|
||||||
|
*flagvar |= result;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -372,6 +372,15 @@ struct debug_flags_s
|
|||||||
int parse_debug_flag (const char *string, unsigned int *debugvar,
|
int parse_debug_flag (const char *string, unsigned int *debugvar,
|
||||||
const struct debug_flags_s *flags);
|
const struct debug_flags_s *flags);
|
||||||
|
|
||||||
|
struct compatibility_flags_s
|
||||||
|
{
|
||||||
|
unsigned int flag;
|
||||||
|
const char *name;
|
||||||
|
const char *desc;
|
||||||
|
};
|
||||||
|
int parse_compatibility_flags (const char *string, unsigned int *flagvar,
|
||||||
|
const struct compatibility_flags_s *flags);
|
||||||
|
|
||||||
|
|
||||||
/*-- Simple replacement functions. */
|
/*-- Simple replacement functions. */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user