Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / idl / source / prj / command.cxx
blob2e09351d5d6834e54ba6e4195537b9d229dced78
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>
26 #include <osl/diagnose.h>
27 #include <rtl/character.hxx>
29 #include <command.hxx>
30 #include <globals.hxx>
31 #include <database.hxx>
32 #include <parser.hxx>
34 char const * const SyntaxStrings[] = {
35 "basic-type:",
36 "\tvoid| char| int| float| double|",
37 "\tUINT16| INT16| UINT32| INT32| BOOL|",
38 "\tBYTE| String| SbxObject",
39 "",
40 "{ import \"filename\" }\n",
41 "module definition:",
42 "module",
43 "\tunique id range (ask MM)",
44 "modul-name",
45 "'['",
46 "\tSlotIdFile( \"filename\" )",
47 "']'",
48 "'{'",
49 "\t{ include \"filename\" }\n",
51 "\titem definition:",
52 "\titem type item-name;\n",
54 "\ttype definition:",
55 "\tstruct identifier",
56 "\t'{'",
57 "\t\t{ type identifier }",
58 "\t'}'",
59 "\t|",
60 "\tenum identifier",
61 "\t'{'",
62 "\t\t{ identifier, }",
63 "\t'}'",
64 "\t|",
65 "\ttypedef type identifier\n",
67 "\titem-method:",
68 "\titem identifier item-method-args\n",
70 "\titem-method-args:",
71 "\t( { item parameter-name SLOT_ID } )\n",
73 "\tslot definition:",
74 "\titem identifier SLOT_ID [ item-method-args ]",
75 "\t'['\n",
77 "\t\titem-method-args",
78 "\t\tAccelConfig, MenuConfig, ToolbarConfig",
79 "\t\tAutoUpdate",
80 "\t\tContainer",
81 "\t\tExecMethod = Identifier",
82 "\t\tExport*",
83 "\t\tFastCall",
84 "\t\tGet, Set",
85 "\t\tGroupId = Identifier",
86 "\t\tReadOnlyDoc*",
87 "\t\tRecordPerSet*, RecordPerItem, NoRecord",
88 "\t\tRecordAbsolute",
89 "\t\tStateMethod = Identifier",
90 "\t\tAsynchron",
91 "\t\tToggle",
92 "\t']'\n",
94 "\tinterface definition:",
95 "\tshell | interface identifier ':' interface",
96 "\t'{'",
97 "\t\t{ slot }",
98 "\t'}'\n",
99 "---syntax example is sfx.idl---\n",
100 nullptr };
102 char const CommandLineSyntax[] =
103 "-fs<slotmap file>\n"
104 "-fm<makefile target file>\n"
105 "-help, ? @<file> response file\n"
106 " <filenames>\n";
108 void Init()
110 if( !GetIdlApp().pHashTable )
111 GetIdlApp().pHashTable.reset( new SvStringHashTable );
112 if( !GetIdlApp().pGlobalNames )
113 GetIdlApp().pGlobalNames.reset( new SvGlobalHashNames() );
116 bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand )
118 for( size_t n = 0; n < rCommand.aInFileList.size(); ++n )
120 OUString aFileName ( rCommand.aInFileList[ n ] );
121 pDataBase->AddDepFile(aFileName);
122 SvTokenStream aTokStm( aFileName );
123 try {
124 SvIdlParser aParser(*pDataBase, aTokStm);
125 aParser.ReadSvIdl( rCommand.aPath );
126 } catch (const SvParseException& ex) {
127 pDataBase->SetError(ex.aError);
128 pDataBase->WriteError(aTokStm);
129 return false;
132 return true;
135 static bool ResponseFile( std::vector<OUString> * pList, int argc, char ** argv )
137 // program name
138 pList->push_back( OUString::createFromAscii(*argv) );
139 for( int i = 1; i < argc; i++ )
141 if( '@' == **(argv +i) )
142 { // when @, then response file
143 SvFileStream aStm( OUString::createFromAscii((*(argv +i)) +1), StreamMode::STD_READ );
144 if( aStm.GetError() != ERRCODE_NONE )
145 return false;
147 OString aStr;
148 while( aStm.ReadLine( aStr ) )
150 sal_uInt16 n = 0;
151 sal_uInt16 nPos = 1;
152 while( n != nPos )
154 while( aStr[n]
155 && rtl::isAsciiWhiteSpace(
156 static_cast<unsigned char>(aStr[n]) ) )
157 n++;
158 nPos = n;
159 while( aStr[n]
160 && !rtl::isAsciiWhiteSpace(
161 static_cast<unsigned char>(aStr[n]) ) )
162 n++;
163 if( n != nPos )
164 pList->push_back( OStringToOUString(aStr.copy(nPos, n - nPos), RTL_TEXTENCODING_ASCII_US) );
168 else if( argv[ i ] )
169 pList->push_back( OUString::createFromAscii( argv[ i ] ) );
171 return true;
174 SvCommand::SvCommand( int argc, char ** argv )
175 : nVerbosity(1)
177 std::vector<OUString> aList;
179 if( ResponseFile( &aList, argc, argv ) )
181 for( size_t i = 1; i < aList.size(); i++ )
183 OUString aParam( aList[ i ] );
184 sal_Unicode aFirstChar( aParam[0] );
185 if( '-' == aFirstChar )
187 aParam = aParam.copy( 1 );
188 aFirstChar = aParam[0];
189 if( aFirstChar == 'F' || aFirstChar == 'f' )
191 aParam = aParam.copy( 1 );
192 aFirstChar = aParam[0];
193 OUString aName( aParam.copy( 1 ) );
194 if( 's' == aFirstChar )
195 { // name of slot output
196 aSlotMapFile = aName;
198 else if( 'm' == aFirstChar )
199 { // name of info file
200 aTargetFile = aName;
202 else if( 'x' == aFirstChar )
203 { // name of IDL file for the CSV file
204 aExportFile = aName;
206 else if( 'M' == aFirstChar )
208 m_DepFile = aName;
210 else
212 printf(
213 "unknown switch: %s\n",
214 OUStringToOString(
215 aParam, RTL_TEXTENCODING_UTF8).getStr());
216 exit( -1 );
219 else if( aParam.equalsIgnoreAsciiCase( "help" ) || aParam.equalsIgnoreAsciiCase( "?" ) )
220 { // help
221 printf( "%s", CommandLineSyntax );
223 else if( aParam.equalsIgnoreAsciiCase( "quiet" ) )
225 nVerbosity = 0;
227 else if( aParam.equalsIgnoreAsciiCase( "verbose" ) )
229 nVerbosity = 2;
231 else if( aParam.equalsIgnoreAsciiCase( "syntax" ) )
232 { // help
233 int j = 0;
234 while(SyntaxStrings[j])
235 printf("%s\n",SyntaxStrings[j++]);
237 else if (aParam == "isystem")
239 // ignore "-isystem" and following arg
240 if (i < aList.size())
242 ++i;
245 else if (aParam.startsWith("isystem"))
247 // ignore args starting with "-isystem"
249 else if( aParam.startsWithIgnoreAsciiCase( "i" ) )
250 { // define include paths
251 OUString aName( aParam.copy( 1 ) );
252 if( !aPath.isEmpty() )
253 aPath += OUStringChar(SAL_PATHSEPARATOR);
254 aPath += aName;
256 else if( aParam.startsWithIgnoreAsciiCase( "rsc" ) )
257 { // first line in *.srs file
258 OSL_ENSURE(false, "does anything use this option, doesn't look like it belong here");
259 if( !aList[ i + 1 ].isEmpty() )
261 i++;
264 else
266 // temporary compatibility hack
267 printf(
268 "unknown switch: %s\n",
269 OUStringToOString(
270 aParam, RTL_TEXTENCODING_UTF8).getStr());
271 exit( -1 );
274 else
276 aInFileList.push_back( aParam );
280 else
282 printf( "%s", CommandLineSyntax );
285 aList.clear();
287 OString aInc(getenv("INCLUDE"));
288 // append include environment variable
289 if( aInc.getLength() )
291 if( !aPath.isEmpty() )
292 aPath += OUStringChar(SAL_PATHSEPARATOR);
293 aPath += OStringToOUString(aInc, RTL_TEXTENCODING_ASCII_US);
297 SvCommand::~SvCommand()
299 // release String list
300 aInFileList.clear();
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */