strings.dll :)

This commit is contained in:
Gabriel Lorenzo 2003-05-26 18:06:58 +00:00
parent 6f239e1691
commit ac426e4b03
7 changed files with 269 additions and 98 deletions

View file

@ -176,7 +176,7 @@ TYPEOF_EDIV_Export_Priority *EDIV_Export_Priority
* FUNCTION_PARAMS deben usarse como parametros para TODAS las funciones * FUNCTION_PARAMS deben usarse como parametros para TODAS las funciones
* ¡ojo! debe ser igual en extern.h * ¡ojo! debe ser igual en extern.h
*/ */
#define FUNCTION_PARAMS struct _fun_params *fp #define FUNCTION_PARAMS struct _fun_params * fp
struct _procs_s{ struct _procs_s{
int id ; /* offset de los datos locales del proceso */ int id ; /* offset de los datos locales del proceso */
@ -236,8 +236,10 @@ struct _fun_params{
TYPEOF_GetVarOffset *GetVarOffset ; TYPEOF_GetVarOffset *GetVarOffset ;
TYPEOF_Stub_Quit *Stub_Quit ; TYPEOF_Stub_Quit *Stub_Quit ;
int imem_max; int imem_max;
int* nullstring;
int* nstring;
SDL_Surface *screen; SDL_Surface *screen;
} ; };
/* Se usa igual que el getparm() de DIV */ /* Se usa igual que el getparm() de DIV */

View file

@ -1,44 +1,48 @@
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <export.h> #include "export.h"
#include "conv.h" #include "conv.h"
/************************/ /************************/
/* char() * */ /* char() * HECHA */
/* lower() * HECHA */ /* lower() * HECHA */
/* strcat() * HECHA */ /* strcat() * HECHA */
/* strchr() * HECHA */ /* strchr() * HECHA */
/* strcmp() * HECHA */ /* strcmp() * HECHA */
/* strcpy() * HECHA */ /* strcpy() * HECHA */
/* strdel() * */ /* strdel() * HECHA */
/* strlen() * HECHA */ /* strlen() * HECHA */
/* strset() * HECHA */ /* strset() * HECHA */
/* strstr() * HECHA */ /* strstr() * HECHA */
/* upper() * HECHA */ /* upper() * HECHA */
/* calculate() * HECHA */ /* calculate() * */
/* fcalculate() * HECHA */ /* fcalculate() * */
/* itoa() * */ /* itoa() * HECHA */
/* asc() * */ /* [<CicTec> text=ASC(65); // test="A";] (Una peticion suya :). */ /* asc() * */ /* [<CicTec> text=ASC(65); // test="A";] (Una peticion suya :). */
/* ftoa() * */ /* Para los nuevos FLOAT :) */ /* ftoa() * */ /* Para los nuevos FLOAT :) */
/************************/ /************************/
/* Rutinas eDiv! :) */ /* Rutinas eDiv! :) */
char *DIV_strcpy(FUNCTION_PARAMS); int DIV_strcpy(FUNCTION_PARAMS);
size_t DIV_strlen(FUNCTION_PARAMS); int DIV_strlen(FUNCTION_PARAMS);
int DIV_strset(FUNCTION_PARAMS);
int DIV_strcmp(FUNCTION_PARAMS); int DIV_strcmp(FUNCTION_PARAMS);
char *DIV_strchr(FUNCTION_PARAMS); int DIV_strchr(FUNCTION_PARAMS);
char *DIV_strcat(FUNCTION_PARAMS); int DIV_strcat(FUNCTION_PARAMS);
char *DIV_strstr(FUNCTION_PARAMS); int DIV_strstr(FUNCTION_PARAMS);
int DIV_atoi(FUNCTION_PARAMS); int DIV_atoi(FUNCTION_PARAMS);
float DIV_atof(FUNCTION_PARAMS); float DIV_atof(FUNCTION_PARAMS);
char *DIV_lower(FUNCTION_PARAMS); int DIV_lower(FUNCTION_PARAMS);
char *DIV_upper(FUNCTION_PARAMS); int DIV_upper(FUNCTION_PARAMS);
char *DIV_strset(FUNCTION_PARAMS); int DIV_char(FUNCTION_PARAMS);
char *DIV_itoa(FUNCTION_PARAMS); int DIV_strdel(FUNCTION_PARAMS);
int DIV_itoa(FUNCTION_PARAMS);
/* Rutinas internas */ /* Rutinas internas */
static int hexval(char c); static int hexval(char c);
void strdelbeg(char * s,int n);
void strdelend(char * s,int n);
/* Variables */ /* Variables */
byte i_lower=0; /* lower ya esta inicializado? */ byte i_lower=0; /* lower ya esta inicializado? */
@ -54,116 +58,166 @@ int ExportaFuncs(EXPORTAFUNCS_PARAMS)
FUNCTION("strcat",2,DIV_strcat); FUNCTION("strcat",2,DIV_strcat);
FUNCTION("strstr",2,DIV_strstr); FUNCTION("strstr",2,DIV_strstr);
FUNCTION("strset",2,DIV_strset); FUNCTION("strset",2,DIV_strset);
FUNCTION("strdel",3,DIV_strdel);
/* Estas dos son iguales, lo sengundo es por una standarizacion :) */ // FUNCTION("calculate",1,DIV_calculate);
FUNCTION("calculate",1,DIV_atoi);
FUNCTION("atoi",1,DIV_atoi); FUNCTION("atoi",1,DIV_atoi);
/* Idem a lo anterior, pero para los datos float :) */
FUNCTION("fcalculate",1,DIV_atof); // FUNCTION("fcalculate",1,DIV_fcalculate);
FUNCTION("atof",1,DIV_atof); FUNCTION("atof",1,DIV_atof);
FUNCTION("itoa",1,DIV_itoa);
FUNCTION("lower",1,DIV_lower); FUNCTION("lower",1,DIV_lower);
FUNCTION("upper",1,DIV_upper); FUNCTION("upper",1,DIV_upper);
FUNCTION("char",1,DIV_char);
return TRUE; return TRUE;
} }
char *DIV_strcpy(FUNCTION_PARAMS) int DIV_strcpy(FUNCTION_PARAMS)
{ {
char *src=(char *)getparm(); int src=getparm();
char *dest=(char *)getparm(); int dest=getparm();
char *tmp = dest; if ((fp->mem[dest-1]&0xFFF00000)!=0xDAD00000) {
fp->Runtime_Error(164); /* Cadena destino inválida */
return 0;
}
if ((unsigned)src>255) {
if ((unsigned)(fp->mem[dest-1]&0xFFFFF)+1<strlen((char*)&fp->mem[src])) {
fp->Runtime_Error(140); /* Acceso fuera de rango */
return 0;
}
strcpy((char*)&fp->mem[dest],(char*)&fp->mem[src]);
}
else
fp->mem[dest]=src;
while ((*dest++ = *src++) != '\0'); return dest;
return tmp;
} }
size_t DIV_strlen(FUNCTION_PARAMS) int DIV_strlen(FUNCTION_PARAMS)
{ {
char *s = (char *)getparm(); int s = getparm();
const char *sc;
for(sc = s; *sc != '\0'; ++sc); if ((unsigned)s>255)
return sc - s; return (int)strlen((char*)&fp->mem[s]);
else
return 1;
} }
char *DIV_strset(FUNCTION_PARAMS) int DIV_strset(FUNCTION_PARAMS)
{ {
int valor=getparm(); int valor=getparm();
char *cadena=(char *)getparm(); int cadena=getparm();
int n;
char *inicio=cadena; if ((fp->mem[cadena-1]&0xFFF00000)!=0xDAD00000) {
fp->Runtime_Error(164); /* Cadena destino inválida */
return 0;
}
n=(fp->mem[cadena-1]&0xFFFFF)+1;
if ((unsigned)valor>255)
memset((char*)&fp->mem[cadena],(char)fp->mem[valor],n);
else
memset((char*)&fp->mem[cadena],(char)valor,n);
while (*cadena) return cadena;
*cadena++ = (char)valor;
return inicio;
} }
int DIV_strcmp(FUNCTION_PARAMS) int DIV_strcmp(FUNCTION_PARAMS)
{ {
const char *ct = (const char *)getparm(); int s1 = getparm();
const char *cs = (const char *)getparm(); int s2 = getparm();
signed char __res; if ((unsigned)s2>255) {
if ((unsigned)s1>255) {
while (1) { return strcmp((char*)&fp->mem[s2],(char*)&fp->mem[s1]);
if ((__res = *cs - *ct++) != 0 || !*cs++) } else {
break; return strcmp((char*)&fp->mem[s2],(char*)&s1);
}
} else {
if ((unsigned)s1>255) {
return strcmp((char*)&s2,(char*)&fp->mem[s1]);
} else {
return strcmp((char*)&s2,(char*)&s1);
}
} }
return __res;
} }
char *DIV_strchr(FUNCTION_PARAMS) int DIV_strchr(FUNCTION_PARAMS)
{ {
int c = getparm(); int c = getparm();
const char *s = (const char *)getparm(); int s = getparm();
char * p;
if ((unsigned)c>255)
p=strpbrk((char*)&fp->mem[s],(char*)&fp->mem[c]);
else
p=strchr((char*)&fp->mem[s],(char)c);
if (p!=NULL)
return (int)(p-(char*)&fp->mem[s]);
else
return -1;
for(; *s != (char) c; ++s)
if (*s == '\0')
return NULL;
return (char *) s;
} }
char *DIV_strcat(FUNCTION_PARAMS) int DIV_strcat(FUNCTION_PARAMS)
{ {
const char *src = (const char *)getparm(); int src = getparm();
char *dest = (char *)getparm(); int dest = getparm();
char *tmp = dest; int n;
while(*dest) if ((fp->mem[dest-1]&0xFFF00000)!=0xDAD00000) {
dest++; fp->Runtime_Error(164); /* Cadena destino inválida */
while((*dest++ = *src++) != '\0') return 0;
;
return tmp;
}
char *DIV_strstr(FUNCTION_PARAMS)
{
const char *s2 = (const char*)getparm();
const char *s1 = (const char*)getparm();
int l1, l2;
l2 = strlen(s2);
if (!l2)
return (char *)s1;
l1 = strlen(s1);
while(l1 >= l2) {
l1--;
if (!memcmp(s1,s2,l2))
return (char *)s1;
s1++;
} }
return NULL;
if ((unsigned)src>255)
n=strlen((char*)&fp->mem[src]);
else
n=1;
if ((fp->mem[dest-1]&0xFFFFF)+1<strlen((char*)&fp->mem[dest])+n) {
fp->Runtime_Error(140); /* Acceso fuera de rango */
return 0;
}
if ((unsigned)src>255)
strcat((char*)&fp->mem[dest],(char*)&fp->mem[src]);
else
sprintf((char*)&fp->mem[dest],"%s%c\0",(char*)&fp->mem[dest],src);
return dest;
} }
int DIV_strstr(FUNCTION_PARAMS)
{
int s2 = getparm();
int s1 = getparm();
char * p;
if ((unsigned)s2>255)
p=strstr((char*)&fp->mem[s1],(char*)&fp->mem[s2]);
else
p=strchr((char*)&fp->mem[s1],(char)s2);
if (p!=NULL)
return (int)(p-(char*)&fp->mem[s1]);
else
return -1;
}
/* NUEVA */
int DIV_atoi(FUNCTION_PARAMS) int DIV_atoi(FUNCTION_PARAMS)
{ {
const char *num = (const char*)getparm(); char *num = getstrparm();
int value = 0; int value = 0;
if (num[0] == '0' && num[1] == 'x') { if (num[0] == '0' && num[1] == 'x') {
/* hexadecimal */ /* hexadecimal */
@ -179,9 +233,10 @@ int DIV_atoi(FUNCTION_PARAMS)
return value; return value;
} }
/* NUEVA */
float DIV_atof(FUNCTION_PARAMS) float DIV_atof(FUNCTION_PARAMS)
{ {
const char *num = (const char*)getparm(); char *num = getstrparm();
float value = 0; float value = 0;
if (num[0] == '0' && num[1] == 'x') { if (num[0] == '0' && num[1] == 'x') {
/* hexadecimal */ /* hexadecimal */
@ -197,34 +252,102 @@ float DIV_atof(FUNCTION_PARAMS)
return value; return value;
} }
char *DIV_lower(FUNCTION_PARAMS) int DIV_lower(FUNCTION_PARAMS)
{ {
int i; int str=getparm();
char *str=(char*)getparm(); int n;
byte* memb=(byte*)fp->mem;
if (!i_lower) if (!i_lower)
inicializa_lower(); inicializa_lower();
for (i=0;str[i]!=0;i++) { if ((unsigned)str>255) {
if (lower[str[i]]!=0) str[i]=lower[str[i]]; n=strlen((char*)&fp->mem[str]);
while (n--) {
if (lower[memb[str*4+n]]!=0)
memb[str*4+n]=lower[memb[str*4+n]];
}
}
else {
if (lower[(char)str]!=0)
return (int)lower[(char)str];
}
return str;
}
int DIV_upper(FUNCTION_PARAMS)
{
int str=getparm();
int n;
byte* memb=(byte*)fp->mem;
if (!i_upper)
inicializa_upper();
if ((unsigned)str>255) {
n=strlen((char*)&fp->mem[str]);
while (n--) {
if (upper[memb[str*4+n]]!=0)
memb[str*4+n]=upper[memb[str*4+n]];
}
}
else {
if (upper[(char)str]!=0)
return (int)upper[(char)str];
}
return str;
}
int DIV_char(FUNCTION_PARAMS)
{
int s=getparm();
char* memb=(char*)fp->mem;
if ((unsigned)s>255)
return (int)memb[s*4];
else
return s;
}
int DIV_strdel(FUNCTION_PARAMS)
{
int m=getparm();
int n=getparm();
int str=getparm();
if ((fp->mem[str-1]&0xFFF00000)!=0xDAD00000) {
fp->Runtime_Error(164); /* Cadena destino inválida */
return str;
}
if ((fp->mem[str-1]&0xFFFFF)+1<strlen((char*)&fp->mem[str])-n-m) {
fp->Runtime_Error(140); /* Acceso fuera de rango */
return str;
}
if (n>m) {
/* Borra primero del inicio */
strdelbeg((char*)&fp->mem[str],n);
strdelend((char*)&fp->mem[str],m);
}
else {
/* Borra primero del final */
strdelend((char*)&fp->mem[str],m);
strdelbeg((char*)&fp->mem[str],n);
} }
return str; return str;
} }
char *DIV_upper(FUNCTION_PARAMS) int DIV_itoa(FUNCTION_PARAMS)
{ {
int i; int n=getparm();
char *str=(char*)getparm(); itoa(n,(char*)&fp->mem[fp->nullstring[*fp->nstring]],10);
n=fp->nullstring[*fp->nstring];
if (!i_upper) *fp->nstring=(((*fp->nstring)+1)&3);
inicializa_upper(); return n;
for (i=0;str[i]!=0;i++) {
if (upper[str[i]]!=0) str[i]=upper[str[i]];
}
return str;
} }
/* Rutinas internas */ /* Rutinas internas */
@ -240,3 +363,35 @@ static int hexval(char c)
return 0; return 0;
} }
void strdelbeg(char * s,int n)
{
int len=strlen(s);
if (n>0) {
if (n>=len)
*s=0;
else
memmove(s,s+n,len+1-n);
}
else if (n<0) {
memmove(s-n,s,len+1);
memset(s,' ',-n);
}
}
void strdelend(char * s,int n)
{
int len=strlen(s);
if (n>0) {
if (n>=len)
*s=0;
else
s[len-n]=0;
}
else if (n<0) {
n=len-n;
for (;len<n;len++)
s[len]=' ';
s[len]=0;
}
}

View file

@ -44,7 +44,8 @@
<Tool <Tool
Name="VCMIDLTool"/> Name="VCMIDLTool"/>
<Tool <Tool
Name="VCPostBuildEventTool"/> Name="VCPostBuildEventTool"
CommandLine="copy ..\..\..\bin\strings.dll ..\..\..\..\ediv\bin\dll"/>
<Tool <Tool
Name="VCPreBuildEventTool"/> Name="VCPreBuildEventTool"/>
<Tool <Tool

View file

@ -4,6 +4,15 @@
rulan bien :) Encontré un bug en el opcode optimizado caraidcpa, rulan bien :) Encontré un bug en el opcode optimizado caraidcpa,
ya está arreglado. (Er_Makina) ya está arreglado. (Er_Makina)
* Añadido el opcode extasp (optimización de ext + asp). (Er_Makina) * Añadido el opcode extasp (optimización de ext + asp). (Er_Makina)
* Adaptada finalmente la strings.dll, ya es perfectamente usable :)
Ya soporta todas las funciones de cadenas de DIV2, excepto calculate(),
y además, atoi() (en DIV2 sólo había calculate() pero a veces nos
puede interesar que se haga una simple conversion sin que se evalúen
expresiones) y atof(), para cuando metamos floats.
Por cierto, si en alguna de estas funciones usamos un número menor
de 256 en vez de una cadena como parámetro, lo tomará como una cadena
que sólo contiene un caracter con ese ascii. :) por ejemplo,
strcat("hol",65) devolverá "holA". (Er_Makina)
25/5/2003 25/5/2003
--------- ---------

View file

@ -241,6 +241,8 @@ struct _fun_params{
TYPEOF_GetVarOffset *GetVarOffset ; TYPEOF_GetVarOffset *GetVarOffset ;
TYPEOF_Stub_Quit *Stub_Quit ; TYPEOF_Stub_Quit *Stub_Quit ;
int imem_max; int imem_max;
int* nullstring;
int* nstring;
SDL_Surface *screen; SDL_Surface *screen;
} fp ; } fp ;

View file

@ -87,6 +87,8 @@ int ini_interprete()
fp.GetVarOffset=GetVarOffset; fp.GetVarOffset=GetVarOffset;
fp.Stub_Quit=stub_quit; fp.Stub_Quit=stub_quit;
fp.imem_max=imem_max; fp.imem_max=imem_max;
fp.nullstring=nullstring;
fp.nstring=&nstring;
#ifdef DBG #ifdef DBG
last_lin=0; last_lin=0;

Binary file not shown.