mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-02 22:11:22 +00:00
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:
parent
ad0314d4ef
commit
fd7a90eacb
1 changed files with 26 additions and 28 deletions
|
@ -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];
|
|
||||||
switch (c) {
|
|
||||||
case ' ':
|
|
||||||
if (!quoted) {
|
|
||||||
// ignore whitespace
|
|
||||||
if (p == ' ')
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (word != nil) {
|
|
||||||
[words addObject:word];
|
|
||||||
[word release];
|
|
||||||
|
|
||||||
word = nil;
|
if (c == ' ' && !quoted) {
|
||||||
}
|
// complete the current word, if any.
|
||||||
}
|
if (word != nil) {
|
||||||
break;
|
[words addObject:word];
|
||||||
case '"':
|
[word release];
|
||||||
quoted = !quoted;
|
word = nil;
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
if (p == ' ') {
|
// ignore the space
|
||||||
word = [[NSMutableString alloc] init];
|
continue;
|
||||||
}
|
|
||||||
[word appendFormat:@"%C", c];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
p = c;
|
|
||||||
|
if (c == '"') {
|
||||||
|
quoted = !quoted;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// other characters just get inserted.
|
||||||
|
|
||||||
|
// start a word if needed
|
||||||
|
if (word == nil) {
|
||||||
|
word = [[NSMutableString alloc] init];
|
||||||
|
}
|
||||||
|
[word appendFormat:@"%C", 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;
|
||||||
|
|
Loading…
Reference in a new issue