aboutsummaryrefslogtreecommitdiff
path: root/src/io/cli.c
diff options
context:
space:
mode:
authorJ08nY2017-10-04 19:09:20 +0200
committerJ08nY2017-10-04 19:09:20 +0200
commitf708453b55b6b05187febf3d5a2bd8608a897370 (patch)
tree340d36ad38ae355aa606820e5a1c045df977cbec /src/io/cli.c
parentcaa000e3625241b930fdcda1594bbaf9c9acf642 (diff)
downloadecgen-f708453b55b6b05187febf3d5a2bd8608a897370.tar.gz
ecgen-f708453b55b6b05187febf3d5a2bd8608a897370.tar.zst
ecgen-f708453b55b6b05187febf3d5a2bd8608a897370.zip
Diffstat (limited to 'src/io/cli.c')
-rw-r--r--src/io/cli.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/io/cli.c b/src/io/cli.c
index 77f279f..74e6cc7 100644
--- a/src/io/cli.c
+++ b/src/io/cli.c
@@ -4,7 +4,6 @@
*/
#include "cli.h"
#include <string.h>
-#include <unistd.h>
#include "exhaustive/ansi.h"
char cli_doc[] =
@@ -34,6 +33,7 @@ enum opt_keys {
OPT_POINTS,
OPT_THREADS,
OPT_TSTACK,
+ OPT_TIMEOUT,
OPT_ANOMALOUS
};
@@ -68,6 +68,7 @@ struct argp_option cli_options[] = {
{"memory", OPT_MEMORY, "SIZE", 0, "Use PARI stack of SIZE (can have suffix k/m/g).", 4},
{"threads", OPT_THREADS, "NUM", 0, "Use NUM threads.", 4},
{"thread-stack", OPT_TSTACK, "SIZE", 0, "Use PARI stack of SIZE (per thread, can have suffix k/m/g).", 4},
+ {"timeout", OPT_TIMEOUT, "TIME", 0, "Timeout computation of a curve parameter after TIME (can have suffix s/m/h/d).", 4},
{0}
};
// clang-format on
@@ -87,6 +88,21 @@ static unsigned long cli_parse_memory(const char *str) {
return read;
}
+static unsigned long cli_parse_time(const char *str) {
+ char *suffix = NULL;
+ unsigned long read = strtoul(str, &suffix, 10);
+ if (suffix) {
+ if (*suffix == 'm' || *suffix == 'M') {
+ read *= 60;
+ } else if (*suffix == 'h' || *suffix == 'H') {
+ read *= 3600;
+ } else if (*suffix == 'd' || *suffix == 'D') {
+ read *= 86400;
+ }
+ }
+ return read;
+}
+
error_t cli_parse(int key, char *arg, struct argp_state *state) {
config_t *cfg = state->input;
@@ -100,6 +116,9 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) {
case OPT_TSTACK:
cfg->thread_memory = cli_parse_memory(arg);
break;
+ case OPT_TIMEOUT:
+ cfg->timeout = cli_parse_time(arg);
+ break;
case OPT_THREADS:
if (!strcmp(arg, "auto") || !strcmp(arg, "AUTO")) {
long nprocs = sysconf(_SC_NPROCESSORS_ONLN);