Enlightenment CVS committal Author : codewarrior Project : e17 Module : proto
Dir : e17/proto/etk/src/lib Modified Files: etk_argument.c etk_argument.h etk_tree.c etk_tree.h Log Message: - more argument work - allow more va_list style functions on the tree =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/etk/src/lib/etk_argument.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- etk_argument.c 2 Mar 2006 14:37:50 -0000 1.3 +++ etk_argument.c 14 Mar 2006 11:42:12 -0000 1.4 @@ -2,11 +2,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <Evas.h> #include "etk_utils.h" #include "etk_argument.h" #define ETK_ARGUMENT_FLAG_PRIV_SET (1 << 4) +static Evas_Hash *_etk_argument_extra = NULL; + /** * @brief Parses the arguments as described by the user * @param args the arguments you are interested in @@ -77,12 +80,12 @@ if(!cur) continue; /* min length is 2, anything less is invalid */ - if(strlen(cur) < 2) + if(strlen(cur) < 2 && cur[0] == '-') { printf(_("Argument %d '%s' is too short\n"), i, argv[i]); return ETK_ARGUMENT_RETURN_MALFORMED; } - + /* short (single char) argument of the form -d val or -dval */ if(cur[0] == '-' && cur[1] != '-') { @@ -106,10 +109,7 @@ return ETK_ARGUMENT_RETURN_REQUIRED_VALUE_NOT_FOUND; } - if(arg->data) - *(arg->data) = *val; - else - arg->data = val; + arg->data = evas_list_append(arg->data, val); arg->flags |= ETK_ARGUMENT_FLAG_PRIV_SET; ++i; } @@ -171,10 +171,7 @@ return ETK_ARGUMENT_RETURN_REQUIRED_VALUE_NOT_FOUND; } - if(arg->data) - *(arg->data) = *val; - else - arg->data = val; + arg->data = evas_list_append(arg->data, val); arg->flags |= ETK_ARGUMENT_FLAG_PRIV_SET; if(!tmp) @@ -196,10 +193,54 @@ free(cur); cur = argv[i]; } + + if(arg->flags & ETK_ARGUMENT_FLAG_MULTIVALUE && i + 1 < argc && + arg->short_name != -1 && arg->flags & ETK_ARGUMENT_FLAG_PRIV_SET) + { + /* if we want multi-argument arguments like: + * foo --bar "one" "two" "three" + * then this is where we get them. + */ + char *extra; + Evas_List *value = NULL; + int j = 1; + + extra = argv[i + j]; + while(i + j < argc) + { + if(extra[0] == '-') + { + j = argc; + break; + } + + if(arg->long_name != NULL) + value = evas_hash_find(_etk_argument_extra, arg->long_name); + else if(arg->short_name != ' ' && arg->short_name != -1) + value = evas_hash_find(_etk_argument_extra, &arg->short_name); + else + break; + + if(!value) + { + value = evas_list_append(value, extra); + _etk_argument_extra = evas_hash_add(_etk_argument_extra, arg->long_name ? arg->long_name : &arg->short_name, value); + } + else + { + _etk_argument_extra = evas_hash_del(_etk_argument_extra, arg->long_name ? arg->long_name : &arg->short_name, value); + value = evas_list_append(value, extra); + _etk_argument_extra = evas_hash_add(_etk_argument_extra, arg->long_name ? arg->long_name : &arg->short_name, value); + } + + ++j; + extra = argv[i + j]; + } + } - ++arg; + ++arg; } - } + } } /* check for required arguments */ @@ -229,4 +270,12 @@ return ETK_ARGUMENT_RETURN_OK; } +Evas_List *etk_argument_extra_find(const char *key) +{ + if(!_etk_argument_extra) + return NULL; + + return evas_hash_find(_etk_argument_extra, "column"); +} + /** @} */ =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/etk/src/lib/etk_argument.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- etk_argument.h 2 Mar 2006 00:48:00 -0000 1.2 +++ etk_argument.h 14 Mar 2006 11:42:13 -0000 1.3 @@ -22,14 +22,15 @@ ETK_ARGUMENT_FLAG_REQUIRED = 1 << 0, /* argument itself is required */ ETK_ARGUMENT_FLAG_OPTIONAL = 1 << 1, /* argument itself is optional */ ETK_ARGUMENT_FLAG_VALUE_REQUIRED = 1 << 2, /* value of the argument is required */ - ETK_ARGUMENT_FLAG_NONE = 1 << 3 /* used when terminating options */ + ETK_ARGUMENT_FLAG_MULTIVALUE = 1 << 3, /* argument uses multi-valued args */ + ETK_ARGUMENT_FLAG_NONE = 1 << 4 /* used when terminating options */ }; struct _Etk_Argument { char *long_name; /* long name of argument: --foo */ char short_name; /* short name of argument: -f */ - char *data; /* filled with value of argument: -f blah */ + Evas_List *data; /* filled with value of argument: -f blah */ void (*func)(Etk_Argument *args, int index); /* callback */ void *func_data; /* data to the callback */ Etk_Argument_Flags flags; /* flags */ @@ -37,7 +38,8 @@ }; int etk_arguments_parse(Etk_Argument *args, int argc, char **argv); - +Evas_List *etk_argument_extra_find(const char *key); + /** @} */ #endif =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/etk/src/lib/etk_tree.c,v retrieving revision 1.56 retrieving revision 1.57 diff -u -3 -r1.56 -r1.57 --- etk_tree.c 12 Mar 2006 12:13:02 -0000 1.56 +++ etk_tree.c 14 Mar 2006 11:42:13 -0000 1.57 @@ -759,6 +759,25 @@ } /** + * @brief Appends a new row to the tree using a va_list + * @param tree a tree + * @param args a va_list consisting of an Etk_Tree_Col * followed by the value of the cell, then again, an Etk_Tree_Col * followed by its value... terminated by NULL + * @return Returns the new row + */ +Etk_Tree_Row *etk_tree_append_valist(Etk_Tree *tree, va_list args) +{ + Etk_Tree_Row *new_row; + + + if (!tree || !tree->built) + return NULL; + + new_row = _etk_tree_row_new_valist(tree, &tree->root, args); + + return new_row; +} + +/** * @brief Appends a new row as a child of a another row of the tree. The tree has to be in the ETK_TREE_MODE_TREE mode * @param row a row * @param ... an Etk_Tree_Col * followed by the value(s) of the cell, then again, an Etk_Tree_Col * followed by its value(s)... terminated by NULL =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/etk/src/lib/etk_tree.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -3 -r1.20 -r1.21 --- etk_tree.h 12 Mar 2006 12:13:02 -0000 1.20 +++ etk_tree.h 14 Mar 2006 11:42:13 -0000 1.21 @@ -188,6 +188,7 @@ void etk_tree_unselect_all(Etk_Tree *tree); Etk_Tree_Row *etk_tree_append(Etk_Tree *tree, ...); +Etk_Tree_Row *etk_tree_append_valist(Etk_Tree *tree, va_list args); Etk_Tree_Row *etk_tree_append_to_row(Etk_Tree_Row *row, ...); void etk_tree_row_del(Etk_Tree_Row *row); void etk_tree_clear(Etk_Tree *tree); ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs