Enlightenment CVS committal
Author : moom
Project : e17
Module : libs/etk
Dir : e17/libs/etk/src/lib
Modified Files:
etk_argument.c etk_argument.h etk_engine.c etk_engine.h
etk_main.c etk_main.h
Log Message:
* [Etk_Main] Add etk_init_full() that adds the ability to pass
custom options to Etk initialisation
* [Etk_Main] Change the prototype of etk_init() to "int etk_init(int
argc, char **argv). Existing programs have to be fixed!
* [Etk_Argument] No longer need to pass argc/argv to parse the arguments
and add etk_argument_get() to retrieve the argc/argv couple passed
to etk_init()
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_argument.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -3 -r1.15 -r1.16
--- etk_argument.c 19 Sep 2007 20:16:25 -0000 1.15
+++ etk_argument.c 14 Oct 2007 20:39:57 -0000 1.16
@@ -14,6 +14,11 @@
* @{
*/
+#define MAX_ARGS 256
+
+static int _argc = 0;
+static char *_argv[MAX_ARGS + 1];
+
/**************************
*
* Implementation
@@ -21,35 +26,118 @@
**************************/
/**
+ * @internal
+ * @brief Initializes the argument parser of Etk
+ * @param argc the number of arguments in @a argv
+ * @param argv a list of arguments given to the program
+ * @param custom_opts a string corresponding to the custom arguments to add to
argv.
+ * For example, "--option1 value --toggle1". It can be set to NULL
+ */
+void etk_argument_init(int argc, char **argv, const char *custom_opts)
+{
+ int i;
+
+ /* Copy the argv array to _argv */
+ _argc = 0;
+ if (argv)
+ {
+ for (i = 0; i < argc && _argc < MAX_ARGS; i++, _argc++)
+ {
+ if (!argv[i])
+ break;
+ _argv[_argc] = strdup(argv[i]);
+ }
+ }
+
+ /* Parse the custom arguments and add them to _argv */
+ if (custom_opts)
+ {
+ const char *start, *end;
+ int len, arg_len;
+
+ start = NULL;
+ end = NULL;
+ len = strlen(custom_opts);
+ for (i = 0; i < len && _argc < MAX_ARGS; i++)
+ {
+ if (!start)
+ {
+ if (custom_opts[i] != ' ')
+ start = &custom_opts[i];
+ }
+ if (start && ((i + 1 == len) || (custom_opts[i + 1] == ' ')))
+ end = &custom_opts[i];
+
+ if (start && end)
+ {
+ arg_len = end - start + 1;
+ _argv[_argc] = malloc(arg_len + 1);
+ strncpy(_argv[_argc], start, arg_len);
+ _argv[_argc][arg_len] = '\0';
+ _argc++;
+
+ start = NULL;
+ end = NULL;
+ }
+ }
+ }
+
+ _argv[_argc] = NULL;
+}
+
+/**
+ * @internal
+ * @brief Shutdowns the argument parser of Etk
+ */
+void etk_argument_shutdown(void)
+{
+ int i;
+
+ for (i = 0; i < _argc; i++)
+ free(_argv[i]);
+ _argc = 0;
+}
+
+/**
+ * @brief Retrieves the arguments passed to etk_init_full()
+ * @param argc the location where to store the number of arguments passed to
etk_init_full()
+ * @param argv the location where to store the list of arguments passed to
etk_init_full()
+ */
+void etk_argument_get(int *argc, char ***argv)
+{
+ if (argc)
+ *argc = _argc;
+ if (argv)
+ *argv = _argv;
+}
+
+/**
* @brief Checks whether the argument has been passed to the program
- * @param argc the location of the "argc" parameter passed to main()
- * @param argv the location of the "argv" parameter passed to main()
* @param long_name the complete name of the argument to find. If
'--long_name' is found in @a argv, this function will
* return ETK_TRUE. You can set this param to NULL to ignore it
* @param short_name a shortcut for the argument to find. If '-short_name' is
found in @a argv, this function will
- * return ETK_TRUE. You can set this param to NULL to ignore it
- * @param remove if @a remove is ETK_TRUE, the argument will be removed from
@a argv if it is found
+ * return ETK_TRUE. You can set this param to 0 to ignore it
+ * @param remove if @a remove is set to ETK_TRUE, the argument will be removed
from the list of arguments passed to
+ * the program if the argument has been found
* @return Returns ETK_TRUE if the argument has been found, ETK_FALSE otherwise
*/
-Etk_Bool etk_argument_is_set(int *argc, char ***argv, const char *long_name,
char short_name, Etk_Bool remove)
+Etk_Bool etk_argument_is_set(const char *long_name, char short_name, Etk_Bool
remove)
{
Etk_Bool is_set = ETK_FALSE;
char *arg;
int arg_len;
int i, j;
- if (!argc || !argv)
- return ETK_FALSE;
-
- for (i = 0; i < *argc; i++)
+ for (i = 0; i < _argc; i++)
{
- if (!(arg = ((*argv)[i])))
- continue;
-
+ arg = _argv[i];
arg_len = strlen(arg);
- if ((arg_len == 2) && (arg[0] == '-') && (arg[1] == short_name))
+ if (arg_len < 2 || arg[0] != '-')
+ continue;
+
+ if ((arg_len == 2) && (arg[1] == short_name))
is_set = ETK_TRUE;
- else if ((arg_len > 2) && (arg[0] == '-') && (arg[1] == '-'))
+ else if ((arg_len > 2) && (arg[1] == '-'))
{
if (long_name && (strcmp(&arg[2], long_name) == 0))
is_set = ETK_TRUE;
@@ -59,9 +147,9 @@
{
if (remove)
{
- for (j = i + 1; j < *argc; j++)
- (*argv)[j - 1] = (*argv)[j];
- (*argc)--;
+ for (j = i + 1; j <= _argc; j++)
+ _argv[j - 1] = _argv[j];
+ _argc--;
}
return ETK_TRUE;
}
@@ -72,35 +160,31 @@
/**
* @brief Gets the value of an argument passed to the program
- * @param argc the location of the "argc" parameter passed to main()
- * @param argv the location of the "argv" parameter passed to main()
* @param long_name the complete name of the argument to find. If --long_name
is found in @a argv and is followed by a
* value, this function will return ETK_TRUE. You can set this param to NULL
to ignore it
* @param short_name a shortcut for the argument to find. If -short_name is
found in @a argv and is followed by a
- * value, this function will return ETK_TRUE. You can set this param to NULL
to ignore it
- * @param remove if @a remove is ETK_TRUE, the argument and its value will be
removed from @a argv
- * if they are found
+ * value, this function will return ETK_TRUE. You can set this param to 0 to
ignore it
+ * @param remove if @a remove is ETK_TRUE, the argument and its value will be
removed from the list of arguments
+ * passed to the program if they have been found
* @param value the location where to store the value of the argument. You'll
have to free it when you no
* longer need it. This parameter should not be NULL, otherwise the function
will return ETK_FALSE
* @return Returns ETK_TRUE if the argument has been found and was followed by
a value, ETK_FALSE otherwise
*/
-Etk_Bool etk_argument_value_get(int *argc, char ***argv, const char
*long_name, char short_name, Etk_Bool remove, char **value)
+Etk_Bool etk_argument_value_get(const char *long_name, char short_name,
Etk_Bool remove, char **value)
{
int num_args = 0;
char *arg, *next, *value_ptr = NULL;
int arg_len, long_name_len;
int i, j;
- if (!argc || !argv || !value)
+ if (!value)
return ETK_FALSE;
long_name_len = long_name ? strlen(long_name) : 0;
- for (i = 0; i < *argc; i++)
+ for (i = 0; i < _argc; i++)
{
- if (!(arg = (*argv)[i]))
- continue;
-
+ arg = _argv[i];
arg_len = strlen(arg);
if (arg_len < 2 || arg[0] != '-')
continue;
@@ -113,7 +197,7 @@
/* -s value */
if (arg_len == 2)
{
- if ((i + 1 < *argc) && (next = (*argv)[i + 1]) && next[0] !=
'-')
+ if ((i + 1 < _argc) && (next = _argv[i + 1]) && next[0] != '-')
{
value_ptr = next;
num_args = 2;
@@ -135,7 +219,7 @@
/* --long_name value */
if (arg_len == long_name_len + 2)
{
- if ((i + 1 < *argc) && (next = (*argv)[i + 1]) && next[0] !=
'-')
+ if ((i + 1 < _argc) && (next = _argv[i + 1]) && next[0] != '-')
{
value_ptr = next;
num_args = 2;
@@ -156,9 +240,9 @@
*value = strdup(value_ptr);
if (remove)
{
- for (j = i; j < *argc - num_args; j++)
- (*argv)[j] = (*argv)[j + num_args];
- (*argc) -= num_args;
+ for (j = i; j <= _argc - num_args; j++)
+ _argv[j] = _argv[j + num_args];
+ _argc -= num_args;
}
return ETK_TRUE;
}
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_argument.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- etk_argument.h 19 Sep 2007 20:16:25 -0000 1.12
+++ etk_argument.h 14 Oct 2007 20:39:57 -0000 1.13
@@ -14,8 +14,12 @@
* @{
*/
-Etk_Bool etk_argument_is_set(int *argc, char ***argv, const char *long_name,
char short_name, Etk_Bool remove);
-Etk_Bool etk_argument_value_get(int *argc, char ***argv, const char
*long_name, char short_name, Etk_Bool remove, char **value);
+void etk_argument_init(int argc, char **argv, const char *custom_opts);
+void etk_argument_shutdown(void);
+void etk_argument_get(int *argc, char ***argv);
+
+Etk_Bool etk_argument_is_set(const char *long_name, char short_name, Etk_Bool
remove);
+Etk_Bool etk_argument_value_get(const char *long_name, char short_name,
Etk_Bool remove, char **value);
/** @} */
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_engine.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -3 -r1.21 -r1.22
--- etk_engine.c 19 Sep 2007 20:16:26 -0000 1.21
+++ etk_engine.c 14 Oct 2007 20:39:57 -0000 1.22
@@ -153,16 +153,12 @@
* @internal
* @brief Loads an engine. The loaded engine will automatically become the
engine used by Etk
* @param engine_name the name of the engine to load
- * @param argc the location of the "argc" parameter passed to main(). It is
used to parse the arguments specific to Etk.
- * It can be set to NULL.
- * @param argv the location of the "argv" parameter passed to main(). It is
used to parse the arguments specific to Etk.
- * It can be set to NULL.
* @return Returns the loaded engine, or NULL if the engine could not be loaded
*/
-Etk_Engine *etk_engine_load(const char *engine_name, int *argc, char ***argv)
+Etk_Engine *etk_engine_load(const char *engine_name)
{
Etk_Engine *engine;
- Etk_Engine *(*engine_open)(int *argc, char ***argv);
+ Etk_Engine *(*engine_open)(void);
char filename[PATH_MAX];
void *handle;
@@ -195,7 +191,7 @@
return NULL;
}
- if (!(engine = engine_open(argc, argv)))
+ if (!(engine = engine_open()))
{
ETK_WARNING("Etk can not open the requested engine!");
dlclose(handle);
@@ -221,20 +217,16 @@
* will be used by the inheriting engine
* @param engine the engine which will inherit from the methods of the base
engine
* @param inherit_name the name of the engine from which @a engine will inherit
- * @param argc the location of the "argc" parameter passed to main(). It is
used to parse the arguments specific to Etk.
- * It can be set to NULL.
- * @param argv the location of the "argv" parameter passed to main(). It is
used to parse the arguments specific to Etk.
- * It can be set to NULL.
* @return Returns ETK_TRUE on success, ETK_FALSE otherwise
*/
-Etk_Bool etk_engine_inherit_from(Etk_Engine *engine, const char *inherit_name,
int *argc, char ***argv)
+Etk_Bool etk_engine_inherit_from(Etk_Engine *engine, const char *inherit_name)
{
Etk_Engine *inherit_from;
if (!engine || !inherit_name)
return ETK_FALSE;
- if (!(inherit_from = etk_engine_load(inherit_name, argc, argv)))
+ if (!(inherit_from = etk_engine_load(inherit_name)))
return ETK_FALSE;
_etk_engine_inheritance_set(engine, inherit_from);
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_engine.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -3 -r1.19 -r1.20
--- etk_engine.h 19 Sep 2007 20:16:26 -0000 1.19
+++ etk_engine.h 14 Oct 2007 20:39:57 -0000 1.20
@@ -103,9 +103,9 @@
Etk_Bool etk_engine_exists(const char *engine_name);
Etk_Engine *etk_engine_get(void);
-Etk_Engine *etk_engine_load(const char *engine_name, int *argc, char ***argv);
+Etk_Engine *etk_engine_load(const char *engine_name);
void etk_engine_unload(Etk_Engine *engine);
-Etk_Bool etk_engine_inherit_from(Etk_Engine *engine, const char *
inherit_name, int *argc, char ***argv);
+Etk_Bool etk_engine_inherit_from(Etk_Engine *engine, const char *
inherit_name);
void etk_engine_window_constructor(Etk_Window *window);
void etk_engine_window_destructor(Etk_Window *window);
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_main.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -3 -r1.43 -r1.44
--- etk_main.c 5 Oct 2007 05:12:38 -0000 1.43
+++ etk_main.c 14 Oct 2007 20:39:57 -0000 1.44
@@ -11,6 +11,7 @@
#include <string.h>
#include <Ecore.h>
+#include <Ecore_Job.h>
#include <Edje.h>
#include "etk_argument.h"
@@ -48,18 +49,37 @@
/**
* @brief Initializes Etk. This function needs to be called before any other
call to an etk_* function. @n
* You can call safely etk_init() several times, it will only have an effect
the first time you call it. The other
- * times, it will just increment the init counter. etk_shutdown() will
decrement this counter and will effectively
+ * times, it will just increment the init-counter. etk_shutdown() will
decrement this counter and will effectively
* shutdown Etk only when the counter reaches 0. So you need to call
etk_shutdown() the same number of times
* you've called etk_init().
+ * @param argc the "argc" parameter passed to main(). It is used to parse the
arguments specific to Etk.
+ * It can be set to 0.
+ * @param argv the "argv" parameter passed to main(). It is used to parse the
arguments specific to Etk.
+ * It can be set to NULL.
+ * @return Returns the number of times Etk has been initialized, or 0 on
failure
+ * @note It initializes Evas, Ecore and Edje so you don't need to initialize
them after an etk_init()
+ * @see etk_init_full()
+ * @see etk_shutdown()
+ */
+int etk_init(int argc, char **argv)
+{
+ return etk_init_full(argc, argv, NULL);
+}
+
+/**
+ * @brief Does the same thing as etk_init() except you can specify custom
arguments that could be then retrieved with
+ * etk_argument_* functions. For example, etk_init_full(argc, argv, "--option1
value --toggle1")
* @param argc the location of the "argc" parameter passed to main(). It is
used to parse the arguments specific to Etk.
* It can be set to NULL.
* @param argv the location of the "argv" parameter passed to main(). It is
used to parse the arguments specific to Etk.
* It can be set to NULL.
+ * @param custom_opts a string corresponding to the custom arguments to add to
argv. It can be set to NULL
* @return Returns the number of times Etk has been initialized, or 0 on
failure
* @note It initializes Evas, Ecore and Edje so you don't need to initialize
them after an etk_init()
+ * @see etk_init()
* @see etk_shutdown()
*/
-int etk_init(int *argc, char ***argv)
+int etk_init_full(int argc, char **argv, const char *custom_opts)
{
char *engine_name = NULL;
@@ -71,10 +91,8 @@
else
{
/* Parse the arguments */
- if (argc && argv)
- {
- etk_argument_value_get(argc, argv, "etk-engine", 0, ETK_TRUE,
&engine_name);
- }
+ etk_argument_init(argc, argv, custom_opts);
+ etk_argument_value_get("etk-engine", 0, ETK_TRUE, &engine_name);
/* Initialize the EFL */
if (!evas_init())
@@ -115,7 +133,7 @@
ETK_WARNING("Etk_Engine initialization failed!");
return 0;
}
- if (!etk_engine_load(engine_name ? engine_name :
"ecore_evas_software_x11", argc, argv))
+ if (!etk_engine_load(engine_name ? engine_name :
"ecore_evas_software_x11"))
{
ETK_WARNING("Etk can not load the requested engine!");
return 0;
@@ -160,6 +178,7 @@
etk_engine_shutdown();
etk_config_shutdown();
etk_theme_shutdown();
+ etk_argument_shutdown();
/* Shutdown the EFL*/
edje_shutdown();
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_main.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- etk_main.h 19 Sep 2007 20:16:26 -0000 1.10
+++ etk_main.h 14 Oct 2007 20:39:57 -0000 1.11
@@ -16,7 +16,8 @@
* @{
*/
-int etk_init(int *argc, char ***argv);
+int etk_init(int argc, char **argv);
+int etk_init_full(int argc, char **argv, const char *custom_opts);
int etk_shutdown(void);
void etk_main(void);
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs