merge the formfield patch from ooo-build
[ooovba.git] / tools / bootstrp / rscdep.cxx
blob3764e883a5dbffe23151ee913ea3e984893f8d3b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rscdep.cxx,v $
10 * $Revision: 1.25.42.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_tools.hxx"
33 #ifdef UNX
34 #include <unistd.h>
35 #endif
37 #include <sys/stat.h>
38 #include <stdio.h>
39 #include <string.h>
41 #include "bootstrp/prj.hxx"
43 #include <tools/string.hxx>
44 #include <tools/list.hxx>
45 #include <tools/fsys.hxx>
46 #include <tools/stream.hxx>
48 #include "cppdep.hxx"
50 class RscHrcDep : public CppDep
52 public:
53 RscHrcDep();
54 virtual ~RscHrcDep();
56 virtual void Execute();
59 RscHrcDep::RscHrcDep() :
60 CppDep()
64 RscHrcDep::~RscHrcDep()
68 void RscHrcDep::Execute()
70 CppDep::Execute();
73 //static String aDelim;
75 /* poor man's getopt() */
76 int simple_getopt(char *argv[], const char *optstring);
77 #if defined(WNT) || defined(OS2)
78 static char *optarg = NULL;
79 static int optind = 1;
80 static int optopt = 0;
81 static int opterr = 0;
82 #endif
85 int
86 #ifdef WNT
87 _cdecl
88 #endif
89 main( int argc, char **argv )
91 int c;
92 char aBuf[255];
93 char pFileNamePrefix[255];
94 char pOutputFileName[255];
95 char pSrsFileName[255];
96 String aSrsBaseName;
97 BOOL bSource = FALSE;
98 ByteString aRespArg;
99 // who needs anything but '/' ?
100 // String aDelim = String(DirEntry::GetAccessDelimiter());
101 String aDelim = '/';
103 RscHrcDep *pDep = new RscHrcDep;
105 pOutputFileName[0] = 0;
106 pSrsFileName[0] = 0;
108 for ( int i=1; i<argc; i++)
110 strcpy( aBuf, (const char *)argv[i] );
111 if ( aBuf[0] == '-' && aBuf[1] == 'p' && aBuf[2] == '=' )
113 strcpy(pFileNamePrefix, &aBuf[3]);
114 //break;
116 if ( aBuf[0] == '-' && aBuf[1] == 'f' && aBuf[2] == 'o' && aBuf[3] == '=' )
118 strcpy(pOutputFileName, &aBuf[4]);
119 //break;
121 if ( aBuf[0] == '-' && aBuf[1] == 'f' && aBuf[2] == 'p' && aBuf[3] == '=' )
123 strcpy(pSrsFileName, &aBuf[4]);
124 String aName( pSrsFileName, gsl_getSystemTextEncoding());
125 DirEntry aDest( aName );
126 aSrsBaseName = aDest.GetBase();
127 //break;
129 if (aBuf[0] == '-' && aBuf[1] == 'i' )
131 //printf("Include : %s\n", &aBuf[2] );
132 pDep->AddSearchPath( &aBuf[2] );
134 if (aBuf[0] == '-' && aBuf[1] == 'I' )
136 //printf("Include : %s\n", &aBuf[2] );
137 pDep->AddSearchPath( &aBuf[2] );
139 if (aBuf[0] == '@' )
141 ByteString aToken;
142 String aRespName( &aBuf[1], gsl_getSystemTextEncoding());
143 SimpleConfig aConfig( aRespName );
144 while ( (aToken = aConfig.GetNext()) != "")
146 char aBuf2[255];
147 (void) strcpy( aBuf2, aToken.GetBuffer());
148 if ( aBuf[0] == '-' && aBuf[1] == 'p' && aBuf[2] == '=' )
150 strcpy(pFileNamePrefix, &aBuf[3]);
151 //break;
153 if ( aBuf2[0] == '-' && aBuf2[1] == 'f' && aBuf2[2] == 'o' )
155 strcpy(pOutputFileName, &aBuf2[3]);
156 //break;
158 if ( aBuf2[0] == '-' && aBuf2[1] == 'f' && aBuf2[2] == 'p' )
160 strcpy(pSrsFileName, &aBuf2[3]);
161 String aName( pSrsFileName, gsl_getSystemTextEncoding());
162 DirEntry aDest( aName );
163 aSrsBaseName = aDest.GetBase();
164 //break;
166 if (aBuf2[0] == '-' && aBuf2[1] == 'i' )
168 //printf("Include : %s\n", &aBuf[2] );
169 pDep->AddSearchPath( &aBuf2[2] );
171 if (aBuf2[0] == '-' && aBuf2[1] == 'I' )
173 //printf("Include : %s\n", &aBuf[2] );
174 pDep->AddSearchPath( &aBuf2[2] );
176 if (( aBuf2[0] != '-' ) && ( aBuf2[0] != '@' ))
178 pDep->AddSource( &aBuf2[0] );
179 aRespArg += " ";
180 aRespArg += &aBuf2[0];
181 bSource = TRUE;
187 while( 1 )
189 c = simple_getopt( argv,
190 "_abcdefghi:jklmnopqrstuvwxyzABCDEFGHI:JKLMNOPQRSTUVWXYZ1234567890/-+=.\\()\"");
191 if ( c == -1 )
192 break;
194 switch( c )
196 case 0:
197 break;
198 case 'a' :
199 #ifdef DEBUG_VERBOSE
200 printf("option a\n");
201 #endif
202 break;
204 case 'l' :
205 #ifdef DEBUG_VERBOSE
206 printf("option l with Value %s\n", optarg );
207 #endif
208 pDep->AddSource( optarg );
209 break;
211 case 'h' :
212 case 'H' :
213 case '?' :
214 printf("RscDep 1.0 (c)2000 StarOffice\n");
215 break;
217 default:
218 #ifdef DEBUG_VERBOSE
219 printf("Unknown getopt error\n");
220 #endif
226 DirEntry aEntry(".");
227 aEntry.ToAbs();
228 // String aCwd = aEntry.GetName();
229 String aCwd(pFileNamePrefix, gsl_getSystemTextEncoding());
230 /* USHORT nPos;
231 #ifndef UNX
232 while ( (nPos = aCwd.Search('\\') != STRING_NOTFOUND ))
233 #else
234 while ( (nPos = aCwd.Search('/') != STRING_NOTFOUND ))
235 #endif
237 String attt = aCwd.Copy( 0, nPos );
238 aCwd.Erase( 0, nPos );
239 } */
240 SvFileStream aOutStream;
241 String aOutputFileName( pOutputFileName, gsl_getSystemTextEncoding());
242 DirEntry aOutEntry( aOutputFileName );
243 String aOutPath = aOutEntry.GetPath().GetFull();
245 String aFileName( aOutPath );
246 aFileName += aDelim;
247 aFileName += aCwd;
248 aFileName += String(".", gsl_getSystemTextEncoding());
249 aFileName += aSrsBaseName;
250 aFileName += String(".dprr", gsl_getSystemTextEncoding());
251 //fprintf( stderr, "OutFileName : %s \n",aFileName.GetStr());
252 aOutStream.Open( aFileName, STREAM_WRITE );
254 ByteString aString;
255 if ( optind < argc )
257 #ifdef DEBUG_VERBOSE
258 printf("further arguments : ");
259 #endif
260 aString = ByteString( pSrsFileName );
261 aString.SearchAndReplaceAll('\\', ByteString( aDelim, RTL_TEXTENCODING_ASCII_US ));
262 aString += ByteString(" : " );
264 while ( optind < argc )
266 if (!bSource )
268 aString += ByteString(" " );
269 aString += ByteString( argv[optind]);
270 pDep->AddSource( argv[optind++]);
272 else
274 optind++;
278 aString += aRespArg;
279 pDep->Execute();
280 ByteStringList *pLst = pDep->GetDepList();
281 ULONG nCount = pLst->Count();
282 if ( nCount == 0 )
284 aOutStream.WriteLine( aString );
286 else
288 aString += ByteString( "\\" );
289 aOutStream.WriteLine( aString );
292 for ( ULONG j=0; j<nCount; j++ )
294 ByteString *pStr = pLst->GetObject(j);
295 pStr->SearchAndReplaceAll('\\', ByteString( aDelim, RTL_TEXTENCODING_ASCII_US ));
296 if ( j != (nCount-1) )
297 *pStr += ByteString( "\\" );
298 aOutStream.WriteLine( *pStr );
300 delete pDep;
301 aOutStream.Close();
303 return 0;
306 /* my very simple minded implementation of getopt()
307 * it's too sad that getopt() is not available everywhere
308 * note: this is not a full POSIX conforming getopt()
310 int simple_getopt(char *argv[], const char *optstring)
312 char *arg = argv[optind];
314 /* skip all response file arguments */
315 if ( arg ) {
316 while ( *arg == '@' )
317 arg = argv[++optind];
319 if ( arg[0] == '-' && arg[1] != '\0' ) {
320 const char *popt;
321 int c = arg[1];
322 if ( (popt = strchr(optstring, c)) == NULL ) {
323 optopt = c;
324 if ( opterr )
325 fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
326 return '?';
328 if ( *(++popt) == ':') {
329 if ( arg[2] != '\0' ) {
330 optarg = ++arg;
331 } else {
332 optarg = argv[++optind];
334 } else {
335 optarg = NULL;
337 ++optind;
338 return c;
341 return -1;