ecore_getopt: common callbacks go in.
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 20 Dec 2008 14:29:45 +0000 (14:29 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 20 Dec 2008 14:29:45 +0000 (14:29 +0000)
ecore_evas_list_engines and geometry_parse, they're used in almost all
applications using ecore_getopt, let's avoid replicating code.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/ecore@38247 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/ecore/Ecore_Getopt.h
src/lib/ecore/ecore_getopt.c

index 3b1a7e9..2f2e8b7 100644 (file)
@@ -380,6 +380,12 @@ extern "C" {
 
   EAPI Eina_List *ecore_getopt_list_free(Eina_List *list);
 
+  /* helper functions to be used with ECORE_GETOPT_CALLBACK_*() */
+
+  EAPI unsigned char ecore_getopt_callback_ecore_evas_list_engines(const Ecore_Getopt *parser, const Ecore_Getopt_Desc *desc, const char *str, void *data, Ecore_Getopt_Value *storage);
+  EAPI unsigned char ecore_getopt_callback_geometry_parse(const Ecore_Getopt *parser, const Ecore_Getopt_Desc *desc, const char *str, void *data, Ecore_Getopt_Value *storage);
+
+
 #ifdef __cplusplus
 }
 #endif
index 11a0b6a..f38c7fa 100644 (file)
@@ -1639,3 +1639,64 @@ ecore_getopt_list_free(Eina_List *list)
      }
    return NULL;
 }
+
+/**
+ * Helper ecore_getopt callback to list available Ecore_Evas engines.
+ *
+ * This will list all available engines except buffer, this is useful
+ * for applications to let user choose how they should create windows
+ * with ecore_evas_new().
+ *
+ * @c callback_data value is used as @c FILE* and says where to output
+ * messages, by default it is @c stdout. You can specify this value
+ * with ECORE_GETOPT_CALLBACK_FULL() or ECORE_GETOPT_CALLBACK_ARGS().
+ *
+ * If there is a boolean storage provided, then it is marked with 1
+ * when this option is executed.
+ */
+unsigned char
+ecore_getopt_callback_ecore_evas_list_engines(const Ecore_Getopt *parser, const Ecore_Getopt_Desc *desc, const char *str, void *data, Ecore_Getopt_Value *storage)
+{
+   Eina_List  *lst, *n;
+   const char *engine;
+   FILE *fp = data;
+
+   if (!fp)
+     fp = stdout;
+
+   lst = ecore_evas_engines_get();
+
+   fputs("supported engines:\n", fp);
+   EINA_LIST_FOREACH(lst, n, engine)
+     if (strcmp(engine, "buffer") != 0)
+       fprintf(fp, "\t%s\n", engine);
+
+   ecore_evas_engines_free(lst);
+
+   if (storage->boolp)
+     *storage->boolp = 1;
+
+   return 1;
+}
+
+/**
+ * Helper ecore_getopt callback to parse geometry (x:y:w:h).
+ *
+ * Storage must be a pointer to @c Eina_Rectangle and will be used to
+ * store the four values passed in the given string.
+ *
+ * @c callback_data value is ignored, you can safely use @c NULL.
+ */
+unsigned char
+ecore_getopt_callback_geometry_parse(const Ecore_Getopt *parser, const Ecore_Getopt_Desc *desc, const char *str, void *data, Ecore_Getopt_Value *storage)
+{
+   Eina_Rectangle *v = (Eina_Rectangle *)storage->ptrp;
+
+   if (sscanf(str, "%d:%d:%d:%d", &v->x, &v->y, &v->w, &v->h) != 4)
+     {
+       fprintf(stderr, "ERROR: incorrect geometry value '%s'\n", str);
+       return 0;
+     }
+
+   return 1;
+}