Lhaz
lzh.h
[詳解]
1 /*************************************************************************/
6 #pragma once
7 
8 #include <stdio.h>
9 #include <time.h>
10 #include "mystr.h"
11 #include "lhazdef.h"
12 #include "lha_macro.h"
13 
14 class MYFILE;
15 
16 #define METHOD_TYPE_STRAGE 5
17 #define LZHUFF0_METHOD "-lh0-"
18 #define LZHUFF1_METHOD "-lh1-"
19 #define LZHUFF2_METHOD "-lh2-"
20 #define LZHUFF3_METHOD "-lh3-"
21 #define LZHUFF4_METHOD "-lh4-"
22 #define LZHUFF5_METHOD "-lh5-"
23 #define LZHUFF6_METHOD "-lh6-"
24 #define LZHUFF7_METHOD "-lh7-"
25 #define LARC_METHOD "-lzs-"
26 #define LARC5_METHOD "-lz5-"
27 #define LARC4_METHOD "-lz4-"
28 #define LZHDIRS_METHOD "-lhd-"
29 
30 #define LZH_EXT_HEAD_CRC 0x00
31 #define LZH_EXT_HEAD_FNAME 0x01
32 #define LZH_EXT_HEAD_PATH 0x02
33 #define LZH_EXT_HEAD_COMNT 0x3F
34 #define LZH_EXT_HEAD_ATRB 0x40
35 #define LZH_EXT_HEAD_TIME 0x41
36 #define LZH_EXT_HEAD_SIZE 0x42
37 #define LZH_EXT_HEAD_UNI_FNAME 0x44
38 #define LZH_EXT_HEAD_UNI_PATH 0x45
39 #define LZH_EXT_HEAD_CP 0x46
40 #define LZH_EXT_HEAD_PERMS 0x50
41 #define LZH_EXT_HEAD_GID 0x51
42 #define LZH_EXT_HEAD_GROUP 0x52
43 #define LZH_EXT_HEAD_USER 0x53
44 #define LZH_EXT_HEAD_MODT 0x54
45 #define LZH_EXT_HEAD_RESRV 0xFF
46 
47 #define EXTEND_GENERIC 0
48 #define EXTEND_UNIX 'U'
49 #define EXTEND_MSDOS 'M'
50 #define EXTEND_MACOS 'm'
51 #define EXTEND_OS9 '9'
52 #define EXTEND_OS2 '2'
53 #define EXTEND_OS68K 'K'
54 #define EXTEND_OS386 '3'
55 #define EXTEND_HUMAN 'H'
56 #define EXTEND_CPM 'C'
57 #define EXTEND_FLEX 'F'
58 #define EXTEND_RUNSER 'R'
59 #define EXTEND_TOWNSOS 'T'
60 #define EXTEND_XOSK 'X'
61 
62 #define I_HEADER_SIZE 0
63 #define I_HEADER_CHECKSUM 1
64 #define I_METHOD 2
65 #define I_PACKED_SIZE 7
66 #define I_ORIGINAL_SIZE 11
67 #define I_LAST_MODIFIED_STAMP 15
68 #define I_ATTRIBUTE 19
69 #define I_HEADER_LEVEL 20
70 #define I_NAME_LENGTH 21
71 #define I_NAME 22
72 #define I_CRC 22 /* + name_length */
73 #define I_EXTEND_TYPE 24 /* + name_length */
74 #define I_MINOR_VERSION 25 /* + name_length */
75 #define I_UNIX_LAST_MODIFIED_STAMP 26 /* + name_length */
76 #define I_UNIX_MODE 30 /* + name_length */
77 #define I_UNIX_UID 32 /* + name_length */
78 #define I_UNIX_GID 34 /* + name_length */
79 #define I_UNIX_EXTEND_BOTTOM 36 /* + name_length */
80 #define I_GENERIC_HEADER_BOTTOM I_EXTEND_TYPE
81 
82 #define GENERIC_ATTRIBUTE 0x20
83 #define GENERIC_DIRECTORY_ATTRIBUTE 0x10
84 
85 class CLZH {
86 public:
87  enum METHOD {
100  };
101  CLZH(int arctype = 0);
102  CLZH(const MYSTR& name, struct _stat *v_stat);
103  ‾CLZH(void);
104  // 展開
105  bool Match(char* p, char* s, int f);
106  bool ReadHeader(MYFILE&);
107  bool Extract(MYFILE& fp, bool& force, bool& skip, bool test = false);
108  // 圧縮
109  bool Add(MYFILE& fp, MYFILE& nafp, int method, uchar level);
110  void WriteHeader(MYFILE& nafp);
111  // サブ
112  const MYSTR& GetName(void) { return Name; }
113  const MYSTR& GetFname(void) { return Fname; }
114  void SetName(const MYSTR& name);
115  void SetFname(const MYSTR& name, bool dir = false);
116  const MYSTR& GetDir(void) { return Dir; }
117  void SetDir(const MYSTR& dir);
118  uchar GetHeaderSize(void) { return HeaderSize; }
119  LONGLONG GetTotalSize(void);
120  LONGLONG GetSize(void) { return OriginalSize; }
121  void SetOriginalSize(LONGLONG size);
122  LONGLONG GetPackedSize(void) { return PackedSize; }
123  void SetPackedSize(ulong size);
124  float GetRatio(void) { return Ratio; }
125  void SetRatio(void);
126  int GetMethod(void) { return MethodNum; }
127  void SetMethod(int method) { MethodNum = method; }
128  const MYSTR& GetMethodText(void) { return MethodText; }
129  void SetMethodText(const MYSTR& method) { MethodText = method; }
130  time_t GetTime(void) { return Unix_last_modified_stamp; }
131  void SetUnix_last_modified_stamp(time_t t);
132  ushort GetUnix_mode(void) { return Unix_mode; }
133  const MYSTR& GetType(void) { return Type; }
134  void SetType(const MYSTR& type) { Type = type; }
135  int GetImage(void) { return Image; }
136  void SetImage(int image) { Image = image; }
137  fpos_t GetFpos(void) { return Fpos; }
138  void SetFpos(fpos_t fpos) { Fpos = fpos; }
139  bool GetEncrypt(void) { return Encrypt; }
140  void SetEncrypt(bool f) { Encrypt = f; }
141  uchar GetHeaderLevel(void) { return HeaderLevel; }
142  int GetTreeFolder(void) const { return TreeFolder; }
143  void SetTreeFolder(int f) { TreeFolder = f; }
144  ushort GetAttribute(void) const { return Attribute; }
145 
146 private:
147  static const int FILENAME_LENGTH;
148  static const int LZHEADER_STRAGE;
149  static const ushort UNIX_FILE_REGULAR;
150  static const ushort UNIX_RW_RW_RW;
151  //
152  uchar HeaderSize; /* ヘッダサイズ */
153  int MethodNum; /* 圧縮形式(数値) */
154  char Method[METHOD_TYPE_STRAGE]; /* 圧縮形式(テキスト) */
155  MYSTR MethodText; /* 圧縮形式(テキスト) */
156  LONGLONG PackedSize; /* 圧縮サイズ */
157  LONGLONG OriginalSize; /* 元サイズ */
158  long Last_modified_stamp; /* 最終更新日時(MS-DOS) */
159  time_t Unix_last_modified_stamp; /* 最終更新日時(time_t) */
160  ushort Attribute; /* 属性 */
161  uchar HeaderLevel; /* ヘッダレベル */
162  MYSTR Dir; /* ディレクトリ */
163  MYSTR Fname; /* ファイル名 */
164  MYSTR Name; /* ファイル名(フルパス) */
165  ushort Crc; /* CRC */
166  bool HasCrc; /* CRC付きか? */
167  uchar ExtendType; /* 拡張形式 */
168  uchar Minor_version; /* マイナーバージョン */
169  ushort Unix_mode; /* モード */
170  ushort Unix_uid; /* ユーザーID */
171  ushort Unix_gid; /* グループID */
172  MYSTR Type; /* ファイルの種別 */
173  int Image; /* イメージインデックス */
174  fpos_t Fpos; /* ファイル位置 */
175  float Ratio; /* 圧縮率 */
176  int ArcType; /* 書庫種別 */
177  bool Encrypt; /* 暗号化フラグ */
178  unsigned char* get_ptr; /* データポインタ */
179  int TreeFolder; /* ツリービューフォルダ */
180  static char* Methods[]; /* 圧縮メソッド */
181  FILETIME CreationTime; /* 作成日時 */
182  FILETIME LastAccessTime; /* 最終アクセス日時 */
183  FILETIME LastWriteTime; /* 最終更新日時 */
184  bool TimeStampExist; /* タイムスタンプヘッダ有無 */
185  //
186  void clzh(void);
187  ushort get_word(void);
188  void put_word(unsigned int);
189  ulong get_longword(void);
190  void put_longword(long);
191  void generic_to_unix_filename(char*, int);
192  void unix_to_generic_filename(MYSTR&);
193  void macos_to_unix_filename(char*, int);
194  long unix_to_generic_stamp(time_t);
195  long gettz(void) const;
196  void adjust_info(const MYSTR& name);
197  int inquire_extract(const MYSTR& name, bool& force, bool& skip);
198  bool open_with_make_path(const MYSTR& name, MYFILE** fp);
199  bool make_parent_path(const MYSTR& name);
200  ushort decode_lzhuf(MYFILE& infp, MYFILE& outfp, LONGLONG original_size, LONGLONG packed_size, const MYSTR& name, int method);
201  ushort encode_lzhuf(MYFILE& infp, MYFILE& outfp, LONGLONG* original_size_var, LONGLONG* packed_size_var);
202  ushort encode_stored_crc(MYFILE& ifp, MYFILE& ofp, LONGLONG size, LONGLONG* original_size_var, LONGLONG* write_size_var);
203  void fatal_error(const MYSTR& msg);
204  bool ReadLevel0Header(MYFILE&);
205  bool ReadLevel1Header(MYFILE&);
206  bool ReadLevel2Header(MYFILE&);
207  bool ReadLevel3Header(MYFILE&);
208  void WriteLevel0Header(MYFILE& nafp);
209  void WriteLevel1Header(MYFILE& nafp);
210  void WriteLevel2Header(MYFILE& nafp);
211  void WriteLevel3Header(MYFILE& nafp);
212 
213 };
Definition: lzh.h:97
ulong get_longword(void)
Definition: lzh.cpp:160
Definition: lzh.h:88
MYSTR MethodText
Definition: lzh.h:155
fpos_t Fpos
Definition: lzh.h:174
static const ushort UNIX_RW_RW_RW
Definition: lzh.h:150
void SetDir(const MYSTR &dir)
Definition: lzh.cpp:482
Definition: lzh.h:85
void SetEncrypt(bool f)
Definition: lzh.h:140
unsigned char * get_ptr
Definition: lzh.h:178
METHOD
Definition: lzh.h:87
ushort Unix_gid
Definition: lzh.h:171
void WriteHeader(MYFILE &nafp)
Definition: lzh.cpp:1081
char Method[METHOD_TYPE_STRAGE]
Definition: lzh.h:154
int Image
Definition: lzh.h:173
void SetImage(int image)
Definition: lzh.h:136
ushort Attribute
Definition: lzh.h:160
int inquire_extract(const MYSTR &name, bool &force, bool &skip)
Definition: lzh.cpp:269
void macos_to_unix_filename(char *, int)
Definition: lzh.cpp:205
uchar HeaderSize
Definition: lzh.h:152
Definition: lzh.h:98
Definition: lzh.h:91
MYSTR Name
Definition: lzh.h:164
int MethodNum
Definition: lzh.h:153
ushort Unix_mode
Definition: lzh.h:169
bool ReadLevel0Header(MYFILE &)
Definition: lzh.cpp:606
void WriteLevel2Header(MYFILE &nafp)
Definition: lzh.cpp:1239
void put_word(unsigned int)
Definition: lzh.cpp:151
Definition: lzh.h:90
bool GetEncrypt(void)
Definition: lzh.h:139
Definition: lzh.h:93
unsigned long ulong
Definition: lhazdef.h:7
bool Extract(MYFILE &fp, bool &force, bool &skip, bool test=false)
Definition: lzh.cpp:1512
void unix_to_generic_filename(MYSTR &)
Definition: lzh.cpp:197
and that you are informed that you can do these things To protect your we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it For if you distribute copies of the whether gratis or for a you must give the recipients all the rights that we gave you You must make sure that receive or can get the source code If you link other code with the you must provide complete object files to the so that they can relink them with the library after making changes to the library and recompiling it And you must show them these terms so they know their rights We protect your rights with a two step method
Definition: copying.txt:35
unsigned short ushort
Definition: lhazdef.h:5
void put_longword(long)
Definition: lzh.cpp:173
void generic_to_unix_filename(char *, int)
Definition: lzh.cpp:184
ushort get_word(void)
Definition: lzh.cpp:140
static const ushort UNIX_FILE_REGULAR
Definition: lzh.h:149
bool Add(MYFILE &fp, MYFILE &nafp, int method, uchar level)
Definition: lzh.cpp:1601
ushort encode_lzhuf(MYFILE &infp, MYFILE &outfp, LONGLONG *original_size_var, LONGLONG *packed_size_var)
Definition: lzh.cpp:414
long Last_modified_stamp
Definition: lzh.h:158
MYSTR Dir
Definition: lzh.h:162
time_t GetTime(void)
Definition: lzh.h:130
void adjust_info(const MYSTR &name)
Definition: lzh.cpp:244
static const int LZHEADER_STRAGE
Definition: lzh.h:148
void SetOriginalSize(LONGLONG size)
Definition: lzh.cpp:495
Definition: lzh.h:96
Definition: lzh.h:94
const MYSTR & GetType(void)
Definition: lzh.h:133
LONGLONG GetTotalSize(void)
Definition: lzh.cpp:503
int TreeFolder
Definition: lzh.h:179
void WriteLevel0Header(MYFILE &nafp)
Definition: lzh.cpp:1102
bool make_parent_path(const MYSTR &name)
Definition: lzh.cpp:332
void SetRatio(void)
Definition: lzh.cpp:525
‾CLZH(void)
Definition: lzh.cpp:133
const MYSTR & GetFname(void)
Definition: lzh.h:113
static char * Methods[]
Definition: lzh.h:180
bool TimeStampExist
Definition: lzh.h:184
ushort Unix_uid
Definition: lzh.h:170
void SetName(const MYSTR &name)
Definition: lzh.cpp:452
fpos_t GetFpos(void)
Definition: lzh.h:137
CLZH(int arctype=0)
Definition: lzh.cpp:70
bool ReadLevel3Header(MYFILE &)
Definition: lzh.cpp:1073
bool ReadLevel2Header(MYFILE &)
Definition: lzh.cpp:876
void clzh(void)
Definition: lzh.cpp:103
int GetTreeFolder(void) const
Definition: lzh.h:142
bool ReadLevel1Header(MYFILE &)
Definition: lzh.cpp:717
int GetMethod(void)
Definition: lzh.h:126
void SetUnix_last_modified_stamp(time_t t)
Definition: lzh.cpp:549
void WriteLevel1Header(MYFILE &nafp)
Definition: lzh.cpp:1137
time_t Unix_last_modified_stamp
Definition: lzh.h:159
LONGLONG GetSize(void)
Definition: lzh.h:120
int GetImage(void)
Definition: lzh.h:135
ushort GetAttribute(void) const
Definition: lzh.h:144
bool open_with_make_path(const MYSTR &name, MYFILE **fp)
Definition: lzh.cpp:297
void SetFname(const MYSTR &name, bool dir=false)
Definition: lzh.cpp:462
FILETIME LastWriteTime
Definition: lzh.h:183
uchar Minor_version
Definition: lzh.h:168
FILETIME LastAccessTime
Definition: lzh.h:182
MYSTR Type
Definition: lzh.h:172
ushort decode_lzhuf(MYFILE &infp, MYFILE &outfp, LONGLONG original_size, LONGLONG packed_size, const MYSTR &name, int method)
Definition: lzh.cpp:374
void SetTreeFolder(int f)
Definition: lzh.h:143
int ArcType
Definition: lzh.h:176
Definition: lzh.h:99
FILETIME CreationTime
Definition: lzh.h:181
MYSTR Fname
Definition: lzh.h:163
bool Match(char *p, char *s, int f)
Definition: lzh.cpp:557
const MYSTR & GetMethodText(void)
Definition: lzh.h:128
uchar HeaderLevel
Definition: lzh.h:161
LONGLONG PackedSize
Definition: lzh.h:156
const MYSTR & GetName(void)
Definition: lzh.h:112
uchar GetHeaderSize(void)
Definition: lzh.h:118
Definition: lzh.h:92
long unix_to_generic_stamp(time_t)
Definition: lzh.cpp:218
#define METHOD_TYPE_STRAGE
Definition: lzh.h:16
void fatal_error(const MYSTR &msg)
Definition: lzh.cpp:443
uchar GetHeaderLevel(void)
Definition: lzh.h:141
float Ratio
Definition: lzh.h:175
bool ReadHeader(MYFILE &)
Definition: lzh.cpp:581
const MYSTR & GetDir(void)
Definition: lzh.h:116
bool Encrypt
Definition: lzh.h:177
Definition: lzh.h:89
void SetMethodText(const MYSTR &method)
Definition: lzh.h:129
static const int FILENAME_LENGTH
Definition: lzh.h:147
ushort Crc
Definition: lzh.h:165
uchar ExtendType
Definition: lzh.h:167
void SetType(const MYSTR &type)
Definition: lzh.h:134
void WriteLevel3Header(MYFILE &nafp)
Definition: lzh.cpp:1354
Definition: lzh.h:95
ushort GetUnix_mode(void)
Definition: lzh.h:132
float GetRatio(void)
Definition: lzh.h:124
void SetPackedSize(ulong size)
Definition: lzh.cpp:517
unsigned char uchar
Definition: lhazdef.h:4
LONGLONG OriginalSize
Definition: lzh.h:157
long gettz(void) const
Definition: lzh.cpp:233
void SetMethod(int method)
Definition: lzh.h:127
LONGLONG GetPackedSize(void)
Definition: lzh.h:122
ushort encode_stored_crc(MYFILE &ifp, MYFILE &ofp, LONGLONG size, LONGLONG *original_size_var, LONGLONG *write_size_var)
Definition: lzh.cpp:433
void SetFpos(fpos_t fpos)
Definition: lzh.h:138
bool HasCrc
Definition: lzh.h:166