1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
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>
50 class RscHrcDep
: public CppDep
56 virtual void Execute();
59 RscHrcDep::RscHrcDep() :
64 RscHrcDep::~RscHrcDep()
68 void RscHrcDep::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;
89 main( int argc
, char **argv
)
93 char pFileNamePrefix
[255];
94 char pOutputFileName
[255];
95 char pSrsFileName
[255];
99 // who needs anything but '/' ?
100 // String aDelim = String(DirEntry::GetAccessDelimiter());
103 RscHrcDep
*pDep
= new RscHrcDep
;
105 pOutputFileName
[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]);
116 if ( aBuf
[0] == '-' && aBuf
[1] == 'f' && aBuf
[2] == 'o' && aBuf
[3] == '=' )
118 strcpy(pOutputFileName
, &aBuf
[4]);
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();
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] );
142 String
aRespName( &aBuf
[1], gsl_getSystemTextEncoding());
143 SimpleConfig
aConfig( aRespName
);
144 while ( (aToken
= aConfig
.GetNext()) != "")
147 (void) strcpy( aBuf2
, aToken
.GetBuffer());
148 if ( aBuf
[0] == '-' && aBuf
[1] == 'p' && aBuf
[2] == '=' )
150 strcpy(pFileNamePrefix
, &aBuf
[3]);
153 if ( aBuf2
[0] == '-' && aBuf2
[1] == 'f' && aBuf2
[2] == 'o' )
155 strcpy(pOutputFileName
, &aBuf2
[3]);
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();
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] );
180 aRespArg
+= &aBuf2
[0];
189 c
= simple_getopt( argv
,
190 "_abcdefghi:jklmnopqrstuvwxyzABCDEFGHI:JKLMNOPQRSTUVWXYZ1234567890/-+=.\\()\"");
200 printf("option a\n");
206 printf("option l with Value %s\n", optarg
);
208 pDep
->AddSource( optarg
);
214 printf("RscDep 1.0 (c)2000 StarOffice\n");
219 printf("Unknown getopt error\n");
226 DirEntry
aEntry(".");
228 // String aCwd = aEntry.GetName();
229 String
aCwd(pFileNamePrefix
, gsl_getSystemTextEncoding());
232 while ( (nPos = aCwd.Search('\\') != STRING_NOTFOUND ))
234 while ( (nPos = aCwd.Search('/') != STRING_NOTFOUND ))
237 String attt = aCwd.Copy( 0, nPos );
238 aCwd.Erase( 0, nPos );
240 SvFileStream aOutStream
;
241 String
aOutputFileName( pOutputFileName
, gsl_getSystemTextEncoding());
242 DirEntry
aOutEntry( aOutputFileName
);
243 String aOutPath
= aOutEntry
.GetPath().GetFull();
245 String
aFileName( aOutPath
);
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
);
258 printf("further arguments : ");
260 aString
= ByteString( pSrsFileName
);
261 aString
.SearchAndReplaceAll('\\', ByteString( aDelim
, RTL_TEXTENCODING_ASCII_US
));
262 aString
+= ByteString(" : " );
264 while ( optind
< argc
)
268 aString
+= ByteString(" " );
269 aString
+= ByteString( argv
[optind
]);
270 pDep
->AddSource( argv
[optind
++]);
280 ByteStringList
*pLst
= pDep
->GetDepList();
281 ULONG nCount
= pLst
->Count();
284 aOutStream
.WriteLine( aString
);
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
);
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 */
316 while ( *arg
== '@' )
317 arg
= argv
[++optind
];
319 if ( arg
[0] == '-' && arg
[1] != '\0' ) {
322 if ( (popt
= strchr(optstring
, c
)) == NULL
) {
325 fprintf(stderr
, "Unknown option character `\\x%x'.\n", optopt
);
328 if ( *(++popt
) == ':') {
329 if ( arg
[2] != '\0' ) {
332 optarg
= argv
[++optind
];