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