author | ecalot
<ecalot> 2003-11-04 00:57:24 UTC |
committer | ecalot
<ecalot> 2003-11-04 00:57:24 UTC |
parent | b1c7548303736f8b2581681bcef3bdcf9b47f211 |
PR/src/Makefile | +15 | -2 |
PR/src/console/main.c | +62 | -47 |
PR/src/lib/actions/classify.c | +2 | -4 |
PR/src/lib/actions/export.c | +82 | -37 |
PR/src/lib/actions/import.c | +14 | -27 |
PR/src/lib/compression/rle_compress.c | +67 | -47 |
PR/src/lib/compression/rle_decompress.c | +67 | -47 |
PR/src/lib/compression/rlev_decompress.c | +67 | -47 |
PR/src/lib/layers/autodetect.c | +85 | -106 |
PR/src/lib/layers/idlist.c | +85 | -106 |
PR/src/lib/object/image/image16.c | +67 | -47 |
PR/src/lib/object/image/image2.c | +67 | -47 |
PR/src/lib/object/image/image256.c | +67 | -47 |
PR/src/lib/object/image/image_common.c | +67 | -47 |
PR/src/lib/pr.c | +62 | -47 |
PR/src/lib/xml/tree.c | +85 | -106 |
PR/src/lib/xml/unknown.c | +85 | -106 |
PR/src/pr.dsp | +192 | -1 |
diff --git a/PR/src/Makefile b/PR/src/Makefile index 0230d31..5461334 100644 --- a/PR/src/Makefile +++ b/PR/src/Makefile @@ -1,7 +1,8 @@ -bin/pr: compile.o compress.o extract.o parser.o pr.o resources.o tasks.o bmp.o mid.o pal.o wav.o +bin/pr: compile.o compress.o extract.o parser.o pr.o resources.o tasks.o disk.o xml.o xmlsearch.o bmp.o mid.o pal.o wav.o @echo Linking files... - @gcc -o bin/pr compile.o compress.o extract.o parser.o pr.o resources.o tasks.o bmp.o mid.o pal.o wav.o -s + @mkdir -p bin + @gcc -o bin/pr compile.o compress.o extract.o parser.o pr.o resources.o tasks.o disk.o xml.o xmlsearch.o bmp.o mid.o pal.o wav.o -s @echo Program succesfully compiled @echo @echo Please read readme.txt for syntax information @@ -35,6 +36,18 @@ tasks.o: tasks.c @echo Compiling extra tasks module... @gcc -c tasks.c -Iinclude/ +xml.o: xml.c + @echo Compiling xml parsing module... + @gcc -c xml.c -Iinclude/ + +xmlsearch.o: xmlsearch.c + @echo Compiling xml search features... + @gcc -c xmlsearch.c -Iinclude/ + +disk.o: disk.c + @echo Compiling disk access functions... + @gcc -c disk.c -Iinclude/ + bmp.o: formats/bmp.c @echo Compiling bitmap files support \(bmp\)... @gcc -c formats/bmp.c -Iinclude/ diff --git a/PR/src/console/main.c b/PR/src/console/main.c index d9c048a..73bd541 100644 --- a/PR/src/console/main.c +++ b/PR/src/console/main.c @@ -56,6 +56,7 @@ pr.c: Main source file for Princed Resources #include "bmp.h" #include "memory.h" +#include "disk.h" //functions @@ -76,17 +77,21 @@ int prExportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt) { Return values: 00 Ok - -1 Error accesing the file - -2 Memory error + -1 Error accesing the file DAT + -2 Memory error in extraction -3 Invalid DAT file + -4 XML Parse error + -5 Memory error in parsing + -6 XML Attribute not recognized + -7 XML File not found */ tResource* r[65536]; int a; - parseFile (vResFile,r); + + a=parseFile (vResFile,vDatFile,r); + if (a<0) return a-3; a=extract(vDatFile, vDirName,r,opt); - printf("termine B %d\n",a); - if (!(opt&8)) generateFile(vResFile,r); - printf("termine C %d\n",a); + //if (!(opt&8)) generateFile(vResFile,r); return a; } @@ -101,13 +106,18 @@ int prImportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt) { 1 - read data type Return values: - -1 File couldn't be open for writing + -1 DAT File couldn't be open for writing + -2 XML Parse error + -3 No memory + -4 XML Attribute not recognized + -5 XML File not found 00 File succesfully compiled positive number: number of missing files */ tResource* r[65536]; int a; - parseFile (vResFile,r); + a=parseFile (vResFile,vDatFile,r); + if (a<0) return a-1; a=compile (vDatFile, vDirName,r,opt); generateFile (vResFile,r); return a; @@ -129,7 +139,7 @@ int prClearRes(char* vResFile) { //Main program #ifndef DLL void syntax() { - printf("Syntax:\r\n pr datfile option [extract dir]\r\n\r\nValid options:\r\n -x[rnus] for extract\r\n r: raw extraction\r\n n: don't extract\r\n u: update res file in case there were records\r\n s: don't save res file\r\n -c[r] for compile\r\n r: raw compiling\r\n -d for type\r\n -t to clear the resource file.\r\n"); + printf("Syntax:\r\n pr datfile option [extract dir]\r\n\r\nValid options:\r\n -x[rn] for extract\r\n r: raw extraction\r\n n: don't extract\r\n -c[r] for compile\r\n r: raw compiling\r\n -d for type\r\n"); } int main(int argc, char* argv[]) { @@ -140,13 +150,6 @@ int main(int argc, char* argv[]) { int option; int i; - //bmp vars - char vFileraw[100]; - char vFilebmp[100]; - unsigned char* data; - tImage img; - int size; - #ifdef UNIX if (argc==2) { printf("Content-Type:text/html\n\nRunning as a cgi\n"); @@ -169,26 +172,54 @@ int main(int argc, char* argv[]) { //do selected taskbars switch (argv[2][1]) { case 'e': - case 'x': // file.dat --> files.ext + resource.txt + case 'x': {// file.dat --> extracted files + resource.xml + char array[8][29]={ + "Ok", + "Error accesing the file DAT", /* DAT or extracted */ + "Memory error in extraction", + "Invalid DAT file", + "XML Parse error", + "Memory error in parsing", + "XML Attribute not recognized", + "XML File not found"}; option=1; for (i=2;argv[2][i];i++) { switch (argv[2][i]) { case 'n':option&=0xFE;break; case 'r':option|=0x04;break; - case 'u':option|=0x02;break; - case 's':option|=0x08;break; default:printf("Found invalid option '%c', skiping . . .\r\n",argv[2][i]);break; } } printf("Extracting '%s' to '%s' with %d\r\n",argv[1],dir,option); - printf("Result: %d\r\n",returnValue=prExportDatOpt(argv[1],dir,"resources.txt",(char)option)); - break; - case 'd': // get type of file.dat + returnValue=prExportDatOpt(argv[1],dir,"resources.xml",(char)option); + printf("Result: %s (%d)\r\n",array[-returnValue],returnValue); + } break; + case 'd': {// get type of file.dat + char array[14][65]={ + "Memory error", + "File not found or no access error", + "Not a valid POP1 DAT file", + "Levels file", + "Graphic file with an image in the first valid entry (not common)", + "Waves/Digital sound file", + "Midis file", + "Valid DAT file with Undefined content", + "Graphic file with a palette in the first valid entry (common)", + "PC Speaker dat file", + "\0","\0","\0", + "Pop2 dat files"}; printf("Classifing '%s'\r\n",argv[1]); - printf("Result: %d type\r\n",returnValue=prVerifyDatType(argv[1])); - break; - case 'i': - case 'c': // files.ext + resource.txt --> files.dat + returnValue=prVerifyDatType(argv[1]); + printf("Result: %s (%d)\r\n",array[2+returnValue],returnValue); + } break; + case 'c': { // extracted files + resource.xml --> files.dat + char array[6][39]={ + "File succesfully compiled", + "DAT File couldn't be open for writing", + "XML Parse error", + "No memory", + "XML Attribute not recognized", + "XML File not found"}; option=1; for (i=2;argv[2][i];i++) { switch (argv[2][i]) { @@ -197,29 +228,13 @@ int main(int argc, char* argv[]) { } } printf("Compiling '%s' from '%s' with %d\r\n",argv[1],dir,option); - printf("Result: %d\r\n",returnValue=prImportDatOpt(argv[1],dir,"resources.txt",(char)option)); - break; - case 't': // none --> resource.txt (destroy resource table) - printf("Clearing 'resources.txt'\r\n"); - printf("Result: %d\r\n",returnValue=prClearRes("resources.txt")); - break; - case 'b': // img.bmp --> img.ext - sprintf(vFileraw,"%s%cres%s.raw",dir,DIR_SEPARATOR,argv[1]); - sprintf(vFilebmp,"%s%cres%s.bmp",dir,DIR_SEPARATOR,argv[1]); - - printf("Converting '%s' into '%s'\r\n",vFilebmp,vFileraw); - size=mLoadFileArray(vFilebmp,&data); - if (size && mReadBitMap(&img,data,size)) { - free(data); - mCompressGraphic(data,img,&size); - free(img.pix); - mSaveRaw(vFileraw,data,size); - free(data); + returnValue=prImportDatOpt(argv[1],dir,"resources.xml",(char)option); + if (returnValue>=0) { + printf("Result: %s (%d)\r\n",array[-returnValue],returnValue); } else { - printf("No access to the file\r\n"); - break; + printf("Result: %d files with errors\r\n",returnValue); } - break; + } break; default: syntax(); return -1; diff --git a/PR/src/lib/actions/classify.c b/PR/src/lib/actions/classify.c index 6454784..d25f8c4 100644 --- a/PR/src/lib/actions/classify.c +++ b/PR/src/lib/actions/classify.c @@ -19,8 +19,8 @@ */ /* -compress.c: Princed Resources : Other DAT file handling tasks -\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf +tasks.c: Princed Resources : Other DAT file handling tasks +\xaf\xaf\xaf\xaf\xaf\xaf\xaf Copyright 2003 Princed Development Team Created: 24 Aug 2003 @@ -66,13 +66,11 @@ int prVerifyDatType(char* vFiledat) { ok=ok&& fread(&indexSize,2,1,fp); ok=ok&& !fseek(fp,indexOffset,SEEK_SET); ok=ok&& fread(&numberOfItems,2,1,fp); -// printf("jaaaj %d",ok); if (!ok) { fclose(fp); return 0; //this is not a valid prince dat file } if ((numberOfItems*8+2)!=indexSize) { -// printf("jajaj %d %d\r\n",indexOffset,indexSize); indexOffset+=indexSize; fseek(fp,0,SEEK_END); printf("jaaaj %d %d\r\n",indexOffset,ftell(fp)); diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c index 81d476b..de08f1a 100644 --- a/PR/src/lib/actions/export.c +++ b/PR/src/lib/actions/export.c @@ -32,8 +32,11 @@ extract.c: Princed Resources : DAT Extractor */ #include <stdio.h> + #include "extract.h" +#include "disk.h" #include "memory.h" + #include "bmp.h" #include "wav.h" #include "pal.h" @@ -43,15 +46,8 @@ extract.c: Princed Resources : DAT Extractor | I M P L E M E N T A T I O N | \***************************************************************/ -char writeData(unsigned char* data, int ignoreChars, char* vFileext, int size) { - FILE* target; - char ok; - ok=((target=fopen(vFileext,"wb"))!=NULL); - ok=ok&&fwrite(data+ignoreChars,size-ignoreChars,1,target); - ok=ok&&(!fclose(target)); - return ok; -} + /***************************************************************\ | M A I N E X T R A C T | @@ -76,21 +72,22 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { if (ok=((fp=fopen(vFiledat,"rb"))!=NULL)) { //loop variables - unsigned long int indexOffset; + unsigned long int indexOffset; unsigned short int indexSize,numberOfItems; - unsigned char* index; + unsigned char* index; int ofk=0; - int k; + int k; //if header ok, new variables - unsigned short int id; - unsigned long int size,offset; - unsigned char* data; - char type=0; + //char aux[260]; + //char isntImageSet=1; char recordSize; - char aux[260]; + char type=0; tImage image; //this is used to make a persistent palette - char isntImageSet=1; + unsigned char* data; + unsigned long int size,offset; + unsigned short int id; + unsigned short int paletteId=0; //verify dat format ok = fread(&indexOffset,4,1,fp); @@ -115,7 +112,14 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { ok=fread(index,indexSize-2,1,fp); //parse folder and take dat filename in caps - getUpperFolder(aux,vFiledat); + //getUpperFolder(aux,vFiledat); + + //Initializes the palette list + for (id=0;id<65000;id++) { + if (r[id]!=NULL) { + r[id]->palAux=NULL; + } + } //main loop for (k=0;ok&&(k<numberOfItems);k++) { @@ -131,33 +135,39 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { ok=ok&&fread(data,size,1,fp); if (!ok) return -3; - //For the moment rebuilt option will be mandatory: - task|=2; + //For the moment rebuilt option will be comented +// task|=2; //If rebuild option has been chosen, destroy previous declaration - if ((r[id]!=NULL)&&(task&2)) { - if ((*(r[id])).coms!=NULL) free ((*(r[id])).coms); - if ((*(r[id])).desc!=NULL) free ((*(r[id])).desc); - free(r[id]); - r[id]=NULL; - } +// if ((r[id]!=NULL)&&(task&2)) { +// if ((*(r[id])).coms!=NULL) free ((*(r[id])).coms); +// if ((*(r[id])).path!=NULL) free ((*(r[id])).path); +// free(r[id]); //TODO uncomment this line +// r[id]=NULL; +// } //set resource information on this index entry if (r[id]==NULL) { r[id]=(tResource*)malloc(sizeof(tResource)); + if (r[id]==NULL) return -2; //no memory + r[id]->path=NULL; + r[id]->palAux=NULL; + r[id]->palette=0; (*(r[id])).size=(unsigned short int)size; (*(r[id])).offset=(unsigned short)offset; - sprintf((*(r[id])).file,aux); - (*(r[id])).desc=NULL; - (*(r[id])).coms=NULL; (*(r[id])).type=verifyHeader(data,(unsigned short int)size); + } else { + if (!(r[id]->type)) r[id]->type=verifyHeader(data,(unsigned short int)size); } - if (task&1) { + if (task&1) { //If "extract to file" is set //select type - if (task&4) (*(r[id])).type=0; + if (task&4) (*(r[id])).type=0; //If "extract as raw" is set type is 0 + + //save file - getFileName(vFileext,vDirExt,(*(r[id])).type,id); + getFileName(vFileext,vDirExt,r[id],id,vFiledat); + switch ((*(r[id])).type) { case 1: case 5: @@ -165,13 +175,17 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { ok=ok&&writeData(data,1,vFileext,size); //Ignore checksum break; case 6: //save and remember palette file - //This will remember the palette for the next extacted images - if (1/*isntImageSet*/) { + //This will remember the palette for the next images + r[id]->palAux=(unsigned char*)malloc(size); + memcpy(r[id]->palAux,data,size); + if (!paletteId) { //In case there is no loaded palettes, then load immediately the first found palette to clear garbage mLoadPalette(data,&image); - isntImageSet=0; + paletteId=id; } + //This will extract the palette ok=ok&&mFormatExtractPal(&data,vFileext,size); break; + case 7: //save pcs file case 4: //save midi file ok=ok&&mFormatExtractMid(data,vFileext,size); break; @@ -179,15 +193,46 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { ok=ok&&mFormatExtractWav(data,vFileext,size); break; case 2: //save image + //Palette handling + if (r[id]->palette!=paletteId) { //The palette isn't the already loaded + if (r[id]->palette) { //We need a palette + /* + We need a palette and it is not the palette we have loaded in memory + So a new palette is going to be loaded. + */ + if ((r[r[id]->palette]->palAux)!=NULL) { //If this palette wasn't loaded, it becomes loaded + mLoadPalette(r[r[id]->palette]->palAux,&image); + paletteId=r[id]->palette; //sets the new palette loaded + } + } /*else { + //This image was linked to the default palette + if ((r[paletteId]->palAux)!=NULL) { //If this palette wasn't loaded (practically impossible), it becomes loaded + mLoadPalette(r[paletteId]->palAux,&image); + } + }*/ + } + + //Extract bitmap ok=ok&&mFormatExtractBmp(data,vFileext,size,image); - //printf("sali\n"); break; } } if (data!=NULL) free(data); } fclose(fp); - return ok; + + //Free allocated palettes + for (id=0;id<65000;id++) { + if (r[id]!=NULL) { + if (r[id]->palAux!=NULL) { + free (r[id]->palAux); + } + } + } + + //Close unknownXML + endUnknownXml(); + return ok-1; } else { return -1; //file could not be open } diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index d790985..baf1f4b 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -43,6 +43,7 @@ compile.c: Princed Resources : DAT Compiler #include "wav.h" #include "pal.h" #include "parser.h" +#include "disk.h" /***************************************************************\ | Dat compiling primitives | @@ -65,7 +66,7 @@ void mAddFileToDatFile(FILE* fp, char* data, int size) { int k; for (k=0;k<size;k++) checksum+=data[k]; checksum=~checksum; - //writes the header and the midi sound + //writes the checksum and the data content fwrite(&checksum,1,1,fp); fwrite(data,size,1,fp); } @@ -83,7 +84,7 @@ void mSetEndFile(FILE* fp,int sizeOfIndex) { fclose(fp); } -int mCreateIndexInDatFile(FILE* fp, tResource* r[], char* vUpperFile) { +int mCreateIndexInDatFile(FILE* fp, tResource* r[]) { //Add extra text at the end of the file unsigned short int i=0; unsigned short int junk=0; @@ -92,9 +93,9 @@ int mCreateIndexInDatFile(FILE* fp, tResource* r[], char* vUpperFile) { int pos=ftell(fp); fwrite(&tot,2,1,fp); - for (;i!=65535;i++) { + for (;i!=65000;i++) { //TODO: add define 65000 if (r[i]!=NULL) { - if (equals((*r[i]).file,vUpperFile)) { +// if (equals((*r[i]).file,vUpperFile)) { //the file is in the archive, so I'll add it to the index k+=8; tot++; @@ -102,7 +103,7 @@ int mCreateIndexInDatFile(FILE* fp, tResource* r[], char* vUpperFile) { fwrite(&((*r[i]).offset),2,1,fp); fwrite(&junk,2,1,fp); fwrite(&((*r[i]).size),2,1,fp); - } +// } } } fseek(fp,pos,SEEK_SET); @@ -136,20 +137,7 @@ char mAddCompiledFileToDatFile(FILE* fp,unsigned char** data, tResource *res) { /***************************************************************\ | M A I N F U N C T I O N | \***************************************************************/ -//TODO: delete this function -/* -char mSaveFile(char* vFile,unsigned char *d, int s) { - FILE *fp; - if ((fp=fopen(vFile,"wb"))==NULL) { - return 0; - } else { - fwrite (d,s,1,fp); - fclose(fp); - return 1; - } -} -*/ int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt) { /* Return values: @@ -160,22 +148,21 @@ int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt) { FILE* fp; char vFileext[200]; - char vUpperFile[200]; +// char vUpperFile[200]; int ok=0; unsigned char* data; unsigned short int i=0; if (!mBeginDatFile(&fp,vFiledat)) { -// printf("Error opening the file.\r\n"); - return -1; + return -1; //File couldn't be open } - getUpperFolder(vUpperFile,vFiledat); + //getUpperFolder(vUpperFile,vFiledat); - for (;i!=65535;i++) { + for (;i!=65000;i++) { if (r[i]!=NULL) { - if (equals((*r[i]).file,vUpperFile)) { - getFileName(vFileext,vDirExt,(char)((opt&1)?((*(r[i])).type):0),i); +// if (equals((*r[i]).file,vUpperFile)) { + getFileName(vFileext,vDirExt,r[i],i,vFiledat); //the file is in the archive, so I'll add it to the main dat body if ((*r[i]).size=mLoadFileArray(vFileext,&data)) { (*r[i]).offset=(unsigned short)ftell(fp); @@ -186,9 +173,9 @@ int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt) { } else { ok++; } - } +// } } } - mSetEndFile(fp,mCreateIndexInDatFile(fp,r,vUpperFile)); + mSetEndFile(fp,mCreateIndexInDatFile(fp,r)); return ok; } diff --git a/PR/src/lib/compression/rle_compress.c b/PR/src/lib/compression/rle_compress.c index 54c519e..4ceddb5 100644 --- a/PR/src/lib/compression/rle_compress.c +++ b/PR/src/lib/compression/rle_compress.c @@ -36,6 +36,7 @@ compress.c: Princed Resources : Image Compressor \***************************************************************/ #include <stdio.h> +#include <string.h> #include "compress.h" #include "memory.h" @@ -65,7 +66,6 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { char k; int pos,h; unsigned char maskbyte,rep; -//printf("expandLzx %d %d \n",virtualSize,cursor); for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage while (cursor<virtualSize) { @@ -91,9 +91,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { char* cursorData = data; char* counter; char* cursorPix = (*img).pix; - char* imgEnd = (*img).pix+( - (((*img).width+1)>>1)*(img->height) - ); + char* imgEnd = (*img).pix+(*dataSize); while (cursorPix<imgEnd) { //Step 1: Create counter @@ -113,7 +111,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { cursorPix++; (*counter)--; } - + *(cursorData)=*(cursorPix); //Print repeated char cursorPix++; cursorData++; @@ -121,7 +119,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); - *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures + *dataSize=(int)((long int)cursorData-(long int)data); //Note: casted to long for portability with 64 bits architectures } //Expands an array into an image @@ -204,50 +202,72 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { return i; } -//Compress an image into an array in the most quick & dirty way -int mCompressGraphic(unsigned char* data,tImage i, int* size) { - int dataSize; - //unsigned char* a; -/* - - *size=(i.size/2)+6; - a=getMemory(*size); - //height - 00 - width - 00 - 00 - compression type - a[2]=i.width; - a[3]=i.width>>8; - - a[0]=i.height; - a[1]=i.height>>8; - - a[4]=0; - a[5]=0xB0; // how q&d I am :) - - memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix - */ -////printf("llega 3\n"); - //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file -////printf("llega 3.3\n"); -#if 1 - compressRle(data+6,&i,&dataSize); -//printf("mCompressGraphic: size=%d\n",dataSize); - //a=getMemory(*size=(dataSize+6)); -////printf("llega 4\n"); - /* - Header Settings: - height - 00 - width - 00 - 00 - compression type - */ - data[2]=i.width; - data[3]=i.width>>8; - - data[0]=i.height; - data[1]=i.height>>8; +#define COMPRESS_WORKING_ALGORITHMS 3 + +//Compress an image into an array +int mCompressGraphic(unsigned char* data,tImage* i, int* size) { + //Declare variables + int compressedSize [COMPRESS_WORKING_ALGORITHMS]; + int algorithm; + int cursor; + int virtualsize; + unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; + unsigned char* outputaux; + + //Initialize variables + virtualsize=(((i->width)+1)>>1)*i->height; + outputaux=getMemory(virtualsize); + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) compressedSize[cursor]=virtualsize; + cursor=0; + + //B0 + compressed[0]=getMemory(compressedSize[0]); + memcpy(compressed[0],i->pix,compressedSize[0]); + + //B1 + compressed[1]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + compressRle(compressed[1],i,&(compressedSize[1])); + + //B2 + compressed[2]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + //Transpose + while (cursor<=virtualsize) { + outputaux[cursor]=i->pix[transpose(cursor,i->width,i->height)]; + cursor++; + } + free(i->pix); + i->pix=outputaux; + compressRle(compressed[2],i,&(compressedSize[2])); + + /*Process results*/ + + //Select the best compression (find minimum) + *size=compressedSize[0]; + algorithm=0; + for (cursor=1;cursor<3;cursor++) { + if ((*size)>compressedSize[cursor]) { + (*size)=compressedSize[cursor]; + algorithm=cursor; + } + } + //Copy the best algorithm in the compressed data + memcpy(data+6,compressed[algorithm],*size); + (*size)+=6; + + //Write header + //(16 bits)height (Intel short int format) + data[0]=i->height; + data[1]=i->height>>8; + //(16 bits)width (Intel short int format) + data[2]=i->width; + data[3]=i->width>>8; + //(12 bits)000000001011+(4 bits)algorithm data[4]=0; - data[5]=0xB1; + data[5]=0xB0+algorithm; -*size=(dataSize+6); -////printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + //Free all compression attempts + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) free(compressed[cursor]); -#endif return 1; } diff --git a/PR/src/lib/compression/rle_decompress.c b/PR/src/lib/compression/rle_decompress.c index 54c519e..4ceddb5 100644 --- a/PR/src/lib/compression/rle_decompress.c +++ b/PR/src/lib/compression/rle_decompress.c @@ -36,6 +36,7 @@ compress.c: Princed Resources : Image Compressor \***************************************************************/ #include <stdio.h> +#include <string.h> #include "compress.h" #include "memory.h" @@ -65,7 +66,6 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { char k; int pos,h; unsigned char maskbyte,rep; -//printf("expandLzx %d %d \n",virtualSize,cursor); for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage while (cursor<virtualSize) { @@ -91,9 +91,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { char* cursorData = data; char* counter; char* cursorPix = (*img).pix; - char* imgEnd = (*img).pix+( - (((*img).width+1)>>1)*(img->height) - ); + char* imgEnd = (*img).pix+(*dataSize); while (cursorPix<imgEnd) { //Step 1: Create counter @@ -113,7 +111,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { cursorPix++; (*counter)--; } - + *(cursorData)=*(cursorPix); //Print repeated char cursorPix++; cursorData++; @@ -121,7 +119,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); - *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures + *dataSize=(int)((long int)cursorData-(long int)data); //Note: casted to long for portability with 64 bits architectures } //Expands an array into an image @@ -204,50 +202,72 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { return i; } -//Compress an image into an array in the most quick & dirty way -int mCompressGraphic(unsigned char* data,tImage i, int* size) { - int dataSize; - //unsigned char* a; -/* - - *size=(i.size/2)+6; - a=getMemory(*size); - //height - 00 - width - 00 - 00 - compression type - a[2]=i.width; - a[3]=i.width>>8; - - a[0]=i.height; - a[1]=i.height>>8; - - a[4]=0; - a[5]=0xB0; // how q&d I am :) - - memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix - */ -////printf("llega 3\n"); - //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file -////printf("llega 3.3\n"); -#if 1 - compressRle(data+6,&i,&dataSize); -//printf("mCompressGraphic: size=%d\n",dataSize); - //a=getMemory(*size=(dataSize+6)); -////printf("llega 4\n"); - /* - Header Settings: - height - 00 - width - 00 - 00 - compression type - */ - data[2]=i.width; - data[3]=i.width>>8; - - data[0]=i.height; - data[1]=i.height>>8; +#define COMPRESS_WORKING_ALGORITHMS 3 + +//Compress an image into an array +int mCompressGraphic(unsigned char* data,tImage* i, int* size) { + //Declare variables + int compressedSize [COMPRESS_WORKING_ALGORITHMS]; + int algorithm; + int cursor; + int virtualsize; + unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; + unsigned char* outputaux; + + //Initialize variables + virtualsize=(((i->width)+1)>>1)*i->height; + outputaux=getMemory(virtualsize); + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) compressedSize[cursor]=virtualsize; + cursor=0; + + //B0 + compressed[0]=getMemory(compressedSize[0]); + memcpy(compressed[0],i->pix,compressedSize[0]); + + //B1 + compressed[1]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + compressRle(compressed[1],i,&(compressedSize[1])); + + //B2 + compressed[2]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + //Transpose + while (cursor<=virtualsize) { + outputaux[cursor]=i->pix[transpose(cursor,i->width,i->height)]; + cursor++; + } + free(i->pix); + i->pix=outputaux; + compressRle(compressed[2],i,&(compressedSize[2])); + + /*Process results*/ + + //Select the best compression (find minimum) + *size=compressedSize[0]; + algorithm=0; + for (cursor=1;cursor<3;cursor++) { + if ((*size)>compressedSize[cursor]) { + (*size)=compressedSize[cursor]; + algorithm=cursor; + } + } + //Copy the best algorithm in the compressed data + memcpy(data+6,compressed[algorithm],*size); + (*size)+=6; + + //Write header + //(16 bits)height (Intel short int format) + data[0]=i->height; + data[1]=i->height>>8; + //(16 bits)width (Intel short int format) + data[2]=i->width; + data[3]=i->width>>8; + //(12 bits)000000001011+(4 bits)algorithm data[4]=0; - data[5]=0xB1; + data[5]=0xB0+algorithm; -*size=(dataSize+6); -////printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + //Free all compression attempts + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) free(compressed[cursor]); -#endif return 1; } diff --git a/PR/src/lib/compression/rlev_decompress.c b/PR/src/lib/compression/rlev_decompress.c index 54c519e..4ceddb5 100644 --- a/PR/src/lib/compression/rlev_decompress.c +++ b/PR/src/lib/compression/rlev_decompress.c @@ -36,6 +36,7 @@ compress.c: Princed Resources : Image Compressor \***************************************************************/ #include <stdio.h> +#include <string.h> #include "compress.h" #include "memory.h" @@ -65,7 +66,6 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { char k; int pos,h; unsigned char maskbyte,rep; -//printf("expandLzx %d %d \n",virtualSize,cursor); for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage while (cursor<virtualSize) { @@ -91,9 +91,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { char* cursorData = data; char* counter; char* cursorPix = (*img).pix; - char* imgEnd = (*img).pix+( - (((*img).width+1)>>1)*(img->height) - ); + char* imgEnd = (*img).pix+(*dataSize); while (cursorPix<imgEnd) { //Step 1: Create counter @@ -113,7 +111,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { cursorPix++; (*counter)--; } - + *(cursorData)=*(cursorPix); //Print repeated char cursorPix++; cursorData++; @@ -121,7 +119,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); - *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures + *dataSize=(int)((long int)cursorData-(long int)data); //Note: casted to long for portability with 64 bits architectures } //Expands an array into an image @@ -204,50 +202,72 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { return i; } -//Compress an image into an array in the most quick & dirty way -int mCompressGraphic(unsigned char* data,tImage i, int* size) { - int dataSize; - //unsigned char* a; -/* - - *size=(i.size/2)+6; - a=getMemory(*size); - //height - 00 - width - 00 - 00 - compression type - a[2]=i.width; - a[3]=i.width>>8; - - a[0]=i.height; - a[1]=i.height>>8; - - a[4]=0; - a[5]=0xB0; // how q&d I am :) - - memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix - */ -////printf("llega 3\n"); - //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file -////printf("llega 3.3\n"); -#if 1 - compressRle(data+6,&i,&dataSize); -//printf("mCompressGraphic: size=%d\n",dataSize); - //a=getMemory(*size=(dataSize+6)); -////printf("llega 4\n"); - /* - Header Settings: - height - 00 - width - 00 - 00 - compression type - */ - data[2]=i.width; - data[3]=i.width>>8; - - data[0]=i.height; - data[1]=i.height>>8; +#define COMPRESS_WORKING_ALGORITHMS 3 + +//Compress an image into an array +int mCompressGraphic(unsigned char* data,tImage* i, int* size) { + //Declare variables + int compressedSize [COMPRESS_WORKING_ALGORITHMS]; + int algorithm; + int cursor; + int virtualsize; + unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; + unsigned char* outputaux; + + //Initialize variables + virtualsize=(((i->width)+1)>>1)*i->height; + outputaux=getMemory(virtualsize); + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) compressedSize[cursor]=virtualsize; + cursor=0; + + //B0 + compressed[0]=getMemory(compressedSize[0]); + memcpy(compressed[0],i->pix,compressedSize[0]); + + //B1 + compressed[1]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + compressRle(compressed[1],i,&(compressedSize[1])); + + //B2 + compressed[2]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + //Transpose + while (cursor<=virtualsize) { + outputaux[cursor]=i->pix[transpose(cursor,i->width,i->height)]; + cursor++; + } + free(i->pix); + i->pix=outputaux; + compressRle(compressed[2],i,&(compressedSize[2])); + + /*Process results*/ + + //Select the best compression (find minimum) + *size=compressedSize[0]; + algorithm=0; + for (cursor=1;cursor<3;cursor++) { + if ((*size)>compressedSize[cursor]) { + (*size)=compressedSize[cursor]; + algorithm=cursor; + } + } + //Copy the best algorithm in the compressed data + memcpy(data+6,compressed[algorithm],*size); + (*size)+=6; + + //Write header + //(16 bits)height (Intel short int format) + data[0]=i->height; + data[1]=i->height>>8; + //(16 bits)width (Intel short int format) + data[2]=i->width; + data[3]=i->width>>8; + //(12 bits)000000001011+(4 bits)algorithm data[4]=0; - data[5]=0xB1; + data[5]=0xB0+algorithm; -*size=(dataSize+6); -////printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + //Free all compression attempts + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) free(compressed[cursor]); -#endif return 1; } diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c index 648c736..1d7c120 100644 --- a/PR/src/lib/layers/autodetect.c +++ b/PR/src/lib/layers/autodetect.c @@ -19,8 +19,8 @@ */ /* -compress.c: Princed Resources : Image Compressor -\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf +resources.c: Princed Resources : Resource Handler +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf Copyright 2003 Princed Development Team Created: 24 Aug 2003 @@ -39,7 +39,10 @@ compress.c: Princed Resources : Image Compressor #include <stdio.h> #include <stdlib.h> #include "pr.h" +#include "xml.h" +#include "xmlsearch.h" #include "parser.h" +#include "disk.h" #include "memory.h" #include "resources.h" #include "compress.h" @@ -79,12 +82,19 @@ char verifyWaveHeader(char* array, int size) { ; } +char verifySpeakerHeader(char* array, int size) { + return + (size>1)&&(array[1]==0x00) + ; +} + char verifyHeader(char* array, int size) { if (verifyLevelHeader(array,size)) return 1; if (verifyMidiHeader(array,size)) return 4; if (verifyImageHeader(array,size)) return 2; if (verifyPaletteHeader(array,size)) return 6; if (verifyWaveHeader(array,size)) return 3; + if (verifySpeakerHeader(array,size)) return 7; return 05; } @@ -93,7 +103,7 @@ char verifyHeader(char* array, int size) { | Parsing resource file | \***************************************************************/ - +#if 0 //Parse line void parseResource(tResource* r[], char* line) { //declare variables @@ -125,6 +135,7 @@ void parseResource(tResource* r[], char* line) { (*(r[id])).type=(char)ty; } } +#endif void emptyTable(tResource* r[]) { int i=0; @@ -132,7 +143,21 @@ void emptyTable(tResource* r[]) { } //parse file -char parseFile(char* vFile,tResource* r[]) { +char parseFile(char* vFile, char* datFile, tResource* r[]) { + + tTag* tree; + int error; + + tree=parseXmlFile(vFile,&error); + if (error) return error; + emptyTable(r); + workTree(tree,datFile,r); + freeTagStructure(tree); + + return 0; + +//Old code (will be removed soon) +#if 0 //declare variables char parsing=0; char line[MAX_LINE_SIZE]; @@ -161,10 +186,14 @@ char parseFile(char* vFile,tResource* r[]) { } else { return 0; } +#endif } //generate file char generateFile(char* vFile,tResource* r[]) { + +//Old code (will be removed soon) +#if 0 //declare variables FILE* fp; FILE* source; @@ -176,8 +205,6 @@ char generateFile(char* vFile,tResource* r[]) { char parsing=0; int id=0; -//printf("hola vengo a generar el archivo\n"); - if ((fp=fopen("res.tmp","wt"))!=NULL) { //insert headers if ((source=fopen(vFile,"rt"))!=NULL) { @@ -215,13 +242,16 @@ char generateFile(char* vFile,tResource* r[]) { sprintf(coms," %s#%s",(*(r[id])).desc,(*(r[id])).coms); } } - sprintf(line,"%05d %05d %05d %s %02d%s\n", - id, - (*(r[id])).size, - (*(r[id])).offset, + sprintf(line,"<item itemtype=\"%d\" value=\"%d\" file=\"%s\" external=\"res%05d.bmp\">Res %d</item>\n", + (*(r[id])).type, + id, + //(*(r[id])).size, + //(*(r[id])).offset, (*(r[id])).file, - (*(r[id])).type, - coms); + id,id + //, + //coms + ); fputs(line,fp); } } @@ -242,107 +272,56 @@ char generateFile(char* vFile,tResource* r[]) { } else { return 0; } +#else + //New code ignores this function (resources.xml is read only) + return 1; +#endif } -//Resources extras - -void getFileName(char* vFileext,char* vDirExt,char type, unsigned short int id) { - char extBmp[] = "bmp"; - char extExtra[] = "ext"; - char extLevel[] = "pet"; - char extMidi[] = "mid"; - char extPal[] = "pal"; - char extRaw[] = "raw"; - char extWave[] = "wav"; - char* ext; - - switch (type) { - case 0: - ext=extRaw; - break; - case 1: - ext=extLevel; - break; - case 2: - ext=extBmp; - break; - case 4: - ext=extMidi; - break; - case 3: - ext=extWave; - break; - case 6: - ext=extPal; - break; - default: - ext=extExtra; - break; +//Resources output to xml functions +static FILE* unknownXmlFile=NULL; + +void AddToUnknownXml(const char* vFiledat,unsigned short id,const char* ext,char type,const char* vDirExt,unsigned short pal) { + if (unknownXmlFile==NULL) { + char xmlFile[260]; + sprintf(xmlFile,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_XML,vDirExt,vFiledat); + //Create base dir + repairFolders(xmlFile); + makebase(xmlFile); + + //Open file + if ((unknownXmlFile=fopen(xmlFile,"wt"))==NULL) return; + + //Save headers + if (type==6) pal=id; + fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, + vFiledat,vFiledat,pal + ); } - - //set filename - sprintf(vFileext,"%s%cres%05d.%s",vDirExt,DIR_SEPARATOR,id,ext); -} - -void getUpperFolder(char* aux, char* vFiledat) { - int i=0; - while (getUpperToken(vFiledat,aux,DIR_SEPARATOR,&i,260)); - aux[12]=0; + //TODO: set itemtype in words + fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, + id,id,ext,type,id + ); //To the xml output } -/***************************************************************\ -| File handling functions | -\***************************************************************/ - -int mLoadFileArray(char* vFile,unsigned char** array) { - /* - Using the string in vFile, it opens the file and returns the - number of bytes in it and the content of the file in array. - In case the file couldn't be open or memory allocated returns 0. - */ - - //declare variables - FILE *fp; - int aux; - - //Open the file - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - //get file size - fseek(fp,0,SEEK_END); - aux=ftell(fp); - if ( !aux || (aux>SIZE_OF_FILE) || ( ((*array=(char*)malloc(sizeof(char)*aux))==NULL) ) ) { - //if the file was null or bigger than the max size or couldn't allocate the file in memory - fclose(fp); - return 0; - } else { - //if the filewas succesfully open - fseek(fp,0,SEEK_SET); - aux=fread (*array,1,aux,fp); - fclose(fp); - return aux; - } +void endUnknownXml() { + if (unknownXmlFile!=NULL) { + fprintf(unknownXmlFile,RES_XML_UNKNOWN_END); + fclose(unknownXmlFile); } } -char mSaveRaw(char* vFile,unsigned char* output, int size) { - /* - Using the given string in vFile, it opens the file and saves the - first "size" bytes from the "output" in it. - In case the file couldn't be open or there was no size returns 0, - otherways returns 1. - */ - - FILE * pFile; - - if (!size) { - return 0; - } - if ((pFile = fopen (vFile , "wb"))==NULL) { - return 0; +//Resources extra functions +void getFileName(char* vFileext,char* vDirExt,tResource* r,short id,char* vFiledat) { + static const char extarray[8][4]={"raw","pet","bmp","wav","mid","ext","pal","pcs"}; + const char* ext; + ext=extarray[((r->type<=7)&&(r->type>=0))?r->type:5]; + if (r->path==NULL) { + //set filename + sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vFiledat,id,ext); + AddToUnknownXml(vFiledat,id,ext,r->type,vDirExt,r->palette); + } else { + //set filename + sprintf(vFileext,"%s/%s",vDirExt,r->path); } - fwrite (output, 1, size, pFile); - fclose (pFile); - return 1; } diff --git a/PR/src/lib/layers/idlist.c b/PR/src/lib/layers/idlist.c index 648c736..1d7c120 100644 --- a/PR/src/lib/layers/idlist.c +++ b/PR/src/lib/layers/idlist.c @@ -19,8 +19,8 @@ */ /* -compress.c: Princed Resources : Image Compressor -\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf +resources.c: Princed Resources : Resource Handler +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf Copyright 2003 Princed Development Team Created: 24 Aug 2003 @@ -39,7 +39,10 @@ compress.c: Princed Resources : Image Compressor #include <stdio.h> #include <stdlib.h> #include "pr.h" +#include "xml.h" +#include "xmlsearch.h" #include "parser.h" +#include "disk.h" #include "memory.h" #include "resources.h" #include "compress.h" @@ -79,12 +82,19 @@ char verifyWaveHeader(char* array, int size) { ; } +char verifySpeakerHeader(char* array, int size) { + return + (size>1)&&(array[1]==0x00) + ; +} + char verifyHeader(char* array, int size) { if (verifyLevelHeader(array,size)) return 1; if (verifyMidiHeader(array,size)) return 4; if (verifyImageHeader(array,size)) return 2; if (verifyPaletteHeader(array,size)) return 6; if (verifyWaveHeader(array,size)) return 3; + if (verifySpeakerHeader(array,size)) return 7; return 05; } @@ -93,7 +103,7 @@ char verifyHeader(char* array, int size) { | Parsing resource file | \***************************************************************/ - +#if 0 //Parse line void parseResource(tResource* r[], char* line) { //declare variables @@ -125,6 +135,7 @@ void parseResource(tResource* r[], char* line) { (*(r[id])).type=(char)ty; } } +#endif void emptyTable(tResource* r[]) { int i=0; @@ -132,7 +143,21 @@ void emptyTable(tResource* r[]) { } //parse file -char parseFile(char* vFile,tResource* r[]) { +char parseFile(char* vFile, char* datFile, tResource* r[]) { + + tTag* tree; + int error; + + tree=parseXmlFile(vFile,&error); + if (error) return error; + emptyTable(r); + workTree(tree,datFile,r); + freeTagStructure(tree); + + return 0; + +//Old code (will be removed soon) +#if 0 //declare variables char parsing=0; char line[MAX_LINE_SIZE]; @@ -161,10 +186,14 @@ char parseFile(char* vFile,tResource* r[]) { } else { return 0; } +#endif } //generate file char generateFile(char* vFile,tResource* r[]) { + +//Old code (will be removed soon) +#if 0 //declare variables FILE* fp; FILE* source; @@ -176,8 +205,6 @@ char generateFile(char* vFile,tResource* r[]) { char parsing=0; int id=0; -//printf("hola vengo a generar el archivo\n"); - if ((fp=fopen("res.tmp","wt"))!=NULL) { //insert headers if ((source=fopen(vFile,"rt"))!=NULL) { @@ -215,13 +242,16 @@ char generateFile(char* vFile,tResource* r[]) { sprintf(coms," %s#%s",(*(r[id])).desc,(*(r[id])).coms); } } - sprintf(line,"%05d %05d %05d %s %02d%s\n", - id, - (*(r[id])).size, - (*(r[id])).offset, + sprintf(line,"<item itemtype=\"%d\" value=\"%d\" file=\"%s\" external=\"res%05d.bmp\">Res %d</item>\n", + (*(r[id])).type, + id, + //(*(r[id])).size, + //(*(r[id])).offset, (*(r[id])).file, - (*(r[id])).type, - coms); + id,id + //, + //coms + ); fputs(line,fp); } } @@ -242,107 +272,56 @@ char generateFile(char* vFile,tResource* r[]) { } else { return 0; } +#else + //New code ignores this function (resources.xml is read only) + return 1; +#endif } -//Resources extras - -void getFileName(char* vFileext,char* vDirExt,char type, unsigned short int id) { - char extBmp[] = "bmp"; - char extExtra[] = "ext"; - char extLevel[] = "pet"; - char extMidi[] = "mid"; - char extPal[] = "pal"; - char extRaw[] = "raw"; - char extWave[] = "wav"; - char* ext; - - switch (type) { - case 0: - ext=extRaw; - break; - case 1: - ext=extLevel; - break; - case 2: - ext=extBmp; - break; - case 4: - ext=extMidi; - break; - case 3: - ext=extWave; - break; - case 6: - ext=extPal; - break; - default: - ext=extExtra; - break; +//Resources output to xml functions +static FILE* unknownXmlFile=NULL; + +void AddToUnknownXml(const char* vFiledat,unsigned short id,const char* ext,char type,const char* vDirExt,unsigned short pal) { + if (unknownXmlFile==NULL) { + char xmlFile[260]; + sprintf(xmlFile,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_XML,vDirExt,vFiledat); + //Create base dir + repairFolders(xmlFile); + makebase(xmlFile); + + //Open file + if ((unknownXmlFile=fopen(xmlFile,"wt"))==NULL) return; + + //Save headers + if (type==6) pal=id; + fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, + vFiledat,vFiledat,pal + ); } - - //set filename - sprintf(vFileext,"%s%cres%05d.%s",vDirExt,DIR_SEPARATOR,id,ext); -} - -void getUpperFolder(char* aux, char* vFiledat) { - int i=0; - while (getUpperToken(vFiledat,aux,DIR_SEPARATOR,&i,260)); - aux[12]=0; + //TODO: set itemtype in words + fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, + id,id,ext,type,id + ); //To the xml output } -/***************************************************************\ -| File handling functions | -\***************************************************************/ - -int mLoadFileArray(char* vFile,unsigned char** array) { - /* - Using the string in vFile, it opens the file and returns the - number of bytes in it and the content of the file in array. - In case the file couldn't be open or memory allocated returns 0. - */ - - //declare variables - FILE *fp; - int aux; - - //Open the file - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - //get file size - fseek(fp,0,SEEK_END); - aux=ftell(fp); - if ( !aux || (aux>SIZE_OF_FILE) || ( ((*array=(char*)malloc(sizeof(char)*aux))==NULL) ) ) { - //if the file was null or bigger than the max size or couldn't allocate the file in memory - fclose(fp); - return 0; - } else { - //if the filewas succesfully open - fseek(fp,0,SEEK_SET); - aux=fread (*array,1,aux,fp); - fclose(fp); - return aux; - } +void endUnknownXml() { + if (unknownXmlFile!=NULL) { + fprintf(unknownXmlFile,RES_XML_UNKNOWN_END); + fclose(unknownXmlFile); } } -char mSaveRaw(char* vFile,unsigned char* output, int size) { - /* - Using the given string in vFile, it opens the file and saves the - first "size" bytes from the "output" in it. - In case the file couldn't be open or there was no size returns 0, - otherways returns 1. - */ - - FILE * pFile; - - if (!size) { - return 0; - } - if ((pFile = fopen (vFile , "wb"))==NULL) { - return 0; +//Resources extra functions +void getFileName(char* vFileext,char* vDirExt,tResource* r,short id,char* vFiledat) { + static const char extarray[8][4]={"raw","pet","bmp","wav","mid","ext","pal","pcs"}; + const char* ext; + ext=extarray[((r->type<=7)&&(r->type>=0))?r->type:5]; + if (r->path==NULL) { + //set filename + sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vFiledat,id,ext); + AddToUnknownXml(vFiledat,id,ext,r->type,vDirExt,r->palette); + } else { + //set filename + sprintf(vFileext,"%s/%s",vDirExt,r->path); } - fwrite (output, 1, size, pFile); - fclose (pFile); - return 1; } diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c index 54c519e..4ceddb5 100644 --- a/PR/src/lib/object/image/image16.c +++ b/PR/src/lib/object/image/image16.c @@ -36,6 +36,7 @@ compress.c: Princed Resources : Image Compressor \***************************************************************/ #include <stdio.h> +#include <string.h> #include "compress.h" #include "memory.h" @@ -65,7 +66,6 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { char k; int pos,h; unsigned char maskbyte,rep; -//printf("expandLzx %d %d \n",virtualSize,cursor); for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage while (cursor<virtualSize) { @@ -91,9 +91,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { char* cursorData = data; char* counter; char* cursorPix = (*img).pix; - char* imgEnd = (*img).pix+( - (((*img).width+1)>>1)*(img->height) - ); + char* imgEnd = (*img).pix+(*dataSize); while (cursorPix<imgEnd) { //Step 1: Create counter @@ -113,7 +111,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { cursorPix++; (*counter)--; } - + *(cursorData)=*(cursorPix); //Print repeated char cursorPix++; cursorData++; @@ -121,7 +119,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); - *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures + *dataSize=(int)((long int)cursorData-(long int)data); //Note: casted to long for portability with 64 bits architectures } //Expands an array into an image @@ -204,50 +202,72 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { return i; } -//Compress an image into an array in the most quick & dirty way -int mCompressGraphic(unsigned char* data,tImage i, int* size) { - int dataSize; - //unsigned char* a; -/* - - *size=(i.size/2)+6; - a=getMemory(*size); - //height - 00 - width - 00 - 00 - compression type - a[2]=i.width; - a[3]=i.width>>8; - - a[0]=i.height; - a[1]=i.height>>8; - - a[4]=0; - a[5]=0xB0; // how q&d I am :) - - memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix - */ -////printf("llega 3\n"); - //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file -////printf("llega 3.3\n"); -#if 1 - compressRle(data+6,&i,&dataSize); -//printf("mCompressGraphic: size=%d\n",dataSize); - //a=getMemory(*size=(dataSize+6)); -////printf("llega 4\n"); - /* - Header Settings: - height - 00 - width - 00 - 00 - compression type - */ - data[2]=i.width; - data[3]=i.width>>8; - - data[0]=i.height; - data[1]=i.height>>8; +#define COMPRESS_WORKING_ALGORITHMS 3 + +//Compress an image into an array +int mCompressGraphic(unsigned char* data,tImage* i, int* size) { + //Declare variables + int compressedSize [COMPRESS_WORKING_ALGORITHMS]; + int algorithm; + int cursor; + int virtualsize; + unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; + unsigned char* outputaux; + + //Initialize variables + virtualsize=(((i->width)+1)>>1)*i->height; + outputaux=getMemory(virtualsize); + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) compressedSize[cursor]=virtualsize; + cursor=0; + + //B0 + compressed[0]=getMemory(compressedSize[0]); + memcpy(compressed[0],i->pix,compressedSize[0]); + + //B1 + compressed[1]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + compressRle(compressed[1],i,&(compressedSize[1])); + + //B2 + compressed[2]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + //Transpose + while (cursor<=virtualsize) { + outputaux[cursor]=i->pix[transpose(cursor,i->width,i->height)]; + cursor++; + } + free(i->pix); + i->pix=outputaux; + compressRle(compressed[2],i,&(compressedSize[2])); + + /*Process results*/ + + //Select the best compression (find minimum) + *size=compressedSize[0]; + algorithm=0; + for (cursor=1;cursor<3;cursor++) { + if ((*size)>compressedSize[cursor]) { + (*size)=compressedSize[cursor]; + algorithm=cursor; + } + } + //Copy the best algorithm in the compressed data + memcpy(data+6,compressed[algorithm],*size); + (*size)+=6; + + //Write header + //(16 bits)height (Intel short int format) + data[0]=i->height; + data[1]=i->height>>8; + //(16 bits)width (Intel short int format) + data[2]=i->width; + data[3]=i->width>>8; + //(12 bits)000000001011+(4 bits)algorithm data[4]=0; - data[5]=0xB1; + data[5]=0xB0+algorithm; -*size=(dataSize+6); -////printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + //Free all compression attempts + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) free(compressed[cursor]); -#endif return 1; } diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c index 54c519e..4ceddb5 100644 --- a/PR/src/lib/object/image/image2.c +++ b/PR/src/lib/object/image/image2.c @@ -36,6 +36,7 @@ compress.c: Princed Resources : Image Compressor \***************************************************************/ #include <stdio.h> +#include <string.h> #include "compress.h" #include "memory.h" @@ -65,7 +66,6 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { char k; int pos,h; unsigned char maskbyte,rep; -//printf("expandLzx %d %d \n",virtualSize,cursor); for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage while (cursor<virtualSize) { @@ -91,9 +91,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { char* cursorData = data; char* counter; char* cursorPix = (*img).pix; - char* imgEnd = (*img).pix+( - (((*img).width+1)>>1)*(img->height) - ); + char* imgEnd = (*img).pix+(*dataSize); while (cursorPix<imgEnd) { //Step 1: Create counter @@ -113,7 +111,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { cursorPix++; (*counter)--; } - + *(cursorData)=*(cursorPix); //Print repeated char cursorPix++; cursorData++; @@ -121,7 +119,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); - *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures + *dataSize=(int)((long int)cursorData-(long int)data); //Note: casted to long for portability with 64 bits architectures } //Expands an array into an image @@ -204,50 +202,72 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { return i; } -//Compress an image into an array in the most quick & dirty way -int mCompressGraphic(unsigned char* data,tImage i, int* size) { - int dataSize; - //unsigned char* a; -/* - - *size=(i.size/2)+6; - a=getMemory(*size); - //height - 00 - width - 00 - 00 - compression type - a[2]=i.width; - a[3]=i.width>>8; - - a[0]=i.height; - a[1]=i.height>>8; - - a[4]=0; - a[5]=0xB0; // how q&d I am :) - - memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix - */ -////printf("llega 3\n"); - //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file -////printf("llega 3.3\n"); -#if 1 - compressRle(data+6,&i,&dataSize); -//printf("mCompressGraphic: size=%d\n",dataSize); - //a=getMemory(*size=(dataSize+6)); -////printf("llega 4\n"); - /* - Header Settings: - height - 00 - width - 00 - 00 - compression type - */ - data[2]=i.width; - data[3]=i.width>>8; - - data[0]=i.height; - data[1]=i.height>>8; +#define COMPRESS_WORKING_ALGORITHMS 3 + +//Compress an image into an array +int mCompressGraphic(unsigned char* data,tImage* i, int* size) { + //Declare variables + int compressedSize [COMPRESS_WORKING_ALGORITHMS]; + int algorithm; + int cursor; + int virtualsize; + unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; + unsigned char* outputaux; + + //Initialize variables + virtualsize=(((i->width)+1)>>1)*i->height; + outputaux=getMemory(virtualsize); + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) compressedSize[cursor]=virtualsize; + cursor=0; + + //B0 + compressed[0]=getMemory(compressedSize[0]); + memcpy(compressed[0],i->pix,compressedSize[0]); + + //B1 + compressed[1]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + compressRle(compressed[1],i,&(compressedSize[1])); + + //B2 + compressed[2]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + //Transpose + while (cursor<=virtualsize) { + outputaux[cursor]=i->pix[transpose(cursor,i->width,i->height)]; + cursor++; + } + free(i->pix); + i->pix=outputaux; + compressRle(compressed[2],i,&(compressedSize[2])); + + /*Process results*/ + + //Select the best compression (find minimum) + *size=compressedSize[0]; + algorithm=0; + for (cursor=1;cursor<3;cursor++) { + if ((*size)>compressedSize[cursor]) { + (*size)=compressedSize[cursor]; + algorithm=cursor; + } + } + //Copy the best algorithm in the compressed data + memcpy(data+6,compressed[algorithm],*size); + (*size)+=6; + + //Write header + //(16 bits)height (Intel short int format) + data[0]=i->height; + data[1]=i->height>>8; + //(16 bits)width (Intel short int format) + data[2]=i->width; + data[3]=i->width>>8; + //(12 bits)000000001011+(4 bits)algorithm data[4]=0; - data[5]=0xB1; + data[5]=0xB0+algorithm; -*size=(dataSize+6); -////printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + //Free all compression attempts + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) free(compressed[cursor]); -#endif return 1; } diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c index 54c519e..4ceddb5 100644 --- a/PR/src/lib/object/image/image256.c +++ b/PR/src/lib/object/image/image256.c @@ -36,6 +36,7 @@ compress.c: Princed Resources : Image Compressor \***************************************************************/ #include <stdio.h> +#include <string.h> #include "compress.h" #include "memory.h" @@ -65,7 +66,6 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { char k; int pos,h; unsigned char maskbyte,rep; -//printf("expandLzx %d %d \n",virtualSize,cursor); for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage while (cursor<virtualSize) { @@ -91,9 +91,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { char* cursorData = data; char* counter; char* cursorPix = (*img).pix; - char* imgEnd = (*img).pix+( - (((*img).width+1)>>1)*(img->height) - ); + char* imgEnd = (*img).pix+(*dataSize); while (cursorPix<imgEnd) { //Step 1: Create counter @@ -113,7 +111,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { cursorPix++; (*counter)--; } - + *(cursorData)=*(cursorPix); //Print repeated char cursorPix++; cursorData++; @@ -121,7 +119,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); - *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures + *dataSize=(int)((long int)cursorData-(long int)data); //Note: casted to long for portability with 64 bits architectures } //Expands an array into an image @@ -204,50 +202,72 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { return i; } -//Compress an image into an array in the most quick & dirty way -int mCompressGraphic(unsigned char* data,tImage i, int* size) { - int dataSize; - //unsigned char* a; -/* - - *size=(i.size/2)+6; - a=getMemory(*size); - //height - 00 - width - 00 - 00 - compression type - a[2]=i.width; - a[3]=i.width>>8; - - a[0]=i.height; - a[1]=i.height>>8; - - a[4]=0; - a[5]=0xB0; // how q&d I am :) - - memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix - */ -////printf("llega 3\n"); - //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file -////printf("llega 3.3\n"); -#if 1 - compressRle(data+6,&i,&dataSize); -//printf("mCompressGraphic: size=%d\n",dataSize); - //a=getMemory(*size=(dataSize+6)); -////printf("llega 4\n"); - /* - Header Settings: - height - 00 - width - 00 - 00 - compression type - */ - data[2]=i.width; - data[3]=i.width>>8; - - data[0]=i.height; - data[1]=i.height>>8; +#define COMPRESS_WORKING_ALGORITHMS 3 + +//Compress an image into an array +int mCompressGraphic(unsigned char* data,tImage* i, int* size) { + //Declare variables + int compressedSize [COMPRESS_WORKING_ALGORITHMS]; + int algorithm; + int cursor; + int virtualsize; + unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; + unsigned char* outputaux; + + //Initialize variables + virtualsize=(((i->width)+1)>>1)*i->height; + outputaux=getMemory(virtualsize); + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) compressedSize[cursor]=virtualsize; + cursor=0; + + //B0 + compressed[0]=getMemory(compressedSize[0]); + memcpy(compressed[0],i->pix,compressedSize[0]); + + //B1 + compressed[1]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + compressRle(compressed[1],i,&(compressedSize[1])); + + //B2 + compressed[2]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + //Transpose + while (cursor<=virtualsize) { + outputaux[cursor]=i->pix[transpose(cursor,i->width,i->height)]; + cursor++; + } + free(i->pix); + i->pix=outputaux; + compressRle(compressed[2],i,&(compressedSize[2])); + + /*Process results*/ + + //Select the best compression (find minimum) + *size=compressedSize[0]; + algorithm=0; + for (cursor=1;cursor<3;cursor++) { + if ((*size)>compressedSize[cursor]) { + (*size)=compressedSize[cursor]; + algorithm=cursor; + } + } + //Copy the best algorithm in the compressed data + memcpy(data+6,compressed[algorithm],*size); + (*size)+=6; + + //Write header + //(16 bits)height (Intel short int format) + data[0]=i->height; + data[1]=i->height>>8; + //(16 bits)width (Intel short int format) + data[2]=i->width; + data[3]=i->width>>8; + //(12 bits)000000001011+(4 bits)algorithm data[4]=0; - data[5]=0xB1; + data[5]=0xB0+algorithm; -*size=(dataSize+6); -////printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + //Free all compression attempts + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) free(compressed[cursor]); -#endif return 1; } diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c index 54c519e..4ceddb5 100644 --- a/PR/src/lib/object/image/image_common.c +++ b/PR/src/lib/object/image/image_common.c @@ -36,6 +36,7 @@ compress.c: Princed Resources : Image Compressor \***************************************************************/ #include <stdio.h> +#include <string.h> #include "compress.h" #include "memory.h" @@ -65,7 +66,6 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) { char k; int pos,h; unsigned char maskbyte,rep; -//printf("expandLzx %d %d \n",virtualSize,cursor); for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage while (cursor<virtualSize) { @@ -91,9 +91,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { char* cursorData = data; char* counter; char* cursorPix = (*img).pix; - char* imgEnd = (*img).pix+( - (((*img).width+1)>>1)*(img->height) - ); + char* imgEnd = (*img).pix+(*dataSize); while (cursorPix<imgEnd) { //Step 1: Create counter @@ -113,7 +111,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { cursorPix++; (*counter)--; } - + *(cursorData)=*(cursorPix); //Print repeated char cursorPix++; cursorData++; @@ -121,7 +119,7 @@ void compressRle(unsigned char* data,tImage* img,int *dataSize) { } *(cursorData++)=0; *(cursorData++)=*(cursorPix); - *dataSize=(int)cursorData-(int)data; //Note: data loss in 64 bits architectures + *dataSize=(int)((long int)cursorData-(long int)data); //Note: casted to long for portability with 64 bits architectures } //Expands an array into an image @@ -204,50 +202,72 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) { return i; } -//Compress an image into an array in the most quick & dirty way -int mCompressGraphic(unsigned char* data,tImage i, int* size) { - int dataSize; - //unsigned char* a; -/* - - *size=(i.size/2)+6; - a=getMemory(*size); - //height - 00 - width - 00 - 00 - compression type - a[2]=i.width; - a[3]=i.width>>8; - - a[0]=i.height; - a[1]=i.height>>8; - - a[4]=0; - a[5]=0xB0; // how q&d I am :) - - memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix - */ -////printf("llega 3\n"); - //=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file -////printf("llega 3.3\n"); -#if 1 - compressRle(data+6,&i,&dataSize); -//printf("mCompressGraphic: size=%d\n",dataSize); - //a=getMemory(*size=(dataSize+6)); -////printf("llega 4\n"); - /* - Header Settings: - height - 00 - width - 00 - 00 - compression type - */ - data[2]=i.width; - data[3]=i.width>>8; - - data[0]=i.height; - data[1]=i.height>>8; +#define COMPRESS_WORKING_ALGORITHMS 3 + +//Compress an image into an array +int mCompressGraphic(unsigned char* data,tImage* i, int* size) { + //Declare variables + int compressedSize [COMPRESS_WORKING_ALGORITHMS]; + int algorithm; + int cursor; + int virtualsize; + unsigned char* compressed [COMPRESS_WORKING_ALGORITHMS]; + unsigned char* outputaux; + + //Initialize variables + virtualsize=(((i->width)+1)>>1)*i->height; + outputaux=getMemory(virtualsize); + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) compressedSize[cursor]=virtualsize; + cursor=0; + + //B0 + compressed[0]=getMemory(compressedSize[0]); + memcpy(compressed[0],i->pix,compressedSize[0]); + + //B1 + compressed[1]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + compressRle(compressed[1],i,&(compressedSize[1])); + + //B2 + compressed[2]=getMemory(10*virtualsize+50); //This will reserve 10*(image size)+50 bytes, to allocate the compressed file + //Transpose + while (cursor<=virtualsize) { + outputaux[cursor]=i->pix[transpose(cursor,i->width,i->height)]; + cursor++; + } + free(i->pix); + i->pix=outputaux; + compressRle(compressed[2],i,&(compressedSize[2])); + + /*Process results*/ + + //Select the best compression (find minimum) + *size=compressedSize[0]; + algorithm=0; + for (cursor=1;cursor<3;cursor++) { + if ((*size)>compressedSize[cursor]) { + (*size)=compressedSize[cursor]; + algorithm=cursor; + } + } + //Copy the best algorithm in the compressed data + memcpy(data+6,compressed[algorithm],*size); + (*size)+=6; + + //Write header + //(16 bits)height (Intel short int format) + data[0]=i->height; + data[1]=i->height>>8; + //(16 bits)width (Intel short int format) + data[2]=i->width; + data[3]=i->width>>8; + //(12 bits)000000001011+(4 bits)algorithm data[4]=0; - data[5]=0xB1; + data[5]=0xB0+algorithm; -*size=(dataSize+6); -////printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]); + //Free all compression attempts + for (cursor=0;cursor<COMPRESS_WORKING_ALGORITHMS;cursor++) free(compressed[cursor]); -#endif return 1; } diff --git a/PR/src/lib/pr.c b/PR/src/lib/pr.c index d9c048a..73bd541 100644 --- a/PR/src/lib/pr.c +++ b/PR/src/lib/pr.c @@ -56,6 +56,7 @@ pr.c: Main source file for Princed Resources #include "bmp.h" #include "memory.h" +#include "disk.h" //functions @@ -76,17 +77,21 @@ int prExportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt) { Return values: 00 Ok - -1 Error accesing the file - -2 Memory error + -1 Error accesing the file DAT + -2 Memory error in extraction -3 Invalid DAT file + -4 XML Parse error + -5 Memory error in parsing + -6 XML Attribute not recognized + -7 XML File not found */ tResource* r[65536]; int a; - parseFile (vResFile,r); + + a=parseFile (vResFile,vDatFile,r); + if (a<0) return a-3; a=extract(vDatFile, vDirName,r,opt); - printf("termine B %d\n",a); - if (!(opt&8)) generateFile(vResFile,r); - printf("termine C %d\n",a); + //if (!(opt&8)) generateFile(vResFile,r); return a; } @@ -101,13 +106,18 @@ int prImportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt) { 1 - read data type Return values: - -1 File couldn't be open for writing + -1 DAT File couldn't be open for writing + -2 XML Parse error + -3 No memory + -4 XML Attribute not recognized + -5 XML File not found 00 File succesfully compiled positive number: number of missing files */ tResource* r[65536]; int a; - parseFile (vResFile,r); + a=parseFile (vResFile,vDatFile,r); + if (a<0) return a-1; a=compile (vDatFile, vDirName,r,opt); generateFile (vResFile,r); return a; @@ -129,7 +139,7 @@ int prClearRes(char* vResFile) { //Main program #ifndef DLL void syntax() { - printf("Syntax:\r\n pr datfile option [extract dir]\r\n\r\nValid options:\r\n -x[rnus] for extract\r\n r: raw extraction\r\n n: don't extract\r\n u: update res file in case there were records\r\n s: don't save res file\r\n -c[r] for compile\r\n r: raw compiling\r\n -d for type\r\n -t to clear the resource file.\r\n"); + printf("Syntax:\r\n pr datfile option [extract dir]\r\n\r\nValid options:\r\n -x[rn] for extract\r\n r: raw extraction\r\n n: don't extract\r\n -c[r] for compile\r\n r: raw compiling\r\n -d for type\r\n"); } int main(int argc, char* argv[]) { @@ -140,13 +150,6 @@ int main(int argc, char* argv[]) { int option; int i; - //bmp vars - char vFileraw[100]; - char vFilebmp[100]; - unsigned char* data; - tImage img; - int size; - #ifdef UNIX if (argc==2) { printf("Content-Type:text/html\n\nRunning as a cgi\n"); @@ -169,26 +172,54 @@ int main(int argc, char* argv[]) { //do selected taskbars switch (argv[2][1]) { case 'e': - case 'x': // file.dat --> files.ext + resource.txt + case 'x': {// file.dat --> extracted files + resource.xml + char array[8][29]={ + "Ok", + "Error accesing the file DAT", /* DAT or extracted */ + "Memory error in extraction", + "Invalid DAT file", + "XML Parse error", + "Memory error in parsing", + "XML Attribute not recognized", + "XML File not found"}; option=1; for (i=2;argv[2][i];i++) { switch (argv[2][i]) { case 'n':option&=0xFE;break; case 'r':option|=0x04;break; - case 'u':option|=0x02;break; - case 's':option|=0x08;break; default:printf("Found invalid option '%c', skiping . . .\r\n",argv[2][i]);break; } } printf("Extracting '%s' to '%s' with %d\r\n",argv[1],dir,option); - printf("Result: %d\r\n",returnValue=prExportDatOpt(argv[1],dir,"resources.txt",(char)option)); - break; - case 'd': // get type of file.dat + returnValue=prExportDatOpt(argv[1],dir,"resources.xml",(char)option); + printf("Result: %s (%d)\r\n",array[-returnValue],returnValue); + } break; + case 'd': {// get type of file.dat + char array[14][65]={ + "Memory error", + "File not found or no access error", + "Not a valid POP1 DAT file", + "Levels file", + "Graphic file with an image in the first valid entry (not common)", + "Waves/Digital sound file", + "Midis file", + "Valid DAT file with Undefined content", + "Graphic file with a palette in the first valid entry (common)", + "PC Speaker dat file", + "\0","\0","\0", + "Pop2 dat files"}; printf("Classifing '%s'\r\n",argv[1]); - printf("Result: %d type\r\n",returnValue=prVerifyDatType(argv[1])); - break; - case 'i': - case 'c': // files.ext + resource.txt --> files.dat + returnValue=prVerifyDatType(argv[1]); + printf("Result: %s (%d)\r\n",array[2+returnValue],returnValue); + } break; + case 'c': { // extracted files + resource.xml --> files.dat + char array[6][39]={ + "File succesfully compiled", + "DAT File couldn't be open for writing", + "XML Parse error", + "No memory", + "XML Attribute not recognized", + "XML File not found"}; option=1; for (i=2;argv[2][i];i++) { switch (argv[2][i]) { @@ -197,29 +228,13 @@ int main(int argc, char* argv[]) { } } printf("Compiling '%s' from '%s' with %d\r\n",argv[1],dir,option); - printf("Result: %d\r\n",returnValue=prImportDatOpt(argv[1],dir,"resources.txt",(char)option)); - break; - case 't': // none --> resource.txt (destroy resource table) - printf("Clearing 'resources.txt'\r\n"); - printf("Result: %d\r\n",returnValue=prClearRes("resources.txt")); - break; - case 'b': // img.bmp --> img.ext - sprintf(vFileraw,"%s%cres%s.raw",dir,DIR_SEPARATOR,argv[1]); - sprintf(vFilebmp,"%s%cres%s.bmp",dir,DIR_SEPARATOR,argv[1]); - - printf("Converting '%s' into '%s'\r\n",vFilebmp,vFileraw); - size=mLoadFileArray(vFilebmp,&data); - if (size && mReadBitMap(&img,data,size)) { - free(data); - mCompressGraphic(data,img,&size); - free(img.pix); - mSaveRaw(vFileraw,data,size); - free(data); + returnValue=prImportDatOpt(argv[1],dir,"resources.xml",(char)option); + if (returnValue>=0) { + printf("Result: %s (%d)\r\n",array[-returnValue],returnValue); } else { - printf("No access to the file\r\n"); - break; + printf("Result: %d files with errors\r\n",returnValue); } - break; + } break; default: syntax(); return -1; diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c index 648c736..1d7c120 100644 --- a/PR/src/lib/xml/tree.c +++ b/PR/src/lib/xml/tree.c @@ -19,8 +19,8 @@ */ /* -compress.c: Princed Resources : Image Compressor -\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf +resources.c: Princed Resources : Resource Handler +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf Copyright 2003 Princed Development Team Created: 24 Aug 2003 @@ -39,7 +39,10 @@ compress.c: Princed Resources : Image Compressor #include <stdio.h> #include <stdlib.h> #include "pr.h" +#include "xml.h" +#include "xmlsearch.h" #include "parser.h" +#include "disk.h" #include "memory.h" #include "resources.h" #include "compress.h" @@ -79,12 +82,19 @@ char verifyWaveHeader(char* array, int size) { ; } +char verifySpeakerHeader(char* array, int size) { + return + (size>1)&&(array[1]==0x00) + ; +} + char verifyHeader(char* array, int size) { if (verifyLevelHeader(array,size)) return 1; if (verifyMidiHeader(array,size)) return 4; if (verifyImageHeader(array,size)) return 2; if (verifyPaletteHeader(array,size)) return 6; if (verifyWaveHeader(array,size)) return 3; + if (verifySpeakerHeader(array,size)) return 7; return 05; } @@ -93,7 +103,7 @@ char verifyHeader(char* array, int size) { | Parsing resource file | \***************************************************************/ - +#if 0 //Parse line void parseResource(tResource* r[], char* line) { //declare variables @@ -125,6 +135,7 @@ void parseResource(tResource* r[], char* line) { (*(r[id])).type=(char)ty; } } +#endif void emptyTable(tResource* r[]) { int i=0; @@ -132,7 +143,21 @@ void emptyTable(tResource* r[]) { } //parse file -char parseFile(char* vFile,tResource* r[]) { +char parseFile(char* vFile, char* datFile, tResource* r[]) { + + tTag* tree; + int error; + + tree=parseXmlFile(vFile,&error); + if (error) return error; + emptyTable(r); + workTree(tree,datFile,r); + freeTagStructure(tree); + + return 0; + +//Old code (will be removed soon) +#if 0 //declare variables char parsing=0; char line[MAX_LINE_SIZE]; @@ -161,10 +186,14 @@ char parseFile(char* vFile,tResource* r[]) { } else { return 0; } +#endif } //generate file char generateFile(char* vFile,tResource* r[]) { + +//Old code (will be removed soon) +#if 0 //declare variables FILE* fp; FILE* source; @@ -176,8 +205,6 @@ char generateFile(char* vFile,tResource* r[]) { char parsing=0; int id=0; -//printf("hola vengo a generar el archivo\n"); - if ((fp=fopen("res.tmp","wt"))!=NULL) { //insert headers if ((source=fopen(vFile,"rt"))!=NULL) { @@ -215,13 +242,16 @@ char generateFile(char* vFile,tResource* r[]) { sprintf(coms," %s#%s",(*(r[id])).desc,(*(r[id])).coms); } } - sprintf(line,"%05d %05d %05d %s %02d%s\n", - id, - (*(r[id])).size, - (*(r[id])).offset, + sprintf(line,"<item itemtype=\"%d\" value=\"%d\" file=\"%s\" external=\"res%05d.bmp\">Res %d</item>\n", + (*(r[id])).type, + id, + //(*(r[id])).size, + //(*(r[id])).offset, (*(r[id])).file, - (*(r[id])).type, - coms); + id,id + //, + //coms + ); fputs(line,fp); } } @@ -242,107 +272,56 @@ char generateFile(char* vFile,tResource* r[]) { } else { return 0; } +#else + //New code ignores this function (resources.xml is read only) + return 1; +#endif } -//Resources extras - -void getFileName(char* vFileext,char* vDirExt,char type, unsigned short int id) { - char extBmp[] = "bmp"; - char extExtra[] = "ext"; - char extLevel[] = "pet"; - char extMidi[] = "mid"; - char extPal[] = "pal"; - char extRaw[] = "raw"; - char extWave[] = "wav"; - char* ext; - - switch (type) { - case 0: - ext=extRaw; - break; - case 1: - ext=extLevel; - break; - case 2: - ext=extBmp; - break; - case 4: - ext=extMidi; - break; - case 3: - ext=extWave; - break; - case 6: - ext=extPal; - break; - default: - ext=extExtra; - break; +//Resources output to xml functions +static FILE* unknownXmlFile=NULL; + +void AddToUnknownXml(const char* vFiledat,unsigned short id,const char* ext,char type,const char* vDirExt,unsigned short pal) { + if (unknownXmlFile==NULL) { + char xmlFile[260]; + sprintf(xmlFile,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_XML,vDirExt,vFiledat); + //Create base dir + repairFolders(xmlFile); + makebase(xmlFile); + + //Open file + if ((unknownXmlFile=fopen(xmlFile,"wt"))==NULL) return; + + //Save headers + if (type==6) pal=id; + fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, + vFiledat,vFiledat,pal + ); } - - //set filename - sprintf(vFileext,"%s%cres%05d.%s",vDirExt,DIR_SEPARATOR,id,ext); -} - -void getUpperFolder(char* aux, char* vFiledat) { - int i=0; - while (getUpperToken(vFiledat,aux,DIR_SEPARATOR,&i,260)); - aux[12]=0; + //TODO: set itemtype in words + fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, + id,id,ext,type,id + ); //To the xml output } -/***************************************************************\ -| File handling functions | -\***************************************************************/ - -int mLoadFileArray(char* vFile,unsigned char** array) { - /* - Using the string in vFile, it opens the file and returns the - number of bytes in it and the content of the file in array. - In case the file couldn't be open or memory allocated returns 0. - */ - - //declare variables - FILE *fp; - int aux; - - //Open the file - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - //get file size - fseek(fp,0,SEEK_END); - aux=ftell(fp); - if ( !aux || (aux>SIZE_OF_FILE) || ( ((*array=(char*)malloc(sizeof(char)*aux))==NULL) ) ) { - //if the file was null or bigger than the max size or couldn't allocate the file in memory - fclose(fp); - return 0; - } else { - //if the filewas succesfully open - fseek(fp,0,SEEK_SET); - aux=fread (*array,1,aux,fp); - fclose(fp); - return aux; - } +void endUnknownXml() { + if (unknownXmlFile!=NULL) { + fprintf(unknownXmlFile,RES_XML_UNKNOWN_END); + fclose(unknownXmlFile); } } -char mSaveRaw(char* vFile,unsigned char* output, int size) { - /* - Using the given string in vFile, it opens the file and saves the - first "size" bytes from the "output" in it. - In case the file couldn't be open or there was no size returns 0, - otherways returns 1. - */ - - FILE * pFile; - - if (!size) { - return 0; - } - if ((pFile = fopen (vFile , "wb"))==NULL) { - return 0; +//Resources extra functions +void getFileName(char* vFileext,char* vDirExt,tResource* r,short id,char* vFiledat) { + static const char extarray[8][4]={"raw","pet","bmp","wav","mid","ext","pal","pcs"}; + const char* ext; + ext=extarray[((r->type<=7)&&(r->type>=0))?r->type:5]; + if (r->path==NULL) { + //set filename + sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vFiledat,id,ext); + AddToUnknownXml(vFiledat,id,ext,r->type,vDirExt,r->palette); + } else { + //set filename + sprintf(vFileext,"%s/%s",vDirExt,r->path); } - fwrite (output, 1, size, pFile); - fclose (pFile); - return 1; } diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c index 648c736..1d7c120 100644 --- a/PR/src/lib/xml/unknown.c +++ b/PR/src/lib/xml/unknown.c @@ -19,8 +19,8 @@ */ /* -compress.c: Princed Resources : Image Compressor -\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf +resources.c: Princed Resources : Resource Handler +\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf Copyright 2003 Princed Development Team Created: 24 Aug 2003 @@ -39,7 +39,10 @@ compress.c: Princed Resources : Image Compressor #include <stdio.h> #include <stdlib.h> #include "pr.h" +#include "xml.h" +#include "xmlsearch.h" #include "parser.h" +#include "disk.h" #include "memory.h" #include "resources.h" #include "compress.h" @@ -79,12 +82,19 @@ char verifyWaveHeader(char* array, int size) { ; } +char verifySpeakerHeader(char* array, int size) { + return + (size>1)&&(array[1]==0x00) + ; +} + char verifyHeader(char* array, int size) { if (verifyLevelHeader(array,size)) return 1; if (verifyMidiHeader(array,size)) return 4; if (verifyImageHeader(array,size)) return 2; if (verifyPaletteHeader(array,size)) return 6; if (verifyWaveHeader(array,size)) return 3; + if (verifySpeakerHeader(array,size)) return 7; return 05; } @@ -93,7 +103,7 @@ char verifyHeader(char* array, int size) { | Parsing resource file | \***************************************************************/ - +#if 0 //Parse line void parseResource(tResource* r[], char* line) { //declare variables @@ -125,6 +135,7 @@ void parseResource(tResource* r[], char* line) { (*(r[id])).type=(char)ty; } } +#endif void emptyTable(tResource* r[]) { int i=0; @@ -132,7 +143,21 @@ void emptyTable(tResource* r[]) { } //parse file -char parseFile(char* vFile,tResource* r[]) { +char parseFile(char* vFile, char* datFile, tResource* r[]) { + + tTag* tree; + int error; + + tree=parseXmlFile(vFile,&error); + if (error) return error; + emptyTable(r); + workTree(tree,datFile,r); + freeTagStructure(tree); + + return 0; + +//Old code (will be removed soon) +#if 0 //declare variables char parsing=0; char line[MAX_LINE_SIZE]; @@ -161,10 +186,14 @@ char parseFile(char* vFile,tResource* r[]) { } else { return 0; } +#endif } //generate file char generateFile(char* vFile,tResource* r[]) { + +//Old code (will be removed soon) +#if 0 //declare variables FILE* fp; FILE* source; @@ -176,8 +205,6 @@ char generateFile(char* vFile,tResource* r[]) { char parsing=0; int id=0; -//printf("hola vengo a generar el archivo\n"); - if ((fp=fopen("res.tmp","wt"))!=NULL) { //insert headers if ((source=fopen(vFile,"rt"))!=NULL) { @@ -215,13 +242,16 @@ char generateFile(char* vFile,tResource* r[]) { sprintf(coms," %s#%s",(*(r[id])).desc,(*(r[id])).coms); } } - sprintf(line,"%05d %05d %05d %s %02d%s\n", - id, - (*(r[id])).size, - (*(r[id])).offset, + sprintf(line,"<item itemtype=\"%d\" value=\"%d\" file=\"%s\" external=\"res%05d.bmp\">Res %d</item>\n", + (*(r[id])).type, + id, + //(*(r[id])).size, + //(*(r[id])).offset, (*(r[id])).file, - (*(r[id])).type, - coms); + id,id + //, + //coms + ); fputs(line,fp); } } @@ -242,107 +272,56 @@ char generateFile(char* vFile,tResource* r[]) { } else { return 0; } +#else + //New code ignores this function (resources.xml is read only) + return 1; +#endif } -//Resources extras - -void getFileName(char* vFileext,char* vDirExt,char type, unsigned short int id) { - char extBmp[] = "bmp"; - char extExtra[] = "ext"; - char extLevel[] = "pet"; - char extMidi[] = "mid"; - char extPal[] = "pal"; - char extRaw[] = "raw"; - char extWave[] = "wav"; - char* ext; - - switch (type) { - case 0: - ext=extRaw; - break; - case 1: - ext=extLevel; - break; - case 2: - ext=extBmp; - break; - case 4: - ext=extMidi; - break; - case 3: - ext=extWave; - break; - case 6: - ext=extPal; - break; - default: - ext=extExtra; - break; +//Resources output to xml functions +static FILE* unknownXmlFile=NULL; + +void AddToUnknownXml(const char* vFiledat,unsigned short id,const char* ext,char type,const char* vDirExt,unsigned short pal) { + if (unknownXmlFile==NULL) { + char xmlFile[260]; + sprintf(xmlFile,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_XML,vDirExt,vFiledat); + //Create base dir + repairFolders(xmlFile); + makebase(xmlFile); + + //Open file + if ((unknownXmlFile=fopen(xmlFile,"wt"))==NULL) return; + + //Save headers + if (type==6) pal=id; + fprintf(unknownXmlFile,RES_XML_UNKNOWN_START, + vFiledat,vFiledat,pal + ); } - - //set filename - sprintf(vFileext,"%s%cres%05d.%s",vDirExt,DIR_SEPARATOR,id,ext); -} - -void getUpperFolder(char* aux, char* vFiledat) { - int i=0; - while (getUpperToken(vFiledat,aux,DIR_SEPARATOR,&i,260)); - aux[12]=0; + //TODO: set itemtype in words + fprintf(unknownXmlFile,RES_XML_UNKNOWN_ITEM, + id,id,ext,type,id + ); //To the xml output } -/***************************************************************\ -| File handling functions | -\***************************************************************/ - -int mLoadFileArray(char* vFile,unsigned char** array) { - /* - Using the string in vFile, it opens the file and returns the - number of bytes in it and the content of the file in array. - In case the file couldn't be open or memory allocated returns 0. - */ - - //declare variables - FILE *fp; - int aux; - - //Open the file - if ((fp=fopen(vFile,"rb"))==NULL) { - return 0; - } else { - //get file size - fseek(fp,0,SEEK_END); - aux=ftell(fp); - if ( !aux || (aux>SIZE_OF_FILE) || ( ((*array=(char*)malloc(sizeof(char)*aux))==NULL) ) ) { - //if the file was null or bigger than the max size or couldn't allocate the file in memory - fclose(fp); - return 0; - } else { - //if the filewas succesfully open - fseek(fp,0,SEEK_SET); - aux=fread (*array,1,aux,fp); - fclose(fp); - return aux; - } +void endUnknownXml() { + if (unknownXmlFile!=NULL) { + fprintf(unknownXmlFile,RES_XML_UNKNOWN_END); + fclose(unknownXmlFile); } } -char mSaveRaw(char* vFile,unsigned char* output, int size) { - /* - Using the given string in vFile, it opens the file and saves the - first "size" bytes from the "output" in it. - In case the file couldn't be open or there was no size returns 0, - otherways returns 1. - */ - - FILE * pFile; - - if (!size) { - return 0; - } - if ((pFile = fopen (vFile , "wb"))==NULL) { - return 0; +//Resources extra functions +void getFileName(char* vFileext,char* vDirExt,tResource* r,short id,char* vFiledat) { + static const char extarray[8][4]={"raw","pet","bmp","wav","mid","ext","pal","pcs"}; + const char* ext; + ext=extarray[((r->type<=7)&&(r->type>=0))?r->type:5]; + if (r->path==NULL) { + //set filename + sprintf(vFileext,RES_XML_UNKNOWN_PATH""RES_XML_UNKNOWN_FILES,vDirExt,vFiledat,id,ext); + AddToUnknownXml(vFiledat,id,ext,r->type,vDirExt,r->palette); + } else { + //set filename + sprintf(vFileext,"%s/%s",vDirExt,r->path); } - fwrite (output, 1, size, pFile); - fclose (pFile); - return 1; } diff --git a/PR/src/pr.dsp b/PR/src/pr.dsp index fef53f3..8693cb1 100644 --- a/PR/src/pr.dsp +++ b/PR/src/pr.dsp @@ -19,6 +19,7 @@ CFG=tasks - Win32 Debug !MESSAGE !MESSAGE "tasks - Win32 Release" (based on "Win32 (x86) Console Application") !MESSAGE "tasks - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "tasks - Win32 Dynamic Link Library" (based on "Win32 (x86) Console Application") !MESSAGE # Begin Project @@ -42,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /I "include\\" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /c +# ADD CPP /nologo /W3 /GX /O2 /I "include\\" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /YX /c # ADD BASE RSC /l 0x2c0a /d "NDEBUG" # ADD RSC /l 0x2c0a /d "NDEBUG" BSC32=bscmake.exe @@ -51,6 +52,10 @@ BSC32=bscmake.exe LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"bin/pr.exe" +# Begin Special Build Tool +SOURCE="$(InputPath)" +PostBuild_Cmds=del winbins\pr.exe copy bin\pr.exe winbins\pr.exe >nul scripts\upx.exe winbins\pr.exe +# End Special Build Tool !ELSEIF "$(CFG)" == "tasks - Win32 Debug" @@ -76,12 +81,43 @@ LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "tasks___Win32_Dynamic_Link_Library" +# PROP BASE Intermediate_Dir "tasks___Win32_Dynamic_Link_Library" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Dll" +# PROP Intermediate_Dir "Dll" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /I "include\\" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /YX /c +# ADD CPP /nologo /W3 /GX /O2 /I "include\\" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "DLL" /FR /YX /c +# ADD BASE RSC /l 0x2c0a /d "NDEBUG" +# ADD RSC /l 0x2c0a /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"bin/pr.exe" +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /dll /machine:I386 /def:"winbins/pr.def" /out:"winbins/pr.dll" /implib:"winbins/pr.lib" +# SUBTRACT LINK32 /pdb:none +# Begin Special Build Tool +SOURCE="$(InputPath)" +PostBuild_Cmds=scripts\upx.exe winbins\pr.dll +# End Special Build Tool + !ENDIF # Begin Target # Name "tasks - Win32 Release" # Name "tasks - Win32 Debug" +# Name "tasks - Win32 Dynamic Link Library" # Begin Group "src" # PROP Default_Filter "" @@ -91,44 +127,76 @@ LINK32=link.exe # Begin Source File SOURCE=.\formats\bmp.c +DEP_CPP_BMP_C=\ + ".\include\bmp.h"\ + ".\include\compile.h"\ + ".\include\compress.h"\ + ".\include\disk.h"\ + ".\include\resources.h"\ + !IF "$(CFG)" == "tasks - Win32 Release" !ELSEIF "$(CFG)" == "tasks - Win32 Debug" +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + !ENDIF # End Source File # Begin Source File SOURCE=.\formats\mid.c +DEP_CPP_MID_C=\ + ".\include\compile.h"\ + ".\include\disk.h"\ + ".\include\mid.h"\ + ".\include\resources.h"\ + !IF "$(CFG)" == "tasks - Win32 Release" !ELSEIF "$(CFG)" == "tasks - Win32 Debug" +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + !ENDIF # End Source File # Begin Source File SOURCE=.\formats\pal.c +DEP_CPP_PAL_C=\ + ".\include\compress.h"\ + ".\include\disk.h"\ + ".\include\pal.h"\ + ".\include\resources.h"\ + !IF "$(CFG)" == "tasks - Win32 Release" !ELSEIF "$(CFG)" == "tasks - Win32 Debug" +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + !ENDIF # End Source File # Begin Source File SOURCE=.\formats\wav.c +DEP_CPP_WAV_C=\ + ".\include\compile.h"\ + ".\include\resources.h"\ + ".\include\wav.h"\ + !IF "$(CFG)" == "tasks - Win32 Release" !ELSEIF "$(CFG)" == "tasks - Win32 Debug" +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + !ENDIF # End Source File @@ -136,33 +204,79 @@ SOURCE=.\formats\wav.c # Begin Source File SOURCE=.\compile.c +DEP_CPP_COMPI=\ + ".\include\bmp.h"\ + ".\include\compile.h"\ + ".\include\compress.h"\ + ".\include\disk.h"\ + ".\include\mid.h"\ + ".\include\pal.h"\ + ".\include\resources.h"\ + ".\include\wav.h"\ + !IF "$(CFG)" == "tasks - Win32 Release" !ELSEIF "$(CFG)" == "tasks - Win32 Debug" +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + !ENDIF # End Source File # Begin Source File SOURCE=.\compress.c +DEP_CPP_COMPR=\ + ".\include\compress.h"\ + !IF "$(CFG)" == "tasks - Win32 Release" !ELSEIF "$(CFG)" == "tasks - Win32 Debug" +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\disk.c +DEP_CPP_DISK_=\ + ".\include\disk.h"\ + ".\include\pr.h"\ + + +!IF "$(CFG)" == "tasks - Win32 Release" + +!ELSEIF "$(CFG)" == "tasks - Win32 Debug" + +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + !ENDIF # End Source File # Begin Source File SOURCE=.\extract.c +DEP_CPP_EXTRA=\ + ".\include\bmp.h"\ + ".\include\compress.h"\ + ".\include\disk.h"\ + ".\include\extract.h"\ + ".\include\mid.h"\ + ".\include\pal.h"\ + ".\include\resources.h"\ + ".\include\wav.h"\ + !IF "$(CFG)" == "tasks - Win32 Release" !ELSEIF "$(CFG)" == "tasks - Win32 Debug" +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + !ENDIF # End Source File @@ -174,39 +288,104 @@ SOURCE=.\parser.c !ELSEIF "$(CFG)" == "tasks - Win32 Debug" +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + !ENDIF # End Source File # Begin Source File SOURCE=.\pr.c +DEP_CPP_PR_C10=\ + ".\include\bmp.h"\ + ".\include\compile.h"\ + ".\include\compress.h"\ + ".\include\disk.h"\ + ".\include\extract.h"\ + ".\include\pr.h"\ + ".\include\resources.h"\ + ".\include\tasks.h"\ + !IF "$(CFG)" == "tasks - Win32 Release" !ELSEIF "$(CFG)" == "tasks - Win32 Debug" +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + !ENDIF # End Source File # Begin Source File SOURCE=.\resources.c +DEP_CPP_RESOU=\ + ".\include\compress.h"\ + ".\include\pr.h"\ + ".\include\resources.h"\ + ".\include\xml.h"\ + ".\include\xmlsearch.h"\ + !IF "$(CFG)" == "tasks - Win32 Release" !ELSEIF "$(CFG)" == "tasks - Win32 Debug" +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + !ENDIF # End Source File # Begin Source File SOURCE=.\tasks.c +DEP_CPP_TASKS=\ + ".\include\resources.h"\ + ".\include\tasks.h"\ + + +!IF "$(CFG)" == "tasks - Win32 Release" + +!ELSEIF "$(CFG)" == "tasks - Win32 Debug" + +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\xml.c +DEP_CPP_XML_C=\ + ".\include\disk.h"\ + ".\include\pr.h"\ + ".\include\xml.h"\ + + +!IF "$(CFG)" == "tasks - Win32 Release" + +!ELSEIF "$(CFG)" == "tasks - Win32 Debug" + +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=.\xmlsearch.c +DEP_CPP_XMLSE=\ + ".\include\resources.h"\ + ".\include\xml.h"\ + ".\include\xmlsearch.h"\ + !IF "$(CFG)" == "tasks - Win32 Release" !ELSEIF "$(CFG)" == "tasks - Win32 Debug" +!ELSEIF "$(CFG)" == "tasks - Win32 Dynamic Link Library" + !ENDIF # End Source File @@ -228,6 +407,10 @@ SOURCE=.\include\compress.h # End Source File # Begin Source File +SOURCE=.\include\disk.h +# End Source File +# Begin Source File + SOURCE=.\include\extract.h # End Source File # Begin Source File @@ -262,6 +445,14 @@ SOURCE=.\include\tasks.h SOURCE=.\include\wav.h # End Source File +# Begin Source File + +SOURCE=.\include\xml.h +# End Source File +# Begin Source File + +SOURCE=include\xmlsearch.h +# End Source File # End Group # End Target # End Project