Enlightenment CVS committal
Author : moom
Project : e17
Module : proto
Dir : e17/proto/etk/src/lib
Modified Files:
etk_argument.c etk_argument.h etk_main.c etk_main.h
Log Message:
* Rewrite Etk_Argument
===================================================================
RCS file: /cvs/e/e17/proto/etk/src/lib/etk_argument.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- etk_argument.c 2 Aug 2006 05:53:59 -0000 1.7
+++ etk_argument.c 5 Aug 2006 02:37:25 -0000 1.8
@@ -1,365 +1,165 @@
/** @file etk_argument.c */
+#include "etk_argument.h"
#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;
-static int _etk_argument_status = 0;
/**
- * @brief Parses the arguments as described by the user
- * @param args the arguments you are interested in
- * @param argc the number of arguments given to your program
- * @param argv the values of the arguments given to your program
- * @return Returns an int which tells the caller about the status
- *
- * Example:
- * @code
- * static void info_func(Etk_Argument *args, int index)
- * {
- * printf("info func!\n");
- * }
- *
- * static void text_func(Etk_Argument *args, int index)
- * {
- * printf("text func! %s\n", args[index].data);
- * }
- *
- * static void hide_func(Etk_Argument *args, int index)
- * {
- * printf("hide func!\n");
- * }
- *
- * Etk_Argument args[] = {
- * { "info", 'i', NULL, info_func, NULL, ETK_ARGUMENT_FLAG_OPTIONAL, " "
},
- * { "text", 't', NULL, text_func, NULL,
ETK_ARGUMENT_FLAG_OPTIONAL|ETK_ARGUMENT_FLAG_VALUE_REQUIRED, " " },
- * { "hide", 'h', NULL, hide_func, NULL, ETK_ARGUMENT_FLAG_OPTIONAL, " "
},
- * { NULL, -1, NULL, NULL, NULL, ETK_ARGUMENT_FLAG_NONE, " " }
- * };
+ * @addtogroup Etk_Argument
+ * @{
+ */
+
+/**************************
*
- * int main(int argc, char **argv)
- * {
- * etk_arguments_parse(args, &argc, argv);
+ * Implementation
*
- * return 0;
- * }
- * @endcode
+ **************************/
+
+/**
+ * @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. It can be set to NULL to be ignored 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. It can be set to 0 to be ignored it
+ * @param remove if @a remove is ETK_TRUE, the argument will be removed from
@a argv if it has been found
+ * @return Returns ETK_TRUE if the argument has been found, ETK_FALSE otherwise
*/
-int etk_arguments_parse(Etk_Argument *args, int *argc, char ***argv)
+Etk_Bool etk_argument_is_set(int *argc, char ***argv, const char *long_name,
char short_name, Etk_Bool remove)
{
- int i;
- int ret_argc;
- char **ret_argv;
- int *delete; /* 1 delete, 0 keep */
- Etk_Argument *arg;
+ Etk_Bool is_set = ETK_FALSE;
+ char *arg;
+ int arg_len;
+ int i, j;
+
+ if (!argc || !argv)
+ return ETK_FALSE;
- if(!args || !argc || !argv)
- return ETK_ARGUMENT_RETURN_OK_NONE_PARSED;
- /* no arguments */
- if(*argc < 2)
+ for (i = 0; i < *argc; i++)
{
- /* check for required arguments */
- i = 0;
- arg = args;
- while(arg->short_name != -1)
+ if (!(arg = ((*argv)[i])))
+ continue;
+
+ arg_len = strlen(arg);
+ if ((arg_len == 2) && (arg[0] == '-') && (arg[1] == short_name))
+ is_set = ETK_TRUE;
+ else if ((arg_len > 2) && (arg[0] == '-') && (arg[1] == '-'))
+ {
+ if (long_name && (strcmp(&arg[2], long_name) == 0))
+ is_set = ETK_TRUE;
+ }
+
+ if (is_set)
{
- if(arg->flags & ETK_ARGUMENT_FLAG_REQUIRED)
- {
- printf(_("Argument %d '-%c | --%s' is required\n"), i,
arg->short_name, arg->long_name);
- return ETK_ARGUMENT_RETURN_REQUIRED_NOT_FOUND;
- }
- ++i; ++arg;
+ if (remove)
+ {
+ for (j = i + 1; j < *argc; j++)
+ (*argv)[j - 1] = (*argv)[j];
+ *argc--;
+ }
+ return ETK_TRUE;
}
- return ETK_ARGUMENT_RETURN_OK_NONE_PARSED;
}
- /* create the array */
- delete = calloc(*argc, sizeof(int));
+
+ return ETK_FALSE;
+}
- /* arguments */
- for(i = 1; i < *argc; i++)
+/**
+ * @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. It can be set to NULL to be
ignored 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. It can be set to 0 to be ignored
it
+ * @param remove if @a remove is ETK_TRUE, the argument and its value will be
removed from @a argv
+ * 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
+ * @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)
+{
+ int num_args = 0;
+ char *arg, *next, *value_ptr = NULL;
+ int arg_len, long_name_len = 0;
+ int i, j;
+
+ if (!argc || !argv)
+ return ETK_FALSE;
+
+ if (long_name)
+ long_name_len = strlen(long_name);
+
+ for (i = 0; i < *argc; i++)
{
- char *cur;
+ if (!(arg = (*argv)[i]))
+ continue;
- cur = (*argv)[i];
- if(!cur) continue;
+ arg_len = strlen(arg);
+ if (arg_len < 2 || arg[0] != '-')
+ continue;
- /* min length is 2, anything less is invalid */
- if(strlen(cur) < 2 && cur[0] == '-')
+ /* Short argument */
+ if (arg[1] != '-')
{
- printf(_("Argument %d '%s' is too short\n"), i, (*argv)[i]);
- free(delete);
- return ETK_ARGUMENT_RETURN_MALFORMED;
+ if (arg[1] == short_name)
+ {
+ /* -s value */
+ if (arg_len == 2)
+ {
+ if ((i + 1 < *argc) && (next = (*argv)[i + 1]) && next[0] !=
'-')
+ {
+ value_ptr = next;
+ num_args = 2;
+ }
+ }
+ /* -svalue */
+ else
+ {
+ value_ptr = &arg[2];
+ num_args = 1;
+ }
+ }
}
-
- /* short (single char) argument of the form -d val or -dval */
- if(cur[0] == '-' && cur[1] != '-')
+ /* Long argument */
+ else if (long_name_len > 0)
{
- arg = args;
-
- while(arg->short_name != -1)
- {
- /* match found for short arg */
- if(arg->short_name == cur[1])
- {
- /* check to see if arg needs value */
- if((arg->flags & ETK_ARGUMENT_FLAG_VALUE_REQUIRED) &&
- i + 1 < *argc)
- {
- char *val = (*argv)[i + 1];
-
- /* if no value is present, report error */
- if(val[0] == '-')
- {
- printf(_("Argument %d '%s' requires a value\n"), i, cur);
- free(delete);
- return ETK_ARGUMENT_RETURN_REQUIRED_VALUE_NOT_FOUND;
- }
-
- arg->data = evas_list_append(arg->data, val);
- arg->flags |= ETK_ARGUMENT_FLAG_PRIV_SET;
- _etk_argument_status = 1;
- ++i;
- delete[i] = delete[i+1] = 1;
- }
- else if (arg->flags & ETK_ARGUMENT_FLAG_VALUE_REQUIRED
- && i + 1 >= *argc)
- {
- /* if no value is present, report error */
- printf(_("Argument %d '%s' requires a value\n"), i, cur);
- free(delete);
- return ETK_ARGUMENT_RETURN_REQUIRED_VALUE_NOT_FOUND;
- }
- else if(!(arg->flags & ETK_ARGUMENT_FLAG_VALUE_REQUIRED))
- {
- arg->flags |= ETK_ARGUMENT_FLAG_PRIV_SET;
- _etk_argument_status = 1;
- delete[i] = 1;
- }
- }
- ++arg;
- }
+ if (strncmp(&arg[2], long_name, long_name_len) == 0)
+ {
+ /* --long_name value */
+ if (arg_len == long_name_len + 2)
+ {
+ if ((i + 1 < *argc) && (next = (*argv)[i + 1]) && next[0] !=
'-')
+ {
+ value_ptr = next;
+ num_args = 2;
+ }
+ }
+ /* --long_name=value */
+ else if ((arg_len > long_name_len + 3) && (arg[long_name_len + 2]
== '='))
+ {
+ value_ptr = &arg[long_name_len + 3];
+ num_args = 1;
+ }
+ }
}
- /* long argument of the form --debug or --debug=something */
- else if(cur[0] == '-' && cur[1] == '-' && strlen(cur) > 2)
- {
- arg = args;
-
- while(arg->short_name != -1)
- {
- char *tmp = NULL;
- char *tmp2;
-
- if(!arg->long_name)
- continue;
-
- /* check if arg if of the form --foo=bar */
- tmp = strchr(cur, '=');
- if(tmp)
- {
- tmp2 = cur;
- cur = calloc(tmp - tmp2 + 1, sizeof(char));
- snprintf(cur, (tmp - tmp2 + 1) * sizeof(char), "%s", tmp2);
- }
- else
- tmp = NULL;
-
- /* match found for long arg */
- if(!strcmp(arg->long_name, cur + 2))
- {
- /* check to see if arg needs value */
- if((arg->flags & ETK_ARGUMENT_FLAG_VALUE_REQUIRED) &&
- ((i + 1 < *argc) || (tmp != NULL)))
- {
- char *val;
-
- if(!tmp)
- val = (*argv)[i + 1];
- else
- val = tmp + 1;
-
- /* if no value is present, report error */
- if(val[0] == '-')
- {
- printf(_("Argument %d '%s' requires a value\n"), i, cur);
- free(delete);
- return ETK_ARGUMENT_RETURN_REQUIRED_VALUE_NOT_FOUND;
- }
-
- arg->data = evas_list_append(arg->data, val);
- arg->flags |= ETK_ARGUMENT_FLAG_PRIV_SET;
- _etk_argument_status = 1;
- delete[i] = 1;
-
- if(!tmp)
- {
- ++i;
- delete[i+1] = 1;
- }
-
- }
- else if (arg->flags & ETK_ARGUMENT_FLAG_VALUE_REQUIRED
- && i + 1 >= *argc)
- {
- /* if no value is present, report error */
- printf(_("Argument %d '%s' requires a value\n"), i, cur);
- free(delete);
- return ETK_ARGUMENT_RETURN_REQUIRED_VALUE_NOT_FOUND;
- }
- else if(!(arg->flags & ETK_ARGUMENT_FLAG_VALUE_REQUIRED))
- {
- arg->flags |= ETK_ARGUMENT_FLAG_PRIV_SET;
- _etk_argument_status = 1;
- delete[i] = 1;
- }
- }
-
- if(tmp)
- {
- free(cur);
- cur = (*argv)[i];
- }
- /* TODO test this on removing args! */
- 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 = i + 1;
-
- extra = (*argv)[j];
- while(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)[j];
- }
- }
-
- ++arg;
- }
- }
- }
-
- /* check for required arguments */
- i = 0;
- arg = args;
- while(arg->short_name != -1)
- {
- if(!(arg->flags & ETK_ARGUMENT_FLAG_PRIV_SET) &&
- arg->flags & ETK_ARGUMENT_FLAG_REQUIRED)
+
+ /* A value has been found */
+ if (value_ptr)
{
- printf(_("Argument %d '-%c | --%s' is required\n"), i,
arg->short_name, arg->long_name); free(delete);
- return ETK_ARGUMENT_RETURN_REQUIRED_NOT_FOUND;
+ if (value)
+ *value = strdup(value_ptr);
+ if (remove)
+ {
+ for (j = i + num_args; j < *argc; j++)
+ (*argv)[j - num_args] = (*argv)[j];
+ *argc--;
+ }
+ return ETK_TRUE;
}
- ++i; ++arg;
- }
- /* copy parameters */
- ret_argc = 0;
- ret_argv = malloc(sizeof(char *) * (*argc));
- for(i = 0; i < *argc; i++)
- {
- if(!delete[i])
- {
- ret_argv[ret_argc] = strdup((*argv)[i]);
- ret_argc++;
- /* TODO: delete this comments after correct behaviour */
- //printf("dont delete %s\n", (*argv)[i]);
- }
- /*else
- printf("deleting %s\n", (*argv)[i]);*/
}
- free(delete);
- *argv = ret_argv;
- *argc = ret_argc;
-
- /* call all the callbacks */
- i = 0;
- arg = args;
- while(arg->short_name != -1)
- {
- if(arg->func && arg->flags & ETK_ARGUMENT_FLAG_PRIV_SET)
- arg->func(args, i);
- ++i; ++arg;
- }
- if(_etk_argument_status == 0)
- return ETK_ARGUMENT_RETURN_OK_NONE_PARSED;
- else
- return ETK_ARGUMENT_RETURN_OK;
-}
-
-void etk_argument_help_show(Etk_Argument *args)
-{
- Etk_Argument *arg;
-
- arg = args;
- while(arg->short_name != -1)
- {
- if(arg->long_name)
- printf("--%s ", arg->long_name);
- if(arg->short_name != -1 && arg->short_name != ' ')
- printf("-%c", arg->short_name);
- printf("\t");
- if(arg->description)
- printf("%s", arg->description);
- printf("\n");
- ++arg;
- }
-}
-
-Evas_List *etk_argument_extra_find(const char *key)
-{
- if(!_etk_argument_extra)
- return NULL;
- return evas_hash_find(_etk_argument_extra, "column");
-}
-
-Etk_Bool etk_argument_is_set(Etk_Argument *args, const char *long_name, char
short_name)
-{
- Etk_Argument *arg;
-
- arg = args;
- while(arg->short_name != -1)
- {
- if((!strcmp(arg->long_name, long_name) ||
- (arg->short_name == short_name && short_name != -1 && short_name != '
'))
- && arg->flags & ETK_ARGUMENT_FLAG_PRIV_SET)
- return ETK_TRUE;
- ++arg;
- }
return ETK_FALSE;
}
===================================================================
RCS file: /cvs/e/e17/proto/etk/src/lib/etk_argument.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- etk_argument.h 2 Aug 2006 05:53:59 -0000 1.7
+++ etk_argument.h 5 Aug 2006 02:37:25 -0000 1.8
@@ -9,39 +9,8 @@
* @{
*/
-typedef enum Etk_Argument_Returns
-{
- ETK_ARGUMENT_RETURN_OK = 1, /* no problems */
- ETK_ARGUMENT_RETURN_OK_NONE_PARSED = 2, /* no problems, no arguments
or no valid args */
- ETK_ARGUMENT_RETURN_REQUIRED_NOT_FOUND = 3, /* required arg not found */
- ETK_ARGUMENT_RETURN_REQUIRED_VALUE_NOT_FOUND = 4, /* required value for arg
no found */
- ETK_ARGUMENT_RETURN_MALFORMED = 5 /* malformed argument */
-} Etk_Argument_Returns;
-
-typedef enum Etk_Argument_Flags
-{
- 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_MULTIVALUE = 1 << 3, /* argument uses multi-valued args
*/
- ETK_ARGUMENT_FLAG_NONE = 1 << 4 /* used when terminating options */
-} Etk_Argument_Flags;
-
-struct _Etk_Argument
-{
- char *long_name; /* long name of argument: --foo */
- char short_name; /* short name of argument: -f */
- 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 */
- char *description; /* description of the argument for help */
-};
-
-int etk_arguments_parse(Etk_Argument *args, int *argc, char ***argv);
-void etk_argument_help_show(Etk_Argument *args);
-Evas_List *etk_argument_extra_find(const char *key);
-Etk_Bool etk_argument_is_set(Etk_Argument *args, const char *long_name, char
short_name);
+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);
/** @} */
===================================================================
RCS file: /cvs/e/e17/proto/etk/src/lib/etk_main.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -3 -r1.28 -r1.29
--- etk_main.c 2 Aug 2006 05:53:59 -0000 1.28
+++ etk_main.c 5 Aug 2006 02:37:25 -0000 1.29
@@ -1,12 +1,12 @@
/** @file etk_main.c */
#include "etk_main.h"
+#include <stdlib.h>
+#include <string.h>
#include <locale.h>
#include <limits.h>
-#include <string.h>
#include <Ecore.h>
#include <Ecore_Job.h>
-#include <Ecore_Evas.h>
#include <Evas.h>
#include <Edje.h>
#include "etk_argument.h"
@@ -33,19 +33,9 @@
static Evas_List *_etk_main_toplevel_widgets = NULL;
static Etk_Bool _etk_main_running = ETK_FALSE;
-static Etk_Bool _etk_main_initialized = ETK_FALSE;
+static int _etk_main_init_count = 0;
static Ecore_Job *_etk_main_iterate_job = NULL;
-/* configuration. FIXME should be on other subsystem? */
-static void _etk_main_options_setup(Etk_Argument *args, int index);
-
-Etk_Argument args[] = {
- { "etk-engine", 0, NULL, _etk_main_options_setup, NULL,
ETK_ARGUMENT_FLAG_OPTIONAL | ETK_ARGUMENT_FLAG_VALUE_REQUIRED, " " },
- { NULL, -1, NULL, NULL, NULL, ETK_ARGUMENT_FLAG_NONE, " " }
-};
-char *_etk_engine_name = NULL;
-
-
/**************************
*
* Implementation
@@ -54,118 +44,124 @@
/**
* @brief Initializes Etk. This function needs to be called before any other
call to an etk_* function. @n
- * It initializes Evas, Ecore, Ecore_Evas, Ecore_X and Edje so you do not need
to initialize them manually
- * if you call etk_init().
- * @return Returns ETK_TRUE on success, ETK_FALSE on failure
+ * You can call safely etk_init() several times, it will have an effect only
the first time you call it. The other times,
+ * it will just increment a counter. etk_shutdown() will decrement this
counter and will effectively shutdown Etk when
+ * the counter reaches 0. So you need to call etk_shutdown() the same number
of times as etk_init().
+ * @param argc the location of the "argc" paramater 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" paramater 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_shutdown()
*/
-Etk_Bool etk_init(int *argc, char ***argv)
+int etk_init(int *argc, char ***argv)
{
- int ret;
+ char *engine_name = NULL;
- if (_etk_main_initialized)
- return ETK_TRUE;
-
- ret = etk_arguments_parse(args, argc, argv);
- if((ret != ETK_ARGUMENT_RETURN_OK_NONE_PARSED) && (ret !=
ETK_ARGUMENT_RETURN_OK))
- {
- ETK_WARNING("Arguments parsing failed!");
- return ETK_FALSE;
- }
- /* TODO after the parsing, setup defaults if they arent set */
- if(!_etk_engine_name)
- _etk_engine_name = strdup("ecore_evas_software_x11");
-
- if (!evas_init())
- {
- ETK_WARNING("Evas initialization failed!");
- return ETK_FALSE;
- }
- if (!ecore_init())
+ if (_etk_main_init_count > 0)
{
- ETK_WARNING("Ecore initialization failed!");
- return ETK_FALSE;
+ _etk_main_init_count++;
+ return _etk_main_init_count;
}
- if (!edje_init())
- {
- ETK_WARNING("Edje initialization failed!");
- return ETK_FALSE;
- }
-
- etk_theme_init();
- if (!etk_engine_init())
- {
- ETK_WARNING("Etk_Engine initialization failed!");
- return ETK_FALSE;
- }
- if (!etk_engine_load(_etk_engine_name))
- {
- ETK_WARNING("Etk can not load the requested engine!");
- return ETK_FALSE;
- }
- if (!etk_dnd_init())
+ else
{
- ETK_WARNING("Etk_dnd initialization failed!");
- return ETK_FALSE;
+ /* Parse the arguments */
+ if (argc && argv)
+ {
+ etk_argument_value_get(argc, argv, "etk-engine", 'e', ETK_TRUE,
&engine_name);
+ }
+
+ /* Initialize the EFL */
+ if (!evas_init())
+ {
+ ETK_WARNING("Evas initialization failed!");
+ return 0;
+ }
+ if (!ecore_init())
+ {
+ ETK_WARNING("Ecore initialization failed!");
+ return 0;
+ }
+ if (!edje_init())
+ {
+ ETK_WARNING("Edje initialization failed!");
+ return 0;
+ }
+
+ /* Initialize the subsystems of Etk */
+ etk_theme_init();
+ if (!etk_engine_init())
+ {
+ ETK_WARNING("Etk_Engine initialization failed!");
+ return 0;
+ }
+ if (!etk_engine_load(engine_name ? engine_name :
"ecore_evas_software_x11"))
+ {
+ ETK_WARNING("Etk can not load the requested engine!");
+ return 0;
+ }
+ if (!etk_dnd_init())
+ {
+ ETK_WARNING("Etk_dnd initialization failed!");
+ return 0;
+ }
+ etk_tooltips_init();
+
+ /* Initialize Gettext */
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+
+ free(engine_name);
+ _etk_main_init_count++;
+ return _etk_main_init_count;
}
- etk_tooltips_init();
-
- /* Initialize Gettext */
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- _etk_main_initialized = ETK_TRUE;
- return ETK_TRUE;
-}
-/**
- * @brief Initializes Etk. This function needs to be called before any other
call to an etk_* function. @n
- * It initializes Evas, Ecore, Ecore_Evas, Ecore_X and Edje so you do not need
to initialize them manually
- * if you call etk_init().
- * @return Returns ETK_TRUE on success, ETK_FALSE on failure
- * @see etk_shutdown()
- */
-Etk_Bool etk_init_with_options(int *argc, char ***argv, const char
*extra_options)
-{
- /* TODO: this is just a stub */
- return ETK_TRUE;
}
/**
- * @brief Shuts down Etk. @n
- * You need to call it at the shutdown of your program to free all the
resources used by Etk. @n
- * It also shutdown Edje, Ecore_Evas, Ecore and Evas, so you do not need to
shut them down manually
+ * @brief Shuts down Etk. It decrements the counter of initializations. If the
counter reaches 0, it frees all the
+ * resources used by Etk. @n
+ * @return Returns the new number of times Etk has been initialized. 0 means
that the resources has been freed.
*/
-void etk_shutdown()
+int etk_shutdown()
{
- if (!_etk_main_initialized)
- return;
-
- etk_object_destroy_all_objects();
- etk_signal_shutdown();
- etk_type_shutdown();
+ if (_etk_main_init_count <= 0)
+ return 0;
- etk_textblock_shutdown();
- etk_tooltips_shutdown();
- etk_dnd_shutdown();
- etk_engine_shutdown();
- etk_theme_shutdown();
+ _etk_main_init_count--;
+ if (_etk_main_init_count == 0)
+ {
+ /* Shutdown the subsystem of Etk */
+ etk_object_destroy_all_objects();
+ etk_signal_shutdown();
+ etk_type_shutdown();
+
+ etk_textblock_shutdown();
+ etk_tooltips_shutdown();
+ etk_dnd_shutdown();
+ etk_engine_shutdown();
+ etk_theme_shutdown();
+
+ _etk_main_toplevel_widgets = evas_list_free(_etk_main_toplevel_widgets);
+
+ /* Shutdown the EFL*/
+ edje_shutdown();
+ ecore_shutdown();
+ evas_shutdown();
+ }
- edje_shutdown();
- ecore_shutdown();
- evas_shutdown();
- _etk_main_toplevel_widgets = evas_list_free(_etk_main_toplevel_widgets);
-
- _etk_main_initialized = ETK_FALSE;
+ return _etk_main_init_count;
}
/**
- * @brief Runs the Etk's main loop (and Ecore's too) until etk_main_quit() is
called. @n
- * The main look updates the widgets that need to be.
+ * @brief Runs the Etk's main loop until etk_main_quit() is called.
+ * @note It calls ecore_main_loop_begin() so you should not call
ecore_main_loop_begin() or ecore_main_loop_quit()
+ * if you are using etk_main() in your program.
*/
void etk_main()
{
- if (!_etk_main_initialized || _etk_main_running)
+ if (_etk_main_init_count <= 0 || _etk_main_running)
return;
_etk_main_running = ETK_TRUE;
@@ -173,8 +169,8 @@
}
/**
- * @brief Leaves the main loop of Etk. @n
- * It will quit the main loop of Ecore and will make etk_main() return.
+ * @brief Leaves the main loop of Etk. It will quit the main loop of Ecore
(ecore_main_loop_quit())
+ * and will make etk_main() return.
*/
void etk_main_quit()
{
@@ -197,7 +193,7 @@
Evas_List *l;
Etk_Widget *widget;
- if (!_etk_main_initialized)
+ if (_etk_main_init_count <= 0)
return;
/* TODO: only update the toplevel widgets that need to be updated */
@@ -210,8 +206,8 @@
}
/**
- * @brief Queues an iteration: it will run an iteration as soon as possible.
- * You do not need to call it manually.
+ * @internal
+ * @brief Queues an iteration: it will run an iteration as soon as possible
*/
void etk_main_iteration_queue()
{
@@ -220,7 +216,8 @@
}
/**
- * @brief Adds the widget to the list of toplevel widgets. For internal use
only!
+ * @internal
+ * @brief Adds the widget to the list of toplevel widgets
* @param widget the toplevel widget to add
*/
void etk_main_toplevel_widget_add(Etk_Toplevel_Widget *widget)
@@ -231,7 +228,8 @@
}
/**
- * @brief Removes the widget from the list of toplevel widgets. For internal
use only!
+ * @internal
+ * @brief Removes the widget from the list of toplevel widgets
* @param widget the toplevel widget to remove
*/
void etk_main_toplevel_widget_remove(Etk_Toplevel_Widget *widget)
@@ -299,15 +297,4 @@
_etk_main_size_allocate_recursive(ETK_WIDGET(l->data), ETK_FALSE);
}
-/* Setup parsed values. FIXME this should be on other subsystem (config?) */
-static void _etk_main_options_setup(Etk_Argument *args, int index)
-{
- Evas_List *l;
-
- l = args[index].data;
- if(!strcmp(args[index].long_name, "etk-engine"))
- {
- _etk_engine_name = l->data;
- }
-}
/** @} */
===================================================================
RCS file: /cvs/e/e17/proto/etk/src/lib/etk_main.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- etk_main.h 2 Aug 2006 05:53:59 -0000 1.6
+++ etk_main.h 5 Aug 2006 02:37:25 -0000 1.7
@@ -11,9 +11,8 @@
* @{
*/
-Etk_Bool etk_init(int *argc, char ***argv);
-Etk_Bool etk_init_with_options(int *argc, char ***argv, const char
*extra_options);
-void etk_shutdown();
+int etk_init(int *argc, char ***argv);
+int etk_shutdown();
void etk_main();
void etk_main_quit();
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs