Update ooo320-m1
[ooovba.git] / xml2cmp / source / support / syshelp.cxx
blobf25d8e975b92cd3ecb66d11a83beb7cb27ebaf16
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: syshelp.cxx,v $
10 * $Revision: 1.13 $
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 ************************************************************************/
32 #include <syshelp.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <string.h>
37 #include "sistr.hxx"
38 #include "list.hxx"
40 #ifdef WNT
41 #include <io.h>
42 #elif defined(UNX) || defined(OS2)
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <dirent.h>
46 #define stricmp strcasecmp
47 #else
48 #error Must run under unix or windows, please define UNX or WNT.
49 #endif
52 char C_sSpaceInName[] = "&nbsp;&nbsp;&nbsp;";
54 void
55 WriteName( std::ostream & o_rFile,
56 const Simstr & i_rIdlDocuBaseDir,
57 const Simstr & i_rName,
58 E_LinkType i_eLinkType )
60 if (i_rName.l() == 0)
61 return;
64 const char * pNameEnd = strstr( i_rName.str(), " in " );
66 // No link:
67 if ( i_eLinkType == lt_nolink )
69 if ( pNameEnd != 0 )
71 const char * pStart = i_rName.str();
72 o_rFile.write( pStart, pNameEnd - pStart );
73 WriteStr( o_rFile, C_sSpaceInName );
74 WriteStr( o_rFile, pNameEnd );
76 else
78 WriteStr( o_rFile, i_rName );
80 return;
83 if ( i_eLinkType == lt_idl )
85 Simstr sPath(i_rName);
86 sPath.replace_all('.','/');
87 int nNameEnd = sPath.pos_first(' ');
88 int nPathStart = sPath.pos_last(' ');
89 WriteStr( o_rFile, "<A HREF=\"" );
91 if ( nNameEnd > -1 )
93 WriteStr( o_rFile, "file:///" );
94 WriteStr( o_rFile, i_rIdlDocuBaseDir );
95 WriteStr( o_rFile, "/" );
96 WriteStr( o_rFile, sPath.str() + 1 + nPathStart );
97 WriteStr( o_rFile, "/" );
98 o_rFile.write( sPath.str(), nNameEnd );
99 WriteStr( o_rFile, ".html\">" );
101 else
102 { // Should not be reached:
103 WriteStr(o_rFile, i_rName);
104 return;
107 else if ( i_eLinkType == lt_html )
109 int nKomma = i_rName.pos_first(',');
110 int nEnd = i_rName.pos_first(' ');
111 if ( nKomma > -1 )
113 o_rFile.write( i_rName.str(), nKomma );
114 WriteStr( o_rFile, ": " );
116 WriteStr( o_rFile, "<A HREF=\"" );
118 o_rFile.write( i_rName.str(), nKomma );
119 WriteStr( o_rFile, ".html#" );
120 if ( nEnd > -1 )
121 o_rFile.write( i_rName.str() + nKomma + 1, nEnd - nKomma );
122 else
123 WriteStr( o_rFile, i_rName.str() + nKomma + 1 );
124 WriteStr( o_rFile, "\">" );
126 o_rFile.write( i_rName.str() + nKomma + 1, nEnd - nKomma );
128 else
130 WriteStr( o_rFile, "<A HREF=\"" );
131 WriteStr( o_rFile, i_rName );
132 WriteStr( o_rFile, ".html\">" );
134 WriteStr( o_rFile, i_rName );
136 WriteStr( o_rFile, "</A>" );
137 return;
140 if ( pNameEnd != 0 )
142 const char * pStart = i_rName.str();
143 if ( pNameEnd > pStart )
144 o_rFile.write( pStart, pNameEnd - pStart );
145 WriteStr( o_rFile, "</A>" );
147 WriteStr( o_rFile, C_sSpaceInName );
148 WriteStr( o_rFile, pNameEnd );
150 else
152 WriteStr( o_rFile, i_rName );
153 WriteStr( o_rFile, "</A>" );
158 void
159 WriteStr( std::ostream & o_rFile,
160 const char * i_sStr )
162 o_rFile.write( i_sStr, (int) strlen(i_sStr) );
165 void
166 WriteStr( std::ostream & o_rFile,
167 const Simstr & i_sStr )
169 o_rFile.write( i_sStr.str(), i_sStr.l() );
173 const char C_sXML_END[] = "\\*.xml";
175 void
176 GatherFileNames( List<Simstr> & o_sFiles,
177 const char * i_sSrcDirectory )
179 static int nAliveCounter = 0;
181 char * sNextDir = 0;
182 Simstr sNew = 0;
184 #ifdef WNT
185 struct _finddata_t aEntry;
186 long hFile = 0;
187 int bFindMore = 0;
188 char * sFilter = new char[ strlen(i_sSrcDirectory) + sizeof C_sXML_END ];
190 // Stayingalive sign
191 if (++nAliveCounter % 100 == 1)
192 std::cout << "." << std::flush;
194 strcpy(sFilter, i_sSrcDirectory); // STRCPY SAFE HERE
195 strcat(sFilter,C_sXML_END); // STRCAT SAFE HERE
197 hFile = _findfirst( sFilter, &aEntry );
198 for ( bFindMore = hFile == -1;
199 bFindMore == 0;
200 bFindMore = _findnext( hFile, &aEntry ) )
202 sNew = i_sSrcDirectory;
203 sNew += "\\";
204 sNew += aEntry.name;
205 o_sFiles.push_back(sNew);
206 } // end for
208 _findclose(hFile);
209 delete [] sFilter;
210 #elif defined(UNX) || defined(OS2)
211 DIR * pDir = opendir( i_sSrcDirectory );
212 dirent * pEntry = 0;
213 char * sEnding;
215 // Stayingalive sign
216 if (++nAliveCounter % 100 == 1)
217 std::cout << "." << std::flush;
219 while ( (pEntry = readdir(pDir)) != 0 )
221 sEnding = strrchr(pEntry->d_name,'.');
222 if (sEnding != 0 ? stricmp(sEnding,".xml") == 0 : 0 )
224 sNew = i_sSrcDirectory;
225 sNew += "/";
226 sNew += pEntry->d_name;
227 o_sFiles.push_back(sNew);
229 } // end while
231 closedir( pDir );
232 #else
233 #error Must run on unix or windows, please define UNX or WNT.
234 #endif
236 // gathering from subdirectories:
237 List<Simstr> aSubDirectories;
238 GatherSubDirectories( aSubDirectories, i_sSrcDirectory );
240 unsigned d_max = aSubDirectories.size();
241 for ( unsigned d = 0; d < d_max; ++d )
243 sNextDir = new char[ strlen(i_sSrcDirectory) + 2 + aSubDirectories[d].l() ];
245 strcpy(sNextDir, i_sSrcDirectory);
246 strcat(sNextDir, C_sSLASH);
247 strcat(sNextDir, aSubDirectories[d].str());
248 GatherFileNames(o_sFiles, sNextDir);
250 delete [] sNextDir;
255 const char * C_sANYDIR = "\\*.*";
257 void
258 GatherSubDirectories( List<Simstr> & o_sSubDirectories,
259 const char * i_sParentdDirectory )
261 Simstr sNew;
263 #ifdef WNT
264 struct _finddata_t aEntry;
265 long hFile = 0;
266 int bFindMore = 0;
267 char * sFilter = new char[strlen(i_sParentdDirectory) + sizeof C_sANYDIR];
269 strcpy(sFilter, i_sParentdDirectory);
270 strcat(sFilter,C_sANYDIR);
272 hFile = _findfirst( sFilter, &aEntry );
273 for ( bFindMore = hFile == -1;
274 bFindMore == 0;
275 bFindMore = _findnext( hFile, &aEntry ) )
277 if (aEntry.attrib == _A_SUBDIR)
279 // Do not gather . .. and outputtree directories
280 if ( strchr(aEntry.name,'.') == 0
281 && strncmp(aEntry.name, "wnt", 3) != 0
282 && strncmp(aEntry.name, "unx", 3) != 0 )
284 sNew = aEntry.name;
285 o_sSubDirectories.push_back(sNew);
287 } // endif (aEntry.attrib == _A_SUBDIR)
288 } // end for
289 _findclose(hFile);
290 delete [] sFilter;
292 #elif defined(UNX) || defined(OS2)
293 DIR * pDir = opendir( i_sParentdDirectory );
294 dirent * pEntry = 0;
295 struct stat aEntryStatus;
297 while ( ( pEntry = readdir(pDir) ) != 0 )
299 stat(pEntry->d_name, &aEntryStatus);
300 if ( ( aEntryStatus.st_mode & S_IFDIR ) == S_IFDIR )
302 // Do not gather . .. and outputtree directories
303 if ( strchr(pEntry->d_name,'.') == 0
304 && strncmp(pEntry->d_name, "wnt", 3) != 0
305 && strncmp(pEntry->d_name, "unx", 3) != 0 )
307 sNew = pEntry->d_name;
308 o_sSubDirectories.push_back(sNew);
310 } // endif (aEntry.attrib == _A_SUBDIR)
311 } // end while
312 closedir( pDir );
313 #else
314 #error Must run on unix or windows, please define UNX or WNT.
315 #endif