Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

arrierego.cpp

Go to the documentation of this file.
00001 #ifdef USENEF
00002 #include <qimage.h>
00003 #include "arrierego.h"
00004 
00005 struct CArriere_dataRecord
00006 {
00007     UInt16 uid;
00008     UInt16 nParagraphs;
00009     UInt32 size;
00010     UInt8 type;
00011     UInt8 reserved;
00012 };
00013 
00014 int CArriere::HeaderSize()
00015 {
00016     return 10;
00017 }
00018 
00019 void CArriere::GetHeader(UInt16& uid, UInt16& nParagraphs, UInt32& size, UInt8& type, UInt8& reserved)
00020 {
00021     CArriere_dataRecord thishdr;
00022     unsuspend();
00023     fread(&thishdr, 1, HeaderSize(), fin);
00024     uid = ntohs(thishdr.uid);
00025     nParagraphs = ntohs(thishdr.nParagraphs);
00026     size = ntohl(thishdr.size);
00027     type = thishdr.type;
00028     reserved = thishdr.reserved;
00029     //    qDebug("UID:%u Paras:%u Size:%u Type:%u Reserved:%u", uid, nParagraphs, size, (unsigned int)type, (unsigned int)reserved);
00030 //    for (int i = 0; i < sizeof(thishdr); i++)
00031 //      printf("%d %x\n", i, (int)(((char *)(&thishdr))[i]));
00032 }
00033 
00034 bool CArriere::CorrectDecoder()
00035 {
00036   char  * type = (char*)(&(head.type));
00037   for (int i = 0; i < 8; ++i) qDebug("%c", type[i]);
00038     return (memcmp(&head.type, "ArriereG", 8) == 0);
00039 }
00040 
00041 int CArriere::bgetch()
00042 {
00043     int ch = EOF;
00044     if (bufferpos >= buffercontent)
00045     {
00046         if (bufferrec >= ntohs(head.recordList.numRecords) - 1)
00047         {
00048                 return EOF;
00049         }
00050         if (isEndOfSection(bufferrec))
00051         {
00052                 return EOF;
00053         }
00054         if (!expand(bufferrec+1))
00055         {
00056                 return EOF;
00057         }
00058         mystyle.unset();
00059         if (m_ParaOffsets[m_nextParaIndex] == 0)
00060         {
00061             while (m_ParaOffsets[m_nextParaIndex+1] == 0)
00062             {
00063                 m_nextParaIndex++;
00064             }
00065         }
00066         mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2);
00067     }
00068     if (bufferpos == m_nextPara)
00069     {
00070         while (bufferpos == m_nextPara)
00071         {
00072             m_nextParaIndex++;
00073             if (m_nextParaIndex == m_nParas)
00074             {
00075                 m_nextPara = -1;
00076             }
00077             else
00078             {
00079                 m_nextPara += m_ParaOffsets[m_nextParaIndex];
00080             }
00081         }
00082         mystyle.unset();
00083         mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2);
00084         if (m_lastBreak == locate())
00085         {
00086             currentpos++;
00087             ch = expandedtextbuffer[bufferpos++];
00088         }
00089         else
00090         {
00091             ch = 10;
00092         }
00093     }
00094     else
00095     {
00096         currentpos++;
00097         ch = expandedtextbuffer[bufferpos++];
00098     }
00099     return ch;
00100 }
00101 
00102 tchar CArriere::getch(bool fast)
00103 {
00104     mystyle.clearPicture();
00105     return getch_base(fast);
00106 }
00107 
00108 /*
00109 void CArriere::setlink(QString& fn, const QString& wrd)
00110 {
00111     fn = wrd;
00112 }
00113 */
00114 
00115 QImage* CArriere::imagefromdata(UInt8* imgbuffer, UInt32 imgsize)
00116 {
00117     QByteArray arr;
00118     arr.assign((const char*)imgbuffer, imgsize);
00119 
00120     QImage* qimage = new QImage(arr);
00121 
00122     return qimage;
00123 }
00124 
00125 void CArriere::start2endSection()
00126 {
00127     m_currentstart = NEFstartSection();
00128     m_currentend = NEFendSection();
00129 }
00130 
00131 unsigned long CArriere::NEFstartSection()
00132 {
00133 //inefficient - Should calc start/end of section on entry to section?
00134     UInt16 thishdr_uid, thishdr_nParagraphs;
00135     UInt32 thishdr_size;
00136     UInt8 thishdr_type, thishdr_reserved;
00137     unsigned long textlength = currentpos-bufferpos;
00138     for (UInt16 recptr = bufferrec-1; recptr >= 1; recptr--)
00139     {
00140         gotorecordnumber(recptr);
00141         //qDebug("recptr:%u", recptr);
00142         GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
00143         if (thishdr_type < 2)
00144         {
00145             if ((thishdr_reserved && continuation_bit) == 0) break;
00146             textlength -= thishdr_size;
00147             //qDebug("Textlength:%u, reserved:%u, recptr:%u", textlength, thishdr_reserved, recptr);
00148         }
00149     }
00150     return textlength;
00151 }
00152 
00153 unsigned long CArriere::NEFendSection()
00154 {
00155 //inefficient - Should calc start/end of section on entry to section?
00156     unsigned long textlength = currentpos-bufferpos+buffercontent;
00157     gotorecordnumber(bufferrec);
00158     UInt16 thishdr_uid, thishdr_nParagraphs;
00159     UInt32 thishdr_size;
00160     UInt8 thishdr_type, thishdr_reserved;
00161     GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
00162     if ((thishdr_reserved && continuation_bit) != 0)
00163       {
00164         for (UInt16 recptr = bufferrec+1; recptr < ntohs(head.recordList.numRecords); recptr++)
00165           {
00166             gotorecordnumber(recptr);
00167             UInt16 thishdr_uid, thishdr_nParagraphs;
00168             UInt32 thishdr_size;
00169             UInt8 thishdr_type, thishdr_reserved;
00170             GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
00171             //  qDebug("recptr %u bufferrec %u type %u m_reserved %u", recptr, bufferrec, typ
00172             if (thishdr_type < 2)
00173               {
00174                 textlength += thishdr_size;
00175                 if ((thishdr_reserved && continuation_bit) == 0) break;
00176               }
00177           }
00178       }
00179     return textlength;
00180 }
00181 
00182 #ifndef __STATIC
00183 extern "C"
00184 {
00185   CExpander* newcodec() { return new CArriere; }
00186 }
00187 #endif
00188 #endif

Generated on Sat Nov 5 16:16:53 2005 for OPIE by  doxygen 1.4.2