fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / idl / source / prj / command.cxx
blob005c0f05946eb28c22002792bb8b676666d03d4e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <ctype.h>
27 #include <osl/diagnose.h>
29 #include <command.hxx>
30 #include <globals.hxx>
31 #include <database.hxx>
33 char const * SyntaxStrings[] = {
34 "basic-type:",
35 "\tvoid| char| int| float| double|",
36 "\tUINT16| INT16| UINT32| INT32| BOOL|",
37 "\tBYTE| String| SbxObject",
38 "",
39 "{ import \"filename\" }\n",
40 "module definition:",
41 "module",
42 "\tunique id range (ask MM)",
43 "modul-name",
44 "'['",
45 "\tSlotIdFile( \"filename\" )",
46 "']'",
47 "'{'",
48 "\t{ include \"filename\" }\n",
50 "\titem definition:",
51 "\titem type item-name;\n",
53 "\ttype definition:",
54 "\tstruct | union identifier",
55 "\t'{'",
56 "\t\t{ type idetifier }",
57 "\t'}'",
58 "\t|",
59 "\tenum identifier",
60 "\t'{'",
61 "\t\t{ identifier, }",
62 "\t'}'",
63 "\t|",
64 "\ttypedef type identifier\n",
66 "\titem-method:",
67 "\titem identifier item-method-args\n",
69 "\titem-method-args:",
70 "\t( { item parameter-name SLOT_ID } )\n",
72 "\tslot definition:",
73 "\titem identifier SLOT_ID [ item-method-args ]",
74 "\t'['\n",
76 "\t\titem-method-args",
77 "\t\tAccelConfig, MenuConfig, StatusBarConfig, ToolbarConfig",
78 "\t\tAutomation*",
79 "\t\tAutoUpdate",
80 "\t\tContainer",
81 "\t\tDefault = Identifier",
82 "\t\tExecMethod = Identifier",
83 "\t\tExport*",
84 "\t\tFastCall",
85 "\t\tGet, Set",
86 "\t\tGroupId = Identifier",
87 "\t\tHasCoreId",
88 "\t\tHasDialog",
89 "\t\tIsCollection",
90 "\t\tImageRotation",
91 "\t\tImageReflection",
92 "\t\tPseudoPrefix = Identifier",
93 "\t\tPseudoSlots",
94 "\t\tReadOnly",
95 "\t\tReadOnlyDoc*",
96 "\t\tRecordPerSet*, RecordPerItem, RecordManual, NoRecord",
97 "\t\tRecordAbsolute",
98 "\t\tStateMethod = Identifier",
99 "\t\tSynchron*, Asynchron",
100 "\t\tToggle",
101 "\t']'\n",
103 "\tinterface definition:",
104 "\tshell | interface identifier ':' interface",
105 "\t'{'",
106 "\t\t{ slot }",
107 "\t'}'\n",
108 "---syntax example is sfx.idl---\n",
109 NULL };
111 char CommandLineSyntax[] =
112 "-fs<slotmap file>\n"
113 "-fm<makefile target file>\n"
114 "-help, ? @<file> response file\n"
115 " <filenames>\n";
117 void Init()
119 if( !IDLAPP->pHashTable )
120 IDLAPP->pHashTable = new SvStringHashTable( 2801 );
121 if( !IDLAPP->pGlobalNames )
122 IDLAPP->pGlobalNames = new SvGlobalHashNames();
125 void DeInit()
127 delete IDLAPP;
130 bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand )
132 for( size_t n = 0; n < rCommand.aInFileList.size(); ++n )
134 OUString aFileName ( rCommand.aInFileList[ n ] );
135 pDataBase->AddDepFile(aFileName);
136 SvFileStream aStm( aFileName, STREAM_STD_READ | StreamMode::NOCREATE );
137 if( aStm.GetError() == SVSTREAM_OK )
139 SvTokenStream aTokStm( aStm, aFileName );
140 if( !pDataBase->ReadSvIdl( aTokStm, false, rCommand.aPath ) )
141 return false;
143 else
145 const OString aStr(OUStringToOString(aFileName,
146 RTL_TEXTENCODING_UTF8));
147 fprintf( stderr, "unable to read input file: %s\n", aStr.getStr() );
148 return false;
151 return true;
154 static bool ResponseFile( StringList * pList, int argc, char ** argv )
156 // program name
157 pList->push_back( OUString::createFromAscii(*argv) );
158 for( int i = 1; i < argc; i++ )
160 if( '@' == **(argv +i) )
161 { // when @, then response file
162 SvFileStream aStm( OUString::createFromAscii((*(argv +i)) +1), STREAM_STD_READ | StreamMode::NOCREATE );
163 if( aStm.GetError() != SVSTREAM_OK )
164 return false;
166 OString aStr;
167 while( aStm.ReadLine( aStr ) )
169 sal_uInt16 n = 0;
170 sal_uInt16 nPos = 1;
171 while( n != nPos )
173 while( aStr[n] && isspace( aStr[n] ) )
174 n++;
175 nPos = n;
176 while( aStr[n] && !isspace( aStr[n] ) )
177 n++;
178 if( n != nPos )
179 pList->push_back( OStringToOUString(aStr.copy(nPos, n - nPos), RTL_TEXTENCODING_ASCII_US) );
183 else if( argv[ i ] )
184 pList->push_back( OUString::createFromAscii( argv[ i ] ) );
186 return true;
189 SvCommand::SvCommand( int argc, char ** argv )
190 : nVerbosity(1)
192 StringList aList;
194 if( ResponseFile( &aList, argc, argv ) )
196 for( size_t i = 1; i < aList.size(); i++ )
198 OUString aParam( aList[ i ] );
199 sal_Unicode aFirstChar( aParam[0] );
200 if( '-' == aFirstChar )
202 aParam = aParam.copy( 1 );
203 aFirstChar = aParam[0];
204 if( aFirstChar == 'F' || aFirstChar == 'f' )
206 aParam = aParam.copy( 1 );
207 aFirstChar = aParam[0];
208 OUString aName( aParam.copy( 1 ) );
209 if( 's' == aFirstChar )
210 { // name of slot output
211 aSlotMapFile = aName;
213 else if( 'm' == aFirstChar )
214 { // name of info file
215 aTargetFile = aName;
217 else if( 'x' == aFirstChar )
218 { // name of IDL file for the CSV file
219 aExportFile = aName;
221 else if( 'M' == aFirstChar )
223 m_DepFile = aName;
225 else
227 printf(
228 "unknown switch: %s\n",
229 OUStringToOString(
230 aParam, RTL_TEXTENCODING_UTF8).getStr());
231 exit( -1 );
234 else if( aParam.equalsIgnoreAsciiCase( "help" ) || aParam.equalsIgnoreAsciiCase( "?" ) )
235 { // help
236 printf( "%s", CommandLineSyntax );
238 else if( aParam.equalsIgnoreAsciiCase( "quiet" ) )
240 nVerbosity = 0;
242 else if( aParam.equalsIgnoreAsciiCase( "verbose" ) )
244 nVerbosity = 2;
246 else if( aParam.equalsIgnoreAsciiCase( "syntax" ) )
247 { // help
248 int j = 0;
249 while(SyntaxStrings[j])
250 printf("%s\n",SyntaxStrings[j++]);
252 else if (aParam == "isystem")
254 // ignore "-isystem" and following arg
255 if (i < aList.size())
257 ++i;
260 else if (aParam.startsWith("isystem"))
262 // ignore args starting with "-isystem"
264 else if( aParam.startsWithIgnoreAsciiCase( "i" ) )
265 { // define include paths
266 OUString aName( aParam.copy( 1 ) );
267 if( !aPath.isEmpty() )
268 aPath += OUString( SAL_PATHSEPARATOR );
269 aPath += aName;
271 else if( aParam.startsWithIgnoreAsciiCase( "rsc" ) )
272 { // first line in *.srs file
273 OSL_ENSURE(false, "does anything use this option, doesn't look like it belong here");
274 if( !aList[ i + 1 ].isEmpty() )
276 i++;
279 else
281 // temporary compatibility hack
282 printf(
283 "unknown switch: %s\n",
284 OUStringToOString(
285 aParam, RTL_TEXTENCODING_UTF8).getStr());
286 exit( -1 );
289 else
291 aInFileList.push_back( aParam );
295 else
297 printf( "%s", CommandLineSyntax );
300 aList.clear();
302 OString aInc(getenv("INCLUDE"));
303 // append include environment variable
304 if( aInc.getLength() )
306 if( !aPath.isEmpty() )
307 aPath += OUString( SAL_PATHSEPARATOR );
308 aPath += OStringToOUString(aInc, RTL_TEXTENCODING_ASCII_US);
312 SvCommand::~SvCommand()
314 // release String list
315 aInFileList.clear();
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */