1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
35 #include <command.hxx>
36 #include <globals.hxx>
37 #include <database.hxx>
38 #include <tools/fsys.hxx>
40 char const * SyntaxStrings
[] = {
42 "\tvoid| char| int| float| double|",
43 "\tUINT16| INT16| UINT32| INT32| BOOL|",
44 "\tBYTE| String| SbxObject",
46 "{ import \"filename\" }\n",
49 "\tunique id range (ask MM)",
52 "\tSlotIdFile( \"filename\" )",
55 "\t{ include \"filename\" }\n",
58 "\titem type item-name;\n",
61 "\tstruct | union identifier",
63 "\t\t{ type idetifier }",
68 "\t\t{ identifier, }",
71 "\ttypedef type identifier\n",
74 "\titem identifier item-method-args\n",
76 "\titem-method-args:",
77 "\t( { item parameter-name SLOT_ID } )\n",
80 "\titem identifier SLOT_ID [ item-method-args ]",
83 "\t\titem-method-args",
84 "\t\tAccelConfig, MenuConfig, StatusBarConfig, ToolbarConfig",
88 "\t\tDefault = Identifier",
89 "\t\tExecMethod = Identifier",
93 "\t\tGroupId = Identifier",
98 "\t\tImageReflection",
99 "\t\tPseudoPrefix = Identifier",
103 "\t\tRecordPerSet*, RecordPerItem, RecordManual, NoRecord",
104 "\t\tRecordAbsolute",
105 "\t\tStateMethod = Identifier",
106 "\t\tSynchron*, Asynchron",
110 "\tinterface definition:",
111 "\tshell | interface identifier ':' interface",
115 "---syntax example is sfx.idl---\n",
118 char CommandLineSyntax
[] =
119 "-fs<slotmap file> -fl<listing file>\n"
120 "-fo<odl file> -fd<data base file>\n"
121 "-fi<item implementation> -ft<type library file> (not OLE)\n"
122 "-fr<ressource file> -fm<makefile target file>\n"
123 "-fC<c++ source file> -fH<c++ header file>\n"
124 "-fc<c source file> -fh<c header file>\n"
125 "-rsc <*.srs header line>\n"
126 "-help, ? @<file> response file\n"
131 if( !IDLAPP
->pHashTable
)
132 IDLAPP
->pHashTable
= new SvStringHashTable( 2801 );
133 if( !IDLAPP
->pGlobalNames
)
134 IDLAPP
->pGlobalNames
= new SvGlobalHashNames();
142 sal_Bool
ReadIdl( SvIdlWorkingBase
* pDataBase
, const SvCommand
& rCommand
)
144 for( size_t n
= 0; n
< rCommand
.aInFileList
.size(); ++n
)
146 String
aFileName ( *rCommand
.aInFileList
[ n
] );
147 pDataBase
->AddDepFile(aFileName
);
148 SvFileStream
aStm( aFileName
, STREAM_STD_READ
| STREAM_NOCREATE
);
149 if( aStm
.GetError() == SVSTREAM_OK
)
151 if( pDataBase
->IsBinaryFormat( aStm
) )
153 pDataBase
->Load( aStm
);
154 if( aStm
.GetError() != SVSTREAM_OK
)
156 rtl::OStringBuffer aStr
;
157 if( aStm
.GetError() == SVSTREAM_FILEFORMAT_ERROR
)
158 aStr
.append("error: incompatible format, file ");
159 else if( aStm
.GetError() == SVSTREAM_WRONGVERSION
)
160 aStr
.append("error: wrong version, file ");
162 aStr
.append("error during load, file ");
163 aStr
.append(rtl::OUStringToOString(aFileName
,
164 RTL_TEXTENCODING_UTF8
));
165 fprintf( stderr
, "%s\n", aStr
.getStr() );
171 SvTokenStream
aTokStm( aStm
, aFileName
);
172 if( !pDataBase
->ReadSvIdl( aTokStm
, sal_False
, rCommand
.aPath
) )
178 const rtl::OString
aStr(rtl::OUStringToOString(aFileName
,
179 RTL_TEXTENCODING_UTF8
));
180 fprintf( stderr
, "unable to read input file: %s\n", aStr
.getStr() );
187 static sal_Bool
ResponseFile( StringList
* pList
, int argc
, char ** argv
)
190 pList
->push_back( new String( String::CreateFromAscii(*argv
) ) );
191 for( int i
= 1; i
< argc
; i
++ )
193 if( '@' == **(argv
+i
) )
194 { // when @, then response file
195 SvFileStream
aStm( String::CreateFromAscii((*(argv
+i
)) +1), STREAM_STD_READ
| STREAM_NOCREATE
);
196 if( aStm
.GetError() != SVSTREAM_OK
)
200 while( aStm
.ReadLine( aStr
) )
206 while( aStr
[n
] && isspace( aStr
[n
] ) )
209 while( aStr
[n
] && !isspace( aStr
[n
] ) )
212 pList
->push_back( new String( rtl::OStringToOUString(aStr
.copy(nPos
, n
- nPos
), RTL_TEXTENCODING_ASCII_US
) ) );
217 pList
->push_back( new String( String::CreateFromAscii( argv
[ i
] ) ) );
222 SvCommand::SvCommand( int argc
, char ** argv
)
223 : nVerbosity(1), nFlags( 0 )
227 if( ResponseFile( &aList
, argc
, argv
) )
228 for( size_t i
= 1; i
< aList
.size(); i
++ )
230 String
aParam( *aList
[ i
] );
231 sal_Unicode
aFirstChar( aParam
.GetChar(0) );
232 if( '-' == aFirstChar
)
234 aParam
.Erase( 0, 1 );
235 aFirstChar
= aParam
.GetChar(0);
236 if( aFirstChar
== 'F' || aFirstChar
== 'f' )
238 aParam
.Erase( 0, 1 );
239 aFirstChar
= aParam
.GetChar(0);
240 String
aName( aParam
.Copy( 1 ) );
241 if( 's' == aFirstChar
)
242 { // name of slot output
243 aSlotMapFile
= aName
;
245 else if( 'l' == aFirstChar
)
249 else if( 'i' == aFirstChar
)
252 else if( 'o' == aFirstChar
)
255 else if( 'd' == aFirstChar
)
256 { // name of data set file
257 aDataBaseFile
= aName
;
259 else if( 'D' == aFirstChar
)
262 else if( 'C' == aFirstChar
)
265 else if( 'H' == aFirstChar
)
268 else if( 'c' == aFirstChar
)
271 else if( 'h' == aFirstChar
)
274 else if( 't' == aFirstChar
)
277 else if( 'm' == aFirstChar
)
278 { // name of info file
281 else if( 'r' == aFirstChar
)
284 else if( 'z' == aFirstChar
)
285 { // name of HelpId file
288 else if( 'y' == aFirstChar
)
289 { // name of CSV file
292 else if( 'x' == aFirstChar
)
293 { // name of IDL file for the CSV file
296 else if( 'M' == aFirstChar
)
303 "unknown switch: %s\n",
304 rtl::OUStringToOString(
305 aParam
, RTL_TEXTENCODING_UTF8
).getStr());
309 else if( aParam
.EqualsIgnoreCaseAscii( "help" ) || aParam
.EqualsIgnoreCaseAscii( "?" ) )
311 printf( "%s", CommandLineSyntax
);
313 else if( aParam
.EqualsIgnoreCaseAscii( "quiet" ) )
317 else if( aParam
.EqualsIgnoreCaseAscii( "verbose" ) )
321 else if( aParam
.EqualsIgnoreCaseAscii( "syntax" ) )
324 while(SyntaxStrings
[j
])
325 printf("%s\n",SyntaxStrings
[j
++]);
327 else if( aParam
.EqualsIgnoreCaseAscii( "i", 0, 1 ) )
328 { // define include paths
329 String
aName( aParam
.Copy( 1 ) );
331 aPath
+= DirEntry::GetSearchDelimiter();
334 else if( aParam
.EqualsIgnoreCaseAscii( "rsc", 0, 3 ) )
335 { // first line in *.srs file
336 OSL_ENSURE(false, "does anything use this option, doesn't look like it belong here");
344 // temporary compatibility hack
346 "unknown switch: %s\n",
347 rtl::OUStringToOString(
348 aParam
, RTL_TEXTENCODING_UTF8
).getStr());
354 aInFileList
.push_back( new String( aParam
) );
359 printf( "%s", CommandLineSyntax
);
362 for ( size_t i
= 0, n
= aList
.size(); i
< n
; ++i
)
366 rtl::OString
aInc(getenv("INCLUDE"));
367 // append include environment variable
368 if( aInc
.getLength() )
371 aPath
+= DirEntry::GetSearchDelimiter();
372 aPath
+= String::CreateFromAscii( aInc
.getStr() );
376 SvCommand::~SvCommand()
378 // release String list
379 for ( size_t i
= 0, n
= aInFileList
.size(); i
< n
; ++i
)
380 delete aInFileList
[ i
];
384 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */