Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
111 lines (92 sloc) 3.7 KB
#import <AppKit/AppKit.h>
#import "iPhoneSimulatorRemoteClient.h"
#import "Simulator.h"
#import "termios.h"
static BOOL gReset = false;
void printUsage();
void simulate(NSString *sdk, NSString *family, NSString *appPath, NSDictionary *environment, NSArray *additionalArgs);
void resetSignal(int sig);
int main(int argc, char *argv[]) {
signal(SIGQUIT, resetSignal);
int c;
char *sdk = nil;
char *family = nil;
char *appPath = nil;
NSMutableArray *additionalArgs = [NSMutableArray array];
NSMutableDictionary *environment = [NSMutableDictionary dictionary];
NSString *environment_variable;
NSArray *environment_variable_parts;
while ((c = getopt(argc, argv, "e:s:f:ah")) != -1) {
switch(c) {
case 'e':
environment_variable = [NSString stringWithCString:optarg encoding:NSUTF8StringEncoding];
environment_variable_parts = [environment_variable componentsSeparatedByString:@"="];
[environment setObject:[environment_variable_parts objectAtIndex:1] forKey:[environment_variable_parts objectAtIndex:0]];
case 's':
sdk = optarg;
case 'f':
family = optarg;
case 'a':
fprintf(stdout, "Available SDK Versions.\n", optopt);
for (NSString *sdkVersion in [Simulator availableSDKs]) {
fprintf(stderr, " %s\n", [sdkVersion UTF8String]);
return 1;
case 'h':
return 1;
case '?':
if (optopt == 's' || optopt == 'f') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
return 1;
abort ();
if (argc > optind) {
appPath = argv[optind++];
// Additional args are sent to app
for (int i = optind; i < argc; i++) {
[additionalArgs addObject:[NSString stringWithUTF8String:argv[i]]];
else {
fprintf(stderr, "No app-path was specified!\n");
return 1;
NSString *sdkString = sdk ? [NSString stringWithUTF8String:sdk] : nil;
NSString *familyString = family ? [NSString stringWithUTF8String:family] : nil;
NSString *appPathString = [NSString stringWithUTF8String:appPath];
simulate(sdkString, familyString, appPathString, environment, additionalArgs);
return 0;
void simulate(NSString *sdk, NSString *family, NSString *appPath, NSDictionary *environment, NSArray *additionalArgs) {
Simulator *simulator = [[Simulator alloc] initWithAppPath:appPath sdk:sdk family:family env:environment args:additionalArgs];
[simulator launch];
while (!gReset && [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:-1]]) ;
[simulator end];
void printUsage() {
fprintf(stderr, "usage: waxsim [options] app-path\n");
fprintf(stderr, "example: waxsim -s 2.2 /path/to/\n");
fprintf(stderr, "Available options are:\n");
fprintf(stderr, "\t-s sdk\tVersion number of sdk to use (-s 3.1)\n");
fprintf(stderr, "\t-f family\tDevice to use (-f ipad)\n");
fprintf(stderr, "\t-e VAR=value\tEnvironment variable to set (-e CFFIXED_HOME=/tmp/iphonehome)\n");
fprintf(stderr, "\t-a \tAvailable SDK's\n");
fprintf(stderr, "\t-h \tPrints out this wonderful documentation!\n");
void resetSignal(int sig) {
gReset = true;