lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / desktop / unx / source / args.c
blob199b58a8e50e6bcd0ca1edd24b53ad8c7e82e250
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 #include <stdlib.h>
10 #include <string.h>
11 #include <osl/process.h>
13 #include "args.h"
15 /* do we start -env: */
16 static int
17 is_env_arg (rtl_uString const *str)
19 return !rtl_ustr_ascii_compare_WithLength (str->buffer, 5, "-env:");
22 static const struct {
23 const char *name;
24 unsigned int bInhibitSplash : 1;
25 unsigned int bInhibitPagein : 1;
26 unsigned int bInhibitJavaLdx : 1;
27 unsigned int bInhibitPipe : 1;
28 const char *pPageinType;
29 } pArgDescr[] = {
30 /* have a trailing argument */
31 { "pt", 1, 0, 0, 0, NULL },
32 { "p", 1, 0, 0, 0, NULL },
33 { "display", 0, 0, 0, 0, NULL },
35 /* no splash */
36 { "nologo", 1, 0, 0, 0, NULL },
37 { "headless", 1, 0, 0, 0, NULL },
38 { "invisible", 1, 0, 0, 0, NULL },
39 { "quickstart", 1, 0, 0, 0, NULL },
40 { "minimized", 1, 0, 0, 0, NULL },
41 { "convert-to", 1, 0, 0, 0, NULL },
42 { "cat", 1, 0, 0, 0, NULL },
44 /* pagein bits */
45 { "writer", 0, 0, 0, 0, "pagein-writer" },
46 { "calc", 0, 0, 0, 0, "pagein-calc" },
47 { "draw", 0, 0, 0, 0, "pagein-draw" },
48 { "impress", 0, 0, 0, 0, "pagein-impress" },
50 /* Do not send --help/--version over the pipe, as their output shall go to
51 the calling process's stdout (ideally, this would also happen in the
52 presence of unknown options); also prevent splash/pagein/javaldx overhead
53 (as these options will be processed early in soffice_main): */
54 { "version", 1, 1, 1, 1, NULL },
55 { "help", 1, 1, 1, 1, NULL },
56 { "h", 1, 1, 1, 1, NULL },
57 { "?", 1, 1, 1, 1, NULL },
60 Args *args_parse (void)
62 Args *args;
63 sal_uInt32 nArgs, i, j;
65 nArgs = osl_getCommandArgCount();
66 i = sizeof (Args) + sizeof (rtl_uString *) * nArgs;
67 args = malloc (i);
68 memset (args, 0, i);
69 args->nArgsTotal = nArgs;
71 j = 0;
73 /* sort the -env: args to the front */
74 for ( i = 0; i < nArgs; ++i )
76 rtl_uString *pTmp = NULL;
77 osl_getCommandArg( i, &pTmp );
78 if (is_env_arg (pTmp))
79 args->ppArgs[j++] = pTmp;
80 else
81 rtl_uString_release (pTmp);
83 args->nArgsEnv = j;
85 /* Then the other args */
86 for ( i = 0; i < nArgs; ++i )
88 rtl_uString *pTmp = NULL;
90 osl_getCommandArg( i, &pTmp );
91 if (!is_env_arg (pTmp))
92 args->ppArgs[j++] = pTmp;
93 else
94 rtl_uString_release (pTmp);
97 for ( i = args->nArgsEnv; i < args->nArgsTotal; i++ )
99 const sal_Unicode *arg = args->ppArgs[i]->buffer;
100 sal_Int32 length = args->ppArgs[i]->length;
102 /* grok only parameters */
103 if (arg[0] != '-')
104 continue;
106 while (length > 1 && arg[0] == '-') {
107 arg++;
108 length--;
111 for ( j = 0; j < SAL_N_ELEMENTS (pArgDescr); ++j ) {
112 if (rtl_ustr_ascii_compare_WithLength(
113 arg, length, pArgDescr[j].name)
114 == 0)
116 args->bInhibitSplash |= pArgDescr[j].bInhibitSplash;
117 args->bInhibitPagein |= pArgDescr[j].bInhibitPagein;
118 args->bInhibitJavaLdx |= pArgDescr[j].bInhibitJavaLdx;
119 args->bInhibitPipe |= pArgDescr[j].bInhibitPipe;
120 if (pArgDescr[j].pPageinType)
121 args->pPageinType = pArgDescr[j].pPageinType;
122 break;
127 return args;
130 void
131 args_free (Args *args)
133 /* FIXME: free ppArgs */
134 rtl_uString_release( args->pAppPath );
135 free (args);
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */