Skip to content

Commit

Permalink
Merge branch 'macos-non-ascii-fix' into buildports7-tads203
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Plotkin committed Apr 5, 2017
2 parents 9381ae5 + 105c4f1 commit 69830a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 64 deletions.
31 changes: 11 additions & 20 deletions garglk/launchmac.m
Expand Up @@ -460,7 +460,7 @@ - (NSString *) openFileDialog: (NSString *) prompt
if (filter != FILTER_ALL)
{
NSArray * filterTypes = [NSArray arrayWithObject: [NSString stringWithCString: winfilters[filter]
encoding: NSASCIIStringEncoding]];
encoding: NSUTF8StringEncoding]];
[openDlg setAllowedFileTypes: filterTypes];
[openDlg setAllowsOtherFileTypes: NO];
result = [openDlg runModalForDirectory: NULL file: NULL types: filterTypes];
Expand Down Expand Up @@ -489,7 +489,7 @@ - (NSString *) saveFileDialog: (NSString *) prompt
if (filter != FILTER_ALL)
{
NSArray * filterTypes = [NSArray arrayWithObject: [NSString stringWithCString: winfilters[filter]
encoding: NSASCIIStringEncoding]];
encoding: NSUTF8StringEncoding]];
[saveDlg setAllowedFileTypes: filterTypes];
[saveDlg setAllowsOtherFileTypes: NO];
}
Expand Down Expand Up @@ -550,12 +550,7 @@ - (id) init
/* set environment variable */
NSString * nsResources = [[NSBundle mainBundle] resourcePath];

int size = [nsResources length];
CFStringGetBytes((CFStringRef) nsResources, CFRangeMake(0, size),
kCFStringEncodingASCII, 0, FALSE,
etc, MaxBuffer, NULL);
int bounds = size < MaxBuffer ? size : MaxBuffer;
etc[bounds] = '\0';
[nsResources getCString: etc maxLength: sizeof etc encoding: NSUTF8StringEncoding];

setenv("GARGLK_INI", etc, TRUE);

Expand Down Expand Up @@ -785,7 +780,7 @@ - (BOOL) launchFileDialog
[openDlg setCanChooseFiles: YES];
[openDlg setCanChooseDirectories: NO];
[openDlg setAllowsMultipleSelection: NO];
[openDlg setTitle: [NSString stringWithCString: AppName encoding: NSASCIIStringEncoding]];
[openDlg setTitle: [NSString stringWithCString: AppName encoding: NSUTF8StringEncoding]];

NSMutableArray *filterTypes = [NSMutableArray arrayWithCapacity:100];

Expand Down Expand Up @@ -817,12 +812,8 @@ - (BOOL) launchFile: (NSString *) file
winpath(dir);

/* get story file */
int size = [file length];
CFStringGetBytes((CFStringRef) file, CFRangeMake(0, size),
kCFStringEncodingASCII, 0, FALSE,
buf, MaxBuffer, NULL);
int bounds = size < MaxBuffer ? size : MaxBuffer;
buf[bounds] = '\0';
if (![file getCString: buf maxLength: sizeof buf encoding: NSUTF8StringEncoding])
return NO;

/* run story file */
int ran = rungame(dir, buf);
Expand Down Expand Up @@ -870,7 +861,7 @@ - (void) openURL: (NSAppleEventDescriptor *) event withReplyEvent: (NSAppleEvent
if (urlParts && [urlParts count] == 2)
{
openedFirstGame = YES;
NSString * game = [[urlParts objectAtIndex: 1] stringByReplacingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSString * game = [[urlParts objectAtIndex: 1] stringByRemovingPercentEncoding];

if ([[NSFileManager defaultManager] fileExistsAtPath: game] == YES)
[self launchFile: game];
Expand Down Expand Up @@ -930,7 +921,7 @@ - (IBAction) toggle: (id) sender

void winmsg(const char *msg)
{
NSString * nsMsg = [NSString stringWithCString: msg encoding: NSASCIIStringEncoding];
NSString * nsMsg = [NSString stringWithCString: msg encoding: NSUTF8StringEncoding];
NSRunAlertPanel(@"Fatal error", @"%@", nil, nil, nil, nsMsg);
}

Expand Down Expand Up @@ -960,7 +951,7 @@ int winexec(const char *cmd, char **args)
NSTask * proc = [[NSTask alloc] init];

/* prepare interpreter path */
NSArray * nsArray = [[NSString stringWithCString: cmd encoding: NSASCIIStringEncoding] componentsSeparatedByString: @"/"];
NSArray * nsArray = [[NSString stringWithCString: cmd encoding: NSUTF8StringEncoding] componentsSeparatedByString: @"/"];
NSString * nsTerp = [nsArray objectAtIndex: [nsArray count] - 1];
NSString * nsCmd = [NSString stringWithFormat: @"%@/%@", [[NSBundle mainBundle] builtInPlugInsPath], nsTerp];

Expand All @@ -972,10 +963,10 @@ int winexec(const char *cmd, char **args)
[nsEnv setObject: [NSString stringWithFormat: @"com.googlecode.garglk-%04x", getpid()] forKey: @"GargoyleApp"];

if (args[1])
[nsArgs addObject: [[NSString alloc] initWithCString: args[1] encoding: NSASCIIStringEncoding]];
[nsArgs addObject: [[NSString alloc] initWithCString: args[1] encoding: NSUTF8StringEncoding]];

if (args[2])
[nsArgs addObject: [[NSString alloc] initWithCString: args[2] encoding: NSASCIIStringEncoding]];
[nsArgs addObject: [[NSString alloc] initWithCString: args[2] encoding: NSUTF8StringEncoding]];

if ([nsCmd length] && [nsArgs count])
{
Expand Down
73 changes: 29 additions & 44 deletions garglk/sysmac.m
Expand Up @@ -32,12 +32,6 @@
#import "Cocoa/Cocoa.h"
#import "sysmac.h"

#ifdef __ppc__
#define ByteOrderUCS4 kCFStringEncodingUTF32
#else
#define ByteOrderUCS4 kCFStringEncodingUTF32LE
#endif

static volatile int gli_event_waiting = FALSE;
static volatile int gli_mach_allowed = FALSE;
static volatile int gli_window_alive = TRUE;
Expand Down Expand Up @@ -160,7 +154,7 @@ void winabort(const char *fmt, ...)

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[gargoyle abortWindowDialog: processID
prompt: [NSString stringWithCString: buf encoding: NSASCIIStringEncoding]];
prompt: [NSString stringWithCString: buf encoding: NSUTF8StringEncoding]];
[pool drain];

exit(1);
Expand All @@ -177,21 +171,14 @@ void winopenfile(char *prompt, char *buf, int len, int filter)
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString * fileref = [gargoyle openWindowDialog: processID
prompt: [NSString stringWithCString: prompt encoding: NSASCIIStringEncoding]
prompt: [NSString stringWithCString: prompt encoding: NSUTF8StringEncoding]
filter: filter];

strcpy(buf, "");

if (fileref)
{
int size = [fileref length];

CFStringGetBytes((CFStringRef) fileref, CFRangeMake(0, size),
kCFStringEncodingASCII, 0, FALSE,
buf, len, NULL);

int bounds = size < len ? size : len;
buf[bounds] = '\0';
[fileref getCString: buf maxLength: len encoding: NSUTF8StringEncoding];
}

[pool drain];
Expand All @@ -202,21 +189,14 @@ void winsavefile(char *prompt, char *buf, int len, int filter)
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString * fileref = [gargoyle saveWindowDialog: processID
prompt: [NSString stringWithCString: prompt encoding: NSASCIIStringEncoding]
prompt: [NSString stringWithCString: prompt encoding: NSUTF8StringEncoding]
filter: filter];

strcpy(buf, "");

if (fileref)
{
int size = [fileref length];

CFStringGetBytes((CFStringRef) fileref, CFRangeMake(0, size),
kCFStringEncodingASCII, 0, FALSE,
buf, len, NULL);

int bounds = size < len ? size : len;
buf[bounds] = '\0';
[fileref getCString: buf maxLength: len encoding: NSUTF8StringEncoding];
}

[pool drain];
Expand All @@ -229,12 +209,12 @@ void winclipstore(glui32 *text, int len)

if (cliptext) {
[cliptext release];
cliptext = NULL;
cliptext = nil;
}

cliptext = (NSString *) CFStringCreateWithBytes(kCFAllocatorDefault,
(char *) text, (len * 4),
ByteOrderUCS4, FALSE);
cliptext = [[NSString string] initWithBytes: text
length: (len * sizeof(glui32))
encoding: NSUTF32StringEncoding];
}

void winclipsend(void)
Expand Down Expand Up @@ -262,9 +242,11 @@ void winclipreceive(void)
len = [input length];
for (i=0; i < len; i++)
{
if (CFStringGetBytes((CFStringRef) input, CFRangeMake(i, 1),
kCFStringEncodingUTF32, 0, FALSE,
(char *) &ch, 4, NULL))
if ([input getBytes: &ch maxLength: sizeof ch usedLength: NULL
encoding: NSUTF32StringEncoding
options: 0
range: NSMakeRange(i, 1)
remainingRange: NULL])
{
switch (ch)
{
Expand All @@ -290,16 +272,17 @@ void wintitle(void)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

char buf[256];
NSString * story_title = [NSString stringWithCString: gli_story_title encoding: NSUTF8StringEncoding];
NSString * story_name = [NSString stringWithCString: gli_story_name encoding: NSUTF8StringEncoding];
NSString * program_name = [NSString stringWithCString: gli_program_name encoding: NSUTF8StringEncoding];

if (strlen(gli_story_title))
sprintf(buf, "%s", gli_story_title);
else if (strlen(gli_story_name))
sprintf(buf, "%s - %s", gli_story_name, gli_program_name);
NSString * title = nil;
if ([story_title length])
title = story_title;
else if ([story_name length])
title = [NSString stringWithFormat: @"%@ - %@", story_name, program_name];
else
sprintf(buf, "%s", gli_program_name);

NSString * title = [NSString stringWithCString: buf encoding: NSASCIIStringEncoding];
title = program_name;

[gargoyle setWindow: processID
title: title];
Expand Down Expand Up @@ -531,10 +514,12 @@ void winkey(NSEvent *evt)

/* convert character to UTF-32 value */
glui32 ch;
if (CFStringGetBytes((CFStringRef) evt_char,
CFRangeMake(0, [evt_char length]),
kCFStringEncodingUTF32, 0, FALSE,
(char *)&ch, 4, NULL)) {
if ([evt_char getBytes: &ch maxLength: sizeof ch usedLength: NULL
encoding: NSUTF32StringEncoding
options: 0
range: NSMakeRange(0, [evt_char length])
remainingRange: NULL])
{
switch (ch)
{
case '\n': gli_input_handle_key(keycode_Return); break;
Expand Down

0 comments on commit 69830a0

Please sign in to comment.