/* * This file is part of TISEAN * * Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber * * TISEAN is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * TISEAN is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with TISEAN; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /*Author: Rainer Hegger Last modified: Aug 19, 1999 */ #include #include #include #include #include "tisean_cec.h" extern void check_alloc(void*); /* possible types are 'd' (long) integer 'u' unsigned (long) '1' one or two unsigned (long) numbers, separated by comma, if two '2' two unsigned (long) numbers separated by a comma '3' three unsigned (long) numbers separated by commas 'f' float 's' string 'o' optional string (must only begin with a minus if there is no space) 'n' no parameter */ void check_unsigned(char *tocheck,int which) { int i,n; char ok=1; n=strlen(tocheck); for (i=0;i= (len-1)) { fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be" " unsigned,unsigned\n",which); exit(CHECK_OPTION_NOT_TWO); } for (j=0;j= (len-1)) { fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be" " unsigned,unsigned,unsigned\n",which); exit(CHECK_OPTION_NOT_THREE); } for (j=i+1;j= (len-1)) { fprintf(stderr,"Wrong type of parameter for flag -%c. Has to be" " unsigned,unsigned,unsigned\n",which); exit(CHECK_OPTION_NOT_THREE); } for (k=0;k 2) { switch(type) { case 'u': check_unsigned(in[i]+2,which);break; case 'd': check_integer(in[i]+2,which);break; case 'f': check_float(in[i]+2,which);break; case '2': check_two(in[i]+2,which);break; case '3': check_three(in[i]+2,which);break; } if (ret != NULL) free(ret); check_alloc(ret=(char*)calloc(strlen(in[i]+2)+1,(size_t)1)); strcpy(ret,in[i]+2); in[i]=NULL; } else { in[i]=NULL; i++; if (i < n) { if (in[i] != NULL) { switch(type) { case 'u': check_unsigned(in[i],which);break; case 'd': check_integer(in[i],which);break; case 'f': check_float(in[i],which);break; case '2': check_two(in[i],which);break; case '3': check_three(in[i]+2,which);break; case 'o': ok=check_optional(in[i],which);break; } if (ok) { if (ret != NULL) free(ret); check_alloc(ret=(char*)calloc(strlen(in[i])+1,(size_t)1)); strcpy(ret,in[i]); in[i]=NULL; } else { i--; if (ret != NULL) free(ret); ret=NULL; } } } else { if (ret != NULL) { free(ret); ret=NULL; } } } } else { in[i]=NULL; } } } } if (((type == 'o') || (type == 'n')) && (ret == NULL) && wasfound) return ""; if (wasfound && (ret == NULL)) { fprintf(stderr,"The option -%c needs some value. Exiting!\n",which); exit(CHECK_OPTION_C_NO_VALUE); } return ret; }