diff --git a/src/tools/3rdparty/iossim/iphonesimulator.mm b/src/tools/3rdparty/iossim/iphonesimulator.mm
index 17fa45d4193..ccb46614478 100644
--- a/src/tools/3rdparty/iossim/iphonesimulator.mm
+++ b/src/tools/3rdparty/iossim/iphonesimulator.mm
@@ -139,33 +139,33 @@ NSString* FindDeveloperDir() {
return output;
}
- (void) printUsage {
- fprintf(stdout, "Usage: ios-sim [--args ...]\n");
+ fprintf(stdout, "Usage: ios-sim <command> <options> [--args ...]\n");
fprintf(stdout, "\n");
fprintf(stdout, "Commands:\n");
fprintf(stdout, " showsdks List the available iOS SDK versions\n");
- fprintf(stdout, " launch Launch the application at the specified path on the iOS Simulator\n");
+ fprintf(stdout, " launch <application path> Launch the application at the specified path on the iOS Simulator\n");
fprintf(stdout, " start Launch iOS Simulator without an app\n");
fprintf(stdout, "\n");
fprintf(stdout, "Options:\n");
fprintf(stdout, " --version Print the version of ios-sim\n");
- fprintf(stdout, " --developer-path path to the developer directory (in Xcode)");
+ fprintf(stdout, " --developer-path <developerDir> path to the developer directory (in Xcode)");
fprintf(stdout, " --help Show this help text\n");
fprintf(stdout, " --verbose Set the output level to verbose\n");
fprintf(stdout, " --exit Exit after startup\n");
fprintf(stdout, " --wait-for-debugger Wait for debugger to attach\n");
fprintf(stdout, " --debug Attach LLDB to the application on startup\n");
fprintf(stdout, " --use-gdb Use GDB instead of LLDB. (Requires --debug)\n");
- fprintf(stdout, " --sdk The iOS SDK version to run the application on (defaults to the latest)\n");
- fprintf(stdout, " --family The device type that should be simulated (defaults to `iphone')\n");
+ fprintf(stdout, " --sdk <sdkversion> The iOS SDK version to run the application on (defaults to the latest)\n");
+ fprintf(stdout, " --family <device family> The device type that should be simulated (defaults to `iphone')\n");
fprintf(stdout, " --retina Start a retina device\n");
fprintf(stdout, " --tall In combination with --retina flag, start the tall version of the retina device (e.g. iPhone 5 (4-inch))\n");
- fprintf(stdout, " --uuid A UUID identifying the session (is that correct?)\n");
- fprintf(stdout, " --env A plist file containing environment key-value pairs that should be set\n");
+ fprintf(stdout, " --uuid <uuid> A UUID identifying the session (is that correct?)\n");
+ fprintf(stdout, " --env <environment file path> A plist file containing environment key-value pairs that should be set\n");
fprintf(stdout, " --setenv NAME=VALUE Set an environment variable\n");
- fprintf(stdout, " --stdout The path where stdout of the simulator will be redirected to (defaults to stdout of ios-sim)\n");
- fprintf(stdout, " --stderr The path where stderr of the simulator will be redirected to (defaults to stderr of ios-sim)\n");
- fprintf(stdout, " --timeout The timeout time to wait for a response from the Simulator. Default value: 30 seconds\n");
- fprintf(stdout, " --args <...> All following arguments will be passed on to the application\n");
+ fprintf(stdout, " --stdout <stdout file path> The path where stdout of the simulator will be redirected to (defaults to stdout of ios-sim)\n");
+ fprintf(stdout, " --stderr <stderr file path> The path where stderr of the simulator will be redirected to (defaults to stderr of ios-sim)\n");
+ fprintf(stdout, " --timeout <seconds> The timeout time to wait for a response from the Simulator. Default value: 30 seconds\n");
+ fprintf(stdout, " --args <...> All following arguments will be passed on to the application\n");
fflush(stdout);
}
@@ -190,7 +190,7 @@ NSString* FindDeveloperDir() {
- (void)session:(DTiPhoneSimulatorSession *)session didEndWithError:(NSError *)error {
if (verbose) {
- nsprintf(@"Session did end with error %@", error);
+ msgprintf(@"Session did end with error %@", error);
}
if (stderrFileHandle != nil) {
@@ -215,7 +215,7 @@ NSString* FindDeveloperDir() {
if (startOnly && session) {
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/osascript"
arguments:[NSArray arrayWithObjects:@"-e", @"tell application \"iPhone Simulator\" to activate", nil]];
- nsprintf(@"Simulator started (no session)");
+ msgprintf(@"Simulator started (no session)");
[self doExit:EXIT_SUCCESS];
return;
}
@@ -238,13 +238,13 @@ NSString* FindDeveloperDir() {
if (child_pid == 0) {
execvp(args[0], args);
} else if (child_pid < 0) {
- nsprintf(@"Could not start debugger process: %@", errno);
+ msgprintf(@"Could not start debugger process: %d", errno);
[self doExit:EXIT_FAILURE];
return;
}
}
if (verbose) {
- nsprintf(@"Session started");
+ msgprintf(@"Session started");
}
nsprintf(@"%d", pid);
fflush(stdout);
@@ -253,7 +253,7 @@ NSString* FindDeveloperDir() {
return;
}
} else {
- nsprintf(@"Session could not be started: %@", error);
+ msgprintf(@"Session could not be started: %@", [error localizedDescription]);
[self doExit:EXIT_FAILURE];
}
}
@@ -275,9 +275,9 @@ NSString* FindDeveloperDir() {
}
}
if ([notification object] == stdoutFileHandle) {
- printf("%s\n", [str UTF8String]);
+ printf("%s\n", [escapeString(str) UTF8String]);
} else {
- nsprintf(@"%@", str); // handle stderr differently?
+ nsprintf(@"%@", escapeString(str)); // handle stderr differently?
}
fflush(stdout);
}
@@ -286,11 +286,11 @@ NSString* FindDeveloperDir() {
- (void)createStdioFIFO:(NSFileHandle **)fileHandle ofType:(NSString *)type atPath:(NSString **)path {
*path = [NSString stringWithFormat:@"%@/ios-sim-%@-pipe-%d", NSTemporaryDirectory(), type, (int)time(NULL)];
if (mkfifo([*path UTF8String], S_IRUSR | S_IWUSR) == -1) {
- nsprintf(@"Unable to create %@ named pipe `%@'", type, *path);
+ msgprintf(@"Unable to create %@ named pipe `%@'", type, *path);
[self doExit:EXIT_FAILURE];
} else {
if (verbose) {
- nsprintf(@"Creating named pipe at `%@'", *path);
+ msgprintf(@"Creating named pipe at `%@'", *path);
}
int fd = open([*path UTF8String], O_RDONLY | O_NDELAY);
*fileHandle = [[[NSFileHandle alloc] initWithFileDescriptor:fd] retain];
@@ -305,12 +305,12 @@ NSString* FindDeveloperDir() {
- (void)removeStdioFIFO:(NSFileHandle *)fileHandle atPath:(NSString *)path {
if (verbose) {
- nsprintf(@"Removing named pipe at `%@'", path);
+ msgprintf(@"Removing named pipe at `%@'", path);
}
[fileHandle closeFile];
[fileHandle release];
if (![[NSFileManager defaultManager] removeItemAtPath:path error:NULL]) {
- nsprintf(@"Unable to remove named pipe `%@'", path);
+ msgprintf(@"Unable to remove named pipe `%@'", path);
}
}
@@ -329,7 +329,7 @@ NSString* FindDeveloperDir() {
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
if (!startOnly && ![fileManager fileExistsAtPath:path]) {
- nsprintf(@"Application path %@ doesn't exist!", path);
+ msgprintf(@"Application path %@ doesn't exist!", path);
return EXIT_FAILURE;
}
@@ -337,11 +337,11 @@ NSString* FindDeveloperDir() {
appSpec = startOnly ? nil : [[self FindClassByName:@"DTiPhoneSimulatorApplicationSpecifier"] specifierWithApplicationPath:path];
if (verbose) {
- nsprintf(@"App Spec: %@", appSpec);
- nsprintf(@"SDK Root: %@", sdkRoot);
+ msgprintf(@"App Spec: %@", appSpec);
+ msgprintf(@"SDK Root: %@", sdkRoot);
for (id key in environment) {
- nsprintf(@"Env: %@ = %@", key, [environment objectForKey:key]);
+ msgprintf(@"Env: %@ = %@", key, [environment objectForKey:key]);
}
}
@@ -413,7 +413,7 @@ NSString* FindDeveloperDir() {
}
if (![session requestStartWithConfig:config timeout:timeout error:&error]) {
- nsprintf(@"Could not start simulator session: %@", error);
+ msgprintf(@"Could not start simulator session: %@", error);
return EXIT_FAILURE;
}
@@ -424,7 +424,7 @@ NSString* FindDeveloperDir() {
NSString *devicePropertyValue;
if (retina) {
if (verbose) {
- nsprintf(@"using retina");
+ msgprintf(@"using retina");
}
if ([family isEqualToString:@"ipad"]) {
devicePropertyValue = deviceIpadRetina;
@@ -496,7 +496,7 @@ NSString* FindDeveloperDir() {
exit([self showSDKs]);
} else if (strcmp(argv[1], "launch") == 0 || startOnly) {
if (strcmp(argv[1], "launch") == 0 && argc < 3) {
- nsprintf(@"Missing application path argument");
+ msgprintf(@"Missing application path argument");
[self printUsage];
exit(EXIT_FAILURE);
}
@@ -560,7 +560,7 @@ NSString* FindDeveloperDir() {
}
}
if (sdkRoot == nil) {
- fprintf(stdout,"Unknown or unsupported SDK version: %s\n",argv[i]);
+ msgprintf(@"Unknown or unsupported SDK version: %s\n",argv[i]);
[self showSDKs];
exit(EXIT_FAILURE);
}
@@ -579,7 +579,7 @@ NSString* FindDeveloperDir() {
NSString *envFilePath = [[NSString stringWithUTF8String:argv[i]] expandPath];
[environment setValuesForKeysWithDictionary:[NSDictionary dictionaryWithContentsOfFile:envFilePath]];
if (!environment) {
- fprintf(stdout, "Could not read environment from file: %s\n", argv[i]);
+ msgprintf(@"Could not read environment from file: %s", argv[i]);
[self printUsage];
exit(EXIT_FAILURE);
}
@@ -603,7 +603,7 @@ NSString* FindDeveloperDir() {
i++;
break;
} else {
- fprintf(stdout, "unrecognized argument:%s\n", argv[i]);
+ msgprintf(@"unrecognized argument:%s", argv[i]);
[self printUsage];
[self doExit:EXIT_FAILURE];
return;
diff --git a/src/tools/3rdparty/iossim/nsprintf.h b/src/tools/3rdparty/iossim/nsprintf.h
index cee7c00d289..0f108a57d57 100644
--- a/src/tools/3rdparty/iossim/nsprintf.h
+++ b/src/tools/3rdparty/iossim/nsprintf.h
@@ -4,3 +4,6 @@
int nsvfprintf (FILE *stream, NSString *format, va_list args);
int nsfprintf (FILE *stream, NSString *format, ...);
int nsprintf (NSString *format, ...);
+int msgvfprintf (FILE *stream, NSString *format, va_list args);
+int msgprintf (NSString *format, ...);
+NSString *escapeString(NSString *origString);
diff --git a/src/tools/3rdparty/iossim/nsprintf.mm b/src/tools/3rdparty/iossim/nsprintf.mm
index 95c12c785fd..b497d0bb72b 100644
--- a/src/tools/3rdparty/iossim/nsprintf.mm
+++ b/src/tools/3rdparty/iossim/nsprintf.mm
@@ -42,3 +42,34 @@ int nsprintf (NSString *format, ...) {
return retval;
}
+
+NSString *escapeString(NSString *origString)
+{
+ return [[[[origString stringByReplacingOccurrencesOfString: @"&" withString: @"&"]
+ stringByReplacingOccurrencesOfString: @"\"" withString: @"""]
+ stringByReplacingOccurrencesOfString: @">" withString: @">"]
+ stringByReplacingOccurrencesOfString: @"<" withString: @"<"];
+}
+
+int msgvfprintf (FILE *stream, NSString *format, va_list args) {
+ int retval;
+
+ NSString *str = (NSString *) CFStringCreateWithFormatAndArguments(NULL, NULL, (CFStringRef) format, args);
+ retval = fprintf(stream, "%s\n", [escapeString(str) UTF8String]);
+ [str release];
+
+ return retval;
+}
+
+int msgprintf(NSString *format, ...) {
+ va_list ap;
+ int retval;
+
+ va_start(ap, format);
+ {
+ retval = msgvfprintf(stdout, format, ap);
+ }
+ va_end(ap);
+
+ return retval;
+}