changeset 5515:439a05a6b409

[gaim-migrate @ 5914] This makes the manual browser setting good. -You can have multiple %s's in a browser command (I don't know why you would want to, but you can) -It doesn't double-free memory and cause gaim to crash -If there is no %s, it adds the URL to the end of the command (it did this before, I'm just re-iterating that it still works) -It's fewer lines of code and it's cleaner, I think committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 25 May 2003 18:35:24 +0000
parents 5664dbaf670c
children dcfe83cdfd42
files src/browser.c src/util.c src/util.h
diffstat 3 files changed, 26 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser.c	Sun May 25 17:06:30 2003 +0000
+++ b/src/browser.c	Sun May 25 18:35:24 2003 +0000
@@ -584,9 +584,6 @@
 			break;
 
 		case BROWSER_MANUAL: {
-			char *space_free_url = NULL;
-			char *web_tmp = NULL;
-
 			if (!web_command[0]) {
 				gaim_notify_error(NULL, NULL,
 								  _("Unable to launch your browser because "
@@ -596,28 +593,12 @@
 				return;
 			}
 
-			space_free_url = g_strdup(url);
-			g_strdelimit(space_free_url, " ", '+');
-			/*
 			if (strstr(web_command, "%s"))
-				command = g_strdup_printf(web_command, space_free_url);
-
-			Replaced the above with the following to avoid users
-			from entering more than one %s as part of the browser
-			command.
-			*/
-			web_tmp = strstr(web_command, "%s");
-			if(web_tmp)
-			{
-				if (strstr((web_tmp + 1), "%s"))
-					command = g_strdup_printf(web_command, space_free_url);
-				else
-					gaim_notify_error(NULL, NULL, _("Unable to launch your browser because the 'Manual' browser command has too many '%s'."), NULL);
-			}
+				command = gaim_strreplace(web_command, "%s", url);
 			else
-				command = g_strdup_printf("%s %s", web_command, space_free_url);
-			g_free(space_free_url);
-			g_free(web_tmp);
+				/* There is no "%s" in the browser command.  Assume the user
+				 * wanted the URL tacked on to the end of the command. */
+				command = g_strdup_printf("%s %s", web_command, url);
 		} break;
 	}
 
--- a/src/util.c	Sun May 25 17:06:30 2003 +0000
+++ b/src/util.c	Sun May 25 18:35:24 2003 +0000
@@ -1170,3 +1170,14 @@
 	g_free(b_norm);
 	return ret;
 }
+
+gchar *gaim_strreplace(const gchar *string, const gchar *delimiter, const gchar *replacement) {
+	gchar **split;
+	gchar *ret;
+
+	split = g_strsplit(string, delimiter, 0);
+	ret = g_strjoinv(replacement, split);
+	g_strfreev(split);
+
+	return ret;
+}
--- a/src/util.h	Sun May 25 17:06:30 2003 +0000
+++ b/src/util.h	Sun May 25 18:35:24 2003 +0000
@@ -332,4 +332,15 @@
  */
 gint gaim_utf8_strcasecmp(const gchar *a, const gchar *b);
 
+/**
+ * Given a string, this replaces one substring with another
+ * and returns a newly allocated string.
+ *
+ * @param string The string from which to replace stuff.
+ * @param delimiter The substring you want replaced.
+ * @param replacement The substring you want inserted in place 
+ *        of the delimiting substring.
+ */
+gchar *gaim_strreplace(const gchar *string, const gchar *delimiter, const gchar *replacement);
+
 #endif /* _GAIM_UTIL_H_ */