summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/ZText.h
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/ZText.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/ZText.h45
1 files changed, 31 insertions, 14 deletions
diff --git a/noncore/apps/opie-reader/ZText.h b/noncore/apps/opie-reader/ZText.h
index 22d3733..ab81a5e 100644
--- a/noncore/apps/opie-reader/ZText.h
+++ b/noncore/apps/opie-reader/ZText.h
@@ -1,25 +1,28 @@
1#ifndef __Text_h 1#ifndef __Text_h
2#define __Text_h 2#define __Text_h
3#include <stdio.h> 3#include <stdio.h>
4#include "zlib/zlib.h" 4#include <zlib.h>
5#include <sys/stat.h> 5#include <sys/stat.h>
6 6#include "useqpe.h"
7#include "CExpander.h" 7#include "CExpander.h"
8 8
9class Text: public CExpander { 9class Text: public CExpander {
10 gzFile file; 10 gzFile file;
11 unsigned long fsize; 11 unsigned long fsize;
12public: 12public:
13 virtual void suspend() 13 void suspend()
14 { 14 {
15#ifdef USEQPE
15 bSuspended = true; 16 bSuspended = true;
16 suspos = gztell(file); 17 suspos = gztell(file);
17 gzclose(file); 18 gzclose(file);
18 file = NULL; 19 file = NULL;
19 sustime = time(NULL); 20 sustime = time(NULL);
21#endif
20 } 22 }
21 virtual void unsuspend() 23 void unsuspend()
22 { 24 {
25#ifdef USEQPE
23 if (bSuspended) 26 if (bSuspended)
24 { 27 {
25 bSuspended = false; 28 bSuspended = false;
@@ -37,14 +40,15 @@ public:
37 exit(0); 40 exit(0);
38 } 41 }
39 suspos = gzseek(file, suspos, SEEK_SET); 42 suspos = gzseek(file, suspos, SEEK_SET);
40 } 43 }
44#endif
41 } 45 }
42 Text() : file(NULL) {}; 46 Text() : file(NULL) {};
43 virtual ~Text() 47 virtual ~Text()
44 { 48 {
45 if (file != NULL) gzclose(file); 49 if (file != NULL) gzclose(file);
46 } 50 }
47 virtual int OpenFile(const char *src) 51 int OpenFile(const char *src)
48 { 52 {
49 if (file != NULL) gzclose(file); 53 if (file != NULL) gzclose(file);
50 struct stat _stat; 54 struct stat _stat;
@@ -52,15 +56,28 @@ public:
52 fsize = _stat.st_size; 56 fsize = _stat.st_size;
53 return ((file = gzopen(src,"rb")) == NULL); 57 return ((file = gzopen(src,"rb")) == NULL);
54 } 58 }
55 virtual int getch() { return gzgetc(file); } 59 int getch() { return gzgetc(file); }
56 virtual unsigned int locate() { return gztell(file); } 60 unsigned int locate() { return gztell(file); }
57 virtual void locate(unsigned int n) { gzseek(file,n,SEEK_SET); } 61 void locate(unsigned int n) { gzseek(file,n,SEEK_SET); }
58 virtual bool hasrandomaccess() { return true; } 62 bool hasrandomaccess() { return true; }
59 virtual void sizes(unsigned long& _file, unsigned long& _text) 63 void sizes(unsigned long& _file, unsigned long& _text)
60 { 64 {
61 _text = _file = fsize; 65 _text = _file = fsize;
66 FILE* f = fopen(fname, "rb");
67 if (f != NULL)
68 {
69 unsigned char mn[2];
70 fread(mn, 1, 2, f);
71 if ((mn[0] == 31) && (mn[1] == 139))
72 {
73 int tmp = sizeof(_text);
74 fseek(f,-tmp,SEEK_END);
75 fread(&_text, sizeof(_text), 1, f);
76 }
77 fclose(f);
78 }
62 } 79 }
63 virtual MarkupType PreferredMarkup() 80 MarkupType PreferredMarkup()
64 { 81 {
65 return cTEXT; 82 return cTEXT;
66 } 83 }