3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #define TONUMBER_uint64(S,E,B) strtoll(S,E,B)
28 #define TONUMBER_uint32(S,E,B) strtol (S,E,B)
30 #define ISNUMBER(TYPE,SHORT) \
31 static inline ALWAYSINLINE bool \
32 isNumber_##SHORT(char const **str,size_t *len,TYPE *res,char end_chr) \
36 *res = ((TYPE)(1)) << TONUMBER_##SHORT(++*str, &err_ptr, 0); \
40 *res = TONUMBER_##SHORT(*str, &err_ptr, 0); \
41 return err_ptr>*str && *err_ptr==end_chr; \
45 #define LISTPARSER(TYPE,SHORT) \
46 ISNUMBER(TYPE,SHORT) \
48 utilvserver_listparser_ ## SHORT(char const *str, size_t len, \
49 char const **err_ptr, \
53 TYPE (*func)(char const *, size_t)) \
55 if (len==0) len = strlen(str); \
57 char const *ptr = strchr(str, ','); \
60 bool is_neg = false; \
61 bool allow_zero = true; \
63 while (len>0 && (*str=='!' || *str=='~')) { \
69 cnt = ptr ? (size_t)(ptr-str) : len; \
70 if (cnt>=len) { cnt=len; len=0; } \
75 else if (strncasecmp(str,"all",cnt)==0 || \
76 strncasecmp(str,"any",cnt)==0) \
78 else if (strncasecmp(str,"none",cnt)==0) {} \
79 else if (!isNumber_##SHORT(&str, &cnt, &tmp, str[cnt])) { \
80 tmp = (*func)(str,cnt); \
84 if (tmp!=0 || allow_zero) { \
85 if (!is_neg) *flag |= tmp; \
90 if (err_ptr) *err_ptr = str; \
91 if (err_len) *err_len = cnt; \
99 if (err_ptr) *err_ptr = 0; \
100 if (err_len) *err_len = 0; \