From 8dfbde5d1610464a2b6bbda58dd09508a2505b11 Mon Sep 17 00:00:00 2001 From: Unbit Date: Mon, 8 Apr 2013 10:20:22 +0200 Subject: [PATCH] added --for-times --- core/utils.c | 19 +++++++++++++++++++ core/uwsgi.c | 1 + uwsgi.h | 1 + 3 files changed, 21 insertions(+) diff --git a/core/utils.c b/core/utils.c index 253c27a6..14c16bed 100644 --- a/core/utils.c +++ b/core/utils.c @@ -1525,6 +1525,25 @@ int uwsgi_logic_opt_for_glob(char *key, char *value) { return 1; } +int uwsgi_logic_opt_for_times(char *key, char *value) { + + int num = atoi(uwsgi.logic_opt_data); + int i; + char str_num[11]; + + for (i = 1; i <= num; i++) { + int ret = uwsgi_num2str2(i, str_num); + // security check + if (ret < 0 || ret > 11) { + exit(1); + } + add_exported_option(key, uwsgi_substitute(value, "%(_)", str_num), 0); + } + + return 1; +} + + void add_exported_option(char *key, char *value, int configured) { diff --git a/core/uwsgi.c b/core/uwsgi.c index ffc0b07b..c7ee2f9e 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -80,6 +80,7 @@ static struct uwsgi_option uwsgi_base_options[] = { {"for", required_argument, 0, "(opt logic) for cycle", uwsgi_opt_logic, (void *) uwsgi_logic_opt_for, UWSGI_OPT_IMMEDIATE}, {"for-glob", required_argument, 0, "(opt logic) for cycle (expand glob)", uwsgi_opt_logic, (void *) uwsgi_logic_opt_for_glob, UWSGI_OPT_IMMEDIATE}, + {"for-times", required_argument, 0, "(opt logic) for cycle (expand the specified num to a list starting from 1)", uwsgi_opt_logic, (void *) uwsgi_logic_opt_for_times, UWSGI_OPT_IMMEDIATE}, {"endfor", optional_argument, 0, "(opt logic) end for cycle", uwsgi_opt_noop, NULL, UWSGI_OPT_IMMEDIATE}, {"end-for", optional_argument, 0, "(opt logic) end for cycle", uwsgi_opt_noop, NULL, UWSGI_OPT_IMMEDIATE}, diff --git a/uwsgi.h b/uwsgi.h index 49e165a8..c043c9fd 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -3287,6 +3287,7 @@ void uwsgi_opt_noop(char *, char *, void *); void uwsgi_opt_logic(char *, char *, void *); int uwsgi_logic_opt_for(char *, char *); int uwsgi_logic_opt_for_glob(char *, char *); +int uwsgi_logic_opt_for_times(char *, char *); int uwsgi_logic_opt_if_env(char *, char *); int uwsgi_logic_opt_if_not_env(char *, char *); int uwsgi_logic_opt_if_opt(char *, char *);