Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifdef UNX
21 : : #include <unistd.h>
22 : : #endif
23 : :
24 : : #include <sys/stat.h>
25 : : #include <stdio.h>
26 : : #include <string.h>
27 : :
28 : : #include "bootstrp/prj.hxx"
29 : :
30 : : #include <rtl/strbuf.hxx>
31 : : #include <tools/string.hxx>
32 : : #include <tools/fsys.hxx>
33 : : #include <tools/stream.hxx>
34 : :
35 : : #include "cppdep.hxx"
36 : :
37 : : class RscHrcDep : public CppDep
38 : : {
39 : : public:
40 : : RscHrcDep();
41 : : virtual ~RscHrcDep();
42 : :
43 : : virtual void Execute();
44 : : };
45 : :
46 : 0 : RscHrcDep::RscHrcDep() :
47 : 0 : CppDep()
48 : : {
49 : 0 : }
50 : :
51 : 0 : RscHrcDep::~RscHrcDep()
52 : : {
53 : 0 : }
54 : :
55 : 0 : void RscHrcDep::Execute()
56 : : {
57 : 0 : CppDep::Execute();
58 : 0 : }
59 : :
60 : 0 : int main( int argc, char** argv )
61 : : {
62 : : char aBuf[255];
63 : : char pFileNamePrefix[255];
64 : : char pOutputFileName[255];
65 : : char pSrsFileName[255];
66 : 0 : String aSrsBaseName;
67 : 0 : sal_Bool bSource = sal_False;
68 : 0 : rtl::OStringBuffer aRespArg;
69 : : // who needs anything but '/' ?
70 : 0 : sal_Char cDelim = '/';
71 : :
72 : 0 : RscHrcDep *pDep = new RscHrcDep;
73 : :
74 : : // When the options are processed, the non-option arguments are
75 : : // collected at the head of the argv array.
76 : : // nLastNonOption points to the last of them.
77 : 0 : int nLastNonOption (-1);
78 : :
79 : 0 : pOutputFileName[0] = 0;
80 : 0 : pSrsFileName[0] = 0;
81 : :
82 : 0 : for ( int i=1; i<argc; i++)
83 : : {
84 : 0 : strcpy( aBuf, (const char *)argv[i] );
85 : 0 : const sal_Int32 nLength (strlen(aBuf));
86 : :
87 : : #ifdef DEBUG
88 : : printf("option %d is [%s] and has length %d\n", i, aBuf, (int)nLength);
89 : : #endif
90 : :
91 : 0 : if (nLength == 0) // Is this even possible?
92 : 0 : continue;
93 : :
94 : 0 : if (aBuf[0] == '-' && nLength > 0)
95 : : {
96 : 0 : bool bIsKnownOption = true;
97 : : // Make a switch on the first character after the - for a
98 : : // preselection of the option.
99 : : // This is faster then multiple ifs and improves readability.
100 : 0 : switch (aBuf[1])
101 : : {
102 : : case 'p':
103 : 0 : if (nLength > 1 && aBuf[2] == '=' )
104 : 0 : strcpy(pFileNamePrefix, &aBuf[3]);
105 : : else
106 : 0 : bIsKnownOption = false;
107 : 0 : break;
108 : : case 'f':
109 : 0 : if (nLength > 2 && aBuf[2] == 'o' && aBuf[3] == '=' )
110 : 0 : strcpy(pOutputFileName, &aBuf[4]);
111 : 0 : else if (nLength>2 && aBuf[2] == 'p' && aBuf[3] == '=' )
112 : : {
113 : 0 : strcpy(pSrsFileName, &aBuf[4]);
114 : 0 : String aName( pSrsFileName, osl_getThreadTextEncoding());
115 : 0 : DirEntry aDest( aName );
116 : 0 : aSrsBaseName = aDest.GetBase();
117 : : }
118 : : else
119 : 0 : bIsKnownOption = false;
120 : 0 : break;
121 : : case 'i':
122 : : case 'I':
123 : : #ifdef DEBUG_VERBOSE
124 : : printf("Include : %s\n", &aBuf[2] );
125 : : #endif
126 : 0 : pDep->AddSearchPath( &aBuf[2] );
127 : 0 : break;
128 : : case 'h' :
129 : : case 'H' :
130 : : case '?' :
131 : 0 : printf("RscDep 1.0\n");
132 : 0 : break;
133 : : case 'a' :
134 : : #ifdef DEBUG_VERBOSE
135 : : printf("option a\n");
136 : : #endif
137 : 0 : break;
138 : :
139 : : case 'l' :
140 : : #ifdef DEBUG_VERBOSE
141 : : printf("option l with Value %s\n", &aBuf[2] );
142 : : #endif
143 : 0 : pDep->AddSource(&aBuf[2]);
144 : 0 : break;
145 : :
146 : : default:
147 : 0 : bIsKnownOption = false;
148 : 0 : break;
149 : : }
150 : : #ifdef DEBUG_VERBOSE
151 : : if ( ! bIsKnownOption)
152 : : printf("Unknown option error [%s]\n", aBuf);
153 : : #else
154 : 0 : (void)bIsKnownOption;
155 : : #endif
156 : : }
157 : 0 : else if (aBuf[0] == '@' )
158 : : {
159 : 0 : rtl::OString aToken;
160 : 0 : String aRespName( &aBuf[1], osl_getThreadTextEncoding());
161 : 0 : SimpleConfig aConfig( aRespName );
162 : 0 : while (!(aToken = aConfig.getNext()).isEmpty())
163 : : {
164 : : char aBuf2[255];
165 : 0 : strcpy( aBuf2, aToken.getStr());
166 : 0 : if ( aBuf[0] == '-' && aBuf[1] == 'p' && aBuf[2] == '=' )
167 : : {
168 : 0 : strcpy(pFileNamePrefix, &aBuf[3]);
169 : : }
170 : 0 : if ( aBuf2[0] == '-' && aBuf2[1] == 'f' && aBuf2[2] == 'o' )
171 : : {
172 : 0 : strcpy(pOutputFileName, &aBuf2[3]);
173 : : }
174 : 0 : if ( aBuf2[0] == '-' && aBuf2[1] == 'f' && aBuf2[2] == 'p' )
175 : : {
176 : 0 : strcpy(pSrsFileName, &aBuf2[3]);
177 : 0 : String aName( pSrsFileName, osl_getThreadTextEncoding());
178 : 0 : DirEntry aDest( aName );
179 : 0 : aSrsBaseName = aDest.GetBase();
180 : : }
181 : 0 : if (aBuf2[0] == '-' && aBuf2[1] == 'i' )
182 : : {
183 : 0 : pDep->AddSearchPath( &aBuf2[2] );
184 : : }
185 : 0 : if (aBuf2[0] == '-' && aBuf2[1] == 'I' )
186 : : {
187 : 0 : pDep->AddSearchPath( &aBuf2[2] );
188 : : }
189 : 0 : if (( aBuf2[0] != '-' ) && ( aBuf2[0] != '@' ))
190 : : {
191 : 0 : pDep->AddSource( &aBuf2[0] );
192 : 0 : aRespArg.append(' ').append(&aBuf2[0]);
193 : 0 : bSource = sal_True;
194 : : }
195 : 0 : }
196 : : }
197 : : else
198 : : {
199 : : // Collect all non-options at the head of argv.
200 : 0 : if (++nLastNonOption < i)
201 : 0 : argv[nLastNonOption] = argv[i];
202 : : }
203 : : }
204 : :
205 : 0 : String aCwd(pFileNamePrefix, osl_getThreadTextEncoding());
206 : 0 : SvFileStream aOutStream;
207 : 0 : String aOutputFileName( pOutputFileName, osl_getThreadTextEncoding());
208 : 0 : DirEntry aOutEntry( aOutputFileName );
209 : 0 : String aOutPath = aOutEntry.GetPath().GetFull();
210 : :
211 : 0 : String aFileName( aOutPath );
212 : 0 : aFileName += cDelim;
213 : 0 : aFileName += aCwd;
214 : 0 : aFileName += String(".", osl_getThreadTextEncoding());
215 : 0 : aFileName += aSrsBaseName;
216 : 0 : aFileName += String(".dprr", osl_getThreadTextEncoding());
217 : 0 : aOutStream.Open( aFileName, STREAM_WRITE );
218 : :
219 : : // Process the yet unhandled non-options. These are supposed to
220 : : // be names of files on which the target depends.
221 : 0 : rtl::OStringBuffer aString;
222 : 0 : if ( nLastNonOption >= 0 )
223 : : {
224 : : #ifdef DEBUG_VERBOSE
225 : : printf("further arguments : ");
226 : : #endif
227 : 0 : aString.append(rtl::OString(pSrsFileName).replace('\\', cDelim));
228 : 0 : aString.append(RTL_CONSTASCII_STRINGPARAM(" : " ));
229 : :
230 : 0 : for (sal_Int32 nIndex=0; nIndex<=nLastNonOption; ++nIndex)
231 : : {
232 : : #ifdef DEBUG
233 : : printf("option at %d is [%s]\n", (int)nIndex, argv[nIndex]);
234 : : #endif
235 : 0 : if (!bSource )
236 : : {
237 : 0 : aString.append(' ');
238 : 0 : aString.append(argv[nIndex]);
239 : 0 : pDep->AddSource(argv[nIndex]);
240 : : }
241 : : }
242 : : }
243 : 0 : aString.append(aRespArg.makeStringAndClear());
244 : 0 : pDep->Execute();
245 : 0 : std::vector<rtl::OString>& rLst = pDep->GetDepList();
246 : 0 : size_t nCount = rLst.size();
247 : 0 : if ( nCount != 0 )
248 : 0 : aString.append('\\');
249 : 0 : aOutStream.WriteLine( aString.makeStringAndClear() );
250 : :
251 : 0 : for ( size_t j = 0; j < nCount; ++j )
252 : : {
253 : 0 : rtl::OStringBuffer aStr(rLst[j].replace('\\', cDelim));
254 : 0 : if ( j != (nCount-1) )
255 : 0 : aStr.append('\\');
256 : 0 : aOutStream.WriteLine(aStr.makeStringAndClear());
257 : 0 : }
258 : 0 : delete pDep;
259 : 0 : aOutStream.Close();
260 : :
261 : 0 : return 0;
262 : : }
263 : :
264 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|