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 | is_env_arg (rtl_uString *str) |
18 | { |
19 | return !rtl_ustr_ascii_compare_WithLength (str->buffer, 5, "-env:" ); |
20 | } |
21 | |
22 | static struct { |
23 | const char *name; |
24 | unsigned int bTwoArgs : 1; |
25 | unsigned int bInhibitSplash : 1; |
26 | unsigned int bInhibitPagein : 1; |
27 | unsigned int bInhibitJavaLdx : 1; |
28 | unsigned int bInhibitPipe : 1; |
29 | const char *pPageinType; |
30 | } pArgDescr[] = { |
31 | /* have a trailing argument */ |
32 | { "pt" , 1, 0, 0, 0, 0, NULL }, |
33 | { "display" , 1, 0, 0, 0, 0, NULL }, |
34 | |
35 | /* no splash */ |
36 | { "nologo" , 0, 1, 0, 0, 0, NULL }, |
37 | { "headless" , 0, 1, 0, 0, 0, NULL }, |
38 | { "invisible" , 0, 1, 0, 0, 0, NULL }, |
39 | { "quickstart" , 0, 1, 0, 0, 0, NULL }, |
40 | { "minimized" , 0, 1, 0, 0, 0, NULL }, |
41 | |
42 | /* pagein bits */ |
43 | { "writer" , 0, 0, 0, 0, 0, "pagein-writer" }, |
44 | { "calc" , 0, 0, 0, 0, 0, "pagein-calc" }, |
45 | { "draw" , 0, 0, 0, 0, 0, "pagein-draw" }, |
46 | { "impress" , 0, 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" , 0, 1, 1, 1, 1, NULL }, |
53 | { "help" , 0, 1, 1, 1, 1, NULL }, |
54 | { "h" , 0, 1, 1, 1, 1, NULL }, |
55 | { "?" , 0, 1, 1, 1, 1, NULL }, |
56 | }; |
57 | |
58 | Args *args_parse (void) |
59 | { |
60 | Args *args; |
61 | sal_uInt32 nArgs, i, j; |
62 | |
63 | nArgs = osl_getCommandArgCount(); |
64 | i = sizeof (Args) + sizeof (rtl_uString *) * nArgs; |
65 | args = malloc (i); |
66 | memset (args, 0, i); |
67 | args->nArgsTotal = nArgs; |
68 | |
69 | j = 0; |
70 | |
71 | /* sort the -env: args to the front */ |
72 | for ( i = 0; i < nArgs; ++i ) |
73 | { |
74 | rtl_uString *pTmp = NULL; |
75 | osl_getCommandArg( i, &pTmp ); |
76 | if (is_env_arg (pTmp)) |
77 | args->ppArgs[j++] = pTmp; |
78 | else |
79 | rtl_uString_release (pTmp); |
80 | } |
81 | args->nArgsEnv = j; |
82 | |
83 | /* Then the other args */ |
84 | for ( i = 0; i < nArgs; ++i ) |
85 | { |
86 | rtl_uString *pTmp = NULL; |
87 | |
88 | osl_getCommandArg( i, &pTmp ); |
89 | if (!is_env_arg (pTmp)) |
90 | args->ppArgs[j++] = pTmp; |
91 | else |
92 | rtl_uString_release (pTmp); |
93 | } |
94 | |
95 | for ( i = args->nArgsEnv; i < args->nArgsTotal; i++ ) |
96 | { |
97 | const sal_Unicode *arg = args->ppArgs[i]->buffer; |
98 | sal_Int32 length = args->ppArgs[i]->length; |
99 | |
100 | /* grok only parameters */ |
101 | if (arg[0] != '-') |
102 | continue; |
103 | |
104 | while (length > 2 && arg[0] == '-') { |
105 | arg++; |
106 | length--; |
107 | } |
108 | |
109 | for ( j = 0; j < SAL_N_ELEMENTS (pArgDescr); ++j ) { |
110 | if (rtl_ustr_ascii_compare_WithLength( |
111 | arg, length, pArgDescr[j].name) |
112 | == 0) |
113 | { |
114 | args->bInhibitSplash |= pArgDescr[j].bInhibitSplash; |
115 | args->bInhibitPagein |= pArgDescr[j].bInhibitPagein; |
116 | args->bInhibitJavaLdx |= pArgDescr[j].bInhibitJavaLdx; |
117 | args->bInhibitPipe |= pArgDescr[j].bInhibitPipe; |
118 | if (pArgDescr[j].pPageinType) |
119 | args->pPageinType = pArgDescr[j].pPageinType; |
120 | break; |
121 | } |
122 | } |
123 | } |
124 | |
125 | return args; |
126 | } |
127 | |
128 | void |
129 | args_free (Args *args) |
130 | { |
131 | /* FIXME: free ppArgs */ |
132 | rtl_uString_release( args->pAppPath ); |
133 | free (args); |
134 | } |
135 | |
136 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
137 | |