Kaydet (Commit) f4a4ba9a authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Clean up option processing

* Support --version on non-UNX, too.

* Consistently show the first unknown option and the help blob in the presence
  of any unknown options.

* There is no need to tunnel --help/--version past oosplash in the soffice
  script, as oosplash is prepared to treat them adequately (esp. not pass them
  over any pipe); this only added unnecessary variance to what spellings exactly
  are supported and how mixtures of --help, --version, and unknown options are
  handled.

Change-Id: I617f2e727e2f0eafd34a2de3b85d441c6783ec4f
üst 4972652e
...@@ -158,21 +158,5 @@ if [ -n "$VALGRINDCHECK" -a -z "$VALGRIND" ] ; then ...@@ -158,21 +158,5 @@ if [ -n "$VALGRINDCHECK" -a -z "$VALGRIND" ] ; then
exec &>valgrind.log exec &>valgrind.log
fi fi
# do not pass the request for command line help to oosplash
for arg in $@ ; do
case "$arg" in
-h | --h | --he | --hel | --help)
"$sd_prog/soffice.bin" --help
exit 0
;;
-V | --v | --ve | --ver | --vers | --versi | --versio | --version)
"$sd_prog/soffice.bin" --version
exit 0
;;
*)
;;
esac
done
# oosplash does the rest: forcing pages in, javaldx etc. are # oosplash does the rest: forcing pages in, javaldx etc. are
exec $VALGRINDCHECK $STRACECHECK "$sd_prog/oosplash" "$@" exec $VALGRINDCHECK $STRACECHECK "$sd_prog/oosplash" "$@"
...@@ -634,7 +634,8 @@ void Desktop::Init() ...@@ -634,7 +634,8 @@ void Desktop::Init()
// 2nd office startup should terminate after sending cmdlineargs through pipe // 2nd office startup should terminate after sending cmdlineargs through pipe
SetBootstrapStatus(BS_TERMINATE); SetBootstrapStatus(BS_TERMINATE);
} }
else if ( rCmdLineArgs.IsHelp() ) else if ( !rCmdLineArgs.GetUnknown().isEmpty()
|| rCmdLineArgs.IsHelp() || rCmdLineArgs.IsVersion() )
{ {
// disable IPC thread in an instance that is just showing a help message // disable IPC thread in an instance that is just showing a help message
OfficeIPCThread::DisableOfficeIPCThread(); OfficeIPCThread::DisableOfficeIPCThread();
...@@ -1388,6 +1389,22 @@ int Desktop::Main() ...@@ -1388,6 +1389,22 @@ int Desktop::Main()
new DesktopContext( com::sun::star::uno::getCurrentContext() ) ); new DesktopContext( com::sun::star::uno::getCurrentContext() ) );
CommandLineArgs& rCmdLineArgs = GetCommandLineArgs(); CommandLineArgs& rCmdLineArgs = GetCommandLineArgs();
OUString aUnknown( rCmdLineArgs.GetUnknown() );
if ( !aUnknown.isEmpty() )
{
displayCmdlineHelp( aUnknown );
return EXIT_FAILURE;
}
if ( rCmdLineArgs.IsHelp() )
{
displayCmdlineHelp( OUString() );
return EXIT_SUCCESS;
}
if ( rCmdLineArgs.IsVersion() )
{
displayVersion();
return EXIT_SUCCESS;
}
// setup configuration error handling // setup configuration error handling
ConfigurationErrorHandler aConfigErrHandler; ConfigurationErrorHandler aConfigErrHandler;
...@@ -1431,14 +1448,6 @@ int Desktop::Main() ...@@ -1431,14 +1448,6 @@ int Desktop::Main()
SetSplashScreenProgress(25); SetSplashScreenProgress(25);
#ifndef UNX
if ( rCmdLineArgs.IsHelp() )
{
displayCmdlineHelp();
return EXIT_SUCCESS;
}
#endif
// check user installation directory for lockfile so we can be sure // check user installation directory for lockfile so we can be sure
// there is no other instance using our data files from a remote host // there is no other instance using our data files from a remote host
RTL_LOGFILE_CONTEXT_TRACE( aLog, "desktop (lo119109) Desktop::Main -> Lockfile" ); RTL_LOGFILE_CONTEXT_TRACE( aLog, "desktop (lo119109) Desktop::Main -> Lockfile" );
...@@ -2696,10 +2705,10 @@ void Desktop::HandleAppEvent( const ApplicationEvent& rAppEvent ) ...@@ -2696,10 +2705,10 @@ void Desktop::HandleAppEvent( const ApplicationEvent& rAppEvent )
} }
break; break;
case ApplicationEvent::TYPE_HELP: case ApplicationEvent::TYPE_HELP:
#ifndef UNX displayCmdlineHelp(rAppEvent.GetData());
// in non unix version allow showing of cmdline help window break;
displayCmdlineHelp(); case ApplicationEvent::TYPE_VERSION:
#endif displayVersion();
break; break;
case ApplicationEvent::TYPE_OPEN: case ApplicationEvent::TYPE_OPEN:
{ {
......
...@@ -287,26 +287,25 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) ...@@ -287,26 +287,25 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier )
{ {
bConversionOutEvent = true; bConversionOutEvent = true;
} }
#if defined UNX
else else
// because it's impossible to filter these options that // because it's impossible to filter these options that
// are handled in the soffice shell script with the // are handled in the soffice shell script with the
// primitive tools that /bin/sh offers, ignore them here // primitive tools that /bin/sh offers, ignore them here
if (!oArg.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("backtrace")) && if (
#if defined UNX
!oArg.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("backtrace")) &&
!oArg.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("strace")) && !oArg.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("strace")) &&
!oArg.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("valgrind")) && !oArg.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("valgrind")) &&
// for X Session Management, handled in // for X Session Management, handled in
// vcl/unx/generic/app/sm.cxx: // vcl/unx/generic/app/sm.cxx:
!oArg.match("session=") && !oArg.match("session=") &&
#endif
//ignore additional legacy options that don't do anything anymore //ignore additional legacy options that don't do anything anymore
!oArg.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("nocrashreport"))) !oArg.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("nocrashreport")) &&
m_unknown.isEmpty())
{ {
fprintf(stderr, "Unknown option %s\n", m_unknown = aArg;
rtl::OUStringToOString(aArg, osl_getThreadTextEncoding()).getStr());
fprintf(stderr, "Run 'soffice --help' to see a full list of available command line options.\n");
m_unknown = true;
} }
#endif
} }
else else
{ {
...@@ -624,7 +623,6 @@ void CommandLineArgs::InitParamValues() ...@@ -624,7 +623,6 @@ void CommandLineArgs::InitParamValues()
m_helpbase = false; m_helpbase = false;
m_psn = false; m_psn = false;
m_version = false; m_version = false;
m_unknown = false;
m_splashpipe = false; m_splashpipe = false;
m_bEmpty = true; m_bEmpty = true;
m_bDocumentArgs = false; m_bDocumentArgs = false;
...@@ -762,7 +760,7 @@ bool CommandLineArgs::IsVersion() const ...@@ -762,7 +760,7 @@ bool CommandLineArgs::IsVersion() const
return m_version; return m_version;
} }
bool CommandLineArgs::HasUnknown() const OUString CommandLineArgs::GetUnknown() const
{ {
return m_unknown; return m_unknown;
} }
......
...@@ -93,9 +93,10 @@ class CommandLineArgs: private boost::noncopyable ...@@ -93,9 +93,10 @@ class CommandLineArgs: private boost::noncopyable
bool IsWeb() const; bool IsWeb() const;
bool IsVersion() const; bool IsVersion() const;
bool HasModuleParam() const; bool HasModuleParam() const;
bool HasUnknown() const;
bool WantsToLoadDocument() const; bool WantsToLoadDocument() const;
OUString GetUnknown() const;
// Access to string parameters // Access to string parameters
bool HasSplashPipe() const; bool HasSplashPipe() const;
std::vector< rtl::OUString > const & GetAccept() const; std::vector< rtl::OUString > const & GetAccept() const;
...@@ -153,9 +154,10 @@ class CommandLineArgs: private boost::noncopyable ...@@ -153,9 +154,10 @@ class CommandLineArgs: private boost::noncopyable
bool m_helpbase; bool m_helpbase;
bool m_psn; bool m_psn;
bool m_version; bool m_version;
bool m_unknown;
bool m_splashpipe; bool m_splashpipe;
OUString m_unknown;
bool m_bEmpty; // No Args at all bool m_bEmpty; // No Args at all
bool m_bDocumentArgs; // A document creation/open/load arg is used bool m_bDocumentArgs; // A document creation/open/load arg is used
std::vector< rtl::OUString > m_accept; std::vector< rtl::OUString > m_accept;
......
...@@ -136,7 +136,7 @@ namespace desktop ...@@ -136,7 +136,7 @@ namespace desktop
rtl::OUString ReplaceStringHookProc(const rtl::OUString& rStr); rtl::OUString ReplaceStringHookProc(const rtl::OUString& rStr);
void displayCmdlineHelp() void displayCmdlineHelp(OUString const & unknown)
{ {
// if you put variables in other chunks don't forget to call the replace routines // if you put variables in other chunks don't forget to call the replace routines
// for those chunks... // for those chunks...
...@@ -147,6 +147,11 @@ namespace desktop ...@@ -147,6 +147,11 @@ namespace desktop
String aHelpMessage_bottom(aCmdLineHelp_bottom, RTL_TEXTENCODING_ASCII_US); String aHelpMessage_bottom(aCmdLineHelp_bottom, RTL_TEXTENCODING_ASCII_US);
aHelpMessage_version = ReplaceStringHookProc(aHelpMessage_version); aHelpMessage_version = ReplaceStringHookProc(aHelpMessage_version);
aHelpMessage_head.SearchAndReplaceAscii( "%CMDNAME", String( "soffice", RTL_TEXTENCODING_ASCII_US) ); aHelpMessage_head.SearchAndReplaceAscii( "%CMDNAME", String( "soffice", RTL_TEXTENCODING_ASCII_US) );
if (!unknown.isEmpty())
{
aHelpMessage_head = "Unknown option: " + unknown + "\n\n"
+ aHelpMessage_head;
}
#ifdef UNX #ifdef UNX
// on unix use console for output // on unix use console for output
fprintf(stdout, "%s%s", fprintf(stdout, "%s%s",
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
namespace desktop namespace desktop
{ {
void displayCmdlineHelp( void ); void displayCmdlineHelp( OUString const & unknown );
void displayVersion(); void displayVersion();
#ifndef UNX #ifndef UNX
class CmdlineHelpDialog : public ModalDialog class CmdlineHelpDialog : public ModalDialog
......
...@@ -60,22 +60,25 @@ extern "C" int DESKTOP_DLLPUBLIC soffice_main() ...@@ -60,22 +60,25 @@ extern "C" int DESKTOP_DLLPUBLIC soffice_main()
// handle --version and --help already here, otherwise they would be handled // handle --version and --help already here, otherwise they would be handled
// after VCL initialization that might fail if $DISPLAY is not set // after VCL initialization that might fail if $DISPLAY is not set
const desktop::CommandLineArgs& rCmdLineArgs = aDesktop.GetCommandLineArgs(); const desktop::CommandLineArgs& rCmdLineArgs = aDesktop.GetCommandLineArgs();
OUString aUnknown( rCmdLineArgs.GetUnknown() );
if ( !aUnknown.isEmpty() )
{
desktop::Desktop::InitApplicationServiceManager();
desktop::displayCmdlineHelp( aUnknown );
return EXIT_FAILURE;
}
if ( rCmdLineArgs.IsHelp() ) if ( rCmdLineArgs.IsHelp() )
{ {
desktop::Desktop::InitApplicationServiceManager(); desktop::Desktop::InitApplicationServiceManager();
desktop::displayCmdlineHelp(); desktop::displayCmdlineHelp( OUString() );
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
else if ( rCmdLineArgs.IsVersion() ) if ( rCmdLineArgs.IsVersion() )
{ {
desktop::Desktop::InitApplicationServiceManager(); desktop::Desktop::InitApplicationServiceManager();
desktop::displayVersion(); desktop::displayVersion();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
else if ( rCmdLineArgs.HasUnknown() )
{
return EXIT_FAILURE;
}
#endif #endif
return SVMain(); return SVMain();
#if defined ANDROID #if defined ANDROID
......
...@@ -48,30 +48,34 @@ static struct { ...@@ -48,30 +48,34 @@ static struct {
unsigned int bInhibitSplash : 1; unsigned int bInhibitSplash : 1;
unsigned int bInhibitPagein : 1; unsigned int bInhibitPagein : 1;
unsigned int bInhibitJavaLdx : 1; unsigned int bInhibitJavaLdx : 1;
unsigned int bInhibitPipe : 1;
const char *pPageinType; const char *pPageinType;
} pArgDescr[] = { } pArgDescr[] = {
/* have a trailing argument */ /* have a trailing argument */
{ "pt", 1, 0, 0, 0, NULL }, { "pt", 1, 0, 0, 0, 0, NULL },
{ "display", 1, 0, 0, 0, NULL }, { "display", 1, 0, 0, 0, 0, NULL },
/* no splash */ /* no splash */
{ "nologo", 0, 1, 0, 0, NULL }, { "nologo", 0, 1, 0, 0, 0, NULL },
{ "headless", 0, 1, 0, 0, NULL }, { "headless", 0, 1, 0, 0, 0, NULL },
{ "invisible", 0, 1, 0, 0, NULL }, { "invisible", 0, 1, 0, 0, 0, NULL },
{ "quickstart", 0, 1, 0, 0, NULL }, { "quickstart", 0, 1, 0, 0, 0, NULL },
{ "minimized", 0, 1, 0, 0, NULL }, { "minimized", 0, 1, 0, 0, 0, NULL },
/* pagein bits */ /* pagein bits */
{ "writer", 0, 0, 0, 0, "pagein-writer" }, { "writer", 0, 0, 0, 0, 0, "pagein-writer" },
{ "calc", 0, 0, 0, 0, "pagein-calc" }, { "calc", 0, 0, 0, 0, 0, "pagein-calc" },
{ "draw", 0, 0, 0, 0, "pagein-draw" }, { "draw", 0, 0, 0, 0, 0, "pagein-draw" },
{ "impress", 0, 0, 0, 0, "pagein-impress" }, { "impress", 0, 0, 0, 0, 0, "pagein-impress" },
/* nothing much */ /* Do not send --help/--version over the pipe, as their output shall go to
{ "version", 0, 1, 1, 1, NULL }, the calling process's stdout (ideally, this would also happen in the
{ "help", 0, 1, 1, 1, NULL }, presence of unknown options); also prevent splash/pagein/javaldx overhead
{ "h", 0, 1, 1, 1, NULL }, (as these options will be processed early in soffice_main): */
{ "?", 0, 1, 1, 1, NULL }, { "version", 0, 1, 1, 1, 1, NULL },
{ "help", 0, 1, 1, 1, 1, NULL },
{ "h", 0, 1, 1, 1, 1, NULL },
{ "?", 0, 1, 1, 1, 1, NULL },
}; };
Args *args_parse (void) Args *args_parse (void)
...@@ -133,6 +137,7 @@ Args *args_parse (void) ...@@ -133,6 +137,7 @@ Args *args_parse (void)
args->bInhibitSplash |= pArgDescr[j].bInhibitSplash; args->bInhibitSplash |= pArgDescr[j].bInhibitSplash;
args->bInhibitPagein |= pArgDescr[j].bInhibitPagein; args->bInhibitPagein |= pArgDescr[j].bInhibitPagein;
args->bInhibitJavaLdx |= pArgDescr[j].bInhibitJavaLdx; args->bInhibitJavaLdx |= pArgDescr[j].bInhibitJavaLdx;
args->bInhibitPipe |= pArgDescr[j].bInhibitPipe;
if (pArgDescr[j].pPageinType) if (pArgDescr[j].pPageinType)
args->pPageinType = pArgDescr[j].pPageinType; args->pPageinType = pArgDescr[j].pPageinType;
break; break;
......
...@@ -38,6 +38,7 @@ typedef struct { ...@@ -38,6 +38,7 @@ typedef struct {
sal_Bool bInhibitSplash; // should we show a splash screen sal_Bool bInhibitSplash; // should we show a splash screen
sal_Bool bInhibitPagein; // should we run pagein ? sal_Bool bInhibitPagein; // should we run pagein ?
sal_Bool bInhibitJavaLdx; // should we run javaldx ? sal_Bool bInhibitJavaLdx; // should we run javaldx ?
sal_Bool bInhibitPipe; // for --help and --version
sal_uInt32 nArgsEnv; // number of -env: style args sal_uInt32 nArgsEnv; // number of -env: style args
sal_uInt32 nArgsTotal; // number of -env: as well as -writer style args sal_uInt32 nArgsTotal; // number of -env: as well as -writer style args
......
...@@ -831,21 +831,24 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv ) ...@@ -831,21 +831,24 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv )
if ( pUsePlugin && !strcmp(pUsePlugin, "svp") ) if ( pUsePlugin && !strcmp(pUsePlugin, "svp") )
args->bInhibitSplash = sal_True; args->bInhibitSplash = sal_True;
pPipePath = get_pipe_path( args->pAppPath ); if ( !args->bInhibitPipe )
if ( ( fd = connect_pipe( pPipePath ) ) >= 0 )
{ {
rtl_uString *pCwdPath = NULL; pPipePath = get_pipe_path( args->pAppPath );
osl_getProcessWorkingDir( &pCwdPath );
if ( ( fd = connect_pipe( pPipePath ) ) >= 0 )
{
rtl_uString *pCwdPath = NULL;
osl_getProcessWorkingDir( &pCwdPath );
bSentArgs = send_args( fd, pCwdPath ); bSentArgs = send_args( fd, pCwdPath );
close( fd ); close( fd );
} }
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
else else
ustr_debug( "Failed to connect to pipe", pPipePath ); ustr_debug( "Failed to connect to pipe", pPipePath );
#endif #endif
}
if ( !bSentArgs ) if ( !bSentArgs )
{ {
...@@ -935,7 +938,8 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv ) ...@@ -935,7 +938,8 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv )
} }
/* cleanup */ /* cleanup */
rtl_uString_release( pPipePath ); if ( pPipePath )
rtl_uString_release( pPipePath );
args_free (args); args_free (args);
return status; return status;
......
...@@ -113,9 +113,9 @@ class VCL_DLLPUBLIC ApplicationEvent ...@@ -113,9 +113,9 @@ class VCL_DLLPUBLIC ApplicationEvent
{ {
public: public:
enum Type { enum Type {
TYPE_ACCEPT, TYPE_APPEAR, TYPE_HELP, TYPE_OPEN, TYPE_OPENHELPURL, TYPE_ACCEPT, TYPE_APPEAR, TYPE_HELP, TYPE_VERSION, TYPE_OPEN,
TYPE_PRINT, TYPE_PRIVATE_DOSHUTDOWN, TYPE_QUICKSTART, TYPE_SHOWDIALOG, TYPE_OPENHELPURL, TYPE_PRINT, TYPE_PRIVATE_DOSHUTDOWN, TYPE_QUICKSTART,
TYPE_UNACCEPT TYPE_SHOWDIALOG, TYPE_UNACCEPT
}; };
ApplicationEvent() {} ApplicationEvent() {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment