Response to issue #513 in the github issue tracker: The command-
line parser does not recognize arguments that are both in the same word and also space separated; this is easy to do from, e.g., a python interpreter by setting an option as a single string as in "-d null"; it is harder to do from the command line, but can be done with quotes, as in 'magic "-d null"'. The utils/args.c routine parses this with ArgStr(), which recognizes two cases, one in which the option is split across two arguments, and one in which the option is one word without space separation. I modified ArgStr() to accept a third syntax in which the option is in a single argument but is also space-separated. This simply detects a space in the third character position and moves forward to the next non-space character and returns that position.
This commit is contained in:
parent
85561d0503
commit
0013dda92d
32
utils/args.c
32
utils/args.c
|
|
@ -21,6 +21,7 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
|
|||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "utils/magic.h"
|
||||
#include "utils/utils.h"
|
||||
|
|
@ -34,12 +35,13 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
|
|||
* ArgStr --
|
||||
*
|
||||
* Process a single argument that is supposed to have a string value.
|
||||
* A string argument can appear in two ways:
|
||||
* A string argument can appear in three ways:
|
||||
*
|
||||
* -avalue (a single element of argv)
|
||||
* -a value (two elements of argv)
|
||||
* "-a value" (a single element of argv, space-separated)
|
||||
*
|
||||
* Both are recognized.
|
||||
* All three forms are recognized.
|
||||
*
|
||||
* Results:
|
||||
* Returns a pointer to the value, or NULL if there wasn't one.
|
||||
|
|
@ -56,15 +58,29 @@ char *
|
|||
ArgStr(
|
||||
int *pargc,
|
||||
char ***pargv,
|
||||
const char *argType)/* For error messages: what the following string is
|
||||
* supposed to be interpreted as.
|
||||
*/
|
||||
const char *argType) /* For error messages: what the following
|
||||
* string is supposed to be interpreted as.
|
||||
*/
|
||||
{
|
||||
char **argv = *pargv;
|
||||
char *result;
|
||||
char *argptr;
|
||||
|
||||
if (argv[0][2])
|
||||
return (&argv[0][2]);
|
||||
argptr = argv[0];
|
||||
argptr++;
|
||||
if (*argptr == '\0')
|
||||
{
|
||||
TxError("Bad argument %s\n", argv[0]);
|
||||
return NULL;
|
||||
}
|
||||
argptr++;
|
||||
if (*argptr != '\0')
|
||||
{
|
||||
while (isspace(*argptr))
|
||||
argptr++;
|
||||
|
||||
return argptr;
|
||||
}
|
||||
|
||||
if ((*pargc)-- > 0)
|
||||
{
|
||||
|
|
@ -74,5 +90,5 @@ ArgStr(
|
|||
}
|
||||
|
||||
TxError("-%c requires a following %s\n", argv[0][1], argType);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue