macOS launcher: fix parsing of quotes in the args text box

e.g. entering
  -basedir "/Users/ericwa/my games/quake" -game xyz
didn't work

git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1475 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Eric Wasylishen 2017-08-14 00:42:14 +00:00
parent ad0314d4ef
commit fd7a90eacb

View file

@ -67,8 +67,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- (void)parseArguments:(NSString *)args { - (void)parseArguments:(NSString *)args {
int i; int i;
unichar c;
unichar p = ' ';
NSMutableString *word = nil; NSMutableString *word = nil;
NSMutableArray *words = [[NSMutableArray alloc] init]; NSMutableArray *words = [[NSMutableArray alloc] init];
BOOL quoted = FALSE; BOOL quoted = FALSE;
@ -76,39 +74,39 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
[quakeArgs removeAllObjects]; [quakeArgs removeAllObjects];
for (i = 0; i < [args length]; i++) { for (i = 0; i < [args length]; i++) {
const unichar c = [args characterAtIndex:i];
c = [args characterAtIndex:i]; if (c == ' ' && !quoted) {
switch (c) { // complete the current word, if any.
case ' ':
if (!quoted) {
// ignore whitespace
if (p == ' ')
break;
if (word != nil) { if (word != nil) {
[words addObject:word]; [words addObject:word];
[word release]; [word release];
word = nil; word = nil;
} }
// ignore the space
continue;
} }
break;
case '"': if (c == '"') {
quoted = !quoted; quoted = !quoted;
break; continue;
default: }
if (p == ' ') {
// other characters just get inserted.
// start a word if needed
if (word == nil) {
word = [[NSMutableString alloc] init]; word = [[NSMutableString alloc] init];
} }
[word appendFormat:@"%C", c]; [word appendFormat:@"%C", c];
break;
}
p = c;
} }
// complete the current word, if any
if (word != nil) { if (word != nil) {
[words addObject:word]; [words addObject:word];
[word release]; [word release];
word = nil;
} }
NSString *current; NSString *current;