diff options
Diffstat (limited to 'src/plugins/fs/helper.c')
-rw-r--r-- | src/plugins/fs/helper.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/plugins/fs/helper.c b/src/plugins/fs/helper.c new file mode 100644 index 00000000..59772a60 --- /dev/null +++ b/src/plugins/fs/helper.c | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2005 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file src/plugins/fs/helper.c | ||
23 | * @brief helper functions (parsing) | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | /** | ||
28 | * Parse a time given in the form | ||
29 | * "XX seconds yy days zz months". | ||
30 | * | ||
31 | * @param val set to the computed time | ||
32 | * @return OK on success, SYSERR on error | ||
33 | */ | ||
34 | int parseTime(const char * t, | ||
35 | cron_t * val) { | ||
36 | int pos; | ||
37 | int start; | ||
38 | unsigned int val; | ||
39 | char * tmp; | ||
40 | cron_t ret; | ||
41 | |||
42 | ret = 0; | ||
43 | pos = 0; | ||
44 | |||
45 | while (t[pos] != '\0') { | ||
46 | start = pos; | ||
47 | while ( (t[pos] != ' ') && | ||
48 | (t[pos] != '\0') ) | ||
49 | pos++; | ||
50 | tmp = STRNDUP(&t[start], | ||
51 | pos - start); | ||
52 | if (1 != sscanf(tmp, | ||
53 | "%u", | ||
54 | &val) ) | ||
55 | return -1; /* parse error */ | ||
56 | FREE(tmp); | ||
57 | while ( t[pos] == ' ') | ||
58 | pos++; | ||
59 | start = pos; | ||
60 | while ( (t[pos] != ' ') && | ||
61 | (t[pos] != '\0') ) | ||
62 | pos++; | ||
63 | if (0 == strncasecmp(&t[start], | ||
64 | _("ms"), | ||
65 | strlen(_("ms")))) | ||
66 | ret += cronMILLIS * val; | ||
67 | if (0 == strncasecmp(&t[start], | ||
68 | _("minutes"), | ||
69 | strlen(_("minutes")))) | ||
70 | ret += cronMINUTES * val; | ||
71 | else if (0 == strncasecmp(&t[start], | ||
72 | _("seconds"), | ||
73 | strlen(_("seconds")))) | ||
74 | ret += cronSECONDS * val; | ||
75 | else if (0 == strncasecmp(&t[start], | ||
76 | _("hours"), | ||
77 | strlen(_("hours")))) | ||
78 | ret += cronHOURS * val; | ||
79 | else if (0 == strncasecmp(&t[start], | ||
80 | _("days"), | ||
81 | strlen(_("days")))) | ||
82 | ret += cronDAYS * val; | ||
83 | else | ||
84 | return SYSERR; /* parse error */ | ||
85 | while ( t[pos] == ' ') | ||
86 | pos++; | ||
87 | } | ||
88 | *val = ret; | ||
89 | return OK; | ||
90 | } | ||
91 | |||