commit ae37fd49e6a179bbb594dddb2ae7f4e4d19e6b79
parent e87498cd5cf86228b0fafd0c76f3a5255bd7fd26
Author: Ari Malinen <ari.malinen@gmail.com>
Date: Fri, 30 Jan 2015 14:48:13 +0200
Accept any number of tabs or spaces as field separator
Diffstat:
M | README | | | 8 | +++++--- |
M | crond.c | | | 69 | ++++++++++++++++++++++++++++----------------------------------------- |
M | scron.1 | | | 10 | ++++++---- |
3 files changed, 39 insertions(+), 48 deletions(-)
diff --git a/README b/README
@@ -16,9 +16,11 @@ Configuration
Columns:
minute, hour, day of month, month, day of week, command
-Syntax:
- Value: * (wildcard), 30 (number), */N (repeat), or 1-5 (range)
- Separator: \t (tab)
+Separator:
+ Any number of tabs or spaces.
+
+Value:
+ * (wildcard), 30 (number), */N (repeat), or 1-5 (range)
Example of crontab file:
# Run updatedb at 6:00 every day
diff --git a/crond.c b/crond.c
@@ -334,6 +334,19 @@ loadentries(void)
int r = 0, y;
size_t size = 0;
ssize_t len;
+ int i, nflim;
+ struct field *f;
+ struct fieldlimits {
+ char *name;
+ long min;
+ long max;
+ } flim[] = {
+ { "min", 0, 59 },
+ { "hour", 0, 23 },
+ { "mday", 1, 31 },
+ { "mon", 1, 12 },
+ { "wday", 0, 6 }
+ };
if ((fp = fopen(config, "r")) == NULL) {
logerr("error: can't open %s: %s\n", config, strerror(errno));
@@ -347,50 +360,24 @@ loadentries(void)
cte = emalloc(sizeof(*cte));
- col = strsep(&p, "\t");
- if (!col || parsefield(col, 0, 59, &cte->min) < 0) {
- logerr("error: failed to parse `min' field on line %d\n",
- y + 1);
- free(cte);
- r = -1;
- break;
- }
-
- col = strsep(&p, "\t");
- if (!col || parsefield(col, 0, 23, &cte->hour) < 0) {
- logerr("error: failed to parse `hour' field on line %d\n",
- y + 1);
- free(cte);
- r = -1;
- break;
- }
-
- col = strsep(&p, "\t");
- if (!col || parsefield(col, 1, 31, &cte->mday) < 0) {
- logerr("error: failed to parse `mday' field on line %d\n",
- y + 1);
- free(cte);
- r = -1;
- break;
- }
-
- col = strsep(&p, "\t");
- if (!col || parsefield(col, 1, 12, &cte->mon) < 0) {
- logerr("error: failed to parse `mon' field on line %d\n",
- y + 1);
- free(cte);
- r = -1;
- break;
+ f = &cte->min;
+ nflim = LEN(flim);
+ for (i = 0; i < nflim; i++) {
+ do
+ col = strsep(&p, "\t ");
+ while (col[0] == '\0');
+
+ if (!col || parsefield(col, flim[i].min, flim[i].max, f++) < 0) {
+ logerr("error: failed to parse `%s' field on line %d\n",
+ flim[i].name, y + 1);
+ free(cte);
+ r = -1;
+ break;
+ }
}
- col = strsep(&p, "\t");
- if (!col || parsefield(col, 0, 6, &cte->wday) < 0) {
- logerr("error: failed to parse `wday' field on line %d\n",
- y + 1);
- free(cte);
- r = -1;
+ if (r == -1)
break;
- }
col = strsep(&p, "\n");
if (!col) {
diff --git a/scron.1 b/scron.1
@@ -1,4 +1,4 @@
-.Dd Jan 29, 2015
+.Dd Jan 30, 2015
.Dt SCRON 1
.Os
.Sh NAME
@@ -28,9 +28,11 @@ Configuration is done by editing the crontab file.
Columns:
minute, hour, day of month, month, day of week, command
-Syntax:
- Value: * (wildcard), 30 (number), */N (repeat), or 1-5 (range)
- Separator: \\t (tab)
+Separator:
+ Any number of tabs or spaces.
+
+Value:
+ * (wildcard), 30 (number), */N (repeat), or 1-5 (range)
.Sh EXAMPLE
Example of crontab file:
# Run updatedb at 6:00 every day