Update ooo320-m1
[ooovba.git] / idl / source / prj / command.cxx
blobbbbda71662e133e5289aef21fea30a1098e98c9e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: command.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_idl.hxx"
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <string.h>
37 #include <ctype.h>
39 #include <command.hxx>
40 #include <globals.hxx>
41 #include <database.hxx>
42 #include <tools/fsys.hxx>
44 /*************************************************************************
46 |* Syntaxbeschreibung
48 *************************************************************************/
49 char const * SyntaxStrings[] = {
50 "basic-type:",
51 "\tvoid| char| int| float| double|",
52 "\tUINT16| INT16| UINT32| INT32| BOOL|",
53 "\tBYTE| String| SbxObject",
54 "",
55 "{ import \"filename\" }\n",
56 "module definition:",
57 "module",
58 "\tunique id range (ask MM)",
59 "modul-name",
60 "'['",
61 "\tSlotIdFile( \"filename\" )",
62 "']'",
63 "'{'",
64 "\t{ include \"filename\" }\n",
66 "\titem definition:",
67 "\titem type item-name;\n",
69 "\ttype definition:",
70 "\tstruct | union identifier",
71 "\t'{'",
72 "\t\t{ type idetifier }",
73 "\t'}'",
74 "\t|",
75 "\tenum identifier",
76 "\t'{'",
77 "\t\t{ identifier, }",
78 "\t'}'",
79 "\t|",
80 "\ttypedef type identifier\n",
82 "\titem-method:",
83 "\titem identifier item-method-args\n",
85 "\titem-method-args:",
86 "\t( { item parameter-name SLOT_ID } )\n",
88 "\tslot definition:",
89 "\titem identifier SLOT_ID [ item-method-args ]",
90 "\t'['\n",
92 "\t\titem-method-args",
93 "\t\tAccelConfig, MenuConfig, StatusBarConfig, ToolbarConfig",
94 "\t\tAutomation*",
95 "\t\tAutoUpdate",
96 // "\t\tCachable*, Volatile",
97 "\t\tContainer",
98 "\t\tDefault = Identifier",
99 "\t\tExecMethod = Identifier",
100 "\t\tExport*",
101 "\t\tFastCall",
102 "\t\tGet, Set",
103 "\t\tGroupId = Identifier",
104 "\t\tHasCoreId",
105 "\t\tHasDialog",
106 "\t\tIsCollection",
107 "\t\tImageRotation",
108 "\t\tImageReflection",
109 "\t\tPseudoPrefix = Identifier",
110 "\t\tPseudoSlots",
111 "\t\tReadOnly",
112 "\t\tReadOnlyDoc*",
113 "\t\tRecordPerSet*, RecordPerItem, RecordManual, NoRecord",
114 "\t\tRecordAbsolute",
115 "\t\tStateMethod = Identifier",
116 "\t\tSynchron*, Asynchron",
117 "\t\tToggle",
118 "\t']'\n",
120 "\tinterface definition:",
121 "\tshell | interface identifier ':' interface",
122 "\t'{'",
123 "\t\t{ slot }",
124 "\t'}'\n",
125 "---syntax example is sfx.idl---\n",
126 NULL };
128 char CommandLineSyntax[] =
129 "-fs<slotmap file> -fl<listing file>\n"
130 "-fo<odl file> -fd<data base file>\n"
131 "-fi<item implementation> -ft<type library file> (not OLE)\n"
132 "-fr<ressource file> -fm<makefile target file>\n"
133 "-fC<c++ source file> -fH<c++ header file>\n"
134 "-fc<c source file> -fh<c header file>\n"
135 "-rsc <*.srs header line>\n"
136 "-help, ? @<file> response file\n"
137 " <filenames>\n";
139 /*************************************************************************
141 |* Init()
143 |* Beschreibung
144 |* Ersterstellung MM 15.12.94
145 |* Letzte Aenderung MM 15.12.94
147 *************************************************************************/
148 void Init()
150 if( !IDLAPP->pHashTable )
151 IDLAPP->pHashTable = new SvStringHashTable( 2801 );
152 if( !IDLAPP->pGlobalNames )
153 IDLAPP->pGlobalNames = new SvGlobalHashNames();
156 /*************************************************************************
158 |* DeInit()
160 |* Beschreibung
162 *************************************************************************/
163 void DeInit()
165 delete IDLAPP;
168 /*************************************************************************
170 |* DeInit()
172 |* Beschreibung
174 *************************************************************************/
175 BOOL ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand )
177 for( USHORT n = 0; n < rCommand.aInFileList.Count(); n++ )
179 String aFileName ( *rCommand.aInFileList.GetObject( n ) );
180 SvFileStream aStm( aFileName, STREAM_STD_READ | STREAM_NOCREATE );
181 if( aStm.GetError() == SVSTREAM_OK )
183 if( pDataBase->IsBinaryFormat( aStm ) )
185 pDataBase->Load( aStm );
186 if( aStm.GetError() != SVSTREAM_OK )
188 ByteString aStr;
189 if( aStm.GetError() == SVSTREAM_FILEFORMAT_ERROR )
190 aStr = "error: incompatible format, file ";
191 else if( aStm.GetError() == SVSTREAM_WRONGVERSION )
192 aStr = "error: wrong version, file ";
193 else
194 aStr = "error during load, file ";
195 aStr += ByteString( aFileName, RTL_TEXTENCODING_UTF8 );
196 fprintf( stderr, "%s\n", aStr.GetBuffer() );
197 return FALSE;
200 else
202 SvTokenStream aTokStm( aStm, aFileName );
203 if( !pDataBase->ReadSvIdl( aTokStm, FALSE, rCommand.aPath ) )
204 return FALSE;
207 else
208 return FALSE;
210 return TRUE;
213 /*************************************************************************
215 |* SvCommand::SvCommand()
217 |* Beschreibung
219 *************************************************************************/
220 static BOOL ResponseFile( StringList * pList, int argc, char ** argv )
222 // Programmname
223 pList->Insert( new String( String::CreateFromAscii(*argv) ), LIST_APPEND );
224 for( int i = 1; i < argc; i++ )
226 if( '@' == **(argv +i) )
227 { // wenn @, dann Response-Datei
228 SvFileStream aStm( String::CreateFromAscii((*(argv +i)) +1), STREAM_STD_READ | STREAM_NOCREATE );
229 if( aStm.GetError() != SVSTREAM_OK )
230 return FALSE;
232 ByteString aStr;
233 while( aStm.ReadLine( aStr ) )
235 USHORT n = 0;
236 USHORT nPos = 1;
237 while( n != nPos )
239 while( aStr.GetChar(n) && isspace( aStr.GetChar(n) ) )
240 n++;
241 nPos = n;
242 while( aStr.GetChar(n) && !isspace( aStr.GetChar(n) ) )
243 n++;
244 if( n != nPos )
245 pList->Insert( new String( String::CreateFromAscii( aStr.Copy( nPos, n - nPos ).GetBuffer() ) ), LIST_APPEND );
249 else if( argv[ i ] )
250 pList->Insert( new String( String::CreateFromAscii( argv[ i ] ) ), LIST_APPEND );
252 return TRUE;
255 /*************************************************************************
256 |* SvCommand::SvCommand()
258 |* Beschreibung
259 *************************************************************************/
260 SvCommand::SvCommand( int argc, char ** argv )
261 : nVerbosity(1), nFlags( 0 )
263 StringList aList;
265 if( ResponseFile( &aList, argc, argv ) )
266 for( ULONG i = 1; i < aList.Count(); i++ )
268 String aParam( *aList.GetObject( i ) );
269 sal_Unicode aFirstChar( aParam.GetChar(0) );
270 if( '-' == aFirstChar )
272 aParam.Erase( 0, 1 );
273 aFirstChar = aParam.GetChar(0);
274 if( aFirstChar == 'F' || aFirstChar == 'f' )
276 aParam.Erase( 0, 1 );
277 aFirstChar = aParam.GetChar(0);
278 String aName( aParam.Copy( 1 ) );
279 if( 's' == aFirstChar )
280 { // Name der Slot-Ausgabe
281 aSlotMapFile = aName;
283 else if( 'l' == aFirstChar )
284 { // Name der Listing
285 aListFile = aName;
287 else if( 'i' == aFirstChar )
288 { // Name der Item-Datei
289 // aSfxItemFile = aName;
291 else if( 'o' == aFirstChar )
292 { // Name der ODL-Datei
293 // aODLFile = aName;
295 else if( 'd' == aFirstChar )
296 { // Name der Datenbasis-Datei
297 aDataBaseFile = aName;
299 else if( 'D' == aFirstChar )
300 { // Name der Docu-Datei f"ur das API
301 // aDocuFile = aName;
303 else if( 'C' == aFirstChar )
304 { // Name der cxx-Datei
305 // aCxxFile = aName;
307 else if( 'H' == aFirstChar )
308 { // Name der hxx-Datei
309 // aHxxFile = aName;
311 else if( 'c' == aFirstChar )
312 { // Name der C-Header-Datei
313 // aCSourceFile = aName;
315 else if( 'h' == aFirstChar )
316 { // Name der C-Header-Datei
317 // aCHeaderFile = aName;
319 else if( 't' == aFirstChar )
320 { // Name der Info-Datei
321 // aCallingFile = aName;
323 else if( 'm' == aFirstChar )
324 { // Name der Info-Datei
325 aTargetFile = aName;
327 else if( 'r' == aFirstChar )
328 { // Name der Resource-Datei
329 // aSrcFile = aName;
331 else if( 'z' == aFirstChar )
332 { // Name der HelpId-Datei
333 aHelpIdFile = aName;
335 else if( 'y' == aFirstChar )
336 { // Name der CSV-Datei
337 aCSVFile = aName;
339 else if( 'x' == aFirstChar )
340 { // Name der IDL-Datei fuer die CSV-Datei
341 aExportFile = aName;
343 else
345 printf(
346 "unknown switch: %s\n",
347 rtl::OUStringToOString(
348 aParam, RTL_TEXTENCODING_UTF8).getStr());
349 exit( -1 );
352 else if( aParam.EqualsIgnoreCaseAscii( "help" ) || aParam.EqualsIgnoreCaseAscii( "?" ) )
353 { // Hilfe
354 printf( "%s", CommandLineSyntax );
356 else if( aParam.EqualsIgnoreCaseAscii( "quiet" ) )
358 nVerbosity = 0;
360 else if( aParam.EqualsIgnoreCaseAscii( "verbose" ) )
362 nVerbosity = 2;
364 else if( aParam.EqualsIgnoreCaseAscii( "syntax" ) )
365 { // Hilfe
366 int j = 0;
367 while(SyntaxStrings[j])
368 printf("%s\n",SyntaxStrings[j++]);
370 else if( aParam.EqualsIgnoreCaseAscii( "i", 0, 1 ) )
371 { // Include-Pfade definieren
372 String aName( aParam.Copy( 1 ) );
373 if( aPath.Len() )
374 aPath += DirEntry::GetSearchDelimiter();
375 aPath += aName;
377 else if( aParam.EqualsIgnoreCaseAscii( "rsc", 0, 3 ) )
378 { // erste Zeile im *.srs File
379 if( aList.GetObject( i +1 ) )
381 aSrsLine = ByteString( *aList.GetObject( i +1 ), RTL_TEXTENCODING_UTF8 );
382 i++;
385 else
387 // temporary compatibility hack
388 printf(
389 "unknown switch: %s\n",
390 rtl::OUStringToOString(
391 aParam, RTL_TEXTENCODING_UTF8).getStr());
392 exit( -1 );
395 else
397 aInFileList.Insert( new String( aParam ), LIST_APPEND );
400 else
402 printf( "%s", CommandLineSyntax );
405 String * pStr = aList.First();
406 while( pStr )
408 delete pStr;
409 pStr = aList.Next();
412 ByteString aInc( getenv( "INCLUDE" ) );
413 // Include Environmentvariable anhaengen
414 if( aInc.Len() )
416 if( aPath.Len() )
417 aPath += DirEntry::GetSearchDelimiter();
418 aPath += String::CreateFromAscii( aInc.GetBuffer() );
422 /*************************************************************************
424 |* SvCommand::~SvCommand()
426 |* Beschreibung
428 *************************************************************************/
429 SvCommand::~SvCommand()
431 // ByteString Liste freigeben
432 String * pStr;
433 while( NULL != (pStr = aInFileList.Remove()) )
434 delete pStr;