189b56da7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
389b56da7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
489b56da7SAndrew Rist * or more contributor license agreements. See the NOTICE file
589b56da7SAndrew Rist * distributed with this work for additional information
689b56da7SAndrew Rist * regarding copyright ownership. The ASF licenses this file
789b56da7SAndrew Rist * to you under the Apache License, Version 2.0 (the
889b56da7SAndrew Rist * "License"); you may not use this file except in compliance
989b56da7SAndrew Rist * with the License. You may obtain a copy of the License at
1089b56da7SAndrew Rist *
1189b56da7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1289b56da7SAndrew Rist *
1389b56da7SAndrew Rist * Unless required by applicable law or agreed to in writing,
1489b56da7SAndrew Rist * software distributed under the License is distributed on an
1589b56da7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1689b56da7SAndrew Rist * KIND, either express or implied. See the License for the
1789b56da7SAndrew Rist * specific language governing permissions and limitations
1889b56da7SAndrew Rist * under the License.
1989b56da7SAndrew Rist *
2089b56da7SAndrew Rist *************************************************************/
2189b56da7SAndrew Rist
2289b56da7SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_tools.hxx"
2627ead02aSPedro Giffuni #if defined(UNX) || defined(OS2)
27cdf0e10cSrcweir #include <unistd.h>
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <sys/stat.h>
31cdf0e10cSrcweir #include <stdio.h>
32cdf0e10cSrcweir #include <string.h>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include "bootstrp/prj.hxx"
35cdf0e10cSrcweir #include "sal/main.h"
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include <tools/string.hxx>
38cdf0e10cSrcweir #include <tools/list.hxx>
39cdf0e10cSrcweir #include <tools/fsys.hxx>
40cdf0e10cSrcweir #include <tools/stream.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include "cppdep.hxx"
43cdf0e10cSrcweir
44cdf0e10cSrcweir class RscHrcDep : public CppDep
45cdf0e10cSrcweir {
46cdf0e10cSrcweir public:
47cdf0e10cSrcweir RscHrcDep();
48cdf0e10cSrcweir virtual ~RscHrcDep();
49cdf0e10cSrcweir
50cdf0e10cSrcweir virtual void Execute();
51cdf0e10cSrcweir };
52cdf0e10cSrcweir
RscHrcDep()53cdf0e10cSrcweir RscHrcDep::RscHrcDep() :
54cdf0e10cSrcweir CppDep()
55cdf0e10cSrcweir {
56cdf0e10cSrcweir }
57cdf0e10cSrcweir
~RscHrcDep()58cdf0e10cSrcweir RscHrcDep::~RscHrcDep()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
Execute()62cdf0e10cSrcweir void RscHrcDep::Execute()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir CppDep::Execute();
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
67cdf0e10cSrcweir //static String aDelim;
68cdf0e10cSrcweir
main(int argc,char ** argv)69cdf0e10cSrcweir int main( int argc, char** argv )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir char aBuf[255];
72cdf0e10cSrcweir char pFileNamePrefix[255];
73cdf0e10cSrcweir char pOutputFileName[255];
74cdf0e10cSrcweir char pSrsFileName[255];
75cdf0e10cSrcweir String aSrsBaseName;
76cdf0e10cSrcweir sal_Bool bSource = sal_False;
77cdf0e10cSrcweir ByteString aRespArg;
78cdf0e10cSrcweir // who needs anything but '/' ?
79cdf0e10cSrcweir // String aDelim = String(DirEntry::GetAccessDelimiter());
80cdf0e10cSrcweir String aDelim = '/';
81cdf0e10cSrcweir RscHrcDep *pDep = new RscHrcDep;
820e842548SPedro Giffuni
830e842548SPedro Giffuni // When the options are processed, the non-option arguments are
840e842548SPedro Giffuni // collected at the head of the argv array.
850e842548SPedro Giffuni // nLastNonOption points to the last of them.
860e842548SPedro Giffuni int nLastNonOption (-1);
870e842548SPedro Giffuni
88cdf0e10cSrcweir pOutputFileName[0] = 0;
89cdf0e10cSrcweir pSrsFileName[0] = 0;
90cdf0e10cSrcweir
91cdf0e10cSrcweir for ( int i=1; i<argc; i++)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir strcpy( aBuf, (const char *)argv[i] );
940e842548SPedro Giffuni const sal_Int32 nLength (strlen(aBuf));
950e842548SPedro Giffuni
96*de7f73eeSAndre Fischer #ifdef DEBUG
970619ec5bSPedro Giffuni printf("option %d is [%s] and has length %d\n", i, aBuf, (int)nLength);
98*de7f73eeSAndre Fischer #endif
990e842548SPedro Giffuni
1000e842548SPedro Giffuni if (nLength == 0)
1010e842548SPedro Giffuni {
1020e842548SPedro Giffuni // Is this even possible?
1030e842548SPedro Giffuni continue;
1040e842548SPedro Giffuni }
1050e842548SPedro Giffuni if (aBuf[0] == '-' && nLength > 0)
1060e842548SPedro Giffuni {
1070e842548SPedro Giffuni bool bIsKnownOption (true);
1080e842548SPedro Giffuni // Make a switch on the first character after the - for a
1090e842548SPedro Giffuni // preselection of the option.
1100e842548SPedro Giffuni // This is faster then multiple ifs and improves readability.
1110e842548SPedro Giffuni switch (aBuf[1])
1120e842548SPedro Giffuni {
1130e842548SPedro Giffuni case 'p':
1140e842548SPedro Giffuni if (nLength>1 && aBuf[2] == '=' )
1150e842548SPedro Giffuni strcpy(pFileNamePrefix, &aBuf[3]);
1160e842548SPedro Giffuni else
1170e842548SPedro Giffuni bIsKnownOption = false;
1180e842548SPedro Giffuni break;
1190e842548SPedro Giffuni
1200e842548SPedro Giffuni case 'f':
1210e842548SPedro Giffuni if (nLength>2 && aBuf[2] == 'o' && aBuf[3] == '=' )
1220e842548SPedro Giffuni {
1230e842548SPedro Giffuni strcpy(pOutputFileName, &aBuf[4]);
1240e842548SPedro Giffuni }
1250e842548SPedro Giffuni else if (nLength>2 && aBuf[2] == 'p' && aBuf[3] == '=' )
1260e842548SPedro Giffuni {
1270e842548SPedro Giffuni strcpy(pSrsFileName, &aBuf[4]);
1280e842548SPedro Giffuni String aName( pSrsFileName, gsl_getSystemTextEncoding());
1290e842548SPedro Giffuni DirEntry aDest( aName );
1300e842548SPedro Giffuni aSrsBaseName = aDest.GetBase();
1310e842548SPedro Giffuni }
1320e842548SPedro Giffuni else
1330e842548SPedro Giffuni bIsKnownOption = false;
1340e842548SPedro Giffuni break;
1350e842548SPedro Giffuni
1360e842548SPedro Giffuni case 'i':
1370e842548SPedro Giffuni case 'I':
1380e842548SPedro Giffuni #ifdef DEBUG_VERBOSE
1390e842548SPedro Giffuni printf("Include : %s\n", &aBuf[2] );
1400e842548SPedro Giffuni #endif
1410e842548SPedro Giffuni pDep->AddSearchPath( &aBuf[2] );
1420e842548SPedro Giffuni break;
1430e842548SPedro Giffuni
1440e842548SPedro Giffuni case 'h' :
1450e842548SPedro Giffuni case 'H' :
1460e842548SPedro Giffuni case '?' :
1470e842548SPedro Giffuni printf("RscDep 1.0\n");
1480e842548SPedro Giffuni break;
1490e842548SPedro Giffuni
1500e842548SPedro Giffuni case 'a' :
1510e842548SPedro Giffuni #ifdef DEBUG_VERBOSE
1520e842548SPedro Giffuni printf("option a\n");
1530e842548SPedro Giffuni #endif
1540e842548SPedro Giffuni break;
1550e842548SPedro Giffuni
1560e842548SPedro Giffuni case 'l' :
1570e842548SPedro Giffuni #ifdef DEBUG_VERBOSE
1580e842548SPedro Giffuni printf("option l with Value %s\n", &aBuf[2] );
1590e842548SPedro Giffuni #endif
1600e842548SPedro Giffuni pDep->AddSource(&aBuf[2]);
1610e842548SPedro Giffuni break;
1620e842548SPedro Giffuni
1630e842548SPedro Giffuni default:
1640e842548SPedro Giffuni bIsKnownOption = false;
1650e842548SPedro Giffuni break;
1660e842548SPedro Giffuni }
1670e842548SPedro Giffuni #ifdef DEBUG_VERBOSE
1680e842548SPedro Giffuni if ( ! bIsKnownOption)
1690e842548SPedro Giffuni printf("Unknown option error [%s]\n", aBuf);
1700e842548SPedro Giffuni #endif
1710e842548SPedro Giffuni }
1720e842548SPedro Giffuni else if (aBuf[0] == '@' )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir ByteString aToken;
175cdf0e10cSrcweir String aRespName( &aBuf[1], gsl_getSystemTextEncoding());
176cdf0e10cSrcweir SimpleConfig aConfig( aRespName );
177cdf0e10cSrcweir while ( (aToken = aConfig.GetNext()) != "")
178cdf0e10cSrcweir {
179cdf0e10cSrcweir char aBuf2[255];
180cdf0e10cSrcweir (void) strcpy( aBuf2, aToken.GetBuffer());
181cdf0e10cSrcweir if ( aBuf[0] == '-' && aBuf[1] == 'p' && aBuf[2] == '=' )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir strcpy(pFileNamePrefix, &aBuf[3]);
184cdf0e10cSrcweir //break;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir if ( aBuf2[0] == '-' && aBuf2[1] == 'f' && aBuf2[2] == 'o' )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir strcpy(pOutputFileName, &aBuf2[3]);
189cdf0e10cSrcweir //break;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir if ( aBuf2[0] == '-' && aBuf2[1] == 'f' && aBuf2[2] == 'p' )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir strcpy(pSrsFileName, &aBuf2[3]);
194cdf0e10cSrcweir String aName( pSrsFileName, gsl_getSystemTextEncoding());
195cdf0e10cSrcweir DirEntry aDest( aName );
196cdf0e10cSrcweir aSrsBaseName = aDest.GetBase();
197cdf0e10cSrcweir //break;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir if (aBuf2[0] == '-' && aBuf2[1] == 'i' )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir //printf("Include : %s\n", &aBuf[2] );
202cdf0e10cSrcweir pDep->AddSearchPath( &aBuf2[2] );
203cdf0e10cSrcweir }
204cdf0e10cSrcweir if (aBuf2[0] == '-' && aBuf2[1] == 'I' )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir //printf("Include : %s\n", &aBuf[2] );
207cdf0e10cSrcweir pDep->AddSearchPath( &aBuf2[2] );
208cdf0e10cSrcweir }
209cdf0e10cSrcweir if (( aBuf2[0] != '-' ) && ( aBuf2[0] != '@' ))
210cdf0e10cSrcweir {
211cdf0e10cSrcweir pDep->AddSource( &aBuf2[0] );
212cdf0e10cSrcweir aRespArg += " ";
213cdf0e10cSrcweir aRespArg += &aBuf2[0];
214cdf0e10cSrcweir bSource = sal_True;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir }
217cdf0e10cSrcweir }
2180e842548SPedro Giffuni else
2190e842548SPedro Giffuni {
2200e842548SPedro Giffuni // Collect all non-options at the head of argv.
2210e842548SPedro Giffuni if (++nLastNonOption < i)
2220e842548SPedro Giffuni argv[nLastNonOption] = argv[i];
2230e842548SPedro Giffuni }
224cdf0e10cSrcweir }
225cdf0e10cSrcweir
226cdf0e10cSrcweir DirEntry aEntry(".");
227cdf0e10cSrcweir aEntry.ToAbs();
228cdf0e10cSrcweir // String aCwd = aEntry.GetName();
229cdf0e10cSrcweir String aCwd(pFileNamePrefix, gsl_getSystemTextEncoding());
230cdf0e10cSrcweir /* sal_uInt16 nPos;
231cdf0e10cSrcweir #ifndef UNX
232cdf0e10cSrcweir while ( (nPos = aCwd.Search('\\') != STRING_NOTFOUND ))
233cdf0e10cSrcweir #else
234cdf0e10cSrcweir while ( (nPos = aCwd.Search('/') != STRING_NOTFOUND ))
235cdf0e10cSrcweir #endif
236cdf0e10cSrcweir {
237cdf0e10cSrcweir String attt = aCwd.Copy( 0, nPos );
238cdf0e10cSrcweir aCwd.Erase( 0, nPos );
239cdf0e10cSrcweir } */
240cdf0e10cSrcweir SvFileStream aOutStream;
241cdf0e10cSrcweir String aOutputFileName( pOutputFileName, gsl_getSystemTextEncoding());
242cdf0e10cSrcweir DirEntry aOutEntry( aOutputFileName );
243cdf0e10cSrcweir String aOutPath = aOutEntry.GetPath().GetFull();
244cdf0e10cSrcweir
245cdf0e10cSrcweir String aFileName( aOutPath );
246cdf0e10cSrcweir aFileName += aDelim;
247cdf0e10cSrcweir aFileName += aCwd;
248cdf0e10cSrcweir aFileName += String(".", gsl_getSystemTextEncoding());
249cdf0e10cSrcweir aFileName += aSrsBaseName;
250cdf0e10cSrcweir aFileName += String(".dprr", gsl_getSystemTextEncoding());
251cdf0e10cSrcweir //fprintf( stderr, "OutFileName : %s \n",aFileName.GetStr());
252cdf0e10cSrcweir aOutStream.Open( aFileName, STREAM_WRITE );
253cdf0e10cSrcweir
2540e842548SPedro Giffuni // Process the yet unhandled non-options. These are supposed to
2550e842548SPedro Giffuni // be names of files on which the target depends.
256cdf0e10cSrcweir ByteString aString;
2570e842548SPedro Giffuni if (nLastNonOption >= 0)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir #ifdef DEBUG_VERBOSE
260cdf0e10cSrcweir printf("further arguments : ");
261cdf0e10cSrcweir #endif
262cdf0e10cSrcweir aString = ByteString( pSrsFileName );
263cdf0e10cSrcweir aString.SearchAndReplaceAll('\\', ByteString( aDelim, RTL_TEXTENCODING_ASCII_US ));
264cdf0e10cSrcweir aString += ByteString(" : " );
265cdf0e10cSrcweir
2660e842548SPedro Giffuni for (sal_Int32 nIndex=0; nIndex<=nLastNonOption; ++nIndex)
267cdf0e10cSrcweir {
268*de7f73eeSAndre Fischer
269*de7f73eeSAndre Fischer #ifdef DEBUG
2700619ec5bSPedro Giffuni printf("option at %d is [%s]\n", (int)nIndex, argv[nIndex]);
271*de7f73eeSAndre Fischer #endif
272cdf0e10cSrcweir if (!bSource )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir aString += ByteString(" " );
2750e842548SPedro Giffuni aString += ByteString( argv[nIndex]);
2760e842548SPedro Giffuni pDep->AddSource( argv[nIndex]);
277cdf0e10cSrcweir }
278cdf0e10cSrcweir }
279cdf0e10cSrcweir }
280cdf0e10cSrcweir aString += aRespArg;
281cdf0e10cSrcweir pDep->Execute();
282cdf0e10cSrcweir ByteStringList *pLst = pDep->GetDepList();
283cdf0e10cSrcweir sal_uIntPtr nCount = pLst->Count();
284cdf0e10cSrcweir if ( nCount == 0 )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir aOutStream.WriteLine( aString );
287cdf0e10cSrcweir }
288cdf0e10cSrcweir else
289cdf0e10cSrcweir {
290cdf0e10cSrcweir aString += ByteString( "\\" );
291cdf0e10cSrcweir aOutStream.WriteLine( aString );
292cdf0e10cSrcweir }
293cdf0e10cSrcweir
294cdf0e10cSrcweir for ( sal_uIntPtr j=0; j<nCount; j++ )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir ByteString *pStr = pLst->GetObject(j);
297cdf0e10cSrcweir pStr->SearchAndReplaceAll('\\', ByteString( aDelim, RTL_TEXTENCODING_ASCII_US ));
298cdf0e10cSrcweir if ( j != (nCount-1) )
299cdf0e10cSrcweir *pStr += ByteString( "\\" );
300cdf0e10cSrcweir aOutStream.WriteLine( *pStr );
301cdf0e10cSrcweir }
302cdf0e10cSrcweir delete pDep;
303cdf0e10cSrcweir aOutStream.Close();
304cdf0e10cSrcweir
305cdf0e10cSrcweir return 0;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir
308