aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fs/helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/fs/helper.c')
-rw-r--r--src/plugins/fs/helper.c127
1 files changed, 50 insertions, 77 deletions
diff --git a/src/plugins/fs/helper.c b/src/plugins/fs/helper.c
index f371505e..a0957628 100644
--- a/src/plugins/fs/helper.c
+++ b/src/plugins/fs/helper.c
@@ -37,91 +37,64 @@
37 * @param val set to the computed time 37 * @param val set to the computed time
38 * @return OK on success, SYSERR on error 38 * @return OK on success, SYSERR on error
39 */ 39 */
40int parseTime(const char * t, 40int
41 TIME_T * param) { 41parseTime (const char *t, TIME_T * param)
42{
42 int pos; 43 int pos;
43 int start; 44 int start;
44 unsigned int val; 45 unsigned int val;
45 char * tmp; 46 char *tmp;
46 cron_t ret; 47 cron_t ret;
47 48
48 ret = 0; 49 ret = 0;
49 pos = 0; 50 pos = 0;
50 51
51 while (t[pos] != '\0') { 52 while (t[pos] != '\0')
52 start = pos; 53 {
53 while ( (isdigit(t[pos])) && 54 start = pos;
54 (t[pos] != '\0') ) 55 while ((isdigit (t[pos])) && (t[pos] != '\0'))
55 pos++; 56 pos++;
56 tmp = STRNDUP(&t[start], 57 tmp = STRNDUP (&t[start], pos - start);
57 pos - start); 58 if (1 != sscanf (tmp, "%u", &val))
58 if (1 != sscanf(tmp, 59 return -1; /* parse error */
59 "%u", 60 FREE (tmp);
60 &val) ) 61 while (t[pos] == ' ')
61 return -1; /* parse error */ 62 pos++;
62 FREE(tmp); 63 start = pos;
63 while ( t[pos] == ' ') 64 while ((t[pos] != ' ') && (t[pos] != '\0'))
64 pos++; 65 pos++;
65 start = pos; 66 if (0 == strncasecmp (&t[start], _("ms"), strlen (_("ms"))))
66 while ( (t[pos] != ' ') && 67 ret += cronMILLIS * val;
67 (t[pos] != '\0') ) 68 if (0 == strncasecmp (&t[start], _("minutes"), strlen (_("minutes"))))
68 pos++; 69 ret += cronMINUTES * val;
69 if (0 == strncasecmp(&t[start], 70 else if (0 == strncasecmp (&t[start],
70 _("ms"), 71 _("seconds"), strlen (_("seconds"))))
71 strlen(_("ms")))) 72 ret += cronSECONDS * val;
72 ret += cronMILLIS * val; 73 else if (0 == strncasecmp (&t[start], _("hours"), strlen (_("hours"))))
73 if (0 == strncasecmp(&t[start], 74 ret += cronHOURS * val;
74 _("minutes"), 75 else if (0 == strncasecmp (&t[start], _("days"), strlen (_("days"))))
75 strlen(_("minutes")))) 76 ret += cronDAYS * val;
76 ret += cronMINUTES * val; 77 else
77 else if (0 == strncasecmp(&t[start], 78 if (0 == strncasecmp (&t[start], _("minute"), strlen (_("minute"))))
78 _("seconds"), 79 ret += cronMINUTES * val;
79 strlen(_("seconds")))) 80 else if (0 == strncasecmp (&t[start],
80 ret += cronSECONDS * val; 81 _("second"), strlen (_("second"))))
81 else if (0 == strncasecmp(&t[start], 82 ret += cronSECONDS * val;
82 _("hours"), 83 else if (0 == strncasecmp (&t[start], _("hour"), strlen (_("hour"))))
83 strlen(_("hours")))) 84 ret += cronHOURS * val;
84 ret += cronHOURS * val; 85 else if (0 == strncasecmp (&t[start], _("day"), strlen (_("day"))))
85 else if (0 == strncasecmp(&t[start], 86 ret += cronDAYS * val;
86 _("days"), 87 else if (0 == strncasecmp (&t[start], "m", strlen ("m")))
87 strlen(_("days")))) 88 ret += cronMINUTES * val;
88 ret += cronDAYS * val; 89 else if (0 == strncasecmp (&t[start], "s", strlen ("s")))
89 else 90 ret += cronSECONDS * val;
90 if (0 == strncasecmp(&t[start], 91 else if (0 == strncasecmp (&t[start], "h", strlen ("h")))
91 _("minute"), 92 ret += cronHOURS * val;
92 strlen(_("minute")))) 93 else
93 ret += cronMINUTES * val; 94 return SYSERR; /* parse error */
94 else if (0 == strncasecmp(&t[start], 95 while (t[pos] == ' ')
95 _("second"), 96 pos++;
96 strlen(_("second")))) 97 }
97 ret += cronSECONDS * val;
98 else if (0 == strncasecmp(&t[start],
99 _("hour"),
100 strlen(_("hour"))))
101 ret += cronHOURS * val;
102 else if (0 == strncasecmp(&t[start],
103 _("day"),
104 strlen(_("day"))))
105 ret += cronDAYS * val;
106 else if (0 == strncasecmp(&t[start],
107 "m",
108 strlen("m")))
109 ret += cronMINUTES * val;
110 else if (0 == strncasecmp(&t[start],
111 "s",
112 strlen("s")))
113 ret += cronSECONDS * val;
114 else if (0 == strncasecmp(&t[start],
115 "h",
116 strlen("h")))
117 ret += cronHOURS * val;
118 else
119 return SYSERR; /* parse error */
120 while ( t[pos] == ' ')
121 pos++;
122 }
123 *param = ret / cronSECONDS; 98 *param = ret / cronSECONDS;
124 return OK; 99 return OK;
125} 100}
126
127