diff --git a/Tools/SOGoTool.h b/Tools/SOGoTool.h index 30613c834..bbc4de098 100644 --- a/Tools/SOGoTool.h +++ b/Tools/SOGoTool.h @@ -31,6 +31,7 @@ { BOOL verbose; NSArray *arguments; + NSArray *sanitizedArguments; /* arguments w/o args from NSArgumentDomain */ } + (NSString *) command; @@ -40,6 +41,7 @@ verbose: (BOOL) isVerbose; - (void) setArguments: (NSArray *) newArguments; +- (void) setSanitizedArguments: (NSArray *) newArguments; - (void) setVerbose: (BOOL) newVerbose; - (BOOL) run; diff --git a/Tools/SOGoTool.m b/Tools/SOGoTool.m index 602fcf04d..9a56debee 100644 --- a/Tools/SOGoTool.m +++ b/Tools/SOGoTool.m @@ -21,7 +21,9 @@ */ #import +#import #import +#import #import "SOGoTool.h" @@ -49,6 +51,7 @@ [instance autorelease]; [instance setArguments: toolArguments]; + [instance setSanitizedArguments: toolArguments]; [instance setVerbose: isVerbose]; return [instance run]; @@ -59,6 +62,7 @@ if ((self = [super init])) { arguments = nil; + sanitizedArguments = nil; verbose = NO; } @@ -70,6 +74,44 @@ ASSIGN (arguments, newArguments); } +- (void) setSanitizedArguments: (NSArray *) newArguments +{ + NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet]; + NSString *argsString = [newArguments componentsJoinedByString:@" "]; + NSDictionary *cliArguments; + + /* Remove NSArgumentDomain -key value from the arguments */ + cliArguments = [[NSUserDefaults standardUserDefaults] + volatileDomainForName:NSArgumentDomain]; + for (NSString *k in cliArguments) + { + NSString *v = [cliArguments objectForKey:k]; + NSString *argPair = [NSString stringWithFormat:@"-%@ %@", k, v]; + argsString = [argsString stringByReplacingOccurrencesOfString: argPair + withString: @""]; + } + if ([argsString length]) + { + /* dance to compact whitespace */ + NSArray *wordsWP = [argsString componentsSeparatedByCharactersInSet: whitespaces]; + NSMutableArray *words = [NSMutableArray array]; + for (NSString *word in wordsWP) + { + if([word length] > 1) + { + [words addObject:word]; + } + } + argsString = [words componentsJoinedByString:@" "]; + ASSIGN (sanitizedArguments, [argsString componentsSeparatedByString:@" "]); + } + else + { + ASSIGN (sanitizedArguments, nil); + } + +} + - (void) setVerbose: (BOOL) newVerbose { verbose = newVerbose;