| author | ecalot
<ecalot> 2004-06-12 01:56:46 UTC |
| committer | ecalot
<ecalot> 2004-06-12 01:56:46 UTC |
| parent | 51b70f5219e6f6d5fd841843038b5f8b1407b05c |
| PR/src/console/main.c | +18 | -1 |
| PR/src/lib/actions/classify.c | +1 | -1 |
| PR/src/lib/compression/rle_compress.c | +30 | -20 |
| PR/src/lib/compression/rle_decompress.c | +30 | -20 |
| PR/src/lib/compression/rlev_decompress.c | +30 | -20 |
| PR/src/lib/layers/dat.c | +2 | -2 |
| PR/src/lib/layers/disk.c | +26 | -5 |
| PR/src/lib/layers/memory.c | +117 | -1 |
| PR/src/lib/object/image/image16.c | +30 | -20 |
| PR/src/lib/object/image/image2.c | +30 | -20 |
| PR/src/lib/object/image/image256.c | +30 | -20 |
| PR/src/lib/object/image/image_common.c | +30 | -20 |
| PR/src/lib/pr.c | +18 | -1 |
diff --git a/PR/src/console/main.c b/PR/src/console/main.c index 2390b8a..7180321 100644 --- a/PR/src/console/main.c +++ b/PR/src/console/main.c @@ -77,6 +77,21 @@ pr.c: Main source file for Princed Resources | Main working functions | \***************************************************************/ +#ifdef MEM_CHECK + +char* strallocandcopy(const char* text) { + int size; + char* aux; + if (text==NULL) return NULL; + size=strlen(text)+1; + aux=(char*)malloc(size); + if (aux) memcpy(aux,text,size); + return aux; +} + +#endif + + FILE* outputStream=NULL; #ifdef DLL @@ -470,7 +485,9 @@ int main (int argc, char **argv) { freeAllocation(datFilePath); freeAllocation(extension); freeAllocation(resFile); - +#ifdef MEM_CHECK + showStats(); +#endif return 0; } diff --git a/PR/src/lib/actions/classify.c b/PR/src/lib/actions/classify.c index 31a9d50..9c3212e 100644 --- a/PR/src/lib/actions/classify.c +++ b/PR/src/lib/actions/classify.c @@ -63,7 +63,7 @@ int prVerifyDatType(const char* vFiledat) { /* main loop */ for (indexNumber=0;(indexNumber<numberOfItems)&&(type==RES_TYPE_BINARY);indexNumber++) { - id=mReadGetFileInDatFile(indexNumber,&data,&size); + id=mReadFileInDatFile(indexNumber,&data,&size); if (id<0) READ_ERROR; /* Read error */ if (id==0xFFFF) continue; /* Tammo Jan Bug fix */ if (id>=MAX_RES_COUNT) READ_ERROR; /* A file with an ID out of range will be treated as invalid */ diff --git a/PR/src/lib/compression/rle_compress.c b/PR/src/lib/compression/rle_compress.c index 1b2680e..44eebf0 100644 --- a/PR/src/lib/compression/rle_compress.c +++ b/PR/src/lib/compression/rle_compress.c @@ -32,15 +32,16 @@ compress.c: Princed Resources : Image Compression Library DO NOT remove this copyright notice */ -/***************************************************************\ -| I M P L E M E N T A T I O N | -\***************************************************************/ - #include <stdio.h> #include <string.h> #include "compress.h" #include "memory.h" #include "pr.h" +#include "disk.h" /* array2short */ + +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ /***************************************************************\ | Image transpose | @@ -186,8 +187,8 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; - *(cursorData++)=*(cursorPix); - *dataSize=(int)((long int)cursorData-(long int)data)-2; /* Note: casted to long for portability with 64 bits architectures */ + *(cursorData)=*(cursorPix); + *dataSize=(int)((long int)cursorData-(long int)data)-1; /* Note: casted to long for portability with 64 bits architectures */ } /***************************************************************\ @@ -212,15 +213,21 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) int imageSizeInBytes; int result; +printf("+K) %d:%d:%d:%d:%d:%d\n",data[0],data[1],data[2],data[3],data[4],data[5]); data++; - image->height=((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - image->width =((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - - if (*(data++)) return -1; /* Verify format */ + image->height=array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; + image->width =array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; +printf("K) %d;%d\n",image->width,image->height); + +fld("XX"); + if (*(data++)) return COMPRESS_RESULT_FATAL; /* Verify format */ +fld("YY"); image->type=(unsigned char)(*(data++)); dataSizeInBytes-=7; - +printf("K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); if (image->type&0xB0) { image->widthInBytes=(image->width+1)/2; } else { @@ -254,11 +261,12 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) result=COMPRESS_RESULT_FATAL; break; } +printf("-K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); return result; /* Ok */ } /* Compress an image into binary data */ -int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { +int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { /* Declare variables */ unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; int compressedSize [COMPRESS_WORKING_ALGORITHMS]; @@ -279,7 +287,7 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { memcpy(compressed[COMPRESS_RAW],image->pix,compressedSize[COMPRESS_RAW]); /* COMPRESS_RLE_LR */ - compressed[COMPRESS_RLE_LR]=getMemory(10*imageSizeInBytes+50); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ + compressed[COMPRESS_RLE_LR]=getMemory((10*imageSizeInBytes+50)); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ compressRle(compressed[COMPRESS_RLE_LR],image,&(compressedSize[COMPRESS_RLE_LR])); /* COMPRESS_RLE_UD */ @@ -302,7 +310,8 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { } /* Copy the best algorithm in the compressed data */ - memcpy(data+6,compressed[algorithm],*dataSizeInBytes); + *data=getMemory(*dataSizeInBytes+6); + memcpy(*data+6,compressed[algorithm],*dataSizeInBytes); (*dataSizeInBytes)+=6; /* @@ -310,16 +319,17 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { */ /* (16 bits)height (Intel short int format) */ - data[0]=image->height; - data[1]=image->height>>8; + (*data)[0]=image->height; + (*data)[1]=image->height>>8; /* (16 bits)width (Intel short int format) */ - data[2]=image->width; - data[3]=image->width>>8; + (*data)[2]=image->width; + (*data)[3]=image->width>>8; /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ - data[4]=0; - data[5]=image->type|algorithm; + (*data)[4]=0; + (*data)[5]=image->type|algorithm; /* Free all compression attempts */ for (i=COMPRESS_RAW;i<COMPRESS_WORKING_ALGORITHMS;i++) free(compressed[i]); return 1; } + diff --git a/PR/src/lib/compression/rle_decompress.c b/PR/src/lib/compression/rle_decompress.c index 1b2680e..44eebf0 100644 --- a/PR/src/lib/compression/rle_decompress.c +++ b/PR/src/lib/compression/rle_decompress.c @@ -32,15 +32,16 @@ compress.c: Princed Resources : Image Compression Library DO NOT remove this copyright notice */ -/***************************************************************\ -| I M P L E M E N T A T I O N | -\***************************************************************/ - #include <stdio.h> #include <string.h> #include "compress.h" #include "memory.h" #include "pr.h" +#include "disk.h" /* array2short */ + +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ /***************************************************************\ | Image transpose | @@ -186,8 +187,8 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; - *(cursorData++)=*(cursorPix); - *dataSize=(int)((long int)cursorData-(long int)data)-2; /* Note: casted to long for portability with 64 bits architectures */ + *(cursorData)=*(cursorPix); + *dataSize=(int)((long int)cursorData-(long int)data)-1; /* Note: casted to long for portability with 64 bits architectures */ } /***************************************************************\ @@ -212,15 +213,21 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) int imageSizeInBytes; int result; +printf("+K) %d:%d:%d:%d:%d:%d\n",data[0],data[1],data[2],data[3],data[4],data[5]); data++; - image->height=((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - image->width =((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - - if (*(data++)) return -1; /* Verify format */ + image->height=array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; + image->width =array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; +printf("K) %d;%d\n",image->width,image->height); + +fld("XX"); + if (*(data++)) return COMPRESS_RESULT_FATAL; /* Verify format */ +fld("YY"); image->type=(unsigned char)(*(data++)); dataSizeInBytes-=7; - +printf("K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); if (image->type&0xB0) { image->widthInBytes=(image->width+1)/2; } else { @@ -254,11 +261,12 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) result=COMPRESS_RESULT_FATAL; break; } +printf("-K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); return result; /* Ok */ } /* Compress an image into binary data */ -int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { +int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { /* Declare variables */ unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; int compressedSize [COMPRESS_WORKING_ALGORITHMS]; @@ -279,7 +287,7 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { memcpy(compressed[COMPRESS_RAW],image->pix,compressedSize[COMPRESS_RAW]); /* COMPRESS_RLE_LR */ - compressed[COMPRESS_RLE_LR]=getMemory(10*imageSizeInBytes+50); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ + compressed[COMPRESS_RLE_LR]=getMemory((10*imageSizeInBytes+50)); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ compressRle(compressed[COMPRESS_RLE_LR],image,&(compressedSize[COMPRESS_RLE_LR])); /* COMPRESS_RLE_UD */ @@ -302,7 +310,8 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { } /* Copy the best algorithm in the compressed data */ - memcpy(data+6,compressed[algorithm],*dataSizeInBytes); + *data=getMemory(*dataSizeInBytes+6); + memcpy(*data+6,compressed[algorithm],*dataSizeInBytes); (*dataSizeInBytes)+=6; /* @@ -310,16 +319,17 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { */ /* (16 bits)height (Intel short int format) */ - data[0]=image->height; - data[1]=image->height>>8; + (*data)[0]=image->height; + (*data)[1]=image->height>>8; /* (16 bits)width (Intel short int format) */ - data[2]=image->width; - data[3]=image->width>>8; + (*data)[2]=image->width; + (*data)[3]=image->width>>8; /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ - data[4]=0; - data[5]=image->type|algorithm; + (*data)[4]=0; + (*data)[5]=image->type|algorithm; /* Free all compression attempts */ for (i=COMPRESS_RAW;i<COMPRESS_WORKING_ALGORITHMS;i++) free(compressed[i]); return 1; } + diff --git a/PR/src/lib/compression/rlev_decompress.c b/PR/src/lib/compression/rlev_decompress.c index 1b2680e..44eebf0 100644 --- a/PR/src/lib/compression/rlev_decompress.c +++ b/PR/src/lib/compression/rlev_decompress.c @@ -32,15 +32,16 @@ compress.c: Princed Resources : Image Compression Library DO NOT remove this copyright notice */ -/***************************************************************\ -| I M P L E M E N T A T I O N | -\***************************************************************/ - #include <stdio.h> #include <string.h> #include "compress.h" #include "memory.h" #include "pr.h" +#include "disk.h" /* array2short */ + +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ /***************************************************************\ | Image transpose | @@ -186,8 +187,8 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; - *(cursorData++)=*(cursorPix); - *dataSize=(int)((long int)cursorData-(long int)data)-2; /* Note: casted to long for portability with 64 bits architectures */ + *(cursorData)=*(cursorPix); + *dataSize=(int)((long int)cursorData-(long int)data)-1; /* Note: casted to long for portability with 64 bits architectures */ } /***************************************************************\ @@ -212,15 +213,21 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) int imageSizeInBytes; int result; +printf("+K) %d:%d:%d:%d:%d:%d\n",data[0],data[1],data[2],data[3],data[4],data[5]); data++; - image->height=((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - image->width =((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - - if (*(data++)) return -1; /* Verify format */ + image->height=array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; + image->width =array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; +printf("K) %d;%d\n",image->width,image->height); + +fld("XX"); + if (*(data++)) return COMPRESS_RESULT_FATAL; /* Verify format */ +fld("YY"); image->type=(unsigned char)(*(data++)); dataSizeInBytes-=7; - +printf("K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); if (image->type&0xB0) { image->widthInBytes=(image->width+1)/2; } else { @@ -254,11 +261,12 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) result=COMPRESS_RESULT_FATAL; break; } +printf("-K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); return result; /* Ok */ } /* Compress an image into binary data */ -int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { +int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { /* Declare variables */ unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; int compressedSize [COMPRESS_WORKING_ALGORITHMS]; @@ -279,7 +287,7 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { memcpy(compressed[COMPRESS_RAW],image->pix,compressedSize[COMPRESS_RAW]); /* COMPRESS_RLE_LR */ - compressed[COMPRESS_RLE_LR]=getMemory(10*imageSizeInBytes+50); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ + compressed[COMPRESS_RLE_LR]=getMemory((10*imageSizeInBytes+50)); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ compressRle(compressed[COMPRESS_RLE_LR],image,&(compressedSize[COMPRESS_RLE_LR])); /* COMPRESS_RLE_UD */ @@ -302,7 +310,8 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { } /* Copy the best algorithm in the compressed data */ - memcpy(data+6,compressed[algorithm],*dataSizeInBytes); + *data=getMemory(*dataSizeInBytes+6); + memcpy(*data+6,compressed[algorithm],*dataSizeInBytes); (*dataSizeInBytes)+=6; /* @@ -310,16 +319,17 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { */ /* (16 bits)height (Intel short int format) */ - data[0]=image->height; - data[1]=image->height>>8; + (*data)[0]=image->height; + (*data)[1]=image->height>>8; /* (16 bits)width (Intel short int format) */ - data[2]=image->width; - data[3]=image->width>>8; + (*data)[2]=image->width; + (*data)[3]=image->width>>8; /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ - data[4]=0; - data[5]=image->type|algorithm; + (*data)[4]=0; + (*data)[5]=image->type|algorithm; /* Free all compression attempts */ for (i=COMPRESS_RAW;i<COMPRESS_WORKING_ALGORITHMS;i++) free(compressed[i]); return 1; } + diff --git a/PR/src/lib/layers/dat.c b/PR/src/lib/layers/dat.c index cb056e5..f73034c 100644 --- a/PR/src/lib/layers/dat.c +++ b/PR/src/lib/layers/dat.c @@ -35,9 +35,9 @@ dat.c: Princed Resources : DAT library #include <string.h> #include "pr.h" -#include "resources.h" +//#include "resources.h" #include "disk.h" -#include "memory.h" +//#include "memory.h" #include "dat.h" /***************************************************************\ diff --git a/PR/src/lib/layers/disk.c b/PR/src/lib/layers/disk.c index bd51e42..218cb4d 100644 --- a/PR/src/lib/layers/disk.c +++ b/PR/src/lib/layers/disk.c @@ -45,12 +45,11 @@ disk.c: Princed Resources : Disk Access & File handling functions #include <sys/types.h> #include <sys/stat.h> -extern FILE* outputStream; + #ifdef UNIX #define defmkdir(a) mkdir (a,(mode_t)0755) #include <dirent.h> #include <termios.h> - /*#include <curses.h>*/ #include <unistd.h> #include <fcntl.h> #define osIndepGetCharacter() getchar() @@ -62,6 +61,8 @@ extern FILE* outputStream; #define osIndepGetCharacter() getche() #endif +extern FILE* outputStream; + /***************************************************************\ | Disk Access & File handling functions | \***************************************************************/ @@ -70,6 +71,7 @@ extern FILE* outputStream; const char *repairFolders(const char* a) { int i,k; static char result[MAX_FILENAME_SIZE]; +fld("rf1"); for (i=0,k=0;a[i]&&(k<MAX_FILENAME_SIZE);) { if (isDirSep(a,i)) { @@ -82,7 +84,9 @@ const char *repairFolders(const char* a) { } k++; } +fld("rf2"); result[k]=0; +fld("rf3"); return result; } @@ -129,15 +133,21 @@ void addFileToOpenFilesList(const char* fileName,int hasBackup) { */ tOpenFiles* newNode; +fld("h1"); /* Create the new node and fill in the fields */ newNode=(tOpenFiles*)malloc(sizeof(tOpenFiles)); newNode->next=openFilesList; newNode->name=strallocandcopy(fileName); +fld("h2"); if (hasBackup) { +fld("h3"); newNode->size=mLoadFileArray(fileName,&(newNode->content)); +fld("h3"); } else { +fld("h4"); newNode->size=0; +fld("h4"); } openFilesList=newNode; } @@ -230,7 +240,7 @@ int writeOpen(const char* vFileext, FILE* *fp, int optionflag) { whatIs fileType; static int all=0; int result; - +fld("g1"); #ifdef UNIX #ifndef IGNORE_TERM_CHANGE /* This will eliminate the enter after the input */ @@ -243,6 +253,7 @@ int writeOpen(const char* vFileext, FILE* *fp, int optionflag) { tcsetattr (STDIN_FILENO, TCSANOW, &term); #endif #endif +fld("g2"); /* Create base directory and save file */ file=repairFolders(vFileext); @@ -250,6 +261,7 @@ int writeOpen(const char* vFileext, FILE* *fp, int optionflag) { /* Verify if file already exists. */ fileType=isDir(vFileext); if (fileType==eDirectory) return 0; +fld("g3"); if (fileType==eFile) { /* File exists. We need to ask */ @@ -264,6 +276,7 @@ int writeOpen(const char* vFileext, FILE* *fp, int optionflag) { } else { makebase(file); } +fld("g4"); #ifdef UNIX #ifndef IGNORE_TERM_CHANGE @@ -276,9 +289,12 @@ int writeOpen(const char* vFileext, FILE* *fp, int optionflag) { If the file exists, we need to remember the old content in memory if not, we need to know the name in case we need to delete it */ +fld("g5"); addFileToOpenFilesList(file,hasFlag(backup_flag)); +fld("g6"); if ((result=((*fp=fopen(file,"wb"))!=NULL))) addPointerToOpenFilesList(*fp); +fld("g7"); return result; } @@ -304,12 +320,16 @@ int writeData(const unsigned char* data, int ignoreChars, char* vFileext, int si /* Verify parameters */ size-=ignoreChars; - if (size<=0) return 0; + if (size<0) return 0; + //if (size==0) return 1; /* Wrote 0 bytes */ /* Save file */ ok=writeOpen(vFileext,&target,optionflag); - ok=ok&&fwrite(data+ignoreChars,size,1,target); +printf("x->%d\n",ok); + ok=ok&&((!size)||fwrite(data+ignoreChars,size,1,target)); +printf("x->%d\n",ok); ok=ok&&(!writeCloseOk(target,optionflag,backupExtension)); +printf("x->%d\n",ok); return ok; } @@ -325,6 +345,7 @@ int mLoadFileArray(const char* vFile,unsigned char** array) { int aux; /* Open the file */ + fp=fopen(repairFolders(vFile),"rb"); if ((fp=fopen(repairFolders(vFile),"rb"))==NULL) { return 0; } else { diff --git a/PR/src/lib/layers/memory.c b/PR/src/lib/layers/memory.c index ce89ee0..a613cca 100644 --- a/PR/src/lib/layers/memory.c +++ b/PR/src/lib/layers/memory.c @@ -33,7 +33,8 @@ memory.c: Princed Resources : Memory handling #include "memory.h" #include <string.h> - + +#ifndef MEM_CHECK char* strallocandcopy(const char* text) { int size; char* aux; @@ -43,3 +44,118 @@ char* strallocandcopy(const char* text) { if (aux) memcpy(aux,text,size); return aux; } + + +#else +#include <stdlib.h> +#include <stdio.h> + +typedef struct memm { + struct memm* next; + void* pointer; + char file[30]; + int line; + int size; +}memm; + + +static memm* list=NULL; +static int memcounter=0; +static long int memsize=0; +static long int memsizef=0; + +void* mymalloc(int size,char* fileName,int line) { + memm* nodo; + void* p; + p=malloc(size); + nodo=malloc(sizeof(memm)); + nodo->next=list; + list=nodo; + strcpy(nodo->file,fileName); + nodo->line=line; + nodo->size=size; + nodo->pointer=p; + //if (!(memcounter%100)) + //fprintf(stderr,"Memory allocation: %d bytes at %p in %d@%s (%d/%d)\n",size,p,line,fileName,memsize,memcounter); + memcounter++; + memsize+=size; + memsizef+=size; + return p; +} + +void myfree(void* a,char* fileName,int line) { + memm* currentNode; + memm* priorNode=NULL; + memcounter--; + //if ((!(memcounter%100))||((memcounter<100)&&(memcounter>-100))) + //fprintf(stderr,"Liberando memoria? -> %p (%d/%d)\n",a,memsize,memcounter); + + + free(a); + + if (list==NULL) { + fprintf(stderr,"Error!!!! se pidio liberar %p pero no estaba alocado (lista vacia)\n",a); + return; /* Empty list */ + } + currentNode=list; + while ((currentNode->pointer!=a)&&(currentNode->next!=NULL)) { + priorNode=currentNode; + currentNode=currentNode->next; + } + if (currentNode->pointer!=a) { + fprintf(stderr,"Error!!!! se pidio liberar %p pero no estaba alocado %d@%s\n",a,line,fileName); + return; /* Not found */ + } + + memsizef-=currentNode->size; + + //fprintf(stderr,"Liberada: %d bytes at %p alloc: %d@%s | free %d@%s (%d/%d)\n",currentNode->size,currentNode->pointer,currentNode->line,currentNode->file,line,fileName,memsize,memcounter); + + /* free node and set prior pointer to the next */ + if (priorNode==NULL) { + list=currentNode->next; + } else { + priorNode->next=currentNode->next; + } + free(currentNode); + +} + +void showInfo(void* a) { + memm* currentNode; + memm* priorNode=NULL; + + if (list==NULL) { + fprintf(stderr,"lista vacia\n"); + return; /* Empty list */ + } + currentNode=list; + while ((currentNode->pointer!=a)&&(currentNode->next!=NULL)) { + priorNode=currentNode; + currentNode=currentNode->next; + } + if (currentNode->pointer!=a) { + fprintf(stderr,"Puntero no alocado\n"); + return; /* Not found */ + } + + fprintf(stderr,"showInfo: %d bytes at %p alloc: %d@%s Mem tot: %d\n",currentNode->size,currentNode->pointer,currentNode->line,currentNode->file,memcounter); + +} + +void showStats() { + fprintf(stderr,"Total de memoria manejada: %d. Allocaciones: %d. Memoria no liberada: %d\n",memsize,memcounter,memsizef); + + memm* currentNode; + if (list==NULL) { + fprintf(stderr,"Todo COOL!!!!!\n"); + return; /* Empty list */ + } + currentNode=list; + do { + fprintf(stderr,"en %s@%d alocaste %d en %p y no los liberaste\n",currentNode->file,currentNode->line,currentNode->size,currentNode->pointer); + currentNode=currentNode->next; + } while (currentNode->next!=NULL); + +} +#endif diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c index 1b2680e..44eebf0 100644 --- a/PR/src/lib/object/image/image16.c +++ b/PR/src/lib/object/image/image16.c @@ -32,15 +32,16 @@ compress.c: Princed Resources : Image Compression Library DO NOT remove this copyright notice */ -/***************************************************************\ -| I M P L E M E N T A T I O N | -\***************************************************************/ - #include <stdio.h> #include <string.h> #include "compress.h" #include "memory.h" #include "pr.h" +#include "disk.h" /* array2short */ + +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ /***************************************************************\ | Image transpose | @@ -186,8 +187,8 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; - *(cursorData++)=*(cursorPix); - *dataSize=(int)((long int)cursorData-(long int)data)-2; /* Note: casted to long for portability with 64 bits architectures */ + *(cursorData)=*(cursorPix); + *dataSize=(int)((long int)cursorData-(long int)data)-1; /* Note: casted to long for portability with 64 bits architectures */ } /***************************************************************\ @@ -212,15 +213,21 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) int imageSizeInBytes; int result; +printf("+K) %d:%d:%d:%d:%d:%d\n",data[0],data[1],data[2],data[3],data[4],data[5]); data++; - image->height=((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - image->width =((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - - if (*(data++)) return -1; /* Verify format */ + image->height=array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; + image->width =array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; +printf("K) %d;%d\n",image->width,image->height); + +fld("XX"); + if (*(data++)) return COMPRESS_RESULT_FATAL; /* Verify format */ +fld("YY"); image->type=(unsigned char)(*(data++)); dataSizeInBytes-=7; - +printf("K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); if (image->type&0xB0) { image->widthInBytes=(image->width+1)/2; } else { @@ -254,11 +261,12 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) result=COMPRESS_RESULT_FATAL; break; } +printf("-K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); return result; /* Ok */ } /* Compress an image into binary data */ -int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { +int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { /* Declare variables */ unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; int compressedSize [COMPRESS_WORKING_ALGORITHMS]; @@ -279,7 +287,7 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { memcpy(compressed[COMPRESS_RAW],image->pix,compressedSize[COMPRESS_RAW]); /* COMPRESS_RLE_LR */ - compressed[COMPRESS_RLE_LR]=getMemory(10*imageSizeInBytes+50); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ + compressed[COMPRESS_RLE_LR]=getMemory((10*imageSizeInBytes+50)); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ compressRle(compressed[COMPRESS_RLE_LR],image,&(compressedSize[COMPRESS_RLE_LR])); /* COMPRESS_RLE_UD */ @@ -302,7 +310,8 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { } /* Copy the best algorithm in the compressed data */ - memcpy(data+6,compressed[algorithm],*dataSizeInBytes); + *data=getMemory(*dataSizeInBytes+6); + memcpy(*data+6,compressed[algorithm],*dataSizeInBytes); (*dataSizeInBytes)+=6; /* @@ -310,16 +319,17 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { */ /* (16 bits)height (Intel short int format) */ - data[0]=image->height; - data[1]=image->height>>8; + (*data)[0]=image->height; + (*data)[1]=image->height>>8; /* (16 bits)width (Intel short int format) */ - data[2]=image->width; - data[3]=image->width>>8; + (*data)[2]=image->width; + (*data)[3]=image->width>>8; /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ - data[4]=0; - data[5]=image->type|algorithm; + (*data)[4]=0; + (*data)[5]=image->type|algorithm; /* Free all compression attempts */ for (i=COMPRESS_RAW;i<COMPRESS_WORKING_ALGORITHMS;i++) free(compressed[i]); return 1; } + diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c index 1b2680e..44eebf0 100644 --- a/PR/src/lib/object/image/image2.c +++ b/PR/src/lib/object/image/image2.c @@ -32,15 +32,16 @@ compress.c: Princed Resources : Image Compression Library DO NOT remove this copyright notice */ -/***************************************************************\ -| I M P L E M E N T A T I O N | -\***************************************************************/ - #include <stdio.h> #include <string.h> #include "compress.h" #include "memory.h" #include "pr.h" +#include "disk.h" /* array2short */ + +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ /***************************************************************\ | Image transpose | @@ -186,8 +187,8 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; - *(cursorData++)=*(cursorPix); - *dataSize=(int)((long int)cursorData-(long int)data)-2; /* Note: casted to long for portability with 64 bits architectures */ + *(cursorData)=*(cursorPix); + *dataSize=(int)((long int)cursorData-(long int)data)-1; /* Note: casted to long for portability with 64 bits architectures */ } /***************************************************************\ @@ -212,15 +213,21 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) int imageSizeInBytes; int result; +printf("+K) %d:%d:%d:%d:%d:%d\n",data[0],data[1],data[2],data[3],data[4],data[5]); data++; - image->height=((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - image->width =((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - - if (*(data++)) return -1; /* Verify format */ + image->height=array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; + image->width =array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; +printf("K) %d;%d\n",image->width,image->height); + +fld("XX"); + if (*(data++)) return COMPRESS_RESULT_FATAL; /* Verify format */ +fld("YY"); image->type=(unsigned char)(*(data++)); dataSizeInBytes-=7; - +printf("K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); if (image->type&0xB0) { image->widthInBytes=(image->width+1)/2; } else { @@ -254,11 +261,12 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) result=COMPRESS_RESULT_FATAL; break; } +printf("-K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); return result; /* Ok */ } /* Compress an image into binary data */ -int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { +int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { /* Declare variables */ unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; int compressedSize [COMPRESS_WORKING_ALGORITHMS]; @@ -279,7 +287,7 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { memcpy(compressed[COMPRESS_RAW],image->pix,compressedSize[COMPRESS_RAW]); /* COMPRESS_RLE_LR */ - compressed[COMPRESS_RLE_LR]=getMemory(10*imageSizeInBytes+50); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ + compressed[COMPRESS_RLE_LR]=getMemory((10*imageSizeInBytes+50)); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ compressRle(compressed[COMPRESS_RLE_LR],image,&(compressedSize[COMPRESS_RLE_LR])); /* COMPRESS_RLE_UD */ @@ -302,7 +310,8 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { } /* Copy the best algorithm in the compressed data */ - memcpy(data+6,compressed[algorithm],*dataSizeInBytes); + *data=getMemory(*dataSizeInBytes+6); + memcpy(*data+6,compressed[algorithm],*dataSizeInBytes); (*dataSizeInBytes)+=6; /* @@ -310,16 +319,17 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { */ /* (16 bits)height (Intel short int format) */ - data[0]=image->height; - data[1]=image->height>>8; + (*data)[0]=image->height; + (*data)[1]=image->height>>8; /* (16 bits)width (Intel short int format) */ - data[2]=image->width; - data[3]=image->width>>8; + (*data)[2]=image->width; + (*data)[3]=image->width>>8; /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ - data[4]=0; - data[5]=image->type|algorithm; + (*data)[4]=0; + (*data)[5]=image->type|algorithm; /* Free all compression attempts */ for (i=COMPRESS_RAW;i<COMPRESS_WORKING_ALGORITHMS;i++) free(compressed[i]); return 1; } + diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c index 1b2680e..44eebf0 100644 --- a/PR/src/lib/object/image/image256.c +++ b/PR/src/lib/object/image/image256.c @@ -32,15 +32,16 @@ compress.c: Princed Resources : Image Compression Library DO NOT remove this copyright notice */ -/***************************************************************\ -| I M P L E M E N T A T I O N | -\***************************************************************/ - #include <stdio.h> #include <string.h> #include "compress.h" #include "memory.h" #include "pr.h" +#include "disk.h" /* array2short */ + +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ /***************************************************************\ | Image transpose | @@ -186,8 +187,8 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; - *(cursorData++)=*(cursorPix); - *dataSize=(int)((long int)cursorData-(long int)data)-2; /* Note: casted to long for portability with 64 bits architectures */ + *(cursorData)=*(cursorPix); + *dataSize=(int)((long int)cursorData-(long int)data)-1; /* Note: casted to long for portability with 64 bits architectures */ } /***************************************************************\ @@ -212,15 +213,21 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) int imageSizeInBytes; int result; +printf("+K) %d:%d:%d:%d:%d:%d\n",data[0],data[1],data[2],data[3],data[4],data[5]); data++; - image->height=((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - image->width =((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - - if (*(data++)) return -1; /* Verify format */ + image->height=array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; + image->width =array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; +printf("K) %d;%d\n",image->width,image->height); + +fld("XX"); + if (*(data++)) return COMPRESS_RESULT_FATAL; /* Verify format */ +fld("YY"); image->type=(unsigned char)(*(data++)); dataSizeInBytes-=7; - +printf("K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); if (image->type&0xB0) { image->widthInBytes=(image->width+1)/2; } else { @@ -254,11 +261,12 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) result=COMPRESS_RESULT_FATAL; break; } +printf("-K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); return result; /* Ok */ } /* Compress an image into binary data */ -int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { +int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { /* Declare variables */ unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; int compressedSize [COMPRESS_WORKING_ALGORITHMS]; @@ -279,7 +287,7 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { memcpy(compressed[COMPRESS_RAW],image->pix,compressedSize[COMPRESS_RAW]); /* COMPRESS_RLE_LR */ - compressed[COMPRESS_RLE_LR]=getMemory(10*imageSizeInBytes+50); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ + compressed[COMPRESS_RLE_LR]=getMemory((10*imageSizeInBytes+50)); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ compressRle(compressed[COMPRESS_RLE_LR],image,&(compressedSize[COMPRESS_RLE_LR])); /* COMPRESS_RLE_UD */ @@ -302,7 +310,8 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { } /* Copy the best algorithm in the compressed data */ - memcpy(data+6,compressed[algorithm],*dataSizeInBytes); + *data=getMemory(*dataSizeInBytes+6); + memcpy(*data+6,compressed[algorithm],*dataSizeInBytes); (*dataSizeInBytes)+=6; /* @@ -310,16 +319,17 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { */ /* (16 bits)height (Intel short int format) */ - data[0]=image->height; - data[1]=image->height>>8; + (*data)[0]=image->height; + (*data)[1]=image->height>>8; /* (16 bits)width (Intel short int format) */ - data[2]=image->width; - data[3]=image->width>>8; + (*data)[2]=image->width; + (*data)[3]=image->width>>8; /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ - data[4]=0; - data[5]=image->type|algorithm; + (*data)[4]=0; + (*data)[5]=image->type|algorithm; /* Free all compression attempts */ for (i=COMPRESS_RAW;i<COMPRESS_WORKING_ALGORITHMS;i++) free(compressed[i]); return 1; } + diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c index 1b2680e..44eebf0 100644 --- a/PR/src/lib/object/image/image_common.c +++ b/PR/src/lib/object/image/image_common.c @@ -32,15 +32,16 @@ compress.c: Princed Resources : Image Compression Library DO NOT remove this copyright notice */ -/***************************************************************\ -| I M P L E M E N T A T I O N | -\***************************************************************/ - #include <stdio.h> #include <string.h> #include "compress.h" #include "memory.h" #include "pr.h" +#include "disk.h" /* array2short */ + +/***************************************************************\ +| I M P L E M E N T A T I O N | +\***************************************************************/ /***************************************************************\ | Image transpose | @@ -186,8 +187,8 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; - *(cursorData++)=*(cursorPix); - *dataSize=(int)((long int)cursorData-(long int)data)-2; /* Note: casted to long for portability with 64 bits architectures */ + *(cursorData)=*(cursorPix); + *dataSize=(int)((long int)cursorData-(long int)data)-1; /* Note: casted to long for portability with 64 bits architectures */ } /***************************************************************\ @@ -212,15 +213,21 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) int imageSizeInBytes; int result; +printf("+K) %d:%d:%d:%d:%d:%d\n",data[0],data[1],data[2],data[3],data[4],data[5]); data++; - image->height=((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - image->width =((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; - - if (*(data++)) return -1; /* Verify format */ + image->height=array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; + image->width =array2short(data);//((unsigned char)data[0])+((unsigned char)data[1]<<8);data+=2; + data+=2; +printf("K) %d;%d\n",image->width,image->height); + +fld("XX"); + if (*(data++)) return COMPRESS_RESULT_FATAL; /* Verify format */ +fld("YY"); image->type=(unsigned char)(*(data++)); dataSizeInBytes-=7; - +printf("K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); if (image->type&0xB0) { image->widthInBytes=(image->width+1)/2; } else { @@ -254,11 +261,12 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes) result=COMPRESS_RESULT_FATAL; break; } +printf("-K) %d+%d*%d,%d\n",image->pix,image->height,image->widthInBytes,image->widthInBytes); return result; /* Ok */ } /* Compress an image into binary data */ -int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { +int mCompressGraphic(unsigned char* *data,tImage* image, int* dataSizeInBytes) { /* Declare variables */ unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; int compressedSize [COMPRESS_WORKING_ALGORITHMS]; @@ -279,7 +287,7 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { memcpy(compressed[COMPRESS_RAW],image->pix,compressedSize[COMPRESS_RAW]); /* COMPRESS_RLE_LR */ - compressed[COMPRESS_RLE_LR]=getMemory(10*imageSizeInBytes+50); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ + compressed[COMPRESS_RLE_LR]=getMemory((10*imageSizeInBytes+50)); /* This will reserve 10*(image size)+50 bytes, to allocate the compressed file */ compressRle(compressed[COMPRESS_RLE_LR],image,&(compressedSize[COMPRESS_RLE_LR])); /* COMPRESS_RLE_UD */ @@ -302,7 +310,8 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { } /* Copy the best algorithm in the compressed data */ - memcpy(data+6,compressed[algorithm],*dataSizeInBytes); + *data=getMemory(*dataSizeInBytes+6); + memcpy(*data+6,compressed[algorithm],*dataSizeInBytes); (*dataSizeInBytes)+=6; /* @@ -310,16 +319,17 @@ int mCompressGraphic(unsigned char* data,tImage* image, int* dataSizeInBytes) { */ /* (16 bits)height (Intel short int format) */ - data[0]=image->height; - data[1]=image->height>>8; + (*data)[0]=image->height; + (*data)[1]=image->height>>8; /* (16 bits)width (Intel short int format) */ - data[2]=image->width; - data[3]=image->width>>8; + (*data)[2]=image->width; + (*data)[3]=image->width>>8; /* (8 bits)00000000+(4 bits)palette type+(4 bits)algorithm */ - data[4]=0; - data[5]=image->type|algorithm; + (*data)[4]=0; + (*data)[5]=image->type|algorithm; /* Free all compression attempts */ for (i=COMPRESS_RAW;i<COMPRESS_WORKING_ALGORITHMS;i++) free(compressed[i]); return 1; } + diff --git a/PR/src/lib/pr.c b/PR/src/lib/pr.c index 2390b8a..7180321 100644 --- a/PR/src/lib/pr.c +++ b/PR/src/lib/pr.c @@ -77,6 +77,21 @@ pr.c: Main source file for Princed Resources | Main working functions | \***************************************************************/ +#ifdef MEM_CHECK + +char* strallocandcopy(const char* text) { + int size; + char* aux; + if (text==NULL) return NULL; + size=strlen(text)+1; + aux=(char*)malloc(size); + if (aux) memcpy(aux,text,size); + return aux; +} + +#endif + + FILE* outputStream=NULL; #ifdef DLL @@ -470,7 +485,9 @@ int main (int argc, char **argv) { freeAllocation(datFilePath); freeAllocation(extension); freeAllocation(resFile); - +#ifdef MEM_CHECK + showStats(); +#endif return 0; }