mirror of
git://git.gnupg.org/gnupg.git
synced 2025-06-13 18:21:03 +02:00
* main.h, misc.c (argsplit): Refactor argsep into argsplit and argsep so
they can be called separately.
This commit is contained in:
parent
d20a79dd07
commit
2936e539cc
@ -1,5 +1,8 @@
|
|||||||
2004-04-15 David Shaw <dshaw@jabberwocky.com>
|
2004-04-15 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
|
* main.h, misc.c (argsplit): Refactor argsep into argsplit and
|
||||||
|
argsep so they can be called separately.
|
||||||
|
|
||||||
* options.h, keyserver.c (parse_keyserver_options): Remove
|
* options.h, keyserver.c (parse_keyserver_options): Remove
|
||||||
duplicate code from parse_keyserver_options by calling the generic
|
duplicate code from parse_keyserver_options by calling the generic
|
||||||
parse_options.
|
parse_options.
|
||||||
|
@ -108,6 +108,7 @@ struct parse_options
|
|||||||
char **value;
|
char **value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
char *argsplit(char **stringp);
|
||||||
char *argsep(char **stringp,char **arg);
|
char *argsep(char **stringp,char **arg);
|
||||||
int parse_options(char *str,unsigned int *options,
|
int parse_options(char *str,unsigned int *options,
|
||||||
struct parse_options *opts,int noisy);
|
struct parse_options *opts,int noisy);
|
||||||
|
87
g10/misc.c
87
g10/misc.c
@ -644,57 +644,46 @@ compliance_failure(void)
|
|||||||
opt.compliance=CO_GNUPG;
|
opt.compliance=CO_GNUPG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Break a string into option pieces. Accepts single word options and
|
||||||
|
key=value argument options. */
|
||||||
char *
|
char *
|
||||||
argsep(char **stringp,char **arg)
|
argsplit(char **stringp)
|
||||||
{
|
{
|
||||||
char *tok,*next;
|
char *tok,*end;
|
||||||
|
|
||||||
tok=*stringp;
|
tok=*stringp;
|
||||||
*arg=NULL;
|
|
||||||
|
|
||||||
if(tok)
|
if(tok)
|
||||||
{
|
{
|
||||||
next=strpbrk(tok," ,=");
|
end=strpbrk(tok," ,=");
|
||||||
|
if(end)
|
||||||
if(next)
|
|
||||||
{
|
{
|
||||||
int sawequals=0;
|
int sawequals=0;
|
||||||
|
char *ptr=end;
|
||||||
|
|
||||||
if(*next=='=')
|
/* what we need to do now is scan along starting with *end,
|
||||||
sawequals=1;
|
If the next character we see (ignoring spaces) is an =
|
||||||
|
|
||||||
*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. */
|
sign, then there is an argument. */
|
||||||
|
|
||||||
while(*next)
|
while(*ptr)
|
||||||
{
|
{
|
||||||
if(*next=='=')
|
if(*ptr=='=')
|
||||||
sawequals=1;
|
sawequals=1;
|
||||||
else if(*next!=' ')
|
else if(*ptr!=' ')
|
||||||
break;
|
break;
|
||||||
next++;
|
ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* At this point, *next is either an empty string, or the
|
/* There is an argument, so grab that too. */
|
||||||
beginning of the next token (which is an argument if
|
|
||||||
sawequals is true). */
|
|
||||||
|
|
||||||
if(sawequals)
|
if(sawequals)
|
||||||
|
end=strpbrk(ptr," ,");
|
||||||
|
|
||||||
|
if(end)
|
||||||
{
|
{
|
||||||
*arg=next;
|
*end='\0';
|
||||||
next=strpbrk(*arg," ,");
|
*stringp=end+1;
|
||||||
if(next)
|
|
||||||
{
|
|
||||||
*next++='\0';
|
|
||||||
*stringp=next;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*stringp=NULL;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
*stringp=NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*stringp=NULL;
|
*stringp=NULL;
|
||||||
@ -703,6 +692,40 @@ argsep(char **stringp,char **arg)
|
|||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Break an option or key=value option into key and value */
|
||||||
|
char *
|
||||||
|
argsep(char **stringp,char **arg)
|
||||||
|
{
|
||||||
|
char *tok;
|
||||||
|
|
||||||
|
*arg=NULL;
|
||||||
|
|
||||||
|
tok=argsplit(stringp);
|
||||||
|
if(tok)
|
||||||
|
{
|
||||||
|
char *equals;
|
||||||
|
equals=strchr(tok,'=');
|
||||||
|
if(equals)
|
||||||
|
{
|
||||||
|
char *space;
|
||||||
|
|
||||||
|
space=strchr(tok,' ');
|
||||||
|
if(space)
|
||||||
|
*space='\0';
|
||||||
|
else
|
||||||
|
*equals='\0';
|
||||||
|
|
||||||
|
space=strrchr(equals+1,' ');
|
||||||
|
if(space)
|
||||||
|
*arg=space+1;
|
||||||
|
else
|
||||||
|
*arg=NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tok;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
parse_options(char *str,unsigned int *options,
|
parse_options(char *str,unsigned int *options,
|
||||||
struct parse_options *opts,int noisy)
|
struct parse_options *opts,int noisy)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user