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