author | ecalot
<ecalot> 2003-11-07 21:01:32 UTC |
committer | ecalot
<ecalot> 2003-11-07 21:01:32 UTC |
parent | cfc2c7be8ef44d543f353f54e99cc045b587ff3c |
PR/src/Makefile | +3 | -7 |
PR/src/lib/actions/export.c | +6 | -18 |
PR/src/lib/actions/import.c | +3 | -8 |
PR/src/parser.c | +0 | -170 |
diff --git a/PR/src/Makefile b/PR/src/Makefile index 5461334..64b26d9 100644 --- a/PR/src/Makefile +++ b/PR/src/Makefile @@ -1,17 +1,13 @@ -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 +bin/pr: compile.o compress.o extract.o pr.o resources.o tasks.o disk.o xml.o xmlsearch.o bmp.o mid.o pal.o wav.o @echo Linking files... @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 + @gcc -o bin/pr compile.o compress.o extract.o pr.o resources.o tasks.o disk.o xml.o xmlsearch.o bmp.o mid.o pal.o wav.o -s + @echo Program successfully compiled @echo @echo Please read readme.txt for syntax information @echo -parser.o: parser.c - @echo Compiling parsing library... - @gcc -c parser.c -Iinclude/ - compile.o: compile.c @echo Compiling import module... @gcc -c compile.c -Iinclude/ diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c index de08f1a..aee1e56 100644 --- a/PR/src/lib/actions/export.c +++ b/PR/src/lib/actions/export.c @@ -32,6 +32,9 @@ extract.c: Princed Resources : DAT Extractor */ #include <stdio.h> +#include <string.h> + +#include "pr.h" #include "extract.h" #include "disk.h" @@ -79,8 +82,6 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { int k; //if header ok, new variables - //char aux[260]; - //char isntImageSet=1; char recordSize; char type=0; tImage image; //this is used to make a persistent palette @@ -115,7 +116,7 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { //getUpperFolder(aux,vFiledat); //Initializes the palette list - for (id=0;id<65000;id++) { + for (id=0;id<MAX_RES_COUNT;id++) { if (r[id]!=NULL) { r[id]->palAux=NULL; } @@ -138,14 +139,6 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { //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])).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)); @@ -204,12 +197,7 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { 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 @@ -222,7 +210,7 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) { fclose(fp); //Free allocated palettes - for (id=0;id<65000;id++) { + for (id=0;id<MAX_RES_COUNT;id++) { if (r[id]!=NULL) { if (r[id]->palAux!=NULL) { free (r[id]->palAux); diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index baf1f4b..ce1e860 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -42,8 +42,8 @@ compile.c: Princed Resources : DAT Compiler #include "mid.h" #include "wav.h" #include "pal.h" -#include "parser.h" #include "disk.h" +#include "pr.h" /***************************************************************\ | Dat compiling primitives | @@ -93,9 +93,8 @@ int mCreateIndexInDatFile(FILE* fp, tResource* r[]) { int pos=ftell(fp); fwrite(&tot,2,1,fp); - for (;i!=65000;i++) { //TODO: add define 65000 + for (;i!=MAX_RES_COUNT;i++) { //TODO: add define MAX_RES_COUNT if (r[i]!=NULL) { -// if (equals((*r[i]).file,vUpperFile)) { //the file is in the archive, so I'll add it to the index k+=8; tot++; @@ -103,7 +102,6 @@ int mCreateIndexInDatFile(FILE* fp, tResource* r[]) { fwrite(&((*r[i]).offset),2,1,fp); fwrite(&junk,2,1,fp); fwrite(&((*r[i]).size),2,1,fp); -// } } } fseek(fp,pos,SEEK_SET); @@ -148,7 +146,6 @@ int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt) { FILE* fp; char vFileext[200]; -// char vUpperFile[200]; int ok=0; unsigned char* data; unsigned short int i=0; @@ -159,9 +156,8 @@ int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt) { //getUpperFolder(vUpperFile,vFiledat); - for (;i!=65000;i++) { + for (;i!=MAX_RES_COUNT;i++) { if (r[i]!=NULL) { -// 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)) { @@ -173,7 +169,6 @@ int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt) { } else { ok++; } -// } } } mSetEndFile(fp,mCreateIndexInDatFile(fp,r)); diff --git a/PR/src/parser.c b/PR/src/parser.c deleted file mode 100644 index 0aa3129..0000000 --- a/PR/src/parser.c +++ /dev/null @@ -1,170 +0,0 @@ -/* Princed V3 - Prince of Persia Level Editor for PC Version - Copyright (C) 2003 Princed Development Team - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - The authors of this program may be contacted at http://forum.princed.com.ar -*/ - -/* -parser.c: Parser -\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf - Copyright 2003 Enrique Calot - Created: 1 May 2003 - - Author: Enrique Calot <ecalot.cod@princed.com.ar> - Version: 1.00 (2003-May-01) - - Note: - DO NOT remove this copyright notice -*/ - -/****************************************************************\ -| Libreria de manejo de strings, conversiones y parsing | -\****************************************************************/ - -#ifndef PARSER_DEFINED -#define PARSER_DEFINED - -#include "parser.h" - -//Letras a numeros -char num(char n) { - return ((0x2F<n)&&(n<0x3A))?(n-(0x30)):0; -} - -//Interprete de numeros en strings -unsigned long str2int(char r[]) { - char i = 0; - int valor = 0; - while(r[i]) { - valor=(10*valor)+num(r[i++]); - } - return valor; -} - -//Comparacion de strings -int equals(char s1[],char s2[]) { - int i=0; - for (;(s1[i]==s2[i])&&s1[i];i++); - return !(s1[i]||s2[i]); -} - -//Tokenizer simple -//Sintaxis: getToken(string texto,var string token,char caracterSeparador, -// var int startPosition, int sizeOfToken) -int getToken(char texto[],char token[],char tokenizer,int* i,int k) { - int j=0; - //Copiar el string hasta que se encuentre el token o se termine la linea. - //En caso de que no entre el texto en el token, lo deja truncado pero avanza i hasta el final - while (texto[*i]!=tokenizer && ((j<k)?(token[j++]=texto[(*i)++]):(texto[(*i)++]))); - token[j]='\0'; - return (texto[((*i)++)-1]); -} - -//Tokenizer simple -//Sintaxis: getNumberToken(string texto,var int token,char caracterSeparador, -// var int startPosition, int deprecated) -int getNumberToken(char texto[],unsigned short int *token,char tokenizer,int* i,int k) { - char a; - //Copiar el string hasta que se encuentre el token o se termine la linea. - //En caso de que no entre el texto en el token, lo deja truncado pero avanza i hasta el final - for (*token=0;(((a=texto[(*i)++])!=tokenizer)&&a);(*token)=(*token)*10+num(a)); - return (a); -} - -//Tokenizer + upperCase, muy bueno para interpretar comandos case insensitive -//Sintaxis: getUpperToken(string texto,var string token,char caracterSeparador, -// var int startPosition, int sizeOfToken) -int getUpperToken(char texto[],char token[],char tokenizer,int* i,int k) { - int j=0; - //Idem, pero si la letra esta entre 'a' y 'z' las pasa a mayusculas - while ((texto[*i]!=tokenizer) && ((j<k)?(token[j++]=(('a'>texto[(*i)])||(texto[(*i)]>'z'))?(texto[(*i)++]):(texto[(*i)++]&UPPER_CASE)):(texto[(*i)++]))); - token[j]='\0'; - return (texto[((*i)++)-1]); -} - -//Tokenizer complejo con soporte de comillas, optimizado para separar palabras -//Sintaxis: getToken(string texto,var string token, -// var int startPosition, int sizeOfToken) -int getMaskToken(char texto[],char token[],int* i,int k) { - int j=0; - //Copiar el string hasta que se encuentre el token Espacio o se termine la linea. - //En caso de que no entre el texto en el token, lo deja truncado pero avanza i hasta el final - char entreComillas=0; //flag que indica si se esta dentro de una cadena entre comillas, alterna entre 0 y 1 dependiendo de si se encuentran las comillas, en caso de valer 1 el while no se detiene - while ((((entreComillas^=(texto[(*i)]==34)) || (texto[*i]!=32)) && ((j<k)?(token[j++]=texto[(*i)++]):(texto[(*i)++])))); - //Seteo el caracter nulo al final del token, incremento i y devuelvo el siguiente caracter del texto o 0 en caso de que este sea el nulo. - token[j]='\0'; - return (texto[((*i)++)-1]); -} - -//Funcion privada -char matches1(char* text,char* mask,char ptext, char pmask) { - /* - Esta funcion verifica que el texto pertenezca a la mascara, - no verifica espacios ya que eso debe ser parseado en la funcion - que la llama. - En caso de poseer * la funcion se vuelve recursiva. - Optimizacion: - 1) Se contempla el caso del * multiple y se lo toma como simple - para evitar la ejecucion de recursividad de O(n cuadrado). - 2) Se contempla el caso del * al final de la mascara, en dicho caso - no ejecuta la recursividad y devuelve verdadero ya que, si se llego a - ese punto, el texto matchea. - En caso de poseer " las ignora. - En caso de poseer ? contempla cualquier caracter (incluso ? y *). - - Devuelve 1 en caso de que el caracter coincida y 0 en caso contrario. - */ - char aux; - - while (text[ptext]||mask[pmask]) { - if (mask[pmask]=='"') { - pmask++; - } else if (mask[pmask]=='?') { - pmask++; - if (!text[ptext]) return 0; - ptext++; - } else if (mask[pmask]=='*') { - while (mask[pmask++]=='*'); - pmask--; - if (!mask[pmask]) return 1; //acelera un poco el proceso para el caso particular de que termine en * - while ((text[ptext]) && !(aux=matches1(text,mask,ptext++,pmask))); - return aux; - } else { - if (text[ptext]!=mask[pmask]) return 0; - ptext++; - pmask++; - } - } - return (text[ptext]==mask[pmask]); -} - -//Funcion publica -char matchesIn(char* text,char* mask) { - int i=0; - char token[PARSING_MAX_TOKEN_SIZE]; - char valor=0; - - /* - Esta funcion se encarga de partir los espacios de la mascara y - llamar a una comparacion por cada parte - */ - while (getMaskToken(mask,token,&i,PARSING_MAX_TOKEN_SIZE) && !(valor=(valor || matches1(text,token,0,0)))); - return valor?1:matches1(text,token,0,0); -} - -#endif -