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 #include <precomp.h> 29 #include <adoc/docu_pe.hxx> 30 31 32 // NOT FULLY DEFINED SERVICES 33 #include <ary/doc/d_oldcppdocu.hxx> 34 #include <ary/info/ci_attag.hxx> 35 #include <ary/info/ci_text.hxx> 36 #include <adoc/adoc_tok.hxx> 37 #include <adoc/tk_attag.hxx> 38 #include <adoc/tk_docw.hxx> 39 40 41 namespace adoc 42 { 43 44 45 inline bool 46 Adoc_PE::UsesHtmlInDocuText() 47 { 48 return bUsesHtmlInDocuText; 49 } 50 51 52 53 54 Adoc_PE::Adoc_PE() 55 : pCurDocu(0), 56 pCurAtTag(0), 57 nLineCountInDocu(0), 58 nCurSpecialMeaningTokens(0), 59 nCurSubtractFromLineStart(0), 60 eCurTagState(ts_new), 61 eDocuState(ds_wait_for_short), 62 bIsComplete(false), 63 bUsesHtmlInDocuText(false) 64 { 65 } 66 67 Adoc_PE::~Adoc_PE() 68 { 69 } 70 71 void 72 Adoc_PE::Hdl_at_std( const Tok_at_std & i_rTok ) 73 { 74 InstallAtTag( 75 CurDocu().Create_StdTag(i_rTok.Id()) ); 76 } 77 78 void 79 Adoc_PE::Hdl_at_base( const Tok_at_base & ) 80 { 81 InstallAtTag( 82 CurDocu().CheckIn_BaseTag() ); 83 } 84 85 void 86 Adoc_PE::Hdl_at_exception( const Tok_at_exception & ) 87 { 88 InstallAtTag( 89 CurDocu().CheckIn_ExceptionTag() ); 90 } 91 92 void 93 Adoc_PE::Hdl_at_impl( const Tok_at_impl & ) 94 { 95 InstallAtTag( 96 CurDocu().Create_ImplementsTag() ); 97 } 98 99 void 100 Adoc_PE::Hdl_at_key( const Tok_at_key & ) 101 { 102 InstallAtTag( 103 CurDocu().Create_KeywordTag() ); 104 } 105 106 void 107 Adoc_PE::Hdl_at_param( const Tok_at_param & ) 108 { 109 InstallAtTag( 110 CurDocu().CheckIn_ParameterTag() ); 111 } 112 113 void 114 Adoc_PE::Hdl_at_see( const Tok_at_see & ) 115 { 116 InstallAtTag( 117 CurDocu().CheckIn_SeeTag() ); 118 } 119 120 void 121 Adoc_PE::Hdl_at_template( const Tok_at_template & ) 122 { 123 InstallAtTag( 124 CurDocu().CheckIn_TemplateTag() ); 125 } 126 127 void 128 Adoc_PE::Hdl_at_interface( const Tok_at_interface & ) 129 { 130 CurDocu().Set_Interface(); 131 } 132 133 void 134 Adoc_PE::Hdl_at_internal( const Tok_at_internal & ) 135 { 136 CurDocu().Set_Internal(); 137 } 138 139 void 140 Adoc_PE::Hdl_at_obsolete( const Tok_at_obsolete & ) 141 { 142 CurDocu().Set_Obsolete(); 143 } 144 145 void 146 Adoc_PE::Hdl_at_module( const Tok_at_module & ) 147 { 148 // KORR_FUTURE 149 150 // pCurAtTag = CurDocu().Assign2_ModuleTag(); 151 // nCurSpecialMeaningTokens = pCurAtTag->NrOfSpecialMeaningTokens(); 152 } 153 154 void 155 Adoc_PE::Hdl_at_file( const Tok_at_file & ) 156 { 157 // KORR_FUTURE 158 159 // pCurAtTag = CurDocu().Assign2_FileTag(); 160 // nCurSpecialMeaningTokens = pCurAtTag->NrOfSpecialMeaningTokens(); 161 } 162 163 void 164 Adoc_PE::Hdl_at_gloss( const Tok_at_gloss & ) 165 { 166 // KORR_FUTURE 167 168 // Create_GlossaryEntry(); 169 } 170 171 void 172 Adoc_PE::Hdl_at_global( const Tok_at_global & ) 173 { 174 // KORR_FUTURE 175 // Create_GlobalTextComponent(); 176 } 177 178 void 179 Adoc_PE::Hdl_at_include( const Tok_at_include & ) 180 { 181 // KORR_FUTURE 182 } 183 184 void 185 Adoc_PE::Hdl_at_label( const Tok_at_label & ) 186 { 187 InstallAtTag( 188 CurDocu().Create_LabelTag() ); 189 } 190 191 void 192 Adoc_PE::Hdl_at_since( const Tok_at_since & ) 193 { 194 InstallAtTag( 195 CurDocu().Create_SinceTag() ); 196 } 197 198 void 199 Adoc_PE::Hdl_at_HTML( const Tok_at_HTML & ) 200 { 201 bUsesHtmlInDocuText = true; 202 } 203 204 void 205 Adoc_PE::Hdl_at_NOHTML( const Tok_at_NOHTML & ) 206 { 207 bUsesHtmlInDocuText = false; 208 } 209 210 void 211 Adoc_PE::Hdl_DocWord( const Tok_DocWord & i_rTok ) 212 { 213 bool bIsSpecial = false; 214 if ( nCurSpecialMeaningTokens > 0 ) 215 { 216 bIsSpecial = CurAtTag().Add_SpecialMeaningToken( 217 i_rTok.Text(), 218 CurAtTag().NrOfSpecialMeaningTokens() 219 - (--nCurSpecialMeaningTokens) ); 220 } 221 222 if ( NOT bIsSpecial ) 223 { 224 if ( eDocuState == ds_wait_for_short OR eDocuState == ds_1newline_after_short ) 225 eDocuState = ds_in_short; 226 if (nLineCountInDocu == 0) 227 nLineCountInDocu = 1; 228 229 uintt nLength = i_rTok.Length(); 230 if ( nLength > 2 ) 231 { 232 bool bMaybeGlobalLink = strncmp( "::", i_rTok.Text(), 2 ) == 0; 233 bool bMayBeFunction = *(i_rTok.Text() + nLength - 2) == '(' 234 AND *(i_rTok.Text() + nLength - 1) == ')'; 235 if ( bMaybeGlobalLink OR bMayBeFunction ) 236 { 237 CurAtTag().Add_PotentialLink( i_rTok.Text(), 238 bMaybeGlobalLink, 239 bMayBeFunction ); 240 return; 241 } 242 } 243 244 CurAtTag().Add_Token( i_rTok.Text() ); 245 eCurTagState = ts_std; 246 } 247 } 248 249 void 250 Adoc_PE::Hdl_Whitespace( const Tok_Whitespace & i_rTok ) 251 { 252 if ( eCurTagState == ts_std ) 253 { 254 255 CurAtTag().Add_Whitespace(i_rTok.Size()); 256 } 257 } 258 259 void 260 Adoc_PE::Hdl_LineStart( const Tok_LineStart & i_rTok ) 261 { 262 if ( pCurAtTag == 0 ) 263 return; 264 265 if ( nLineCountInDocu == 2 ) 266 { 267 nCurSubtractFromLineStart = i_rTok.Size(); 268 eCurTagState = ts_std; 269 } 270 else if ( nLineCountInDocu > 2 ) 271 { 272 if ( i_rTok.Size() > nCurSubtractFromLineStart ) 273 { 274 CurAtTag().Add_Whitespace( i_rTok.Size() 275 - nCurSubtractFromLineStart ); 276 } 277 // else do nothing, because there is no whitespace. 278 } 279 } 280 281 void 282 Adoc_PE::Hdl_Eol( const Tok_Eol & ) 283 { 284 if ( pCurAtTag == 0 ) 285 return; 286 287 nLineCountInDocu++; 288 289 if ( nCurSpecialMeaningTokens == 0 ) 290 { 291 CurAtTag().Add_Eol(); 292 293 switch ( eDocuState ) 294 { 295 case ds_wait_for_short: break; 296 case ds_in_short: if ( nLineCountInDocu < 4 ) 297 eDocuState = ds_1newline_after_short; 298 else 299 { 300 RenameCurShortTag(); 301 eDocuState = ds_in_descr; 302 } 303 break; 304 case ds_1newline_after_short: FinishCurShortTag(); 305 eDocuState = ds_in_descr; 306 break; 307 default: 308 ; // Do noting. 309 } 310 } 311 else 312 { 313 nCurSpecialMeaningTokens = 0; 314 } 315 316 317 } 318 319 void 320 Adoc_PE::Hdl_EoDocu( const Tok_EoDocu & ) 321 { 322 bIsComplete = true; 323 } 324 325 DYN ary::doc::OldCppDocu * 326 Adoc_PE::ReleaseJustParsedDocu() 327 { 328 pCurAtTag = 0; 329 nLineCountInDocu = 0; 330 nCurSpecialMeaningTokens = 0; 331 nCurSubtractFromLineStart = 0; 332 eCurTagState = ts_new; 333 eDocuState = ds_wait_for_short; 334 bIsComplete = false; 335 return pCurDocu.Release(); 336 } 337 338 void 339 Adoc_PE::InstallAtTag( DYN ary::info::AtTag * let_dpTag, 340 bool i_bImplicit ) 341 { 342 pCurAtTag = let_dpTag; 343 if ( pCurAtTag != 0 ) 344 { 345 nCurSpecialMeaningTokens = pCurAtTag->NrOfSpecialMeaningTokens(); 346 pCurAtTag->Set_HtmlUseInDocuText( bUsesHtmlInDocuText ); 347 } 348 349 eCurTagState = ts_new; 350 if ( NOT i_bImplicit ) 351 eDocuState = ds_std; 352 } 353 354 ary::doc::OldCppDocu & 355 Adoc_PE::CurDocu() 356 { 357 if (NOT pCurDocu) 358 pCurDocu = new ary::doc::OldCppDocu; 359 return *pCurDocu; 360 } 361 362 ary::info::AtTag & 363 Adoc_PE::CurAtTag() 364 { 365 if (NOT pCurAtTag) 366 { 367 if ( int(eDocuState) < int(ds_in_descr) ) 368 { 369 InstallAtTag( 370 CurDocu().Create_StdTag(ary::info::atid_short), 371 true ); 372 } 373 else 374 { 375 InstallAtTag( 376 CurDocu().Create_StdTag(ary::info::atid_descr), 377 true ); 378 } 379 } 380 return *pCurAtTag; 381 } 382 383 void 384 Adoc_PE::RenameCurShortTag() 385 { 386 CurDocu().Replace_AtShort_By_AtDescr(); 387 } 388 389 void 390 Adoc_PE::FinishCurShortTag() 391 { 392 InstallAtTag( 393 CurDocu().Create_StdTag(ary::info::atid_descr), 394 true ); 395 } 396 397 398 } // namespace adoc 399 400 401 402 403 404