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 $
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"
39 #include <command.hxx>
40 #include <globals.hxx>
41 #include <database.hxx>
42 #include <tools/fsys.hxx>
44 /*************************************************************************
48 *************************************************************************/
49 char const * SyntaxStrings
[] = {
51 "\tvoid| char| int| float| double|",
52 "\tUINT16| INT16| UINT32| INT32| BOOL|",
53 "\tBYTE| String| SbxObject",
55 "{ import \"filename\" }\n",
58 "\tunique id range (ask MM)",
61 "\tSlotIdFile( \"filename\" )",
64 "\t{ include \"filename\" }\n",
67 "\titem type item-name;\n",
70 "\tstruct | union identifier",
72 "\t\t{ type idetifier }",
77 "\t\t{ identifier, }",
80 "\ttypedef type identifier\n",
83 "\titem identifier item-method-args\n",
85 "\titem-method-args:",
86 "\t( { item parameter-name SLOT_ID } )\n",
89 "\titem identifier SLOT_ID [ item-method-args ]",
92 "\t\titem-method-args",
93 "\t\tAccelConfig, MenuConfig, StatusBarConfig, ToolbarConfig",
96 // "\t\tCachable*, Volatile",
98 "\t\tDefault = Identifier",
99 "\t\tExecMethod = Identifier",
103 "\t\tGroupId = Identifier",
108 "\t\tImageReflection",
109 "\t\tPseudoPrefix = Identifier",
113 "\t\tRecordPerSet*, RecordPerItem, RecordManual, NoRecord",
114 "\t\tRecordAbsolute",
115 "\t\tStateMethod = Identifier",
116 "\t\tSynchron*, Asynchron",
120 "\tinterface definition:",
121 "\tshell | interface identifier ':' interface",
125 "---syntax example is sfx.idl---\n",
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"
139 /*************************************************************************
144 |* Ersterstellung MM 15.12.94
145 |* Letzte Aenderung MM 15.12.94
147 *************************************************************************/
150 if( !IDLAPP
->pHashTable
)
151 IDLAPP
->pHashTable
= new SvStringHashTable( 2801 );
152 if( !IDLAPP
->pGlobalNames
)
153 IDLAPP
->pGlobalNames
= new SvGlobalHashNames();
156 /*************************************************************************
162 *************************************************************************/
168 /*************************************************************************
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
)
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 ";
194 aStr
= "error during load, file ";
195 aStr
+= ByteString( aFileName
, RTL_TEXTENCODING_UTF8
);
196 fprintf( stderr
, "%s\n", aStr
.GetBuffer() );
202 SvTokenStream
aTokStm( aStm
, aFileName
);
203 if( !pDataBase
->ReadSvIdl( aTokStm
, FALSE
, rCommand
.aPath
) )
213 /*************************************************************************
215 |* SvCommand::SvCommand()
219 *************************************************************************/
220 static BOOL
ResponseFile( StringList
* pList
, int argc
, char ** argv
)
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
)
233 while( aStm
.ReadLine( aStr
) )
239 while( aStr
.GetChar(n
) && isspace( aStr
.GetChar(n
) ) )
242 while( aStr
.GetChar(n
) && !isspace( aStr
.GetChar(n
) ) )
245 pList
->Insert( new String( String::CreateFromAscii( aStr
.Copy( nPos
, n
- nPos
).GetBuffer() ) ), LIST_APPEND
);
250 pList
->Insert( new String( String::CreateFromAscii( argv
[ i
] ) ), LIST_APPEND
);
255 /*************************************************************************
256 |* SvCommand::SvCommand()
259 *************************************************************************/
260 SvCommand::SvCommand( int argc
, char ** argv
)
261 : nVerbosity(1), nFlags( 0 )
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
287 else if( 'i' == aFirstChar
)
288 { // Name der Item-Datei
289 // aSfxItemFile = aName;
291 else if( 'o' == aFirstChar
)
292 { // Name der ODL-Datei
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
307 else if( 'H' == aFirstChar
)
308 { // Name der hxx-Datei
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
327 else if( 'r' == aFirstChar
)
328 { // Name der Resource-Datei
331 else if( 'z' == aFirstChar
)
332 { // Name der HelpId-Datei
335 else if( 'y' == aFirstChar
)
336 { // Name der CSV-Datei
339 else if( 'x' == aFirstChar
)
340 { // Name der IDL-Datei fuer die CSV-Datei
346 "unknown switch: %s\n",
347 rtl::OUStringToOString(
348 aParam
, RTL_TEXTENCODING_UTF8
).getStr());
352 else if( aParam
.EqualsIgnoreCaseAscii( "help" ) || aParam
.EqualsIgnoreCaseAscii( "?" ) )
354 printf( "%s", CommandLineSyntax
);
356 else if( aParam
.EqualsIgnoreCaseAscii( "quiet" ) )
360 else if( aParam
.EqualsIgnoreCaseAscii( "verbose" ) )
364 else if( aParam
.EqualsIgnoreCaseAscii( "syntax" ) )
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 ) );
374 aPath
+= DirEntry::GetSearchDelimiter();
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
);
387 // temporary compatibility hack
389 "unknown switch: %s\n",
390 rtl::OUStringToOString(
391 aParam
, RTL_TEXTENCODING_UTF8
).getStr());
397 aInFileList
.Insert( new String( aParam
), LIST_APPEND
);
402 printf( "%s", CommandLineSyntax
);
405 String
* pStr
= aList
.First();
412 ByteString
aInc( getenv( "INCLUDE" ) );
413 // Include Environmentvariable anhaengen
417 aPath
+= DirEntry::GetSearchDelimiter();
418 aPath
+= String::CreateFromAscii( aInc
.GetBuffer() );
422 /*************************************************************************
424 |* SvCommand::~SvCommand()
428 *************************************************************************/
429 SvCommand::~SvCommand()
431 // ByteString Liste freigeben
433 while( NULL
!= (pStr
= aInFileList
.Remove()) )