mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-21 10:09:57 +01:00
common: New functions get_option_value and ascii_strupr.
* common/server-help.c (get_option_value): New. * common/stringhelp.c (ascii_strupr): New. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
b79bc877f2
commit
e2f18023b3
@ -30,8 +30,22 @@
|
||||
#include <config.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "server-help.h"
|
||||
#include "util.h"
|
||||
#include "server-help.h"
|
||||
|
||||
|
||||
static GPGRT_INLINE gpg_error_t
|
||||
my_error (int e)
|
||||
{
|
||||
return gpg_err_make (default_errsource, (e));
|
||||
}
|
||||
|
||||
static GPGRT_INLINE gpg_error_t
|
||||
my_error_from_syserror (void)
|
||||
{
|
||||
return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||
}
|
||||
|
||||
|
||||
/* Skip over options in LINE.
|
||||
|
||||
@ -114,6 +128,40 @@ has_option_name (const char *line, const char *name)
|
||||
}
|
||||
|
||||
|
||||
/* Parse an option with the format "--NAME=VALUE" which must occur in
|
||||
* LINE before a double-dash. LINE is written to but not modified by
|
||||
* this function. If the option is found and has a value the value is
|
||||
* stored as a malloced string at R_VALUE. If the option was not
|
||||
* found or an error occurred NULL is stored there. Note that
|
||||
* currently the value must be a string without any space; we may
|
||||
* eventually update this function to allow for a quoted value. */
|
||||
gpg_error_t
|
||||
get_option_value (char *line, const char *name, char **r_value)
|
||||
{
|
||||
char *p, *pend;
|
||||
int c;
|
||||
|
||||
*r_value = NULL;
|
||||
|
||||
p = (char*)has_option_name (line, name);
|
||||
if (!p || p >= skip_options (line))
|
||||
return 0;
|
||||
|
||||
if (*p != '=' || !p[1] || spacep (p+1))
|
||||
return my_error (GPG_ERR_INV_ARG);
|
||||
p++;
|
||||
for (pend = p; *pend && !spacep (pend); pend++)
|
||||
;
|
||||
c = *pend;
|
||||
*pend = 0;
|
||||
*r_value = xtrystrdup (p);
|
||||
*pend = c;
|
||||
if (!p)
|
||||
return my_error_from_syserror ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Return a pointer to the argument of the option with NAME. If such
|
||||
an option is not given, NULL is returned. */
|
||||
char *
|
||||
|
@ -55,6 +55,14 @@ int has_leading_option (const char *line, const char *name);
|
||||
or a space. */
|
||||
const char *has_option_name (const char *line, const char *name);
|
||||
|
||||
/* Same as has_option_name but ignores all options after a "--" and
|
||||
* does not return a const char ptr. */
|
||||
char *has_leading_option_name (char *line, const char *name);
|
||||
|
||||
/* Parse an option with the format "--NAME=VALUE" and return the value
|
||||
* as a malloced string. */
|
||||
gpg_error_t get_option_value (char *line, const char *name, char **r_value);
|
||||
|
||||
/* Return a pointer to the argument of the option with NAME. If such
|
||||
an option is not given, NULL is returned. */
|
||||
char *option_value (const char *line, const char *name);
|
||||
|
@ -810,6 +810,19 @@ ascii_strlwr (char *s)
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Upcase all ASCII characters in S. */
|
||||
char *
|
||||
ascii_strupr (char *s)
|
||||
{
|
||||
char *p = s;
|
||||
|
||||
for (p=s; *p; p++ )
|
||||
if (isascii (*p) && *p >= 'a' && *p <= 'z')
|
||||
*p &= ~0x20;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
ascii_strcasecmp( const char *a, const char *b )
|
||||
{
|
||||
|
@ -76,6 +76,7 @@ int ascii_islower (int c);
|
||||
int ascii_toupper (int c);
|
||||
int ascii_tolower (int c);
|
||||
char *ascii_strlwr (char *s);
|
||||
char *ascii_strupr (char *s);
|
||||
int ascii_strcasecmp( const char *a, const char *b );
|
||||
int ascii_strncasecmp (const char *a, const char *b, size_t n);
|
||||
int ascii_memcasecmp( const void *a, const void *b, size_t n );
|
||||
|
Loading…
x
Reference in New Issue
Block a user