Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / idl / source / prj / command.cxx
blob7a7bc82777a85b5d2366031ddb4bdd9babb05f94
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 ************************************************************************/
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <ctype.h>
35 #include <command.hxx>
36 #include <globals.hxx>
37 #include <database.hxx>
38 #include <tools/fsys.hxx>
40 char const * SyntaxStrings[] = {
41 "basic-type:",
42 "\tvoid| char| int| float| double|",
43 "\tUINT16| INT16| UINT32| INT32| BOOL|",
44 "\tBYTE| String| SbxObject",
45 "",
46 "{ import \"filename\" }\n",
47 "module definition:",
48 "module",
49 "\tunique id range (ask MM)",
50 "modul-name",
51 "'['",
52 "\tSlotIdFile( \"filename\" )",
53 "']'",
54 "'{'",
55 "\t{ include \"filename\" }\n",
57 "\titem definition:",
58 "\titem type item-name;\n",
60 "\ttype definition:",
61 "\tstruct | union identifier",
62 "\t'{'",
63 "\t\t{ type idetifier }",
64 "\t'}'",
65 "\t|",
66 "\tenum identifier",
67 "\t'{'",
68 "\t\t{ identifier, }",
69 "\t'}'",
70 "\t|",
71 "\ttypedef type identifier\n",
73 "\titem-method:",
74 "\titem identifier item-method-args\n",
76 "\titem-method-args:",
77 "\t( { item parameter-name SLOT_ID } )\n",
79 "\tslot definition:",
80 "\titem identifier SLOT_ID [ item-method-args ]",
81 "\t'['\n",
83 "\t\titem-method-args",
84 "\t\tAccelConfig, MenuConfig, StatusBarConfig, ToolbarConfig",
85 "\t\tAutomation*",
86 "\t\tAutoUpdate",
87 "\t\tContainer",
88 "\t\tDefault = Identifier",
89 "\t\tExecMethod = Identifier",
90 "\t\tExport*",
91 "\t\tFastCall",
92 "\t\tGet, Set",
93 "\t\tGroupId = Identifier",
94 "\t\tHasCoreId",
95 "\t\tHasDialog",
96 "\t\tIsCollection",
97 "\t\tImageRotation",
98 "\t\tImageReflection",
99 "\t\tPseudoPrefix = Identifier",
100 "\t\tPseudoSlots",
101 "\t\tReadOnly",
102 "\t\tReadOnlyDoc*",
103 "\t\tRecordPerSet*, RecordPerItem, RecordManual, NoRecord",
104 "\t\tRecordAbsolute",
105 "\t\tStateMethod = Identifier",
106 "\t\tSynchron*, Asynchron",
107 "\t\tToggle",
108 "\t']'\n",
110 "\tinterface definition:",
111 "\tshell | interface identifier ':' interface",
112 "\t'{'",
113 "\t\t{ slot }",
114 "\t'}'\n",
115 "---syntax example is sfx.idl---\n",
116 NULL };
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"
127 " <filenames>\n";
129 void Init()
131 if( !IDLAPP->pHashTable )
132 IDLAPP->pHashTable = new SvStringHashTable( 2801 );
133 if( !IDLAPP->pGlobalNames )
134 IDLAPP->pGlobalNames = new SvGlobalHashNames();
137 void DeInit()
139 delete IDLAPP;
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 ");
161 else
162 aStr.append("error during load, file ");
163 aStr.append(rtl::OUStringToOString(aFileName,
164 RTL_TEXTENCODING_UTF8));
165 fprintf( stderr, "%s\n", aStr.getStr() );
166 return sal_False;
169 else
171 SvTokenStream aTokStm( aStm, aFileName );
172 if( !pDataBase->ReadSvIdl( aTokStm, sal_False, rCommand.aPath ) )
173 return sal_False;
176 else
178 const rtl::OString aStr(rtl::OUStringToOString(aFileName,
179 RTL_TEXTENCODING_UTF8));
180 fprintf( stderr, "unable to read input file: %s\n", aStr.getStr() );
181 return sal_False;
184 return sal_True;
187 static sal_Bool ResponseFile( StringList * pList, int argc, char ** argv )
189 // program name
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 )
197 return sal_False;
199 rtl::OString aStr;
200 while( aStm.ReadLine( aStr ) )
202 sal_uInt16 n = 0;
203 sal_uInt16 nPos = 1;
204 while( n != nPos )
206 while( aStr[n] && isspace( aStr[n] ) )
207 n++;
208 nPos = n;
209 while( aStr[n] && !isspace( aStr[n] ) )
210 n++;
211 if( n != nPos )
212 pList->push_back( new String( rtl::OStringToOUString(aStr.copy(nPos, n - nPos), RTL_TEXTENCODING_ASCII_US) ) );
216 else if( argv[ i ] )
217 pList->push_back( new String( String::CreateFromAscii( argv[ i ] ) ) );
219 return sal_True;
222 SvCommand::SvCommand( int argc, char ** argv )
223 : nVerbosity(1), nFlags( 0 )
225 StringList aList;
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 )
246 { // name of listing
247 aListFile = aName;
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
279 aTargetFile = aName;
281 else if( 'r' == aFirstChar )
284 else if( 'z' == aFirstChar )
285 { // name of HelpId file
286 aHelpIdFile = aName;
288 else if( 'y' == aFirstChar )
289 { // name of CSV file
290 aCSVFile = aName;
292 else if( 'x' == aFirstChar )
293 { // name of IDL file for the CSV file
294 aExportFile = aName;
296 else if( 'M' == aFirstChar )
298 m_DepFile = aName;
300 else
302 printf(
303 "unknown switch: %s\n",
304 rtl::OUStringToOString(
305 aParam, RTL_TEXTENCODING_UTF8).getStr());
306 exit( -1 );
309 else if( aParam.EqualsIgnoreCaseAscii( "help" ) || aParam.EqualsIgnoreCaseAscii( "?" ) )
310 { // help
311 printf( "%s", CommandLineSyntax );
313 else if( aParam.EqualsIgnoreCaseAscii( "quiet" ) )
315 nVerbosity = 0;
317 else if( aParam.EqualsIgnoreCaseAscii( "verbose" ) )
319 nVerbosity = 2;
321 else if( aParam.EqualsIgnoreCaseAscii( "syntax" ) )
322 { // help
323 int j = 0;
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 ) );
330 if( aPath.Len() )
331 aPath += DirEntry::GetSearchDelimiter();
332 aPath += aName;
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");
337 if( aList[ i + 1 ] )
339 i++;
342 else
344 // temporary compatibility hack
345 printf(
346 "unknown switch: %s\n",
347 rtl::OUStringToOString(
348 aParam, RTL_TEXTENCODING_UTF8).getStr());
349 exit( -1 );
352 else
354 aInFileList.push_back( new String( aParam ) );
357 else
359 printf( "%s", CommandLineSyntax );
362 for ( size_t i = 0, n = aList.size(); i < n; ++i )
363 delete aList[ i ];
364 aList.clear();
366 rtl::OString aInc(getenv("INCLUDE"));
367 // append include environment variable
368 if( aInc.getLength() )
370 if( aPath.Len() )
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 ];
381 aInFileList.clear();
384 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */