1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
26 #include <osl/diagnose.h>
27 #include <rtl/character.hxx>
29 #include <command.hxx>
30 #include <globals.hxx>
31 #include <database.hxx>
34 char const * const SyntaxStrings
[] = {
36 "\tvoid| char| int| float| double|",
37 "\tUINT16| INT16| UINT32| INT32| BOOL|",
38 "\tBYTE| String| SbxObject",
40 "{ import \"filename\" }\n",
43 "\tunique id range (ask MM)",
46 "\tSlotIdFile( \"filename\" )",
49 "\t{ include \"filename\" }\n",
52 "\titem type item-name;\n",
55 "\tstruct identifier",
57 "\t\t{ type identifier }",
62 "\t\t{ identifier, }",
65 "\ttypedef type identifier\n",
68 "\titem identifier item-method-args\n",
70 "\titem-method-args:",
71 "\t( { item parameter-name SLOT_ID } )\n",
74 "\titem identifier SLOT_ID [ item-method-args ]",
77 "\t\titem-method-args",
78 "\t\tAccelConfig, MenuConfig, ToolbarConfig",
81 "\t\tExecMethod = Identifier",
85 "\t\tGroupId = Identifier",
87 "\t\tRecordPerSet*, RecordPerItem, NoRecord",
89 "\t\tStateMethod = Identifier",
94 "\tinterface definition:",
95 "\tshell | interface identifier ':' interface",
99 "---syntax example is sfx.idl---\n",
102 char const CommandLineSyntax
[] =
103 "-fs<slotmap file>\n"
104 "-fm<makefile target file>\n"
105 "-help, ? @<file> response file\n"
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
);
124 SvIdlParser
aParser(*pDataBase
, aTokStm
);
125 aParser
.ReadSvIdl( rCommand
.aPath
);
126 } catch (const SvParseException
& ex
) {
127 pDataBase
->SetError(ex
.aError
);
128 pDataBase
->WriteError(aTokStm
);
135 static bool ResponseFile( std::vector
<OUString
> * pList
, int argc
, char ** argv
)
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
)
148 while( aStm
.ReadLine( aStr
) )
155 && rtl::isAsciiWhiteSpace(
156 static_cast<unsigned char>(aStr
[n
]) ) )
160 && !rtl::isAsciiWhiteSpace(
161 static_cast<unsigned char>(aStr
[n
]) ) )
164 pList
->push_back( OStringToOUString(aStr
.copy(nPos
, n
- nPos
), RTL_TEXTENCODING_ASCII_US
) );
169 pList
->push_back( OUString::createFromAscii( argv
[ i
] ) );
174 SvCommand::SvCommand( int argc
, char ** argv
)
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
202 else if( 'x' == aFirstChar
)
203 { // name of IDL file for the CSV file
206 else if( 'M' == aFirstChar
)
213 "unknown switch: %s\n",
215 aParam
, RTL_TEXTENCODING_UTF8
).getStr());
219 else if( aParam
.equalsIgnoreAsciiCase( "help" ) || aParam
.equalsIgnoreAsciiCase( "?" ) )
221 printf( "%s", CommandLineSyntax
);
223 else if( aParam
.equalsIgnoreAsciiCase( "quiet" ) )
227 else if( aParam
.equalsIgnoreAsciiCase( "verbose" ) )
231 else if( aParam
.equalsIgnoreAsciiCase( "syntax" ) )
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())
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
);
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() )
266 // temporary compatibility hack
268 "unknown switch: %s\n",
270 aParam
, RTL_TEXTENCODING_UTF8
).getStr());
276 aInFileList
.push_back( aParam
);
282 printf( "%s", CommandLineSyntax
);
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
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */