summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/CExpander.h
authorllornkcor <llornkcor>2002-07-01 23:24:08 (UTC)
committer llornkcor <llornkcor>2002-07-01 23:24:08 (UTC)
commit59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2 (patch) (unidiff)
treef148d4858859dac3b413e675c760acfdab24b8e6 /noncore/apps/opie-reader/CExpander.h
parentc08be8ae22dcc1bfb83cfdec807149b161d770f5 (diff)
downloadopie-59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2.zip
opie-59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2.tar.gz
opie-59222a752fa4c8a1e8c2a00ee2f9e22855f12bb2.tar.bz2
initial
Diffstat (limited to 'noncore/apps/opie-reader/CExpander.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/CExpander.h145
1 files changed, 145 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h
new file mode 100644
index 0000000..07c14fa
--- a/dev/null
+++ b/noncore/apps/opie-reader/CExpander.h
@@ -0,0 +1,145 @@
1#ifndef __CExpander_h
2#define __CExpander_h
3
4#include "my_list.h"
5#include "config.h"
6
7class Bkmk
8{
9 friend class BkmkFile;
10 tchar* m_name;
11 unsigned int m_position;
12 public:
13 Bkmk() : m_name(NULL), m_position(0) {};
14 Bkmk(const tchar* _nm, unsigned int _p) : m_position(_p)
15 {
16 int len = ustrlen(_nm)+1;
17 m_name = new tchar[len];
18 for (int i = 0; i < len; i++) m_name[i] = _nm[i];
19 }
20 Bkmk(const Bkmk& rhs) : m_name(NULL)
21 {
22 *this = rhs;
23 }
24 ~Bkmk() { if (m_name != NULL) delete [] m_name; }
25 unsigned int value() const { return m_position; }
26 tchar *name() const { return m_name; }
27 bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); }
28 Bkmk& operator=(const Bkmk& rhs)
29 {
30 if (m_name != NULL) delete [] m_name;
31 if (rhs.m_name != NULL)
32 {
33 int len = ustrlen(rhs.m_name)+1;
34 m_name = new tchar[len];
35 for (int i = 0; i < len; i++) m_name[i] = rhs.m_name[i];
36 }
37 else
38 m_name = NULL;
39 m_position = rhs.m_position;
40 return *this;
41 }
42 bool operator==(const Bkmk& rhs)
43 {
44 return (m_position == rhs.m_position && ustrcmp(m_name,rhs.m_name) == 0);
45 }
46};
47
48class BkmkFile
49{
50 FILE* f;
51 bool wt;
52public:
53 BkmkFile(const char *fnm, bool w = false)
54 :
55 wt(w)
56 {
57 if (w)
58 f = fopen(fnm, "wb");
59 else
60 f = fopen(fnm, "rb");
61 }
62 ~BkmkFile()
63 {
64 if (f != NULL) fclose(f);
65 }
66 void write(tchar* nm, const unsigned int& pos)
67 {
68 if (f != NULL)
69 {
70 unsigned short ln = ustrlen(nm);
71 fwrite(&ln,sizeof(ln),1,f);
72 fwrite(nm,sizeof(tchar),ln,f);
73 fwrite(&pos,sizeof(pos),1,f);
74 }
75 }
76 void write(const Bkmk& b) { write(b.name(), b.value()); }
77 void write(CList<Bkmk>& bl)
78 {
79 if (f != NULL)
80 {
81 for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++)
82 {
83 write(*i);
84 }
85 }
86 }
87 Bkmk* read()
88 {
89 Bkmk* b = NULL;
90 if (f != NULL)
91 {
92 unsigned short ln;
93 if (fread(&ln,sizeof(ln),1,f) == 1)
94 {
95 b = new Bkmk;
96 b->m_name = new tchar[ln+1];
97 fread(b->m_name,sizeof(tchar),ln,f);
98 b->m_name[ln] = 0;
99 fread(&b->m_position,sizeof(b->m_position),1,f);
100 }
101 }
102 return b;
103 }
104 CList<Bkmk>* readall()
105 {
106 CList<Bkmk>* bl = NULL;
107 if (f != NULL)
108 {
109 bl = new CList<Bkmk>;
110 while (1)
111 {
112 Bkmk* b = read();
113 if (b == NULL) break;
114 bl->push_back(*b);
115 delete b;
116 }
117 }
118 return bl;
119 }
120};
121
122class CCharacterSource
123{
124 public:
125#ifdef _UNICODE
126 virtual tchar getch() = 0;
127#else
128 virtual int getch() = 0;
129#endif
130};
131
132class CExpander
133{
134 public:
135 CExpander() {};
136 virtual ~CExpander() {};
137 virtual int openfile(const char *src) = 0;
138 virtual unsigned int locate() = 0;
139 virtual void locate(unsigned int n) = 0;
140 virtual bool hasrandomaccess() = 0;
141 virtual void sizes(unsigned long& file, unsigned long& text) = 0;
142 virtual CList<Bkmk>* getbkmklist() { return NULL; }
143 virtual int getch() = 0;
144};
145#endif