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: syshelp.cxx,v $
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
42 #elif defined(UNX) || defined(OS2)
43 #include <sys/types.h>
46 #define stricmp strcasecmp
48 #error Must run under unix or windows, please define UNX or WNT.
52 char C_sSpaceInName
[] = " ";
55 WriteName( std::ostream
& o_rFile
,
56 const Simstr
& i_rIdlDocuBaseDir
,
57 const Simstr
& i_rName
,
58 E_LinkType i_eLinkType
)
64 const char * pNameEnd
= strstr( i_rName
.str(), " in " );
67 if ( i_eLinkType
== lt_nolink
)
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
);
78 WriteStr( o_rFile
, i_rName
);
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=\"" );
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\">" );
102 { // Should not be reached:
103 WriteStr(o_rFile
, i_rName
);
107 else if ( i_eLinkType
== lt_html
)
109 int nKomma
= i_rName
.pos_first(',');
110 int nEnd
= i_rName
.pos_first(' ');
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#" );
121 o_rFile
.write( i_rName
.str() + nKomma
+ 1, nEnd
- nKomma
);
123 WriteStr( o_rFile
, i_rName
.str() + nKomma
+ 1 );
124 WriteStr( o_rFile
, "\">" );
126 o_rFile
.write( i_rName
.str() + nKomma
+ 1, nEnd
- nKomma
);
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>" );
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
);
152 WriteStr( o_rFile
, i_rName
);
153 WriteStr( o_rFile
, "</A>" );
159 WriteStr( std::ostream
& o_rFile
,
160 const char * i_sStr
)
162 o_rFile
.write( i_sStr
, (int) strlen(i_sStr
) );
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";
176 GatherFileNames( List
<Simstr
> & o_sFiles
,
177 const char * i_sSrcDirectory
)
179 static int nAliveCounter
= 0;
185 struct _finddata_t aEntry
;
188 char * sFilter
= new char[ strlen(i_sSrcDirectory
) + sizeof C_sXML_END
];
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;
200 bFindMore
= _findnext( hFile
, &aEntry
) )
202 sNew
= i_sSrcDirectory
;
205 o_sFiles
.push_back(sNew
);
210 #elif defined(UNX) || defined(OS2)
211 DIR * pDir
= opendir( i_sSrcDirectory
);
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
;
226 sNew
+= pEntry
->d_name
;
227 o_sFiles
.push_back(sNew
);
233 #error Must run on unix or windows, please define UNX or WNT.
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
);
255 const char * C_sANYDIR
= "\\*.*";
258 GatherSubDirectories( List
<Simstr
> & o_sSubDirectories
,
259 const char * i_sParentdDirectory
)
264 struct _finddata_t aEntry
;
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;
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 )
285 o_sSubDirectories
.push_back(sNew
);
287 } // endif (aEntry.attrib == _A_SUBDIR)
292 #elif defined(UNX) || defined(OS2)
293 DIR * pDir
= opendir( i_sParentdDirectory
);
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)
314 #error Must run on unix or windows, please define UNX or WNT.