Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Initial Developer of the Original Code is
16 : * Novell, Inc.
17 : * Portions created by the Initial Developer are Copyright (C) 2010 the
18 : * Initial Developer. All Rights Reserved.
19 : *
20 : * Major Contributor(s):
21 : * Michael Meeks <michael.meeks@novell.com>
22 : * Portions created by the Ted are Copyright (C) 2010 Ted. All Rights Reserved.
23 : *
24 : * For minor contributions see the git repository.
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
28 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
29 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
30 : * instead of those above.
31 : */
32 : #include <stdlib.h>
33 : #include <string.h>
34 : #include <osl/process.h>
35 :
36 : #include "args.h"
37 :
38 : /* do we start -env: */
39 : static int
40 0 : is_env_arg (rtl_uString *str)
41 : {
42 0 : return !rtl_ustr_ascii_compare_WithLength (str->buffer, 5, "-env:");
43 : }
44 :
45 : static struct {
46 : const char *name;
47 : unsigned int bTwoArgs : 1;
48 : unsigned int bInhibitSplash : 1;
49 : unsigned int bInhibitPagein : 1;
50 : unsigned int bInhibitJavaLdx : 1;
51 : unsigned int bInhibitPipe : 1;
52 : const char *pPageinType;
53 : } pArgDescr[] = {
54 : /* have a trailing argument */
55 : { "pt", 1, 0, 0, 0, 0, NULL },
56 : { "display", 1, 0, 0, 0, 0, NULL },
57 :
58 : /* no splash */
59 : { "nologo", 0, 1, 0, 0, 0, NULL },
60 : { "headless", 0, 1, 0, 0, 0, NULL },
61 : { "invisible", 0, 1, 0, 0, 0, NULL },
62 : { "quickstart", 0, 1, 0, 0, 0, NULL },
63 : { "minimized", 0, 1, 0, 0, 0, NULL },
64 :
65 : /* pagein bits */
66 : { "writer", 0, 0, 0, 0, 0, "pagein-writer" },
67 : { "calc", 0, 0, 0, 0, 0, "pagein-calc" },
68 : { "draw", 0, 0, 0, 0, 0, "pagein-draw" },
69 : { "impress", 0, 0, 0, 0, 0, "pagein-impress" },
70 :
71 : /* Do not send --help/--version over the pipe, as their output shall go to
72 : the calling process's stdout (ideally, this would also happen in the
73 : presence of unknown options); also prevent splash/pagein/javaldx overhead
74 : (as these options will be processed early in soffice_main): */
75 : { "version", 0, 1, 1, 1, 1, NULL },
76 : { "help", 0, 1, 1, 1, 1, NULL },
77 : { "h", 0, 1, 1, 1, 1, NULL },
78 : { "?", 0, 1, 1, 1, 1, NULL },
79 : };
80 :
81 0 : Args *args_parse (void)
82 : {
83 : Args *args;
84 : sal_uInt32 nArgs, i, j;
85 :
86 0 : nArgs = osl_getCommandArgCount();
87 0 : i = sizeof (Args) + sizeof (rtl_uString *) * nArgs;
88 0 : args = malloc (i);
89 0 : memset (args, 0, i);
90 0 : args->nArgsTotal = nArgs;
91 :
92 0 : j = 0;
93 :
94 : /* sort the -env: args to the front */
95 0 : for ( i = 0; i < nArgs; ++i )
96 : {
97 0 : rtl_uString *pTmp = NULL;
98 0 : osl_getCommandArg( i, &pTmp );
99 0 : if (is_env_arg (pTmp))
100 0 : args->ppArgs[j++] = pTmp;
101 : else
102 0 : rtl_uString_release (pTmp);
103 : }
104 0 : args->nArgsEnv = j;
105 :
106 : /* Then the other args */
107 0 : for ( i = 0; i < nArgs; ++i )
108 : {
109 0 : rtl_uString *pTmp = NULL;
110 :
111 0 : osl_getCommandArg( i, &pTmp );
112 0 : if (!is_env_arg (pTmp))
113 0 : args->ppArgs[j++] = pTmp;
114 : else
115 0 : rtl_uString_release (pTmp);
116 : }
117 :
118 0 : for ( i = args->nArgsEnv; i < args->nArgsTotal; i++ )
119 : {
120 0 : const sal_Unicode *arg = args->ppArgs[i]->buffer;
121 0 : sal_Int32 length = args->ppArgs[i]->length;
122 :
123 : /* grok only parameters */
124 0 : if (arg[0] != '-')
125 0 : continue;
126 :
127 0 : while (length > 2 && arg[0] == '-') {
128 0 : arg++;
129 0 : length--;
130 : }
131 :
132 0 : for ( j = 0; j < SAL_N_ELEMENTS (pArgDescr); ++j ) {
133 0 : if (rtl_ustr_ascii_compare_WithLength(
134 0 : arg, length, pArgDescr[j].name)
135 : == 0)
136 : {
137 0 : args->bInhibitSplash |= pArgDescr[j].bInhibitSplash;
138 0 : args->bInhibitPagein |= pArgDescr[j].bInhibitPagein;
139 0 : args->bInhibitJavaLdx |= pArgDescr[j].bInhibitJavaLdx;
140 0 : args->bInhibitPipe |= pArgDescr[j].bInhibitPipe;
141 0 : if (pArgDescr[j].pPageinType)
142 0 : args->pPageinType = pArgDescr[j].pPageinType;
143 0 : break;
144 : }
145 : }
146 : }
147 :
148 0 : return args;
149 : }
150 :
151 : void
152 0 : args_free (Args *args)
153 : {
154 : /* FIXME: free ppArgs */
155 0 : rtl_uString_release( args->pAppPath );
156 0 : free (args);
157 0 : }
158 :
159 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|