2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2011-2011 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula(R) is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Kern Sibbald, January MMXII
31 * Selection list. A string of integers separated by commas
32 * representing items selected. Ranges of the form nn-mm
41 * error if returns -1 and errmsg set
42 * end of items if returns -1 and errmsg NULL
44 int64_t sellist::next()
54 * As we walk the list, we set EOF in
55 * the end of the next item to ease scanning,
56 * but save and then restore the character.
58 for (p=e; p && *p; p=e) {
68 h = strchr(p, '-'); /* range? */
70 errmsg = _("Negative numbers not permitted.\n");
76 if (!is_an_integer(h)) {
77 errmsg = _("Range end is not integer.\n");
81 if (!is_an_integer(p)) {
82 errmsg = _("Range start is not an integer.\n");
85 beg = str_to_int64(p);
86 end = str_to_int64(h);
88 errmsg = _("Range end not bigger than start.\n");
94 if (!is_an_integer(p)) {
95 errmsg = _("Input value is not an integer.\n");
98 beg = end = str_to_int64(p);
106 if (beg <= 0 || end <= 0) {
107 errmsg = _("Selection items must be be greater than zero.\n");
111 errmsg = _("Selection item too large.\n");
119 errmsg = NULL; /* No error */
123 return -1; /* Error, errmsg set */
128 * Set selection string and optionally scan it
129 * returns false on error in string
132 bool sellist::set_string(char *string, bool scan=true)
135 * Copy string, because we write into it,
136 * then scan through it once to find any
142 e = str = bstrdup(string);
147 while (next() >= 0) {
161 int main(int argc, char **argv, char **env)
168 msg = _("No input string given.\n");
171 Dmsg1(000, "argv[1]=%s\n", argv[1]);
173 strip_trailing_junk(argv[1]);
174 sl.set_string(argv[1]);
175 if ((msg = sl.get_errmsg())) {
178 while ((i=sl.next()) >= 0) {
179 Dmsg1(000, "%d\n", i);
181 if ((msg = sl.get_errmsg())) {
184 printf("\nPass 2\n");
185 sl.set_string(argv[1]);
186 while ((i=sl.next()) >= 0) {
187 Dmsg1(000, "%d\n", i);
189 if ((msg = sl.get_errmsg())) {
195 Dmsg1(000, "Error: %s\n", msg);
199 #endif /* TEST_PROGRAM */