2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2011-2012 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
40 * error if returns -1 and errmsg set
41 * end of items if returns -1 and errmsg NULL
43 int64_t sellist::next()
53 * As we walk the list, we set EOF in
54 * the end of the next item to ease scanning,
55 * but save and then restore the character.
57 for (p=e; p && *p; p=e) {
67 h = strchr(p, '-'); /* range? */
69 errmsg = _("Negative numbers not permitted.\n");
75 if (!is_an_integer(h)) {
76 errmsg = _("Range end is not integer.\n");
80 if (!is_an_integer(p)) {
81 errmsg = _("Range start is not an integer.\n");
84 beg = str_to_int64(p);
85 end = str_to_int64(h);
87 errmsg = _("Range end not bigger than start.\n");
93 if (!is_an_integer(p)) {
94 errmsg = _("Input value is not an integer.\n");
97 beg = end = str_to_int64(p);
105 if (beg <= 0 || end <= 0) {
106 errmsg = _("Selection items must be be greater than zero.\n");
110 errmsg = _("Selection item too large.\n");
118 errmsg = NULL; /* No error */
122 return -1; /* Error, errmsg set */
127 * Set selection string and optionally scan it
128 * returns false on error in string
131 bool sellist::set_string(char *string, bool scan=true)
134 * Copy string, because we write into it,
135 * then scan through it once to find any
141 e = str = bstrdup(string);
146 while (next() >= 0) {
160 int main(int argc, char **argv, char **env)
167 msg = _("No input string given.\n");
170 Dmsg1(000, "argv[1]=%s\n", argv[1]);
172 strip_trailing_junk(argv[1]);
173 sl.set_string(argv[1]);
174 if ((msg = sl.get_errmsg())) {
177 while ((i=sl.next()) >= 0) {
178 Dmsg1(000, "%d\n", i);
180 if ((msg = sl.get_errmsg())) {
183 printf("\nPass 2\n");
184 sl.set_string(argv[1]);
185 while ((i=sl.next()) >= 0) {
186 Dmsg1(000, "%d\n", i);
188 if ((msg = sl.get_errmsg())) {
194 Dmsg1(000, "Error: %s\n", msg);
198 #endif /* TEST_PROGRAM */