From 64ce68f004af9bca11a57ff0b04d6ecf7ff13c1a Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Fri, 24 Jan 2014 12:44:23 +0100
Subject: [PATCH] Added cmdline args support to wget example.
---
examples/wget/Makefile.apple2enh.defines | 2 +-
examples/wget/Makefile.atarixl.defines | 2 +-
examples/wget/Makefile.c128.defines | 2 +-
examples/wget/Makefile.c64.defines | 2 +-
examples/wget/wget.c | 17 +++++++++++++++--
5 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/examples/wget/Makefile.apple2enh.defines b/examples/wget/Makefile.apple2enh.defines
index 405794c09..a4bbe71fb 100644
--- a/examples/wget/Makefile.apple2enh.defines
+++ b/examples/wget/Makefile.apple2enh.defines
@@ -1 +1 @@
-DEFINES = WITH_LOGGING,WITH_CLIENT,WITH_DNS
+DEFINES = WITH_LOGGING,WITH_CLIENT,WITH_DNS,WITH_ARGS
diff --git a/examples/wget/Makefile.atarixl.defines b/examples/wget/Makefile.atarixl.defines
index 405794c09..a4bbe71fb 100644
--- a/examples/wget/Makefile.atarixl.defines
+++ b/examples/wget/Makefile.atarixl.defines
@@ -1 +1 @@
-DEFINES = WITH_LOGGING,WITH_CLIENT,WITH_DNS
+DEFINES = WITH_LOGGING,WITH_CLIENT,WITH_DNS,WITH_ARGS
diff --git a/examples/wget/Makefile.c128.defines b/examples/wget/Makefile.c128.defines
index 405794c09..a4bbe71fb 100644
--- a/examples/wget/Makefile.c128.defines
+++ b/examples/wget/Makefile.c128.defines
@@ -1 +1 @@
-DEFINES = WITH_LOGGING,WITH_CLIENT,WITH_DNS
+DEFINES = WITH_LOGGING,WITH_CLIENT,WITH_DNS,WITH_ARGS
diff --git a/examples/wget/Makefile.c64.defines b/examples/wget/Makefile.c64.defines
index 3dbfd3e2f..91a6f26ad 100644
--- a/examples/wget/Makefile.c64.defines
+++ b/examples/wget/Makefile.c64.defines
@@ -1 +1 @@
-DEFINES = WITH_LOGGING,WITH_CLIENT,WITH_DNS,WITH_PFS
+DEFINES = WITH_LOGGING,WITH_CLIENT,WITH_DNS,WITH_PFS,WITH_ARGS
diff --git a/examples/wget/wget.c b/examples/wget/wget.c
index d968f99d1..8a452771c 100644
--- a/examples/wget/wget.c
+++ b/examples/wget/wget.c
@@ -44,6 +44,9 @@ PROCESS(wget_process, "Wget");
AUTOSTART_PROCESSES(&wget_process);
+extern int contiki_argc;
+extern char **contiki_argv;
+
static int file = -1;
static char url[128];
@@ -162,9 +165,19 @@ PROCESS_THREAD(wget_process, ev, data)
}
fputs("Get url:", stdout);
- gets(url);
+ if(contiki_argc > 1) {
+ strcpy(url, contiki_argv[1]);
+ puts(url);
+ } else {
+ gets(url);
+ }
fputs("Save as:", stdout);
- gets(name);
+ if(contiki_argc > 2) {
+ strcpy(name, contiki_argv[2]);
+ puts(name);
+ } else {
+ gets(name);
+ }
file = cfs_open(name, CFS_WRITE);
if(file == -1) {
printf("Open error with '%s'\n", name);