LibreOffice Module idl (master) 1
command.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <stdlib.h>
23#include <stdio.h>
24
25#include <osl/diagnose.h>
26#include <osl/thread.h>
27#include <rtl/character.hxx>
28
29#include <command.hxx>
30#include <globals.hxx>
31#include <database.hxx>
32#include <parser.hxx>
33
34char 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",
50
51"\titem definition:",
52"\titem type item-name;\n",
53
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",
66
67"\titem-method-args:",
68"\t( { item parameter-name SLOT_ID } )\n",
69
70"\tslot definition:",
71"\titem identifier SLOT_ID [ item-method-args ]",
72"\t'['",
73"\t\tAccelConfig, MenuConfig, ToolbarConfig",
74"\t\tAutoUpdate",
75"\t\tContainer",
76"\t\tExecMethod = Identifier",
77"\t\tFastCall",
78"\t\tGroupId = Identifier",
79"\t\tReadOnlyDoc*",
80"\t\tRecordPerSet*, RecordPerItem, NoRecord",
81"\t\tRecordAbsolute",
82"\t\tStateMethod = Identifier",
83"\t\tAsynchron",
84"\t\tToggle",
85"\t']'\n",
86
87"\tinterface definition:",
88"\tshell | interface identifier ':' interface",
89"\t'{'",
90"\t\t{ slot }",
91"\t'}'\n",
92"---syntax example is sfx.idl---\n",
93nullptr };
94
95char const CommandLineSyntax[] =
96"-fs<slotmap file>\n"
97"-fm<makefile target file>\n"
98"-help, ? @<file> response file\n"
99" <filenames>\n";
100
101void Init()
102{
103 if( !GetIdlApp().pHashTable )
105 if( !GetIdlApp().pGlobalNames )
107}
108
109bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand )
110{
111 for( size_t n = 0; n < rCommand.aInFileList.size(); ++n )
112 {
113 OUString aFileName ( rCommand.aInFileList[ n ] );
114 pDataBase->AddDepFile(aFileName);
115 SvTokenStream aTokStm( aFileName );
116 try {
117 SvIdlParser aParser(*pDataBase, aTokStm);
118 aParser.ReadSvIdl( rCommand.aPath );
119 } catch (const SvParseException& ex) {
120 pDataBase->SetError(ex.aError);
121 pDataBase->WriteError(aTokStm);
122 return false;
123 }
124 }
125 return true;
126}
127
128static bool ResponseFile( std::vector<OUString> * pList, int argc, char ** argv )
129{
130 // program name
131 pList->push_back( OStringToOUString(*argv, osl_getThreadTextEncoding()) );
132 for( int i = 1; i < argc; i++ )
133 {
134 if( '@' == **(argv +i) )
135 { // when @, then response file
136 SvFileStream aStm(
137 OStringToOUString((*(argv +i)) +1, osl_getThreadTextEncoding()),
138 StreamMode::STD_READ );
139 if( aStm.GetError() != ERRCODE_NONE )
140 return false;
141
142 OStringBuffer aStr;
143 while( aStm.ReadLine( aStr ) )
144 {
145 sal_uInt16 n = 0;
146 sal_uInt16 nPos = 1;
147 while( n != nPos )
148 {
149 while( aStr[n]
150 && rtl::isAsciiWhiteSpace(
151 static_cast<unsigned char>(aStr[n]) ) )
152 n++;
153 nPos = n;
154 while( aStr[n]
155 && !rtl::isAsciiWhiteSpace(
156 static_cast<unsigned char>(aStr[n]) ) )
157 n++;
158 if( n != nPos )
159 pList->push_back( OStringToOUString(std::string_view(aStr).substr(nPos, n - nPos), RTL_TEXTENCODING_ASCII_US) );
160 }
161 }
162 }
163 else if( argv[ i ] )
164 pList->push_back( OStringToOUString( argv[ i ], osl_getThreadTextEncoding() ) );
165 }
166 return true;
167}
168
169SvCommand::SvCommand( int argc, char ** argv )
170 : nVerbosity(1)
171{
172 std::vector<OUString> aList;
173
174 if( ResponseFile( &aList, argc, argv ) )
175 {
176 for( size_t i = 1; i < aList.size(); i++ )
177 {
178 OUString aParam( aList[ i ] );
179 sal_Unicode aFirstChar( aParam[0] );
180 if( '-' == aFirstChar )
181 {
182 aParam = aParam.copy( 1 );
183 aFirstChar = aParam[0];
184 if( aFirstChar == 'F' || aFirstChar == 'f' )
185 {
186 aParam = aParam.copy( 1 );
187 aFirstChar = aParam[0];
188 OUString aName( aParam.copy( 1 ) );
189 if( 's' == aFirstChar )
190 { // name of slot output
191 aSlotMapFile = aName;
192 }
193 else if( 'm' == aFirstChar )
194 { // name of info file
195 aTargetFile = aName;
196 }
197 else if( 'x' == aFirstChar )
198 { // name of IDL file for the CSV file
199 aExportFile = aName;
200 }
201 else if( 'M' == aFirstChar )
202 {
203 m_DepFile = aName;
204 }
205 else
206 {
207 printf(
208 "unknown switch: %s\n",
210 aParam, RTL_TEXTENCODING_UTF8).getStr());
211 exit( -1 );
212 }
213 }
214 else if( aParam.equalsIgnoreAsciiCase( "help" ) || aParam.equalsIgnoreAsciiCase( "?" ) )
215 { // help
216 printf( "%s", CommandLineSyntax );
217 }
218 else if( aParam.equalsIgnoreAsciiCase( "quiet" ) )
219 {
220 nVerbosity = 0;
221 }
222 else if( aParam.equalsIgnoreAsciiCase( "verbose" ) )
223 {
224 nVerbosity = 2;
225 }
226 else if( aParam.equalsIgnoreAsciiCase( "syntax" ) )
227 { // help
228 int j = 0;
229 while(SyntaxStrings[j])
230 printf("%s\n",SyntaxStrings[j++]);
231 }
232 else if (aParam == "isystem")
233 {
234 // ignore "-isystem" and following arg
235 if (i < aList.size())
236 {
237 ++i;
238 }
239 }
240 else if (aParam.startsWith("isystem"))
241 {
242 // ignore args starting with "-isystem"
243 }
244 else if( aParam.startsWithIgnoreAsciiCase( "i" ) )
245 { // define include paths
246 OUString aName( aParam.copy( 1 ) );
247 if( !aPath.isEmpty() )
248 aPath += OUStringChar(SAL_PATHSEPARATOR);
249 aPath += aName;
250 }
251 else if( aParam.startsWithIgnoreAsciiCase( "rsc" ) )
252 { // first line in *.srs file
253 OSL_ENSURE(false, "does anything use this option, doesn't look like it belong here");
254 if( !aList[ i + 1 ].isEmpty() )
255 {
256 i++;
257 }
258 }
259 else
260 {
261 // temporary compatibility hack
262 printf(
263 "unknown switch: %s\n",
265 aParam, RTL_TEXTENCODING_UTF8).getStr());
266 exit( -1 );
267 }
268 }
269 else
270 {
271 aInFileList.push_back( aParam );
272 }
273 }
274 }
275 else
276 {
277 printf( "%s", CommandLineSyntax );
278 }
279
280 aList.clear();
281
282 auto const env = getenv("INCLUDE");
283 OString aInc(env == nullptr ? "" : env);
284 // append include environment variable
285 if( aInc.getLength() )
286 {
287 if( !aPath.isEmpty() )
288 aPath += OUStringChar(SAL_PATHSEPARATOR);
289 aPath += OStringToOUString(aInc, RTL_TEXTENCODING_ASCII_US);
290 }
291}
292
293SvCommand::~SvCommand()
294{
295 // release String list
296 aInFileList.clear();
297}
298
299/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< SvStringHashTable > pHashTable
Definition: globals.hxx:71
std::unique_ptr< SvGlobalHashNames > pGlobalNames
Definition: globals.hxx:72
SvCommand(const OUString &rCommand, const OUString &rArg)
void SetError(const SvIdlError &r)
Definition: database.hxx:101
void WriteError(SvTokenStream &rInStm)
Definition: database.cxx:400
void AddDepFile(OUString const &rFileName)
Definition: database.cxx:509
void ReadSvIdl(const OUString &rPath)
Definition: parser.cxx:30
bool ReadLine(OStringBuffer &rStr, sal_Int32 nMaxBytesToRead=0xFFFE)
ErrCode GetError() const
void Init()
Definition: command.cxx:101
bool ReadIdl(SvIdlWorkingBase *pDataBase, const SvCommand &rCommand)
Definition: command.cxx:109
static bool ResponseFile(std::vector< OUString > *pList, int argc, char **argv)
Definition: command.cxx:128
char const CommandLineSyntax[]
Definition: command.cxx:95
char const *const SyntaxStrings[]
Definition: command.cxx:34
#define ERRCODE_NONE
IdlDll & GetIdlApp()
Definition: globals.cxx:24
OUString aName
sal_Int64 n
sal_uInt16 nPos
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment > & env
aStr
int i
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
sal_uInt16 sal_Unicode