"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "lha-114i/src/lha_macro.h" of archive lha-114i.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /* ------------------------------------------------------------------------ */
    2 /* LHa for UNIX    Archiver Driver	macro define							*/
    3 /*																			*/
    4 /*		Modified          		Nobutaka Watazaki							*/
    5 /*																			*/
    6 /*	Ver. 1.14	Soruce All chagned				1995.01.14	N.Watazaki		*/
    7 /*	Ver. 1.14g	modified   						2000.05.06	T.OKAMOTO		*/
    8 /* ------------------------------------------------------------------------ */
    9 
   10 #define LHA_VERSION "lha for unix version 1.14g"
   11 
   12 /* Most of System V, define SYSTIME_HAS_NO_TM */
   13 #ifdef	SYSTIME_HAS_NO_TM
   14 #include <time.h>
   15 #else
   16 #include <sys/time.h>
   17 #endif	/* SYSTIME_HAS_NO_TM */
   18 
   19 /* ------------------------------------------------------------------------ */
   20 /*	Directory Access Stuff													*/
   21 /* ------------------------------------------------------------------------ */
   22 #ifndef NODIRECTORY
   23 #ifdef SYSV_SYSTEM_DIR
   24 
   25 #include <dirent.h>
   26 
   27 #define DIRENTRY	struct dirent
   28 #define NAMLEN(p)	strlen (p->d_name)
   29 
   30 #else	/* not SYSV_SYSTEM_DIR */
   31 
   32 #ifdef NONSYSTEM_DIR_LIBRARY
   33 #include "lhdir.h"
   34 #else
   35 #include <sys/dir.h>
   36 #endif	/* not NONSYSTEM_DIR_LIBRARY */
   37 
   38 #define DIRENTRY		struct direct
   39 #define NAMLEN(p)		p->d_namlen
   40 
   41 #endif	/* not SYSV_SYSTEM_DIR */
   42 #endif  /* NODIRECTORY */
   43 
   44 /* ------------------------------------------------------------------------ */
   45 /*	Other Define															*/
   46 /* ------------------------------------------------------------------------ */
   47 /* Not support 'void' */
   48 #ifdef NOVOID
   49 #define void
   50 #endif
   51 
   52 #ifndef SEEK_SET
   53 #define SEEK_SET		0
   54 #define SEEK_CUR		1
   55 #define SEEK_END		2
   56 #endif	/* SEEK_SET
   57 
   58 
   59 /* non-integral functions */
   60 extern struct tm *localtime();
   61 extern char    *getenv();
   62 
   63 #ifndef _MINIX
   64 #ifndef __STDC__
   65 extern char    *malloc();
   66 extern char    *realloc();
   67 #endif
   68 #endif
   69 
   70 /* external variables */
   71 extern int      errno;
   72 
   73 #define	FALSE			0
   74 #define TRUE			1
   75 typedef int				boolean;
   76 
   77 /* used by qsort() for alphabetic-sort */
   78 #define STRING_COMPARE(a,b)		strcmp((a),(b))
   79 
   80 #define FILENAME_LENGTH	1024
   81 
   82 /* ------------------------------------------------------------------------ */
   83 /* YOUR CUSTOMIZIES															*/
   84 /* ------------------------------------------------------------------------ */
   85 
   86 #ifndef ARCHIVENAME_EXTENTION
   87 #define ARCHIVENAME_EXTENTION	".lzh"
   88 #endif
   89 #ifndef BACKUPNAME_EXTENTION
   90 #define BACKUPNAME_EXTENTION	".bak"
   91 #endif
   92 #ifndef TMP_FILENAME_TEMPLATE
   93 #define TMP_FILENAME_TEMPLATE	"/tmp/lhXXXXXX"
   94 #endif
   95 
   96 #define SJC_FIRST_P(c)			\
   97   (((unsigned char)(c) >= 0x80) &&	\
   98    (((unsigned char)(c) < 0xa0) ||	\
   99     ((unsigned char)(c) >= 0xe0) &&	\
  100     ((unsigned char)(c) < 0xfd)))
  101 #define SJC_SECOND_P(c)			\
  102   (((unsigned char)(c) >= 0x40) &&	\
  103    ((unsigned char)(c) < 0xfd) &&	\
  104    ((unsigned char)(c) != 0x7f))
  105 
  106 #ifdef MULTIBYTE_CHAR
  107 #define MULTIBYTE_FIRST_P	SJC_FIRST_P
  108 #define MULTIBYTE_SECOND_P	SJC_SECOND_P
  109 #endif				/* MULTIBYTE_CHAR */
  110 
  111 /* ------------------------------------------------------------------------ */
  112 /*	LHa File Definitions													*/
  113 /* ------------------------------------------------------------------------ */
  114 #ifdef S_IFLNK
  115 #define GETSTAT lstat
  116 #else
  117 #define GETSTAT stat
  118 #endif
  119 
  120 #ifdef LHA_MAIN_SRC
  121 #define EXTERN
  122 #else
  123 #define EXTERN				extern
  124 #endif	/* LHA_MAIN_SRC */
  125 
  126 #define LZHUFF0_METHOD			"-lh0-"
  127 #define LZHUFF1_METHOD			"-lh1-"
  128 #define LZHUFF2_METHOD			"-lh2-"
  129 #define LZHUFF3_METHOD			"-lh3-"
  130 #define LZHUFF4_METHOD			"-lh4-"
  131 #define LZHUFF5_METHOD			"-lh5-"
  132 #define LZHUFF6_METHOD			"-lh6-"
  133 #define LZHUFF7_METHOD			"-lh7-"
  134 #define LARC_METHOD				"-lzs-"
  135 #define LARC5_METHOD			"-lz5-"
  136 #define LARC4_METHOD			"-lz4-"
  137 #define LZHDIRS_METHOD			"-lhd-"
  138 
  139 #define METHOD_TYPE_STRAGE		5
  140 
  141 /* Added N.Watazaki ..V */
  142 #define LZHUFF0_METHOD_NUM		0
  143 #define LZHUFF1_METHOD_NUM		1
  144 #define LZHUFF2_METHOD_NUM		2
  145 #define LZHUFF3_METHOD_NUM		3
  146 #define LZHUFF4_METHOD_NUM		4
  147 #define LZHUFF5_METHOD_NUM		5
  148 #define LZHUFF6_METHOD_NUM		6
  149 #define LZHUFF7_METHOD_NUM		7
  150 #define LARC_METHOD_NUM			8
  151 #define LARC5_METHOD_NUM		9
  152 #define LARC4_METHOD_NUM		10
  153 #define LZHDIRS_METHOD_NUM		11
  154 /* Added N.Watazaki ..^ */
  155 
  156 #define I_HEADER_SIZE			0
  157 #define I_HEADER_CHECKSUM		1
  158 #define I_METHOD				2
  159 #define I_PACKED_SIZE			7
  160 #define I_ORIGINAL_SIZE			11
  161 #define I_LAST_MODIFIED_STAMP	15
  162 #define I_ATTRIBUTE				19
  163 #define I_HEADER_LEVEL			20
  164 #define I_NAME_LENGTH			21
  165 #define I_NAME					22
  166 
  167 #define I_CRC						22	/* + name_length */
  168 #define I_EXTEND_TYPE				24	/* + name_length */
  169 #define I_MINOR_VERSION				25	/* + name_length */
  170 #define I_UNIX_LAST_MODIFIED_STAMP	26	/* + name_length */
  171 #define I_UNIX_MODE					30	/* + name_length */
  172 #define I_UNIX_UID					32	/* + name_length */
  173 #define I_UNIX_GID					34	/* + name_length */
  174 #define I_UNIX_EXTEND_BOTTOM		36	/* + name_length */
  175 
  176 #define I_GENERIC_HEADER_BOTTOM		I_EXTEND_TYPE
  177 
  178 #define EXTEND_GENERIC			0
  179 #define EXTEND_UNIX				'U'
  180 #define EXTEND_MSDOS			'M'
  181 #define EXTEND_MACOS			'm'
  182 #define EXTEND_OS9				'9'
  183 #define EXTEND_OS2				'2'
  184 #define EXTEND_OS68K			'K'
  185 #define EXTEND_OS386			'3'	/* OS-9000??? */
  186 #define EXTEND_HUMAN			'H'
  187 #define EXTEND_CPM				'C'
  188 #define EXTEND_FLEX				'F'
  189 #define EXTEND_RUNSER			'R'
  190 
  191 /* this OS type is not official */
  192 
  193 #define EXTEND_TOWNSOS			'T'
  194 #define EXTEND_XOSK				'X'
  195 
  196 /*---------------------------------------------------------------------------*/
  197 
  198 #define GENERIC_ATTRIBUTE				0x20
  199 #define GENERIC_DIRECTORY_ATTRIBUTE		0x10
  200 #define HEADER_LEVEL0					0x00
  201 #define HEADER_LEVEL1					0x01
  202 #define HEADER_LEVEL2					0x02
  203 
  204 #define CURRENT_UNIX_MINOR_VERSION		0x00
  205 
  206 #define DELIM		('/')
  207 #define DELIM2		(0xff)
  208 #define DELIMSTR	"/"
  209 
  210 #define OSK_RW_RW_RW			0000033
  211 #define OSK_FILE_REGULAR		0000000
  212 #define OSK_DIRECTORY_PERM		0000200
  213 #define OSK_SHARED_PERM			0000100
  214 #define OSK_OTHER_EXEC_PERM		0000040
  215 #define OSK_OTHER_WRITE_PERM	0000020
  216 #define OSK_OTHER_READ_PERM		0000010
  217 #define OSK_OWNER_EXEC_PERM		0000004
  218 #define OSK_OWNER_WRITE_PERM	0000002
  219 #define OSK_OWNER_READ_PERM		0000001
  220 
  221 #define UNIX_FILE_TYPEMASK		0170000
  222 #define UNIX_FILE_REGULAR		0100000
  223 #define UNIX_FILE_DIRECTORY		0040000
  224 #define UNIX_FILE_SYMLINK		0120000
  225 #define UNIX_SETUID				0004000
  226 #define UNIX_SETGID				0002000
  227 #define UNIX_STYCKYBIT			0001000
  228 #define UNIX_OWNER_READ_PERM	0000400
  229 #define UNIX_OWNER_WRITE_PERM	0000200
  230 #define UNIX_OWNER_EXEC_PERM	0000100
  231 #define UNIX_GROUP_READ_PERM	0000040
  232 #define UNIX_GROUP_WRITE_PERM	0000020
  233 #define UNIX_GROUP_EXEC_PERM	0000010
  234 #define UNIX_OTHER_READ_PERM	0000004
  235 #define UNIX_OTHER_WRITE_PERM	0000002
  236 #define UNIX_OTHER_EXEC_PERM	0000001
  237 #define UNIX_RW_RW_RW			0000666
  238 
  239 #define LZHEADER_STRAGE			4096
  240 
  241 #define MAX_INDICATOR_COUNT		64
  242 
  243 typedef short   				node;
  244 
  245 /* ------------------------------------------------------------------------ */
  246 /*	Slide relation															*/
  247 /* ------------------------------------------------------------------------ */
  248 #if defined(__STDC__) || defined(AIX)
  249 
  250 #include <limits.h>
  251 
  252 #else
  253 
  254 #ifndef CHAR_BIT
  255 #define CHAR_BIT  8
  256 #endif
  257 
  258 #ifndef UCHAR_MAX
  259 #define UCHAR_MAX				((1<<(sizeof(unsigned char)*8))-1)
  260 #endif
  261 
  262 #ifndef USHRT_MAX
  263 #define USHRT_MAX				((1<<(sizeof(unsigned short)*8))-1)
  264 #endif
  265 
  266 #ifndef SHRT_MAX
  267 #define SHRT_MAX				((1<<(sizeof(short)*8-1))-1)
  268 #endif
  269 
  270 #ifndef SHRT_MIN
  271 #define SHRT_MIN				(SHRT_MAX-USHRT_MAX)
  272 #endif
  273 
  274 #ifndef ULONG_MAX
  275 #define ULONG_MAX	((1<<(sizeof(unsigned long)*8))-1)
  276 #endif
  277 
  278 #ifndef LONG_MAX
  279 #define LONG_MAX	((1<<(sizeof(long)*8-1))-1)
  280 #endif
  281 
  282 #ifndef LONG_MIN
  283 #define LONG_MIN	(LONG_MAX-ULONG_MAX)
  284 #endif
  285 
  286 #endif	/* not __STDC__ */
  287 
  288 /* ------------------------------------------------------------------------ */
  289 /*	FILE Attribute															*/
  290 /* ------------------------------------------------------------------------ */
  291 #define is_directory(statp)		(((statp)->st_mode & S_IFMT) == S_IFDIR)
  292 #define is_symlink(statp)		(((statp)->st_mode & S_IFMT) == S_IFLNK)
  293 #define is_regularfile(statp)	(((statp)->st_mode & S_IFMT) == S_IFREG)
  294 
  295 #ifdef MSDOS
  296 #define WRITE_BINARY	"wb"
  297 #define READ_BINARY		"rb"
  298 #else
  299 #define WRITE_BINARY	"w"
  300 #define READ_BINARY		"r"
  301 #endif
  302 
  303 /* ------------------------------------------------------------------------ */
  304 /*	Memory and String function												*/
  305 /* ------------------------------------------------------------------------ */
  306 #include <string.h>
  307 
  308 #ifdef NOINDEX
  309 #define index			strchr
  310 #define rindex			strrchr
  311 #endif	/* NOINDEX */
  312 
  313 #ifdef NOBSTRING
  314 #define bcmp(a,b,n)		memcmp ((a),(b),(n))
  315 #define bzero(d,n)		memset((d),0,(n))
  316 #define bcopy(s,d,n)	memmove((d),(s),(n))
  317 #endif	/* NOBSTRING */
  318 
  319 #ifdef USESTRCASECMP
  320 #define strucmp(p,q)	strcasecmp((p),(q))
  321 #endif
  322 
  323 /* ------------------------------------------------------------------------ */
  324 /* Individual macro define													*/
  325 /* ------------------------------------------------------------------------ */
  326 
  327 /* from crcio.c */
  328 #define CRCPOLY			0xA001		/* CRC-16 */
  329 #define UPDATE_CRC(c)	crc = crctable[(crc ^ (c)) & 0xFF] ^ (crc >> CHAR_BIT)
  330 
  331 /* dhuf.c */
  332 #define N_CHAR      (256 + 60 - THRESHOLD + 1)
  333 #define TREESIZE_C  (N_CHAR * 2)
  334 #define TREESIZE_P  (128 * 2)
  335 #define TREESIZE    (TREESIZE_C + TREESIZE_P)
  336 #define ROOT_C      0
  337 #define ROOT_P      TREESIZE_C
  338 
  339 /* header.c */
  340 #define setup_get(PTR)	(get_ptr = (PTR))
  341 #define get_byte()		(*get_ptr++ & 0xff)
  342 #define put_ptr			get_ptr
  343 #define setup_put(PTR)	(put_ptr = (PTR))
  344 #define put_byte(c)		(*put_ptr++ = (char)(c))
  345 
  346 /* huf.c */
  347 #define NP			(MAX_DICBIT + 1)
  348 #define NT			(USHRT_BIT + 3)
  349 #if 0
  350 #define PBIT		4		/* smallest integer such that (1 << PBIT) > * NP */
  351 #define TBIT 		5		/* smallest integer such that (1 << TBIT) > * NT */
  352 #endif
  353 
  354 #define PBIT		5		/* smallest integer such that (1 << PBIT) > * NP */
  355 #define TBIT 		5		/* smallest integer such that (1 << TBIT) > * NT */
  356 
  357 #define NC 			(UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
  358 
  359 /*		#if NT > NP #define NPT NT #else #define NPT NP #endif	*/
  360 #define NPT			0x80
  361 
  362 /* larc.c */
  363 #define MAGIC0		18
  364 #define MAGIC5		19
  365 
  366 /* lharc.c */
  367 #define CMD_UNKNOWN	0
  368 #define CMD_EXTRACT	1
  369 #define CMD_ADD		2
  370 #define CMD_LIST	3
  371 #define CMD_DELETE	4
  372 
  373 #define STREQU(a,b)	(((a)[0] == (b)[0]) ? (strcmp ((a),(b)) == 0) : FALSE)
  374 
  375 /* shuf.c */
  376 #define N1			286				/* alphabet size */
  377 #define N2			(2 * N1 - 1)	/* # of nodes in Huffman tree */
  378 #define EXTRABITS	8				/* >= log2(F-THRESHOLD+258-N1) */
  379 #define BUFBITS		16				/* >= log2(MAXBUF) */
  380 #define LENFIELD	4				/* bit size of length field for tree output */
  381 
  382 /* util.c */
  383 #define BUFFERSIZE	2048
  384 #define MAXSFXCODE	1024*64
  385 
  386 #ifndef NULL
  387 #define NULL		(char *)0
  388 #endif
  389 
  390 /* slide.c */
  391 /*
  392 #define PERCOLATE  1
  393 #define NIL        0
  394 #define HASH(p, c) ((p) + ((c) << hash1) + hash2)
  395 */
  396 
  397 /* slide.c */
  398 #ifdef SUPPORT_LH7
  399 #define MAX_DICBIT			16      /* lh7 use 16bits */
  400 #endif
  401 
  402 #ifndef SUPPORT_LH7
  403 #define MAX_DICBIT			15      /* lh6 use 15bits */
  404 #endif
  405 
  406 #define MAX_DICSIZ			(1 << MAX_DICBIT)
  407 #define MATCHBIT			8	/* bits for MAXMATCH - THRESHOLD */
  408 #define MAXMATCH			256	/* formerly F (not more than UCHAR_MAX + 1) */
  409 #define THRESHOLD			3	/* choose optimal value */
  410 
  411 /* from huf.c */
  412 
  413 /* alphabet = {0, 1, 2, ..., NC - 1} */
  414 #define CBIT				9	/* $\lfloor \log_2 NC \rfloor + 1$ */
  415 #define USHRT_BIT			16	/* (CHAR_BIT * sizeof(ushort)) */
  416 
  417 /* Local Variables: */
  418 /* mode:c */
  419 /* tab-width:4 */
  420 /* End: */