Subversion Repositories tpanel

Rev

Rev 446 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
446 andreas 1
/*
475 andreas 2
 * Copyright (C) 2022 to 2024 by Andreas Theofilu <andreas@theosys.at>
446 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#ifndef __READTP4__
20
#define __READTP4__
21
 
22
#include <string>
23
#include <cstdint>
24
#include <vector>
25
 
26
namespace reader
27
{
28
    typedef struct
29
    {
30
        unsigned char ch;
31
        short byte;
32
    } CHTABLE;
33
 
34
    static CHTABLE __cht[] =
35
    {
36
        {0x80,  0x20AC},
37
        {0x81,  0x0081},
38
        {0x82,  0x201A},
39
        {0x83,  0x0192},
40
        {0x84,  0x201E},
41
        {0x85,  0x2026},
42
        {0x86,  0x2020},
43
        {0x87,  0x2021},
44
        {0x88,  0x02C6},
45
        {0x89,  0x2030},
46
        {0x8A,  0x0160},
47
        {0x8B,  0x2039},
48
        {0x8C,  0x0152},
49
        {0x8D,  0x008d},
50
        {0x8E,  0x017D},
51
        {0x8F,  0x008f},
52
        {0x90,  0x0090},
53
        {0x91,  0x2018},
54
        {0x92,  0x2019},
55
        {0x93,  0x201C},
56
        {0x94,  0x201D},
57
        {0x95,  0x2022},
58
        {0x96,  0x2013},
59
        {0x97,  0x2014},
60
        {0x98,  0x02DC},
61
        {0x99,  0x2122},
62
        {0x9A,  0x0161},
63
        {0x9B,  0x203A},
64
        {0x9C,  0x0153},
65
        {0x9D,  0x009d},
66
        {0x9E,  0x017E},
67
        {0x9F,  0x0178},
68
        {0xA0,  0x00A0},
69
        {0xA1,  0x00A1},
70
        {0xA2,  0x00A2},
71
        {0xA3,  0x00A3},
72
        {0xA4,  0x00A4},
73
        {0xA5,  0x00A5},
74
        {0xA6,  0x00A6},
75
        {0xA7,  0x00A7},
76
        {0xA8,  0x00A8},
77
        {0xA9,  0x00A9},
78
        {0xAA,  0x00AA},
79
        {0xAB,  0x00AB},
80
        {0xAC,  0x00AC},
81
        {0xAD,  0x00AD},
82
        {0xAE,  0x00AE},
83
        {0xAF,  0x00AF},
84
        {0xB0,  0x00B0},
85
        {0xB1,  0x00B1},
86
        {0xB2,  0x00B2},
87
        {0xB3,  0x00B3},
88
        {0xB4,  0x00B4},
89
        {0xB5,  0x00B5},
90
        {0xB6,  0x00B6},
91
        {0xB7,  0x00B7},
92
        {0xB8,  0x00B8},
93
        {0xB9,  0x00B9},
94
        {0xBA,  0x00BA},
95
        {0xBB,  0x00BB},
96
        {0xBC,  0x00BC},
97
        {0xBD,  0x00BD},
98
        {0xBE,  0x00BE},
99
        {0xBF,  0x00BF},
100
        {0xC0,  0x00C0},
101
        {0xC1,  0x00C1},
102
        {0xC2,  0x00C2},
103
        {0xC3,  0x00C3},
104
        {0xC4,  0x00C4},
105
        {0xC5,  0x00C5},
106
        {0xC6,  0x00C6},
107
        {0xC7,  0x00C7},
108
        {0xC8,  0x00C8},
109
        {0xC9,  0x00C9},
110
        {0xCA,  0x00CA},
111
        {0xCB,  0x00CB},
112
        {0xCC,  0x00CC},
113
        {0xCD,  0x00CD},
114
        {0xCE,  0x00CE},
115
        {0xCF,  0x00CF},
116
        {0xD0,  0x00D0},
117
        {0xD1,  0x00D1},
118
        {0xD2,  0x00D2},
119
        {0xD3,  0x00D3},
120
        {0xD4,  0x00D4},
121
        {0xD5,  0x00D5},
122
        {0xD6,  0x00D6},
123
        {0xD7,  0x00D7},
124
        {0xD8,  0x00D8},
125
        {0xD9,  0x00D9},
126
        {0xDA,  0x00DA},
127
        {0xDB,  0x00DB},
128
        {0xDC,  0x00DC},
129
        {0xDD,  0x00DD},
130
        {0xDE,  0x00DE},
131
        {0xDF,  0x00DF},
132
        {0xE0,  0x00E0},
133
        {0xE1,  0x00E1},
134
        {0xE2,  0x00E2},
135
        {0xE3,  0x00E3},
136
        {0xE4,  0x00E4},
137
        {0xE5,  0x00E5},
138
        {0xE6,  0x00E6},
139
        {0xE7,  0x00E7},
140
        {0xE8,  0x00E8},
141
        {0xE9,  0x00E9},
142
        {0xEA,  0x00EA},
143
        {0xEB,  0x00EB},
144
        {0xEC,  0x00EC},
145
        {0xED,  0x00ED},
146
        {0xEE,  0x00EE},
147
        {0xEF,  0x00EF},
148
        {0xF0,  0x00F0},
149
        {0xF1,  0x00F1},
150
        {0xF2,  0x00F2},
151
        {0xF3,  0x00F3},
152
        {0xF4,  0x00F4},
153
        {0xF5,  0x00F5},
154
        {0xF6,  0x00F6},
155
        {0xF7,  0x00F7},
156
        {0xF8,  0x00F8},
157
        {0xF9,  0x00F9},
158
        {0xFA,  0x00FA},
159
        {0xFB,  0x00FB},
160
        {0xFC,  0x00FC},
161
        {0xFD,  0x00FD},
162
        {0xFE,  0x00FE},
163
        {0xFF,  0x00FF}
164
    };
165
 
166
    struct HEADER       // This is the first entry in the file.
167
    {
168
        unsigned char abyFileID[8];     // 0 - 7
169
        uint32_t listStartBlock;        // 8 - 11
170
    };
171
 
172
    struct BLOCK        // This is a block. It points to other blocks and contains the block data.
173
    {
174
        uint32_t thisBlock;             // 0 - 3
175
        uint32_t prevBlock;             // 4 - 7
176
        uint32_t nextBlock;             // 8 - 11
177
        uint16_t bytesUsed;             // 12 - 13
178
        unsigned char abyData[512];     // 14 - 525
179
    };
180
 
181
    struct USAGE_BLOCK  // This is an index entry
182
    {
183
        uint32_t thisBlock;             // 0 - 3
184
        uint32_t prevBlock;             // 4 - 7
185
        uint32_t nextBlock;             // 8 - 11
186
        uint16_t bytesUsed;             // 12 - 13
187
        unsigned char filePath[260];    // 14 - 273
188
        time_t tmCreate;                // 274 - 277
189
        time_t tmModify;                // 278 - 281
190
        uint32_t flags;                 // 282 - 285
191
        uint32_t startBlock;            // 286 - 289
192
        uint32_t sizeBlocks;            // 290 - 293
193
        uint32_t sizeBytes;             // 294 - 297
194
    };
195
 
196
    struct FILE_HEAD    // This is the pointer part of a block.
197
    {
198
        uint32_t thisBlock;             // 228 - 231
199
        uint32_t prevBlock;             // 232 - 235
200
        uint32_t nextBlock;             // 236 - 239
201
        uint16_t blockLen;              // 240 - 141
202
    };
203
 
204
    struct INDEX
205
    {
206
        struct USAGE_BLOCK *ublock {nullptr};
207
        struct INDEX *prev {nullptr};
208
        struct INDEX *next {nullptr};
209
    };
210
 
211
    struct MANIFEST
212
    {
213
        size_t size;
214
        time_t tmCreate;
215
        time_t tmModify;
216
        std::string fname;
217
    };
218
 
219
#define SIZE_HEADER         12
220
#define SIZE_BLOCK          526
221
#define SIZE_USAGE_BLOCK    298
222
#define SIZE_FILE_HEAD      14
223
 
224
    class ReadTP4
225
    {
226
            std::string fname{""};
227
            std::string target{"."};
228
            struct INDEX *idx {nullptr};
229
 
230
        public:
231
            explicit ReadTP4(const std::string& fn)
232
                : fname{fn}
233
            {}
234
 
235
            ReadTP4(const std::string& fn, const std::string& tg)
236
                : fname{fn},
237
                  target{tg}
238
            {}
239
 
240
            ~ReadTP4();
241
 
242
            bool isReady();
243
            bool doRead();
244
            std::string toHex(int num, int width);
475 andreas 245
            bool isTP5() { return tp5Type; }
446 andreas 246
 
247
        private:
248
            void fillBlock(struct BLOCK& bl, const unsigned char *buf);
249
            void fillUsageBlock(struct USAGE_BLOCK& ub, const unsigned char *buf);
250
            void fillFileHead(struct FILE_HEAD& fh, const unsigned char *buf);
251
            size_t calcBlockPos(uint32_t block);
252
 
253
            struct INDEX *appendUBlock(const struct USAGE_BLOCK *ub);
254
            void deleteIndex();
255
 
256
            uint32_t makeDWord(const unsigned char *buf);
257
            uint16_t makeWord(const unsigned char *buf);
258
            std::string cp1250ToUTF8(const std::string& str);
259
            static bool compareManifest(struct MANIFEST& m1, struct MANIFEST& m2);
260
 
261
            std::vector<struct MANIFEST> manifest;
475 andreas 262
            bool tp5Type{false};
446 andreas 263
    };
264
}
265
 
266
#endif