aboutsummaryrefslogtreecommitdiffstats
path: root/g10/misc.c
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2004-02-14 05:03:45 +0000
committerDavid Shaw <[email protected]>2004-02-14 05:03:45 +0000
commitc9aa5000d70b9d2bae7903074c8f10b75815e01d (patch)
treefb4110bcd821ed6dad24a5571e351f1a500aa6ea /g10/misc.c
parent* import.c (check_prefs): Some language fixes. (sec_to_pub_keyblock, (diff)
downloadgnupg-c9aa5000d70b9d2bae7903074c8f10b75815e01d.tar.gz
gnupg-c9aa5000d70b9d2bae7903074c8f10b75815e01d.zip
* keyserver.c (argsep): Move to misc.c.
* main.h, misc.c (parse_options), export.c (parse_export_options), import.c (parse_import_options), g10.c (main): Use it here to allow for options with optional arguments. Change all callers.
Diffstat (limited to 'g10/misc.c')
-rw-r--r--g10/misc.c65
1 files changed, 63 insertions, 2 deletions
diff --git a/g10/misc.c b/g10/misc.c
index 2a8e29211..01f34b4a9 100644
--- a/g10/misc.c
+++ b/g10/misc.c
@@ -669,13 +669,72 @@ compliance_failure(void)
opt.compliance=CO_GNUPG;
}
+char *
+argsep(char **stringp,char **arg)
+{
+ char *tok,*next;
+
+ tok=*stringp;
+ *arg=NULL;
+
+ if(tok)
+ {
+ next=strpbrk(tok," ,=");
+
+ if(next)
+ {
+ int sawequals=0;
+
+ if(*next=='=')
+ sawequals=1;
+
+ *next++='\0';
+ *stringp=next;
+
+ /* what we need to do now is scan along starting with *next.
+ If the next character we see (ignoring spaces) is a =
+ sign, then there is an argument. */
+
+ while(*next)
+ {
+ if(*next=='=')
+ sawequals=1;
+ else if(*next!=' ')
+ break;
+ next++;
+ }
+
+ /* At this point, *next is either an empty string, or the
+ beginning of the next token (which is an argument if
+ sawequals is true). */
+
+ if(sawequals)
+ {
+ *arg=next;
+ next=strpbrk(*arg," ,");
+ if(next)
+ {
+ *next++='\0';
+ *stringp=next;
+ }
+ else
+ *stringp=NULL;
+ }
+ }
+ else
+ *stringp=NULL;
+ }
+
+ return tok;
+}
+
int
parse_options(char *str,unsigned int *options,
struct parse_options *opts,int noisy)
{
- char *tok;
+ char *tok,*arg;
- while((tok=strsep(&str," ,")))
+ while((tok=argsep(&str,&arg)))
{
int i,rev=0;
char *otok=tok;
@@ -715,6 +774,8 @@ parse_options(char *str,unsigned int *options,
*options&=~opts[i].bit;
else
*options|=opts[i].bit;
+ if(opts[i].value)
+ *opts[i].value=arg?m_strdup(arg):NULL;
break;
}
}