nss: upgrade to release 3.73
[LibreOffice.git] / idl / source / prj / command.cxx
blob35f6e6c28e87503d9ae0b8bec5d0839ee0b7f26c
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-args:",
68 "\t( { item parameter-name SLOT_ID } )\n",
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",
87 "\tinterface definition:",
88 "\tshell | interface identifier ':' interface",
89 "\t'{'",
90 "\t\t{ slot }",
91 "\t'}'\n",
92 "---syntax example is sfx.idl---\n",
93 nullptr };
95 char const CommandLineSyntax[] =
96 "-fs<slotmap file>\n"
97 "-fm<makefile target file>\n"
98 "-help, ? @<file> response file\n"
99 " <filenames>\n";
101 void Init()
103 if( !GetIdlApp().pHashTable )
104 GetIdlApp().pHashTable.reset( new SvStringHashTable );
105 if( !GetIdlApp().pGlobalNames )
106 GetIdlApp().pGlobalNames.reset( new SvGlobalHashNames() );
109 bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand )
111 for( size_t n = 0; n < rCommand.aInFileList.size(); ++n )
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;
125 return true;
128 static bool ResponseFile( std::vector<OUString> * pList, int argc, char ** argv )
130 // program name
131 pList->push_back( OUString::createFromAscii(*argv) );
132 for( int i = 1; i < argc; i++ )
134 if( '@' == **(argv +i) )
135 { // when @, then response file
136 SvFileStream aStm( OUString::createFromAscii((*(argv +i)) +1), StreamMode::STD_READ );
137 if( aStm.GetError() != ERRCODE_NONE )
138 return false;
140 OString aStr;
141 while( aStm.ReadLine( aStr ) )
143 sal_uInt16 n = 0;
144 sal_uInt16 nPos = 1;
145 while( n != nPos )
147 while( aStr[n]
148 && rtl::isAsciiWhiteSpace(
149 static_cast<unsigned char>(aStr[n]) ) )
150 n++;
151 nPos = n;
152 while( aStr[n]
153 && !rtl::isAsciiWhiteSpace(
154 static_cast<unsigned char>(aStr[n]) ) )
155 n++;
156 if( n != nPos )
157 pList->push_back( OStringToOUString(aStr.copy(nPos, n - nPos), RTL_TEXTENCODING_ASCII_US) );
161 else if( argv[ i ] )
162 pList->push_back( OUString::createFromAscii( argv[ i ] ) );
164 return true;
167 SvCommand::SvCommand( int argc, char ** argv )
168 : nVerbosity(1)
170 std::vector<OUString> aList;
172 if( ResponseFile( &aList, argc, argv ) )
174 for( size_t i = 1; i < aList.size(); i++ )
176 OUString aParam( aList[ i ] );
177 sal_Unicode aFirstChar( aParam[0] );
178 if( '-' == aFirstChar )
180 aParam = aParam.copy( 1 );
181 aFirstChar = aParam[0];
182 if( aFirstChar == 'F' || aFirstChar == 'f' )
184 aParam = aParam.copy( 1 );
185 aFirstChar = aParam[0];
186 OUString aName( aParam.copy( 1 ) );
187 if( 's' == aFirstChar )
188 { // name of slot output
189 aSlotMapFile = aName;
191 else if( 'm' == aFirstChar )
192 { // name of info file
193 aTargetFile = aName;
195 else if( 'x' == aFirstChar )
196 { // name of IDL file for the CSV file
197 aExportFile = aName;
199 else if( 'M' == aFirstChar )
201 m_DepFile = aName;
203 else
205 printf(
206 "unknown switch: %s\n",
207 OUStringToOString(
208 aParam, RTL_TEXTENCODING_UTF8).getStr());
209 exit( -1 );
212 else if( aParam.equalsIgnoreAsciiCase( "help" ) || aParam.equalsIgnoreAsciiCase( "?" ) )
213 { // help
214 printf( "%s", CommandLineSyntax );
216 else if( aParam.equalsIgnoreAsciiCase( "quiet" ) )
218 nVerbosity = 0;
220 else if( aParam.equalsIgnoreAsciiCase( "verbose" ) )
222 nVerbosity = 2;
224 else if( aParam.equalsIgnoreAsciiCase( "syntax" ) )
225 { // help
226 int j = 0;
227 while(SyntaxStrings[j])
228 printf("%s\n",SyntaxStrings[j++]);
230 else if (aParam == "isystem")
232 // ignore "-isystem" and following arg
233 if (i < aList.size())
235 ++i;
238 else if (aParam.startsWith("isystem"))
240 // ignore args starting with "-isystem"
242 else if( aParam.startsWithIgnoreAsciiCase( "i" ) )
243 { // define include paths
244 OUString aName( aParam.copy( 1 ) );
245 if( !aPath.isEmpty() )
246 aPath += OUStringChar(SAL_PATHSEPARATOR);
247 aPath += aName;
249 else if( aParam.startsWithIgnoreAsciiCase( "rsc" ) )
250 { // first line in *.srs file
251 OSL_ENSURE(false, "does anything use this option, doesn't look like it belong here");
252 if( !aList[ i + 1 ].isEmpty() )
254 i++;
257 else
259 // temporary compatibility hack
260 printf(
261 "unknown switch: %s\n",
262 OUStringToOString(
263 aParam, RTL_TEXTENCODING_UTF8).getStr());
264 exit( -1 );
267 else
269 aInFileList.push_back( aParam );
273 else
275 printf( "%s", CommandLineSyntax );
278 aList.clear();
280 OString aInc(getenv("INCLUDE"));
281 // append include environment variable
282 if( aInc.getLength() )
284 if( !aPath.isEmpty() )
285 aPath += OUStringChar(SAL_PATHSEPARATOR);
286 aPath += OStringToOUString(aInc, RTL_TEXTENCODING_ASCII_US);
290 SvCommand::~SvCommand()
292 // release String list
293 aInFileList.clear();
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */