[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r23730 - in gnunet: doc/man src/fs src/include src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r23730 - in gnunet: doc/man src/fs src/include src/util |
Date: |
Sun, 9 Sep 2012 20:36:01 +0200 |
Author: grothoff
Date: 2012-09-09 20:36:01 +0200 (Sun, 09 Sep 2012)
New Revision: 23730
Modified:
gnunet/doc/man/gnunet-search.1
gnunet/src/fs/gnunet-search.c
gnunet/src/include/gnunet_getopt_lib.h
gnunet/src/util/getopt_helpers.c
Log:
new getopt helper function to parse relative time command line argument
Modified: gnunet/doc/man/gnunet-search.1
===================================================================
--- gnunet/doc/man/gnunet-search.1 2012-09-09 15:43:59 UTC (rev 23729)
+++ gnunet/doc/man/gnunet-search.1 2012-09-09 18:36:01 UTC (rev 23730)
@@ -47,8 +47,8 @@
automatically terminate the search after receiving VALUE results.
.TP
-\fB\-t \fIVALUE\fR, \fB\-\-timeout=\fIVALUE\fR
-Automatically timeout search after VALUE ms. Otherwise the search runs until
gnunet\-search is aborted with CTRL\-C.
+\fB\-t \fIDELAY\fR, \fB\-\-timeout=\fIDELAY\fR
+Automatically timeout search after DELAY. The value given must be a number
followed by a space and a time unit, for example "500 ms". Note that the
quotes are required on the shell. Otherwise the search runs until
gnunet\-search is aborted with CTRL\-C.
.TP
\fB\-v\fR, \fB\-\-version\fR
Modified: gnunet/src/fs/gnunet-search.c
===================================================================
--- gnunet/src/fs/gnunet-search.c 2012-09-09 15:43:59 UTC (rev 23729)
+++ gnunet/src/fs/gnunet-search.c 2012-09-09 18:36:01 UTC (rev 23730)
@@ -42,11 +42,14 @@
static unsigned int anonymity = 1;
-static unsigned long long timeout;
+/**
+ * Timeout for the search, 0 means to wait for CTRL-C.
+ */
+static struct GNUNET_TIME_Relative timeout;
static unsigned int results_limit;
-static unsigned int results = 0;
+static unsigned int results;
static int verbose;
@@ -220,7 +223,6 @@
struct GNUNET_FS_Uri *uri;
unsigned int argc;
enum GNUNET_FS_SearchOptions options;
- struct GNUNET_TIME_Relative delay;
argc = 0;
while (NULL != args[argc])
@@ -257,16 +259,11 @@
ret = 1;
return;
}
- if (timeout != 0)
- {
- delay.rel_value = timeout;
- GNUNET_SCHEDULER_add_delayed (delay, &shutdown_task, NULL);
- }
+ if (0 != timeout.rel_value)
+ GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL);
else
- {
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
NULL);
- }
}
@@ -290,9 +287,9 @@
{'o', "output", "PREFIX",
gettext_noop ("write search results to file starting with PREFIX"),
1, &GNUNET_GETOPT_set_string, &output_filename},
- {'t', "timeout", "VALUE",
- gettext_noop ("automatically terminate search after VALUE ms"),
- 1, &GNUNET_GETOPT_set_ulong, &timeout},
+ {'t', "timeout", "DELAY",
+ gettext_noop ("automatically terminate search after DELAY"),
+ 1, &GNUNET_GETOPT_set_relative_time, &timeout},
{'V', "verbose", NULL,
gettext_noop ("be verbose (print progress information)"),
0, &GNUNET_GETOPT_set_one, &verbose},
Modified: gnunet/src/include/gnunet_getopt_lib.h
===================================================================
--- gnunet/src/include/gnunet_getopt_lib.h 2012-09-09 15:43:59 UTC (rev
23729)
+++ gnunet/src/include/gnunet_getopt_lib.h 2012-09-09 18:36:01 UTC (rev
23730)
@@ -232,6 +232,24 @@
/**
+ * Set an option of type 'struct GNUNET_TIME_Relative' from the command line.
+ * A pointer to this function should be passed as part of the
+ * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options
+ * of this type. It should be followed by a pointer to a value of
+ * type 'struct GNUNET_TIME_Relative'.
+ *
+ * @param ctx command line processing context
+ * @param scls additional closure (will point to the 'struct
GNUNET_TIME_Relative')
+ * @param option name of the option
+ * @param value actual value of the option as a string.
+ * @return GNUNET_OK if parsing the value worked
+ */
+int
+GNUNET_GETOPT_set_relative_time (struct
GNUNET_GETOPT_CommandLineProcessorContext *ctx,
+ void *scls, const char *option, const char
*value);
+
+
+/**
* Set an option of type 'unsigned int' from the command line.
* A pointer to this function should be passed as part of the
* 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options
Modified: gnunet/src/util/getopt_helpers.c
===================================================================
--- gnunet/src/util/getopt_helpers.c 2012-09-09 15:43:59 UTC (rev 23729)
+++ gnunet/src/util/getopt_helpers.c 2012-09-09 18:36:01 UTC (rev 23730)
@@ -26,7 +26,7 @@
#include "platform.h"
#include "gnunet_common.h"
-#include "gnunet_getopt_lib.h"
+#include "gnunet_util_lib.h"
#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
@@ -263,6 +263,36 @@
/**
+ * Set an option of type 'struct GNUNET_TIME_Relative' from the command line.
+ * A pointer to this function should be passed as part of the
+ * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options
+ * of this type. It should be followed by a pointer to a value of
+ * type 'struct GNUNET_TIME_Relative'.
+ *
+ * @param ctx command line processing context
+ * @param scls additional closure (will point to the 'struct
GNUNET_TIME_Relative')
+ * @param option name of the option
+ * @param value actual value of the option as a string.
+ * @return GNUNET_OK if parsing the value worked
+ */
+int
+GNUNET_GETOPT_set_relative_time (struct
GNUNET_GETOPT_CommandLineProcessorContext *ctx,
+ void *scls, const char *option, const char
*value)
+{
+ struct GNUNET_TIME_Relative *val = scls;
+
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_fancy_time_to_relative (value,
+ val))
+ {
+ FPRINTF (stderr, _("You must pass relative time to the `%s' option.\n"),
option);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
* Set an option of type 'unsigned int' from the command line.
* A pointer to this function should be passed as part of the
* 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r23730 - in gnunet: doc/man src/fs src/include src/util,
gnunet <=