strings.dll :)
This commit is contained in:
parent
6f239e1691
commit
ac426e4b03
|
@ -176,7 +176,7 @@ TYPEOF_EDIV_Export_Priority *EDIV_Export_Priority
|
|||
* FUNCTION_PARAMS deben usarse como parametros para TODAS las funciones
|
||||
* ¡ojo! debe ser igual en extern.h
|
||||
*/
|
||||
#define FUNCTION_PARAMS struct _fun_params *fp
|
||||
#define FUNCTION_PARAMS struct _fun_params * fp
|
||||
|
||||
struct _procs_s{
|
||||
int id ; /* offset de los datos locales del proceso */
|
||||
|
@ -236,8 +236,10 @@ struct _fun_params{
|
|||
TYPEOF_GetVarOffset *GetVarOffset ;
|
||||
TYPEOF_Stub_Quit *Stub_Quit ;
|
||||
int imem_max;
|
||||
int* nullstring;
|
||||
int* nstring;
|
||||
SDL_Surface *screen;
|
||||
} ;
|
||||
};
|
||||
|
||||
|
||||
/* Se usa igual que el getparm() de DIV */
|
||||
|
|
|
@ -1,44 +1,48 @@
|
|||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <export.h>
|
||||
#include "export.h"
|
||||
#include "conv.h"
|
||||
|
||||
/************************/
|
||||
/* char() * */
|
||||
/* char() * HECHA */
|
||||
/* lower() * HECHA */
|
||||
/* strcat() * HECHA */
|
||||
/* strchr() * HECHA */
|
||||
/* strcmp() * HECHA */
|
||||
/* strcpy() * HECHA */
|
||||
/* strdel() * */
|
||||
/* strdel() * HECHA */
|
||||
/* strlen() * HECHA */
|
||||
/* strset() * HECHA */
|
||||
/* strstr() * HECHA */
|
||||
/* upper() * HECHA */
|
||||
/* calculate() * HECHA */
|
||||
/* fcalculate() * HECHA */
|
||||
/* itoa() * */
|
||||
/* calculate() * */
|
||||
/* fcalculate() * */
|
||||
/* itoa() * HECHA */
|
||||
/* asc() * */ /* [<CicTec> text=ASC(65); // test="A";] (Una peticion suya :). */
|
||||
/* ftoa() * */ /* Para los nuevos FLOAT :) */
|
||||
/************************/
|
||||
|
||||
/* Rutinas eDiv! :) */
|
||||
char *DIV_strcpy(FUNCTION_PARAMS);
|
||||
size_t DIV_strlen(FUNCTION_PARAMS);
|
||||
int DIV_strcpy(FUNCTION_PARAMS);
|
||||
int DIV_strlen(FUNCTION_PARAMS);
|
||||
int DIV_strset(FUNCTION_PARAMS);
|
||||
int DIV_strcmp(FUNCTION_PARAMS);
|
||||
char *DIV_strchr(FUNCTION_PARAMS);
|
||||
char *DIV_strcat(FUNCTION_PARAMS);
|
||||
char *DIV_strstr(FUNCTION_PARAMS);
|
||||
int DIV_strchr(FUNCTION_PARAMS);
|
||||
int DIV_strcat(FUNCTION_PARAMS);
|
||||
int DIV_strstr(FUNCTION_PARAMS);
|
||||
int DIV_atoi(FUNCTION_PARAMS);
|
||||
float DIV_atof(FUNCTION_PARAMS);
|
||||
char *DIV_lower(FUNCTION_PARAMS);
|
||||
char *DIV_upper(FUNCTION_PARAMS);
|
||||
char *DIV_strset(FUNCTION_PARAMS);
|
||||
char *DIV_itoa(FUNCTION_PARAMS);
|
||||
int DIV_lower(FUNCTION_PARAMS);
|
||||
int DIV_upper(FUNCTION_PARAMS);
|
||||
int DIV_char(FUNCTION_PARAMS);
|
||||
int DIV_strdel(FUNCTION_PARAMS);
|
||||
int DIV_itoa(FUNCTION_PARAMS);
|
||||
|
||||
/* Rutinas internas */
|
||||
static int hexval(char c);
|
||||
void strdelbeg(char * s,int n);
|
||||
void strdelend(char * s,int n);
|
||||
|
||||
/* Variables */
|
||||
byte i_lower=0; /* lower ya esta inicializado? */
|
||||
|
@ -54,116 +58,166 @@ int ExportaFuncs(EXPORTAFUNCS_PARAMS)
|
|||
FUNCTION("strcat",2,DIV_strcat);
|
||||
FUNCTION("strstr",2,DIV_strstr);
|
||||
FUNCTION("strset",2,DIV_strset);
|
||||
FUNCTION("strdel",3,DIV_strdel);
|
||||
|
||||
/* Estas dos son iguales, lo sengundo es por una standarizacion :) */
|
||||
FUNCTION("calculate",1,DIV_atoi);
|
||||
// FUNCTION("calculate",1,DIV_calculate);
|
||||
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("itoa",1,DIV_itoa);
|
||||
|
||||
FUNCTION("lower",1,DIV_lower);
|
||||
FUNCTION("upper",1,DIV_upper);
|
||||
|
||||
FUNCTION("char",1,DIV_char);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *DIV_strcpy(FUNCTION_PARAMS)
|
||||
int DIV_strcpy(FUNCTION_PARAMS)
|
||||
{
|
||||
char *src=(char *)getparm();
|
||||
char *dest=(char *)getparm();
|
||||
int src=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 tmp;
|
||||
return dest;
|
||||
}
|
||||
|
||||
size_t DIV_strlen(FUNCTION_PARAMS)
|
||||
int DIV_strlen(FUNCTION_PARAMS)
|
||||
{
|
||||
char *s = (char *)getparm();
|
||||
const char *sc;
|
||||
int s = getparm();
|
||||
|
||||
for(sc = s; *sc != '\0'; ++sc);
|
||||
return sc - s;
|
||||
if ((unsigned)s>255)
|
||||
return (int)strlen((char*)&fp->mem[s]);
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *DIV_strset(FUNCTION_PARAMS)
|
||||
int DIV_strset(FUNCTION_PARAMS)
|
||||
{
|
||||
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)
|
||||
*cadena++ = (char)valor;
|
||||
|
||||
return inicio;
|
||||
return cadena;
|
||||
}
|
||||
|
||||
int DIV_strcmp(FUNCTION_PARAMS)
|
||||
{
|
||||
const char *ct = (const char *)getparm();
|
||||
const char *cs = (const char *)getparm();
|
||||
int s1 = getparm();
|
||||
int s2 = getparm();
|
||||
|
||||
signed char __res;
|
||||
|
||||
while (1) {
|
||||
if ((__res = *cs - *ct++) != 0 || !*cs++)
|
||||
break;
|
||||
if ((unsigned)s2>255) {
|
||||
if ((unsigned)s1>255) {
|
||||
return strcmp((char*)&fp->mem[s2],(char*)&fp->mem[s1]);
|
||||
} else {
|
||||
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();
|
||||
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();
|
||||
char *dest = (char *)getparm();
|
||||
int src = getparm();
|
||||
int dest = getparm();
|
||||
|
||||
char *tmp = dest;
|
||||
int n;
|
||||
|
||||
while(*dest)
|
||||
dest++;
|
||||
while((*dest++ = *src++) != '\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++;
|
||||
if ((fp->mem[dest-1]&0xFFF00000)!=0xDAD00000) {
|
||||
fp->Runtime_Error(164); /* Cadena destino inválida */
|
||||
return 0;
|
||||
}
|
||||
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)
|
||||
{
|
||||
const char *num = (const char*)getparm();
|
||||
char *num = getstrparm();
|
||||
int value = 0;
|
||||
if (num[0] == '0' && num[1] == 'x') {
|
||||
/* hexadecimal */
|
||||
|
@ -179,9 +233,10 @@ int DIV_atoi(FUNCTION_PARAMS)
|
|||
return value;
|
||||
}
|
||||
|
||||
/* NUEVA */
|
||||
float DIV_atof(FUNCTION_PARAMS)
|
||||
{
|
||||
const char *num = (const char*)getparm();
|
||||
char *num = getstrparm();
|
||||
float value = 0;
|
||||
if (num[0] == '0' && num[1] == 'x') {
|
||||
/* hexadecimal */
|
||||
|
@ -197,34 +252,102 @@ float DIV_atof(FUNCTION_PARAMS)
|
|||
return value;
|
||||
}
|
||||
|
||||
char *DIV_lower(FUNCTION_PARAMS)
|
||||
int DIV_lower(FUNCTION_PARAMS)
|
||||
{
|
||||
int i;
|
||||
char *str=(char*)getparm();
|
||||
int str=getparm();
|
||||
int n;
|
||||
|
||||
byte* memb=(byte*)fp->mem;
|
||||
|
||||
if (!i_lower)
|
||||
inicializa_lower();
|
||||
|
||||
for (i=0;str[i]!=0;i++) {
|
||||
if (lower[str[i]]!=0) str[i]=lower[str[i]];
|
||||
if ((unsigned)str>255) {
|
||||
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;
|
||||
}
|
||||
|
||||
char *DIV_upper(FUNCTION_PARAMS)
|
||||
int DIV_itoa(FUNCTION_PARAMS)
|
||||
{
|
||||
int i;
|
||||
char *str=(char*)getparm();
|
||||
|
||||
if (!i_upper)
|
||||
inicializa_upper();
|
||||
|
||||
for (i=0;str[i]!=0;i++) {
|
||||
if (upper[str[i]]!=0) str[i]=upper[str[i]];
|
||||
}
|
||||
|
||||
return str;
|
||||
int n=getparm();
|
||||
itoa(n,(char*)&fp->mem[fp->nullstring[*fp->nstring]],10);
|
||||
n=fp->nullstring[*fp->nstring];
|
||||
*fp->nstring=(((*fp->nstring)+1)&3);
|
||||
return n;
|
||||
}
|
||||
|
||||
/* Rutinas internas */
|
||||
|
@ -240,3 +363,35 @@ static int hexval(char c)
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,8 @@
|
|||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="copy ..\..\..\bin\strings.dll ..\..\..\..\ediv\bin\dll"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
rulan bien :) Encontré un bug en el opcode optimizado caraidcpa,
|
||||
ya está arreglado. (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
|
||||
---------
|
||||
|
|
|
@ -241,6 +241,8 @@ struct _fun_params{
|
|||
TYPEOF_GetVarOffset *GetVarOffset ;
|
||||
TYPEOF_Stub_Quit *Stub_Quit ;
|
||||
int imem_max;
|
||||
int* nullstring;
|
||||
int* nstring;
|
||||
SDL_Surface *screen;
|
||||
} fp ;
|
||||
|
||||
|
|
|
@ -87,6 +87,8 @@ int ini_interprete()
|
|||
fp.GetVarOffset=GetVarOffset;
|
||||
fp.Stub_Quit=stub_quit;
|
||||
fp.imem_max=imem_max;
|
||||
fp.nullstring=nullstring;
|
||||
fp.nstring=&nstring;
|
||||
|
||||
#ifdef DBG
|
||||
last_lin=0;
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue