forked from enlightenment/efl
efl/ecore_getopt: add ECORE_GETOPT_ACTION_BREAK.
Thanks to PrinceAMD (Deon Thomas) for bugging me to implement this, then test and add a fix, now we can implement something similar to "xterm -e" in terminology. ECORE_GETOPT_ACTION_BREAK will allow generic options to behave the same as GNU's --, breaking out of argument parsing logic. SVN revision: 80619
This commit is contained in:
parent
0ca0b36df1
commit
c5667e3802
|
@ -1,3 +1,8 @@
|
||||||
|
2012-12-10 Gustavo Sverzut Barbieri (k-s)
|
||||||
|
|
||||||
|
* Added ECORE_GETOPT_ACTION_BREAK to force breaking out of argument
|
||||||
|
parsing logic (will behabe same as GNU's "--", useful for xterm -e)
|
||||||
|
|
||||||
2012-12-07 Cedric Bail
|
2012-12-07 Cedric Bail
|
||||||
|
|
||||||
* Don't leak fd on exec.
|
* Don't leak fd on exec.
|
||||||
|
|
1
NEWS
1
NEWS
|
@ -38,6 +38,7 @@ Additions:
|
||||||
- Add window profile support.
|
- Add window profile support.
|
||||||
* ecore_evas_buffer:
|
* ecore_evas_buffer:
|
||||||
- Add window profile support.
|
- Add window profile support.
|
||||||
|
* ecore_getopt: add ECORE_GETOPT_ACTION_BREAK
|
||||||
|
|
||||||
Deprecations:
|
Deprecations:
|
||||||
* ecore_x:
|
* ecore_x:
|
||||||
|
|
|
@ -64,7 +64,8 @@ typedef enum {
|
||||||
ECORE_GETOPT_ACTION_HELP,
|
ECORE_GETOPT_ACTION_HELP,
|
||||||
ECORE_GETOPT_ACTION_VERSION,
|
ECORE_GETOPT_ACTION_VERSION,
|
||||||
ECORE_GETOPT_ACTION_COPYRIGHT,
|
ECORE_GETOPT_ACTION_COPYRIGHT,
|
||||||
ECORE_GETOPT_ACTION_LICENSE
|
ECORE_GETOPT_ACTION_LICENSE,
|
||||||
|
ECORE_GETOPT_ACTION_BREAK
|
||||||
} Ecore_Getopt_Action;
|
} Ecore_Getopt_Action;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -369,6 +370,16 @@ struct _Ecore_Getopt
|
||||||
ECORE_GETOPT_ACTION_LICENSE, \
|
ECORE_GETOPT_ACTION_LICENSE, \
|
||||||
{.dummy = NULL}}
|
{.dummy = NULL}}
|
||||||
|
|
||||||
|
#define ECORE_GETOPT_BREAK(shortname, longname) \
|
||||||
|
{shortname, longname, "stop parsing options.", NULL, \
|
||||||
|
ECORE_GETOPT_ACTION_BREAK, \
|
||||||
|
{.dummy = NULL}}
|
||||||
|
|
||||||
|
#define ECORE_GETOPT_BREAK_STR(shortname, longname, help) \
|
||||||
|
{shortname, longname, help, NULL, \
|
||||||
|
ECORE_GETOPT_ACTION_BREAK, \
|
||||||
|
{.dummy = NULL}}
|
||||||
|
|
||||||
#define ECORE_GETOPT_SENTINEL {0, NULL, NULL, NULL, 0, {.dummy = NULL}}
|
#define ECORE_GETOPT_SENTINEL {0, NULL, NULL, NULL, 0, {.dummy = NULL}}
|
||||||
|
|
||||||
#define ECORE_GETOPT_VALUE_STR(val) {.strp = &(val)}
|
#define ECORE_GETOPT_VALUE_STR(val) {.strp = &(val)}
|
||||||
|
|
|
@ -763,19 +763,26 @@ _ecore_getopt_parse_find_nonargs_base(const Ecore_Getopt *parser,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
char **nonargs;
|
char **nonargs;
|
||||||
int src, dst, used, base;
|
int src, dst, used, base, abreak;
|
||||||
|
|
||||||
nonargs = alloca(sizeof(char *) * argc);
|
nonargs = alloca(sizeof(char *) * argc);
|
||||||
src = 1;
|
src = 1;
|
||||||
dst = 1;
|
dst = 1;
|
||||||
used = 0;
|
used = 0;
|
||||||
base = 0;
|
base = 0;
|
||||||
|
abreak = 0;
|
||||||
while (src < argc)
|
while (src < argc)
|
||||||
{
|
{
|
||||||
const Ecore_Getopt_Desc *desc;
|
const Ecore_Getopt_Desc *desc;
|
||||||
Ecore_Getopt_Desc_Arg_Requirement arg_req;
|
Ecore_Getopt_Desc_Arg_Requirement arg_req;
|
||||||
char *arg = argv[src];
|
char *arg = argv[src];
|
||||||
|
|
||||||
|
if (abreak)
|
||||||
|
{
|
||||||
|
base = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (arg[0] != '-')
|
if (arg[0] != '-')
|
||||||
goto found_nonarg;
|
goto found_nonarg;
|
||||||
|
|
||||||
|
@ -806,6 +813,11 @@ _ecore_getopt_parse_find_nonargs_base(const Ecore_Getopt *parser,
|
||||||
goto found_nonarg;
|
goto found_nonarg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (desc->action == ECORE_GETOPT_ACTION_BREAK)
|
||||||
|
abreak = 1;
|
||||||
|
|
||||||
if (src != dst)
|
if (src != dst)
|
||||||
argv[dst] = argv[src];
|
argv[dst] = argv[src];
|
||||||
src++;
|
src++;
|
||||||
|
@ -1407,6 +1419,18 @@ _ecore_getopt_parse_license(const Ecore_Getopt *parser,
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Eina_Bool
|
||||||
|
_ecore_getopt_parse_break(const Ecore_Getopt *parser EINA_UNUSED,
|
||||||
|
const Ecore_Getopt_Desc *desc EINA_UNUSED,
|
||||||
|
Ecore_Getopt_Value *val,
|
||||||
|
const char *arg_val EINA_UNUSED)
|
||||||
|
{
|
||||||
|
if (val->boolp)
|
||||||
|
(*val->boolp) = EINA_TRUE;
|
||||||
|
|
||||||
|
return EINA_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_ecore_getopt_desc_handle(const Ecore_Getopt *parser,
|
_ecore_getopt_desc_handle(const Ecore_Getopt *parser,
|
||||||
const Ecore_Getopt_Desc *desc,
|
const Ecore_Getopt_Desc *desc,
|
||||||
|
@ -1451,6 +1475,9 @@ _ecore_getopt_desc_handle(const Ecore_Getopt *parser,
|
||||||
case ECORE_GETOPT_ACTION_LICENSE:
|
case ECORE_GETOPT_ACTION_LICENSE:
|
||||||
return _ecore_getopt_parse_license(parser, desc, value, arg_val);
|
return _ecore_getopt_parse_license(parser, desc, value, arg_val);
|
||||||
|
|
||||||
|
case ECORE_GETOPT_ACTION_BREAK:
|
||||||
|
return _ecore_getopt_parse_break(parser, desc, value, arg_val);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue