xref: /AOO41X/main/xml2cmp/source/support/syshelp.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #include <syshelp.hxx>
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
33*cdf0e10cSrcweir #include <string.h>
34*cdf0e10cSrcweir #include "sistr.hxx"
35*cdf0e10cSrcweir #include "list.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #ifdef WNT
38*cdf0e10cSrcweir #include <io.h>
39*cdf0e10cSrcweir #elif defined(UNX) || defined(OS2)
40*cdf0e10cSrcweir #include <sys/types.h>
41*cdf0e10cSrcweir #include <sys/stat.h>
42*cdf0e10cSrcweir #include <dirent.h>
43*cdf0e10cSrcweir #define stricmp strcasecmp
44*cdf0e10cSrcweir #else
45*cdf0e10cSrcweir #error Must run under unix or windows, please define UNX or WNT.
46*cdf0e10cSrcweir #endif
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir char C_sSpaceInName[] = "&nbsp;&nbsp;&nbsp;";
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir void
52*cdf0e10cSrcweir WriteName( std::ostream & 		o_rFile,
53*cdf0e10cSrcweir 		   const Simstr &	i_rIdlDocuBaseDir,
54*cdf0e10cSrcweir 		   const Simstr &   i_rName,
55*cdf0e10cSrcweir 		   E_LinkType		i_eLinkType )
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir 	if (i_rName.l() == 0)
58*cdf0e10cSrcweir 		return;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 	const char * pNameEnd = strstr( i_rName.str(), " in " );
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 	// No link:
64*cdf0e10cSrcweir 	if ( i_eLinkType == lt_nolink )
65*cdf0e10cSrcweir 	{
66*cdf0e10cSrcweir 		if ( pNameEnd != 0 )
67*cdf0e10cSrcweir 		{
68*cdf0e10cSrcweir 			const char * pStart = i_rName.str();
69*cdf0e10cSrcweir 			o_rFile.write( pStart, pNameEnd - pStart );
70*cdf0e10cSrcweir 			WriteStr( o_rFile, C_sSpaceInName );
71*cdf0e10cSrcweir 			WriteStr( o_rFile, pNameEnd );
72*cdf0e10cSrcweir 		}
73*cdf0e10cSrcweir 		else
74*cdf0e10cSrcweir 		{
75*cdf0e10cSrcweir 			WriteStr( o_rFile, i_rName );
76*cdf0e10cSrcweir 		}
77*cdf0e10cSrcweir 		return;
78*cdf0e10cSrcweir 	}
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	if ( i_eLinkType == lt_idl )
81*cdf0e10cSrcweir 	{
82*cdf0e10cSrcweir 		Simstr sPath(i_rName);
83*cdf0e10cSrcweir 		sPath.replace_all('.','/');
84*cdf0e10cSrcweir 		int nNameEnd = sPath.pos_first(' ');
85*cdf0e10cSrcweir 		int nPathStart = sPath.pos_last(' ');
86*cdf0e10cSrcweir 		WriteStr( o_rFile, "<A HREF=\"" );
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 		if ( nNameEnd > -1 )
89*cdf0e10cSrcweir 		{
90*cdf0e10cSrcweir 			WriteStr( o_rFile, "file:///" );
91*cdf0e10cSrcweir 			WriteStr( o_rFile, i_rIdlDocuBaseDir );
92*cdf0e10cSrcweir 			WriteStr( o_rFile, "/" );
93*cdf0e10cSrcweir 			WriteStr( o_rFile, sPath.str() + 1 + nPathStart );
94*cdf0e10cSrcweir 			WriteStr( o_rFile, "/" );
95*cdf0e10cSrcweir 			o_rFile.write( sPath.str(), nNameEnd );
96*cdf0e10cSrcweir 			WriteStr( o_rFile, ".html\">" );
97*cdf0e10cSrcweir 		}
98*cdf0e10cSrcweir 		else
99*cdf0e10cSrcweir 		{  	// Should not be reached:
100*cdf0e10cSrcweir 			WriteStr(o_rFile, i_rName);
101*cdf0e10cSrcweir 			return;
102*cdf0e10cSrcweir 		}
103*cdf0e10cSrcweir 	}
104*cdf0e10cSrcweir 	else if ( i_eLinkType == lt_html )
105*cdf0e10cSrcweir 	{
106*cdf0e10cSrcweir 		int nKomma = i_rName.pos_first(',');
107*cdf0e10cSrcweir 		int nEnd = i_rName.pos_first(' ');
108*cdf0e10cSrcweir 		if ( nKomma > -1 )
109*cdf0e10cSrcweir 		{
110*cdf0e10cSrcweir 			o_rFile.write( i_rName.str(), nKomma );
111*cdf0e10cSrcweir 			WriteStr( o_rFile, ": " );
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 			WriteStr( o_rFile, "<A HREF=\"" );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 			o_rFile.write( i_rName.str(), nKomma );
116*cdf0e10cSrcweir 			WriteStr( o_rFile, ".html#" );
117*cdf0e10cSrcweir 			if ( nEnd > -1 )
118*cdf0e10cSrcweir 				o_rFile.write( i_rName.str() + nKomma + 1, nEnd - nKomma );
119*cdf0e10cSrcweir 			else
120*cdf0e10cSrcweir 				WriteStr( o_rFile, i_rName.str() + nKomma + 1 );
121*cdf0e10cSrcweir 			WriteStr( o_rFile, "\">" );
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 			o_rFile.write( i_rName.str() + nKomma + 1, nEnd - nKomma );
124*cdf0e10cSrcweir 		}
125*cdf0e10cSrcweir 		else
126*cdf0e10cSrcweir 		{
127*cdf0e10cSrcweir 			WriteStr( o_rFile, "<A HREF=\"" );
128*cdf0e10cSrcweir 			WriteStr( o_rFile, i_rName );
129*cdf0e10cSrcweir 			WriteStr( o_rFile, ".html\">" );
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 			WriteStr( o_rFile, i_rName );
132*cdf0e10cSrcweir 		}
133*cdf0e10cSrcweir 		WriteStr( o_rFile, "</A>" );
134*cdf0e10cSrcweir         return;
135*cdf0e10cSrcweir 	}
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	if ( pNameEnd != 0 )
138*cdf0e10cSrcweir 	{
139*cdf0e10cSrcweir 		const char * pStart = i_rName.str();
140*cdf0e10cSrcweir 		if ( pNameEnd > pStart )
141*cdf0e10cSrcweir 			o_rFile.write( pStart, pNameEnd - pStart );
142*cdf0e10cSrcweir 		WriteStr( o_rFile, "</A>" );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 		WriteStr( o_rFile, C_sSpaceInName );
145*cdf0e10cSrcweir 		WriteStr( o_rFile, pNameEnd );
146*cdf0e10cSrcweir 	}
147*cdf0e10cSrcweir 	else
148*cdf0e10cSrcweir 	{
149*cdf0e10cSrcweir 		WriteStr( o_rFile, i_rName );
150*cdf0e10cSrcweir 		WriteStr( o_rFile, "</A>" );
151*cdf0e10cSrcweir 	}
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir void
156*cdf0e10cSrcweir WriteStr( std::ostream & 	o_rFile,
157*cdf0e10cSrcweir 		  const char *		i_sStr )
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir 	o_rFile.write( i_sStr, (int) strlen(i_sStr) );
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir void
163*cdf0e10cSrcweir WriteStr( std::ostream & 	  o_rFile,
164*cdf0e10cSrcweir 		  const Simstr &      i_sStr )
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	o_rFile.write( i_sStr.str(), i_sStr.l() );
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir const char C_sXML_END[] = "\\*.xml";
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir void
173*cdf0e10cSrcweir GatherFileNames( List<Simstr> &   	o_sFiles,
174*cdf0e10cSrcweir 				 const char *		i_sSrcDirectory )
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir 	static int 	 nAliveCounter = 0;
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 	char * 		 sNextDir = 0;
179*cdf0e10cSrcweir 	Simstr       sNew = 0;
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir #ifdef WNT
182*cdf0e10cSrcweir 	struct _finddata_t aEntry;
183*cdf0e10cSrcweir 	long hFile = 0;
184*cdf0e10cSrcweir 	int bFindMore = 0;
185*cdf0e10cSrcweir 	char * sFilter = new char[ strlen(i_sSrcDirectory) + sizeof C_sXML_END ];
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 	// Stayingalive sign
188*cdf0e10cSrcweir 	if (++nAliveCounter % 100 == 1)
189*cdf0e10cSrcweir 		std::cout << "." << std::flush;
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	strcpy(sFilter, i_sSrcDirectory);       // STRCPY SAFE HERE
192*cdf0e10cSrcweir 	strcat(sFilter,C_sXML_END);             // STRCAT SAFE HERE
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	hFile = _findfirst( sFilter, &aEntry );
195*cdf0e10cSrcweir 	for ( bFindMore = hFile == -1;
196*cdf0e10cSrcweir 		  bFindMore == 0;
197*cdf0e10cSrcweir 		  bFindMore = _findnext( hFile, &aEntry ) )
198*cdf0e10cSrcweir 	{
199*cdf0e10cSrcweir 		sNew = i_sSrcDirectory;
200*cdf0e10cSrcweir 		sNew += "\\";
201*cdf0e10cSrcweir 		sNew += aEntry.name;
202*cdf0e10cSrcweir 		o_sFiles.push_back(sNew);
203*cdf0e10cSrcweir 	}	// end for
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 	_findclose(hFile);
206*cdf0e10cSrcweir 	delete [] sFilter;
207*cdf0e10cSrcweir #elif defined(UNX) || defined(OS2)
208*cdf0e10cSrcweir 	DIR * pDir = opendir( i_sSrcDirectory );
209*cdf0e10cSrcweir 	dirent * pEntry = 0;
210*cdf0e10cSrcweir 	char * sEnding;
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 	// Stayingalive sign
213*cdf0e10cSrcweir 	if (++nAliveCounter % 100 == 1)
214*cdf0e10cSrcweir 		std::cout << "." << std::flush;
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 	while ( (pEntry = readdir(pDir)) != 0 )
217*cdf0e10cSrcweir 	{
218*cdf0e10cSrcweir 		sEnding = strrchr(pEntry->d_name,'.');
219*cdf0e10cSrcweir 		if (sEnding != 0 ? stricmp(sEnding,".xml") == 0 : 0 )
220*cdf0e10cSrcweir 		{
221*cdf0e10cSrcweir 			sNew = i_sSrcDirectory;
222*cdf0e10cSrcweir 			sNew += "/";
223*cdf0e10cSrcweir 			sNew += pEntry->d_name;
224*cdf0e10cSrcweir 			o_sFiles.push_back(sNew);
225*cdf0e10cSrcweir 		}
226*cdf0e10cSrcweir 	}	// end while
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 	closedir( pDir );
229*cdf0e10cSrcweir #else
230*cdf0e10cSrcweir #error Must run on unix or windows, please define UNX or WNT.
231*cdf0e10cSrcweir #endif
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 	//  gathering from subdirectories:
234*cdf0e10cSrcweir 	List<Simstr> aSubDirectories;
235*cdf0e10cSrcweir 	GatherSubDirectories( aSubDirectories, i_sSrcDirectory );
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 	unsigned d_max = aSubDirectories.size();
238*cdf0e10cSrcweir 	for ( unsigned d = 0; d < d_max; ++d )
239*cdf0e10cSrcweir 	{
240*cdf0e10cSrcweir 		sNextDir = new char[ strlen(i_sSrcDirectory) + 2 + aSubDirectories[d].l() ];
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 		strcpy(sNextDir, i_sSrcDirectory);
243*cdf0e10cSrcweir 		strcat(sNextDir, C_sSLASH);
244*cdf0e10cSrcweir 		strcat(sNextDir, aSubDirectories[d].str());
245*cdf0e10cSrcweir 		GatherFileNames(o_sFiles, sNextDir);
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 		delete [] sNextDir;
248*cdf0e10cSrcweir 	}
249*cdf0e10cSrcweir }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir const char * C_sANYDIR = "\\*.*";
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir void
255*cdf0e10cSrcweir GatherSubDirectories( List<Simstr> &   	o_sSubDirectories,
256*cdf0e10cSrcweir 					  const char *	   	i_sParentdDirectory )
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir 	Simstr sNew;
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir #ifdef WNT
261*cdf0e10cSrcweir 	struct _finddata_t aEntry;
262*cdf0e10cSrcweir 	long hFile = 0;
263*cdf0e10cSrcweir 	int bFindMore = 0;
264*cdf0e10cSrcweir 	char * sFilter = new char[strlen(i_sParentdDirectory) + sizeof C_sANYDIR];
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 	strcpy(sFilter, i_sParentdDirectory);
267*cdf0e10cSrcweir 	strcat(sFilter,C_sANYDIR);
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 	hFile = _findfirst( sFilter, &aEntry );
270*cdf0e10cSrcweir 	for ( bFindMore = hFile == -1;
271*cdf0e10cSrcweir 		  bFindMore == 0;
272*cdf0e10cSrcweir 		  bFindMore = _findnext( hFile, &aEntry ) )
273*cdf0e10cSrcweir 	{
274*cdf0e10cSrcweir 		if (aEntry.attrib == _A_SUBDIR)
275*cdf0e10cSrcweir 		{
276*cdf0e10cSrcweir 			// Do not gather . .. and outputtree directories
277*cdf0e10cSrcweir 			if ( strchr(aEntry.name,'.') == 0
278*cdf0e10cSrcweir 				 && strncmp(aEntry.name, "wnt", 3) != 0
279*cdf0e10cSrcweir 				 && strncmp(aEntry.name, "unx", 3) != 0 )
280*cdf0e10cSrcweir 			{
281*cdf0e10cSrcweir 				sNew = aEntry.name;
282*cdf0e10cSrcweir 				o_sSubDirectories.push_back(sNew);
283*cdf0e10cSrcweir 			}
284*cdf0e10cSrcweir 		}   // endif (aEntry.attrib == _A_SUBDIR)
285*cdf0e10cSrcweir 	}   // end for
286*cdf0e10cSrcweir 	_findclose(hFile);
287*cdf0e10cSrcweir 	delete [] sFilter;
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir #elif defined(UNX) || defined(OS2)
290*cdf0e10cSrcweir 	DIR * pDir = opendir( i_sParentdDirectory );
291*cdf0e10cSrcweir 	dirent * pEntry = 0;
292*cdf0e10cSrcweir 	struct stat 	aEntryStatus;
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 	while ( ( pEntry = readdir(pDir) ) != 0 )
295*cdf0e10cSrcweir 	{
296*cdf0e10cSrcweir 		stat(pEntry->d_name, &aEntryStatus);
297*cdf0e10cSrcweir 		if ( ( aEntryStatus.st_mode & S_IFDIR ) == S_IFDIR )
298*cdf0e10cSrcweir 		{
299*cdf0e10cSrcweir 			// Do not gather . .. and outputtree directories
300*cdf0e10cSrcweir 			if ( strchr(pEntry->d_name,'.') == 0
301*cdf0e10cSrcweir 				 && strncmp(pEntry->d_name, "wnt", 3) != 0
302*cdf0e10cSrcweir 				 && strncmp(pEntry->d_name, "unx", 3) != 0 )
303*cdf0e10cSrcweir 			{
304*cdf0e10cSrcweir 				sNew = pEntry->d_name;
305*cdf0e10cSrcweir 				o_sSubDirectories.push_back(sNew);
306*cdf0e10cSrcweir 			}
307*cdf0e10cSrcweir 		}   // endif (aEntry.attrib == _A_SUBDIR)
308*cdf0e10cSrcweir 	}	// end while
309*cdf0e10cSrcweir 	closedir( pDir );
310*cdf0e10cSrcweir #else
311*cdf0e10cSrcweir #error Must run on unix or windows, please define UNX or WNT.
312*cdf0e10cSrcweir #endif
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir 
315