allow winebrowser to use commands with arguments
Yuriy
yuriy.kozlov at gmail.com
Fri Aug 11 13:46:05 CDT 2006
Hello,
I fixed a bug that wasn't allowing multi-word commands to be used as a
browser for winebrowser, which are needed for things such as launching
the KDE default browser or a new tab in opera. This is my first time
writing more than a couple lines of C, so my patch probably warrants
some extra scrutiny.
PROBLEM:
winebrowser doesn't work with browsers/commands that
are more than one word. For example, the command to run konqueror
with the webbrowsing profile on kubuntu is:
kfmclient openProfile webbrowsing [url]
Setting that to be the first attempted webbrowser in the registry:
[HKEY_USERS\S-1-5-4\Software\Wine\WineBrowser]
"Browsers"="kfmclient openProfile webbrowsing,firefox,mozilla,opera,dillo"
and running:
winebrowser http://www.winehq.org
yields this:
Considering: kfmclient openProfile webbrowsing
argv[1]: http://www.winehq.org
Considering: firefox
argv[1]: http://www.winehq.org
DESCRIPTION:
This patch parses the app to seperate the arguments. It allows up to
5 arguments including the app name. It sends all the arguments to the
spawn function and preserves the app name to display.
CHANGE:
allow winebrowser to use commands with arguments
PATCH:
index 690f931..81b2f42 100644
--- a/programs/winebrowser/main.c
+++ b/programs/winebrowser/main.c
@@ -51,20 +51,39 @@ typedef LPSTR (*wine_get_unix_file_name_
/* try to launch an app from a comma separated string of app names */
static int launch_app( char *candidates, const char *argv1 )
{
- char *app;
- const char *argv_new[3];
+ char *app, *appname;
+ const char *argv_new[7];
+ int i1 = 0, i2 = 0, i3 = 0, len = 0;
app = strtok( candidates, "," );
while (app)
{
- argv_new[0] = app;
- argv_new[1] = argv1;
- argv_new[2] = NULL;
+ i2 = 0;
+ i3 = 0;
+ len = strlen(app);
+ appname = (char *)malloc(len);
+ for(i1 = 0; i1 < len && i3 < 4; i1++)
+ {
+ appname[i1] = app[i1];
+ if (app[i1] == ' ')
+ {
+ app[i1] = '\0';
+ argv_new[i3] = app + i2;
+ i3++;
+ i2 = i1 + 1;
+ }
+ }
+
+ appname[i1] = '\0';
+ argv_new[i3] = app+i2;
+ argv_new[i3+1] = argv1;
+ argv_new[i3+2] = NULL;
- fprintf( stderr, "Considering: %s\n", app );
+ fprintf( stderr, "Considering: %s\n", appname );
fprintf( stderr, "argv[1]: %s\n", argv1 );
spawnvp( _P_OVERLAY, app, argv_new ); /* only returns on error */
+ free(appname);
app = strtok( NULL, "," ); /* grab the next app */
}
fprintf( stderr, "winebrowser: could not find a suitable app to run\n" );
More information about the wine-patches
mailing list