wok diff lzma/stuff/lzlib.u @ rev 7482

modify .desktop of 3 file
author fireflyoo <lufeng369@gmail.com>
date Fri Dec 03 00:24:35 2010 +0800 (2010-12-03)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lzma/stuff/lzlib.u	Fri Dec 03 00:24:35 2010 +0800
     1.3 @@ -0,0 +1,202 @@
     1.4 +--- CPP/7zip/Compress/LZMA_Alone/makefile.gcc
     1.5 ++++ CPP/7zip/Compress/LZMA_Alone/makefile.gcc
     1.6 +@@ -1,6 +1,6 @@
     1.7 + PROG = lzma
     1.8 +-CXX = g++ -O2 -Wall
     1.9 +-CXX_C = gcc -O2 -Wall
    1.10 ++CXX = g++ -s -O2 -Wall
    1.11 ++CXX_C = gcc -s -O2 -Wall
    1.12 + LIB = -lm
    1.13 + RM = rm -f
    1.14 + CFLAGS = -c
    1.15 +@@ -46,8 +46,47 @@
    1.16 +   LzmaDecode.o \
    1.17 +   LzmaRamDecode.o \
    1.18 + 
    1.19 ++LIB = liblz.so.1.0.0
    1.20 ++LIB_OBJS = \
    1.21 ++  LzmaRamDecode.o \
    1.22 ++  LzmaDecode.o \
    1.23 ++  BranchX86.o \
    1.24 ++  Wrapper.o \
    1.25 ++  
    1.26 ++SHARED_OBJS = \
    1.27 ++  LzmaAlone.o \
    1.28 ++  LzmaBench.o \
    1.29 ++  LzmaBenchCon.o \
    1.30 ++  LZMADecoder.o \
    1.31 ++  LZMAEncoder.o \
    1.32 ++  LzmaRam.o \
    1.33 ++  InBuffer.o \
    1.34 ++  OutBuffer.o \
    1.35 ++  CRC.o \
    1.36 ++  IntToString.o \
    1.37 ++  MyString.o \
    1.38 ++  StringConvert.o \
    1.39 ++  StringToInt.o \
    1.40 ++  MyVector.o \
    1.41 ++  7zCrc.o \
    1.42 ++  Alloc.o \
    1.43 ++  MatchFinder.o \
    1.44 ++  StreamUtils.o \
    1.45 ++  LZOutWindow.o \
    1.46 ++  RangeCoderBit.o \
    1.47 ++  FileStreams.o \
    1.48 ++  $(FILE_IO).o \
    1.49 ++  CommandLineParser.o \
    1.50 ++
    1.51 ++all: $(PROG) $(LIB)
    1.52 ++
    1.53 ++$(LIB): $(LIB_OBJS)
    1.54 ++	$(CXX) -shared -Wl,-soname -Wl,liblz.so.1 -o $(LIB) $(LIB_OBJS) -lz
    1.55 ++	$(CXX) $(LDFLAGS) -o lzma-shared $(SHARED_OBJS) liblz.so.1.0.0 $(LIB) $(LIB2)
    1.56 ++
    1.57 ++Wrapper.o: Wrapper.c
    1.58 ++	$(CXX_C) $(CFLAGS) Wrapper.c
    1.59 + 
    1.60 +-all: $(PROG)
    1.61 + 
    1.62 + $(PROG): $(OBJS)
    1.63 + 	$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)
    1.64 +	
    1.65 +--- CPP/7zip/Compress/LZMA_Alone/lzlib.h
    1.66 ++++ CPP/7zip/Compress/LZMA_Alone/lzlib.h
    1.67 +@@ -0,0 +1,15 @@
    1.68 ++#ifndef LZLIB_H
    1.69 ++#define LZLIB_H
    1.70 ++#include <zlib.h>
    1.71 ++typedef struct {
    1.72 ++	int handlertype;
    1.73 ++	unsigned long lzsize;
    1.74 ++	int fd;
    1.75 ++	gzFile gzfd;
    1.76 ++} *lzFile;
    1.77 ++
    1.78 ++extern lzFile lzdopen(int fd, const char *mode);
    1.79 ++extern lzFile lzopen(const char *path, const char *mode);
    1.80 ++extern void *lzgrab(lzFile file, unsigned long *size);
    1.81 ++extern int lzclose(lzFile file);
    1.82 ++#endif
    1.83 +
    1.84 +--- CPP/7zip/Compress/LZMA_Alone/Wrapper.c
    1.85 ++++ CPP/7zip/Compress/LZMA_Alone/Wrapper.c
    1.86 +@@ -0,0 +1,119 @@
    1.87 ++#include <stdlib.h>
    1.88 ++#include <unistd.h>
    1.89 ++#include <sys/types.h>
    1.90 ++#include <sys/stat.h>
    1.91 ++#include <fcntl.h>
    1.92 ++#include "lzlib.h"
    1.93 ++#include "LzmaRamDecode.h"
    1.94 ++
    1.95 ++#define LZ_READ		0
    1.96 ++#define LZ_GZREAD	1
    1.97 ++#define LZ_LZREAD	2
    1.98 ++
    1.99 ++#define LZMA_PROP	0x5d
   1.100 ++
   1.101 ++static int fullread(int fd, unsigned char *buffer, size_t len)
   1.102 ++{
   1.103 ++	int i, n;
   1.104 ++	for (n = 0; (i = read(fd, buffer + n, len - n)) > 0; n += i);
   1.105 ++	return n;
   1.106 ++}
   1.107 ++
   1.108 ++lzFile lzdopen(int fd, const char *mode)
   1.109 ++{
   1.110 ++	unsigned char tmp[13];
   1.111 ++	int n;
   1.112 ++	lzFile lzfd;
   1.113 ++	
   1.114 ++	if (fd < 0) return NULL;
   1.115 ++	n = fullread(fd, tmp, sizeof(tmp));
   1.116 ++	lzfd = malloc(sizeof(*lzfd));
   1.117 ++	if (!lzfd) return NULL;
   1.118 ++	lzfd->handlertype = LZ_READ;
   1.119 ++	if (n == sizeof(tmp) && tmp[0] == LZMA_PROP && 
   1.120 ++	    !LzmaRamGetUncompressedSize(tmp-1, sizeof(tmp)+1, &lzfd->lzsize))
   1.121 ++	    	lzfd->handlertype = LZ_LZREAD;
   1.122 ++	else if (n > 2 && tmp[0] == 0x1F && tmp[1] == 0x8B)
   1.123 ++		lzfd->handlertype = LZ_GZREAD;
   1.124 ++	lzfd->fd = fd;
   1.125 ++	lseek(fd, 0, SEEK_SET);
   1.126 ++	if (lzfd->handlertype != LZ_LZREAD) {
   1.127 ++		if (lzfd->handlertype == LZ_GZREAD) {
   1.128 ++			lzfd->gzfd = gzdopen(fd, mode);
   1.129 ++			if (lzfd->gzfd == Z_NULL) {
   1.130 ++				free(lzfd);
   1.131 ++				return NULL;
   1.132 ++			}
   1.133 ++		}
   1.134 ++	}
   1.135 ++	return lzfd;
   1.136 ++}
   1.137 ++
   1.138 ++lzFile lzopen(const char *path, const char *mode)
   1.139 ++{
   1.140 ++	int fd = open(path, O_RDONLY);
   1.141 ++	return lzdopen(fd, mode);
   1.142 ++}
   1.143 ++
   1.144 ++static int lzread(lzFile file, void *buf, unsigned len)
   1.145 ++{
   1.146 ++	if (file->handlertype == LZ_GZREAD)
   1.147 ++		return gzread(file->gzfd, buf, len);
   1.148 ++	return read(file->fd, buf, len);
   1.149 ++}
   1.150 ++
   1.151 ++void *lzgrab(lzFile file, unsigned long *size)
   1.152 ++{
   1.153 ++	unsigned int n, max;
   1.154 ++	unsigned char *output;
   1.155 ++	
   1.156 ++	if (!file) return NULL;
   1.157 ++	if (file->handlertype == LZ_LZREAD) {
   1.158 ++		unsigned char *input;
   1.159 ++		size_t outsize;
   1.160 ++
   1.161 ++		output = malloc(file->lzsize + file->lzsize/20); // 105%
   1.162 ++		if (!output) return NULL;
   1.163 ++		output[0] = 0;
   1.164 ++		max = 1 + fullread(file->fd, output+1, file->lzsize);
   1.165 ++		input = realloc(output, max);
   1.166 ++		output = malloc(file->lzsize);
   1.167 ++		if (!output || LzmaRamDecompress(input, max,
   1.168 ++		     output, file->lzsize, &outsize, malloc, free)) {
   1.169 ++			if (output) free(output);
   1.170 ++			free(input);
   1.171 ++			return NULL;
   1.172 ++		}
   1.173 ++		free(input);
   1.174 ++		*size = outsize;
   1.175 ++		return output;
   1.176 ++	}
   1.177 ++	max = 16384;
   1.178 ++	output = malloc(max);
   1.179 ++	if (!output) return NULL;
   1.180 ++	*size = 0;
   1.181 ++	while ((n = lzread(file, output + *size, max - *size)) > 0) {
   1.182 ++		*size += n;
   1.183 ++		if (*size == max) {
   1.184 ++			output = realloc(output, max *= 2);
   1.185 ++			if (!output) return NULL;
   1.186 ++		}
   1.187 ++	}
   1.188 ++	if (n < 0) {
   1.189 ++		free(output);
   1.190 ++		return NULL;
   1.191 ++        }
   1.192 ++	return realloc(output, *size);
   1.193 ++}
   1.194 ++
   1.195 ++int lzclose(lzFile file)
   1.196 ++{
   1.197 ++	int status = -1;
   1.198 ++	if (file) {
   1.199 ++		if (file->handlertype == LZ_GZREAD)
   1.200 ++			status = gzclose(file->gzfd);
   1.201 ++		else	status = close(file->fd);
   1.202 ++		free(file);
   1.203 ++	}
   1.204 ++	return status;
   1.205 ++}