mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-09-17 04:15:46 +00:00
Merge pull request #239 from mkilgore/fix-macos-escaping
Fix osascript escaping on Mac OS
This commit is contained in:
commit
f5b24dfdc1
1 changed files with 30 additions and 16 deletions
|
@ -4133,6 +4133,20 @@ static void concatAndEscapeSingleQuote(char *dest, const char *source)
|
||||||
tfd_replaceSubStrConCat(source, "'", "'\\''", dest);
|
tfd_replaceSubStrConCat(source, "'", "'\\''", dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Concats the source string to the destination string, and escapes sutable for
|
||||||
|
// osascript run via sh.
|
||||||
|
//
|
||||||
|
// This is achieved by first escaping double quotes, and then escaping single
|
||||||
|
// quotes for bash/sh.
|
||||||
|
static void concatAndEscapeOsascript(char *dest, const char *source)
|
||||||
|
{
|
||||||
|
char tmp[MAX_PATH_OR_CMD] = "\0";
|
||||||
|
|
||||||
|
tfd_replaceSubStrConCat(source, "\"", "\\\"", tmp);
|
||||||
|
|
||||||
|
concatAndEscapeSingleQuote(dest, tmp);
|
||||||
|
}
|
||||||
|
|
||||||
int tinyfd_messageBox(
|
int tinyfd_messageBox(
|
||||||
char const * aTitle , /* NULL or "" */
|
char const * aTitle , /* NULL or "" */
|
||||||
char const * aMessage , /* NULL or "" may contain \n and \t */
|
char const * aMessage , /* NULL or "" may contain \n and \t */
|
||||||
|
@ -4171,13 +4185,13 @@ int tinyfd_messageBox(
|
||||||
strcat( lDialogString , " -e 'try' -e 'set {vButton} to {button returned} of ( display dialog \"") ;
|
strcat( lDialogString , " -e 'try' -e 'set {vButton} to {button returned} of ( display dialog \"") ;
|
||||||
if ( aMessage && strlen(aMessage) )
|
if ( aMessage && strlen(aMessage) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, aMessage) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, aMessage) ;
|
||||||
}
|
}
|
||||||
strcat(lDialogString, "\" ") ;
|
strcat(lDialogString, "\" ") ;
|
||||||
if ( aTitle && strlen(aTitle) )
|
if ( aTitle && strlen(aTitle) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, "with title \"") ;
|
strcat(lDialogString, "with title \"") ;
|
||||||
strcat(lDialogString, aTitle) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, aTitle) ;
|
||||||
strcat(lDialogString, "\" ") ;
|
strcat(lDialogString, "\" ") ;
|
||||||
}
|
}
|
||||||
strcat(lDialogString, "with icon ") ;
|
strcat(lDialogString, "with icon ") ;
|
||||||
|
@ -4942,13 +4956,13 @@ int tinyfd_notifyPopup(
|
||||||
strcat( lDialogString , " -e 'try' -e 'display notification \"") ;
|
strcat( lDialogString , " -e 'try' -e 'display notification \"") ;
|
||||||
if ( aMessage && strlen(aMessage) )
|
if ( aMessage && strlen(aMessage) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, aMessage) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, aMessage) ;
|
||||||
}
|
}
|
||||||
strcat(lDialogString, " \" ") ;
|
strcat(lDialogString, " \" ") ;
|
||||||
if ( aTitle && strlen(aTitle) )
|
if ( aTitle && strlen(aTitle) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, "with title \"") ;
|
strcat(lDialogString, "with title \"") ;
|
||||||
strcat(lDialogString, aTitle) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, aTitle) ;
|
||||||
strcat(lDialogString, "\" ") ;
|
strcat(lDialogString, "\" ") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5096,13 +5110,13 @@ char * tinyfd_inputBox(
|
||||||
strcat( lDialogString , " -e 'try' -e 'display dialog \"") ;
|
strcat( lDialogString , " -e 'try' -e 'display dialog \"") ;
|
||||||
if ( aMessage && strlen(aMessage) )
|
if ( aMessage && strlen(aMessage) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, aMessage) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, aMessage) ;
|
||||||
}
|
}
|
||||||
strcat(lDialogString, "\" ") ;
|
strcat(lDialogString, "\" ") ;
|
||||||
strcat(lDialogString, "default answer \"") ;
|
strcat(lDialogString, "default answer \"") ;
|
||||||
if ( aDefaultInput && strlen(aDefaultInput) )
|
if ( aDefaultInput && strlen(aDefaultInput) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, aDefaultInput) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, aDefaultInput) ;
|
||||||
}
|
}
|
||||||
strcat(lDialogString, "\" ") ;
|
strcat(lDialogString, "\" ") ;
|
||||||
if ( ! aDefaultInput )
|
if ( ! aDefaultInput )
|
||||||
|
@ -5112,7 +5126,7 @@ char * tinyfd_inputBox(
|
||||||
if ( aTitle && strlen(aTitle) )
|
if ( aTitle && strlen(aTitle) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, "with title \"") ;
|
strcat(lDialogString, "with title \"") ;
|
||||||
strcat(lDialogString, aTitle) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, aTitle) ;
|
||||||
strcat(lDialogString, "\" ") ;
|
strcat(lDialogString, "\" ") ;
|
||||||
}
|
}
|
||||||
strcat(lDialogString, "with icon note' ") ;
|
strcat(lDialogString, "with icon note' ") ;
|
||||||
|
@ -5593,21 +5607,21 @@ char * tinyfd_saveFileDialog(
|
||||||
if ( aTitle && strlen(aTitle) )
|
if ( aTitle && strlen(aTitle) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, "with prompt \"") ;
|
strcat(lDialogString, "with prompt \"") ;
|
||||||
strcat(lDialogString, aTitle) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, aTitle) ;
|
||||||
strcat(lDialogString, "\" ") ;
|
strcat(lDialogString, "\" ") ;
|
||||||
}
|
}
|
||||||
getPathWithoutFinalSlash( lString , aDefaultPathAndFile ) ;
|
getPathWithoutFinalSlash( lString , aDefaultPathAndFile ) ;
|
||||||
if ( strlen(lString) )
|
if ( strlen(lString) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, "default location \"") ;
|
strcat(lDialogString, "default location \"") ;
|
||||||
strcat(lDialogString, lString ) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, lString ) ;
|
||||||
strcat(lDialogString , "\" " ) ;
|
strcat(lDialogString , "\" " ) ;
|
||||||
}
|
}
|
||||||
getLastName( lString , aDefaultPathAndFile ) ;
|
getLastName( lString , aDefaultPathAndFile ) ;
|
||||||
if ( strlen(lString) )
|
if ( strlen(lString) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, "default name \"") ;
|
strcat(lDialogString, "default name \"") ;
|
||||||
strcat(lDialogString, lString ) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, lString ) ;
|
||||||
strcat(lDialogString , "\" " ) ;
|
strcat(lDialogString , "\" " ) ;
|
||||||
}
|
}
|
||||||
strcat( lDialogString , ")' " ) ;
|
strcat( lDialogString , ")' " ) ;
|
||||||
|
@ -5966,25 +5980,25 @@ char * tinyfd_openFileDialog(
|
||||||
if ( aTitle && strlen(aTitle) )
|
if ( aTitle && strlen(aTitle) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, "with prompt \"") ;
|
strcat(lDialogString, "with prompt \"") ;
|
||||||
strcat(lDialogString, aTitle) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, aTitle) ;
|
||||||
strcat(lDialogString, "\" ") ;
|
strcat(lDialogString, "\" ") ;
|
||||||
}
|
}
|
||||||
getPathWithoutFinalSlash( lString , aDefaultPathAndFile ) ;
|
getPathWithoutFinalSlash( lString , aDefaultPathAndFile ) ;
|
||||||
if ( strlen(lString) )
|
if ( strlen(lString) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, "default location \"") ;
|
strcat(lDialogString, "default location \"") ;
|
||||||
strcat(lDialogString, lString ) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, lString ) ;
|
||||||
strcat(lDialogString , "\" " ) ;
|
strcat(lDialogString , "\" " ) ;
|
||||||
}
|
}
|
||||||
if ( aNumOfFilterPatterns > 0 )
|
if ( aNumOfFilterPatterns > 0 )
|
||||||
{
|
{
|
||||||
strcat(lDialogString , "of type {\"" );
|
strcat(lDialogString , "of type {\"" );
|
||||||
strcat( lDialogString , aFilterPatterns[0] + 2 ) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript( lDialogString , aFilterPatterns[0] + 2 ) ;
|
||||||
strcat( lDialogString , "\"" ) ;
|
strcat( lDialogString , "\"" ) ;
|
||||||
for ( i = 1 ; i < aNumOfFilterPatterns ; i ++ )
|
for ( i = 1 ; i < aNumOfFilterPatterns ; i ++ )
|
||||||
{
|
{
|
||||||
strcat( lDialogString , ",\"" ) ;
|
strcat( lDialogString , ",\"" ) ;
|
||||||
strcat( lDialogString , aFilterPatterns[i] + 2) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript( lDialogString , aFilterPatterns[i] + 2) ;
|
||||||
strcat( lDialogString , "\"" ) ;
|
strcat( lDialogString , "\"" ) ;
|
||||||
}
|
}
|
||||||
strcat( lDialogString , "} " ) ;
|
strcat( lDialogString , "} " ) ;
|
||||||
|
@ -6348,13 +6362,13 @@ char * tinyfd_selectFolderDialog(
|
||||||
if ( aTitle && strlen(aTitle) )
|
if ( aTitle && strlen(aTitle) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, "with prompt \"") ;
|
strcat(lDialogString, "with prompt \"") ;
|
||||||
strcat(lDialogString, aTitle) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, aTitle) ;
|
||||||
strcat(lDialogString, "\" ") ;
|
strcat(lDialogString, "\" ") ;
|
||||||
}
|
}
|
||||||
if ( aDefaultPath && strlen(aDefaultPath) )
|
if ( aDefaultPath && strlen(aDefaultPath) )
|
||||||
{
|
{
|
||||||
strcat(lDialogString, "default location \"") ;
|
strcat(lDialogString, "default location \"") ;
|
||||||
strcat(lDialogString, aDefaultPath ) ; // FIXME: Escape double quotes
|
concatAndEscapeOsascript(lDialogString, aDefaultPath ) ;
|
||||||
strcat(lDialogString , "\" " ) ;
|
strcat(lDialogString , "\" " ) ;
|
||||||
}
|
}
|
||||||
strcat( lDialogString , ")' " ) ;
|
strcat( lDialogString , ")' " ) ;
|
||||||
|
|
Loading…
Reference in a new issue