2 * This file is part of TISEAN
4 * Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber
6 * TISEAN is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * TISEAN is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with TISEAN; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /*Author: Rainer Hegger Last modified: Aug 19, 1999 */
25 #include "tisean_cec.h"
27 extern void check_alloc(void*);
31 '1' one or two unsigned (long) numbers, separated by comma, if two
32 '2' two unsigned (long) numbers separated by a comma
33 '3' three unsigned (long) numbers separated by commas
36 'o' optional string (must only begin with a minus if there is no space)
40 void check_unsigned(char *tocheck,int which)
47 if (!isdigit((unsigned int)tocheck[i]))
51 fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be an "
52 "unsigned integer\n",which);
53 exit(CHECK_OPTION_NOT_UNSIGNED);
57 void check_integer(char *tocheck,int which)
63 ok=(tocheck[0] == '-') || isdigit((unsigned int)tocheck[0]);
66 if (!isdigit((unsigned int)tocheck[i]))
70 fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be an "
72 exit(CHECK_OPTION_NOT_INTEGER);
76 void check_float(char *tocheck,int which)
82 check_alloc(rest=(char*)calloc(strlen(tocheck)+1,(size_t)1));
83 found=sscanf(tocheck,"%lf%s",&dummy,rest);
85 fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be a "
87 exit(CHECK_OPTION_NOT_FLOAT);
92 void check_two(char *tocheck,int which)
97 len=(unsigned int)strlen(tocheck);
99 if (tocheck[i] == ',')
102 fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be"
103 " unsigned,unsigned\n",which);
104 exit(CHECK_OPTION_NOT_TWO);
107 if (!isdigit((unsigned int)tocheck[j])) {
108 fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be"
109 " unsigned,unsigned\n",which);
110 exit(CHECK_OPTION_NOT_TWO);
112 for (j=i+1;j<len;j++)
113 if (!isdigit((unsigned int)tocheck[j])) {
114 fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be"
115 " unsigned,unsigned\n",which);
116 exit(CHECK_OPTION_NOT_TWO);
120 void check_three(char *tocheck,int which)
125 len=(unsigned int)strlen(tocheck);
127 if (tocheck[i] == ',')
131 fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be"
132 " unsigned,unsigned,unsigned\n",which);
133 exit(CHECK_OPTION_NOT_THREE);
136 for (j=i+1;j<len;j++)
137 if (tocheck[j] == ',')
141 fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be"
142 " unsigned,unsigned,unsigned\n",which);
143 exit(CHECK_OPTION_NOT_THREE);
147 if (!isdigit((unsigned int)tocheck[k])) {
148 fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be"
149 " unsigned,unsigned,unsigned\n",which);
150 exit(CHECK_OPTION_NOT_THREE);
153 if (!isdigit((unsigned int)tocheck[k])) {
154 fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be"
155 " unsigned,unsigned,unsigned\n",which);
156 exit(CHECK_OPTION_NOT_THREE);
158 for (k=j+1;k<len;k++)
159 if (!isdigit((unsigned int)tocheck[k])) {
160 fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be"
161 " unsigned,unsigned,unsigned\n",which);
162 exit(CHECK_OPTION_NOT_THREE);
166 char check_optional(char *tocheck,int which)
168 if (tocheck[0] == '-') {
169 fprintf(stderr,"If you want to give the -%c flag a parameter starting"
170 " with a - don't put a space. Ignoring it.\n",which);
176 char* check_option(char **in,int n,int which,int type)
178 char test,*ret=NULL,wasfound=0,ok=1;
183 test= (in[i][0] == '-') && (in[i][1] == which);
187 if (strlen(in[i]) > 2) {
189 case 'u': check_unsigned(in[i]+2,which);break;
190 case 'd': check_integer(in[i]+2,which);break;
191 case 'f': check_float(in[i]+2,which);break;
192 case '2': check_two(in[i]+2,which);break;
193 case '3': check_three(in[i]+2,which);break;
197 check_alloc(ret=(char*)calloc(strlen(in[i]+2)+1,(size_t)1));
207 case 'u': check_unsigned(in[i],which);break;
208 case 'd': check_integer(in[i],which);break;
209 case 'f': check_float(in[i],which);break;
210 case '2': check_two(in[i],which);break;
211 case '3': check_three(in[i]+2,which);break;
212 case 'o': ok=check_optional(in[i],which);break;
217 check_alloc(ret=(char*)calloc(strlen(in[i])+1,(size_t)1));
244 if (((type == 'o') || (type == 'n')) && (ret == NULL) && wasfound)
247 if (wasfound && (ret == NULL)) {
248 fprintf(stderr,"The option -%c needs some value. Exiting!\n",which);
249 exit(CHECK_OPTION_C_NO_VALUE);