#ifndef __args_h__
#define __args_h__
+#ifndef NO_ARGPARSER
+
extern int args_callback_option(char*,char*);
extern int args_callback_longoption(char*,char*);
extern int args_callback_command(char*,char*);
//int argn;
//char**argv;
-void processargs(int argn2,char**argv2)
+static void processargs(int argn2,char**argv2)
{
int t;
if(argn2==1)
if(t<argn2-1) next=argv2[t+1];
else next=0;
- if(argv2[t][0]=='-')
+ if(argv2[t][0]=='-' && argv2[t][1])
{
if(argv2[t][1]=='-')
{
s++;
} while(!ret);
}
- else // - usually means "read stdout"
- {
- t+=args_callback_option(&argv2[t][1],next);
- }
}
}
else
{
- t+=args_callback_command(argv2[t],next);
+ int num = args_callback_command(argv2[t],next);
+ if(num>2) {
+ fprintf(stderr, "internal error in command line parsing\n");
+ exit(1);
+ }
+ t+=num;
}
}
}
struct options_t
{
- char*shortoption;
- char*longoption;
+ const char*shortoption;
+ const char*longoption;
};
-int args_long2shortoption(struct options_t*options, char*name, char*val)
+static int args_long2shortoption(struct options_t*options, char*name, char*val)
{
char*equal = strchr(name,'=');
if (equal) {
exit(1);
}
+#endif
+
/* 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)
+static char is_in_range(int t, char*irange)
{
char*pos = irange;
char*digits;
return 0;
}
+static char* filename2template(char*filename, int*startindex)
+{
+ int l = strlen(filename);
+ char*newname = (char*)malloc(l+5);
+ /* first look whether the file is already numbered */
+ while(1) {
+ l--;
+ if(l<0 || strchr("0123456789", filename[l]))
+ break;
+ };
+ if(l>=0) {
+ int lastdigit=l;
+ int firstdigit=l;
+ while(firstdigit && strchr("0123456789", filename[firstdigit-1]))
+ firstdigit--;
+ *startindex = atoi(filename+firstdigit);
+ memcpy(newname, filename, firstdigit);
+ sprintf(newname+firstdigit, "%%%dd", lastdigit+1-firstdigit);
+ strcat(newname+firstdigit, filename+lastdigit+1);
+ return newname;
+ }
+ /* if it isn't, try to paste a %d between filename and extension */
+ char*dot = strrchr(filename, '.');
+ if(dot) {
+ int pos = dot-filename;
+ memcpy(newname, filename, pos);
+ newname[pos++] = '.';
+ newname[pos++] = '%';
+ newname[pos++] = 'd';
+ strcpy(newname+pos, dot);
+ *startindex = 1;
+ return newname;
+ }
+ /* if that didn't work either, just append the number at the end */
+ strcpy(newname, filename);
+ strcat(newname, ".%d");
+ *startindex = 1;
+ return newname;
+}
+
#endif //__args_h__