summaryrefslogtreecommitdiff
path: root/n/avr/modules/host
diff options
context:
space:
mode:
Diffstat (limited to 'n/avr/modules/host')
-rw-r--r--n/avr/modules/host/host.h7
-rw-r--r--n/avr/modules/host/host.host.c13
-rw-r--r--n/avr/modules/host/test/test_host.c5
3 files changed, 22 insertions, 3 deletions
diff --git a/n/avr/modules/host/host.h b/n/avr/modules/host/host.h
index d1a00af..73cd4a5 100644
--- a/n/avr/modules/host/host.h
+++ b/n/avr/modules/host/host.h
@@ -30,10 +30,15 @@
# error Use this header only for HOST only files !
#endif
-/** Initialise host modules. */
+/** Initialise host module. */
void
host_init (int argc, char **argv);
+/** Retrieve saved program arguments. Program name and used parameters are
+ * stripped. */
+void
+host_get_program_arguments (int *argc, char ***argv);
+
/** Host variables are usefull on reset. They are passed in the environment.
* This is not optimised for performance. */
diff --git a/n/avr/modules/host/host.host.c b/n/avr/modules/host/host.host.c
index bcfd7d2..7967e9c 100644
--- a/n/avr/modules/host/host.host.c
+++ b/n/avr/modules/host/host.host.c
@@ -36,7 +36,7 @@
static int host_saved_argc;
static char **host_saved_argv;
-/** Initialise host modules. */
+/** Initialise host module. */
void
host_init (int argc, char **argv)
{
@@ -44,6 +44,16 @@ host_init (int argc, char **argv)
host_saved_argv = argv;
}
+/** Retrieve saved program arguments. Program name and used parameters are
+ * stripped. */
+void
+host_get_program_arguments (int *argc, char ***argv)
+{
+ assert (host_saved_argc);
+ *argc = host_saved_argc - 1;
+ *argv = host_saved_argv + 1;
+}
+
/** Register a host integer. */
void
host_register_integer (const char *name, int val)
@@ -84,6 +94,7 @@ host_fetch_string (const char *name)
void
host_reset (void)
{
+ assert (host_saved_argv);
execv (program_invocation_name, host_saved_argv);
assert_perror (errno);
abort ();
diff --git a/n/avr/modules/host/test/test_host.c b/n/avr/modules/host/test/test_host.c
index db8161f..8c98a94 100644
--- a/n/avr/modules/host/test/test_host.c
+++ b/n/avr/modules/host/test/test_host.c
@@ -33,6 +33,8 @@ main (int argc, char **argv)
{
int i;
const char *s;
+ int ac;
+ char **av;
printf ("reset\n");
host_init (argc, argv);
i = host_fetch_integer ("avr_integer");
@@ -40,7 +42,8 @@ main (int argc, char **argv)
if (i != -1)
{
printf ("get\n");
- assert_print (argc == 2 && strcmp (argv[1], "ni") == 0,
+ host_get_program_arguments (&ac, &av);
+ assert_print (ac == 1 && strcmp (av[0], "ni") == 0,
"argument passing not working");
assert (i == 42);
assert (strcmp (s, "Ni!") == 0);