diff --git a/mozilla/xpfe/appshell/src/nsCommandLineService.cpp b/mozilla/xpfe/appshell/src/nsCommandLineService.cpp index 84534c15608..6fe63c4bb7e 100644 --- a/mozilla/xpfe/appshell/src/nsCommandLineService.cpp +++ b/mozilla/xpfe/appshell/src/nsCommandLineService.cpp @@ -41,6 +41,7 @@ #include "nsIComponentManager.h" #include "nsString.h" #include "plstr.h" +#include "nsNetUtil.h" nsCmdLineService::nsCmdLineService() : mArgCount(0), mArgc(0), mArgv(0) @@ -53,6 +54,38 @@ nsCmdLineService::nsCmdLineService() */ NS_IMPL_ISUPPORTS1(nsCmdLineService, nsICmdLineService); +static void* ProcessURLArg(char* str) +{ + // Problem: since the arg parsing code doesn't know which flags + // take arguments, it always calls this method for the last + // non-flag argument. But sometimes that argument is actually + // the arg for the last switch, e.g. -width 500 or -Profile default. + // nsLocalFile will only work on absolute pathnames, so return + // if str doesn't start with '/' or '\'. + if (str && (*str == '\\' || *str == '/')) + { + nsCOMPtr uri; + nsresult rv = NS_NewURI(getter_AddRefs(uri), str); + if (NS_FAILED(rv)) + { + nsCOMPtr file(do_CreateInstance("@mozilla.org/file/local;1")); + if (file) + { + rv = file->InitWithPath(str); + if (NS_SUCCEEDED(rv)) + { + nsXPIDLCString fileurl; + rv = file->GetURL(getter_Copies(fileurl)); + if (NS_SUCCEEDED(rv) && fileurl.get()) + return NS_REINTERPRET_CAST(void*, nsCRT::strdup(fileurl.get())); + } + } + } + } + + return NS_REINTERPRET_CAST(void*, nsCRT::strdup(str)); +} + NS_IMETHODIMP nsCmdLineService::Initialize(int aArgc, char ** aArgv) { @@ -75,8 +108,12 @@ nsCmdLineService::Initialize(int aArgc, char ** aArgv) for(i=1; iCount(); i++) { + for (i=0; i < (PRUint32)paramList->Count(); i++) { const char *param = (const char*)paramList->ElementAt(i); // skip past leading / and - diff --git a/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp b/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp index 84534c15608..6fe63c4bb7e 100644 --- a/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp +++ b/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp @@ -41,6 +41,7 @@ #include "nsIComponentManager.h" #include "nsString.h" #include "plstr.h" +#include "nsNetUtil.h" nsCmdLineService::nsCmdLineService() : mArgCount(0), mArgc(0), mArgv(0) @@ -53,6 +54,38 @@ nsCmdLineService::nsCmdLineService() */ NS_IMPL_ISUPPORTS1(nsCmdLineService, nsICmdLineService); +static void* ProcessURLArg(char* str) +{ + // Problem: since the arg parsing code doesn't know which flags + // take arguments, it always calls this method for the last + // non-flag argument. But sometimes that argument is actually + // the arg for the last switch, e.g. -width 500 or -Profile default. + // nsLocalFile will only work on absolute pathnames, so return + // if str doesn't start with '/' or '\'. + if (str && (*str == '\\' || *str == '/')) + { + nsCOMPtr uri; + nsresult rv = NS_NewURI(getter_AddRefs(uri), str); + if (NS_FAILED(rv)) + { + nsCOMPtr file(do_CreateInstance("@mozilla.org/file/local;1")); + if (file) + { + rv = file->InitWithPath(str); + if (NS_SUCCEEDED(rv)) + { + nsXPIDLCString fileurl; + rv = file->GetURL(getter_Copies(fileurl)); + if (NS_SUCCEEDED(rv) && fileurl.get()) + return NS_REINTERPRET_CAST(void*, nsCRT::strdup(fileurl.get())); + } + } + } + } + + return NS_REINTERPRET_CAST(void*, nsCRT::strdup(str)); +} + NS_IMETHODIMP nsCmdLineService::Initialize(int aArgc, char ** aArgv) { @@ -75,8 +108,12 @@ nsCmdLineService::Initialize(int aArgc, char ** aArgv) for(i=1; iCount(); i++) { + for (i=0; i < (PRUint32)paramList->Count(); i++) { const char *param = (const char*)paramList->ElementAt(i); // skip past leading / and -