LibreOffice Module desktop (master)  1
cmdlinehelp.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <comphelper/string.hxx>
24 #include <sal/types.h>
25 #include <app.hxx>
26 
27 #include "cmdlinehelp.hxx"
28 
29 #ifdef _WIN32
30 #if !defined WIN32_LEAN_AND_MEAN
31 # define WIN32_LEAN_AND_MEAN
32 #endif
33 #include <windows.h>
34 #include <io.h>
35 #include <fcntl.h>
36 #endif
37 
38 namespace desktop
39 {
40  const char aCmdLineHelp_version[] =
41  "%PRODUCTNAME %PRODUCTVERSION%PRODUCTEXTENSION %BUILDID\n"
42  "\n";
43  const char aCmdLineHelp[] =
44  "Usage: %CMDNAME [argument...]\n"
45  " argument - switches, switch parameters and document URIs (filenames). \n\n"
46  "Using without special arguments: \n"
47  "Opens the start center, if it is used without any arguments. \n"
48  " {file} Tries to open the file (files) in the components \n"
49  " suitable for them. \n"
50  " {file} {macro:///Library.Module.MacroName} \n"
51  " Opens the file and runs specified macros from \n"
52  " the file. \n\n"
53  "Getting help and information: \n"
54  " --help | -h | -? Shows this help and quits. \n"
55  " --helpwriter Opens built-in or online Help on Writer. \n"
56  " --helpcalc Opens built-in or online Help on Calc. \n"
57  " --helpdraw Opens built-in or online Help on Draw. \n"
58  " --helpimpress Opens built-in or online Help on Impress. \n"
59  " --helpbase Opens built-in or online Help on Base. \n"
60  " --helpbasic Opens built-in or online Help on Basic scripting \n"
61  " language. \n"
62  " --helpmath Opens built-in or online Help on Math. \n"
63  " --version Shows the version and quits. \n"
64  " --nstemporarydirectory \n"
65  " (MacOS X sandbox only) Returns path of the temporary \n"
66  " directory for the current user and exits. Overrides \n"
67  " all other arguments. \n\n"
68  "General arguments: \n"
69  " --quickstart[=no] Activates[Deactivates] the Quickstarter service. \n"
70  " --nolockcheck Disables check for remote instances using one \n"
71  " installation. \n"
72  " --infilter={filter} Force an input filter type if possible. For example: \n"
73  " --infilter=\"Calc Office Open XML\" \n"
74  " --infilter=\"Text (encoded):UTF8,LF,,,\" \n"
75  " --pidfile={file} Store soffice.bin pid to {file}. \n"
76  " --display {display} Sets the DISPLAY environment variable on UNIX-like \n"
77  " platforms to the value {display} (only supported by a \n"
78  " start script). \n\n"
79  "User/programmatic interface control: \n"
80  " --nologo Disables the splash screen at program start. \n"
81  " --minimized Starts minimized. The splash screen is not displayed. \n"
82  " --nodefault Starts without displaying anything except the splash \n"
83  " screen (do not display initial window). \n"
84  " --invisible Starts in invisible mode. Neither the start-up logo nor \n"
85  " the initial program window will be visible. Application \n"
86  " can be controlled, and documents and dialogs can be \n"
87  " controlled and opened via the API. Using the parameter, \n"
88  " the process can only be ended using the taskmanager \n"
89  " (Windows) or the kill command (UNIX-like systems). It \n"
90  " cannot be used in conjunction with --quickstart. \n"
91  " --headless Starts in \"headless mode\" which allows using the \n"
92  " application without GUI. This special mode can be used \n"
93  " when the application is controlled by external clients \n"
94  " via the API. \n"
95  " --norestore Disables restart and file recovery after a system crash.\n"
96  " --safe-mode Starts in a safe mode, i.e. starts temporarily with a \n"
97  " fresh user profile and helps to restore a broken \n"
98  " configuration. \n"
99  " --accept={UNO-URL} Specifies an UNO-URL connect-string to create an UNO \n"
100  " acceptor through which other programs can connect to \n"
101  " access the API. Note that API access allows execution \n"
102  " of arbitrary commands. \n"
103  " The syntax of an UNO-URL connect-string is: \n"
104  " uno:connection-type,params;protocol-name,params;ObjectName \n"
105  " --unaccept={UNO-URL} Closes an acceptor that was created with --accept. Use \n"
106  " --unaccept=all to close all open acceptors. \n"
107  " --language={lang} Uses specified language, if language is not selected \n"
108  " yet for UI. The lang is a tag of the language in IETF \n"
109  " language tag. \n\n"
110  "Developer arguments: \n"
111  " --terminate_after_init \n"
112  " Exit after initialization complete (no documents loaded)\n"
113  " --eventtesting Exit after loading documents. \n\n"
114  "New document creation arguments: \n"
115  "The arguments create an empty document of specified kind. Only one of them may \n"
116  "be used in one command line. If filenames are specified after an argument, \n"
117  "then it tries to open those files in the specified component. \n"
118  " --writer Creates an empty Writer document. \n"
119  " --calc Creates an empty Calc document. \n"
120  " --draw Creates an empty Draw document. \n"
121  " --impress Creates an empty Impress document. \n"
122  " --base Creates a new database. \n"
123  " --global Creates an empty Writer master (global) document. \n"
124  " --math Creates an empty Math document (formula). \n"
125  " --web Creates an empty HTML document. \n\n"
126  "File open arguments: \n"
127  "The arguments define how following filenames are treated. New treatment begins \n"
128  "after the argument and ends at the next argument. The default treatment is to \n"
129  "open documents for editing, and create new documents from document templates. \n"
130  " -n Treats following files as templates for creation of new \n"
131  " documents. \n"
132  " -o Opens following files for editing, regardless whether \n"
133  " they are templates or not. \n"
134  " --pt {Printername} Prints following files to the printer {Printername}, \n"
135  " after which those files are closed. The splash screen \n"
136  " does not appear. If used multiple times, only last \n"
137  " {Printername} is effective for all documents of all \n"
138  " --pt runs. Also, --printer-name argument of \n"
139  " --print-to-file switch interferes with {Printername}. \n"
140  " -p Prints following files to the default printer, after \n"
141  " which those files are closed. The splash screen does \n"
142  " not appear. If the file name contains spaces, then it \n"
143  " must be enclosed in quotation marks. \n"
144  " --view Opens following files in viewer mode (read-only). \n"
145  " --show Opens and starts the following presentation documents \n"
146  " of each immediately. Files are closed after the showing.\n"
147  " Files other than Impress documents are opened in \n"
148  " default mode , regardless of previous mode. \n"
149  " --convert-to OutputFileExtension[:OutputFilterName] \\ \n"
150  " [--outdir output_dir] [--convert-images-to] \n"
151  " Batch convert files (implies --headless). If --outdir \n"
152  " isn't specified, then current working directory is used \n"
153  " as output_dir. If --convert-images-to is given, its \n"
154  " parameter is taken as the target filter format for *all*\n"
155  " images written to the output format. If --convert-to is \n"
156  " used more than once, the last value of \n"
157  " OutputFileExtension[:OutputFilterName] is effective. If \n"
158  " --outdir is used more than once, only its last value is \n"
159  " effective. For example: \n"
160  " --convert-to pdf *.odt \n"
161  " --convert-to epub *.doc \n"
162  " --convert-to pdf:writer_pdf_Export --outdir /home/user *.doc\n"
163  " --convert-to \"html:XHTML Writer File:UTF8\" \\ \n"
164  " --convert-images-to \"jpg\" *.doc \n"
165  " --convert-to \"txt:Text (encoded):UTF8\" *.doc \n"
166  " --print-to-file [--printer-name printer_name] [--outdir output_dir] \n"
167  " Batch print files to file. If --outdir is not specified,\n"
168  " then current working directory is used as output_dir. \n"
169  " If --printer-name or --outdir used multiple times, only \n"
170  " last value of each is effective. Also, {Printername} of \n"
171  " --pt switch interferes with --printer-name. \n"
172  " --cat Dump text content of the following files to console \n"
173  " (implies --headless). Cannot be used with --convert-to. \n"
174  " --script-cat Dump text content of any scripts embedded in the files \n"
175  " to console (implies --headless). Cannot be used with \n"
176  " --convert-to. \n"
177  " -env:<VAR>[=<VALUE>] Set a bootstrap variable. For example: to set \n"
178  " a non-default user profile path: \n"
179  " -env:UserInstallation=file:///tmp/test \n\n"
180  "Ignored switches: \n"
181  " -psn Ignored (MacOS X only). \n"
182  " -Embedding Ignored (COM+ related; Windows only). \n"
183  " --nofirststartwizard Does nothing, accepted only for backward compatibility.\n"
184  " --protector {arg1} {arg2} \n"
185  " Used only in unit tests and should have two arguments. \n\n";
186 #ifdef _WIN32
187  namespace{
188  // This class is only used to create a console when soffice.bin is run without own console
189  // (like using soffice.exe launcher as opposed to soffice.com), and either --version or
190  // --help command line options were specified, or an error in a command line option was
191  // detected, which requires to output strings to user.
192  class lcl_Console {
193  public:
194  explicit lcl_Console(short nBufHeight)
195  : m_bOwnConsole(AllocConsole() != FALSE)
196  {
197  if (m_bOwnConsole)
198  {
199  HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
200 
201  // Ensure that console buffer is enough to hold required data
202  CONSOLE_SCREEN_BUFFER_INFO cinfo;
203  GetConsoleScreenBufferInfo(hOut, &cinfo);
204  if (cinfo.dwSize.Y < nBufHeight)
205  {
206  cinfo.dwSize.Y = nBufHeight;
207  SetConsoleScreenBufferSize(hOut, cinfo.dwSize);
208  }
209 
210  (void)freopen("CON", "r", stdin);
211  (void)freopen("CON", "w", stdout);
212  (void)freopen("CON", "w", stderr);
213 
214  std::ios::sync_with_stdio(true);
215  }
216  }
217 
218  ~lcl_Console()
219  {
220  if (m_bOwnConsole)
221  {
222  fflush(stdout);
223  fprintf(stdout, "Press Enter to continue...");
224  fgetc(stdin);
225  FreeConsole();
226  }
227  }
228  private:
229  bool m_bOwnConsole;
230  };
231  }
232 #endif
233 
234  void displayCmdlineHelp(OUString const & unknown)
235  {
236  OUString aHelpMessage_version = ReplaceStringHookProc(aCmdLineHelp_version);
237  OUString aHelpMessage(OUString(aCmdLineHelp).replaceFirst("%CMDNAME", "soffice"));
238  if (!unknown.isEmpty())
239  {
240  aHelpMessage = "Error in option: " + unknown + "\n\n"
241  + aHelpMessage;
242  }
243 #ifdef _WIN32
244  sal_Int32 n = comphelper::string::getTokenCount(aHelpMessage, '\n');
245  lcl_Console aConsole(short(n*2));
246 #endif
247  fprintf(stdout, "%s%s",
248  OUStringToOString(aHelpMessage_version, RTL_TEXTENCODING_ASCII_US).getStr(),
249  OUStringToOString(aHelpMessage, RTL_TEXTENCODING_ASCII_US).getStr());
250  }
251 
253  {
254  OUString aVersionMsg(aCmdLineHelp_version);
255  aVersionMsg = ReplaceStringHookProc(aVersionMsg);
256 #ifdef _WIN32
257  lcl_Console aConsole(short(10));
258 #endif
259  fprintf(stdout, "%s", OUStringToOString(aVersionMsg, RTL_TEXTENCODING_ASCII_US).getStr());
260  }
261 }
262 
263 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char aCmdLineHelp[]
Definition: cmdlinehelp.cxx:43
void displayCmdlineHelp(OUString const &unknown)
OUString ReplaceStringHookProc(const OUString &rStr)
Definition: app.cxx:397
Definition: app.cxx:167
void displayVersion()
const char aCmdLineHelp_version[]
Definition: cmdlinehelp.cxx:40
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
#define FALSE
sal_Int32 getTokenCount(const OString &rIn, sal_Char cTok)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo