From a1e67dbf640a185f35e875ef698525b9c881f5e9 Mon Sep 17 00:00:00 2001 From: "radha%netscape.com" Date: Fri, 22 Jan 1999 22:21:45 +0000 Subject: [PATCH] Command line service provider. Initial checkin --- xpfe/appshell/src/nsCommandLineService.cpp | 346 ++++++++++++++++++ .../startup/src/nsCommandLineService.cpp | 346 ++++++++++++++++++ 2 files changed, 692 insertions(+) create mode 100644 xpfe/appshell/src/nsCommandLineService.cpp create mode 100644 xpfe/components/startup/src/nsCommandLineService.cpp diff --git a/xpfe/appshell/src/nsCommandLineService.cpp b/xpfe/appshell/src/nsCommandLineService.cpp new file mode 100644 index 00000000000..72fe12926c3 --- /dev/null +++ b/xpfe/appshell/src/nsCommandLineService.cpp @@ -0,0 +1,346 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + + +#include "nsICmdLineService.h" +#include "nsVoidArray.h" +#include "nsRepository.h" +#include "nsString.h" +#include "plstr.h" + + +/* Define Class IDs */ +static NS_DEFINE_IID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID); +static NS_DEFINE_IID(kICommandLineIID, NS_ICOMMANDLINE_SERVICE_IID); + +/* Define Interface IDs */ + +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); +static NS_DEFINE_IID(kICommandLineServiceIID, NS_ICOMMANDLINE_SERVICE_IID); + + +class nsCmdLineService : public nsICmdLineService +{ +public: + nsCmdLineService(void); + + NS_DECL_ISUPPORTS + + nsresult Initialize(int argc, char** argv); + nsresult GetCmdLineValue(char* arg, char **value); + nsresult GetURLToLoad(char ** aResult); + nsresult GetProgramName(char ** aResult); +// nsresult PrintCmdArgs(); + +protected: + virtual ~nsCmdLineService(); + + nsVoidArray mArgList; // The arguments + nsVoidArray mArgValueList; // The argument values + PRInt32 mArgCount; // This is not argc. This is # of argument pairs + // in the arglist and argvaluelist arrays. This + // normally is argc/2. +}; + + +nsCmdLineService::nsCmdLineService() +{ + mArgCount = 0; +} + + +nsresult nsCmdLineService::Initialize(int argc, char ** argv) +{ + NS_INIT_REFCNT(); + PRInt32 i=0; + nsresult rv = nsnull; + + //Insert the program name + mArgList.AppendElement((void *)PL_strdup("-progname")); + mArgValueList.AppendElement((void *)PL_strdup(argv[0])); + mArgCount++; + i++; + + for(i=1; iQueryInterface(aIID, aResult); + NS_RELEASE(inst); + +done: + return rv; +} + + +extern "C" NS_APPSHELL nsresult +NS_NewCmdLineServiceFactory(nsIFactory** aFactory) +{ + nsresult rv = NS_OK; + nsIFactory* inst = new nsCmdLineServiceFactory(); + if (nsnull == inst) { + rv = NS_ERROR_OUT_OF_MEMORY; + } + else { + NS_ADDREF(inst); + } + *aFactory = inst; + return rv; +} diff --git a/xpfe/components/startup/src/nsCommandLineService.cpp b/xpfe/components/startup/src/nsCommandLineService.cpp new file mode 100644 index 00000000000..72fe12926c3 --- /dev/null +++ b/xpfe/components/startup/src/nsCommandLineService.cpp @@ -0,0 +1,346 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + + +#include "nsICmdLineService.h" +#include "nsVoidArray.h" +#include "nsRepository.h" +#include "nsString.h" +#include "plstr.h" + + +/* Define Class IDs */ +static NS_DEFINE_IID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID); +static NS_DEFINE_IID(kICommandLineIID, NS_ICOMMANDLINE_SERVICE_IID); + +/* Define Interface IDs */ + +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); +static NS_DEFINE_IID(kICommandLineServiceIID, NS_ICOMMANDLINE_SERVICE_IID); + + +class nsCmdLineService : public nsICmdLineService +{ +public: + nsCmdLineService(void); + + NS_DECL_ISUPPORTS + + nsresult Initialize(int argc, char** argv); + nsresult GetCmdLineValue(char* arg, char **value); + nsresult GetURLToLoad(char ** aResult); + nsresult GetProgramName(char ** aResult); +// nsresult PrintCmdArgs(); + +protected: + virtual ~nsCmdLineService(); + + nsVoidArray mArgList; // The arguments + nsVoidArray mArgValueList; // The argument values + PRInt32 mArgCount; // This is not argc. This is # of argument pairs + // in the arglist and argvaluelist arrays. This + // normally is argc/2. +}; + + +nsCmdLineService::nsCmdLineService() +{ + mArgCount = 0; +} + + +nsresult nsCmdLineService::Initialize(int argc, char ** argv) +{ + NS_INIT_REFCNT(); + PRInt32 i=0; + nsresult rv = nsnull; + + //Insert the program name + mArgList.AppendElement((void *)PL_strdup("-progname")); + mArgValueList.AppendElement((void *)PL_strdup(argv[0])); + mArgCount++; + i++; + + for(i=1; iQueryInterface(aIID, aResult); + NS_RELEASE(inst); + +done: + return rv; +} + + +extern "C" NS_APPSHELL nsresult +NS_NewCmdLineServiceFactory(nsIFactory** aFactory) +{ + nsresult rv = NS_OK; + nsIFactory* inst = new nsCmdLineServiceFactory(); + if (nsnull == inst) { + rv = NS_ERROR_OUT_OF_MEMORY; + } + else { + NS_ADDREF(inst); + } + *aFactory = inst; + return rv; +}