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 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <stdlib.h>
22 : #include <stdio.h>
23 : #include <string.h>
24 : #include <ctype.h>
25 :
26 : #include <command.hxx>
27 : #include <globals.hxx>
28 : #include <database.hxx>
29 : #include "sal/config.h"
30 :
31 : char const * SyntaxStrings[] = {
32 : "basic-type:",
33 : "\tvoid| char| int| float| double|",
34 : "\tUINT16| INT16| UINT32| INT32| BOOL|",
35 : "\tBYTE| String| SbxObject",
36 : "",
37 : "{ import \"filename\" }\n",
38 : "module definition:",
39 : "module",
40 : "\tunique id range (ask MM)",
41 : "modul-name",
42 : "'['",
43 : "\tSlotIdFile( \"filename\" )",
44 : "']'",
45 : "'{'",
46 : "\t{ include \"filename\" }\n",
47 :
48 : "\titem definition:",
49 : "\titem type item-name;\n",
50 :
51 : "\ttype definition:",
52 : "\tstruct | union identifier",
53 : "\t'{'",
54 : "\t\t{ type idetifier }",
55 : "\t'}'",
56 : "\t|",
57 : "\tenum identifier",
58 : "\t'{'",
59 : "\t\t{ identifier, }",
60 : "\t'}'",
61 : "\t|",
62 : "\ttypedef type identifier\n",
63 :
64 : "\titem-method:",
65 : "\titem identifier item-method-args\n",
66 :
67 : "\titem-method-args:",
68 : "\t( { item parameter-name SLOT_ID } )\n",
69 :
70 : "\tslot definition:",
71 : "\titem identifier SLOT_ID [ item-method-args ]",
72 : "\t'['\n",
73 :
74 : "\t\titem-method-args",
75 : "\t\tAccelConfig, MenuConfig, StatusBarConfig, ToolbarConfig",
76 : "\t\tAutomation*",
77 : "\t\tAutoUpdate",
78 : "\t\tContainer",
79 : "\t\tDefault = Identifier",
80 : "\t\tExecMethod = Identifier",
81 : "\t\tExport*",
82 : "\t\tFastCall",
83 : "\t\tGet, Set",
84 : "\t\tGroupId = Identifier",
85 : "\t\tHasCoreId",
86 : "\t\tHasDialog",
87 : "\t\tIsCollection",
88 : "\t\tImageRotation",
89 : "\t\tImageReflection",
90 : "\t\tPseudoPrefix = Identifier",
91 : "\t\tPseudoSlots",
92 : "\t\tReadOnly",
93 : "\t\tReadOnlyDoc*",
94 : "\t\tRecordPerSet*, RecordPerItem, RecordManual, NoRecord",
95 : "\t\tRecordAbsolute",
96 : "\t\tStateMethod = Identifier",
97 : "\t\tSynchron*, Asynchron",
98 : "\t\tToggle",
99 : "\t']'\n",
100 :
101 : "\tinterface definition:",
102 : "\tshell | interface identifier ':' interface",
103 : "\t'{'",
104 : "\t\t{ slot }",
105 : "\t'}'\n",
106 : "---syntax example is sfx.idl---\n",
107 : NULL };
108 :
109 : char CommandLineSyntax[] =
110 : "-fs<slotmap file>\n"
111 : "-fm<makefile target file>\n"
112 : "-help, ? @<file> response file\n"
113 : " <filenames>\n";
114 :
115 8 : void Init()
116 : {
117 8 : if( !IDLAPP->pHashTable )
118 8 : IDLAPP->pHashTable = new SvStringHashTable( 2801 );
119 8 : if( !IDLAPP->pGlobalNames )
120 8 : IDLAPP->pGlobalNames = new SvGlobalHashNames();
121 8 : }
122 :
123 8 : void DeInit()
124 : {
125 8 : delete IDLAPP;
126 8 : }
127 :
128 8 : bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand )
129 : {
130 16 : for( size_t n = 0; n < rCommand.aInFileList.size(); ++n )
131 : {
132 8 : OUString aFileName ( rCommand.aInFileList[ n ] );
133 8 : pDataBase->AddDepFile(aFileName);
134 16 : SvFileStream aStm( aFileName, STREAM_STD_READ | STREAM_NOCREATE );
135 8 : if( aStm.GetError() == SVSTREAM_OK )
136 : {
137 8 : SvTokenStream aTokStm( aStm, aFileName );
138 8 : if( !pDataBase->ReadSvIdl( aTokStm, false, rCommand.aPath ) )
139 0 : return false;
140 : }
141 : else
142 : {
143 : const OString aStr(OUStringToOString(aFileName,
144 0 : RTL_TEXTENCODING_UTF8));
145 0 : fprintf( stderr, "unable to read input file: %s\n", aStr.getStr() );
146 0 : return false;
147 : }
148 8 : }
149 8 : return true;
150 : }
151 :
152 8 : static bool ResponseFile( StringList * pList, int argc, char ** argv )
153 : {
154 : // program name
155 8 : pList->push_back( OUString::createFromAscii(*argv) );
156 115 : for( int i = 1; i < argc; i++ )
157 : {
158 107 : if( '@' == **(argv +i) )
159 : { // when @, then response file
160 0 : SvFileStream aStm( OUString::createFromAscii((*(argv +i)) +1), STREAM_STD_READ | STREAM_NOCREATE );
161 0 : if( aStm.GetError() != SVSTREAM_OK )
162 0 : return false;
163 :
164 0 : OString aStr;
165 0 : while( aStm.ReadLine( aStr ) )
166 : {
167 0 : sal_uInt16 n = 0;
168 0 : sal_uInt16 nPos = 1;
169 0 : while( n != nPos )
170 : {
171 0 : while( aStr[n] && isspace( aStr[n] ) )
172 0 : n++;
173 0 : nPos = n;
174 0 : while( aStr[n] && !isspace( aStr[n] ) )
175 0 : n++;
176 0 : if( n != nPos )
177 0 : pList->push_back( OStringToOUString(aStr.copy(nPos, n - nPos), RTL_TEXTENCODING_ASCII_US) );
178 : }
179 0 : }
180 : }
181 107 : else if( argv[ i ] )
182 107 : pList->push_back( OUString::createFromAscii( argv[ i ] ) );
183 : }
184 8 : return true;
185 : }
186 :
187 8 : SvCommand::SvCommand( int argc, char ** argv )
188 8 : : nVerbosity(1)
189 : {
190 8 : StringList aList;
191 :
192 8 : if( ResponseFile( &aList, argc, argv ) )
193 : {
194 115 : for( size_t i = 1; i < aList.size(); i++ )
195 : {
196 107 : OUString aParam( aList[ i ] );
197 107 : sal_Unicode aFirstChar( aParam[0] );
198 107 : if( '-' == aFirstChar )
199 : {
200 99 : aParam = aParam.copy( 1 );
201 99 : aFirstChar = aParam[0];
202 99 : if( aFirstChar == 'F' || aFirstChar == 'f' )
203 : {
204 32 : aParam = aParam.copy( 1 );
205 32 : aFirstChar = aParam[0];
206 32 : OUString aName( aParam.copy( 1 ) );
207 32 : if( 's' == aFirstChar )
208 : { // name of slot output
209 8 : aSlotMapFile = aName;
210 : }
211 24 : else if( 'm' == aFirstChar )
212 : { // name of info file
213 8 : aTargetFile = aName;
214 : }
215 16 : else if( 'x' == aFirstChar )
216 : { // name of IDL file for the CSV file
217 8 : aExportFile = aName;
218 : }
219 8 : else if( 'M' == aFirstChar )
220 : {
221 8 : m_DepFile = aName;
222 : }
223 : else
224 : {
225 : printf(
226 : "unknown switch: %s\n",
227 : OUStringToOString(
228 0 : aParam, RTL_TEXTENCODING_UTF8).getStr());
229 0 : exit( -1 );
230 32 : }
231 : }
232 67 : else if( aParam.equalsIgnoreAsciiCase( "help" ) || aParam.equalsIgnoreAsciiCase( "?" ) )
233 : { // help
234 0 : printf( "%s", CommandLineSyntax );
235 : }
236 67 : else if( aParam.equalsIgnoreAsciiCase( "quiet" ) )
237 : {
238 8 : nVerbosity = 0;
239 : }
240 59 : else if( aParam.equalsIgnoreAsciiCase( "verbose" ) )
241 : {
242 0 : nVerbosity = 2;
243 : }
244 59 : else if( aParam.equalsIgnoreAsciiCase( "syntax" ) )
245 : { // help
246 0 : int j = 0;
247 0 : while(SyntaxStrings[j])
248 0 : printf("%s\n",SyntaxStrings[j++]);
249 : }
250 59 : else if (aParam == "isystem")
251 : {
252 : // ignore "-isystem" and following arg
253 0 : if (i < aList.size())
254 : {
255 0 : ++i;
256 : }
257 : }
258 59 : else if (aParam.startsWith("isystem"))
259 : {
260 : // ignore args starting with "-isystem"
261 : }
262 59 : else if( aParam.startsWithIgnoreAsciiCase( "i" ) )
263 : { // define include paths
264 59 : OUString aName( aParam.copy( 1 ) );
265 59 : if( !aPath.isEmpty() )
266 51 : aPath += OUString( SAL_PATHSEPARATOR );
267 59 : aPath += aName;
268 : }
269 0 : else if( aParam.startsWithIgnoreAsciiCase( "rsc" ) )
270 : { // first line in *.srs file
271 : OSL_ENSURE(false, "does anything use this option, doesn't look like it belong here");
272 0 : if( !aList[ i + 1 ].isEmpty() )
273 : {
274 0 : i++;
275 : }
276 : }
277 : else
278 : {
279 : // temporary compatibility hack
280 : printf(
281 : "unknown switch: %s\n",
282 : OUStringToOString(
283 0 : aParam, RTL_TEXTENCODING_UTF8).getStr());
284 0 : exit( -1 );
285 : }
286 : }
287 : else
288 : {
289 8 : aInFileList.push_back( aParam );
290 : }
291 107 : }
292 : }
293 : else
294 : {
295 0 : printf( "%s", CommandLineSyntax );
296 : }
297 :
298 8 : aList.clear();
299 :
300 16 : OString aInc(getenv("INCLUDE"));
301 : // append include environment variable
302 8 : if( aInc.getLength() )
303 : {
304 0 : if( !aPath.isEmpty() )
305 0 : aPath += OUString( SAL_PATHSEPARATOR );
306 0 : aPath += OStringToOUString(aInc, RTL_TEXTENCODING_ASCII_US);
307 8 : }
308 8 : }
309 :
310 16 : SvCommand::~SvCommand()
311 : {
312 : // release String list
313 8 : aInFileList.clear();
314 8 : }
315 :
316 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|