LIBRARY.H 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/pslib/rcs/library.h $
  15. * $Revision: 1.9 $
  16. * $Author: yuan $
  17. * $Date: 1993/09/29 17:54:09 $
  18. *
  19. * PSLIB and library generation tool header file.
  20. *
  21. * $Log: library.h $
  22. * Revision 1.9 1993/09/29 17:54:09 yuan
  23. * ReadFileRaw, etc. prototypes imported.
  24. *
  25. * Revision 1.8 1993/09/27 17:12:48 yuan
  26. * Cleaned up... function prototypes internal to pslib.c removed.
  27. *
  28. * Revision 1.7 1993/09/21 17:22:14 yuan
  29. * *** empty log message ***
  30. *
  31. * Revision 1.6 1993/09/21 17:16:50 yuan
  32. * cleaning up
  33. *
  34. * Revision 1.5 1993/09/21 17:07:11 yuan
  35. * broken and unbroken
  36. *
  37. * Revision 1.4 1993/09/14 14:19:08 yuan
  38. * header fixed.
  39. *
  40. * Revision 1.3 1993/09/14 13:16:37 yuan
  41. * Minor function prototype modifications were made.
  42. *
  43. * Revision 1.2 1993/09/09 12:39:19 yuan
  44. * compression routine prototypes moved to pslib.h
  45. *
  46. * Revision 1.1 1993/09/08 16:16:07 yuan
  47. * Initial revision
  48. *
  49. *
  50. */
  51. #include "cflib.h"
  52. #include "time.h"
  53. #include "types.h"
  54. #define TICKER (*(volatile int *)0x46C)
  55. #define USECS_PER_READING( start, stop, frames ) (((stop-start)*54945)/frames)
  56. #define MSECS_TOTAL_TIME( start, stop ) ((stop - start)*55)
  57. #define MAX_FILES 100
  58. #define ERROR_OPENING_FILE 21
  59. #define ERROR_WRITING_FILE 22
  60. #define ERROR_READING_DATA -20
  61. typedef struct bit_file {
  62. ubyte *buf;
  63. int current_byte;
  64. ubyte mask;
  65. int rack;
  66. int pacifier_counter;
  67. int length;
  68. } BIT_BUF;
  69. typedef struct lib_header {
  70. char id[4]; // set to 'PSLB'
  71. short nfiles; // how many files in this library
  72. } lib_header;
  73. typedef struct file_header {
  74. char name[13]; // 8 chars, dot, extension, null
  75. byte compression; // compression method
  76. int offset, // where in the lib file
  77. length, // how much space in lib taken by this file
  78. original_size; // how long the actual (uncompressed) data is
  79. // time_t time; // the date & time, from the time() function
  80. ushort date; // the date
  81. ushort time; // the time
  82. short ratio; // this makes the structure 32 bytes
  83. } file_header;
  84. // Date and time macros
  85. #define YEAR(t) (((t & 0xFE00) >> 9) + 1980)
  86. #define MONTH(t) ((t & 0x01E0) >> 5)
  87. #define DAY(t) (t & 0x001F)
  88. #define HOUR(t) ((t & 0xF800) >> 11)
  89. #define MINUTE(t) ((t & 0x07E0) >> 5)
  90. #define SECOND(t) ((t & 0x001F) << 1)
  91. // bitio function prototypes
  92. BIT_BUF *OpenInputBitBuf( ubyte *buffer );
  93. BIT_BUF *OpenOutputBitBuf();
  94. void OutputBit( BIT_BUF *bit_file, int bit );
  95. void OutputBits( BIT_BUF *bit_file, unsigned int code, int count );
  96. int InputBit( BIT_BUF *bit_file );
  97. unsigned int InputBits( BIT_BUF *bit_file, int bit_count );
  98. void CloseInputBitBuf( BIT_BUF *bit_file );
  99. void CloseOutputBitBuf( BIT_BUF *bit_file );
  100. void FilePrintBinary( FILE *file, unsigned int code, int bits );
  101. #define LISTING 1 // listing the library
  102. #define BUILDING 1 // building the library
  103. #define LF_LZW 1 // this file has LZW compression
  104. #define MAX_FILE_SIZE 1024 * 100
  105. // pslib function prototypes
  106. int file_size( char *name );
  107. void header_count( char *argv );
  108. int read_data( FILE *fp, struct file_header *p );
  109. void init_library( char *filename, int numfiles );
  110. void write_file_header( char *filename, file_header Header );
  111. //void print_usage( void );
  112. //void check_list( char *argv );
  113. //void list_files( void );
  114. //void cfr_test( char *input, char *output );
  115. //void cfw_test( char *input, char *output );
  116. //void extract_test( char *extractname, char *extractout );
  117. //void lib_read_test( char *extractname, char *extractout );
  118. //void process_arg( char *argv );
  119. extern char *Usage;
  120. extern char *CompressionName;
  121. extern int lib_flag; // library flag
  122. extern int b_flag; // building flag
  123. extern int c_flag; // compression flag
  124. extern int l_flag; // listing flag
  125. extern int lib_flag; // library flag
  126. extern FILE *InputLibFile; // file to read from
  127. extern FILE *OutputLibFile; // file to write to
  128. extern char *lib_name; // name of the library
  129. extern int file_count; // number of files processed
  130. extern int headers; // number of header spaces allocated
  131. extern file_header Header; // Holds header info of file being processed
  132. extern char *FileList[100]; // Contains the list of files being processed
  133. extern file_header *LibHeaderList;
  134. extern FILE *InputLibInitFile; // file to read from
  135. extern short init_numfiles; // number of files in the library
  136. void *ReadFileRaw( char *filename, int *length );
  137. // ReadFileRaw reads 'filename' and returns the buffer and passes the length
  138. // in bytes.
  139. int WriteFile( char *filename, void *data, int length );
  140. // WriteFile writes 'length' bytes of 'data' to 'filename'
  141. // returns an error code != 0 if there is an error.
  142. int AppendFile( char *filename, void *data, int length );
  143. // AppendFile appends 'length' bytes of 'data' to 'filename'
  144. // returns an error code != 0 if there is an error.
  145. int ReadFileBuf( char *filename, byte *buf, int bufsize );
  146. // ReadFileBuf reads bufize bytes of 'filename' into the address of 'buf'
  147. // returns an error code < 0 if there is an error.