summaryrefslogtreecommitdiff
path: root/tests/suite/ecore/src/lib/ecore_app.c
blob: b83e5b2958539e8f38b934a46422ebdea7b2ed87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>

#ifndef _MSC_VER
#include <unistd.h>
#else
#include <process.h>
#endif

#ifdef HAVE_EVIL
#include <Evil.h>
#endif

#include "Ecore.h"
#include "ecore_private.h"

static int app_argc = 0;
static char **app_argv = NULL;

/**
 * Set up the programs command-line arguments.
 * @param argc The same as passed as argc to the programs main() function
 * @param argv The same as passed as argv to the programs main() function
 *
 * A call to this function will store the programs command-line arguments
 * for later use by ecore_app_restart() or ecore_app_args_get().
 */
EAPI void ecore_app_args_set(int argc, const char **argv)
{
	if ((argc < 1) || (!argv))
		return;
	app_argc = argc;
	app_argv = (char **) argv;
}

/**
 * Return the programs stored command-line arguments.
 * @param argc A pointer to the return value to hold argc
 * @param argv A pointer to the return value to hold argv
 *
 * When called, this funciton returns the arguments for the program stored by
 * ecore_app_args_set(). The integer pointed to by @p argc will be filled, if
 * the pointer is not NULL, and the string array pointer @p argv will be filled
 * also if the pointer is not NULL. The values they are filled with will be the
 * same set by ecore_app_args_set().
 */
EAPI void ecore_app_args_get(int *argc, char ***argv)
{
	if (argc)
		*argc = app_argc;
	if (argv)
		*argv = app_argv;
}

/**
 * Restart the program executable with the command-line arguments stored.
 *
 * This function will restart & re-execute this program in place of itself
 * using the command-line arguments stored by ecore_app_args_set(). This is
 * an easy way for a program to restart itself for cleanup purposes,
 * configuration reasons or in the event of a crash.
 */
EAPI void ecore_app_restart(void)
{
	char *args[4096];
	int i;

	if ((app_argc < 1) || (!app_argv))
		return;
	if (app_argc >= 4096)
		return;
	for (i = 0; i < app_argc; i++)
		args[i] = app_argv[i];
	args[i] = NULL;
	execvp(app_argv[0], args);
}