X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.fastlz%2Fnative%2Ffastlz_read.c;h=63d1e699ddc39aa3bb12c7626712f358995b4ff9;hb=refs%2Fchanges%2F38%2F238%2F2;hp=50314f2590e195b1df372e3aa4390dc0a02df402;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.fastlz/native/fastlz_read.c b/bundles/org.simantics.fastlz/native/fastlz_read.c index 50314f259..63d1e699d 100644 --- a/bundles/org.simantics.fastlz/native/fastlz_read.c +++ b/bundles/org.simantics.fastlz/native/fastlz_read.c @@ -1,82 +1,82 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -#include -#include -#include -#include "fastlz.h" - -char* uncompressed; -int uncompressedCapacity; -int position; -int uncompressedSize; -char* compressed; -int compressedCapacity; - -FILE* handle; - -void initRead(FILE* _handle) { - uncompressed = 0; - uncompressedCapacity = 0; - position = 0; - uncompressedSize = 0; - compressed = malloc(8); - compressedCapacity = 8; - handle = _handle; -} - -void deinitRead() { - free(uncompressed); - uncompressed = 0; - free(compressed); - compressed = 0; - handle = 0; -} - -void fillBuffer() { - int compressedSize; - - fread(compressed, 8, 1, handle); - compressedSize = ((int*)compressed)[0]; - uncompressedSize = ((int*)compressed)[1]; - - if(compressedSize > compressedCapacity) { - free(compressed); - compressed = malloc(compressedSize); - compressedCapacity = compressedSize; - } - if(uncompressedSize > uncompressedCapacity) { - free(uncompressed); - uncompressed = malloc(uncompressedSize); - uncompressedCapacity = uncompressedSize; - } - - fread(compressed, compressedSize, 1, handle); - printf("decompress %d %d %d %d\n", compressedSize, compressedCapacity, uncompressedSize, uncompressedCapacity); fflush(stdout); - fastlz_decompress(compressed, compressedSize, uncompressed, uncompressedSize); - position = 0; -} - -void read(char* data, int offset, int length) { - int s; - - while(length > uncompressedSize - position) { - s = uncompressedSize - position; - memcpy(data + offset, uncompressed + position, s); - offset += s; - length -= s; - fillBuffer(); - } - memcpy(data + offset, uncompressed + position, length); - position += length; -} - - +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +#include +#include +#include +#include "fastlz.h" + +char* uncompressed; +int uncompressedCapacity; +int position; +int uncompressedSize; +char* compressed; +int compressedCapacity; + +FILE* handle; + +void initRead(FILE* _handle) { + uncompressed = 0; + uncompressedCapacity = 0; + position = 0; + uncompressedSize = 0; + compressed = malloc(8); + compressedCapacity = 8; + handle = _handle; +} + +void deinitRead() { + free(uncompressed); + uncompressed = 0; + free(compressed); + compressed = 0; + handle = 0; +} + +void fillBuffer() { + int compressedSize; + + fread(compressed, 8, 1, handle); + compressedSize = ((int*)compressed)[0]; + uncompressedSize = ((int*)compressed)[1]; + + if(compressedSize > compressedCapacity) { + free(compressed); + compressed = malloc(compressedSize); + compressedCapacity = compressedSize; + } + if(uncompressedSize > uncompressedCapacity) { + free(uncompressed); + uncompressed = malloc(uncompressedSize); + uncompressedCapacity = uncompressedSize; + } + + fread(compressed, compressedSize, 1, handle); + printf("decompress %d %d %d %d\n", compressedSize, compressedCapacity, uncompressedSize, uncompressedCapacity); fflush(stdout); + fastlz_decompress(compressed, compressedSize, uncompressed, uncompressedSize); + position = 0; +} + +void read(char* data, int offset, int length) { + int s; + + while(length > uncompressedSize - position) { + s = uncompressedSize - position; + memcpy(data + offset, uncompressed + position, s); + offset += s; + length -= s; + fillBuffer(); + } + memcpy(data + offset, uncompressed + position, length); + position += length; +} + +