summaryrefslogtreecommitdiff
path: root/src/lib/ecore/ecore_getopt.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-10 18:43:36 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-10 18:43:36 +0000
commitc5667e38029a6f3d6377f9a26b2f2dcbac5a1d6b (patch)
treea1223ecf055e52ec6d631f5aca39335143595ee5 /src/lib/ecore/ecore_getopt.c
parent0ca0b36df13855c38a2d97395eddfb945566b5d5 (diff)
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
Diffstat (limited to 'src/lib/ecore/ecore_getopt.c')
-rw-r--r--src/lib/ecore/ecore_getopt.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/lib/ecore/ecore_getopt.c b/src/lib/ecore/ecore_getopt.c
index 42e43e8915..f31f7c2290 100644
--- a/src/lib/ecore/ecore_getopt.c
+++ b/src/lib/ecore/ecore_getopt.c
@@ -763,19 +763,26 @@ _ecore_getopt_parse_find_nonargs_base(const Ecore_Getopt *parser,
763 char **argv) 763 char **argv)
764{ 764{
765 char **nonargs; 765 char **nonargs;
766 int src, dst, used, base; 766 int src, dst, used, base, abreak;
767 767
768 nonargs = alloca(sizeof(char *) * argc); 768 nonargs = alloca(sizeof(char *) * argc);
769 src = 1; 769 src = 1;
770 dst = 1; 770 dst = 1;
771 used = 0; 771 used = 0;
772 base = 0; 772 base = 0;
773 abreak = 0;
773 while (src < argc) 774 while (src < argc)
774 { 775 {
775 const Ecore_Getopt_Desc *desc; 776 const Ecore_Getopt_Desc *desc;
776 Ecore_Getopt_Desc_Arg_Requirement arg_req; 777 Ecore_Getopt_Desc_Arg_Requirement arg_req;
777 char *arg = argv[src]; 778 char *arg = argv[src];
778 779
780 if (abreak)
781 {
782 base = 1;
783 break;
784 }
785
779 if (arg[0] != '-') 786 if (arg[0] != '-')
780 goto found_nonarg; 787 goto found_nonarg;
781 788
@@ -806,6 +813,11 @@ _ecore_getopt_parse_find_nonargs_base(const Ecore_Getopt *parser,
806 goto found_nonarg; 813 goto found_nonarg;
807 } 814 }
808 815
816
817
818 if (desc->action == ECORE_GETOPT_ACTION_BREAK)
819 abreak = 1;
820
809 if (src != dst) 821 if (src != dst)
810 argv[dst] = argv[src]; 822 argv[dst] = argv[src];
811 src++; 823 src++;
@@ -1408,6 +1420,18 @@ _ecore_getopt_parse_license(const Ecore_Getopt *parser,
1408} 1420}
1409 1421
1410static Eina_Bool 1422static Eina_Bool
1423_ecore_getopt_parse_break(const Ecore_Getopt *parser EINA_UNUSED,
1424 const Ecore_Getopt_Desc *desc EINA_UNUSED,
1425 Ecore_Getopt_Value *val,
1426 const char *arg_val EINA_UNUSED)
1427{
1428 if (val->boolp)
1429 (*val->boolp) = EINA_TRUE;
1430
1431 return EINA_TRUE;
1432}
1433
1434static Eina_Bool
1411_ecore_getopt_desc_handle(const Ecore_Getopt *parser, 1435_ecore_getopt_desc_handle(const Ecore_Getopt *parser,
1412 const Ecore_Getopt_Desc *desc, 1436 const Ecore_Getopt_Desc *desc,
1413 Ecore_Getopt_Value *value, 1437 Ecore_Getopt_Value *value,
@@ -1451,6 +1475,9 @@ _ecore_getopt_desc_handle(const Ecore_Getopt *parser,
1451 case ECORE_GETOPT_ACTION_LICENSE: 1475 case ECORE_GETOPT_ACTION_LICENSE:
1452 return _ecore_getopt_parse_license(parser, desc, value, arg_val); 1476 return _ecore_getopt_parse_license(parser, desc, value, arg_val);
1453 1477
1478 case ECORE_GETOPT_ACTION_BREAK:
1479 return _ecore_getopt_parse_break(parser, desc, value, arg_val);
1480
1454 default: 1481 default:
1455 return EINA_FALSE; 1482 return EINA_FALSE;
1456 } 1483 }