#include "argument.h" #include "console.h" /* formatarg: 01) remove prepended spaces 02) get command (first space) and lowercase 03) get arguments 04) remove double quotes (from arguments) 05) temp. remove double backslash 06) remove prepended/appended non-escaped commas and spaces (from arguments) a) prepended b) appended 07) get quote count, ignore escaped (from arguments) 08) process quotes (from arguments): a) zero quotes b) restore double backslash c) escape commas and spaces 09) temp. remove double backslash 10) remove unescaped double commas (from arguments) 11) remove unescaped spaces (from arguments) 12) restore double backslash 13) combine formatted arguments and command */ void argformat(char* cmd) { if(strlen(cmd)>=deflen) return; char command_[deflen]=""; char* command=command_; strcpy(command, cmd); while(*command==' ') command++; int len=strlen(command); int start=0; for(int i=0; i=deflen) return -1; int arg_count=0; int start=0; while(cmd[start]!=' ' and start=deflen) return false; int argcount=arggetcount(cmd); if((arg_num+1)>argcount) { if(!optional) dprintf("missing argument nr %d\n", arg_num+1); return false; } int len=strlen(cmd); int start=0; while(cmd[start]!=' ') start++; while(cmd[start]==' ') start++; char temp[deflen]=""; strcpy(temp, cmd+start); len=strlen(temp); for(int i=0; i