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