Index: src/Command.mm ================================================================== --- src/Command.mm +++ src/Command.mm @@ -1,8 +1,24 @@ #import "Command.h" #include + +static OFArray * +padArguments(OFArray *arguments, size_t count) +{ + OFMutableArray *copy; + + if (arguments.count >= count) + return arguments; + + copy = [arguments mutableCopy]; + while (copy.count < count) + [copy addObject:@""]; + + [copy makeImmutable]; + return copy; +} @implementation Command - (instancetype)initWithName:(OFString *)name function:(void (*)())function argumentsTypes:(int)argumentsTypes @@ -17,87 +33,112 @@ - (int)callWithArguments:(OFArray *)arguments isDown:(bool)isDown { switch (_argumentsTypes) { case ARG_1INT: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 2); ((void(__cdecl *)(int))_function)( (int)[arguments[1] longLongValueWithBase:0]); + } break; case ARG_2INT: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 3); ((void(__cdecl *)(int, int))_function)( (int)[arguments[1] longLongValueWithBase:0], (int)[arguments[2] longLongValueWithBase:0]); + } break; case ARG_3INT: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 4); ((void(__cdecl *)(int, int, int))_function)( (int)[arguments[1] longLongValueWithBase:0], (int)[arguments[2] longLongValueWithBase:0], (int)[arguments[3] longLongValueWithBase:0]); + } break; case ARG_4INT: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 5); ((void(__cdecl *)(int, int, int, int))_function)( (int)[arguments[1] longLongValueWithBase:0], (int)[arguments[2] longLongValueWithBase:0], (int)[arguments[3] longLongValueWithBase:0], (int)[arguments[4] longLongValueWithBase:0]); + } break; case ARG_NONE: if (isDown) ((void(__cdecl *)())_function)(); break; case ARG_1STR: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 2); ((void(__cdecl *)(OFString *))_function)(arguments[1]); + } break; case ARG_2STR: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 3); ((void(__cdecl *)(OFString *, OFString *))_function)( arguments[1], arguments[2]); + } break; case ARG_3STR: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 4); ((void(__cdecl *)( OFString *, OFString *, OFString *))_function)( arguments[1], arguments[2], arguments[3]); + } break; case ARG_5STR: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 6); ((void(__cdecl *)(OFString *, OFString *, OFString *, OFString *, OFString *))_function)(arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); + } break; case ARG_DOWN: ((void(__cdecl *)(bool))_function)(isDown); break; case ARG_DWN1: + arguments = padArguments(arguments, 2); ((void(__cdecl *)(bool, OFString *))_function)( isDown, arguments[1]); break; case ARG_1EXP: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 2); return ((int(__cdecl *)(int))_function)( execute(arguments[1])); + } break; case ARG_2EXP: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 3); return ((int(__cdecl *)(int, int))_function)( execute(arguments[1]), execute(arguments[2])); + } break; case ARG_1EST: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 2); return ((int(__cdecl *)(OFString *))_function)( arguments[1]); + } break; case ARG_2EST: - if (isDown) + if (isDown) { + arguments = padArguments(arguments, 3); return ((int(__cdecl *)(OFString *, OFString *))_function)(arguments[1], arguments[2]); + } break; case ARG_VARI: if (isDown) // limit, remove ((void(__cdecl *)(OFString *))_function)([[arguments Index: src/commands.mm ================================================================== --- src/commands.mm +++ src/commands.mm @@ -343,16 +343,18 @@ bool execfile(OFString *cfgfile) { @autoreleasepool { + OFString *command; @try { - execute([OFString stringWithContentsOfFile:cfgfile]); + command = [OFString stringWithContentsOfFile:cfgfile]; } @catch (id e) { return false; } + execute(command); return true; } } void