xref: /trunk/main/tools/bootstrp/rscdep.cxx (revision 50e6b0721ed882c1c74690abd9bee6b3a8da8cfd)
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_tools.hxx"
26 #ifdef UNX
27 #include <unistd.h>
28 #endif
29 
30 #include <sys/stat.h>
31 #include <stdio.h>
32 #include <string.h>
33 
34 #include "bootstrp/prj.hxx"
35 #include "sal/main.h"
36 
37 #include <tools/string.hxx>
38 #include <tools/list.hxx>
39 #include <tools/fsys.hxx>
40 #include <tools/stream.hxx>
41 
42 #include "cppdep.hxx"
43 
44 #if defined WNT
45 #if !defined HAVE_GETOPT
46 #define __STDC__ 1
47 #define __GNU_LIBRARY__
48 #include <external/glibc/getopt.h>
49 #else
50 #include <getopt.h>
51 #endif
52 #endif
53 
54 class RscHrcDep : public CppDep
55 {
56 public:
57                     RscHrcDep();
58     virtual         ~RscHrcDep();
59 
60     virtual void    Execute();
61 };
62 
63 RscHrcDep::RscHrcDep()  :
64     CppDep()
65 {
66 }
67 
68 RscHrcDep::~RscHrcDep()
69 {
70 }
71 
72 void RscHrcDep::Execute()
73 {
74     CppDep::Execute();
75 }
76 
77 //static String aDelim;
78 
79 int main( int argc, char** argv )
80 {
81     int c;
82     char aBuf[255];
83     char pFileNamePrefix[255];
84     char pOutputFileName[255];
85     char pSrsFileName[255];
86     String aSrsBaseName;
87     sal_Bool bSource = sal_False;
88     ByteString aRespArg;
89 //  who needs anything but '/' ?
90 //  String aDelim = String(DirEntry::GetAccessDelimiter());
91     String aDelim = '/';
92 
93     RscHrcDep *pDep = new RscHrcDep;
94 
95     pOutputFileName[0] = 0;
96     pSrsFileName[0] = 0;
97 
98     for ( int i=1; i<argc; i++)
99     {
100         strcpy( aBuf, (const char *)argv[i] );
101         if ( aBuf[0] == '-' && aBuf[1] == 'p' && aBuf[2] == '=' )
102         {
103             strcpy(pFileNamePrefix, &aBuf[3]);
104             //break;
105         }
106         if ( aBuf[0] == '-' && aBuf[1] == 'f' && aBuf[2] == 'o' && aBuf[3] == '=' )
107         {
108             strcpy(pOutputFileName, &aBuf[4]);
109             //break;
110         }
111         if ( aBuf[0] == '-' && aBuf[1] == 'f' && aBuf[2] == 'p' && aBuf[3] == '=' )
112         {
113             strcpy(pSrsFileName, &aBuf[4]);
114             String aName( pSrsFileName, gsl_getSystemTextEncoding());
115             DirEntry aDest( aName );
116             aSrsBaseName = aDest.GetBase();
117             //break;
118         }
119         if (aBuf[0] == '-' &&  aBuf[1] == 'i' )
120         {
121             //printf("Include : %s\n", &aBuf[2] );
122             pDep->AddSearchPath( &aBuf[2] );
123         }
124         if (aBuf[0] == '-' &&  aBuf[1] == 'I' )
125         {
126             //printf("Include : %s\n", &aBuf[2] );
127             pDep->AddSearchPath( &aBuf[2] );
128         }
129         if (aBuf[0] == '@' )
130         {
131             ByteString aToken;
132             String aRespName( &aBuf[1], gsl_getSystemTextEncoding());
133             SimpleConfig aConfig( aRespName );
134             while ( (aToken = aConfig.GetNext()) != "")
135             {
136                 char aBuf2[255];
137                 (void) strcpy( aBuf2, aToken.GetBuffer());
138                 if ( aBuf[0] == '-' && aBuf[1] == 'p' && aBuf[2] == '=' )
139                 {
140                     strcpy(pFileNamePrefix, &aBuf[3]);
141                     //break;
142                 }
143                 if ( aBuf2[0] == '-' && aBuf2[1] == 'f' && aBuf2[2] == 'o' )
144                 {
145                     strcpy(pOutputFileName, &aBuf2[3]);
146                     //break;
147                 }
148                 if ( aBuf2[0] == '-' && aBuf2[1] == 'f' && aBuf2[2] == 'p' )
149                 {
150                     strcpy(pSrsFileName, &aBuf2[3]);
151                     String aName( pSrsFileName, gsl_getSystemTextEncoding());
152                     DirEntry aDest( aName );
153                     aSrsBaseName = aDest.GetBase();
154                     //break;
155                 }
156                 if (aBuf2[0] == '-' &&  aBuf2[1] == 'i' )
157                 {
158                     //printf("Include : %s\n", &aBuf[2] );
159                     pDep->AddSearchPath( &aBuf2[2] );
160                 }
161                 if (aBuf2[0] == '-' &&  aBuf2[1] == 'I' )
162                 {
163                     //printf("Include : %s\n", &aBuf[2] );
164                     pDep->AddSearchPath( &aBuf2[2] );
165                 }
166                 if (( aBuf2[0] != '-' ) && ( aBuf2[0] != '@' ))
167                 {
168                     pDep->AddSource( &aBuf2[0] );
169                     aRespArg += " ";
170                     aRespArg += &aBuf2[0];
171                     bSource = sal_True;
172                 }
173             }
174         }
175     }
176 
177     while( 1 )
178     {
179         c = getopt( argc, argv,
180         "_abcdefghi:jklmnopqrstuvwxyzABCDEFGHI:JKLMNOPQRSTUVWXYZ1234567890/-+=.\\()\"");
181         if ( c == -1 )
182             break;
183 
184         switch( c )
185         {
186             case 0:
187                 break;
188             case 'a' :
189 #ifdef DEBUG_VERBOSE
190                 printf("option a\n");
191 #endif
192                 break;
193 
194             case 'l' :
195 #ifdef DEBUG_VERBOSE
196                 printf("option l with Value %s\n", optarg );
197 #endif
198                 pDep->AddSource( optarg );
199                 break;
200 
201             case 'h' :
202             case 'H' :
203             case '?' :
204                 printf("RscDep 1.0\n");
205                 break;
206 
207             default:
208 #ifdef DEBUG_VERBOSE
209                 printf("Unknown getopt error\n");
210 #endif
211                 ;
212         }
213     }
214 
215 
216     DirEntry aEntry(".");
217     aEntry.ToAbs();
218 //  String aCwd = aEntry.GetName();
219     String aCwd(pFileNamePrefix, gsl_getSystemTextEncoding());
220 /*  sal_uInt16 nPos;
221 #ifndef UNX
222     while ( (nPos = aCwd.Search('\\') != STRING_NOTFOUND  ))
223 #else
224     while ( (nPos = aCwd.Search('/') != STRING_NOTFOUND  ))
225 #endif
226     {
227         String attt = aCwd.Copy( 0, nPos );
228         aCwd.Erase( 0, nPos );
229     } */
230     SvFileStream aOutStream;
231     String aOutputFileName( pOutputFileName, gsl_getSystemTextEncoding());
232     DirEntry aOutEntry( aOutputFileName );
233     String aOutPath = aOutEntry.GetPath().GetFull();
234 
235     String aFileName( aOutPath );
236     aFileName += aDelim;
237     aFileName += aCwd;
238     aFileName += String(".", gsl_getSystemTextEncoding());
239     aFileName += aSrsBaseName;
240     aFileName += String(".dprr", gsl_getSystemTextEncoding());
241     //fprintf( stderr, "OutFileName : %s \n",aFileName.GetStr());
242     aOutStream.Open( aFileName, STREAM_WRITE );
243 
244     ByteString aString;
245     if ( optind < argc )
246     {
247 #ifdef DEBUG_VERBOSE
248         printf("further arguments : ");
249 #endif
250         aString = ByteString( pSrsFileName );
251         aString.SearchAndReplaceAll('\\', ByteString( aDelim,  RTL_TEXTENCODING_ASCII_US ));
252         aString += ByteString(" : " );
253 
254         while ( optind < argc )
255         {
256             if (!bSource )
257             {
258                 aString += ByteString(" " );
259                 aString += ByteString( argv[optind]);
260                 pDep->AddSource( argv[optind++]);
261             }
262             else
263             {
264                 optind++;
265             }
266         }
267     }
268     aString += aRespArg;
269     pDep->Execute();
270     ByteStringList *pLst = pDep->GetDepList();
271     sal_uIntPtr nCount = pLst->Count();
272     if ( nCount == 0 )
273     {
274         aOutStream.WriteLine( aString );
275     }
276     else
277     {
278         aString += ByteString( "\\" );
279         aOutStream.WriteLine( aString );
280     }
281 
282     for ( sal_uIntPtr j=0; j<nCount; j++ )
283     {
284         ByteString *pStr = pLst->GetObject(j);
285         pStr->SearchAndReplaceAll('\\', ByteString( aDelim,  RTL_TEXTENCODING_ASCII_US ));
286         if ( j != (nCount-1) )
287             *pStr += ByteString( "\\" );
288         aOutStream.WriteLine( *pStr );
289     }
290     delete pDep;
291     aOutStream.Close();
292 
293     return 0;
294 }
295 
296