xref: /trunk/main/idl/source/prj/command.cxx (revision 724893d4)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_idl.hxx"
26 
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <ctype.h>
31 
32 #include <command.hxx>
33 #include <globals.hxx>
34 #include <database.hxx>
35 #include <tools/fsys.hxx>
36 
37 /*************************************************************************
38 |*
39 |*	  Syntaxbeschreibung
40 |*
41 *************************************************************************/
42 char const * SyntaxStrings[] = {
43 "basic-type:",
44 "\tvoid|        char|       int|        float|      double|",
45 "\tUINT16|      INT16|      UINT32|     INT32|      BOOL|",
46 "\tBYTE|        String|     SbxObject",
47 "",
48 "{ import \"filename\" }\n",
49 "module definition:",
50 "module",
51 "\tunique id range (ask MM)",
52 "modul-name",
53 "'['",
54 "\tSlotIdFile( \"filename\" )",
55 "']'",
56 "'{'",
57 "\t{ include \"filename\" }\n",
58 
59 "\titem definition:",
60 "\titem type item-name;\n",
61 
62 "\ttype definition:",
63 "\tstruct | union identifier",
64 "\t'{'",
65 "\t\t{ type idetifier }",
66 "\t'}'",
67 "\t|",
68 "\tenum identifier",
69 "\t'{'",
70 "\t\t{ identifier, }",
71 "\t'}'",
72 "\t|",
73 "\ttypedef type identifier\n",
74 
75 "\titem-method:",
76 "\titem identifier item-method-args\n",
77 
78 "\titem-method-args:",
79 "\t( { item parameter-name SLOT_ID } )\n",
80 
81 "\tslot definition:",
82 "\titem identifier SLOT_ID [ item-method-args ]",
83 "\t'['\n",
84 
85 "\t\titem-method-args",
86 "\t\tAccelConfig, MenuConfig, StatusBarConfig, ToolbarConfig",
87 "\t\tAutomation*",
88 "\t\tAutoUpdate",
89 // "\t\tCachable*, Volatile",
90 "\t\tContainer",
91 "\t\tDefault        = Identifier",
92 "\t\tExecMethod     = Identifier",
93 "\t\tExport*",
94 "\t\tFastCall",
95 "\t\tGet, Set",
96 "\t\tGroupId        = Identifier",
97 "\t\tHasCoreId",
98 "\t\tHasDialog",
99 "\t\tIsCollection",
100 "\t\tImageRotation",
101 "\t\tImageReflection",
102 "\t\tPseudoPrefix   = Identifier",
103 "\t\tPseudoSlots",
104 "\t\tReadOnly",
105 "\t\tReadOnlyDoc*",
106 "\t\tRecordPerSet*, RecordPerItem, RecordManual, NoRecord",
107 "\t\tRecordAbsolute",
108 "\t\tStateMethod    = Identifier",
109 "\t\tSynchron*, Asynchron",
110 "\t\tToggle",
111 "\t']'\n",
112 
113 "\tinterface definition:",
114 "\tshell | interface identifier ':' interface",
115 "\t'{'",
116 "\t\t{ slot }",
117 "\t'}'\n",
118 "---syntax example is sfx.idl---\n",
119 NULL };
120 
121 char CommandLineSyntax[] =
122 "-fs<slotmap file>          -fl<listing file>\n"
123 "-fo<odl file>              -fd<data base file>\n"
124 "-fi<item implementation>   -ft<type library file> (not OLE)\n"
125 "-fr<ressource file>        -fm<makefile target file>\n"
126 "-fC<c++ source file>       -fH<c++ header file>\n"
127 "-fc<c source file>         -fh<c header file>\n"
128 "-rsc <*.srs header line>\n"
129 "-help, ?                   @<file> response file\n"
130 " <filenames>\n";
131 
132 /*************************************************************************
133 |*
134 |*	  Init()
135 |*
136 |*	  Beschreibung
137 |*	  Ersterstellung	MM 15.12.94
138 |*	  Letzte Aenderung	MM 15.12.94
139 |*
140 *************************************************************************/
141 void Init()
142 {
143 	if( !IDLAPP->pHashTable )
144 		IDLAPP->pHashTable		= new SvStringHashTable( 2801 );
145 	if( !IDLAPP->pGlobalNames )
146 		IDLAPP->pGlobalNames	= new SvGlobalHashNames();
147 }
148 
149 /*************************************************************************
150 |*
151 |*	  DeInit()
152 |*
153 |*	  Beschreibung
154 |*
155 *************************************************************************/
156 void DeInit()
157 {
158 	delete IDLAPP;
159 }
160 
161 /*************************************************************************
162 |*
163 |*	  DeInit()
164 |*
165 |*	  Beschreibung
166 |*
167 *************************************************************************/
168 sal_Bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand )
169 {
170 	for( sal_uInt16 n = 0; n < rCommand.aInFileList.Count(); n++ )
171 	{
172         String aFileName ( *rCommand.aInFileList.GetObject( n ) );
173 		SvFileStream aStm( aFileName, STREAM_STD_READ | STREAM_NOCREATE );
174 		if( aStm.GetError() == SVSTREAM_OK )
175 		{
176 			if( pDataBase->IsBinaryFormat( aStm ) )
177 			{
178 				pDataBase->Load( aStm );
179 				if( aStm.GetError() != SVSTREAM_OK )
180 				{
181 					ByteString aStr;
182 					if( aStm.GetError() == SVSTREAM_FILEFORMAT_ERROR )
183 						aStr = "error: incompatible format, file ";
184 					else if( aStm.GetError() == SVSTREAM_WRONGVERSION )
185 						aStr = "error: wrong version, file ";
186 					else
187 						aStr = "error during load, file ";
188                     aStr += ByteString( aFileName, RTL_TEXTENCODING_UTF8 );
189                     fprintf( stderr, "%s\n", aStr.GetBuffer() );
190 					return sal_False;
191 				}
192 			}
193 			else
194 			{
195 				SvTokenStream aTokStm( aStm, aFileName );
196 				if( !pDataBase->ReadSvIdl( aTokStm, sal_False, rCommand.aPath ) )
197 					return sal_False;
198 			}
199 		}
200 		else
201         {
202             const ByteString aStr( aFileName, RTL_TEXTENCODING_UTF8 );
203             fprintf( stderr, "unable to read input file: %s\n", aStr.GetBuffer() );
204 			return sal_False;
205         }
206 	}
207 	return sal_True;
208 }
209 
210 /*************************************************************************
211 |*
212 |*	  SvCommand::SvCommand()
213 |*
214 |*	  Beschreibung
215 |*
216 *************************************************************************/
217 static sal_Bool ResponseFile( StringList * pList, int argc, char ** argv )
218 {
219 	// Programmname
220     pList->Insert( new String( String::CreateFromAscii(*argv) ), LIST_APPEND );
221 	for( int i = 1; i < argc; i++ )
222 	{
223 		if( '@' == **(argv +i) )
224 		{ // wenn @, dann Response-Datei
225             SvFileStream aStm( String::CreateFromAscii((*(argv +i)) +1), STREAM_STD_READ | STREAM_NOCREATE );
226 			if( aStm.GetError() != SVSTREAM_OK )
227 				return sal_False;
228 
229 			ByteString aStr;
230 			while( aStm.ReadLine( aStr ) )
231 			{
232 				sal_uInt16 n = 0;
233 				sal_uInt16 nPos = 1;
234 				while( n != nPos )
235 				{
236                     while( aStr.GetChar(n) && isspace( aStr.GetChar(n) ) )
237 						n++;
238 					nPos = n;
239                     while( aStr.GetChar(n) && !isspace( aStr.GetChar(n) ) )
240 						n++;
241 					if( n != nPos )
242                         pList->Insert( new String( String::CreateFromAscii( aStr.Copy( nPos, n - nPos ).GetBuffer() ) ), LIST_APPEND );
243 				}
244 			}
245 		}
246 		else if( argv[ i ] )
247             pList->Insert( new String( String::CreateFromAscii( argv[ i ] ) ), LIST_APPEND );
248 	}
249 	return sal_True;
250 }
251 
252 /*************************************************************************
253 |*	  SvCommand::SvCommand()
254 |*
255 |*	  Beschreibung
256 *************************************************************************/
257 SvCommand::SvCommand( int argc, char ** argv )
258 	: nVerbosity(1), nFlags( 0 )
259 {
260 	StringList aList;
261 
262 	if( ResponseFile( &aList, argc, argv ) )
263 	for( sal_uLong i = 1; i < aList.Count(); i++ )
264 	{
265         String aParam( *aList.GetObject( i ) );
266         sal_Unicode aFirstChar( aParam.GetChar(0) );
267         if( '-' == aFirstChar )
268 		{
269 			aParam.Erase( 0, 1 );
270             aFirstChar = aParam.GetChar(0);
271             if( aFirstChar == 'F' || aFirstChar == 'f' )
272 			{
273 				aParam.Erase( 0, 1 );
274                 aFirstChar = aParam.GetChar(0);
275                 String aName( aParam.Copy( 1 ) );
276                 if( 's' == aFirstChar )
277 				{ // Name der Slot-Ausgabe
278                     aSlotMapFile = aName;
279 				}
280                 else if( 'l' == aFirstChar )
281 				{ // Name der Listing
282                     aListFile = aName;
283 				}
284                 else if( 'i' == aFirstChar )
285 				{ // Name der Item-Datei
286 //                    aSfxItemFile = aName;
287 				}
288                 else if( 'o' == aFirstChar )
289 				{ // Name der ODL-Datei
290 //                    aODLFile = aName;
291 				}
292                 else if( 'd' == aFirstChar )
293 				{ // Name der Datenbasis-Datei
294                     aDataBaseFile = aName;
295 				}
296                 else if( 'D' == aFirstChar )
297 				{ // Name der Docu-Datei f"ur das API
298 //                    aDocuFile = aName;
299 				}
300                 else if( 'C' == aFirstChar )
301 				{ // Name der cxx-Datei
302 //                    aCxxFile = aName;
303 				}
304                 else if( 'H' == aFirstChar )
305 				{ // Name der hxx-Datei
306 //                    aHxxFile = aName;
307 				}
308                 else if( 'c' == aFirstChar )
309 				{ // Name der C-Header-Datei
310 //                    aCSourceFile = aName;
311 				}
312                 else if( 'h' == aFirstChar )
313 				{ // Name der C-Header-Datei
314 //                    aCHeaderFile = aName;
315 				}
316                 else if( 't' == aFirstChar )
317 				{ // Name der Info-Datei
318 //                    aCallingFile = aName;
319 				}
320                 else if( 'm' == aFirstChar )
321 				{ // Name der Info-Datei
322                     aTargetFile = aName;
323 				}
324                 else if( 'r' == aFirstChar )
325 				{ // Name der Resource-Datei
326 //                    aSrcFile = aName;
327 				}
328                 else if( 'z' == aFirstChar )
329 				{ // Name der HelpId-Datei
330                     aHelpIdFile = aName;
331 				}
332                 else if( 'y' == aFirstChar )
333 				{ // Name der CSV-Datei
334                     aCSVFile = aName;
335 				}
336                 else if( 'x' == aFirstChar )
337 				{ // Name der IDL-Datei fuer die CSV-Datei
338                     aExportFile = aName;
339 				}
340 				else
341 				{
342                     printf(
343                         "unknown switch: %s\n",
344                         rtl::OUStringToOString(
345                             aParam, RTL_TEXTENCODING_UTF8).getStr());
346 					exit( -1 );
347 				}
348 			}
349             else if( aParam.EqualsIgnoreCaseAscii( "help" ) || aParam.EqualsIgnoreCaseAscii( "?" ) )
350 			{ // Hilfe
351                 printf( "%s", CommandLineSyntax );
352 			}
353             else if( aParam.EqualsIgnoreCaseAscii( "quiet" ) )
354             {
355                 nVerbosity = 0;
356             }
357             else if( aParam.EqualsIgnoreCaseAscii( "verbose" ) )
358             {
359                 nVerbosity = 2;
360             }
361             else if( aParam.EqualsIgnoreCaseAscii( "syntax" ) )
362 			{ // Hilfe
363 				int j = 0;
364 				while(SyntaxStrings[j])
365 					printf("%s\n",SyntaxStrings[j++]);
366 			}
367             else if( aParam.EqualsIgnoreCaseAscii( "i", 0, 1 ) )
368 			{ // Include-Pfade definieren
369                 String aName( aParam.Copy( 1 ) );
370 				if( aPath.Len() )
371 					aPath += DirEntry::GetSearchDelimiter();
372                 aPath += aName;
373 			}
374             else if( aParam.EqualsIgnoreCaseAscii( "rsc", 0, 3 ) )
375 			{ // erste Zeile im *.srs File
376 				if( aList.GetObject( i +1 ) )
377 				{
378                     aSrsLine = ByteString( *aList.GetObject( i +1 ), RTL_TEXTENCODING_UTF8 );
379 					i++;
380 				}
381 			}
382 			else
383 			{
384                 // temporary compatibility hack
385                 printf(
386                     "unknown switch: %s\n",
387                     rtl::OUStringToOString(
388                         aParam, RTL_TEXTENCODING_UTF8).getStr());
389 				exit( -1 );
390 			}
391 		}
392 		else
393 		{
394             aInFileList.Insert( new String( aParam ), LIST_APPEND );
395 		}
396 	}
397 	else
398 	{
399         printf( "%s", CommandLineSyntax );
400 	}
401 
402     String * pStr = aList.First();
403 	while( pStr )
404 	{
405 		delete pStr;
406 		pStr = aList.Next();
407 	}
408 
409 	ByteString aInc( getenv( "INCLUDE" ) );
410 	// Include Environmentvariable anhaengen
411 	if( aInc.Len() )
412 	{
413 		if( aPath.Len() )
414 			aPath += DirEntry::GetSearchDelimiter();
415         aPath += String::CreateFromAscii( aInc.GetBuffer() );
416 	}
417 }
418 
419 /*************************************************************************
420 |*
421 |*	  SvCommand::~SvCommand()
422 |*
423 |*	  Beschreibung
424 |*
425 *************************************************************************/
426 SvCommand::~SvCommand()
427 {
428 	// ByteString Liste freigeben
429     String * pStr;
430 	while( NULL != (pStr = aInFileList.Remove()) )
431 		delete pStr;
432 }
433 
434