gHtmlSeq.cpp

Go to the documentation of this file.
00001 // gHtmlSeq, part of gUnweb
00002 
00003 #include "gHtmlSeq.h"
00004 #include "gHtmlCtrl.h"
00005 ////////////////////////////////////////////////////////////
00006 gTagTree::gTagTree (char* descStr)
00007     : mCoord( -1 ),
00008       myTree( nil )
00009 {
00010  if ( descStr!=nil ) sDesc.Set( descStr );
00011 }
00012 
00013 gTagTree::~gTagTree ()
00014 {
00015  // Delete myTree not performed, because tree should be added somewhere-else!
00016 }
00017 
00018 char* gTagTree::Str ()
00019 {
00020  return sDesc.Str();
00021 }
00022 
00023 void gTagTree::Reset ()
00024 {
00025  mCoord = -1;
00026  myTree = nil;  // not allocated
00027  gTagCoord::Reset();
00028 }
00029 ////////////////////////////////////////////////////////////
00030 /* ---
00031 gHTrElem::gHTrElem ()
00032     : ptrBlock( nil ),
00033       nextNode( nil )
00034 {
00035 }
00036 
00037 gHTrElem::~gHTrElem ()
00038 {
00039  // Not a gStorage behaviour: the ptrBlock is not copied, but deleted by this gHTrElem...!
00040  delete ptrBlock;
00041 }
00042 
00043 char* gHTrElem::GetStr ()
00044 {
00045  ASSERTION(ptrBlock!=nil,"ptrBlock!=nil");
00046 
00047  sOutTr.SetEmpty();
00048 
00049  if ( ptrBlock->IsTag() ) {
00050      sOutTr.Set( "[" );
00051      sOutTr.Add( ptrBlock->GetTagPtr()->GetStr() );
00052      gString sTemp( 10, '\0' );
00053      sprintf(sTemp.Str(),":idTag=%d",ptrBlock->GetTagPtr()->idTag);
00054      sOutTr.AddString( sTemp );
00055      sOutTr.Add( "]" );
00056  }
00057 
00058  unsigned i, n = ptrBlock->N();
00059  if ( n>0 ) sOutTr.Add( '{' );
00060  for (i=1; i<=n; i++) {
00061      sOutTr.Add( ptrBlock->Str( i ) );
00062      if ( i<n ) sOutTr.Add( '#' );
00063  }
00064  if ( n>0 ) sOutTr.Add( '}' );
00065 
00066  return sOutTr.Str();
00067 }
00068 --- */
00069 ////////////////////////////////////////////////////////////
00070 gHNode::gHNode ()
00071     : nextNode( nil ),
00072       tSub( nil ),
00073       pCouple( nil )
00074 {
00075 }
00076 
00077 gHNode::~gHNode ()
00078 {
00079  delete tSub;
00080  tSub = nil;
00081 }
00082 
00083 gHtmlCouple* gHNode::GetCouple ()
00084 {
00085  ASSERTION(pCouple!=nil,"pCouple!=nil");
00086  return pCouple;
00087 }
00088 
00089 bool gHNode::SetCouplePtr (gHtmlCouple* ptrCouple)
00090 {
00091  ASSERTION(ptrCouple!=nil,"ptrCouple!=nil");
00092  pCouple = ptrCouple;
00093  return ptrCouple!=nil;
00094 }
00095 ////////////////////////////////////////////////////////////
00096 gHTree::gHTree ()
00097     : pStart( nil ),
00098       pEnd( nil )
00099 {
00100 }
00101 
00102 gHTree::~gHTree ()
00103 {
00104  Reset();
00105 }
00106 
00107 gHNode* gHTree::GetLastNode ()
00108 {
00109  ASSERTION(pEnd!=nil,"pEnd!=nil");
00110  return pEnd;
00111 }
00112 
00113 void gHTree::Reset ()
00114 {
00115  gHNode* pMark, *pNextElem;
00116 
00117  gList::Reset(); //Actually no op...
00118  for (pMark=pStart; pMark!=nil; ) {
00119      pNextElem = pMark->nextNode;
00120      delete pMark;
00121      pMark = pNextElem;
00122  }
00123  pStart = pEnd = nil;
00124 }
00125 
00126 int gHTree::AppendCouplePtr (gHtmlCouple* ptrCouple)
00127 {
00128  ASSERTION(ptrCouple!=nil,"ptrCouple!=nil");
00129  if ( ptrCouple->coupleId>-1 ) return -1;
00130  ptrCouple->coupleId = 0;
00131  gHNode* newNode = new gHNode;
00132  ASSERTION(newNode!=nil,"newNode!=nil");
00133  newNode->SetCouplePtr( ptrCouple );
00134 #ifdef DEBUG_WEBX
00135  gString sDbgStr;
00136  if ( ptrCouple->IsText() ) {
00137      ptrCouple->pHStr->ConvertAmpToAscii( ptrCouple->GetStr(), sDbgStr );
00138  }
00139  DBGPRINT_WEB3("DBG: AppendCouple:[%s:%s:%u]\n",ptrCouple->GetStr(),sDbgStr.Str(),ptrCouple->N());
00140 #endif
00141  thisAppendNode( newNode );
00142  return 0;
00143 }
00144 
00145 int gHTree::AppendTreePtr (gHTree* pTree)
00146 {
00147  gHNode* newNode = new gHNode;
00148  ASSERTION(newNode!=nil,"newNode!=nil");
00149  newNode->tSub = pTree;
00150  thisAppendNode( newNode );
00151  return 0;
00152 }
00153 
00154 int gHTree::thisAppendNode (gHNode* newNode)
00155 {
00156  ASSERTION(newNode!=nil,"newNode!=nil");
00157  if ( pEnd==nil ) {
00158      pStart = pEnd = newNode;
00159  }
00160  else {
00161      pEnd->nextNode = newNode;
00162      pEnd = newNode;
00163  }
00164  return 0;
00165 }
00166 
00167 int gHTree::thisShowNode (gHNode* pNode, bool doShowAll, int level)
00168 {
00169  gHtmlCouple* pCouple;
00170  if ( pNode==nil ) return -1;
00171  pCouple = pNode->GetCouplePtr();
00172 
00173  char sMyFmt[ 100 ];
00174  sprintf(sMyFmt,"%%%ds(%d)",level*4,level);
00175 
00176  printf(sMyFmt," ");
00177  if ( pCouple==nil ) {
00178      printf("_\n");
00179      return 0;
00180  }
00181  printf(": {%s}\n",pCouple->GetStrForTree());
00182  return 0;
00183 }
00184 
00185 void gHTree::Show (bool doShowAll)
00186 {
00187  DBGPRINT("gHTree::Show: START\n");
00188  ShowTree( doShowAll, 0 );
00189  DBGPRINT("gHTree::Show: END\n");
00190 }
00191 
00192 void gHTree::ShowTree (bool doShowAll, int level)
00193 {
00194  gHNode* pNode = pStart;
00195  char sMyFmt[ 100 ];
00196 
00197  sprintf(sMyFmt,"%%%ds(%d)<<:\n",level*4,level);
00198  if ( level>0 && doShowAll==true ) printf(sMyFmt," ");
00199  for ( ; pNode!=nil; ) {
00200      thisShowNode( pNode, doShowAll, level );
00201      if ( pNode->tSub!=nil )
00202          pNode->tSub->ShowTree( doShowAll, level+1 );
00203      pNode = pNode->nextNode;
00204  }
00205  sprintf(sMyFmt,"%%%ds(%d)>>.\n",level*4,level);
00206  if ( level>0 && doShowAll==true ) printf(sMyFmt," ");
00207 }
00208 ////////////////////////////////////////////////////////////
00209 gHSeq::gHSeq (FILE* afRepErr)
00210     : fRepErr( afRepErr ),
00211       baseURI( gURI::e_http ),
00212       nCoords( 0 ),
00213       iCoordStt( 0 ),
00214       pTagCoords( nil ),
00215       nTagTree( 0 ),
00216       pTagTree( nil )
00217 {
00218 }
00219 
00220 gHSeq::~gHSeq ()
00221 {
00222  if ( pTagCoords!=nil ) delete[] pTagCoords;
00223 
00224 #ifdef DEBUG
00225  for (int pIdx=1; pIdx<=nTagTree; pIdx++) {
00226      printf("DBG: TagTree %d/%d: %d: %s\n",pIdx,nTagTree,pTagTree[pIdx].GetY(),pTagTree[pIdx].Str());
00227  }
00228 #endif //DEBUG_...
00229 
00230  if ( pTagTree!=nil ) delete[] pTagTree;
00231 }
00232 
00233 char* gHSeq::GetURL (char* strURI)
00234 {
00235  gURI::ePathType pathTypeAnchor, pathTypeBase;
00236 
00237  if ( strURI==nil ) return nil;
00238 
00239  gURI aURI;
00240  aURI.SetString( strURI );
00241  pathTypeAnchor = aURI.GetPathType();
00242  if ( pathTypeAnchor==gURI::e_NoType ) return nil;
00243 
00244  pathTypeBase = baseURI.GetPathType();
00245 
00246  DBGPRINT("DBG: GetURL: [%s|%s] base-type:%d anchor-type:%d\n",sBaseHRef.Str(),strURI,pathTypeBase,pathTypeAnchor);
00247 
00248  switch ( pathTypeBase ) {
00249  case gURI::e_Absolute:
00250  case gURI::e_Relative:
00251  case gURI::e_RelativeQualified:
00252      sOut = sBaseHRef;
00253      break;
00254  case gURI::e_NoType:
00255  default:
00256      sOut.SetEmpty();
00257      break;
00258  }
00259  if ( pathTypeAnchor==gURI::e_Absolute ) {
00260      sOut.Set( strURI );
00261  }
00262  else {
00263      sOut.Add( aURI.Str() );
00264  }
00265  return sOut.Str();
00266 }
00267 
00268 bool gHSeq::SetBaseHRef (gString& aBaseHRef)
00269 {
00270  sBaseHRef = aBaseHRef;
00271  if ( sBaseHRef[sBaseHRef.Length()]!='/' ) sBaseHRef.Add( '/' );
00272  baseURI.SetString( sBaseHRef.Str() );
00273  return baseURI.GetPathType()!=gURI::e_NoType;
00274 }
00275 
00276 int gHSeq::Build (gHList& lH, eHState state)
00277 {
00278  int error;
00279  unsigned n = lH.N();
00280 
00281  delete[] pTagCoords;
00282  pTagCoords = new gTagCoord[ n+1 ];
00283  ASSERTION(pTagCoords!=nil,"pTagCoords!=nil");
00284 
00285  error = thisCheck( lH, state, 1, n );
00286  DBGPRINT_WEB("DBG: gHSeq::Check: error=%d\n",error);
00287  if ( error!=0 ) return error;
00288 
00289 #ifdef DEBUG
00290  ///lH.Show( true ); printf("DBG: <EOX>\n");
00291  for (t_int32 kCoord=1; kCoord<=nCoords; kCoord++) {
00292      int yLine = pTagCoords[kCoord].GetY();
00293      printf("%u/%u: {%d,%d},y=%d [%s]\n",kCoord,nCoords,yLine,pTagCoords[kCoord].GetZ(),pTagCoords[kCoord].depth,lH.GetCouple(yLine)->GetStr());
00294  }
00295 #endif //DEBUG...
00296 
00297  delete[] pTagTree;
00298  pTagTree = new gTagTree[ nCoords+1 ];  // Maximized
00299  ASSERTION(pTagTree!=nil,"pTagTree!=nil");
00300  nTagTree = 0;
00301 
00302  error = thisBuild( lH );
00303  DBGPRINT_WEB("DBG: gHSeq::Build: error=%d\n",error);
00304  ASSERTION(error==0,"error==0");
00305 
00306  error = thisConsolidate( hTree );
00307  DBGPRINT_WEB("DBG: gHSeq::Consolidate: error=%d\n",error);
00308  ASSERTION(error==0,"error==0");
00309 
00310  return 0;
00311 }
00312 
00313 void gHSeq::ShowPart (gHList& lH, eHState state, gHtmlOpt& htmlOpt)
00314 {
00315  unsigned i, stN;
00316  gHParsed pHAux;
00317  stN = lH.N();
00318  if ( stN>0 ) {
00319      for (i=1; i<=stN; i++)
00320          printf("%s%s\n",htmlOpt.outFmt.GetBeginLineStr( state, i ),lH.Str( i ));
00321  }
00322 }
00323 
00324 int gHSeq::thisCheck (gHList& lH, eHState state, unsigned sttLine, unsigned endLine)
00325 {
00326  unsigned i;
00327  unsigned nParsed;
00328  t_int16 id;
00329  t_int32 idxCoord;
00330  bool isText;
00331  bool inRefEnd, inCannotEnd, inOptEnd;
00332  gHtmlCouple* pObjC;
00333  gHParsed hParsed;
00334 
00335 
00336  if ( state==e_HS_Sp_FakeBody ) {
00337      pObjC = new gHtmlCouple( 0, "BODY", nil );
00338      ASSERTION(pObjC!=nil,"pObjC!=nil");
00339      delete lH.coupleFakeBody;
00340      lH.coupleFakeBody = pObjC;
00341      nCoords++;
00342      pTagCoords[ nCoords ].SetTagId( XH_IDTAG_BODY );
00343      pTagCoords[ nCoords ].SetY( 0 ); //tag start (line)
00344      hParsed.PushTag( *pObjC );
00345      pTagCoords[ nCoords ].depth = hParsed.Depth();
00346  }
00347 
00348  // Build-up pTagCoords
00349 
00350  for (i=sttLine; i<=endLine; i++) {
00351      pObjC = lH.GetCouple( i );
00352      id = pObjC->idTag;
00353      isText = pObjC->IsText();
00354      DBGPRINT("DBG: %u/%u: idTag=%d/synError=%d [%s] OK?%c\n",i,endLine,id,pObjC->synError,pObjC->GetStr(),ISyORn(pObjC->IsOk()));
00355      if ( isText || pObjC->synError<0 ) continue;
00356      inCannotEnd = pObjC->pElem->CannotEndTag();
00357      inOptEnd = pObjC->pElem->MayEndTag();
00358      inRefEnd = pObjC->IsTagEnd();
00359 
00360      //bool isAnchorStart = pObjC->IsAnchor()==true && inRefEnd==false; printf("DBG: CHK: %s [%d]%c%s%s\n",pObjC->GetStr(),id,isText?'.':inCannotEnd?':':inRefEnd?'/':'\\',isAnchorStart?"ANCHOR":"\0",inOptEnd?" MayNotEnd":"\0");
00361      //if ( isAnchorStart ) printf("DBG: CHK: HREF=[%s] URL=[%s]\n",pObjC->GetHRef(),GetURL( pObjC->GetHRef() ));
00362      // Note: GetURL( ... ) returns the full link reference (if specified by HREF, otherwise, returns nil)
00363      // .
00364      //Ahdoc tip: to find <Hn> (e.g. <H1> and </H1> pair), we would apply: id>=XH_IDTAG_H1 && id<=XH_IDTAG_HL ...
00365 
00366      if ( inCannotEnd || inOptEnd ) continue;
00367 
00368      // Check if hard-coded suppression works
00369      if ( id==XH_IDTAG_TABLEx || id==XH_IDTAG_FONTx ) continue; // -temp
00370 
00371      if ( inRefEnd ) {
00372          hParsed.PopTag( false );
00373          for (idxCoord=nCoords; idxCoord>0; idxCoord--)
00374              if ( id==pTagCoords[idxCoord].GetTagId() && pTagCoords[idxCoord].GetZ()==0 ) break;
00375          ASSERTION(idxCoord>0,"idxCoord>0");
00376          pTagCoords[ idxCoord ].SetZ( i ); //end tag (line)
00377      }
00378      else {
00379          nCoords++;
00380          pTagCoords[ nCoords ].SetTagId( id );
00381          pTagCoords[ nCoords ].SetY( i ); //tag start (line)
00382          hParsed.PushTag( *pObjC );
00383          pTagCoords[ nCoords ].depth = hParsed.Depth();
00384      }
00385  }
00386 
00387 #ifdef DEBUG
00388  for (idxCoord=1; idxCoord<=nCoords; idxCoord++) {
00389      if ( pTagCoords[idxCoord].IsOk()==false && pTagCoords[idxCoord].GetTagId()!=XH_IDTAG_BODY )
00390          printf("DBG: COORD(%d): tagId=%d (START=%d/END=%d) OK?%c\n",(int)idxCoord,pTagCoords[idxCoord].GetTagId(),pTagCoords[idxCoord].GetY(),pTagCoords[idxCoord].GetZ(),ISyORn(pTagCoords[idxCoord].IsOk()));
00391  }
00392 #endif //DEBUG...
00393 
00394  for (idxCoord=1, i=0; idxCoord<=nCoords; idxCoord++) i += pTagCoords[idxCoord].IsOk()==false;
00395 
00396  DBGPRINT_WEB3("DBG: thisCheck: i=%u(1 is o.k., >1 error), nParsed=%u\n",i,hParsed.N());
00397  if ( i>1 ) return 1; // E.g. <BODY> is included in lH, but not </BODY>, so at least one unterminated tag allowed
00398 
00399  idxCoord = 1;
00400  nParsed = hParsed.N();
00401  if ( i>0 ) {
00402      DBGPRINT_WEB3("DBG: Body idxCoord=%ld, y(next)=%d\n",(long)idxCoord,pTagCoords[idxCoord].GetY());
00403      if ( pTagCoords[idxCoord].IsOk()==true ) return 2; //First tag should be unterminated (e.g. <BODY>)
00404      iCoordStt = ++idxCoord;
00405      ASSERTION(nParsed>0,"nParsed>0");
00406      nParsed--; // Discount e.g. <BODY>
00407  }
00408 
00409  if ( nParsed>0 ) return 4;
00410  return 0;
00411 }
00412 
00413 int gHSeq::thisBuild (gHList& lH)
00414 {
00415  // Return always 0
00416  int y, z, deltaLines, keepZ;
00417  int hLine, inY;
00418  int blockY;
00419  int thisDepth;
00420  int errAppend;
00421  int idxTagTree;
00422  t_int16 id;
00423  t_int32 idxCoord = iCoordStt;
00424  t_int32 kCoord, mCoord;
00425  t_int32 inCoord;
00426  bool doSkip;
00427  bool isRemembered;
00428  gHtmlCouple* pObjC;
00429 
00430  DBGPRINT_WEB1("DBG: thisBuild: y(iCoordStt=%ld/%ld)=%d\n",(long)iCoordStt,(long)nCoords,pTagCoords[idxCoord].GetY());
00431 
00432  // Append text stuff before first tag
00433  for (hLine=1; hLine<pTagCoords[idxCoord].GetY(); hLine++) {
00434      pObjC = lH.GetCouple( (unsigned)hLine );
00435      if ( pObjC->idTag>=0 && iCoordStt>1 ) continue;  // Skip first tag, redundant for the blocks
00436      DBGPRINT_WEB2("DBG: TXT-prepend: %s\n",pObjC->GetStr());
00437      thisAppendNormal( pObjC );
00438  }
00439 
00440  // Start block join
00441  for (z=-1; idxCoord>0 && idxCoord<=nCoords; ) {
00442      keepZ = z;
00443      y = pTagCoords[ idxCoord ].GetY();
00444      z = pTagCoords[ idxCoord ].GetZ();
00445      thisDepth = pTagCoords[ idxCoord ].depth;
00446      ASSERTION(thisDepth>1,"thisDepth>1");
00447      deltaLines = z - y;  // e.g. end-line 12 and start-line 10 gives 2, because end-tag on 12 is skipped
00448      ASSERTION(deltaLines>0 && z>0,"deltaLines>0");
00449 
00450      DBGPRINT_WEB1("\nDBG: idxCoord=%d/%d,thisDepth=%d: [%s]\n",idxCoord,nCoords,thisDepth,lH.GetCouple( y )->GetStr());
00451      // Add lines before 'y'
00452      for (hLine=keepZ+1; hLine<y && keepZ>0; hLine++) {
00453          pObjC = lH.GetCouple( (unsigned)hLine );
00454          if ( pObjC->IsTagEnd() ) continue;
00455          DBGPRINT_WEB2("DBG: ADDTXT: %s\n",pObjC->GetStr());
00456          thisAppendNormal( pObjC );
00457      }
00458      //
00459      // Before adding the current block, seek if any sub-blocks exist (and store the line: blockY)
00460      for (kCoord=idxCoord+1, blockY=-1, inCoord=0; kCoord<=nCoords; kCoord++) {
00461          inY = pTagCoords[ kCoord ].GetY();
00462          if ( inY<z && blockY<=-1 && pTagCoords[ kCoord ].opId==0 ) {
00463              blockY = inY;
00464              inCoord = kCoord;
00465              pTagCoords[ kCoord ].opId = (t_int16)inCoord;
00466          }
00467      }
00468      DBGPRINT_WEB2("DBG: blockY=%d [%s]\n",blockY,blockY<=-1?"-":lH.GetCouple(blockY)->GetStr());
00469 
00470      if ( blockY<=-1 ) {
00471          // No sub-block
00472          gHTree* thisBlock = NewTree();
00473          gHTree* subBlock = NewTree();
00474          gHTree* whichBlock;
00475 
00476          // Check if block is already remembered: if yes, then append this couple to it, not to subBlock
00477          whichBlock = thisFindRememberedBlock( idxCoord, y, idxTagTree );
00478          if ( (isRemembered = idxTagTree>0)==true ) {
00479              // Reset (like deleting...) this remembered block
00480              pTagTree[ idxTagTree ].Reset();
00481          }
00482          else {
00483              whichBlock = subBlock;
00484          }
00485 
00486          for (hLine=y; hLine<z; hLine++) {
00487              pObjC = lH.GetCouple( hLine );
00488              id = pObjC->idTag;
00489              if ( thisLineSubBlock( hLine, idxCoord+1, doSkip ) || doSkip ) {
00490                  DBGPRINT_WEB2("DBG: SG-subBlock skip: %s\n",pObjC->GetStr());
00491                  continue;
00492              }
00493              ASSERTION(whichBlock!=nil,"whichBlock!=nil");  // Academic assert
00494              if ( id==XH_IDTAG_ANCHOR && pObjC->IsTagEnd()==false ) {
00495                  gHTree* inAnchor = NewTree();
00496                  gHtmlCouple* pObjX = nil;
00497                  for (int kLine=hLine; kLine<z; kLine++) {
00498                      pObjX = lH.GetCouple( kLine );
00499                      if ( pObjX->IsTagEnd()==true ) {
00500                          if ( pObjX->idTag==XH_IDTAG_ANCHOR ) break;
00501                      }
00502                      else {
00503                          inAnchor->AppendCouplePtr( pObjX );
00504                      }
00505                  }
00506                  ASSERTION(pObjX!=nil,"pObjX!=nil");
00507                  whichBlock->AppendTreePtr( inAnchor );
00508                  DBGPRINT_WEB1("DBG: SA-subBlock add: [%s|%s|...]\n",pObjC->GetStr(),pObjX->GetStr());
00509              }
00510              else {
00511                  if ( pObjC->IsTagEnd()==false ) {
00512                      errAppend = whichBlock->AppendCouplePtr( pObjC );
00513                      DBGPRINT_WEB1("DBG: SG-subBlock add%s: [%s]%s\n",errAppend==0?"\0":"{SKIP}",pObjC->GetStr(),isRemembered?" {REMEMBERED}":"\0");
00514                  }
00515              }
00516          }
00517          if ( isRemembered ) {
00518              // Unuseful created blocks
00519              delete thisBlock;
00520              delete subBlock;
00521          }
00522          else {
00523              thisBlock->AppendTreePtr( subBlock );
00524              thisAppendTree( thisBlock );
00525          }
00526          idxCoord++; continue;
00527      }
00528 
00529      // At least one sub-block
00530      gHTree* inBlock = NewTree();
00531      gHTree* subBlock = NewTree();
00532      ASSERTION(inBlock!=nil,"inBlock!=nil");
00533      ASSERTION(subBlock!=nil,"subBlock!=nil");
00534      for (hLine=y+1; hLine<blockY; hLine++) {
00535          // Non-tag before block added to 'inBlock'
00536          pObjC = lH.GetCouple( hLine );
00537          if ( pObjC->IsTagEnd() ) continue;
00538          errAppend = inBlock->AppendCouplePtr( pObjC );
00539          DBGPRINT_WEB1("DBG: inBlock add%s: [%s]\n",errAppend==0?"\0":"{SKIP}",pObjC->GetStr());
00540      }
00541      ASSERTION(hLine==blockY,"hLine==blockY");
00542      gHTree* thisBlock = NewTree();
00543      ASSERTION(thisBlock!=nil,"thisBlock!=nil");
00544      pObjC = lH.GetCouple( y );
00545      errAppend = thisBlock->AppendCouplePtr( pObjC );
00546      DBGPRINT_WEB1("DBG: inBlock-thisBlock add%s: [%s]\n",errAppend==0?"\0":"{SKIP}",pObjC->GetStr());
00547      thisBlock->AppendTreePtr( inBlock );
00548      ;
00549      if ( thisDepth+1==pTagCoords[ inCoord ].depth ) {
00550          for (hLine=blockY; hLine<pTagCoords[ inCoord ].GetZ(); hLine++) {
00551              pObjC = lH.GetCouple( hLine );
00552              if ( thisLineSubBlockCoord( hLine, inCoord+1, mCoord, doSkip )!=0 ) {
00553                  DBGPRINT_WEB1("DBG: IN-subBlock remember: mCoord(%d, line=%d): %s\n",mCoord,hLine,pObjC->GetStr());
00554                  gHTree* innerBlock = NewTree( mCoord, hLine, pObjC->GetStr(), true );
00555                  subBlock->AppendTreePtr( innerBlock );
00556              }
00557              if ( doSkip ) {
00558                  DBGPRINT_WEB1("DBG: IN-subBlock rem{--SKIP--}: %s\n",pObjC->GetStr());
00559                  continue;
00560              }
00561              errAppend = subBlock->AppendCouplePtr( pObjC );
00562              DBGPRINT_WEB1("DBG: IN-subBlock add%s: [%s]\n",errAppend==0?"\0":"{SKIP}",pObjC->GetStr());
00563          }
00564      }
00565      thisBlock->AppendTreePtr( subBlock );
00566      thisAppendTree( thisBlock );
00567      z = hLine;  // To update next-loop keepZ
00568  }//end FOR idxCoord
00569 
00570  idxCoord--;
00571  if ( idxCoord<=iCoordStt ) return 0;
00572 
00573  // Add trailing text
00574  for (hLine=pTagCoords[idxCoord].GetZ()+1, inY=lH.N(); hLine<=inY; hLine++) {
00575      pObjC = lH.GetCouple( (unsigned)hLine );
00576      if ( pObjC->IsText() ) thisAppendNormal( pObjC );
00577  }
00578 
00579  // end 'thisBuild'
00580  return 0;
00581 }
00582 
00583 int gHSeq::thisConsolidate (gHTree& hT)
00584 {
00585  ;
00586  return 0;
00587 }
00588 
00589 int gHSeq::thisLineSubBlock (int hLine, t_int32 startCoord, bool& doSkip)
00590 {
00591  t_int32 fCoord;
00592  return thisLineSubBlockCoord( hLine, startCoord, fCoord, doSkip );
00593 }
00594 
00595 int gHSeq::thisLineSubBlockCoord (int hLine, t_int32 startCoord, t_int32& fCoord, bool& doSkip)
00596 {
00597  int y, z;
00598  t_int32 kCoord;
00599 
00600  // Returns 1 only if 'hLine' matches exactly one 'Y' coordinate (of 'pTagCoords')
00601  for (kCoord=startCoord, doSkip=true; kCoord<=nCoords; kCoord++) {
00602      fCoord = kCoord;
00603      if ( hLine==(y = pTagCoords[ kCoord ].GetY()) ) return 1;
00604      z = pTagCoords[ kCoord ].GetZ();
00605      if ( hLine>y && hLine<=z ) return 0;
00606  }
00607  doSkip = false;
00608  fCoord = -1;
00609  return 0;
00610 }
00611 
00612 gHTree* gHSeq::thisFindRememberedBlock (t_int32 mCoord, int hLine, int& idxTagTree)
00613 {
00614  // Finds if any remembered block matches the coordinate index 'mCoord'.
00615 
00616  int k;
00617 
00618  idxTagTree = 0;
00619  for (k=1; k<=nTagTree; k++) {
00620      if ( pTagTree[k].mCoord==mCoord &&
00621           pTagTree[k].GetY()==hLine ) {
00622          idxTagTree = k;
00623          ASSERTION(pTagTree[k].IsOk(),"pTagTree[k].IsOk()");
00624          return pTagTree[k].myTree;
00625      }
00626  }
00627  // ...not found
00628  return nil;
00629 }
00630 
00631 int gHSeq::thisAppendNormal (gHtmlCouple* pCouple)
00632 {
00633  if ( pCouple==nil ) return -1;
00634  hTree.AppendCouplePtr( pCouple );
00635  return 0;
00636 }
00637 
00638 int gHSeq::thisAppendTree (gHTree* pTree)
00639 {
00640  ASSERTION(pTree!=nil,"pTree!=nil");
00641  return hTree.AppendTreePtr( pTree );
00642 }
00643 
00644 gHTree* gHSeq::NewTree (t_int32 mCoord, int hLine, char* descStr, bool doRegister)
00645 {
00646  gHTree* newTree = new gHTree;
00647  ASSERTION(newTree!=nil,"newTree!=nil");
00648  if ( doRegister==false )
00649      return newTree;
00650  nTagTree++;
00651  if ( descStr!=nil ) pTagTree[ nTagTree ].sDesc.Set( descStr );
00652  pTagTree[ nTagTree ].SetY( hLine );
00653  pTagTree[ nTagTree ].mCoord = mCoord;
00654  return pTagTree[ nTagTree ].myTree = newTree;
00655 }
00656 ////////////////////////////////////////////////////////////
00657 

Generated on Sat Aug 18 02:40:56 2007 for xpfweb_v2x lib by  doxygen 1.4.2