OSDN Git Service

reformat
authorikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Fri, 2 Jul 2004 16:53:01 +0000 (16:53 +0000)
committerikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Fri, 2 Jul 2004 16:53:01 +0000 (16:53 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@1217 56b19765-1e22-0410-a548-a0f45d66c51a

kita/src/libkita/access.h
kita/src/libkita/datinfo.cpp
kita/src/libkita/datinfo.h

index 323c418..5be9a46 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
-*   Copyright (C) 2003 by Hideki Ikemoto                                  *
-*   ikemo@wakaba.jp                                                       *
+*   Copyright (C) 2003-2004 by Hideki Ikemoto                             *
+*   ikemo@users.sourceforge.jp                                            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
index c4971f0..46f2991 100644 (file)
@@ -38,18 +38,19 @@ DatInfo::DatInfo( const KURL& url ) : m_access ( 0 )
 {
     QString refstr;
     m_datURL = Kita::ParseMisc::parseURL( url, refstr);
-    m_thread = Kita::Thread::getByURLNew( m_datURL ); 
+    m_thread = Kita::Thread::getByURLNew( m_datURL );
 
     /* japanese strings */
     m_spacestr = ". ";
     m_framestr1 = ParseMisc::utf8ToUnicode( KITAUTF8_FRAME1 ); /* |  */
     m_framestr2 = ParseMisc::utf8ToUnicode( KITAUTF8_FRAME2 ); /* |- */
     m_framestr3 = ParseMisc::utf8ToUnicode( KITAUTF8_FRAME3 ); /* L  */
-    
+
     initPrivate();
 }
 
-DatInfo::~DatInfo(){
+DatInfo::~DatInfo()
+{
     deleteAccessJob();
 }
 
@@ -64,7 +65,8 @@ void DatInfo::init()
 }
 
 /* private */
-void DatInfo::initPrivate(){
+void DatInfo::initPrivate()
+{
 
     /* stop & delete dat loader */
     deleteAccessJob();
@@ -78,7 +80,7 @@ void DatInfo::initPrivate(){
     m_nowLoading = FALSE;
     m_lastLine = QString::null;
     m_kokoyonNum = KitaThreadInfo::readNum( m_datURL.prettyURL() );
-    
+
     /* clear & resize ResDatVec */
     RESDAT resdat;
     resetResDat(resdat);
@@ -87,12 +89,12 @@ void DatInfo::initPrivate(){
 
     /* reset Abone */
     resetAbonePrivate();
-    
+
     /* create dat loader */
     m_access = new Kita::Access( m_datURL );
-    
+
     connect( m_access, SIGNAL( receiveData( const QString& ) ),
-            SLOT( slotReceiveData( const QString& ) ) );
+             SLOT( slotReceiveData( const QString& ) ) );
     connect( m_access, SIGNAL( finishLoad() ),SLOT( slotFinishLoad() ) );
 
     /* get dat from cahce & copy it to buffer */
@@ -102,7 +104,8 @@ void DatInfo::initPrivate(){
 
 
 /* private */
-void DatInfo::resetResDat(RESDAT& resdat){
+void DatInfo::resetResDat(RESDAT& resdat)
+{
 
     resdat.set = FALSE;
     resdat.parsed = FALSE;
@@ -119,7 +122,8 @@ void DatInfo::resetResDat(RESDAT& resdat){
 /* delete dat loader */ /* private */
 void DatInfo::deleteAccessJob()
 {
-    if ( m_access ) {
+    if ( m_access )
+    {
         m_access->killJob();
         delete m_access;
         m_access = NULL;
@@ -136,56 +140,63 @@ void DatInfo::copyRawDataToBuffer(const QString& rawData)
 {
     QStringList linelist;
     int basenum = m_maxNum + 1;
-    
+
     // hack for machiBBS
-    if ( Kita::boardType( m_datURL.url() ) == Board_MachiBBS && m_lastLine == QString::null && m_access->responseCode() == 200 ) {
+    if ( Kita::boardType( m_datURL.url() ) == Board_MachiBBS && m_lastLine == QString::null && m_access->responseCode() == 200 )
+    {
         basenum = 1;
         m_maxNum = 0;
     }
-    
+
     bool endIsLF = FALSE;
-    if ( rawData != QString::null ){
-
-       if(rawData.at(rawData.length()-1) == '\n') endIsLF = TRUE;
-
-       /* split the raw data */
-       m_lastLine += rawData;
-       linelist = QStringList::split( "\n", m_lastLine );
-
-       /* backup the last line */
-       QStringList::iterator lastit = linelist.end();
-       lastit--;
-       if( lastit != linelist.end() ){
-           m_lastLine = (*lastit);
-           linelist.remove(lastit);
-           
-           /* If the last char of rawData is LF, then
-              add LF to m_lastLine, because LF was
-              removed by above QStringList::split().  */
-           if(endIsLF) m_lastLine += '\n';
-       }
-       else m_lastLine = QString::null;
+    if ( rawData != QString::null )
+    {
+
+        if(rawData.at(rawData.length()-1) == '\n') endIsLF = TRUE;
+
+        /* split the raw data */
+        m_lastLine += rawData;
+        linelist = QStringList::split( "\n", m_lastLine );
+
+        /* backup the last line */
+        QStringList::iterator lastit = linelist.end();
+        lastit--;
+        if( lastit != linelist.end() )
+        {
+            m_lastLine = (*lastit);
+            linelist.remove(lastit);
+
+            /* If the last char of rawData is LF, then
+               add LF to m_lastLine, because LF was
+               removed by above QStringList::split().  */
+            if(endIsLF) m_lastLine += '\n';
+        }
+        else m_lastLine = QString::null;
 
     }
-    else{ /* If rawData == null, then copy the last line */
+    else
+    { /* If rawData == null, then copy the last line */
 
-           if ( m_lastLine != QString::null
-                && m_lastLine.contains( "<>" ) == 4
-                 && m_lastLine.at(m_lastLine.length()-1) == '\n' ) {
+        if ( m_lastLine != QString::null
+                && m_lastLine.contains( "<>" ) == 4
+                && m_lastLine.at(m_lastLine.length()-1) == '\n' )
+        {
+
+            m_lastLine.truncate(m_lastLine.length()-1);/* remove LF */
+            linelist += m_lastLine;
+            m_lastLine = QString::null;
+        }
+    }
 
-               m_lastLine.truncate(m_lastLine.length()-1);/* remove LF */
-               linelist += m_lastLine;
-               m_lastLine = QString::null;
-           }
-       }
-   
     /* copy lines to buffer */
     for ( QStringList::iterator it = linelist.begin();
-         it != linelist.end(); ++it, ++basenum ) {
-       if((*it) != QString::null){
-           QString line = ParseMisc::qcpToUnicode((*it));
-           setDat(line,basenum);
-       }
+            it != linelist.end(); ++it, ++basenum )
+    {
+        if((*it) != QString::null)
+        {
+            QString line = ParseMisc::qcpToUnicode((*it));
+            setDat(line,basenum);
+        }
     }
 
     /* update thread info */
@@ -196,7 +207,8 @@ void DatInfo::copyRawDataToBuffer(const QString& rawData)
 
 
 /* private */
-bool DatInfo::setDat( const QString& line, int num ){
+bool DatInfo::setDat( const QString& line, int num )
+{
 
     if ( num <= 0 || (int) m_resDatVec.size() <= num ) return FALSE;
     if ( line == QString::null ) return FALSE;
@@ -204,7 +216,7 @@ bool DatInfo::setDat( const QString& line, int num ){
     /* reset and  set new data */
     RESDAT& resdat = m_resDatVec[ num ];
     resetResDat(resdat);
-    
+
     resdat.set = TRUE;
     resdat.linestr = line;
     if(m_maxNum < num) m_maxNum = num;
@@ -213,11 +225,12 @@ bool DatInfo::setDat( const QString& line, int num ){
     if(num == 1) parseDat ( num ); /* to get subject */
 
     /* is this dat file broken ? */
-    if ( line.contains( "<>" ) != 4 ) {
-       resdat.broken = TRUE;
-       m_broken = TRUE;
-    }    
-    
+    if ( line.contains( "<>" ) != 4 )
+    {
+        resdat.broken = TRUE;
+        m_broken = TRUE;
+    }
+
     return TRUE;
 }
 
@@ -227,7 +240,7 @@ bool DatInfo::setDat( const QString& line, int num ){
 const KURL& DatInfo::url()
 {
     QMutexLocker locker( &m_mutex );
-    
+
     return m_datURL;
 }
 
@@ -254,20 +267,21 @@ bool DatInfo::updateCache(const QObject* parent)
     m_lock++; /* By locking, DatManager can't delete this while loading. */
 
     connect( this, SIGNAL( receiveData() ),
-            parent,SLOT( slotReceiveData() ) );
-    
+             parent,SLOT( slotReceiveData() ) );
+
     connect( this, SIGNAL( finishLoad() ),
-            parent,SLOT( slotFinishLoad() ) );
+             parent,SLOT( slotFinishLoad() ) );
 
     m_access->getupdate();
-    
+
     return TRUE;
 }
 
 
 /* slot called when Kita::Access
    received new data              */      /* private  slot */
-void DatInfo::slotReceiveData(const QString& newLine){
+void DatInfo::slotReceiveData(const QString& newLine)
+{
 
     int rescode = m_access->responseCode();
 
@@ -281,11 +295,12 @@ void DatInfo::slotReceiveData(const QString& newLine){
 
 /* slot called when Kita::Access
    finished loading new dat */      /* private  slot */
-void DatInfo::slotFinishLoad(){
+void DatInfo::slotFinishLoad()
+{
 
     /* copy the last line */
-    copyRawDataToBuffer(QString::null); 
-    
+    copyRawDataToBuffer(QString::null);
+
     /* finish loading session & emit signal to the parent object */
     m_nowLoading = FALSE;
     emit finishLoad();
@@ -293,7 +308,7 @@ void DatInfo::slotFinishLoad(){
     /* disconnect signals */
     disconnect( SIGNAL( receiveData() ));
     disconnect( SIGNAL( finishLoad() ) );
-    
+
     if(m_lock) m_lock--;
 }
 
@@ -303,7 +318,7 @@ int DatInfo::getResponseCode()
 {
     QMutexLocker locker( &m_mutex );
     if ( m_access == NULL ) return 0;
-    
+
     return m_access->responseCode();
 }
 
@@ -313,39 +328,42 @@ int DatInfo::getServerTime()
 {
     QMutexLocker locker( &m_mutex );
     if ( m_access == NULL ) return 0;
-    
+
     return m_access->serverTime();
 }
 
 
 /* public */
-bool DatInfo::deleteCache(QWidget* parent){
+bool DatInfo::deleteCache(QWidget* parent)
+{
 
-   QMutexLocker locker( &m_mutex );
-   if ( m_access == NULL ) return FALSE;
-   if ( m_nowLoading ) return FALSE;
+    QMutexLocker locker( &m_mutex );
+    if ( m_access == NULL ) return FALSE;
+    if ( m_nowLoading ) return FALSE;
 
-   bool ret = FALSE;
-   if( m_thread ) ret = Kita::Access::deleteLog( m_thread, parent );
-   KitaThreadInfo::removeThreadInfo( m_datURL.prettyURL() );
-   if(ret) initPrivate();
+    bool ret = FALSE;
+    if( m_thread ) ret = Kita::Access::deleteLog( m_thread, parent );
+    KitaThreadInfo::removeThreadInfo( m_datURL.prettyURL() );
+    if(ret) initPrivate();
 
-   return ret;
+    return ret;
 }
 
 
 /* public */
-bool DatInfo::isLoadingNow(){
+bool DatInfo::isLoadingNow()
+{
 
-   QMutexLocker locker( &m_mutex );
+    QMutexLocker locker( &m_mutex );
 
-   return m_nowLoading;
+    return m_nowLoading;
 }
 
 
 
 /* public */
-void DatInfo::stopLoading(){
+void DatInfo::stopLoading()
+{
 
     /* Don't lock the mutex here !!!
        It will cause deadlock , because
@@ -415,7 +433,7 @@ const QString& DatInfo::getDat( int num )
 
     if ( num <= 0 || KITA_MAXRES <= num ) return QString::null;
     if ( ! m_resDatVec[ num ].set ) return QString::null;
-    
+
     return m_resDatVec[ num ].linestr;
 }
 
@@ -461,9 +479,9 @@ QString DatInfo::getPlainBody(int num)
 
     QString bodytext;
     QString line = m_resDatVec[ num ].body;
-    
+
     ParseMisc::parseBODYdatText(PARSEMODE_TEXT,line,bodytext);
-    
+
     return bodytext;
 }
 
@@ -476,7 +494,7 @@ QString DatInfo::getPlainTitle(int num)
 
     bool showAddr = KitaConfig::showMailAddress();
     QString titletext;
-    ParseMisc::parseTITLEdatText(PARSEMODE_TEXT,num,showAddr,m_resDatVec[ num ],titletext);    
+    ParseMisc::parseTITLEdatText(PARSEMODE_TEXT,num,showAddr,m_resDatVec[ num ],titletext);
 
     return titletext;
 }
@@ -493,13 +511,14 @@ QString DatInfo::getHtml(int startnum, int endnum)
 
     QString retstr = QString::null;
     bool showAddr = KitaConfig::showMailAddress();
-    
-    for(int num = startnum; num <= endnum; num++){
 
-       if(!parseDat(num)) continue;
-       if(checkAbonePrivate(num)) retstr += aboneHTML( num );
-       else if(m_resDatVec[ num ].broken) retstr += brokenHTML( num );
-       else retstr += ParseMisc::ResDatToHtml(m_resDatVec[ num ],  num, showAddr );
+    for(int num = startnum; num <= endnum; num++)
+    {
+
+        if(!parseDat(num)) continue;
+        if(checkAbonePrivate(num)) retstr += aboneHTML( num );
+        else if(m_resDatVec[ num ].broken) retstr += brokenHTML( num );
+        else retstr += ParseMisc::ResDatToHtml(m_resDatVec[ num ],  num, showAddr );
     }
 
     return retstr;
@@ -514,19 +533,21 @@ QString DatInfo::getHtmlByID(const QString& strid, int &count )
 
     QString retstr = QString::null;
     bool showAddr = KitaConfig::showMailAddress();
-    
+
     count = 0;
 
-    for ( int i = 1; i <= m_maxNum; i++ ){
+    for ( int i = 1; i <= m_maxNum; i++ )
+    {
 
-       if(!parseDat(i)) continue;
+        if(!parseDat(i)) continue;
 
-       if(m_resDatVec[i].id == strid){
-           count ++;
-           if(checkAbonePrivate(i)) retstr += aboneHTML(i);
-           else if(m_resDatVec[ i ].broken) retstr += brokenHTML(i);
-           else retstr += ParseMisc::ResDatToHtml(m_resDatVec[i], i, showAddr);
-       }
+        if(m_resDatVec[i].id == strid)
+        {
+            count ++;
+            if(checkAbonePrivate(i)) retstr += aboneHTML(i);
+            else if(m_resDatVec[ i ].broken) retstr += brokenHTML(i);
+            else retstr += ParseMisc::ResDatToHtml(m_resDatVec[i], i, showAddr);
+        }
     }
 
     return retstr;
@@ -534,7 +555,8 @@ QString DatInfo::getHtmlByID(const QString& strid, int &count )
 
 
 /* private */
-QString DatInfo::aboneHTML(int num){
+QString DatInfo::aboneHTML(int num)
+{
 
     QString tmpstr = QString( "<dl><dt>" );
     tmpstr += QString().setNum( num ) + " "  + ParseMisc::utf8ToUnicode( KITAUTF8_ABONE );
@@ -547,7 +569,8 @@ QString DatInfo::aboneHTML(int num){
 
 
 /* private */
-QString DatInfo::brokenHTML(int num){
+QString DatInfo::brokenHTML(int num)
+{
 
     QString tmpstr = QString( "<dl><dt>" );
     tmpstr += QString().setNum( num ) + " "  + ParseMisc::utf8ToUnicode( KITAUTF8_NAME );
@@ -562,7 +585,7 @@ QString DatInfo::brokenHTML(int num){
 /*-------------------------------*/
 /* Get HTML document of res tree.*/
 /* For example, when rootnum = 1,
-
 >>1 
 |-->>4
 |  |--->>10
@@ -579,7 +602,7 @@ QString DatInfo::getTreeByRes(const int rootnum, int& count)
 /*---------------------------------------*/
 /* Get HTML document of reverse res tree.*/
 /* For example, when rootnum = 10,
-
 >>10 
 |-->>5
 |  |--->>2
@@ -598,14 +621,15 @@ QString DatInfo::getTreeByResReverse(const int rootnum, int& count)
 QString DatInfo::getTreeByResPrivate(
     const int rootnum,
     bool reverse,  /* reverse search */
-    int& count){
+    int& count)
+{
 
     QString tmp = QString().setNum( rootnum );
     QString retstr = "<a href=\"#" + tmp + "\">&gt;&gt;" + tmp + "</a><br>";
 
     retstr += getTreeByResCore(rootnum,reverse,count,"");
-    
-    return retstr;    
+
+    return retstr;
 }
 
 /* private */
@@ -616,54 +640,62 @@ QString DatInfo::getTreeByResCore(
 {
     if(!parseDat(rootnum)) return QString::null;
     if( checkAbonePrivate(rootnum) ) return QString::null;
-    
-    QString retstr = QString::null ;    
+
+    QString retstr = QString::null ;
     count = 0;
     QStringList strlists;
 
-    if( !reverse ){
-    
-       /* collect responses that have anchor to rootnum */
-       for ( int i = rootnum+1; i <= m_maxNum; i++ ){
-           if(checkAbonePrivate( i ) ) continue;
-           if(checkRes(i,rootnum)){
-               count ++;
-               strlists += QString().setNum( i );
-           }
-       }
-    
+    if( !reverse )
+    {
+
+        /* collect responses that have anchor to rootnum */
+        for ( int i = rootnum+1; i <= m_maxNum; i++ )
+        {
+            if(checkAbonePrivate( i ) ) continue;
+            if(checkRes(i,rootnum))
+            {
+                count ++;
+                strlists += QString().setNum( i );
+            }
+        }
+
     }
-    else { /* collect responses for which rootnum has anchors */
-
-       setAncList(rootnum);
-       AncList& anclist = m_resDatVec[ rootnum ].anclist;
-       for ( AncList::iterator it = anclist.begin(); it != anclist.end(); ++it ){
-           for( int i = (*it).from; i <= QMIN(rootnum-1,(*it).to) ; i++){
-               if(checkAbonePrivate(i) ) continue;
-               count ++;
-               strlists += QString().setNum( i );
-           }
-       }
+    else
+    { /* collect responses for which rootnum has anchors */
+
+        setAncList(rootnum);
+        AncList& anclist = m_resDatVec[ rootnum ].anclist;
+        for ( AncList::iterator it = anclist.begin(); it != anclist.end(); ++it )
+        {
+            for( int i = (*it).from; i <= QMIN(rootnum-1,(*it).to) ; i++)
+            {
+                if(checkAbonePrivate(i) ) continue;
+                count ++;
+                strlists += QString().setNum( i );
+            }
+        }
     }
 
     /* make HTML document */
-    if(count){
-       
-       for ( QStringList::iterator it = strlists.begin(); it != strlists.end(); ++it ){
-           QString tmpstr;
-           if((*it) == strlists.last()) tmpstr = m_framestr3;  /* 'L' */
-           else tmpstr = m_framestr2;  /* '|-' */
-
-           retstr += prestr + tmpstr + "<a href=\"#" + (*it) + "\">&gt;&gt;" + (*it) + "</a><br>";
-
-           /* call myself recursively */
-           int tmpnum;
-           tmpstr = prestr;
-           if((*it) == strlists.last()) tmpstr += m_spacestr + m_spacestr + m_spacestr; /* "   " */
-           else tmpstr += m_framestr1  + m_spacestr; /* "| " */
-           retstr += getTreeByResCore((*it).toInt(),reverse,tmpnum,tmpstr);
-           count += tmpnum;
-       }
+    if(count)
+    {
+
+        for ( QStringList::iterator it = strlists.begin(); it != strlists.end(); ++it )
+        {
+            QString tmpstr;
+            if((*it) == strlists.last()) tmpstr = m_framestr3;  /* 'L' */
+            else tmpstr = m_framestr2;  /* '|-' */
+
+            retstr += prestr + tmpstr + "<a href=\"#" + (*it) + "\">&gt;&gt;" + (*it) + "</a><br>";
+
+            /* call myself recursively */
+            int tmpnum;
+            tmpstr = prestr;
+            if((*it) == strlists.last()) tmpstr += m_spacestr + m_spacestr + m_spacestr; /* "   " */
+            else tmpstr += m_framestr1  + m_spacestr; /* "| " */
+            retstr += getTreeByResCore((*it).toInt(),reverse,tmpnum,tmpstr);
+            count += tmpnum;
+        }
     }
 
     return retstr;
@@ -683,8 +715,9 @@ bool DatInfo::checkRes(const int num, const int target )
     setAncList(num);
     AncList& anclist = m_resDatVec[ num ].anclist;
 
-    for ( AncList::iterator it = anclist.begin(); it != anclist.end(); ++it ){
-       if ( target >= (*it).from && target <= (*it).to ) return TRUE;
+    for ( AncList::iterator it = anclist.begin(); it != anclist.end(); ++it )
+    {
+        if ( target >= (*it).from && target <= (*it).to ) return TRUE;
     }
 
     return FALSE;
@@ -703,13 +736,14 @@ bool DatInfo::checkRes(const int num, const int target )
    anclist[1].from = 4,
    anclist[1].to = 4.   
 */
-void DatInfo::setAncList(int num){
+void DatInfo::setAncList(int num)
+{
 
     if(! parseDat(num)) return;
     if( m_resDatVec[ num ].setAnclist ) return;
 
     m_resDatVec[ num ].setAnclist = TRUE;
-    
+
     QString linkstr;
     int refNum[2];
     unsigned int pos;
@@ -717,7 +751,7 @@ void DatInfo::setAncList(int num){
 
     AncList& anclist = m_resDatVec[ num ].anclist;
     anclist.clear();
-    
+
     QString line = m_resDatVec[ num ].body;
 
     /* remove HTML tags */
@@ -729,21 +763,24 @@ void DatInfo::setAncList(int num){
     unsigned int length = line.length();
 
     /* parse body */
-    for ( i = 0 ; i < length ; i++ ) {
-
-       if( chpt[ i ].unicode() == UTF16_BRACKET || /* > */
-           (chpt[ i] == '&' && chpt[ i+1] == 'g' && chpt[ i+2] == 't' && chpt[ i+3] == ';') /* "&gt;" */
-           ){
-           while(ParseMisc::parseResAnchor(chpt+i,length-i,linkstr,refNum,pos)){
-               if(refNum[1] < refNum[0]) refNum[1] = refNum[0];
-               anctmp.from = refNum[0];
-               anctmp.to = refNum[1];
-               anclist += anctmp;
-               i += pos;
-           }
-
-           i += (pos-1);
-       }
+    for ( i = 0 ; i < length ; i++ )
+    {
+
+        if( chpt[ i ].unicode() == UTF16_BRACKET || /* > */
+                (chpt[ i] == '&' && chpt[ i+1] == 'g' && chpt[ i+2] == 't' && chpt[ i+3] == ';') /* "&gt;" */
+          )
+        {
+            while(ParseMisc::parseResAnchor(chpt+i,length-i,linkstr,refNum,pos))
+            {
+                if(refNum[1] < refNum[0]) refNum[1] = refNum[0];
+                anctmp.from = refNum[0];
+                anctmp.to = refNum[1];
+                anclist += anctmp;
+                i += pos;
+            }
+
+            i += (pos-1);
+        }
     }
 
     /* parse name */
@@ -751,14 +788,15 @@ void DatInfo::setAncList(int num){
     chpt = line.unicode();
     i = 0;
     length = line.length();
-    
-    while(ParseMisc::parseResAnchor(chpt+i,length-i,linkstr,refNum,pos)){
-       if(refNum[1] < refNum[0]) refNum[1] = refNum[0];
-       anctmp.from = refNum[0];
-       anctmp.to = refNum[1];
-       anclist += anctmp;
-       i += pos;
-    }    
+
+    while(ParseMisc::parseResAnchor(chpt+i,length-i,linkstr,refNum,pos))
+    {
+        if(refNum[1] < refNum[0]) refNum[1] = refNum[0];
+        anctmp.from = refNum[0];
+        anctmp.to = refNum[1];
+        anclist += anctmp;
+        i += pos;
+    }
 }
 
 
@@ -768,7 +806,7 @@ void DatInfo::setAncList(int num){
 
 /* This function returns the element
    of DOM.
-
    This function checks Abone
    internally. So, if the res is
    aboned,the output is "abone" node.
@@ -786,7 +824,7 @@ bool DatInfo::getDomElement(
     /* output */
     DOM::Element& retelm)
 {
-    
+
     QMutexLocker locker( &m_mutex );
     if(!parseDat(num)) return FALSE;
 
@@ -798,69 +836,75 @@ bool DatInfo::getDomElement(
     bool abone = checkAbonePrivate( num );
 
     RESDAT& resdat = m_resDatVec[ num ];
-    
-    if ( !resdat.broken && !abone ){
-
-       /* title node */
-       titlenode = hdoc.createElement( "DT" );
-       ParseMisc::parseTITLEdat(PARSEMODE_DOM,hdoc,num,showAddr,resdat,titlenode,tmpstr);
-
-       /* body node */
-       bodynode = hdoc.createElement( "DD" );
-       {
-           /* put the span node at the head of each line */
-           if ( showAA ){
-
-               tmpelm = bodynode.appendChild( hdoc.createElement( "SPAN" ) );
-               {
-                   tmpelm.setAttribute( "style", "color: white" );
-                   tmpelm.appendChild( hdoc.createTextNode( "" ) );
-               }
-           }
-
-           ParseMisc::parseBODYdat(PARSEMODE_DOM,resdat.body,hdoc,showAA,bodynode,tmpstr);
-       }
-
-    } else { /* abone or data is broken */
-
-       QString namestr;
-       QString bodystr;
-
-       if(abone){ /* "abone" node */
-           namestr = ParseMisc::utf8ToUnicode( KITAUTF8_ABONE );
-           bodystr = ParseMisc::utf8ToUnicode( KITAUTF8_ABONE );
-           status = "abone";
-       }
-       else{ /* "broken" node */
-           namestr = ParseMisc::utf8ToUnicode( KITAUTF8_NAME );
-           bodystr = ParseMisc::utf8ToUnicode( KITAUTF8_KOWARE );
-           status = "broken";
-       }
-
-       /* title node */
-       titlenode = hdoc.createElement( "DT" );
-       titlenode.appendChild( hdoc.createTextNode(
+
+    if ( !resdat.broken && !abone )
+    {
+
+        /* title node */
+        titlenode = hdoc.createElement( "DT" );
+        ParseMisc::parseTITLEdat(PARSEMODE_DOM,hdoc,num,showAddr,resdat,titlenode,tmpstr);
+
+        /* body node */
+        bodynode = hdoc.createElement( "DD" );
+        {
+            /* put the span node at the head of each line */
+            if ( showAA )
+            {
+
+                tmpelm = bodynode.appendChild( hdoc.createElement( "SPAN" ) );
+                {
+                    tmpelm.setAttribute( "style", "color: white" );
+                    tmpelm.appendChild( hdoc.createTextNode( "" ) );
+                }
+            }
+
+            ParseMisc::parseBODYdat(PARSEMODE_DOM,resdat.body,hdoc,showAA,bodynode,tmpstr);
+        }
+
+    }
+    else
+    { /* abone or data is broken */
+
+        QString namestr;
+        QString bodystr;
+
+        if(abone)
+        { /* "abone" node */
+            namestr = ParseMisc::utf8ToUnicode( KITAUTF8_ABONE );
+            bodystr = ParseMisc::utf8ToUnicode( KITAUTF8_ABONE );
+            status = "abone";
+        }
+        else
+        { /* "broken" node */
+            namestr = ParseMisc::utf8ToUnicode( KITAUTF8_NAME );
+            bodystr = ParseMisc::utf8ToUnicode( KITAUTF8_KOWARE );
+            status = "broken";
+        }
+
+        /* title node */
+        titlenode = hdoc.createElement( "DT" );
+        titlenode.appendChild( hdoc.createTextNode(
                                    QString().setNum( num ) + " " + namestr ) );
 
-       /* body node */
-       bodynode = hdoc.createElement( "DD" );
-       tmpelm = bodynode.appendChild( hdoc.createElement( "SPAN" ) );
-       {
-           tmpelm.setAttribute( "style", "color: red" );
-           tmpelm.appendChild( hdoc.createTextNode( bodystr ) );
-       }
+        /* body node */
+        bodynode = hdoc.createElement( "DD" );
+        tmpelm = bodynode.appendChild( hdoc.createElement( "SPAN" ) );
+        {
+            tmpelm.setAttribute( "style", "color: red" );
+            tmpelm.appendChild( hdoc.createTextNode( bodystr ) );
+        }
 
     }
 
     bodynode.appendChild( hdoc.createElement( "BR" ) );
     bodynode.appendChild( hdoc.createElement( "BR" ) );
-    
+
     /*-----------------------------*/
 
     retelm = hdoc.createElement( "DIV" );
     {
         retelm.setAttribute( "kita_type", "res" );
-        retelm.setAttribute( "kita_status", status );  
+        retelm.setAttribute( "kita_status", status );
         retelm.setAttribute( "id", QString().setNum( num ) );
         retelm.setAttribute( "kita_rname", resdat.name );
         retelm.setAttribute( "kita_rid", resdat.id );
@@ -897,22 +941,23 @@ int DatInfo::getNumByID( const QString& strid )
 
     int count = 0;
 
-    for ( int i = 1; i <= m_maxNum; i++ ) {
+    for ( int i = 1; i <= m_maxNum; i++ )
+    {
 
-       if( !parseDat(i) ) continue;
-       if( checkAbonePrivate( i ) ) continue;
+        if( !parseDat(i) ) continue;
+        if( checkAbonePrivate( i ) ) continue;
 
-       if ( m_resDatVec[i].id == strid ) count++;
+        if ( m_resDatVec[i].id == strid ) count++;
     }
 
-    return count;    
+    return count;
 }
 
 /* public */
 int DatInfo::getKokoyonNum()
 {
     QMutexLocker locker( &m_mutex );
-    
+
     return QMIN(m_kokoyonNum, m_maxNum);
 }
 
@@ -924,14 +969,14 @@ void DatInfo::setKokoyonNum(int num)
     num = QMIN(num, m_maxNum);
 
     m_kokoyonNum = num;
-    KitaThreadInfo::setReadNum( m_datURL.prettyURL(), num );    
+    KitaThreadInfo::setReadNum( m_datURL.prettyURL(), num );
 }
 
 /* public */
 int DatInfo::getDatSize()
 {
     QMutexLocker locker( &m_mutex );
-    
+
     return m_rawData.length();
 }
 
@@ -957,7 +1002,7 @@ bool DatInfo::isResBroken(int num)
 {
     QMutexLocker locker( &m_mutex );
     if(!parseDat(num)) return FALSE;
-    
+
     return m_resDatVec[ num ].broken;
 }
 
@@ -966,7 +1011,7 @@ bool DatInfo::checkID(const QString& strid, int num )
 {
     QMutexLocker locker( &m_mutex );
     if(!parseDat(num)) return FALSE;
-    
+
     if(m_resDatVec[num].id  == strid) return TRUE;
 
     return FALSE;
@@ -975,25 +1020,30 @@ bool DatInfo::checkID(const QString& strid, int num )
 
 /* Are keywords included ? */ /* public */
 bool DatInfo::checkWord(QStringList& stlist, /* list of keywords */
-                          int num,
-                          bool checkOR /* AND or OR search */
-    )
+                        int num,
+                        bool checkOR /* AND or OR search */
+                       )
 {
     QMutexLocker locker( &m_mutex );
     if(!parseDat(num)) return FALSE;
 
     QString str_text = m_resDatVec[ num ].body;
-    
-    for ( QStringList::iterator it = stlist.begin(); it != stlist.end(); ++it ) {
 
-       QRegExp regexp( (*it) );
-       regexp.setCaseSensitive( FALSE );
+    for ( QStringList::iterator it = stlist.begin(); it != stlist.end(); ++it )
+    {
+
+        QRegExp regexp( (*it) );
+        regexp.setCaseSensitive( FALSE );
 
-        if ( checkOR ) { /* OR */
-            if ( str_text.find( regexp, 0 ) != -1 ) {
+        if ( checkOR )
+        { /* OR */
+            if ( str_text.find( regexp, 0 ) != -1 )
+            {
                 return TRUE;
             }
-        } else { /* AND */
+        }
+        else
+        { /* AND */
             if ( str_text.find( regexp, 0 ) == -1 ) return FALSE;
         }
     }
@@ -1072,58 +1122,64 @@ bool DatInfo::checkAbonePrivate(int num)
 
     m_resDatVec[ num ].checkAbone = TRUE;
     bool checktmp = FALSE;
-    
+
     if( m_aboneByID )
-       checktmp = checkAboneCore(m_resDatVec[ num ].id,KitaConfig::aboneIDList());
+        checktmp = checkAboneCore(m_resDatVec[ num ].id,KitaConfig::aboneIDList());
 
     if(!checktmp && m_aboneByName )
-           checktmp = checkAboneCore(m_resDatVec[ num ].parsedName,KitaConfig::aboneNameList());
+        checktmp = checkAboneCore(m_resDatVec[ num ].parsedName,KitaConfig::aboneNameList());
 
     if(!checktmp && m_aboneByBody )
-           checktmp = checkAboneCore(m_resDatVec[ num ].body,KitaConfig::aboneWordList());
+        checktmp = checkAboneCore(m_resDatVec[ num ].body,KitaConfig::aboneWordList());
 
     if(!checktmp && m_aboneByRes )
     {
-       setAncList(num);
-       AncList& anclist = m_resDatVec[ num ].anclist;
-
-       for ( AncList::iterator it = anclist.begin();
-             it != anclist.end() && !checktmp ; ++it ){
-
-           int refNum = (*it).from;
-           int refNum2 = (*it).to;
-
-           /* I don't want to enter loop... */
-           if ( refNum >= num ) continue;
-           if ( refNum2 >= num ) refNum2 = num - 1;
-
-           for (int  i = refNum; i <= refNum2; i++ ){
-               if (checkAbonePrivate(i)){
-                   checktmp = TRUE;
-                   break;
-               }
-           }
-       }
+        setAncList(num);
+        AncList& anclist = m_resDatVec[ num ].anclist;
+
+        for ( AncList::iterator it = anclist.begin();
+                it != anclist.end() && !checktmp ; ++it )
+        {
+
+            int refNum = (*it).from;
+            int refNum2 = (*it).to;
+
+            /* I don't want to enter loop... */
+            if ( refNum >= num ) continue;
+            if ( refNum2 >= num ) refNum2 = num - 1;
+
+            for (int  i = refNum; i <= refNum2; i++ )
+            {
+                if (checkAbonePrivate(i))
+                {
+                    checktmp = TRUE;
+                    break;
+                }
+            }
+        }
     }
-    
+
     m_resDatVec[ num ].abone = checktmp;
 
     return m_resDatVec[ num ].abone;
 }
 
-/* private */ 
+/* private */
 bool DatInfo::checkAboneCore(const QString& str, QStringList& strlist)
 {
-    if(strlist.count()){
-
-       int i;
-       for ( QStringList::iterator it = strlist.begin();
-             it != strlist.end(); ++it ) {
-           i = str.find( ( *it ) );
-           if ( i != -1 ) {
-               return TRUE;
-           }
-       }
+    if(strlist.count())
+    {
+
+        int i;
+        for ( QStringList::iterator it = strlist.begin();
+                it != strlist.end(); ++it )
+        {
+            i = str.find( ( *it ) );
+            if ( i != -1 )
+            {
+                return TRUE;
+            }
+        }
     }
 
     return FALSE;
@@ -1138,13 +1194,14 @@ bool DatInfo::checkAboneCore(const QString& str, QStringList& strlist)
    ParseMisc::parseResDat. In short, this
    splits the raw date into name, id,
    date, and bodytext, etc.
-
    Note that this function keeps data as
    the raw data. So, you need to parse them
    later by getPlainBody, getHtml,
    getDomElement, etc. 
                                          */ /* private */
-bool DatInfo::parseDat( int num ){
+bool DatInfo::parseDat( int num )
+{
 
     if ( num <= 0 || KITA_MAXRES <= num ) return FALSE;
     if( m_resDatVec[ num ].parsed ) return TRUE;
@@ -1153,13 +1210,11 @@ bool DatInfo::parseDat( int num ){
     if( !ParseMisc::parseResDat( m_resDatVec[ num ], tmpstr ) ) return FALSE;
 
     /* get subject */
-    if ( m_subject == QString::null && tmpstr != QString::null ){
-       m_subject = tmpstr;
-       Kita::Thread::setName( m_datURL.prettyURL(), m_subject );
+    if ( m_subject == QString::null && tmpstr != QString::null )
+    {
+        m_subject = tmpstr;
+        Kita::Thread::setName( m_datURL.prettyURL(), m_subject );
     }
 
     return TRUE;
 }
-
-
-
index 8792e63..27f5418 100644 (file)
@@ -1,6 +1,6 @@
-/**************************************************************************
+/***************************************************************************
  *   Copyright (C) 2003 by Hideki Ikemoto , (c)2004 by 421                 *
- *   ikemo@wakaba.jp                                                       *
+ *   ikemo@users.sourceforge.jp                                            *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -21,9 +21,9 @@ class QStringList;
 
 namespace DOM
 {
-class HTMLDocument;
-class Element;
-} 
+    class HTMLDocument;
+    class Element;
+}
 
 
 enum{
@@ -35,55 +35,57 @@ enum{
 /* ResDatVec is the Database for responses. */
 /* For example, No.5 res has name = "foo", id "id1234", and anchors >>2-3 and >>4,
    then,
-
    m_resDatVec[5].name = "foo",
    m_resDatVec[5].id = "id1234",
    m_resDatVec[5].anclist[0].from = 2,
    m_resDatVec[5].anclist[0].to = 3,
    m_resDatVec[5].anclist[1].from = 4,
    m_resDatVec[5].anclist[1].to = 4.   
-
 */
-struct ANCNUM{
+struct ANCNUM
+{
     int from;
     int to;
 };
 typedef QValueList<ANCNUM> AncList;
 
-/* Data of one response */ 
-struct RESDAT{
+/* Data of one response */
+struct RESDAT
+{
+
+    bool set; /* Is linestr set ? */
 
-     bool set; /* Is linestr set ? */
+    QString linestr; /* raw line strings */
 
-     QString linestr; /* raw line strings */
+    /*-------*/
 
-     /*-------*/
-    
-     bool parsed; /* Is dat parsed ? */
+    bool parsed; /* Is dat parsed ? */
 
-     bool broken; /* This dat is broken */
+    bool broken; /* This dat is broken */
 
     bool marked;
 
-     QString name;
-     QString parsedName;    
-     QString address;
-     QString body;
-     QString id;
-     QDateTime dateTime;
-     QString dateId;
+    QString name;
+    QString parsedName;
+    QString address;
+    QString body;
+    QString id;
+    QDateTime dateTime;
+    QString dateId;
+
+    /*-------*/
 
-     /*-------*/
-    
-     bool setAnclist; /* Is anclist set ? */
+    bool setAnclist; /* Is anclist set ? */
 
-     AncList anclist; /* anchor list. See also setAncList()  */ 
+    AncList anclist; /* anchor list. See also setAncList()  */
 
-     /*-------*/
+    /*-------*/
 
-     bool checkAbone; /* Is abone checked ? */
+    bool checkAbone; /* Is abone checked ? */
 
-     bool abone;
+    bool abone;
 };
 
 typedef QValueVector<RESDAT> ResDatVec;
@@ -92,147 +94,147 @@ typedef QValueVector<RESDAT> ResDatVec;
 namespace Kita
 {
 
-class Access;
-class Thread; 
+    class Access;
+    class Thread;
 
-/*-----------------------*/
+    /*-----------------------*/
 
-class DatInfo : public QObject
+    class DatInfo : public QObject
     {
-       Q_OBJECT
-
-       QMutex m_mutex;
-
-      /* basic information */
-      int m_maxNum;
-       QString m_rawData;
-       KURL m_datURL;
-       QString m_subject;
-       bool m_broken;
-       ResDatVec m_resDatVec;
-       int m_lock;
-       int m_kokoyonNum; /* kokomade yonda */
-       
-       /* for caching */
-       Access* m_access;
-       Thread* m_thread;
-       QString m_lastLine;
-       bool m_nowLoading;
-
-       /* abone */
-       bool m_aboneByID;
-       bool m_aboneByName;
-       bool m_aboneByBody;
-       bool m_aboneByRes;
-
-       
-       /* japanese strings */
-       QString m_spacestr;
-       QString m_framestr1; /* '|' */
-       QString m_framestr2; /* '|-' */
-       QString m_framestr3; /* 'L' */
-
-       /*-------------------------------*/
-       
-      public:
-    
-       DatInfo();
-       DatInfo( const KURL& url );
-       ~DatInfo();
-       void init();
-       const KURL& url();
-       
-       /* for caching */
-       bool updateCache(const QObject* parent);
-       int getResponseCode();
-       int getServerTime();
-       bool deleteCache(QWidget* parent);
-       bool isLoadingNow();
-       void stopLoading();
-    
-       /* lock, unlock */
-       void lock();
-       void unlock();
-       int isLocked();
-
-       /* string data */
-       const QString& getSubject();
-       const QString& getRawDat();
-       const QString& getDat( int num );
-       const QString& getId( int num );
-       const QString& getName( int num );
-       const QString& getBody( int num );      
-       QString getPlainName(int num);
-       QString getPlainBody(int num);
-       QString getPlainTitle(int num);
-
-       /* HTML data */
-       QString getHtml(int startnum, int endnum);
-       QString getHtmlByID(const QString& strid, int &count );
-       QString getTreeByRes(const int rootnum, int& count );
-       QString getTreeByResReverse(const int rootnum, int& count );    
-
-       /* DOM element */
-       bool getDomElement(int num, DOM::HTMLDocument& hdoc, DOM::Element& retelm);
-
-       /* numerical data */
-       int getMaxResNumber();
-       int getNumByID( const QString& strid );
-       int getKokoyonNum();
-       void setKokoyonNum(int num);
-       int getDatSize();
-
-       /* several informations */
-       bool isResValid(int num);
-       bool isBroken();
-       bool isResBroken(int num);
-       bool checkID(const QString& strid, int num );
-       bool checkWord(QStringList& stlist, int num, bool checkOR);
-       bool isMarked( int num );
-       void setMark( int num, bool mark );     
-       
-       /* abone check */
-       bool checkAbone(int num);
-       void resetAbone();
-
-       /*-------------------------*/
-
-      private:
-
-       void initPrivate();
-       void resetResDat(RESDAT& resdat);
-       void deleteAccessJob();
-
-       /* copy data */
-       void copyRawDataToBuffer(const QString& rawData);
-       bool setDat( const QString& line, int num );
-       
-       /* HTML data */
-       QString aboneHTML(int num);
-       QString brokenHTML(int num);    
-       QString getTreeByResPrivate(const int rootnum,bool reverse,int& count);
-       QString getTreeByResCore(const int rootnum, bool reverse, int& count, QString prestr);
-       bool checkRes(const  int num, const int target );
-       void setAncList(int num);
-       
-       /* for abone */
-       void resetAbonePrivate();
-       bool checkAbonePrivate(int num);
-       bool checkAboneCore(const QString& str, QStringList& strlist);
-
-       /* parsing funtions */
-       bool parseDat( int num );
-       
-       /*----------------------------*/
-
-       private slots:
-
-      void slotReceiveData(const QString& newLine);
-       void slotFinishLoad();
-
-      signals:
+        Q_OBJECT
+
+        QMutex m_mutex;
+
+        /* basic information */
+        int m_maxNum;
+        QString m_rawData;
+        KURL m_datURL;
+        QString m_subject;
+        bool m_broken;
+        ResDatVec m_resDatVec;
+        int m_lock;
+        int m_kokoyonNum; /* kokomade yonda */
+
+        /* for caching */
+        Access* m_access;
+        Thread* m_thread;
+        QString m_lastLine;
+        bool m_nowLoading;
+
+        /* abone */
+        bool m_aboneByID;
+        bool m_aboneByName;
+        bool m_aboneByBody;
+        bool m_aboneByRes;
+
+
+        /* japanese strings */
+        QString m_spacestr;
+        QString m_framestr1; /* '|' */
+        QString m_framestr2; /* '|-' */
+        QString m_framestr3; /* 'L' */
+
+        /*-------------------------------*/
+
+    public:
+
+        DatInfo();
+        DatInfo( const KURL& url );
+        ~DatInfo();
+        void init();
+        const KURL& url();
+
+        /* for caching */
+        bool updateCache(const QObject* parent);
+        int getResponseCode();
+        int getServerTime();
+        bool deleteCache(QWidget* parent);
+        bool isLoadingNow();
+        void stopLoading();
+
+        /* lock, unlock */
+        void lock();
+        void unlock();
+        int isLocked();
+
+        /* string data */
+        const QString& getSubject();
+        const QString& getRawDat();
+        const QString& getDat( int num );
+        const QString& getId( int num );
+        const QString& getName( int num );
+        const QString& getBody( int num );
+        QString getPlainName(int num);
+        QString getPlainBody(int num);
+        QString getPlainTitle(int num);
+
+        /* HTML data */
+        QString getHtml(int startnum, int endnum);
+        QString getHtmlByID(const QString& strid, int &count );
+        QString getTreeByRes(const int rootnum, int& count );
+        QString getTreeByResReverse(const int rootnum, int& count );
+
+        /* DOM element */
+        bool getDomElement(int num, DOM::HTMLDocument& hdoc, DOM::Element& retelm);
+
+        /* numerical data */
+        int getMaxResNumber();
+        int getNumByID( const QString& strid );
+        int getKokoyonNum();
+        void setKokoyonNum(int num);
+        int getDatSize();
+
+        /* several informations */
+        bool isResValid(int num);
+        bool isBroken();
+        bool isResBroken(int num);
+        bool checkID(const QString& strid, int num );
+        bool checkWord(QStringList& stlist, int num, bool checkOR);
+        bool isMarked( int num );
+        void setMark( int num, bool mark );
+
+        /* abone check */
+        bool checkAbone(int num);
+        void resetAbone();
+
+        /*-------------------------*/
+
+    private:
+
+        void initPrivate();
+        void resetResDat(RESDAT& resdat);
+        void deleteAccessJob();
+
+        /* copy data */
+        void copyRawDataToBuffer(const QString& rawData);
+        bool setDat( const QString& line, int num );
+
+        /* HTML data */
+        QString aboneHTML(int num);
+        QString brokenHTML(int num);
+        QString getTreeByResPrivate(const int rootnum,bool reverse,int& count);
+        QString getTreeByResCore(const int rootnum, bool reverse, int& count, QString prestr);
+        bool checkRes(const  int num, const int target );
+        void setAncList(int num);
+
+        /* for abone */
+        void resetAbonePrivate();
+        bool checkAbonePrivate(int num);
+        bool checkAboneCore(const QString& str, QStringList& strlist);
+
+        /* parsing funtions */
+        bool parseDat( int num );
+
+        /*----------------------------*/
+
+    private slots:
+
+        void slotReceiveData(const QString& newLine);
+        void slotFinishLoad();
+
+    signals:
         void receiveData();
-        void finishLoad();     
+        void finishLoad();
     };
 
 }