X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fargs.h;h=ac8586c5ab7ab7dc96af31cd76c6590b2bd796e7;hp=cc9a58d3f300142bbb7f738126de510171f77b61;hb=ede90e3f60487332bcaede6d8f62ad0f3e0fb715;hpb=9d85e6224fa9ac5b4c54e7af8ea3b7c9271c2680 diff --git a/lib/args.h b/lib/args.h index cc9a58d..ac8586c 100644 --- a/lib/args.h +++ b/lib/args.h @@ -4,8 +4,20 @@ Part of the swftools package. Copyright (c) 2001 Matthias Kramm + + This program 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. - This file is distributed under the GPL, see file COPYING for details */ + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __args_h__ #define __args_h__ @@ -15,48 +27,69 @@ extern int args_callback_longoption(char*,char*); extern int args_callback_command(char*,char*); extern void args_callback_usage(char*name); -int argn; -char**argv; +//int argn; +//char**argv; void processargs(int argn2,char**argv2) { int t; if(argn2==1) { - args_callback_usage(argv2[0]); - exit(1); + args_callback_usage(argv2[0]); + exit(1); } for(t=1;tshortoption) { if(!strcmp(options->longoption, name)) { - char*tmp = (char*)malloc(strlen(options->shortoption) - +(equal?strlen(equal)+2:2)); - strcpy(tmp, options->shortoption); - if(equal) { - //strcpy(&tmp[strlen(tmp)], equal); - int ret = args_callback_option(tmp, equal); - return 0; - } - return args_callback_option(tmp,val); - } - options++; + char*tmp = (char*)malloc(strlen(options->shortoption) + +(equal?strlen(equal)+2:2)); + strcpy(tmp, options->shortoption); + if(equal) { + //strcpy(&tmp[strlen(tmp)], equal); + int ret = args_callback_option(tmp, equal); + if(!ret) { + fprintf(stderr, "Warning: Option --%s takes no parameter.\n", name); + } + return 0; + } + return args_callback_option(tmp,val); + } + options++; } fprintf(stderr, "Unknown option: --%s\n", name); exit(1); } +/* check whether the value t is in a given range. + examples: 3 is in range 1-10: true + 7 is in range 2-4,6,8-10: false + 9 is in range 1,2,3-12: true +*/ +char is_in_range(int t, char*irange) +{ + char*pos = irange; + char*digits; + int num; + char range = 0; + int last=0; + char tmp; + + if(!irange) // no range resembles (-OO,OO) + return 1; + + while(*pos) + { + while(*pos == ' ' || *pos == '\r' || *pos == '\n' || *pos == '\t') + pos++; + + digits = pos; + while(*digits>='0' && *digits<='9') + digits++; + if(digits == pos) { + fprintf(stderr, "Error: \"%s\" is not a valid format (digit expected)\n",irange); + exit(1); + } + + tmp=*digits;*digits=0; + num = atoi(pos); + *digits=tmp; + pos = digits; + + while(*pos == ' ' || *pos == '\r' || *pos == '\n' || *pos == '\t') + pos++; + + if(range && last<=t && num>=t) + return 1; + if(range) { + range = 0; + if(*pos) + pos ++; + continue; + } + + if(*pos=='-') + { + if(range) { + fprintf(stderr, "Error: \"%s\" is not a valid format (too many '-'s)\n",irange); + exit(1); + } + last = num; + range = 1; + if(*pos) + pos ++; + continue; + } + else + { + /* if it isn't a '-', we assume it is a seperator like + ',', ';', ':', whatever. */ + if(t == num) + return 1; + if(*pos) + pos ++; + continue; + } + } + if(range && last<=t) + return 1; + return 0; +} + #endif //__args_h__