Bump for 3.6-28
[LibreOffice.git] / tools / bootstrp / rscdep.cxx
blob269086b8de4699694ecd8df10f1a1f96b1e349ea
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifdef UNX
30 #include <unistd.h>
31 #endif
33 #include <sys/stat.h>
34 #include <stdio.h>
35 #include <string.h>
37 #include "bootstrp/prj.hxx"
39 #include <rtl/strbuf.hxx>
40 #include <tools/string.hxx>
41 #include <tools/fsys.hxx>
42 #include <tools/stream.hxx>
44 #include "cppdep.hxx"
46 #if defined WNT
47 #define __STDC__ 1
48 #define __GNU_LIBRARY__
49 #include <external/glibc/getopt.h>
50 #endif
52 class RscHrcDep : public CppDep
54 public:
55 RscHrcDep();
56 virtual ~RscHrcDep();
58 virtual void Execute();
61 RscHrcDep::RscHrcDep() :
62 CppDep()
66 RscHrcDep::~RscHrcDep()
70 void RscHrcDep::Execute()
72 CppDep::Execute();
75 int main( int argc, char** argv )
77 int c;
78 char aBuf[255];
79 char pFileNamePrefix[255];
80 char pOutputFileName[255];
81 char pSrsFileName[255];
82 String aSrsBaseName;
83 sal_Bool bSource = sal_False;
84 rtl::OStringBuffer aRespArg;
85 // who needs anything but '/' ?
86 sal_Char cDelim = '/';
88 RscHrcDep *pDep = new RscHrcDep;
90 pOutputFileName[0] = 0;
91 pSrsFileName[0] = 0;
93 for ( int i=1; i<argc; i++)
95 strcpy( aBuf, (const char *)argv[i] );
96 if ( aBuf[0] == '-' && aBuf[1] == 'p' && aBuf[2] == '=' )
98 strcpy(pFileNamePrefix, &aBuf[3]);
100 if ( aBuf[0] == '-' && aBuf[1] == 'f' && aBuf[2] == 'o' && aBuf[3] == '=' )
102 strcpy(pOutputFileName, &aBuf[4]);
104 if ( aBuf[0] == '-' && aBuf[1] == 'f' && aBuf[2] == 'p' && aBuf[3] == '=' )
106 strcpy(pSrsFileName, &aBuf[4]);
107 String aName( pSrsFileName, osl_getThreadTextEncoding());
108 DirEntry aDest( aName );
109 aSrsBaseName = aDest.GetBase();
111 if (aBuf[0] == '-' && aBuf[1] == 'i' )
113 pDep->AddSearchPath( &aBuf[2] );
115 if (aBuf[0] == '-' && aBuf[1] == 'I' )
117 pDep->AddSearchPath( &aBuf[2] );
119 if (aBuf[0] == '@' )
121 rtl::OString aToken;
122 String aRespName( &aBuf[1], osl_getThreadTextEncoding());
123 SimpleConfig aConfig( aRespName );
124 while (!(aToken = aConfig.getNext()).isEmpty())
126 char aBuf2[255];
127 strcpy( aBuf2, aToken.getStr());
128 if ( aBuf[0] == '-' && aBuf[1] == 'p' && aBuf[2] == '=' )
130 strcpy(pFileNamePrefix, &aBuf[3]);
132 if ( aBuf2[0] == '-' && aBuf2[1] == 'f' && aBuf2[2] == 'o' )
134 strcpy(pOutputFileName, &aBuf2[3]);
136 if ( aBuf2[0] == '-' && aBuf2[1] == 'f' && aBuf2[2] == 'p' )
138 strcpy(pSrsFileName, &aBuf2[3]);
139 String aName( pSrsFileName, osl_getThreadTextEncoding());
140 DirEntry aDest( aName );
141 aSrsBaseName = aDest.GetBase();
143 if (aBuf2[0] == '-' && aBuf2[1] == 'i' )
145 pDep->AddSearchPath( &aBuf2[2] );
147 if (aBuf2[0] == '-' && aBuf2[1] == 'I' )
149 pDep->AddSearchPath( &aBuf2[2] );
151 if (( aBuf2[0] != '-' ) && ( aBuf2[0] != '@' ))
153 pDep->AddSource( &aBuf2[0] );
154 aRespArg.append(' ').append(&aBuf2[0]);
155 bSource = sal_True;
161 while( 1 )
163 c = getopt( argc, argv,
164 "_abcdefghi:jklmnopqrstuvwxyzABCDEFGHI:JKLMNOPQRSTUVWXYZ1234567890/-+=.\\()\"");
165 if ( c == -1 )
166 break;
168 switch( c )
170 case 0:
171 break;
172 case 'a' :
173 #ifdef DEBUG_VERBOSE
174 printf("option a\n");
175 #endif
176 break;
178 case 'l' :
179 #ifdef DEBUG_VERBOSE
180 printf("option l with Value %s\n", optarg );
181 #endif
182 pDep->AddSource( optarg );
183 break;
185 case 'h' :
186 case 'H' :
187 case '?' :
188 printf("RscDep 1.0\n");
189 break;
191 default:
192 #ifdef DEBUG_VERBOSE
193 printf("Unknown getopt error\n");
194 #endif
200 String aCwd(pFileNamePrefix, osl_getThreadTextEncoding());
201 SvFileStream aOutStream;
202 String aOutputFileName( pOutputFileName, osl_getThreadTextEncoding());
203 DirEntry aOutEntry( aOutputFileName );
204 String aOutPath = aOutEntry.GetPath().GetFull();
206 String aFileName( aOutPath );
207 aFileName += cDelim;
208 aFileName += aCwd;
209 aFileName += String(".", osl_getThreadTextEncoding());
210 aFileName += aSrsBaseName;
211 aFileName += String(".dprr", osl_getThreadTextEncoding());
212 aOutStream.Open( aFileName, STREAM_WRITE );
214 rtl::OStringBuffer aString;
215 if ( optind < argc )
217 #ifdef DEBUG_VERBOSE
218 printf("further arguments : ");
219 #endif
220 aString.append(rtl::OString(pSrsFileName).replace('\\', cDelim));
221 aString.append(RTL_CONSTASCII_STRINGPARAM(" : " ));
223 while ( optind < argc )
225 if (!bSource )
227 aString.append(' ');
228 aString.append(argv[optind]);
229 pDep->AddSource( argv[optind++]);
231 else
233 optind++;
237 aString.append(aRespArg.makeStringAndClear());
238 pDep->Execute();
239 std::vector<rtl::OString>& rLst = pDep->GetDepList();
240 size_t nCount = rLst.size();
241 if ( nCount != 0 )
242 aString.append('\\');
243 aOutStream.WriteLine( aString.makeStringAndClear() );
245 for ( size_t j = 0; j < nCount; ++j )
247 rtl::OStringBuffer aStr(rLst[j].replace('\\', cDelim));
248 if ( j != (nCount-1) )
249 aStr.append('\\');
250 aOutStream.WriteLine(aStr.makeStringAndClear());
252 delete pDep;
253 aOutStream.Close();
255 return 0;
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */