Branch data 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 : 1588 : is_env_arg (rtl_uString *str)
41 : : {
42 : 1588 : 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 : : const char *pPageinType;
52 : : } pArgDescr[] = {
53 : : /* have a trailing argument */
54 : : { "pt", 1, 0, 0, 0, NULL },
55 : : { "display", 1, 0, 0, 0, NULL },
56 : :
57 : : /* no splash */
58 : : { "nologo", 0, 1, 0, 0, NULL },
59 : : { "headless", 0, 1, 0, 0, NULL },
60 : : { "invisible", 0, 1, 0, 0, NULL },
61 : : { "quickstart", 0, 1, 0, 0, NULL },
62 : : { "minimized", 0, 1, 0, 0, NULL },
63 : :
64 : : /* pagein bits */
65 : : { "writer", 0, 0, 0, 0, "pagein-writer" },
66 : : { "calc", 0, 0, 0, 0, "pagein-calc" },
67 : : { "draw", 0, 0, 0, 0, "pagein-draw" },
68 : : { "impress", 0, 0, 0, 0, "pagein-impress" },
69 : :
70 : : /* nothing much */
71 : : { "version", 0, 1, 1, 1, NULL },
72 : : { "help", 0, 1, 1, 1, NULL },
73 : : { "h", 0, 1, 1, 1, NULL },
74 : : { "?", 0, 1, 1, 1, NULL },
75 : : };
76 : :
77 : 99 : Args *args_parse (void)
78 : : {
79 : : Args *args;
80 : : sal_uInt32 nArgs, i, j;
81 : :
82 : 99 : nArgs = osl_getCommandArgCount();
83 : 99 : i = sizeof (Args) + sizeof (rtl_uString *) * nArgs;
84 : 99 : args = malloc (i);
85 : 99 : memset (args, 0, i);
86 : 99 : args->nArgsTotal = nArgs;
87 : :
88 : 99 : j = 0;
89 : :
90 : : /* sort the -env: args to the front */
91 [ + + ]: 893 : for ( i = 0; i < nArgs; ++i )
92 : : {
93 : 794 : rtl_uString *pTmp = NULL;
94 : 794 : osl_getCommandArg( i, &pTmp );
95 [ + + ]: 794 : if (is_env_arg (pTmp))
96 : 200 : args->ppArgs[j++] = pTmp;
97 : : else
98 : 594 : rtl_uString_release (pTmp);
99 : : }
100 : 99 : args->nArgsEnv = j;
101 : :
102 : : /* Then the other args */
103 [ + + ]: 893 : for ( i = 0; i < nArgs; ++i )
104 : : {
105 : 794 : rtl_uString *pTmp = NULL;
106 : :
107 : 794 : osl_getCommandArg( i, &pTmp );
108 [ + + ]: 794 : if (!is_env_arg (pTmp))
109 : 594 : args->ppArgs[j++] = pTmp;
110 : : else
111 : 200 : rtl_uString_release (pTmp);
112 : : }
113 : :
114 [ + + ]: 693 : for ( i = args->nArgsEnv; i < args->nArgsTotal; i++ )
115 : : {
116 : 594 : const sal_Unicode *arg = args->ppArgs[i]->buffer;
117 : 594 : sal_Int32 length = args->ppArgs[i]->length;
118 : :
119 : : /* grok only parameters */
120 [ - + ]: 594 : if (arg[0] != '-')
121 : 0 : continue;
122 : :
123 [ + - ][ + + ]: 1782 : while (length > 2 && arg[0] == '-') {
124 : 1188 : arg++;
125 : 1188 : length--;
126 : : }
127 : :
128 [ + + ]: 9504 : for ( j = 0; j < SAL_N_ELEMENTS (pArgDescr); ++j ) {
129 [ + + ]: 8910 : if (!rtl_ustr_indexOfAscii_WithLength
130 : 8910 : (arg, length, pArgDescr[j].name, strlen (pArgDescr[j].name))) {
131 : :
132 : 396 : args->bInhibitSplash |= pArgDescr[j].bInhibitSplash;
133 : 396 : args->bInhibitPagein |= pArgDescr[j].bInhibitPagein;
134 : 396 : args->bInhibitJavaLdx |= pArgDescr[j].bInhibitJavaLdx;
135 [ - + ]: 396 : if (pArgDescr[j].pPageinType)
136 : 0 : args->pPageinType = pArgDescr[j].pPageinType;
137 : : }
138 : : }
139 : : }
140 : :
141 : 99 : return args;
142 : : }
143 : :
144 : : void
145 : 99 : args_free (Args *args)
146 : : {
147 : : /* FIXME: free ppArgs */
148 : 99 : rtl_uString_release( args->pAppPath );
149 : 99 : free (args);
150 : 99 : }
151 : :
152 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|