summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Aportis.h
blob: 5e9d1dabeb10232668e2ac4e33b5244df05de1aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
  Derived from makedoc9 by Pat Beirne
*/

#ifndef __Aportis_h
#define __Aportis_h
#include "CExpander.h"
#include "pdb.h"

typedef UInt32 DWORD;
typedef UInt16 WORD;

#define DISP_BITS 11
#define COUNT_BITS 3
/*
// all numbers in these structs are big-endian, MAC format
struct tDocHeader {
	char sName[32];
	DWORD dwUnknown1;
	DWORD dwTime1;
	DWORD dwTime2;
	DWORD dwTime3;
	DWORD dwLastSync;
	DWORD ofsSort;
	DWORD ofsCatagories;
	DWORD dwCreator;
	DWORD dwType;
	DWORD dwUnknown2;
	DWORD dwUnknown3;
	WORD  wNumRecs;
};
*/
struct tDocRecord0 {
	WORD wVersion;	// 1=plain text, 2=compressed
	WORD wSpare;
	DWORD dwStoryLen;   // in chars, when decompressed
	WORD wNumRecs; 			// text records only; equals tDocHeader.wNumRecs-1
	WORD wRecSize;			// usually 0x1000
	DWORD dwSpare2;
};

struct PeanutHeader
{
    UInt16 Version;
    UInt8 Junk1[6];
    UInt16 Records;
    UInt8 Junk2[106];
};

////////////// utilities //////////////////////////////////////

inline WORD SwapWord(WORD r)
{
	return (r>>8) + (r<<8);
}

inline DWORD SwapLong(DWORD r)
{
	return  ((r>>24) & 0xFF) + (r<<24) + ((r>>8) & 0xFF00) + ((r<<8) & 0xFF0000);
}

class Aportis : public Cpdb {
    bool peanutfile, html;
    void dePeanut(int&);
  DWORD dwLen;
  WORD nRecs2;
  DWORD dwTLen;
  WORD nRecs;
  WORD BlockSize;
  DWORD dwRecLen;
  WORD mobiimagerec;
  int currentrec, currentpos;
  unsigned int cbptr;
  unsigned int outptr;
  unsigned char circbuf[2048];
  char bCompressed;
public:
  void sizes(unsigned long& _file, unsigned long& _text)
    {
      qDebug("Calling aportis sizes:(%u,%u,%u)", dwTLen, nRecs, BlockSize);
      _file = dwLen;
      _text = dwTLen;
    }
  bool hasrandomaccess() { return true; }
  virtual ~Aportis() {}
  Aportis();
  int OpenFile(const char *src);
  int getch();
  unsigned int locate();
  void locate(unsigned int n);
  CList<Bkmk>* getbkmklist();
  MarkupType PreferredMarkup()
      {
	  return (peanutfile) ? cPML : ((html) ? cHTML : cTEXT);
      }
  QImage* getPicture(unsigned long);
  QString about() { return QString("AportisDoc codec (c) Tim Wentford"); }
private:
  bool refreshbuffer();
  unsigned int GetBS(unsigned int bn);
};

#endif