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>
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>
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",
67 "\titem-method-args:",
68 "\t( { item parameter-name SLOT_ID } )\n",
71 "\titem identifier SLOT_ID [ item-method-args ]",
73 "\t\tAccelConfig, MenuConfig, ToolbarConfig",
76 "\t\tExecMethod = Identifier",
78 "\t\tGroupId = Identifier",
80 "\t\tRecordPerSet*, RecordPerItem, NoRecord",
82 "\t\tStateMethod = Identifier",
87 "\tinterface definition:",
88 "\tshell | interface identifier ':' interface",
92 "---syntax example is sfx.idl---\n",
95 char const CommandLineSyntax
[] =
97 "-fm<makefile target file>\n"
98 "-help, ? @<file> response file\n"
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
);
117 SvIdlParser
aParser(*pDataBase
, aTokStm
);
118 aParser
.ReadSvIdl( rCommand
.aPath
);
119 } catch (const SvParseException
& ex
) {
120 pDataBase
->SetError(ex
.aError
);
121 pDataBase
->WriteError(aTokStm
);
128 static bool ResponseFile( std::vector
<OUString
> * pList
, int argc
, char ** argv
)
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
137 OStringToOUString((*(argv
+i
)) +1, osl_getThreadTextEncoding()),
138 StreamMode::STD_READ
);
139 if( aStm
.GetError() != ERRCODE_NONE
)
143 while( aStm
.ReadLine( aStr
) )
150 && rtl::isAsciiWhiteSpace(
151 static_cast<unsigned char>(aStr
[n
]) ) )
155 && !rtl::isAsciiWhiteSpace(
156 static_cast<unsigned char>(aStr
[n
]) ) )
159 pList
->push_back( OStringToOUString(std::string_view(aStr
).substr(nPos
, n
- nPos
), RTL_TEXTENCODING_ASCII_US
) );
164 pList
->push_back( OStringToOUString( argv
[ i
], osl_getThreadTextEncoding() ) );
169 SvCommand::SvCommand( int argc
, char ** argv
)
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
197 else if( 'x' == aFirstChar
)
198 { // name of IDL file for the CSV file
201 else if( 'M' == aFirstChar
)
208 "unknown switch: %s\n",
210 aParam
, RTL_TEXTENCODING_UTF8
).getStr());
214 else if( aParam
.equalsIgnoreAsciiCase( "help" ) || aParam
.equalsIgnoreAsciiCase( "?" ) )
216 printf( "%s", CommandLineSyntax
);
218 else if( aParam
.equalsIgnoreAsciiCase( "quiet" ) )
222 else if( aParam
.equalsIgnoreAsciiCase( "verbose" ) )
226 else if( aParam
.equalsIgnoreAsciiCase( "syntax" ) )
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())
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
);
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() )
261 // temporary compatibility hack
263 "unknown switch: %s\n",
265 aParam
, RTL_TEXTENCODING_UTF8
).getStr());
271 aInFileList
.push_back( aParam
);
277 printf( "%s", CommandLineSyntax
);
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
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */