1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <precomp.h>
23 #include "hdimpl.hxx"
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <ary/ceslot.hxx>
30 #include <ary/qualiname.hxx>
31 #include <ary/cpp/c_class.hxx>
32 #include <ary/cpp/c_de.hxx>
33 #include <ary/cpp/c_enum.hxx>
34 #include <ary/cpp/c_funct.hxx>
35 #include <ary/cpp/c_gate.hxx>
36 #include <ary/cpp/cp_ce.hxx>
37 #include <udm/html/htmlitem.hxx>
38 #include "cre_link.hxx"
39 #include "hd_docu.hxx"
40 #include "html_kit.hxx"
41 #include "opageenv.hxx"
42 #include "pagemake.hxx"
43 #include "strconst.hxx"
44 
45 
46 using namespace csi;
47 
48 
49 //********************       HtmlDisplay_Impl        *********************//
50 
~HtmlDisplay_Impl()51 HtmlDisplay_Impl::~HtmlDisplay_Impl()
52 {
53 }
54 
HtmlDisplay_Impl(OuputPage_Environment & io_rEnv)55 HtmlDisplay_Impl::HtmlDisplay_Impl( OuputPage_Environment & io_rEnv )
56     :   pEnv(&io_rEnv)
57         // aWriteHelper
58 {
59 }
60 
61 
62 //********************       Free Functions        *********************//
63 
64 
65 
66 namespace dshelp
67 {
68 
69 void
DisplaySlot(ary::Display & o_rDisplay,const ary::AryGroup & i_rGroup,ary::SlotAccessId i_nSlot)70 DisplaySlot( ary::Display &          o_rDisplay,
71              const ary::AryGroup &   i_rGroup,
72              ary::SlotAccessId       i_nSlot )
73 {
74  	ary::Slot_AutoPtr pSlot( i_rGroup.Create_Slot(i_nSlot) );
75     pSlot->StoreAt( o_rDisplay );
76 }
77 
78 
79 const char *
PathUp(uintt i_nLevels)80 PathUp( uintt i_nLevels )
81 {
82     static char sResult[300];
83 
84     sResult[0] = NULCH;
85     for ( uintt lev = 0; lev < i_nLevels; ++lev )
86     {
87         strcat( sResult, "../");        // SAFE STRCAT (#100211# - checked)
88     }
89     return sResult;
90 }
91 
92 const char *
PathPerLevelsUp(uintt i_nLevels,const char * i_nPathBelowDestinationLevel)93 PathPerLevelsUp( uintt                   i_nLevels,
94                  const char *            i_nPathBelowDestinationLevel )
95 {
96     static char sResult[500];
97     strcpy( sResult, PathUp(i_nLevels) );               // SAFE STRCPY (#100211# - checked)
98     // KORR_FUTURE: Make it still safer here:
99     strcat( sResult, i_nPathBelowDestinationLevel );    // SAFE STRCAT (#100211# - checked)
100     return sResult;
101 }
102 
103 
104 const char *
PathPerRoot(const OuputPage_Environment & i_rEnv,const char * i_sPathFromRootDir)105 PathPerRoot( const OuputPage_Environment & i_rEnv,
106              const char *                  i_sPathFromRootDir )
107 {
108     return PathPerLevelsUp( i_rEnv.Depth(), i_sPathFromRootDir );
109 }
110 
111 const char *
PathPerNamespace(const OuputPage_Environment & i_rEnv,const char * i_sPathFromNamespaceDir)112 PathPerNamespace( const OuputPage_Environment & i_rEnv,
113                   const char *                  i_sPathFromNamespaceDir )
114 {
115     const ary::cpp::Namespace * pNsp = i_rEnv.CurNamespace();
116     if ( pNsp == 0 )
117         return "";
118 
119     uintt nCount = i_rEnv.Depth() - (pNsp->Depth() + 1) ;
120     csv_assert( nCount < 100 );
121     return PathPerLevelsUp( nCount, i_sPathFromNamespaceDir );
122 }
123 
124 const char *
HtmlFileName(const char * i_sPrefix,const char * i_sEntityName)125 HtmlFileName( const char *            i_sPrefix,
126               const char *            i_sEntityName )
127 {
128     // KORR_FUTURE: Make it still safer here:
129     static char sResult[300];
130     strcpy( sResult, i_sPrefix );       // SAFE STRCPY (#100211# - checked)
131     strcat( sResult, i_sEntityName );   // SAFE STRCAT (#100211# - checked)
132     strcat( sResult, ".html" );         // SAFE STRCAT (#100211# - checked)
133     return sResult;
134 }
135 
136 const char *
Path2Class(uintt i_nLevelsUp,const char * i_sClassLocalName)137 Path2Class( uintt                   i_nLevelsUp,
138             const char *            i_sClassLocalName )
139 {
140     return PathPerLevelsUp( i_nLevelsUp, ClassFileName(i_sClassLocalName) );
141 }
142 
143 const char *
Path2Child(const char * i_sFileName,const char * i_sSubDir)144 Path2Child( const char *            i_sFileName,
145             const char *            i_sSubDir )
146 {
147     static char sResult[400];
148     if ( i_sSubDir != 0 )
149     {
150         // KORR_FUTURE: Make it still safer here:
151         strcpy( sResult, i_sSubDir );       // SAFE STRCPY (#100211# - checked)
152         strcat( sResult, "/" );             // SAFE STRCAT (#100211# - checked)
153     }
154     else
155     {
156         sResult[0] = NULCH;
157     }
158 
159     strcat( sResult, i_sFileName );         // SAFE STRCAT (#100211# - checked)
160     return sResult;
161 }
162 
163 const char *
Path2ChildNamespace(const char * i_sLocalName)164 Path2ChildNamespace( const char * i_sLocalName )
165 {
166     return Path2Child( C_sHFN_Namespace, i_sLocalName );
167 }
168 
169 String
OperationLink(const ary::cpp::Gate &,const String & i_sOpName,ary::cpp::Ce_id i_nOpId,const char * i_sPrePath)170 OperationLink( const ary::cpp::Gate &               ,
171                const String  &                      i_sOpName,
172                ary::cpp::Ce_id                      i_nOpId,
173                const char *                         i_sPrePath )
174 {
175     StreamLock
176         slResult(3000);
177     StreamStr &
178         sResult = slResult();
179 
180     sResult
181         << i_sPrePath
182         << "#"
183         << i_sOpName
184         << "-"
185         << i_nOpId.Value();
186 
187 
188 
189     return sResult.c_str();
190 }
191 
192 const char *
DataLink(const String & i_sLocalName,const char * i_sPrePath)193 DataLink( const String  &         i_sLocalName,
194           const char *            i_sPrePath )
195 {
196     StreamLock
197         slResult(3000);
198     StreamStr &
199         sResult = slResult();
200 
201     sResult
202         << i_sPrePath
203         << "#"
204         << i_sLocalName;
205 
206     return sResult.c_str();
207 }
208 
209 void
Get_LinkedTypeText(csi::xml::Element & o_rOut,const OuputPage_Environment & i_rEnv,ary::cpp::Type_id i_nId,bool i_bWithAbsolutifier)210 Get_LinkedTypeText( csi::xml::Element &             o_rOut,
211                     const OuputPage_Environment &   i_rEnv,
212                     ary::cpp::Type_id               i_nId,
213                     bool                            i_bWithAbsolutifier )
214 {
215     if (NOT i_nId.IsValid())
216         return;
217 
218  	const char * sPreName = "";
219  	const char * sName = "";
220  	const char * sPostName = "";
221 
222     bool bTypeExists = Get_TypeText( sPreName,
223                                      sName,
224                                      sPostName,
225                                      i_nId,
226                                      i_rEnv.Gate() );
227     if ( NOT bTypeExists )
228         return;
229 
230     if ( NOT i_bWithAbsolutifier AND strncmp(sPreName,"::",2) == 0 )
231         sPreName+=2;
232 
233     const ary::cpp::CodeEntity *
234         pCe = i_rEnv.Gate().Search_RelatedCe(i_nId);
235 
236     String  sLink;
237     if ( pCe != 0 )
238     {
239         sLink = Link2Ce(i_rEnv,*pCe);
240     }
241     else
242     {
243         if ( strstr(sPreName,"com::sun::star") != 0 )
244         {
245             static StreamStr aLink(400);
246             aLink.seekp(0);
247             aLink << PathPerRoot(i_rEnv, "../../common/ref");
248             if ( *sPreName != ':' )
249                 aLink << '/';
250             for ( const char * s = sPreName;
251                   *s != 0;
252                   ++s )
253             {
254                 if ( *s == ':' )
255                 {
256                  	aLink << '/';
257                     ++s;
258                 }
259                 else
260                 {
261                  	aLink << *s;
262                 }
263             }   // end for
264             aLink << sName
265                   << ".html";
266             sLink = aLink.c_str();
267         }
268     }   // endif( pCe != 0 )
269 
270     o_rOut
271         << sPreName;
272     csi::xml::Element &
273         o_Goon = sLink.length() > 0
274                      ?   o_rOut >> * new html::Link( sLink.c_str() )
275                      :   o_rOut;
276     o_Goon
277         <<  sName;
278     o_rOut
279         << sPostName;
280 }
281 
282 void
Create_ChildListLabel(csi::xml::Element & o_rParentElement,const char * i_sLabel)283 Create_ChildListLabel( csi::xml::Element &     o_rParentElement,
284                        const char *            i_sLabel )
285 {
286     if ( NOT csv::no_str(i_sLabel) )
287     {
288         o_rParentElement
289             >> *new html::Label(i_sLabel)
290                     << " ";
291     }
292 }
293 
294 DYN csi::html::Table &
Create_ChildListTable(const char * i_sTitle)295 Create_ChildListTable( const char * i_sTitle )
296 {
297     html::Table *
298             dpTable = new html::Table;
299     *dpTable
300         << new html::ClassAttr( "childlist")
301         << new xml::AnAttribute( "border", "1" )
302         << new xml::AnAttribute( "cellpadding", "5" )
303         << new xml::AnAttribute( "cellspacing", "0" )
304         << new html::WidthAttr( "100%" );
305 
306     html::TableRow &
307             rRow = dpTable->AddRow();
308     rRow
309         << new html::ClassAttr("subtitle")
310         >> *new html::TableCell
311                 << new xml::AnAttribute( "colspan","2" )
312                 >> *new html::Headline(4)
313                         << i_sTitle;
314     return *dpTable;
315 }
316 
317 const char *
Link2Ce(const OuputPage_Environment & i_rEnv,const ary::cpp::CodeEntity & i_rCe)318 Link2Ce( const OuputPage_Environment & i_rEnv,
319          const ary::cpp::CodeEntity &  i_rCe )
320 {
321     const uintt         nMaxSize
322                             = 3000;
323     static char         sLink[nMaxSize];
324     static LinkCreator  aLinkCreator( &sLink[0], nMaxSize );
325     sLink[0] = NULCH;
326 
327     aLinkCreator.SetEnv(i_rEnv);
328     i_rCe.Accept(aLinkCreator);
329 
330     return sLink;
331 }
332 
333 const char *
Link2CppDefinition(const OuputPage_Environment & i_rEnv,const ary::cpp::DefineEntity & i_rDef)334 Link2CppDefinition( const OuputPage_Environment & i_rEnv,
335                     const ary::cpp::DefineEntity &    i_rDef )
336 {
337     const uintt         nMaxSize
338                             = 1000;
339     static char         sLink[nMaxSize];
340     static LinkCreator  aLinkCreator( &sLink[0], nMaxSize );
341     sLink[0] = NULCH;
342 
343     aLinkCreator.SetEnv(i_rEnv);
344     i_rDef.Accept(aLinkCreator);
345 
346     return sLink;
347 }
348 
349 const ary::cpp::CodeEntity *
FindUnambiguousCe(const OuputPage_Environment & i_rEnv,const ary::QualifiedName & i_rQuName,const ary::cpp::Class * i_pJustDocumentedClass)350 FindUnambiguousCe( const OuputPage_Environment & i_rEnv,
351                    const ary::QualifiedName &    i_rQuName,
352                    const ary::cpp::Class *       i_pJustDocumentedClass )
353 {
354  	if ( i_rEnv.CurNamespace() == 0 )
355 		return 0;
356 
357 	const ary::cpp::CodeEntity * ret = 0;
358 
359     if ( NOT i_rQuName.IsQualified() )
360     {
361         if ( i_pJustDocumentedClass != 0 )
362             ret = i_rEnv.Gate().Ces().Search_CeLocal( i_rQuName.LocalName(),
363                                                       i_rQuName.IsFunction(),
364                                                       *i_rEnv.CurNamespace(),
365                                                       i_pJustDocumentedClass );
366         if (ret != 0)
367             return ret;
368 
369         ret = i_rEnv.Gate().Ces().Search_CeLocal( i_rQuName.LocalName(),
370                                                   i_rQuName.IsFunction(),
371                                                   *i_rEnv.CurNamespace(),
372                                                   i_rEnv.CurClass() );
373     }
374     if (ret != 0)
375         return ret;
376 
377     return i_rEnv.Gate().Ces().Search_CeAbsolute( *i_rEnv.CurNamespace(),
378                                                   i_rQuName );
379 }
380 
381 void
ShowDocu_On(csi::xml::Element & o_rOut,Docu_Display & io_rDisplay,const ary::cpp::CppEntity & i_rRE)382 ShowDocu_On( csi::xml::Element &            o_rOut,
383              Docu_Display &                 io_rDisplay,
384              const ary::cpp::CppEntity &    i_rRE )
385 {
386     if (i_rRE.Docu().Data() != 0)
387     {
388         io_rDisplay.Assign_Out( o_rOut );
389         io_rDisplay.Process(i_rRE.Docu());
390         io_rDisplay.Unassign_Out();
391     }
392 }
393 
394 void
WriteOut_TokenList(csi::xml::Element & o_rOut,const StringVector & i_rTokens,const char * i_sSeparator)395 WriteOut_TokenList( csi::xml::Element &     o_rOut,
396                     const StringVector &    i_rTokens,
397                     const char *            i_sSeparator )
398 {
399     if ( i_rTokens.size() > 0 )
400     {
401         StringVector::const_iterator
402             it      = i_rTokens.begin();
403         StringVector::const_iterator
404             itEnd   = i_rTokens.end();
405 
406         o_rOut << *it;
407         for ( ++it; it != itEnd; ++it )
408         {
409             o_rOut << i_sSeparator << *it;
410         }
411     };
412 
413 }
414 
415 void
EraseLeadingSpace(String & io_rStr)416 EraseLeadingSpace( String  & io_rStr )
417 {
418     if ( *io_rStr.c_str() < 33 AND io_rStr.length() > 0 )
419     {
420         const unsigned char * pNew;
421         for ( pNew = (const unsigned char * ) io_rStr.c_str();
422               *pNew < 33 AND *pNew != 0;
423               ++pNew ) {}
424         String  sNew( (const char*)pNew );
425         io_rStr = sNew;
426     }
427 }
428 
429 void
WriteOut_LinkedFunctionText(csi::xml::Element & o_rTitleOut,adcdisp::ParameterTable & o_rParameters,const ary::cpp::Function & i_rFunction,const OuputPage_Environment & i_rEnv,bool * o_bIsConst,bool * o_bIsVirtual)430 WriteOut_LinkedFunctionText( csi::xml::Element &            o_rTitleOut,
431                              adcdisp::ParameterTable &      o_rParameters,
432                              const ary::cpp::Function &     i_rFunction,
433                              const OuputPage_Environment &  i_rEnv,
434                              bool *                         o_bIsConst,
435                              bool *                         o_bIsVirtual )
436 {
437     // write pre-name:
438     const ary::cpp::FunctionFlags & rFlags = i_rFunction.Flags();
439     if ( rFlags.IsStaticLocal() OR rFlags.IsStaticMember() )
440         o_rTitleOut << "static ";
441     if ( rFlags.IsExplicit() )
442         o_rTitleOut << "explicit ";
443     if ( rFlags.IsMutable() )
444         o_rTitleOut << "mutable ";
445     if ( i_rFunction.Virtuality() != ary::cpp::VIRTUAL_none )
446         o_rTitleOut << "virtual ";
447 //    o_rTitleOut << new html::LineBreak;
448 
449     Get_LinkedTypeText( o_rTitleOut, i_rEnv, i_rFunction.ReturnType() );
450 
451     // write name:
452     o_rTitleOut
453         << " "
454         >> *new html::Strong
455             << i_rFunction.LocalName();
456     o_rTitleOut
457             << "(";
458 
459 
460     csi::xml::Element * pOutLast = &o_rTitleOut;
461 
462     // write post-name:
463     FunctionParam_Iterator fit;
464     fit.Assign(i_rFunction);
465 
466     if (fit)
467     {
468         o_rParameters.AddEntry();
469         Get_LinkedTypeText( o_rParameters.Type(), i_rEnv, fit.CurType() );
470         o_rParameters.Type() << " ";
471         o_rParameters.Name() << " " << fit.CurName();
472 
473         for ( ++fit; fit; ++fit )
474         {
475             o_rParameters.Name() << ",";
476             o_rParameters.AddEntry();
477             Get_LinkedTypeText( o_rParameters.Type(), i_rEnv, fit.CurType() );
478             o_rParameters.Name() << fit.CurName();
479         }
480 
481         pOutLast = &o_rParameters.Name();
482         o_rParameters.Name() << " ";
483     }
484 
485     *pOutLast  << ")";
486     if ( fit.IsFunctionConst() )
487     {
488         *pOutLast << " const";
489         if ( o_bIsConst != 0 )
490             *o_bIsConst = true;
491     }
492     if ( fit.IsFunctionVolatile() )
493     {
494         *pOutLast << " volatile";
495         if ( o_bIsVirtual != 0 )
496             *o_bIsVirtual = true;
497     }
498 
499     // write Exceptions:
500     const std::vector< ary::cpp::Type_id > *
501             pThrow = i_rFunction.Exceptions();
502     if ( pThrow)
503     {
504         std::vector< ary::cpp::Type_id >::const_iterator
505 		    	it = pThrow->begin();
506         std::vector< ary::cpp::Type_id >::const_iterator
507 	    		it_end = pThrow->end();
508 
509         if (it != it_end)
510         {
511             o_rParameters.AddEntry();
512             pOutLast = &o_rParameters.Name();
513 
514             o_rParameters.Name() << " throw( ";
515             Get_LinkedTypeText(o_rParameters.Name(), i_rEnv, *it);
516 
517             for ( ++it; it != it_end; ++it )
518             {
519                 o_rParameters.Name() << ", ";
520                 Get_LinkedTypeText(o_rParameters.Name(), i_rEnv, *it);
521             }
522             o_rParameters.Name() << " )";
523         }
524         else
525         {
526             *pOutLast << " throw()";
527         }
528     }   // endif // pThrow
529 
530     // abstractness:
531     if ( i_rFunction.Virtuality() == ary::cpp::VIRTUAL_abstract )
532         *pOutLast << " = 0";
533 
534     // finish:
535     *pOutLast << ";";
536 }
537 
538 
539 
540 }   // namespace dshelp
541