"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "lha-114i/src/larc.c" 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    															*/
    3 /*				larc.c -- extra *.lzs										*/
    4 /*																			*/
    5 /*		Modified          		Nobutaka Watazaki							*/
    6 /*																			*/
    7 /*	Ver. 1.14 	Source All chagned				1995.01.14	N.Watazaki		*/
    8 /* ------------------------------------------------------------------------ */
    9 #include "lha.h"
   10 
   11 /* ------------------------------------------------------------------------ */
   12 static int      flag, flagcnt, matchpos;
   13 /* ------------------------------------------------------------------------ */
   14 unsigned short
   15 decode_c_lzs( /*void*/ )
   16 {
   17 	if (getbits(1)) {
   18 		return getbits(8);
   19 	}
   20 	else {
   21 		matchpos = getbits(11);
   22 		return getbits(4) + 0x100;
   23 	}
   24 }
   25 
   26 /* ------------------------------------------------------------------------ */
   27 unsigned short
   28 decode_p_lzs( /*void*/ )
   29 {
   30 	return (loc - matchpos - MAGIC0) & 0x7ff;
   31 }
   32 
   33 /* ------------------------------------------------------------------------ */
   34 void
   35 decode_start_lzs( /*void*/ )
   36 {
   37 	init_getbits();
   38 }
   39 
   40 /* ------------------------------------------------------------------------ */
   41 unsigned short
   42 decode_c_lz5( /*void*/ )
   43 {
   44 	int             c;
   45 
   46 	if (flagcnt == 0) {
   47 		flagcnt = 8;
   48 		flag = getc(infile);
   49 	}
   50 	flagcnt--;
   51 	c = getc(infile);
   52 	if ((flag & 1) == 0) {
   53 		matchpos = c;
   54 		c = getc(infile);
   55 		matchpos += (c & 0xf0) << 4;
   56 		c &= 0x0f;
   57 		c += 0x100;
   58 	}
   59 	flag >>= 1;
   60 	return c;
   61 }
   62 
   63 /* ------------------------------------------------------------------------ */
   64 unsigned short
   65 decode_p_lz5( /*void*/ )
   66 {
   67 	return (loc - matchpos - MAGIC5) & 0xfff;
   68 }
   69 
   70 /* ------------------------------------------------------------------------ */
   71 void
   72 decode_start_lz5( /*void*/ )
   73 {
   74 	int             i;
   75 
   76 	flagcnt = 0;
   77 	for (i = 0; i < 256; i++)
   78 		memset(&text[i * 13 + 18], i, 13);
   79 	for (i = 0; i < 256; i++)
   80 		text[256 * 13 + 18 + i] = i;
   81 	for (i = 0; i < 256; i++)
   82 		text[256 * 13 + 256 + 18 + i] = 255 - i;
   83 	memset(&text[256 * 13 + 512 + 18], 0, 128);
   84 	memset(&text[256 * 13 + 512 + 128 + 18], ' ', 128 - 18);
   85 }