From: Sean E. <sea...@us...> - 2002-08-22 03:16:06
|
Update of /cvsroot/gaim/gaim/src In directory usw-pr-cvs1:/tmp/cvs-serv20322/src Modified Files: Tag: gtk1-stable browser.c Log Message: We've gone and done something drastic. Index: browser.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/browser.c,v retrieving revision 1.23 retrieving revision 1.23.2.1 diff -u -d -r1.23 -r1.23.2.1 --- browser.c 17 Jun 2002 00:10:34 -0000 1.23 +++ browser.c 22 Aug 2002 03:16:03 -0000 1.23.2.1 @@ -559,6 +559,58 @@ } +#if !GTK_CHECK_VERSION(1,3,0) +/* From Glib 2.0 */ +/** + * g_shell_quote: + * @unquoted_string: a literal string + * + * Quotes a string so that the shell (/bin/sh) will interpret the + * quoted string to mean @unquoted_string. If you pass a filename to + * the shell, for example, you should first quote it with this + * function. The return value must be freed with g_free(). The + * quoting style used is undefined (single or double quotes may be + * used). + * + * Return value: quoted string +**/ +gchar* +g_shell_quote (const gchar *unquoted_string) +{ + /* We always use single quotes, because the algorithm is cheesier. + * We could use double if we felt like it, that might be more + * human-readable. + */ + const gchar *p; + GString *dest; + + g_return_val_if_fail (unquoted_string != NULL, NULL); + + dest = g_string_new ("'"); + + p = unquoted_string; + + /* could speed this up a lot by appending chunks of text at a + * time. + */ + while (*p) + { + /* Replace literal ' with a close ', a \', and a open ' */ + if (*p == '\'') + g_string_append (dest, "'\\''"); + else + g_string_append_c (dest, *p); + ++p; + } + /* close the quote */ + g_string_append_c (dest, '\''); + + p = dest->str; + g_string_free (dest, FALSE); + return p; +} +#endif + void open_url(GtkWidget *w, char *url) { @@ -584,6 +636,7 @@ if (pid == 0) { char *args[4]; char command[1024]; + char *quoted = NULL; if (web_browser == BROWSER_OPERA) { args[0] = "opera"; @@ -610,14 +663,17 @@ args[1] = url; args[2] = NULL; } else if (web_browser == BROWSER_MANUAL) { - g_snprintf(command, sizeof(command), web_command, url); + g_snprintf(command, sizeof(command), web_command, quoted); + quoted = g_shell_quote(command); args[0] = "sh"; args[1] = "-c"; - args[2] = command; + args[2] = quoted; args[3] = NULL; } execvp(args[0], args); + if (quoted) + g_free(quoted); _exit(0); } } |