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