Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / idl / source / prj / command.cxx
blobe73d9615c776ab9a696ff91993a13d4f06f7e70b
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>
25 #include <osl/diagnose.h>
26 #include <osl/thread.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( OStringToOUString(*argv, osl_getThreadTextEncoding()) );
132 for( int i = 1; i < argc; i++ )
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;
142 OStringBuffer aStr;
143 while( aStm.ReadLine( aStr ) )
145 sal_uInt16 n = 0;
146 sal_uInt16 nPos = 1;
147 while( n != nPos )
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) );
163 else if( argv[ i ] )
164 pList->push_back( OStringToOUString( argv[ i ], osl_getThreadTextEncoding() ) );
166 return true;
169 SvCommand::SvCommand( int argc, char ** argv )
170 : nVerbosity(1)
172 std::vector<OUString> aList;
174 if( ResponseFile( &aList, argc, argv ) )
176 for( size_t i = 1; i < aList.size(); i++ )
178 OUString aParam( aList[ i ] );
179 sal_Unicode aFirstChar( aParam[0] );
180 if( '-' == aFirstChar )
182 aParam = aParam.copy( 1 );
183 aFirstChar = aParam[0];
184 if( aFirstChar == 'F' || aFirstChar == 'f' )
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;
193 else if( 'm' == aFirstChar )
194 { // name of info file
195 aTargetFile = aName;
197 else if( 'x' == aFirstChar )
198 { // name of IDL file for the CSV file
199 aExportFile = aName;
201 else if( 'M' == aFirstChar )
203 m_DepFile = aName;
205 else
207 printf(
208 "unknown switch: %s\n",
209 OUStringToOString(
210 aParam, RTL_TEXTENCODING_UTF8).getStr());
211 exit( -1 );
214 else if( aParam.equalsIgnoreAsciiCase( "help" ) || aParam.equalsIgnoreAsciiCase( "?" ) )
215 { // help
216 printf( "%s", CommandLineSyntax );
218 else if( aParam.equalsIgnoreAsciiCase( "quiet" ) )
220 nVerbosity = 0;
222 else if( aParam.equalsIgnoreAsciiCase( "verbose" ) )
224 nVerbosity = 2;
226 else if( aParam.equalsIgnoreAsciiCase( "syntax" ) )
227 { // help
228 int j = 0;
229 while(SyntaxStrings[j])
230 printf("%s\n",SyntaxStrings[j++]);
232 else if (aParam == "isystem")
234 // ignore "-isystem" and following arg
235 if (i < aList.size())
237 ++i;
240 else if (aParam.startsWith("isystem"))
242 // ignore args starting with "-isystem"
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;
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() )
256 i++;
259 else
261 // temporary compatibility hack
262 printf(
263 "unknown switch: %s\n",
264 OUStringToOString(
265 aParam, RTL_TEXTENCODING_UTF8).getStr());
266 exit( -1 );
269 else
271 aInFileList.push_back( aParam );
275 else
277 printf( "%s", CommandLineSyntax );
280 aList.clear();
282 auto const env = getenv("INCLUDE");
283 OString aInc(env == nullptr ? "" : env);
284 // append include environment variable
285 if( aInc.getLength() )
287 if( !aPath.isEmpty() )
288 aPath += OUStringChar(SAL_PATHSEPARATOR);
289 aPath += OStringToOUString(aInc, RTL_TEXTENCODING_ASCII_US);
293 SvCommand::~SvCommand()
295 // release String list
296 aInFileList.clear();
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */