Line data Source code
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 : #include <stdlib.h>
10 : #include <string.h>
11 : #include <osl/process.h>
12 :
13 : #include "args.h"
14 :
15 : /* do we start -env: */
16 : static int
17 898 : is_env_arg (rtl_uString *str)
18 : {
19 898 : return !rtl_ustr_ascii_compare_WithLength (str->buffer, 5, "-env:");
20 : }
21 :
22 : static 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", 0, 0, 0, 0, NULL },
32 : { "display", 0, 0, 0, 0, NULL },
33 :
34 : /* no splash */
35 : { "nologo", 1, 0, 0, 0, NULL },
36 : { "headless", 1, 0, 0, 0, NULL },
37 : { "invisible", 1, 0, 0, 0, NULL },
38 : { "quickstart", 1, 0, 0, 0, NULL },
39 : { "minimized", 1, 0, 0, 0, NULL },
40 : { "convert-to", 1, 0, 0, 0, NULL },
41 :
42 : /* pagein bits */
43 : { "writer", 0, 0, 0, 0, "pagein-writer" },
44 : { "calc", 0, 0, 0, 0, "pagein-calc" },
45 : { "draw", 0, 0, 0, 0, "pagein-draw" },
46 : { "impress", 0, 0, 0, 0, "pagein-impress" },
47 :
48 : /* Do not send --help/--version over the pipe, as their output shall go to
49 : the calling process's stdout (ideally, this would also happen in the
50 : presence of unknown options); also prevent splash/pagein/javaldx overhead
51 : (as these options will be processed early in soffice_main): */
52 : { "version", 1, 1, 1, 1, NULL },
53 : { "help", 1, 1, 1, 1, NULL },
54 : { "h", 1, 1, 1, 1, NULL },
55 : { "?", 1, 1, 1, 1, NULL },
56 : };
57 :
58 64 : Args *args_parse (void)
59 : {
60 : Args *args;
61 : sal_uInt32 nArgs, i, j;
62 :
63 64 : nArgs = osl_getCommandArgCount();
64 64 : i = sizeof (Args) + sizeof (rtl_uString *) * nArgs;
65 64 : args = malloc (i);
66 64 : memset (args, 0, i);
67 64 : args->nArgsTotal = nArgs;
68 :
69 64 : j = 0;
70 :
71 : /* sort the -env: args to the front */
72 513 : for ( i = 0; i < nArgs; ++i )
73 : {
74 449 : rtl_uString *pTmp = NULL;
75 449 : osl_getCommandArg( i, &pTmp );
76 449 : if (is_env_arg (pTmp))
77 129 : args->ppArgs[j++] = pTmp;
78 : else
79 320 : rtl_uString_release (pTmp);
80 : }
81 64 : args->nArgsEnv = j;
82 :
83 : /* Then the other args */
84 513 : for ( i = 0; i < nArgs; ++i )
85 : {
86 449 : rtl_uString *pTmp = NULL;
87 :
88 449 : osl_getCommandArg( i, &pTmp );
89 449 : if (!is_env_arg (pTmp))
90 320 : args->ppArgs[j++] = pTmp;
91 : else
92 129 : rtl_uString_release (pTmp);
93 : }
94 :
95 384 : for ( i = args->nArgsEnv; i < args->nArgsTotal; i++ )
96 : {
97 320 : const sal_Unicode *arg = args->ppArgs[i]->buffer;
98 320 : sal_Int32 length = args->ppArgs[i]->length;
99 :
100 : /* grok only parameters */
101 320 : if (arg[0] != '-')
102 0 : continue;
103 :
104 1280 : while (length > 2 && arg[0] == '-') {
105 640 : arg++;
106 640 : length--;
107 : }
108 :
109 3712 : for ( j = 0; j < SAL_N_ELEMENTS (pArgDescr); ++j ) {
110 3520 : if (rtl_ustr_ascii_compare_WithLength(
111 3520 : arg, length, pArgDescr[j].name)
112 : == 0)
113 : {
114 128 : args->bInhibitSplash |= pArgDescr[j].bInhibitSplash;
115 128 : args->bInhibitPagein |= pArgDescr[j].bInhibitPagein;
116 128 : args->bInhibitJavaLdx |= pArgDescr[j].bInhibitJavaLdx;
117 128 : args->bInhibitPipe |= pArgDescr[j].bInhibitPipe;
118 128 : if (pArgDescr[j].pPageinType)
119 0 : args->pPageinType = pArgDescr[j].pPageinType;
120 128 : break;
121 : }
122 : }
123 : }
124 :
125 64 : return args;
126 : }
127 :
128 : void
129 64 : args_free (Args *args)
130 : {
131 : /* FIXME: free ppArgs */
132 64 : rtl_uString_release( args->pAppPath );
133 64 : free (args);
134 64 : }
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|