Enlightenment CVS committal

Author  : handyande
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_config


Modified Files:
        Ecore_Config.h ecore_config_extra.c 


Log Message:
Beginning of ecore_config_arg support for arguments with no direct property 
relationship
see engage for demo usage
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_config/Ecore_Config.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -3 -r1.39 -r1.40
--- Ecore_Config.h      27 Nov 2004 23:14:23 -0000      1.39
+++ Ecore_Config.h      1 Dec 2004 00:49:18 -0000       1.40
@@ -249,6 +249,14 @@
    EAPI char               *ecore_config_theme_with_path_get(const char *key);
    EAPI void                ecore_config_args_display(void);
    EAPI int                 ecore_config_args_parse(void);
+   EAPI void                ecore_config_args_callback_str_add(char short_opt,
+                               char *long_opt, char *desc,
+                               void (*func)(char *val, void *data),
+                               void *data);
+   EAPI void                ecore_config_args_callback_noarg_add(char 
short_opt,
+                               char *long_opt, char *desc,
+                               void (*func)(char *val, void *data),
+                               void *data);
    EAPI void                ecore_config_app_describe(char *description);
 
    EAPI int                 ecore_config_create(const char *key, void *val,
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_config/ecore_config_extra.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- ecore_config_extra.c        27 Nov 2004 23:14:28 -0000      1.2
+++ ecore_config_extra.c        1 Dec 2004 00:49:18 -0000       1.3
@@ -10,7 +10,20 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+typedef struct __Ecore_Config_Arg_Callback _Ecore_Config_Arg_Callback;
+struct __Ecore_Config_Arg_Callback
+{
+   char                  short_opt;
+   char                 *long_opt;
+   char                 *description;
+   void                 *data;
+   void                (*func)(char *val, void *data);
+   Ecore_Config_Type type;
+   _Ecore_Config_Arg_Callback *next;
+};
+
 char               *__ecore_config_app_description;
+_Ecore_Config_Arg_Callback *_ecore_config_arg_callbacks;
 
 extern int          ecore_config_bound(Ecore_Config_Prop * e);
 extern char        *ecore_config_rgb_to_argb(char *rgb);
@@ -524,7 +537,7 @@
 }
 
 static char        *_ecore_config_short_types[] =
-   { "<nil> ", "<int> ", "<flt> ", "<str> ", "<rgb> ", "<str> ", "<bool>" };
+   { "      ", "<int> ", "<flt> ", "<str> ", "<rgb> ", "<str> ", "<bool>" };
 
 /**
  * Prints the property list of the local configuration bundle to output.
@@ -533,6 +546,7 @@
 ecore_config_args_display(void)
 {
    Ecore_Config_Prop  *props;
+   _Ecore_Config_Arg_Callback *callbacks;
 
    if (__ecore_config_app_description)
       printf("%s\n\n", __ecore_config_app_description);
@@ -554,11 +568,24 @@
               props->short_opt ? ',' : ' ',
               props->long_opt ? props->long_opt : props->key,
               _ecore_config_short_types[props->type],
-              props->description ? props->
-              description : "(no description available)");
+              props->description ? props->description :
+              "(no description available)");
 
        props = props->next;
      }
+   callbacks = _ecore_config_arg_callbacks;
+   while (callbacks)
+     {
+        printf(" %c%c%c --%s\t%s %s\n", callbacks->short_opt ? '-' : ' ',
+              callbacks->short_opt ? callbacks->short_opt : ' ',
+              callbacks->short_opt ? ',' : ' ',
+              callbacks->long_opt ? callbacks->long_opt : "",
+               _ecore_config_short_types[callbacks->type],
+              callbacks->description ? callbacks->description :
+              "(no description available)");
+
+       callbacks = callbacks->next;
+     }
 }
 
 static int
@@ -581,6 +608,40 @@
    return ECORE_CONFIG_PARSE_CONTINUE;
 }
 
+static void
+ecore_config_args_callback_add(char short_opt, char *long_opt, char *desc,
+                              void (*func)(char *val, void *data),
+                              void *data, Ecore_Config_Type type) {
+   _Ecore_Config_Arg_Callback *new_cb;
+
+   new_cb = malloc(sizeof(_Ecore_Config_Arg_Callback));
+   new_cb->short_opt = short_opt;
+   if (long_opt)
+      new_cb->long_opt = strdup(long_opt);
+   if (desc)
+      new_cb->description = strdup(desc);
+   new_cb->data = data;
+   new_cb->func = func;
+   new_cb->type = type;
+
+   new_cb->next = _ecore_config_arg_callbacks;
+   _ecore_config_arg_callbacks = new_cb;
+}
+
+void
+ecore_config_args_callback_str_add(char short_opt, char *long_opt, char *desc,
+                                  void (*func)(char *val, void *data),
+                                  void *data) {
+   ecore_config_args_callback_add(short_opt, long_opt, desc, func, data, 
PT_STR);
+}
+
+void
+ecore_config_args_callback_noarg_add(char short_opt, char *long_opt, char 
*desc,
+                                    void (*func)(char *val, void *data),
+                                    void *data) {
+   ecore_config_args_callback_add(short_opt, long_opt, desc, func, data, 
PT_NIL);
+}
+
 /**
  * Parse the arguments set by @ref ecore_app_args_set and set properties
  * accordingly.
@@ -599,6 +660,7 @@
    char               *arg;
    char               *long_opt, short_opt;
    Ecore_Config_Prop  *prop;
+   _Ecore_Config_Arg_Callback *callback;
 
    ecore_app_args_get(&argc, &argv);
    nextarg = 1;
@@ -646,6 +708,33 @@
               }
             if (!found)
               {
+                 callback = _ecore_config_arg_callbacks;
+                 while (callback)
+                   {
+                      if ((callback->long_opt && 
+                           !strcmp(long_opt, callback->long_opt)))
+                        {
+                           found = 1;
+                           if (callback->type == PT_NIL)
+                             {
+                                callback->func(NULL, callback->data);
+                             }
+                           else 
+                             {
+                                if (!argv[++nextarg])
+                                  {
+                                     printf("Missing expected argument for 
option --%s\n", long_opt);
+                                     return ECORE_CONFIG_PARSE_EXIT;
+                                  }
+                                  callback->func(argv[nextarg], 
callback->data);
+                             }
+                           break;
+                        }
+                      callback = callback->next;
+                   }
+              }
+            if (!found)
+              {
                  printf("Unrecognised option \"%s\"\n", long_opt);
                  printf("Try using -h or --help for more information.\n\n");
                  return ECORE_CONFIG_PARSE_EXIT;
@@ -683,6 +772,32 @@
 
                       if (!found)
                         {
+                           callback = _ecore_config_arg_callbacks;
+                           while (callback)
+                             {
+                                if (short_opt == callback->short_opt)
+                                  {
+                                     found = 1;
+                                     if (callback->type == PT_NIL)
+                                       {
+                                          callback->func(NULL, callback->data);
+                                       }
+                                     else
+                                       {
+                                          if (!argv[++nextarg])
+                                            {
+                                               printf("Missing expected 
argument for option -%c\n", short_opt);
+                                               return ECORE_CONFIG_PARSE_EXIT;
+                                            }
+                                          callback->func(argv[nextarg], 
callback->data);
+                                       }
+                                     break;
+                                  }
+                                callback = callback->next;
+                             }
+                        }
+                      if (!found)
+                        {
                            printf("Unrecognised option '%c'\n", short_opt);
                            printf
                               ("Try using -h or --help for more 
information.\n\n");




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to