PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/milkytracker-0.90.85/src/compression/unlzx.h

#
C Header | 138 lines | 96 code | 30 blank | 12 comment | 0 complexity | 8bf9ff653cc92f54a19b2e50229d7429 MD5 | raw file
Possible License(s): GPL-3.0
  1. /*
  2. ** LZX Extract in (supposedly) portable C.
  3. **
  4. ** Based on unlzx 1.0 by David Tritscher.
  5. ** Rewritten by Oliver Gantert <lucyg@t-online.de>
  6. **
  7. ** Compiled with vbcc/Amiga and lcc/Win32
  8. */
  9. #ifndef unlzx_unlzx_h
  10. #undef AMIGA
  11. #define UNLZX_VERSION "2.16"
  12. #define UNLZX_VERDATE "14.11.2000"
  13. /*
  14. #define UNLZX_DEBUG
  15. #define UNLZX_TIME
  16. */
  17. #if defined(AMIGA)
  18. #include <exec/types.h>
  19. LONG mkdir(STRPTR path, UWORD perm);
  20. #endif
  21. #include "BasicTypes.h"
  22. class XMFile;
  23. class Unlzx
  24. {
  25. public:
  26. struct FileIdentificator
  27. {
  28. virtual bool identify(const PPSystemString& filename) const = 0;
  29. };
  30. private:
  31. struct filename_node
  32. {
  33. struct filename_node * next;
  34. unsigned long length;
  35. unsigned long crc;
  36. unsigned char filename[256];
  37. };
  38. struct UnLZX
  39. {
  40. unsigned char match_pattern[256];
  41. signed long use_outdir;
  42. unsigned char output_dir[768];
  43. unsigned char work_buffer[1024];
  44. signed long mode;
  45. unsigned char info_header[10];
  46. unsigned char archive_header[32];
  47. unsigned char header_filename[256];
  48. unsigned char header_comment[256];
  49. unsigned long pack_size;
  50. unsigned long unpack_size;
  51. unsigned long crc;
  52. unsigned long year;
  53. unsigned long month;
  54. unsigned long day;
  55. unsigned long hour;
  56. unsigned long minute;
  57. unsigned long second;
  58. unsigned char attributes;
  59. unsigned char pack_mode;
  60. struct filename_node *filename_list;
  61. unsigned char read_buffer[16384];
  62. unsigned char decrunch_buffer[66560];
  63. unsigned char *source;
  64. unsigned char *destination;
  65. unsigned char *source_end;
  66. unsigned char *destination_end;
  67. unsigned long decrunch_method;
  68. unsigned long decrunch_length;
  69. unsigned long last_offset;
  70. unsigned long global_control;
  71. signed long global_shift;
  72. unsigned char offset_len[8];
  73. unsigned short offset_table[128];
  74. unsigned char huffman20_len[20];
  75. unsigned short huffman20_table[96];
  76. unsigned char literal_len[768];
  77. unsigned short literal_table[5120];
  78. unsigned long sum;
  79. const PPSystemString* temporaryFile;
  80. };
  81. PPSystemString archiveFilename;
  82. const FileIdentificator* identificator;
  83. UnLZX* unlzx;
  84. void mkdir(const char* name, int len);
  85. struct UnLZX *unlzx_init(void);
  86. void unlzx_free(struct UnLZX *unlzx);
  87. int pmatch(const char *mask, const char *name);
  88. void just_wait(void);
  89. unsigned long argopt(unsigned char * ao_strg, unsigned long ao_argc, unsigned char **ao_argv);
  90. void crc_calc(unsigned char *memory, unsigned long length, struct UnLZX *unlzx);
  91. signed long make_decode_table(signed long number_symbols, signed long table_size, unsigned char *length, unsigned short *table);
  92. signed long read_literal_table(struct UnLZX *unlzx);
  93. void decrunch(struct UnLZX *unlzx);
  94. XMFile* open_output(const PPSystemString& filename);
  95. signed long extract_normal(XMFile* in_file, struct UnLZX *unlzx, bool& found);
  96. signed long extract_store(XMFile* in_file, struct UnLZX *unlzx, bool& found);
  97. signed long extract_unknown(XMFile* in_file, struct UnLZX *unlzx, bool& found);
  98. signed long extract_archive(XMFile* in_file, struct UnLZX *unlzx, bool& found);
  99. signed long view_archive(XMFile* in_file, struct UnLZX *unlzx);
  100. signed long process_archive(const PPSystemString& filename, struct UnLZX *unlzx, bool& found);
  101. public:
  102. Unlzx(const PPSystemString& archiveFilename, const FileIdentificator* identificator = NULL);
  103. ~Unlzx();
  104. bool extractFile(bool extract, const PPSystemString* outFilename);
  105. };
  106. #define PMATCH_MAXSTRLEN 512 /* max string length */
  107. #define make_percent(p,m) ((p*100)/m)
  108. #endif /* unlzx_unlzx_h */