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>
27 #include <osl/diagnose.h>
29 #include <command.hxx>
30 #include <globals.hxx>
31 #include <database.hxx>
33 char const * SyntaxStrings
[] = {
35 "\tvoid| char| int| float| double|",
36 "\tUINT16| INT16| UINT32| INT32| BOOL|",
37 "\tBYTE| String| SbxObject",
39 "{ import \"filename\" }\n",
42 "\tunique id range (ask MM)",
45 "\tSlotIdFile( \"filename\" )",
48 "\t{ include \"filename\" }\n",
51 "\titem type item-name;\n",
54 "\tstruct | union identifier",
56 "\t\t{ type idetifier }",
61 "\t\t{ identifier, }",
64 "\ttypedef type identifier\n",
67 "\titem identifier item-method-args\n",
69 "\titem-method-args:",
70 "\t( { item parameter-name SLOT_ID } )\n",
73 "\titem identifier SLOT_ID [ item-method-args ]",
76 "\t\titem-method-args",
77 "\t\tAccelConfig, MenuConfig, StatusBarConfig, ToolbarConfig",
81 "\t\tDefault = Identifier",
82 "\t\tExecMethod = Identifier",
86 "\t\tGroupId = Identifier",
91 "\t\tImageReflection",
92 "\t\tPseudoPrefix = Identifier",
96 "\t\tRecordPerSet*, RecordPerItem, RecordManual, NoRecord",
98 "\t\tStateMethod = Identifier",
99 "\t\tSynchron*, Asynchron",
103 "\tinterface definition:",
104 "\tshell | interface identifier ':' interface",
108 "---syntax example is sfx.idl---\n",
111 char CommandLineSyntax
[] =
112 "-fs<slotmap file>\n"
113 "-fm<makefile target file>\n"
114 "-help, ? @<file> response file\n"
119 if( !IDLAPP
->pHashTable
)
120 IDLAPP
->pHashTable
= new SvStringHashTable( 2801 );
121 if( !IDLAPP
->pGlobalNames
)
122 IDLAPP
->pGlobalNames
= new SvGlobalHashNames();
130 bool ReadIdl( SvIdlWorkingBase
* pDataBase
, const SvCommand
& rCommand
)
132 for( size_t n
= 0; n
< rCommand
.aInFileList
.size(); ++n
)
134 OUString
aFileName ( rCommand
.aInFileList
[ n
] );
135 pDataBase
->AddDepFile(aFileName
);
136 SvFileStream
aStm( aFileName
, STREAM_STD_READ
| StreamMode::NOCREATE
);
137 if( aStm
.GetError() == SVSTREAM_OK
)
139 SvTokenStream
aTokStm( aStm
, aFileName
);
140 if( !pDataBase
->ReadSvIdl( aTokStm
, false, rCommand
.aPath
) )
145 const OString
aStr(OUStringToOString(aFileName
,
146 RTL_TEXTENCODING_UTF8
));
147 fprintf( stderr
, "unable to read input file: %s\n", aStr
.getStr() );
154 static bool ResponseFile( StringList
* pList
, int argc
, char ** argv
)
157 pList
->push_back( OUString::createFromAscii(*argv
) );
158 for( int i
= 1; i
< argc
; i
++ )
160 if( '@' == **(argv
+i
) )
161 { // when @, then response file
162 SvFileStream
aStm( OUString::createFromAscii((*(argv
+i
)) +1), STREAM_STD_READ
| StreamMode::NOCREATE
);
163 if( aStm
.GetError() != SVSTREAM_OK
)
167 while( aStm
.ReadLine( aStr
) )
173 while( aStr
[n
] && isspace( aStr
[n
] ) )
176 while( aStr
[n
] && !isspace( aStr
[n
] ) )
179 pList
->push_back( OStringToOUString(aStr
.copy(nPos
, n
- nPos
), RTL_TEXTENCODING_ASCII_US
) );
184 pList
->push_back( OUString::createFromAscii( argv
[ i
] ) );
189 SvCommand::SvCommand( int argc
, char ** argv
)
194 if( ResponseFile( &aList
, argc
, argv
) )
196 for( size_t i
= 1; i
< aList
.size(); i
++ )
198 OUString
aParam( aList
[ i
] );
199 sal_Unicode
aFirstChar( aParam
[0] );
200 if( '-' == aFirstChar
)
202 aParam
= aParam
.copy( 1 );
203 aFirstChar
= aParam
[0];
204 if( aFirstChar
== 'F' || aFirstChar
== 'f' )
206 aParam
= aParam
.copy( 1 );
207 aFirstChar
= aParam
[0];
208 OUString
aName( aParam
.copy( 1 ) );
209 if( 's' == aFirstChar
)
210 { // name of slot output
211 aSlotMapFile
= aName
;
213 else if( 'm' == aFirstChar
)
214 { // name of info file
217 else if( 'x' == aFirstChar
)
218 { // name of IDL file for the CSV file
221 else if( 'M' == aFirstChar
)
228 "unknown switch: %s\n",
230 aParam
, RTL_TEXTENCODING_UTF8
).getStr());
234 else if( aParam
.equalsIgnoreAsciiCase( "help" ) || aParam
.equalsIgnoreAsciiCase( "?" ) )
236 printf( "%s", CommandLineSyntax
);
238 else if( aParam
.equalsIgnoreAsciiCase( "quiet" ) )
242 else if( aParam
.equalsIgnoreAsciiCase( "verbose" ) )
246 else if( aParam
.equalsIgnoreAsciiCase( "syntax" ) )
249 while(SyntaxStrings
[j
])
250 printf("%s\n",SyntaxStrings
[j
++]);
252 else if (aParam
== "isystem")
254 // ignore "-isystem" and following arg
255 if (i
< aList
.size())
260 else if (aParam
.startsWith("isystem"))
262 // ignore args starting with "-isystem"
264 else if( aParam
.startsWithIgnoreAsciiCase( "i" ) )
265 { // define include paths
266 OUString
aName( aParam
.copy( 1 ) );
267 if( !aPath
.isEmpty() )
268 aPath
+= OUString( SAL_PATHSEPARATOR
);
271 else if( aParam
.startsWithIgnoreAsciiCase( "rsc" ) )
272 { // first line in *.srs file
273 OSL_ENSURE(false, "does anything use this option, doesn't look like it belong here");
274 if( !aList
[ i
+ 1 ].isEmpty() )
281 // temporary compatibility hack
283 "unknown switch: %s\n",
285 aParam
, RTL_TEXTENCODING_UTF8
).getStr());
291 aInFileList
.push_back( aParam
);
297 printf( "%s", CommandLineSyntax
);
302 OString
aInc(getenv("INCLUDE"));
303 // append include environment variable
304 if( aInc
.getLength() )
306 if( !aPath
.isEmpty() )
307 aPath
+= OUString( SAL_PATHSEPARATOR
);
308 aPath
+= OStringToOUString(aInc
, RTL_TEXTENCODING_ASCII_US
);
312 SvCommand::~SvCommand()
314 // release String list
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */