Add an argument to all uses of the __ONLY_IN_WINELIB macro (spotted by
[wine/multimedia.git] / programs / winebrowser / main.c
blobe2d63ab26fe2124e093e83f79e4e60955a874aea
1 /*
2 * winebrowser - winelib app to launch native OS browser
4 * Copyright (C) 2004 Chris Morgan
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * NOTES:
21 * Winebrowser is a winelib application that will start the appropriate
22 * native browser up for a wine installation that lacks a windows browser.
23 * Thus you will be able to open urls via native mozilla if no browser
24 * has yet been installed in wine.
27 #include "config.h"
28 #include "wine/port.h"
30 #include <windows.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <errno.h>
35 typedef LPSTR (*wine_get_unix_file_name_t) ( LPCWSTR dos );
37 /*****************************************************************************
38 * Main entry point. This is a console application so we have a main() not a
39 * winmain().
41 int main (int argc, char *argv[])
43 const char *argv_new[3];
44 DWORD maxLength;
45 CHAR szBrowsers[256];
46 DWORD type;
47 const CHAR *defaultBrowsers =
48 "mozilla,firefox,netscape,konqueror,galeon,opera,dillo";
49 char *browser;
50 HKEY hkey;
51 LONG r;
52 wine_get_unix_file_name_t wine_get_unix_file_name_ptr;
54 if (argc <= 1)
56 fprintf( stderr, "Usage: winebrowser URL\n" );
57 return 1;
60 /* check if the argument is a local file */
61 wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t)
62 GetProcAddress( GetModuleHandle( "KERNEL32"), "wine_get_unix_file_name");
63 if( wine_get_unix_file_name_ptr == NULL) {
64 fprintf( stderr, "%s: cannot get the address of "
65 "'wine_get_unix_file_name'\n", argv[0]);
66 } else {
67 WCHAR dospathW[ MAX_PATH];
68 char *p;
69 MultiByteToWideChar( CP_ACP, 0, argv[1], -1, dospathW, MAX_PATH);
70 if((p = wine_get_unix_file_name_ptr( dospathW))) {
71 struct stat dummy;
72 if(stat( p, &dummy) >= 0 ) argv[1] = p;
76 maxLength = sizeof(szBrowsers);
78 /* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */
79 if(RegCreateKeyEx( HKEY_CURRENT_USER,
80 "Software\\Wine\\WineBrowser", 0, NULL,
81 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
82 &hkey, NULL))
84 fprintf( stderr, "winebrowser: cannot create config key\n" );
85 return 1;
88 r = RegQueryValueExA( hkey, "Browsers", 0, &type, (LPBYTE)szBrowsers, &maxLength);
89 if(r != ERROR_SUCCESS)
91 /* set value to the default */
92 RegSetValueExA(hkey, "Browsers", 0, REG_SZ,
93 (LPBYTE)defaultBrowsers, lstrlen(defaultBrowsers) + 1);
94 strcpy( szBrowsers, defaultBrowsers );
97 RegCloseKey(hkey);
100 /* now go through the list of browsers until we run out or we find one that */
101 /* works */
102 browser = strtok(szBrowsers, ",");
104 while(browser)
106 argv_new[0] = browser;
107 argv_new[1] = argv[1];
108 argv_new[2] = NULL;
110 spawnvp(_P_OVERLAY, browser, argv_new); /* only returns on error */
112 browser = strtok(NULL, ","); /* grab the next browser */
114 fprintf( stderr, "winebrowser: could not find a browser to run\n" );
115 return 1;