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