# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1614875635 0 # Node ID 5ddc447fb367484669b064a0f7b26509d2ac8725 # Parent 123e22827a828f9c9de5ebd60607376230296faa Mac: Partial rewrite of dw_exect(). Implement DW_EXEC_CON with Terminal.app. Previously we had been using xterm, which hasn't been included MacOS since 10.7 (Lion). Also, rewrite the DW_EXEC_GUI to allow more than one file to open. diff -r 123e22827a82 -r 5ddc447fb367 mac/dw.m --- a/mac/dw.m Thu Mar 04 12:32:56 2021 +0000 +++ b/mac/dw.m Thu Mar 04 16:33:55 2021 +0000 @@ -12756,18 +12756,25 @@ if(params && params[0] && params[1]) { - NSString *file = [NSString stringWithUTF8String:params[1]]; - #ifdef BUILDING_FOR_CATALINA if(@available(macOS 10.15, *)) { NSURL *url = _dw_url_from_program(nsprogram, ws); - NSURL *nsfile = [NSURL fileURLWithPath:file]; - - [ws openURLs:[NSArray arrayWithObjects:nsfile, nil] - withApplicationAtURL:url - configuration:[NSWorkspaceOpenConfiguration configuration] - completionHandler:^(NSRunningApplication *app, NSError *error) { + NSMutableArray *array = [[NSMutableArray alloc] init]; + int z = 1; + + while(params[z]) + { + NSString *thisfile = [NSString stringWithUTF8String:params[z]]; + NSURL *nsfile = [NSURL fileURLWithPath:thisfile]; + + [array addObject:nsfile]; + z++; + } + + [ws openURLs:array withApplicationAtURL:url + configuration:[NSWorkspaceOpenConfiguration configuration] + completionHandler:^(NSRunningApplication *app, NSError *error) { if(error) NSLog(@"openURLs: %@", [error localizedDescription]); }]; @@ -12779,8 +12786,16 @@ if([ws respondsToSelector:sofwa]) { - DWIMP iofwa = (DWIMP)[ws methodForSelector:sofwa]; - iofwa(ws, sofwa, file, nsprogram); + int z = 1; + + while(params[z]) + { + NSString *file = [NSString stringWithUTF8String:params[z]]; + DWIMP iofwa = (DWIMP)[ws methodForSelector:sofwa]; + + iofwa(ws, sofwa, file, nsprogram); + z++; + } } } } @@ -12810,50 +12825,50 @@ } } } - return DW_ERROR_NONE; - } - - if((ret = fork()) == 0) - { - int i; - - for (i = 3; i < 256; i++) - close(i); - setsid(); - - if(type == DW_EXEC_CON) - { - char **tmpargs; - - if(!params) - { - tmpargs = malloc(sizeof(char *)); - tmpargs[0] = NULL; - } - else - { - int z = 0; - - while(params[z]) - { - z++; - } - tmpargs = malloc(sizeof(char *)*(z+3)); - z=0; - tmpargs[0] = "xterm"; - tmpargs[1] = "-e"; - while(params[z]) - { - tmpargs[z+2] = params[z]; - z++; - } - tmpargs[z+2] = NULL; - } - execvp("xterm", tmpargs); - free(tmpargs); - } - /* If we got here exec failed */ - _exit(-1); + ret = DW_ERROR_NONE; + } + else + { + /* Use AppleScript to Open Terminal.app or contact an existing copy, + * and execute the command passed in params[]. + */ + char *commandline; + char *format = "osascript -e \'tell app \"Terminal\" to do script \""; + int len = (int)strlen(format) + 3; + + /* Generate a command line from the parameters */ + if(params && *params) + { + int z = 0; + + while(params[z]) + { + len+=strlen(params[z]) + 1; + z++; + } + z=1; + commandline = calloc(1, len); + strcpy(commandline, format); + strcat(commandline, params[0]); + while(params[z]) + { + strcat(commandline, " "); + strcat(commandline, params[z]); + z++; + } + } + else + { + len += strlen(program); + commandline = calloc(1, len); + strcpy(commandline, format); + strcat(commandline, program); + } + strcat(commandline, "\"\'"); + + /* Attempt to execute the commmand, DW_ERROR_NONE on success */ + if(system(commandline) != -1) + ret = DW_ERROR_NONE; } return ret; }