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 "cre_link.hxx" 24 25 26 // NOT FULLY DEFINED SERVICES 27 #include <ary/cpp/c_class.hxx> 28 #include <ary/cpp/c_define.hxx> 29 #include <ary/cpp/c_enum.hxx> 30 #include <ary/cpp/c_enuval.hxx> 31 #include <ary/cpp/c_funct.hxx> 32 #include <ary/cpp/c_gate.hxx> 33 #include <ary/cpp/c_macro.hxx> 34 #include <ary/cpp/c_namesp.hxx> 35 #include <ary/cpp/c_tydef.hxx> 36 #include <ary/cpp/c_vari.hxx> 37 #include <ary/cpp/cp_ce.hxx> 38 #include <ary/loc/loc_file.hxx> 39 #include <ary/loc/locp_le.hxx> 40 #include "hdimpl.hxx" 41 #include "opageenv.hxx" 42 #include "strconst.hxx" 43 44 45 46 47 48 LinkCreator::LinkCreator( char * o_rOutput, 49 uintt i_nOutputSize ) 50 : pOut(o_rOutput), 51 nOutMaxSize(i_nOutputSize), 52 pEnv(0) 53 { 54 } 55 56 LinkCreator::~LinkCreator() 57 { 58 } 59 60 void 61 LinkCreator::do_Process( const ary::cpp::Namespace & i_rData ) 62 { 63 Create_PrePath( i_rData ); 64 strcat( pOut, "index.html" ); // KORR_FUTURE // SAFE STRCAT (#100211# - checked) 65 } 66 67 void 68 LinkCreator::do_Process( const ary::cpp::Class & i_rData ) 69 { 70 Create_PrePath( i_rData ); 71 strcat( pOut, ClassFileName(i_rData.LocalName().c_str()) ); // SAFE STRCAT (#100211# - checked) 72 } 73 74 void 75 LinkCreator::do_Process( const ary::cpp::Enum & i_rData ) 76 { 77 Create_PrePath( i_rData ); 78 strcat( pOut, EnumFileName(i_rData.LocalName().c_str()) ); // SAFE STRCAT (#100211# - checked) 79 } 80 81 void 82 LinkCreator::do_Process( const ary::cpp::Typedef & i_rData ) 83 { 84 Create_PrePath( i_rData ); 85 strcat( pOut, TypedefFileName(i_rData.LocalName().c_str()) ); // SAFE STRCAT (#100211# - checked) 86 } 87 88 void 89 LinkCreator::do_Process( const ary::cpp::Function & i_rData ) 90 { 91 Create_PrePath( i_rData ); 92 93 if ( i_rData.Protection() != ary::cpp::PROTECT_global ) 94 { 95 strcat( pOut, "o.html" ); // SAFE STRCAT (#100211# - checked) 96 } 97 else 98 { 99 csv_assert(i_rData.Location().IsValid()); 100 const ary::loc::File & 101 rFile = pEnv->Gate().Locations().Find_File(i_rData.Location()); 102 strcat( pOut, HtmlFileName("o-", rFile.LocalName().c_str()) ); // SAFE STRCAT (#100211# - checked) 103 } 104 105 csv_assert(pEnv != 0); 106 strcat( pOut, OperationLink(pEnv->Gate(), i_rData.LocalName(), i_rData.CeId()) ); // SAFE STRCAT (#100211# - checked) 107 } 108 109 void 110 LinkCreator::do_Process( const ary::cpp::Variable & i_rData ) 111 { 112 Create_PrePath( i_rData ); 113 114 if ( i_rData.Protection() != ary::cpp::PROTECT_global ) 115 { 116 strcat( pOut, "d.html" ); // SAFE STRCAT (#100211# - checked) 117 } 118 else 119 { 120 csv_assert(i_rData.Location().IsValid()); 121 const ary::loc::File & 122 rFile = pEnv->Gate().Locations().Find_File(i_rData.Location()); 123 strcat( pOut, HtmlFileName("d-", rFile.LocalName().c_str()) ); // SAFE STRCAT (#100211# - checked) 124 } 125 126 strcat( pOut, DataLink(i_rData.LocalName()) ); // SAFE STRCAT (#100211# - checked) 127 } 128 129 void 130 LinkCreator::do_Process( const ary::cpp::EnumValue & i_rData ) 131 { 132 const ary::cpp::CodeEntity * 133 pEnum = pEnv->Gate().Ces().Search_Ce(i_rData.Owner()); 134 if (pEnum == 0) 135 return; 136 137 pEnum->Accept(*this); 138 strcat(pOut, "#"); // SAFE STRCAT (#100211# - checked) 139 strcat(pOut, i_rData.LocalName().c_str()); // SAFE STRCAT (#100211# - checked) 140 } 141 142 void 143 LinkCreator::do_Process( const ary::cpp::Define & i_rData ) 144 { 145 // KORR_FUTURE 146 // Only valid from Index: 147 148 *pOut = '\0'; 149 strcat(pOut, "../def-all.html#"); // SAFE STRCAT (#100211# - checked) 150 strcat(pOut, i_rData.LocalName().c_str()); // SAFE STRCAT (#100211# - checked) 151 } 152 153 void 154 LinkCreator::do_Process( const ary::cpp::Macro & i_rData ) 155 { 156 // KORR_FUTURE 157 // Only valid from Index: 158 159 *pOut = '\0'; 160 strcat(pOut, "../def-all.html#"); // SAFE STRCAT (#100211# - checked) 161 strcat(pOut, i_rData.LocalName().c_str()); // SAFE STRCAT (#100211# - checked) 162 } 163 164 165 namespace 166 { 167 168 class NameScope_const_iterator 169 { 170 public: 171 NameScope_const_iterator( 172 ary::cpp::Ce_id i_nId, 173 const ary::cpp::Gate & 174 i_rGate ); 175 176 operator bool() const { return pCe != 0; } 177 const String & operator*() const; 178 179 void go_up(); 180 181 private: 182 const ary::cpp::CodeEntity * 183 pCe; 184 const ary::cpp::Gate * 185 pGate; 186 }; 187 188 189 NameScope_const_iterator::NameScope_const_iterator( 190 ary::cpp::Ce_id i_nId, 191 const ary::cpp::Gate & i_rGate ) 192 : pCe(i_rGate.Ces().Search_Ce(i_nId)), 193 pGate(&i_rGate) 194 { 195 } 196 197 const String & 198 NameScope_const_iterator::operator*() const 199 { 200 return pCe ? pCe->LocalName() 201 : String::Null_(); 202 } 203 204 void 205 NameScope_const_iterator::go_up() 206 { 207 if (pCe == 0) 208 return; 209 pCe = pGate->Ces().Search_Ce(pCe->Owner()); 210 } 211 212 213 void Recursive_CreatePath( 214 char * o_pOut, 215 const NameScope_const_iterator & 216 i_it ); 217 218 void 219 Recursive_CreatePath( char * o_pOut, 220 const NameScope_const_iterator & i_it ) 221 { 222 if (NOT i_it) 223 return; 224 225 NameScope_const_iterator it( i_it ); 226 it.go_up(); 227 if (NOT it) 228 return; // Global Namespace 229 Recursive_CreatePath( o_pOut, it ); 230 231 strcat( o_pOut, (*i_it).c_str() ); // SAFE STRCAT (#100211# - checked) 232 strcat( o_pOut, "/" ); // SAFE STRCAT (#100211# - checked) 233 } 234 235 236 } // anonymous namespace 237 238 239 240 241 242 void 243 LinkCreator::Create_PrePath( const ary::cpp::CodeEntity & i_rData ) 244 { 245 *pOut = NULCH; 246 247 if ( pEnv->CurNamespace() != 0 ) 248 { 249 if ( pEnv->CurClass() 250 ? pEnv->CurClass()->CeId() == i_rData.Owner() 251 : pEnv->CurNamespace()->CeId() == i_rData.Owner() ) 252 return; 253 254 strcat( pOut, PathUp(pEnv->Depth() - 1) ); // SAFE STRCAT (#100211# - checked) 255 } 256 else 257 { // Within Index 258 strcat( pOut, "../names/" ); // SAFE STRCAT (#100211# - checked) 259 } 260 261 NameScope_const_iterator it( i_rData.Owner(), pEnv->Gate() ); 262 Recursive_CreatePath( pOut, it ); 263 } 264