Compare commits

..

10 commits

30 changed files with 6773 additions and 4067 deletions

View file

@ -1,13 +1,13 @@
edivc edivc
===== =====
eDivc was an attempt to make a DIV language compiler started in 2000 and publicly released in 2002. After many years and a very unstable 0.1 version, it was left on SourceForge mostly abandoned. The code was written while all of us were about between 14-17 y/o and it had parts of the DIV Games Studio original compiler written in C for MS-DOS using Watcom C/C++. The quality is poor. eDivc was an attempt to make a DIV language compiler started in 2000 and publicly released in 2002. After many years and an unstable 0.1 version, it was left on [SourceForge](https://sf.net/projects/edivc) mostly abandoned. The code was written while all of us were about between 14-17 y/o and it had parts of the DIV Games Studio original compiler written in C for MS-DOS using Watcom C/C++. The quality is poor.
I took the work we (the eDiv Team at that time) did and moved into GitHub just for historical and nostalgic tracking. The commit history from CVS has been keept. At sometimes I will send some changes for fun, maybe I release a working (at that time state) version which can run the included test programs but this is not a promise nor a thing I may do soon. I took the work we (the eDiv Team at that time) did and moved into GitHub just for historical and nostalgic tracking, keeping the CVS commit history. At sometimes I may send some changes for fun, maybe I release a working (at that time state) version which can run the included test programs, but this is not a promise nor a thing I may do soon.
I don't have plans to maintain this, so feel free to fork and send pull requests if you want your changes merged. I don't have plans to maintain this, so feel free to fork and send pull requests if you want your changes merged.
You must known this thing won't compile nowadays with current versions of GCC, LLVM or Visual C++. I have sent some changes to build it on OS X 10.9 Mavericks, but it fails at runtime and needs many fixes. The code is not commented and variables/functions are in spanish. You have been warned :-). You must know this thing won't compile nowadays with current versions of GCC, LLVM or Visual C++. I have sent some changes to build it on latest macOS builds, but it fails at runtime and needs many fixes. The code is not commented, and variables/functions are in Spanish. You have been warned :-).
textshot textshot
======== ========
@ -35,6 +35,3 @@ Lista de opciones:
macbookair:bin vroman$ macbookair:bin vroman$
``` ```

View file

@ -66,11 +66,11 @@ zoomSurfaceRGBA (SDL_Surface * src, SDL_Surface * dst, int smooth)
} }
/* Allocate memory for row increments */ /* Allocate memory for row increments */
if ((sax = (int *) malloc ((dst->w + 1) * sizeof (Uint32))) == NULL) if ((sax = malloc ((dst->w + 1) * sizeof (Uint32))) == NULL)
{ {
return (-1); return (-1);
} }
if ((say = (int *) malloc ((dst->h + 1) * sizeof (Uint32))) == NULL) if ((say = malloc ((dst->h + 1) * sizeof (Uint32))) == NULL)
{ {
free (sax); free (sax);
return (-1); return (-1);
@ -213,11 +213,11 @@ zoomSurfaceY (SDL_Surface * src, SDL_Surface * dst)
sy = (Uint32) (65536.0 * (float) src->h / (float) dst->h); sy = (Uint32) (65536.0 * (float) src->h / (float) dst->h);
/* Allocate memory for row increments */ /* Allocate memory for row increments */
if ((sax = (Uint32 *) malloc (dst->w * sizeof (Uint32))) == NULL) if ((sax = malloc (dst->w * sizeof (Uint32))) == NULL)
{ {
return (-1); return (-1);
} }
if ((say = (Uint32 *) malloc (dst->h * sizeof (Uint32))) == NULL) if ((say = malloc (dst->h * sizeof (Uint32))) == NULL)
{ {
if (sax != NULL) if (sax != NULL)
{ {
@ -554,21 +554,24 @@ transformSurfaceY (SDL_Surface * src, SDL_Surface * dst, int cx, int cy,
*/ */
/*XPUT/* Sanity check */ /*
/* Determine if source surface is 32bit or 8bit */ Sanity check
/* New source surface is 32bit with a defined RGBA ordering */ Determine if source surface is 32bit or 8bit
/* Sanity check zoom factor */ New source surface is 32bit with a defined RGBA ordering
/* Check if we have a rotozoom or just a zoom */ Sanity check zoom factor
/* Angle!=0: full rotozoom * Check if we have a rotozoom or just a zoom
//* ----------------------- */ Angle!=0: full rotozoom
/* Calculate target factors from sin/cos and zoom Calculate target factors from sin/cos and zoom
*/
/*
Determine destination width and height by rotating a centered source box
Alloc space to completely contain the rotated surface
Target surface is 32bit with source RGBA/ABGR ordering
Lock source surface
Check which kind of surface we have
Call the 32bit transformation routine to do the rotation (using alpha)
*/ */
/* Determine destination width and height by rotating a centered source box */
/* Alloc space to completely contain the rotated surface */
/* Target surface is 32bit with source RGBA/ABGR ordering */
/* Lock source surface */
/* Check which kind of surface we have */
/* Call the 32bit transformation routine to do the rotation (using alpha) */
#define VALUE_LIMIT 0.001 #define VALUE_LIMIT 0.001

View file

@ -136,7 +136,7 @@ int eDIV_LOAD_FPG(FUNCTION_PARAMS)
fread(files[0].mapa[num].cpoint,2,2*infomapa.number_of_points,f) ; fread(files[0].mapa[num].cpoint,2,2*infomapa.number_of_points,f) ;
} }
graphic = (char*)malloc(infomapa.wide*infomapa.height*bpp/8); graphic = malloc(infomapa.wide*infomapa.height*bpp/8);
fread(graphic,1,infomapa.wide*infomapa.height*bpp/8,f); fread(graphic,1,infomapa.wide*infomapa.height*bpp/8,f);
files[0].mapa[num].Surface = SDL_CreateRGBSurfaceFrom(graphic,infomapa.wide,infomapa.height,bpp,infomapa.wide*bpp/8,0,0,0,0) ; files[0].mapa[num].Surface = SDL_CreateRGBSurfaceFrom(graphic,infomapa.wide,infomapa.height,bpp,infomapa.wide*bpp/8,0,0,0,0) ;

View file

@ -177,20 +177,26 @@ FILE * memo ;
* nombre. * nombre.
* @param nombre_program Nombre del programa, obtenido de fp->nombre_program * @param nombre_program Nombre del programa, obtenido de fp->nombre_program
*/ */
void guarda_pantallazo(char* nombre_program) void guarda_pantallazo(unsigned char *nombre_program)
{ {
char capturef[256]; char capturef[256];
int c=0; int c=0;
FILE* f; FILE* f;
sprintf(capturef,"%s%04d.bmp",nombre_program,c); while(1) {
while(f=fopen(capturef,"rb")) { /* 256 son mas que suficientes */
fclose(f); if (c >= 256)
c++;
sprintf(capturef,"%s%04d.bmp",nombre_program,c);
if(c==0)
break; break;
sprintf(capturef,"%s%04d.bmp",nombre_program,c);
f = fopen(capturef, "rb");
if (f == NULL)
c++;
fclose(f);
} }
SDL_SaveBMP(screen,capturef); SDL_SaveBMP(screen,capturef);
} }
@ -344,25 +350,6 @@ void frame(FUNCTION_PARAMS)
{ {
if ( draws[i].existe ) if ( draws[i].existe )
{ {
/* if ( draws[i].x + draws[i].Surface->w >= fp->regions[0].x && draws[i].x < fp->regions[0].x + fp->regions[0].w &&
draws[i].y + draws[i].Surface->h >= fp->regions[0].y && draws[i].y < fp->regions[0].y + fp->regions[0].h )
{
if ( draws[i].x >= fp->regions[0].x && draws[i].x + draws[i].Surface->w < fp->regions[0].x + fp->regions[0].w &&
draws[i].y >= fp->regions[0].y && draws[i].y + draws[i].Surface->h < fp->regions[0].y + fp->regions[0].h )
{
srcrect.x = 0 ;
srcrect.y = 0 ;
srcrect.w = draws[i].Surface->w ;
srcrect.h = draws[i].Surface->h ;
dstrect.x = draws[i].x ;
dstrect.y = draws[i].y ;
dstrect.w = 0 ; /* Se ignora *//*
dstrect.h = 0 ; /* Se ignora *//*
Dibuja( draws[i].Surface , srcrect , dstrect , z , draws[i].t,100,0) ;
}
}*/
Dibuja(draws[i].Surface,draws[i].x,draws[i].y,0,0,draws[i].region,z,0,draws[i].t,100,0); Dibuja(draws[i].Surface,draws[i].x,draws[i].y,0,0,draws[i].region,z,0,draws[i].t,100,0);
} }
} }

View file

@ -344,7 +344,7 @@ int DIV_strdel(FUNCTION_PARAMS)
int DIV_itoa(FUNCTION_PARAMS) int DIV_itoa(FUNCTION_PARAMS)
{ {
int n=getparm(); int n=getparm();
itoa(n,(char*)&fp->mem[fp->nullstring[*fp->nstring]],10); sprintf((char*)&fp->mem[fp->nullstring[*fp->nstring]], "%d", n);
n=fp->nullstring[*fp->nstring]; n=fp->nullstring[*fp->nstring];
*fp->nstring=(((*fp->nstring)+1)&3); *fp->nstring=(((*fp->nstring)+1)&3);
return n; return n;

0
ediv/bin/makelib.sh Normal file → Executable file
View file

File diff suppressed because it is too large Load diff

View file

@ -29,83 +29,86 @@
#include "expresion.h" #include "expresion.h"
FILE *f; FILE *f;
int i,tamano; int i, tamano;
char* buffer; char *buffer;
int linea; int linea;
char cfg[256]; char cfg[256];
/*void cfg_error(int error) void salta_spc()
{ {
printf(translate(41),cfg,linea,translate_cfg_error(error)); while (lower[buffer[i]] == 0 && i < tamano)
printf(translate(42)); {
exit(1); if (buffer[i] == '\n')
}*/ linea++;
else if (buffer[i] == '\'')
void salta_spc() { {
while(lower[buffer[i]]==0 && i<tamano) { while (buffer[i] != '\n' && i < tamano)
if(buffer[i]=='\n') linea++; i++;
else if(buffer[i]=='\'') {
while(buffer[i]!='\n' && i<tamano) i++;
linea++; linea++;
} }
i++; i++;
} }
} }
void lee_ediv_cfg(char* ediv_cfg) void lee_ediv_cfg(char *ediv_cfg)
{ {
int c; int c;
char tag[20]; char tag[20];
strcpy(cfg,ediv_cfg); strcpy(cfg, ediv_cfg);
/* Valores de las opciones por defecto */ /* Valores de las opciones por defecto */
max_process=0; max_process = 0;
ignore_errors=0; ignore_errors = 0;
free_sintax=0; free_sintax = 0;
extended_conditions=0; extended_conditions = 0;
simple_conditions=0; simple_conditions = 0;
comprueba_rango=1; comprueba_rango = 1;
comprueba_id=1; comprueba_id = 1;
comprueba_null=1; comprueba_null = 1;
hacer_strfix=1; hacer_strfix = 1;
optimizar=1; optimizar = 1;
if((f=fopen(ediv_cfg,"r"))==NULL) { if ((f = fopen(ediv_cfg, "r")) == NULL)
{
return; return;
} }
fseek(f,0,SEEK_END); fseek(f, 0, SEEK_END);
tamano=ftell(f); tamano = ftell(f);
fseek(f,0,SEEK_SET); fseek(f, 0, SEEK_SET);
buffer=(char*)e_malloc(tamano); buffer = e_malloc(tamano);
fread(buffer,1,tamano,f); fread(buffer, 1, tamano, f);
fclose(f); fclose(f);
for(i=0;i<tamano;i++) { for (i = 0; i < tamano; i++)
{
salta_spc(); salta_spc();
c=0; c = 0;
while(lower[buffer[i]]!=0 && c<20 && i<tamano) while (lower[buffer[i]] != 0 && c < 20 && i < tamano)
tag[c++]=lower[buffer[i++]]; tag[c++] = lower[buffer[i++]];
tag[c]=0; tag[c] = 0;
if(!strcmp(tag,"max_process")) { if (!strcmp(tag, "max_process"))
{
salta_spc(); salta_spc();
if(buffer[i]!='=') cfg_error(1); /* se esperaba '=' */ if (buffer[i] != '=')
cfg_error(1); /* se esperaba '=' */
salta_spc(); salta_spc();
if(buffer[i]<'0' || buffer[i]>'9') cfg_error(2); /* se esperaba un dato numerico */ if (buffer[i] < '0' || buffer[i] > '9')
c=0; cfg_error(2); /* se esperaba un dato numerico */
while(buffer[i]>='0' && buffer[i]<='9' && i<tamano) c = 0;
tag[c++]=buffer[i++]; while (buffer[i] >= '0' && buffer[i] <= '9' && i < tamano)
tag[c]=0; tag[c++] = buffer[i++];
tag[c] = 0;
itoa( itoa(
max_process=constante(); max_process=constante();
if (max_process<0) max_process=0; if (max_process<0) max_process=0;
#ifdef _DEBUG #ifdef _DEBUG
printf("dbg: max_process=%d\n",max_process); printf("dbg: max_process=%d\n",max_process);
#endif #endif
break; break;
case 1: /* _extended_conditions */ case 1: /* _extended_conditions */
lexico(); lexico();
@ -155,8 +158,7 @@ void lee_ediv_cfg(char* ediv_cfg)
lexico(); lexico();
comprueba_null=0; comprueba_null=0;
break; break;
} }
free(buffer); free(buffer);
} }

View file

@ -125,7 +125,7 @@ static int AddDLLReference(void *pImageBase, char *svName, DWORD dwFlags)
} }
// Add new dll to list // Add new dll to list
cur=(IMAGE_PARAMETERS *)e_malloc(sizeof(IMAGE_PARAMETERS)); cur = e_malloc(sizeof(IMAGE_PARAMETERS));
if(cur==NULL) { if(cur==NULL) {
LeaveCriticalSection(&g_DLLCrit); LeaveCriticalSection(&g_DLLCrit);
return -1; return -1;

View file

@ -19,8 +19,8 @@
*/ */
#ifdef _WIN32 #ifdef _WIN32
# include <winsock2.h> #include <winsock2.h>
# include "dll_load.h" #include "dll_load.h"
struct in_addr iahost; struct in_addr iahost;
struct hostent *htent; struct hostent *htent;
struct servent *svent; struct servent *svent;
@ -28,14 +28,14 @@ int status;
char buffer[1024]; char buffer[1024];
SOCKET sock; SOCKET sock;
#define sock_error(s) fprintf(stderr,"\nerror: %d\n", WSAGetLastError()) #define sock_error(s) fprintf(stderr, "\nerror: %d\n", WSAGetLastError())
void muestra_motd(); void muestra_motd();
void conecta(char *servidor, char *archivo); void conecta(char *servidor, char *archivo);
#else #else
# include <dlfcn.h> /* ¿será igual en BeOS? */ #include <dlfcn.h> /* ¿será igual en BeOS? */
# include <dirent.h> #include <dirent.h>
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -63,113 +63,132 @@ int main(int argc, char *argv[])
char *p; char *p;
char libmagic[14]; /* cabecera "magic" de EDIVRUN.LIB */ char libmagic[14]; /* cabecera "magic" de EDIVRUN.LIB */
int i,j; int i, j;
byte hayprog=0; byte hayprog = 0;
char sistema[20]; char sistema[20];
n_errors=0; n_errors = 0;
n_warnings=0; n_warnings = 0;
debug=0; debug = 0;
listados=0; listados = 0;
noexe=0; noexe = 0;
/* Sistemas */ /* Sistemas */
#ifdef _WIN32 #if defined(_WIN32)
strcpy(sistema,"win32"); strcpy(sistema, "win32");
#endif #elif defined(__linux__)
strcpy(sistema, "linux");
#elif defined(__APPLE__)
strcpy(sistema, "osx");
#else
strcpy(sistema, "unknown");
#endif
#ifdef __linux__ ini = iniparser_load("ediv.cfg");
strcpy(sistema,"linux");
#endif
ini=iniparser_load("ediv.cfg"); idioma = detecta_idioma();
idioma=detecta_idioma();
/* mensaje de cabecera */ /* mensaje de cabecera */
printf(translate(0)); print_translate(0);
printf(translate(1)); print_translate(1);
printf("\n"); printf("\n");
if(argc<2) goto ayuda; if (argc < 2)
goto ayuda;
if(strcmp(argv[1],"--version")==0 || strcmp(argv[1],"-v")==0) if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-v") == 0)
exit(0); exit(0);
if(strcmp(argv[1],"--help")==0 || strcmp(argv[1],"-h")==0) { if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0)
{
ayuda: ayuda:
/* pantalla de ayuda */ /* pantalla de ayuda */
printf(translate(2)); print_translate(2);
printf(translate(3),argv[0]); print_translate(3, argv[0]);
printf(translate(4)); print_translate(4);
printf(translate(5)); print_translate(5);
printf(translate(6)); print_translate(6);
printf(translate(7)); print_translate(7);
printf(translate(8)); print_translate(8);
printf(translate(9)); print_translate(9);
printf(translate(10),sistema); print_translate(10, sistema);
printf(translate(48)); print_translate(48);
printf(translate(11)); print_translate(11);
exit(0); exit(0);
} }
for(i=1;i<argc;i++) { for (i = 1; i < argc; i++)
if(argv[i][0]=='-') { {
if(argv[i][1]=='-') { if (argv[i][0] == '-')
if(strcmp(argv[i]+2,"debug")==0) {
debug=1; if (argv[i][1] == '-')
else if(strcmp(argv[i]+2,"list")==0) {
listados|=1; if (strcmp(argv[i] + 2, "debug") == 0)
else if(strcmp(argv[i]+2,"table")==0) debug = 1;
listados|=2; else if (strcmp(argv[i] + 2, "list") == 0)
else if(strcmp(argv[i]+2,"check")==0) listados |= 1;
noexe=1; else if (strcmp(argv[i] + 2, "table") == 0)
else if(strcmp(argv[i]+2,"system")==0) listados |= 2;
if(++i<argc) { else if (strcmp(argv[i] + 2, "check") == 0)
strcpy(sistema,argv[i]); noexe = 1;
} else { else if (strcmp(argv[i] + 2, "system") == 0)
printf(translate(12)); /* se debe indicar un sistema para --system */ if (++i < argc)
{
strcpy(sistema, argv[i]);
}
else
{
print_translate(12); /* se debe indicar un sistema para --system */
exit(1); exit(1);
} }
#ifdef _WIN32 #ifdef _WIN32
else if(strcmp(argv[i]+2,"news")==0) { else if (strcmp(argv[i] + 2, "news") == 0)
{
muestra_motd(); muestra_motd();
} }
#endif #endif
else { else
printf(translate(13),argv[i]); /* parámetro erróneo */ {
print_translate(13, argv[i]); /* parámetro erróneo */
exit(1); exit(1);
} }
} }
else { else
j=1; {
while(argv[i][j]!=0) { j = 1;
switch(argv[i][j]) { while (argv[i][j] != 0)
{
switch (argv[i][j])
{
case 'd': case 'd':
debug=1; debug = 1;
break; break;
case 'l': case 'l':
listados|=1; listados |= 1;
break; break;
case 't': case 't':
listados|=2; listados |= 2;
break; break;
case 'c': case 'c':
noexe=1; noexe = 1;
break; break;
case 's': case 's':
if(argv[i][j+1]!=0) { if (argv[i][j + 1] != 0)
strcpy(sistema,argv[i]+j+1); {
j=strlen(argv[i])-1; strcpy(sistema, argv[i] + j + 1);
j = strlen(argv[i]) - 1;
} }
else { else
if(++i<argc) { {
strcpy(sistema,argv[i]); if (++i < argc)
j=strlen(argv[i])-1; {
strcpy(sistema, argv[i]);
j = strlen(argv[i]) - 1;
} }
else { else
printf(translate(14)); /* se debe indicar un sistema para -s */ {
print_translate(14); /* se debe indicar un sistema para -s */
exit(1); exit(1);
} }
} }
@ -180,139 +199,156 @@ int main(int argc, char *argv[])
exit(0); exit(0);
#endif #endif
default: default:
printf(translate(15),argv[i][j]); /* parámetro erróneo */ print_translate(15, argv[i][j]); /* parámetro erróneo */
exit(1); exit(1);
} }
j++; j++;
} }
} }
} }
else switch (hayprog) { else
switch (hayprog)
{
case 0: case 0:
fichero_prg=argv[i]; fichero_prg = argv[i];
hayprog=1; hayprog = 1;
break; break;
case 1: case 1:
strcpy(outfilename,argv[i]); strcpy(outfilename, argv[i]);
hayprog=2; hayprog = 2;
break; break;
default: default:
printf(translate(13),argv[i]); /* parámetro erróneo */ print_translate(13, argv[i]); /* parámetro erróneo */
exit(1); exit(1);
} }
} }
if(hayprog==0) { if (hayprog == 0)
printf(translate(16)); /* no se ha especificado un archivo */ {
print_translate(16); /* no se ha especificado un archivo */
exit(1); exit(1);
} }
for (i=0;i<=strlen(fichero_prg);i++) { for (i = 0; i <= strlen(fichero_prg); i++)
if (*(fichero_prg+i) == '.') {
if (*(fichero_prg + i) == '.')
break; break;
nombreprog[i] = *(fichero_prg+i); nombreprog[i] = *(fichero_prg + i);
} }
nombreprog[i]=0; nombreprog[i] = 0;
if(!(fp = fopen(fichero_prg, "rb"))) { if (!(fp = fopen(fichero_prg, "rb")))
if(!strcmp(nombreprog,fichero_prg)) { {
strcpy(fichero_prg,nombreprog); if (!strcmp(nombreprog, fichero_prg))
strcat(fichero_prg,".prg"); {
if(!(fp = fopen(fichero_prg, "rb"))) { strcpy(fichero_prg, nombreprog);
strcpy(fichero_prg,nombreprog); strcat(fichero_prg, ".prg");
strcat(fichero_prg,".PRG"); if (!(fp = fopen(fichero_prg, "rb")))
if(!(fp = fopen(fichero_prg, "rb"))) { {
printf(translate(17),nombreprog); /* error al abrir archivo */ strcpy(fichero_prg, nombreprog);
strcat(fichero_prg, ".PRG");
if (!(fp = fopen(fichero_prg, "rb")))
{
print_translate(17, nombreprog); /* error al abrir archivo */
exit(1); exit(1);
} }
} }
} }
else { else
printf(translate(17),argv[1]); /* error al abrir archivo */ {
print_translate(17, argv[1]); /* error al abrir archivo */
exit(1); exit(1);
} }
} }
/* Componemos el nombre del ejecutable */ /* Componemos el nombre del ejecutable */
if(hayprog<2) { if (hayprog < 2)
strcpy(outfilename,nombreprog); {
if(!strcmp(sistema,"win32")) strcpy(outfilename, nombreprog);
strcat(outfilename,".exe"); if (!strcmp(sistema, "win32"))
strcat(outfilename, ".exe");
} }
printf(translate(18),fichero_prg); /* compilando... */ print_translate(18, fichero_prg); /* compilando... */
/* mete el PRG en el buffer prog */ /* mete el PRG en el buffer prog */
fseek(fp,0,SEEK_END); fseek(fp, 0, SEEK_END);
progsize=ftell(fp); progsize = ftell(fp);
prog = (unsigned char *)e_malloc(progsize+1); prog = e_malloc(progsize + 1);
fseek(fp,0,SEEK_SET); fseek(fp, 0, SEEK_SET);
p=(char*)prog; p = (char *)prog;
do { do
{
*p = getc(fp); *p = getc(fp);
p++; p++;
} while(!feof(fp)); } while (!feof(fp));
fclose(fp); fclose(fp);
/* Comprueba si existe la edivrun.lib */ /* Comprueba si existe la edivrun.lib */
if(!noexe) { if (!noexe)
strcpy(edivrun_lib,sistema); {
if(debug) strcpy(edivrun_lib, sistema);
strcat(edivrun_lib,".dbg"); if (debug)
strcat(edivrun_lib, ".dbg");
else else
strcat(edivrun_lib,".rel"); strcat(edivrun_lib, ".rel");
if((fp = fopen(edivrun_lib, "rb"))==NULL) { if ((fp = fopen(edivrun_lib, "rb")) == NULL)
printf(translate(19),edivrun_lib); /* no se encuentra el fichero */ {
print_translate(19, edivrun_lib); /* no se encuentra el fichero */
exit(1); exit(1);
} }
else { else
fread(libmagic,1,14,fp); {
if(strcmp(libmagic,magic)) { fread(libmagic, 1, 14, fp);
printf(translate(20),edivrun_lib); /* formato incorrecto de edivrun.lib */ if (strcmp(libmagic, magic))
{
print_translate(20, edivrun_lib); /* formato incorrecto de edivrun.lib */
fclose(fp); fclose(fp);
exit(1); exit(1);
} }
else { else
fread(&stub_size,1,4,fp); {
fread(&stub_size, 1, 4, fp);
fclose(fp); fclose(fp);
#ifdef _DEBUG #ifdef _DEBUG
printf("dbg: STUB_SIZE: %d\n",stub_size); printf("dbg: STUB_SIZE: %d\n", stub_size);
#endif #endif
} }
} }
} }
if(!ini) { if (!ini)
{
/* Valores de las opciones por defecto */ /* Valores de las opciones por defecto */
max_process=0; max_process = 0;
ignore_errors=0; ignore_errors = 0;
free_sintax=0; free_sintax = 0;
extended_conditions=0; extended_conditions = 0;
simple_conditions=0; simple_conditions = 0;
comprueba_rango=1; comprueba_rango = 1;
comprueba_id=1; comprueba_id = 1;
comprueba_null=1; comprueba_null = 1;
hacer_strfix=1; hacer_strfix = 1;
optimizar=1; optimizar = 1;
case_sensitive=0; case_sensitive = 0;
} else { }
max_process=iniparser_getint(ini,"default_compiler_options:max_process",0); else
ignore_errors=iniparser_getboolean(ini,"default_compiler_options:ignore_errors",0); {
free_sintax=iniparser_getboolean(ini,"default_compiler_options:free_sintax",0); max_process = iniparser_getint(ini, "default_compiler_options:max_process", 0);
extended_conditions=iniparser_getboolean(ini,"default_compiler_options:extended_conditions",0); ignore_errors = iniparser_getboolean(ini, "default_compiler_options:ignore_errors", 0);
simple_conditions=iniparser_getboolean(ini,"default_compiler_options:simple_conditions",0); free_sintax = iniparser_getboolean(ini, "default_compiler_options:free_sintax", 0);
case_sensitive=iniparser_getboolean(ini,"default_compiler_options:case_sensitive",0); extended_conditions = iniparser_getboolean(ini, "default_compiler_options:extended_conditions", 0);
comprueba_rango=iniparser_getboolean(ini,"default_compiler_options:no_range_check",0)?0:1; simple_conditions = iniparser_getboolean(ini, "default_compiler_options:simple_conditions", 0);
comprueba_id=iniparser_getboolean(ini,"default_compiler_options:no_id_check",0)?0:1; case_sensitive = iniparser_getboolean(ini, "default_compiler_options:case_sensitive", 0);
comprueba_null=iniparser_getboolean(ini,"default_compiler_options:no_null_check",0)?0:1; comprueba_rango = iniparser_getboolean(ini, "default_compiler_options:no_range_check", 0) ? 0 : 1;
hacer_strfix=iniparser_getboolean(ini,"default_compiler_options:no_strfix",0)?0:1; comprueba_id = iniparser_getboolean(ini, "default_compiler_options:no_id_check", 0) ? 0 : 1;
optimizar=iniparser_getboolean(ini,"default_compiler_options:no_optimization",0)?0:1; comprueba_null = iniparser_getboolean(ini, "default_compiler_options:no_null_check", 0) ? 0 : 1;
case_sensitive=iniparser_getboolean(ini,"default_compiler_options:case_sensitive",0); hacer_strfix = iniparser_getboolean(ini, "default_compiler_options:no_strfix", 0) ? 0 : 1;
if(iniparser_getboolean(ini,"default_compiler_options:no_check",0)) optimizar = iniparser_getboolean(ini, "default_compiler_options:no_optimization", 0) ? 0 : 1;
comprueba_rango=comprueba_id=comprueba_null=0; case_sensitive = iniparser_getboolean(ini, "default_compiler_options:case_sensitive", 0);
if (iniparser_getboolean(ini, "default_compiler_options:no_check", 0))
comprueba_rango = comprueba_id = comprueba_null = 0;
} }
prepara_compilacion(); prepara_compilacion();
@ -321,24 +357,23 @@ int main(int argc, char *argv[])
compila(); compila();
#ifdef MULTI_ERROR #ifdef MULTI_ERROR
printf("edivc: Finalizado - %d advertencias, %d errores\n",n_warnings,n_errors); printf("edivc: Finalizado - %d advertencias, %d errores\n", n_warnings, n_errors);
#else #else
if(n_errors) if (n_errors)
printf(translate(21),n_warnings); print_translate(21, n_warnings);
else else
printf(translate(22),n_warnings); print_translate(22, n_warnings);
#endif #endif
if(n_errors==0) if (n_errors == 0)
return 0; return 0;
else { else
printf(translate(23)); {
print_translate(23);
return 2; return 2;
} }
} }
/* /*
* void *e_malloc(size_t size) * void *e_malloc(size_t size)
* Idéntico a malloc, pero con errormsg automático * Idéntico a malloc, pero con errormsg automático
@ -346,12 +381,13 @@ int main(int argc, char *argv[])
* Retorna: * Retorna:
* El numero de bytes de memoria alojados o sale si no se puede reservar la memoria. * El numero de bytes de memoria alojados o sale si no se puede reservar la memoria.
*/ */
void* e_malloc(size_t size) void *e_malloc(size_t size)
{ {
void* ret; void *ret;
if(!(ret = malloc(size))) { if (!(ret = malloc(size)))
printf(translate(24)); /* memoria insuficiente */ {
print_translate(24); /* memoria insuficiente */
exit(1); exit(1);
} }
@ -360,32 +396,47 @@ void* e_malloc(size_t size)
void e_free(void *puntero) void e_free(void *puntero)
{ {
if (puntero) { if (puntero)
{
free(puntero); free(puntero);
puntero=NULL; puntero = NULL;
} }
} }
void errormem() void errormem()
{ {
printf(translate(24)); print_translate(24);
exit(1); exit(1);
} }
/* /*
* Gestión de errores * Gestión de errores
*/ */
int _le,_t; int _le, _t;
byte *_ie; byte *_ie;
void save_error(word tipo) { /* Guarda una posicion de error (de 0 .. 3) */ void save_error(word tipo)
switch(tipo) { { /* Guarda una posicion de error (de 0 .. 3) */
case 0: _le=linea; _ie=ierror; break; switch (tipo)
case 1: _le=old_linea; _ie=old_ierror_end; break; {
case 2: _le=old_linea; _ie=old_ierror; break; case 0:
case 3: _le=old_linea; _ie=old_ierror_end; break; _le = linea;
} _t=tipo; _ie = ierror;
break;
case 1:
_le = old_linea;
_ie = old_ierror_end;
break;
case 2:
_le = old_linea;
_ie = old_ierror;
break;
case 3:
_le = old_linea;
_ie = old_ierror_end;
break;
}
_t = tipo;
} }
/* /*
@ -397,48 +448,75 @@ void save_error(word tipo) { /* Guarda una posicion de error (de 0 .. 3) */
*/ */
void error(word tipo, word num, ...) void error(word tipo, word num, ...)
{ {
int columna=0; int columna = 0;
int linea_error; int linea_error;
byte *_p,*p; byte *_p, *p;
va_list opparam; va_list opparam;
switch(tipo) { switch (tipo)
case 0: linea_error=linea; p=ierror; break; {
case 1: linea_error=old_linea; _p=p=old_ierror_end; break; case 0:
case 2: linea_error=old_linea; p=old_ierror; break; linea_error = linea;
case 3: linea_error=old_linea; _p=p=old_ierror_end; break; p = ierror;
case 4: linea_error=_le; _p=p=_ie; tipo=_t; break; break;
case 1:
linea_error = old_linea;
_p = p = old_ierror_end;
break;
case 2:
linea_error = old_linea;
p = old_ierror;
break;
case 3:
linea_error = old_linea;
_p = p = old_ierror_end;
break;
case 4:
linea_error = _le;
_p = p = _ie;
tipo = _t;
break;
} }
if (num!=2 && num!=6) { if (num != 2 && num != 6)
while (--p>=prog) { {
if (*p==lf || (*p==cr && *(p+1)==lf)) break; while (--p >= prog)
{
if (*p == lf || (*p == cr && *(p + 1) == lf))
break;
columna++; columna++;
} }
if (p<prog) columna++; if (p < prog)
columna++;
} }
if (tipo==1) { if (tipo == 1)
if (*(_p+1)==' ' || *(_p+1)==cr || *(_p+1)==lf) columna++; columna++; {
} else if (tipo==3) columna++; if (*(_p + 1) == ' ' || *(_p + 1) == cr || *(_p + 1) == lf)
columna++;
columna++;
}
else if (tipo == 3)
columna++;
va_start(opparam,num); va_start(opparam, num);
printf(translate(25), fichero_prg, linea_error, columna, num); print_translate(25, fichero_prg, linea_error, columna, num);
vprintf(translate_error(num),opparam); vprintf(translate_error(num), opparam);
printf("\n"); printf("\n");
n_errors++; n_errors++;
#ifdef MULTI_ERROR #ifdef MULTI_ERROR
if(n_errors>20) if (n_errors > 20)
printf("Demasiados errores. Compilación interrumpida.\n"); printf("Demasiados errores. Compilación interrumpida.\n");
if(num==1 || num==2 || num==6 || n_errors>20) { if (num == 1 || num == 2 || num == 6 || n_errors > 20)
printf("edivc: Finalizado - %d advertencias, %d errores\n",n_warnings,n_errors); {
printf("edivc: Finalizado - %d advertencias, %d errores\n", n_warnings, n_errors);
#else #else
printf(translate(21),n_warnings); print_translate(21, n_warnings);
#endif #endif
printf(translate(23)); print_translate(23);
exit(2); exit(2);
#ifdef MULTI_ERROR #ifdef MULTI_ERROR
} }
@ -449,9 +527,9 @@ void warning(int num, ...)
{ {
va_list opparam; va_list opparam;
va_start(opparam,num); va_start(opparam, num);
printf(translate(26), fichero_prg, linea); print_translate(26, fichero_prg, linea);
vprintf(translate_warning(num),opparam); vprintf(translate_warning(num), opparam);
printf("\n"); printf("\n");
n_warnings++; n_warnings++;
} }
@ -462,21 +540,26 @@ void warning(int num, ...)
#ifdef _WIN32 #ifdef _WIN32
void muestra_motd() void muestra_motd()
{ {
char* motdserver=NULL; char *motdserver = NULL;
char* motdpath=NULL; char *motdpath = NULL;
if(ini) { if (ini)
motdserver=iniparser_getstr(ini,"general:motd_host"); {
motdpath=iniparser_getstr(ini,"general:motd_path"); motdserver = iniparser_getstr(ini, "general:motd_host");
if(!motdserver) { motdpath = iniparser_getstr(ini, "general:motd_path");
printf(translate(49)); /* el servidor de motd debe estar en ediv.cfg */ if (!motdserver)
{
print_translate(49); /* el servidor de motd debe estar en ediv.cfg */
exit(1); exit(1);
} }
if(!motdpath) motdpath="/ediv/actual/motd.txt"; if (!motdpath)
conecta(motdserver,motdpath); motdpath = "/ediv/actual/motd.txt";
conecta(motdserver, motdpath);
exit(0); exit(0);
} else { }
printf(translate(49)); /* el servidor de motd debe estar en ediv.cfg */ else
{
print_translate(49); /* el servidor de motd debe estar en ediv.cfg */
exit(1); exit(1);
} }
} }
@ -485,54 +568,57 @@ void conecta(char *servidor, char *archivo)
{ {
struct sockaddr_in sin; struct sockaddr_in sin;
char *size, *content,*ras; char *size, *content, *ras;
int tam,inc; int tam, inc;
WSADATA wsaData; WSADATA wsaData;
WSAStartup(MAKEWORD(2,2),&wsaData); WSAStartup(MAKEWORD(2, 2), &wsaData);
iahost.s_addr=inet_addr(servidor); iahost.s_addr = inet_addr(servidor);
if (iahost.s_addr==INADDR_NONE) if (iahost.s_addr == INADDR_NONE)
htent=gethostbyname(servidor); htent = gethostbyname(servidor);
else else
htent=gethostbyaddr((const char *)&iahost,sizeof(struct in_addr),AF_INET); htent = gethostbyaddr((const char *)&iahost, sizeof(struct in_addr), AF_INET);
if (htent==NULL) { if (htent == NULL)
{
sock_error("gethostbyname()"); sock_error("gethostbyname()");
return; return;
} }
sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock==INVALID_SOCKET) { if (sock == INVALID_SOCKET)
{
sock_error("socket()"); sock_error("socket()");
return; return;
} }
svent=getservbyname("http", "tcp"); svent = getservbyname("http", "tcp");
if (svent==NULL) if (svent == NULL)
sin.sin_port=htons((u_short)80); sin.sin_port = htons((u_short)80);
else else
sin.sin_port=svent->s_port; sin.sin_port = svent->s_port;
sin.sin_family=AF_INET; sin.sin_family = AF_INET;
sin.sin_addr=*(struct in_addr *)*htent->h_addr_list; sin.sin_addr = *(struct in_addr *)*htent->h_addr_list;
status=connect(sock,(struct sockaddr *)&sin,sizeof(sin)); status = connect(sock, (struct sockaddr *)&sin, sizeof(sin));
if (status==SOCKET_ERROR) { if (status == SOCKET_ERROR)
{
sock_error("connect()"); sock_error("connect()");
closesocket(sock); closesocket(sock);
return; return;
} }
sprintf(buffer,"GET %s HTTP/1.1\n" sprintf(buffer, "GET %s HTTP/1.1\n"
"User-Agent: Mozilla/4.76 (Windows 2000; U) Opera 5.12 [es]\n" "User-Agent: Mozilla/4.76 (Windows 2000; U) Opera 5.12 [es]\n"
"Host: %s\n" "Host: %s\n"
"Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*\n" "Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*\n"
"Accept-Language: es\nAccept-Encoding: deflate, gzip, x-gzip, identity, *;q=0\n" "Accept-Language: es\nAccept-Encoding: deflate, gzip, x-gzip, identity, *;q=0\n"
"Connection: Keep-Alive\n" "Connection: Keep-Alive\n"
"\n" "\n",
,archivo,servidor); archivo, servidor);
#ifdef DEBUG_HTTP #ifdef DEBUG_HTTP
printf("GET %s HTTP/1.1\n" printf("GET %s HTTP/1.1\n"
@ -541,59 +627,68 @@ void conecta(char *servidor, char *archivo)
"Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*\n" "Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*\n"
"Accept-Language: es\nAccept-Encoding: deflate, gzip, x-gzip, identity, *;q=0\n" "Accept-Language: es\nAccept-Encoding: deflate, gzip, x-gzip, identity, *;q=0\n"
"Connection: Keep-Alive\n" "Connection: Keep-Alive\n"
"\n" "\n",
,archivo,servidor); archivo, servidor);
#endif #endif
status=send(sock,buffer,strlen(buffer),0); status = send(sock, buffer, strlen(buffer), 0);
if (status==SOCKET_ERROR) { if (status == SOCKET_ERROR)
{
sock_error("send()"); sock_error("send()");
closesocket(sock); closesocket(sock);
return; return;
} }
status=recv(sock,buffer,sizeof(buffer),0); status = recv(sock, buffer, sizeof(buffer), 0);
if (status == SOCKET_ERROR) { if (status == SOCKET_ERROR)
{
sock_error("recv()"); sock_error("recv()");
} }
closesocket(sock); closesocket(sock);
if(*(buffer+9)!='2' || *(buffer+10)!='0' || *(buffer+10)!='0') { if (*(buffer + 9) != '2' || *(buffer + 10) != '0' || *(buffer + 10) != '0')
*strchr(buffer,0x0d)=0; {
printf("%s\n",buffer); *strchr(buffer, 0x0d) = 0;
printf("%s\n", buffer);
exit(1); exit(1);
} }
size=strstr(buffer,"Content-Type: "); size = strstr(buffer, "Content-Type: ");
if(!size) { if (!size)
printf(translate(50)); {
print_translate(50);
exit(1); exit(1);
} }
size+=14; size += 14;
*(ras=strchr(size,0x0d))=0; *(ras = strchr(size, 0x0d)) = 0;
if(strcmp(size,"text/plain")) { if (strcmp(size, "text/plain"))
printf(translate(50)); {
print_translate(50);
exit(1); exit(1);
} }
*ras=0x0d; *ras = 0x0d;
size=strstr(buffer,"Content-Length: "); size = strstr(buffer, "Content-Length: ");
if(!size) { if (!size)
printf(translate(50)); {
print_translate(50);
exit(1); exit(1);
} }
size+=16; size += 16;
ras=strchr(size,0x0d)-1; ras = strchr(size, 0x0d) - 1;
content=strstr(size,"\x0d\x0a\x0d\x0a")+4; content = strstr(size, "\x0d\x0a\x0d\x0a") + 4;
tam=0; inc=1; tam = 0;
for(;ras>=size;ras--) { inc = 1;
if (*ras>='0' && *ras<='9') for (; ras >= size; ras--)
tam+=(*ras-'0')*inc; {
if (*ras >= '0' && *ras <= '9')
tam += (*ras - '0') * inc;
else else
break; break;
inc*=10; inc *= 10;
} }
if(tam>1024) tam=1024; if (tam > 1024)
tam = 1024;
fwrite(content, tam, 1, stdout); fwrite(content, tam, 1, stdout);
} }

View file

@ -32,612 +32,664 @@
#include "language.h" #include "language.h"
int len; int len;
struct objeto * ob; struct objeto *ob;
struct objeto * ob2; struct objeto *ob2;
int creaobj; int creaobj;
int numparams; int numparams;
byte decl_struct=0; /* 1 si se está declarando un struct */ byte decl_struct = 0; /* 1 si se está declarando un struct */
byte struct_reserved=0; /* 1 si se está declarando la estructura reserved */ byte struct_reserved = 0; /* 1 si se está declarando la estructura reserved */
/* Errores específicos en la ejecución de una DLL */ /* Errores específicos en la ejecución de una DLL */
void dll_error(int error, ...) void dll_error(int error, ...)
{ {
va_list opparam; va_list opparam;
va_start(opparam,error); va_start(opparam, error);
printf(translate(35), fichdll); print_translate(35, fichdll);
vprintf(translate_dll_error(error-1),opparam); vprintf(translate_dll_error(error - 1), opparam);
printf("\n"); printf("\n");
n_errors++; n_errors++;
} }
int EDIV_Export(char *cadena, int nparam, void *hfuncion)
int EDIV_Export(char* cadena, int nparam, void* hfuncion)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
if(nparam<0) { if (nparam < 0)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
creaobj=crea_objeto((byte*)cadena,nparam); creaobj = crea_objeto((byte *)cadena, nparam);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_function:\t-- ID FUNCION: %d\n" printf("export_function:\t-- ID FUNCION: %d\n"
"export_function:\tCadena exportada: %s\n" "export_function:\tCadena exportada: %s\n"
"export_function:\tN. parametros: %d\n" "export_function:\tN. parametros: %d\n"
"export_function:\tOffset de la funcion: 0x%X\n",n_externs,cadena,nparam,(unsigned int)hfuncion); "export_function:\tOffset de la funcion: 0x%X\n",
#endif n_externs, cadena, nparam, (unsigned int)hfuncion);
#endif
if(creaobj) { if (creaobj)
dll_error(creaobj,cadena); {
dll_error(creaobj, cadena);
return 0; return 0;
} }
ob=o; ob = o;
if (ob->tipo!=tnone) { if (ob->tipo != tnone)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
ob->tipo=tfext; ob->tipo = tfext;
ob->fext.codigo=n_externs; ob->fext.codigo = n_externs;
ob->fext.num_par=nparam; ob->fext.num_par = nparam;
n_externs++; n_externs++;
return 1; return 1;
} }
int EDIV_Export_Entrypoint(int ep, void *hfuncion)
int EDIV_Export_Entrypoint(int ep, void* hfuncion)
{ {
entrypoints[n_entrypoints].tipo=ep; entrypoints[n_entrypoints].tipo = ep;
entrypoints[n_entrypoints].hfuncion=hfuncion; entrypoints[n_entrypoints].hfuncion = hfuncion;
entrypoints[n_entrypoints].dll=numdlls; entrypoints[n_entrypoints].dll = numdlls;
return 0; return 0;
} }
int EDIV_Export_Priority(int priority) int EDIV_Export_Priority(int priority)
{ {
dlls[numdlls].prioridad=priority; dlls[numdlls].prioridad = priority;
return 0; return 0;
} }
int EDIV_Export_Const(char *cadena, int valor)
int EDIV_Export_Const(char* cadena, int valor)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
creaobj=crea_objeto((byte*)cadena,-1); creaobj = crea_objeto((byte *)cadena, -1);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_const:\t-- ID OBJETO: %d\n" printf("export_const:\t-- ID OBJETO: %d\n"
"export_const:\tCadena exportada: %s\n" "export_const:\tCadena exportada: %s\n"
"export_const:\tValor: %d\n" "export_const:\tValor: %d\n"
"export_const:\tOffset del objeto: 0x%X\n",num_obj-1,cadena,valor,(unsigned int)o); "export_const:\tOffset del objeto: 0x%X\n",
#endif num_obj - 1, cadena, valor, (unsigned int)o);
#endif
if(creaobj) { if (creaobj)
dll_error(creaobj,cadena); {
dll_error(creaobj, cadena);
return 0; return 0;
} }
ob=o; ob = o;
if (ob->tipo!=tnone) { if (ob->tipo != tnone)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
ob->tipo=tcons; ob->tipo = tcons;
ob->cons.valor=valor; ob->cons.valor = valor;
ob->cons.literal=0; ob->cons.literal = 0;
return 1; return 1;
} }
int EDIV_Export_Global(char *cadena, int valor)
int EDIV_Export_Global(char* cadena, int valor)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
creaobj=crea_objeto((byte*)cadena,-1); creaobj = crea_objeto((byte *)cadena, -1);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_global:\t-- ID OBJETO: %d\n" printf("export_global:\t-- ID OBJETO: %d\n"
"export_global:\tCadena exportada: %s\n" "export_global:\tCadena exportada: %s\n"
"export_global:\tValor: %d\n" "export_global:\tValor: %d\n"
"export_global:\tOffset del objeto: 0x%X\n",num_obj-1,cadena,valor,(unsigned int)o); "export_global:\tOffset del objeto: 0x%X\n",
#endif num_obj - 1, cadena, valor, (unsigned int)o);
#endif
if(creaobj) { if (creaobj)
dll_error(creaobj,cadena); {
dll_error(creaobj, cadena);
return 0; return 0;
} }
ob=o; ob = o;
if (ob->tipo!=tnone) { if (ob->tipo != tnone)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
indexa_variable(v_global,cadena,imem); indexa_variable(v_global, cadena, imem);
ob->tipo=tvglo; ob->tipo = tvglo;
ob->vglo.offset=imem; ob->vglo.offset = imem;
mem[imem]=valor; mem[imem] = valor;
return imem++; return imem++;
} }
int EDIV_Export_Global_Tab(char *cadena, int numregs)
int EDIV_Export_Global_Tab(char* cadena, int numregs)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
creaobj=crea_objeto((byte*)cadena,-1); creaobj = crea_objeto((byte *)cadena, -1);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_global_tab:\t-- ID OBJETO: %d\n" printf("export_global_tab:\t-- ID OBJETO: %d\n"
"export_global_tab:\tCadena exportada: %s\n" "export_global_tab:\tCadena exportada: %s\n"
"export_global_tab:\tN.regs: %d\n" "export_global_tab:\tN.regs: %d\n"
"export_global_tab:\tOffset del objeto: 0x%X\n",num_obj-1,cadena,numregs,(unsigned int)o); "export_global_tab:\tOffset del objeto: 0x%X\n",
#endif num_obj - 1, cadena, numregs, (unsigned int)o);
#endif
if(creaobj) { if (creaobj)
dll_error(creaobj,cadena); {
dll_error(creaobj, cadena);
return 0; return 0;
} }
ob=o; ob = o;
if (ob->tipo!=tnone) { if (ob->tipo != tnone)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
indexa_variable(v_global,cadena,imem); indexa_variable(v_global, cadena, imem);
ob->tipo=ttglo; ob->tipo = ttglo;
ob->tglo.offset=imem; ob->tglo.offset = imem;
ob->tglo.len1=len=numregs; ob->tglo.len1 = len = numregs;
ob->tglo.len2=-1; ob->tglo.len2 = -1;
ob->tglo.len3=-1; ob->tglo.len3 = -1;
ob->tglo.totalen=len+1; ob->tglo.totalen = len + 1;
/* Inicializamos la tabla a 0 */ /* Inicializamos la tabla a 0 */
do { do
mem[imem++]=0; {
mem[imem++] = 0;
} while (len--); } while (len--);
return ob->tglo.offset; return ob->tglo.offset;
} }
int EDIV_Export_Global_Struct(char *cadena, int numregs)
int EDIV_Export_Global_Struct(char* cadena, int numregs)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
creaobj=crea_objeto((byte*)cadena,-1); creaobj = crea_objeto((byte *)cadena, -1);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_global_struct:\t-- ID OBJETO: %d\n" printf("export_global_struct:\t-- ID OBJETO: %d\n"
"export_global_struct:\tCadena exportada: %s\n" "export_global_struct:\tCadena exportada: %s\n"
"export_global_struct:\tN.regs: %d\n" "export_global_struct:\tN.regs: %d\n"
"export_global_struct:\tOffset del objeto: 0x%X\n",num_obj-1,cadena,numregs,(unsigned int)o); "export_global_struct:\tOffset del objeto: 0x%X\n",
#endif num_obj - 1, cadena, numregs, (unsigned int)o);
#endif
if(creaobj) { if (creaobj)
dll_error(creaobj,cadena); {
dll_error(creaobj, cadena);
return 0; return 0;
} }
ob=o; ob = o;
if (ob->tipo!=tnone) { if (ob->tipo != tnone)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
indexa_variable(v_global,cadena,imem); indexa_variable(v_global, cadena, imem);
decl_struct=1; decl_struct = 1;
ob->tipo=tsglo; ob->tipo = tsglo;
ob->sglo.offset=imem; ob->sglo.offset = imem;
ob->sglo.items1=numregs; ob->sglo.items1 = numregs;
ob->sglo.items2=ob->sglo.items3=-1; ob->sglo.items2 = ob->sglo.items3 = -1;
ob->sglo.totalitems=numregs+1; ob->sglo.totalitems = numregs + 1;
ob->sglo.len_item=0; ob->sglo.len_item = 0;
member=ob; member = ob;
len=0; len = 0;
return imem; return imem;
} }
int EDIV_Export_Member_Int(char *cadena, int valor)
int EDIV_Export_Member_Int(char* cadena, int valor)
{ {
if(!decl_struct) { if (!decl_struct)
dll_error(7,cadena); {
dll_error(7, cadena);
return 0; return 0;
} }
creaobj=crea_objeto((byte*)cadena,-1); creaobj = crea_objeto((byte *)cadena, -1);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_member_int:\t-- ID OBJETO: %d\n" printf("export_member_int:\t-- ID OBJETO: %d\n"
"export_member_int:\tCadena exportada: %s\n" "export_member_int:\tCadena exportada: %s\n"
"export_member_int:\tValor: %d\n" "export_member_int:\tValor: %d\n"
"export_member_int:\tOffset del objeto: 0x%X\n",num_obj-1,cadena,valor,(unsigned int)o); "export_member_int:\tOffset del objeto: 0x%X\n",
#endif num_obj - 1, cadena, valor, (unsigned int)o);
#endif
if(creaobj) { if (creaobj)
dll_error(creaobj,cadena); {
dll_error(creaobj, cadena);
return 0; return 0;
} }
ob2=o; ob2 = o;
if ((*ob2).tipo!=tnone) { if ((*ob2).tipo != tnone)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
if(ob->tipo==tsglo) { /* int miembro de struct global */ if (ob->tipo == tsglo)
(*ob2).tipo=tvglo; { /* int miembro de struct global */
(*ob2).vglo.offset=len++; (*ob2).tipo = tvglo;
mem[imem]=valor; (*ob2).vglo.offset = len++;
mem[imem] = valor;
ob->sglo.len_item++; ob->sglo.len_item++;
return imem++; return imem++;
} }
else { /* int miembro de struct local */ else
if(struct_reserved) { /* int miembro de struct local */
indexa_variable(v_reserved,cadena,iloc); if (struct_reserved)
(*ob2).tipo=tvloc; indexa_variable(v_reserved, cadena, iloc);
(*ob2).vloc.offset=len++; (*ob2).tipo = tvloc;
loc[iloc]=valor; (*ob2).vloc.offset = len++;
loc[iloc] = valor;
ob->sloc.len_item++; ob->sloc.len_item++;
return iloc++; return iloc++;
} }
} }
int EDIV_Export_Member_Str(char *cadena, int tamano)
int EDIV_Export_Member_Str(char* cadena, int tamano)
{ {
if(!decl_struct) { if (!decl_struct)
dll_error(7,cadena); {
dll_error(7, cadena);
return 0; return 0;
} }
creaobj=crea_objeto((byte*)cadena,-1); creaobj = crea_objeto((byte *)cadena, -1);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_member_str:\t-- ID OBJETO: %d\n" printf("export_member_str:\t-- ID OBJETO: %d\n"
"export_member_str:\tCadena exportada: %s\n" "export_member_str:\tCadena exportada: %s\n"
"export_member_str:\tTamano: %d\n" "export_member_str:\tTamano: %d\n"
"export_member_str:\tOffset del objeto: 0x%X\n",num_obj-1,cadena,tamano,(unsigned int)o); "export_member_str:\tOffset del objeto: 0x%X\n",
#endif num_obj - 1, cadena, tamano, (unsigned int)o);
#endif
if(creaobj) { if (creaobj)
dll_error(creaobj,cadena); {
dll_error(creaobj, cadena);
return 0; return 0;
} }
ob2=o; ob2 = o;
if ((*ob2).tipo!=tnone) { if ((*ob2).tipo != tnone)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
if(ob->tipo==tsglo) { /* string miembro de struct global */ if (ob->tipo == tsglo)
{ /* string miembro de struct global */
(*ob2).tipo=tcglo; (*ob2).tipo = tcglo;
(*ob2).cglo.offset=len+1; (*ob2).cglo.offset = len + 1;
if (((*ob2).cglo.totalen=tamano)<0) { if (((*ob2).cglo.totalen = tamano) < 0)
dll_error(8,cadena); {
dll_error(8, cadena);
return 0; return 0;
} }
if ((*ob2).cglo.totalen>0xFFFFF) { if ((*ob2).cglo.totalen > 0xFFFFF)
dll_error(8,cadena); {
dll_error(8, cadena);
return 0; return 0;
} }
mem[imem]=0xDAD00000|(*ob2).cglo.totalen; mem[imem] = 0xDAD00000 | (*ob2).cglo.totalen;
len+=1+((*ob2).cglo.totalen+5)/4; len += 1 + ((*ob2).cglo.totalen + 5) / 4;
mem[imem+1]=0; mem[imem + 1] = 0;
imem+=1+((*ob2).cglo.totalen+5)/4; imem += 1 + ((*ob2).cglo.totalen + 5) / 4;
ob->sglo.len_item+=1+((*ob2).cglo.totalen+5)/4; ob->sglo.len_item += 1 + ((*ob2).cglo.totalen + 5) / 4;
return (*ob2).cglo.offset; return (*ob2).cglo.offset;
} }
else { /* string miembro de struct local */ else
{ /* string miembro de struct local */
(*ob2).tipo=tcloc; (*ob2).tipo = tcloc;
(*ob2).cloc.offset=len+1; (*ob2).cloc.offset = len + 1;
if (((*ob2).cloc.totalen=tamano)<0) { if (((*ob2).cloc.totalen = tamano) < 0)
dll_error(8,cadena); {
dll_error(8, cadena);
return 0; return 0;
} }
if ((*ob2).cloc.totalen>0xFFFFF) { if ((*ob2).cloc.totalen > 0xFFFFF)
dll_error(8,cadena); {
dll_error(8, cadena);
return 0; return 0;
} }
loc[iloc]=0xDAD00000|(*ob2).cloc.totalen; loc[iloc] = 0xDAD00000 | (*ob2).cloc.totalen;
len+=1+((*ob2).cloc.totalen+5)/4; len += 1 + ((*ob2).cloc.totalen + 5) / 4;
loc[iloc+1]=0; loc[iloc + 1] = 0;
iloc+=1+((*ob2).cloc.totalen+5)/4; iloc += 1 + ((*ob2).cloc.totalen + 5) / 4;
ob->sloc.len_item+=1+((*ob2).cloc.totalen+5)/4; ob->sloc.len_item += 1 + ((*ob2).cloc.totalen + 5) / 4;
return (*ob2).cloc.offset; return (*ob2).cloc.offset;
} }
} }
int EDIV_Export_Member_Tab(char *cadena, int numregs)
int EDIV_Export_Member_Tab(char* cadena, int numregs)
{ {
if(!decl_struct) { if (!decl_struct)
dll_error(7,cadena); {
dll_error(7, cadena);
return 0; return 0;
} }
creaobj=crea_objeto((byte*)cadena,-1); creaobj = crea_objeto((byte *)cadena, -1);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_member_tab:\t-- ID OBJETO: %d\n" printf("export_member_tab:\t-- ID OBJETO: %d\n"
"export_member_tab:\tCadena exportada: %s\n" "export_member_tab:\tCadena exportada: %s\n"
"export_member_tab:\tN.regs: %d\n" "export_member_tab:\tN.regs: %d\n"
"export_member_tab:\tOffset del objeto: 0x%X\n",num_obj-1,cadena,numregs,(unsigned int)o); "export_member_tab:\tOffset del objeto: 0x%X\n",
#endif num_obj - 1, cadena, numregs, (unsigned int)o);
#endif
if(creaobj) { if (creaobj)
dll_error(creaobj,cadena); {
dll_error(creaobj, cadena);
return 0; return 0;
} }
ob2=o; ob2 = o;
if ((*ob2).tipo!=tnone) { if ((*ob2).tipo != tnone)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
if(ob->tipo==tsglo) { /* array miembro de struct global */ if (ob->tipo == tsglo)
(*ob2).tipo=ttglo; { /* array miembro de struct global */
(*ob2).tglo.offset=len; (*ob2).tipo = ttglo;
(*ob2).tglo.len1=numregs; (*ob2).tglo.offset = len;
(*ob2).tglo.len2=-1; (*ob2).tglo.len1 = numregs;
(*ob2).tglo.len3=-1; (*ob2).tglo.len2 = -1;
(*ob2).tglo.totalen=numregs+1; (*ob2).tglo.len3 = -1;
len+=numregs+1; (*ob2).tglo.totalen = numregs + 1;
memset(&mem[imem],0,(numregs+1)*4); len += numregs + 1;
imem+=numregs+1; memset(&mem[imem], 0, (numregs + 1) * 4);
ob->sglo.len_item+=numregs+1; imem += numregs + 1;
ob->sglo.len_item += numregs + 1;
return (*ob2).tglo.offset; return (*ob2).tglo.offset;
} }
else { /* array miembro de struct local */ else
if(struct_reserved) { /* array miembro de struct local */
indexa_variable(v_reserved,cadena,iloc); if (struct_reserved)
(*ob2).tipo=ttloc; indexa_variable(v_reserved, cadena, iloc);
(*ob2).tloc.offset=len; (*ob2).tipo = ttloc;
(*ob2).tloc.len1=numregs; (*ob2).tloc.offset = len;
(*ob2).tloc.len2=-1; (*ob2).tloc.len1 = numregs;
(*ob2).tloc.len3=-1; (*ob2).tloc.len2 = -1;
(*ob2).tloc.totalen=numregs+1; (*ob2).tloc.len3 = -1;
len+=numregs+1; (*ob2).tloc.totalen = numregs + 1;
memset(&loc[iloc],0,(numregs+1)*4); len += numregs + 1;
iloc+=numregs+1; memset(&loc[iloc], 0, (numregs + 1) * 4);
ob->sloc.len_item+=numregs+1; iloc += numregs + 1;
ob->sloc.len_item += numregs + 1;
return (*ob2).tloc.offset; return (*ob2).tloc.offset;
} }
} }
int EDIV_Export_EndStruct() int EDIV_Export_EndStruct()
{ {
if(!decl_struct) { if (!decl_struct)
{
dll_error(9); dll_error(9);
return 0; return 0;
} }
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_endstruct:\t--- estructura cerrada\n"); printf("export_endstruct:\t--- estructura cerrada\n");
#endif #endif
member=NULL; member = NULL;
if(ob->tipo==tsglo) { /* cierra estructura global */ if (ob->tipo == tsglo)
if (ob->sglo.len_item==0) { { /* cierra estructura global */
if (ob->sglo.len_item == 0)
{
dll_error(10); dll_error(10);
return 0; return 0;
} }
if (ob->sglo.totalitems>1) { if (ob->sglo.totalitems > 1)
len=(ob->sglo.totalitems-1)*ob->sglo.len_item-1; {
do { len = (ob->sglo.totalitems - 1) * ob->sglo.len_item - 1;
mem[imem]=mem[imem-ob->sglo.len_item]; do
{
mem[imem] = mem[imem - ob->sglo.len_item];
imem++; imem++;
} while (len--); } while (len--);
} }
} }
else { /* cierra estructura local */ else
if (ob->sloc.len_item==0) { { /* cierra estructura local */
if (ob->sloc.len_item == 0)
{
dll_error(10); dll_error(10);
return 0; return 0;
} }
if (ob->sloc.totalitems>1) { if (ob->sloc.totalitems > 1)
len=(ob->sloc.totalitems-1)*ob->sloc.len_item-1; {
do { len = (ob->sloc.totalitems - 1) * ob->sloc.len_item - 1;
loc[iloc]=loc[iloc-ob->sloc.len_item]; do
{
loc[iloc] = loc[iloc - ob->sloc.len_item];
iloc++; iloc++;
} while (len--); } while (len--);
} }
} }
decl_struct=0; decl_struct = 0;
struct_reserved=0; struct_reserved = 0;
return 1; return 1;
} }
int EDIV_Export_Local(char *cadena, int valor)
int EDIV_Export_Local(char* cadena, int valor)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
creaobj=crea_objeto((byte*)cadena,-1); creaobj = crea_objeto((byte *)cadena, -1);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_local:\t-- ID OBJETO: %d\n" printf("export_local:\t-- ID OBJETO: %d\n"
"export_local:\tCadena exportada: %s\n" "export_local:\tCadena exportada: %s\n"
"export_local:\tValor: %d\n" "export_local:\tValor: %d\n"
"export_local:\tOffset del objeto: 0x%X\n",num_obj-1,cadena,valor,(unsigned int)o); "export_local:\tOffset del objeto: 0x%X\n",
#endif num_obj - 1, cadena, valor, (unsigned int)o);
#endif
if(creaobj) { if (creaobj)
dll_error(creaobj,cadena); {
dll_error(creaobj, cadena);
return 0; return 0;
} }
ob=o; ob = o;
if (ob->tipo!=tnone) { if (ob->tipo != tnone)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
indexa_variable(v_local,cadena,iloc); indexa_variable(v_local, cadena, iloc);
ob->tipo=tvloc; ob->tipo = tvloc;
ob->vloc.offset=iloc; ob->vloc.offset = iloc;
loc[iloc]=valor; loc[iloc] = valor;
return iloc++; return iloc++;
} }
int EDIV_Export_Local_Tab(char *cadena, int numregs)
int EDIV_Export_Local_Tab(char* cadena, int numregs)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
creaobj=crea_objeto((byte*)cadena,-1); creaobj = crea_objeto((byte *)cadena, -1);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_local_tab:\t-- ID OBJETO: %d\n" printf("export_local_tab:\t-- ID OBJETO: %d\n"
"export_local_tab:\tCadena exportada: %s\n" "export_local_tab:\tCadena exportada: %s\n"
"export_local_tab:\tN.regs: %d\n" "export_local_tab:\tN.regs: %d\n"
"export_local_tab:\tOffset del objeto: 0x%X\n",num_obj-1,cadena,numregs,(unsigned int)o); "export_local_tab:\tOffset del objeto: 0x%X\n",
#endif num_obj - 1, cadena, numregs, (unsigned int)o);
#endif
if(creaobj) { if (creaobj)
dll_error(creaobj,cadena); {
dll_error(creaobj, cadena);
return 0; return 0;
} }
ob=o; ob = o;
if (ob->tipo!=tnone) { if (ob->tipo != tnone)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
indexa_variable(v_local,cadena,iloc); indexa_variable(v_local, cadena, iloc);
ob->tipo=ttloc; ob->tipo = ttloc;
ob->tloc.offset=iloc; ob->tloc.offset = iloc;
ob->tloc.len1=len=numregs; ob->tloc.len1 = len = numregs;
ob->tloc.len2=-1; ob->tloc.len2 = -1;
ob->tloc.len3=-1; ob->tloc.len3 = -1;
ob->tloc.totalen=len+1; ob->tloc.totalen = len + 1;
/* Inicializamos la tabla a 0 */ /* Inicializamos la tabla a 0 */
do { do
loc[iloc++]=0; {
loc[iloc++] = 0;
} while (len--); } while (len--);
return ob->tloc.offset; return ob->tloc.offset;
} }
int EDIV_Export_Local_Struct(char *cadena, int numregs)
int EDIV_Export_Local_Struct(char* cadena, int numregs)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
creaobj=crea_objeto((byte*)cadena,-1); creaobj = crea_objeto((byte *)cadena, -1);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_local_struct:\t-- ID OBJETO: %d\n" printf("export_local_struct:\t-- ID OBJETO: %d\n"
"export_local_struct:\tCadena exportada: %s\n" "export_local_struct:\tCadena exportada: %s\n"
"export_local_struct:\tN.regs: %d\n" "export_local_struct:\tN.regs: %d\n"
"export_local_struct:\tOffset del objeto: 0x%X\n",num_obj-1,cadena,numregs,(unsigned int)o); "export_local_struct:\tOffset del objeto: 0x%X\n",
#endif num_obj - 1, cadena, numregs, (unsigned int)o);
#endif
if(creaobj) { if (creaobj)
dll_error(creaobj,cadena); {
dll_error(creaobj, cadena);
return 0; return 0;
} }
ob=o; ob = o;
if (ob->tipo!=tnone) { if (ob->tipo != tnone)
dll_error(5,cadena); {
dll_error(5, cadena);
return 0; return 0;
} }
decl_struct=1; decl_struct = 1;
if(!strcmp(cadena,"reserved")) { if (!strcmp(cadena, "reserved"))
struct_reserved=1; {
struct_reserved = 1;
} }
else { else
indexa_variable(v_local,cadena,iloc); {
indexa_variable(v_local, cadena, iloc);
} }
ob->tipo=tsloc; ob->tipo = tsloc;
ob->sloc.offset=iloc; ob->sloc.offset = iloc;
ob->sloc.items1=numregs; ob->sloc.items1 = numregs;
ob->sloc.items2=ob->sloc.items3=-1; ob->sloc.items2 = ob->sloc.items3 = -1;
ob->sloc.totalitems=numregs+1; ob->sloc.totalitems = numregs + 1;
ob->sloc.len_item=0; ob->sloc.len_item = 0;
member=ob; member = ob;
len=0; len = 0;
return iloc; return iloc;
} }

View file

@ -110,7 +110,7 @@ void _encriptar(int encode, char * fichero, char * clave)
fseek(f,0,SEEK_END); fseek(f,0,SEEK_END);
size=ftell(f); size=ftell(f);
if ((ptr=(byte *)malloc(size))!=NULL) { if ((ptr=malloc(size))!=NULL) {
fseek(f,0,SEEK_SET); fseek(f,0,SEEK_SET);
if(fread(ptr,1,size,f) ==(unsigned int) size) { if(fread(ptr,1,size,f) ==(unsigned int) size) {
fclose(f); fclose(f);
@ -181,7 +181,7 @@ void _comprimir(int encode, char *fichero) {
fseek(f,0,SEEK_END); fseek(f,0,SEEK_END);
size=ftell(f); size=ftell(f);
if ((ptr=(byte *)malloc(size))!=NULL) { if ((ptr=malloc(size))!=NULL) {
fseek(f,0,SEEK_SET); fseek(f,0,SEEK_SET);
if(fread(ptr,1,size,f) == size) { if(fread(ptr,1,size,f) == size) {
@ -203,7 +203,7 @@ void _comprimir(int encode, char *fichero) {
return; return;
size2=size+size/100+256; size2=size+size/100+256;
if ((ptr_dest=(byte *)malloc(size2))==NULL) { if ((ptr_dest=malloc(size2))==NULL) {
e_free(ptr); e_free(ptr);
return; return;
} }
@ -226,7 +226,7 @@ void _comprimir(int encode, char *fichero) {
size2=*(int*)(ptr+8); size2=*(int*)(ptr+8);
if ((ptr_dest=(byte *)malloc(size2))==NULL) { if ((ptr_dest=malloc(size2))==NULL) {
e_free(ptr); e_free(ptr);
return; return;
} }

File diff suppressed because it is too large Load diff

View file

@ -18,20 +18,21 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> #include <windows.h>
#else #else
# include <stdlib.h> #include <stdlib.h>
# include <string.h> #include <string.h>
#include <stdarg.h>
#endif #endif
#include "shared.h" #include "shared.h"
#include "language.h" #include "language.h"
#include "edivcfg/iniparser.h" #include "edivcfg/iniparser.h"
static char *ediv_strlwr(char *str);
int detecta_idioma_iso(char* lang) int detecta_idioma_iso(char *lang)
{ {
int i; int i;
static char getid[NUM_LANGUAGES][3] = { static char getid[NUM_LANGUAGES][3] = {
@ -42,24 +43,28 @@ int detecta_idioma_iso(char* lang)
"ca", /* catalán */ "ca", /* catalán */
"eu" /* euskera */ "eu" /* euskera */
}; };
if(lang==NULL) return DEFAULT_LANGUAGE; if (lang == NULL)
if(strlen(lang)>2) lang[2]=0; return DEFAULT_LANGUAGE;
strlwr(lang); if (strlen(lang) > 2)
for(i=0;i<NUM_LANGUAGES;i++) lang[2] = 0;
if(lang[0]==getid[i][0]) ediv_strlwr(lang);
if(lang[1]==getid[i][1]) for (i = 0; i < NUM_LANGUAGES; i++)
if (lang[0] == getid[i][0])
if (lang[1] == getid[i][1])
break; break;
if(i==NUM_LANGUAGES) i=DEFAULT_LANGUAGE; if (i == NUM_LANGUAGES)
i = DEFAULT_LANGUAGE;
return i; return i;
} }
int detecta_idioma() int detecta_idioma()
{ {
char* langcfg=NULL; char *langcfg = NULL;
if (ini!=NULL) langcfg=iniparser_getstr(ini,"general:lang"); if (ini != NULL)
if(langcfg==NULL) { langcfg = iniparser_getstr(ini, "general:lang");
#ifdef _WIN32 if (langcfg == NULL)
{
#ifdef _WIN32
int i; int i;
static int getid[NUM_LANGUAGES] = { static int getid[NUM_LANGUAGES] = {
0x0a, /* español */ 0x0a, /* español */
@ -71,22 +76,26 @@ int detecta_idioma()
}; };
LANGID lang; LANGID lang;
lang=GetSystemDefaultLangID()&0xff; lang = GetSystemDefaultLangID() & 0xff;
for(i=0;i<NUM_LANGUAGES;i++) for (i = 0; i < NUM_LANGUAGES; i++)
if(lang==getid[i]) break; if (lang == getid[i])
if(i==NUM_LANGUAGES) i=DEFAULT_LANGUAGE; break;
if (i == NUM_LANGUAGES)
i = DEFAULT_LANGUAGE;
return i; return i;
#else #else
langcfg=getenv("LANG"); langcfg = getenv("LANG");
if(langcfg==NULL) return DEFAULT_LANGUAGE; if (langcfg == NULL)
else return detecta_idioma_iso(langcfg); return DEFAULT_LANGUAGE;
#endif else
return detecta_idioma_iso(langcfg);
#endif
} }
else return detecta_idioma_iso(langcfg); else
return detecta_idioma_iso(langcfg);
} }
char *translate_error(int num)
char* translate_error(int num)
{ {
static char *e[NUM_LANGUAGES][74] = { static char *e[NUM_LANGUAGES][74] = {
@ -99,7 +108,7 @@ char* translate_error(int num)
return e[idioma][num]; return e[idioma][num];
} }
char* translate_warning(int num) char *translate_warning(int num)
{ {
static char *e[NUM_LANGUAGES][3] = { static char *e[NUM_LANGUAGES][3] = {
@ -112,7 +121,7 @@ char* translate_warning(int num)
return e[idioma][num]; return e[idioma][num];
} }
char* translate_dll_error(int num) char *translate_dll_error(int num)
{ {
static char *e[NUM_LANGUAGES][10] = { static char *e[NUM_LANGUAGES][10] = {
@ -123,7 +132,7 @@ char* translate_dll_error(int num)
return e[idioma][num]; return e[idioma][num];
} }
char* translate_ltlex_error(int num) char *translate_ltlex_error(int num)
{ {
static char *e[NUM_LANGUAGES][5] = { static char *e[NUM_LANGUAGES][5] = {
@ -134,8 +143,7 @@ char* translate_ltlex_error(int num)
return e[idioma][num]; return e[idioma][num];
} }
char *translate(int num)
char* translate(int num)
{ {
static char *e[NUM_LANGUAGES][74] = { static char *e[NUM_LANGUAGES][74] = {
@ -145,3 +153,45 @@ char* translate(int num)
}; };
return e[idioma][num]; return e[idioma][num];
} }
void print_translate(int num, ...)
{
va_list arg_ptr;
const char *message = translate(num);
size_t msglen = strlen(message);
char *strbuf = malloc(msglen + 1);
va_start(arg_ptr, message);
vsprintf(strbuf, message, arg_ptr);
va_end(arg_ptr);
printf("%s", strbuf);
free(strbuf);
}
const char *get_translate(int num, ...)
{
va_list arg_ptr;
const char *message = translate(num);
size_t msglen = strlen(message);
char *strbuf = malloc(msglen + 1);
va_start(arg_ptr, message);
vsprintf(strbuf, message, arg_ptr);
va_end(arg_ptr);
return strbuf;
}
static char *ediv_strlwr(char *str)
{
unsigned char *p = (unsigned char *)str;
while (*p)
{
*p = tolower((unsigned char)*p);
p++;
}
return str;
}

File diff suppressed because it is too large Load diff

View file

@ -33,120 +33,152 @@
void ltlex_error(int error) void ltlex_error(int error)
{ {
if(error==1) if (error == 1)
printf(translate(40),translate_ltlex_error(error)); print_translate(40, translate_ltlex_error(error));
else else
printf(translate(41),"ltlex.def",linea,translate_ltlex_error(error)); print_translate(41, "ltlex.def", linea, translate_ltlex_error(error));
printf(translate(42)); print_translate(42);
exit(1); exit(1);
} }
void analiza_ltlex(void){ void analiza_ltlex(void)
{
byte *_buf, * buf; /* Buffer del texto y puntero al carácter actual */ byte *_buf, *buf; /* Buffer del texto y puntero al carácter actual */
byte cont=1; /* 0 indica final del archivo */ byte cont = 1; /* 0 indica final del archivo */
int len; /* Tamaño del archivo */ int len; /* Tamaño del archivo */
struct lex_ele * e; /* Puntero al lex_case correspondiente */ struct lex_ele *e; /* Puntero al lex_case correspondiente */
FILE * def; /* Stream del fichero */ FILE *def; /* Stream del fichero */
int t; /* token (pieza) */ int t; /* token (pieza) */
byte h; /* hash (para id) */ byte h; /* hash (para id) */
byte * _ivnom; byte *_ivnom;
byte * * ptr; byte **ptr;
/* Busca el archivo ltlex.def */ /* Busca el archivo ltlex.def */
if ((def=fopen("system/ltlex.def","rb"))==NULL) if ((def = fopen("system/ltlex.def", "rb")) == NULL)
ltlex_error(1); ltlex_error(1);
/* Lo lee */ /* Lo lee */
fseek(def,0,SEEK_END); fseek(def, 0, SEEK_END);
len=ftell(def); len = ftell(def);
_buf=buf=(byte *) e_malloc(len+1); _buf = buf = e_malloc(len + 1);
fseek(def,0,SEEK_SET); fseek(def, 0, SEEK_SET);
len=fread(buf,1,len,def); len = fread(buf, 1, len, def);
/* El carácter ASCII 0 indica final del fichero */ /* El carácter ASCII 0 indica final del fichero */
*(buf+len)=0; *(buf + len) = 0;
#ifdef _DEBUG #ifdef _DEBUG
printf("dbg: tamano ltlex: %d\n",len); printf("dbg: tamano ltlex: %d\n", len);
#endif #endif
linea=1; linea = 1;
do { do
switch (*buf++) { {
switch (*buf++)
{
/* Fin de fichero */ /* Fin de fichero */
case 0: case 0:
cont=0; break; cont = 0;
break;
/* Ignoramos los espacios */ /* Ignoramos los espacios */
case ' ': case ' ':
case tab: case tab:
break; break;
/* Salta de linea */ /* Salta de linea */
case cr: case cr:
if(*buf==lf) buf++; if (*buf == lf)
buf++;
case lf: case lf:
linea++; linea++;
break; break;
/* Los ; indican línea de comentario */ /* Los ; indican línea de comentario */
case ';': case ';':
while (*buf!=cr && *buf!=lf) buf++; break; while (*buf != cr && *buf != lf)
buf++;
break;
/* El símbolo & indica definición de token */ /* El símbolo & indica definición de token */
case '&': case '&':
*buf=lower[*buf]; *buf = lower[*buf];
if (*buf>='0' && *buf<='9') if (*buf >= '0' && *buf <= '9')
t=(*buf++-'0')<<4; t = (*buf++ - '0') << 4;
else else if (*buf >= 'a' && *buf <= 'f')
if (*buf>='a' && *buf<='f') t = (*buf++ - 'a' + 10) << 4;
t=(*buf++-'a'+10)<<4;
else else
ltlex_error(2); ltlex_error(2);
*buf=lower[*buf]; *buf = lower[*buf];
if (*buf>='0' && *buf<='9') if (*buf >= '0' && *buf <= '9')
t+=(*buf++-'0'); t += (*buf++ - '0');
else else if (*buf >= 'a' && *buf <= 'f')
if (*buf>='a' && *buf<='f') t += (*buf++ - 'a' + 10);
t+=(*buf++-'a'+10);
else else
ltlex_error(2); ltlex_error(2);
if (*buf==cr || *buf==lf || *buf==' ' || *buf==tab) break; if (*buf == cr || *buf == lf || *buf == ' ' || *buf == tab)
else if (lower[*buf]) { /* Analiza una palabra reservada */ break;
_ivnom=ivnom.b; *ivnom.p++=0; *ivnom.p++=(unsigned char*)t; h=0; else if (lower[*buf])
while ((*ivnom.b=lower[*buf++])) h=((byte)(h<<1)+(h>>7))^(*ivnom.b++); { /* Analiza una palabra reservada */
ptr=&vhash[h]; while (*ptr) ptr=(unsigned char * *)*ptr; *ptr=_ivnom; _ivnom = ivnom.b;
buf--; ivnom.b++; *ivnom.p++ = 0;
} else if (t>=0x78 && t<=0x7b) { /* Analiza un delimitador de literal */ *ivnom.p++ = (unsigned char *)t;
lex_case[*buf]=(struct lex_ele*)l_lit; h = 0;
} else { /* Analiza un nuevo símbolo */ while ((*ivnom.b = lower[*buf++]))
if ((e=lex_case[*buf])==0) { h = ((byte)(h << 1) + (h >> 7)) ^ (*ivnom.b++);
if (num_nodos++==max_nodos) ptr = &vhash[h];
while (*ptr)
ptr = (unsigned char **)*ptr;
*ptr = _ivnom;
buf--;
ivnom.b++;
}
else if (t >= 0x78 && t <= 0x7b)
{ /* Analiza un delimitador de literal */
lex_case[*buf] = (struct lex_ele *)l_lit;
}
else
{ /* Analiza un nuevo símbolo */
if ((e = lex_case[*buf]) == 0)
{
if (num_nodos++ == max_nodos)
ltlex_error(3); ltlex_error(3);
e=lex_case[*buf]=ilex_simb++; e = lex_case[*buf] = ilex_simb++;
e->caracter=*buf++; e->caracter = *buf++;
} }
else else
buf++; buf++;
while (*buf!=' ' && *buf!=tab && *buf!=cr) { while (*buf != ' ' && *buf != tab && *buf != cr)
if (lower[*buf]) ltlex_error(4); {
if (e->siguiente==0) if (lower[*buf])
if (num_nodos++==max_nodos) ltlex_error(3); ltlex_error(4);
else e=e->siguiente=ilex_simb++; if (e->siguiente == 0)
else { if (num_nodos++ == max_nodos)
e=e->siguiente; ltlex_error(3);
while (e->caracter!=*buf && e->alternativa) else
e=e->alternativa; e = e->siguiente = ilex_simb++;
if (e->caracter!=*buf) { else
if (num_nodos++==max_nodos) ltlex_error(3); {
else e=e->alternativa=ilex_simb++; e = e->siguiente;
while (e->caracter != *buf && e->alternativa)
e = e->alternativa;
if (e->caracter != *buf)
{
if (num_nodos++ == max_nodos)
ltlex_error(3);
else
e = e->alternativa = ilex_simb++;
} }
} }
e->caracter=*buf++; e->caracter = *buf++;
} }
e->token=t; e->token = t;
} break; }
}} while (cont); break;
}
} while (cont);
e_free(_buf); _buf=NULL; e_free(_buf);
fclose(def); def=NULL; _buf = NULL;
fclose(def);
def = NULL;
} }

View file

@ -19,12 +19,12 @@
*/ */
#ifdef _WIN32 #ifdef _WIN32
#include "dll_load.h" #include "dll_load.h"
#include <io.h> #include <io.h>
#else #else
#include <dlfcn.h> #include <dlfcn.h>
#include <dirent.h> #include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#include <string.h> #include <string.h>
@ -39,139 +39,142 @@ int imem_temp;
int iloc_temp; int iloc_temp;
/* obtiene el nombre esencial de la libreria (sin extension ni path) */ /* obtiene el nombre esencial de la libreria (sin extension ni path) */
void get_rawname(char* completo, char* rawname) void get_rawname(char *completo, char *rawname)
{ {
char* p=completo; char *p = completo;
int i; int i;
for(i=strlen(completo)-1;i>0;i--) for (i = strlen(completo) - 1; i > 0; i--)
if(completo[i]=='\\' || completo[i]=='/') { if (completo[i] == '\\' || completo[i] == '/')
p=&completo[i+1]; {
p = &completo[i + 1];
break; break;
} }
strcpy(rawname,p); strcpy(rawname, p);
i=strlen(rawname); i = strlen(rawname);
#ifdef _WIN32 #ifdef _WIN32
if (rawname[i-4]=='.' && (rawname[i-3]=='d' || rawname[i-3]=='D') if (rawname[i - 4] == '.' && (rawname[i - 3] == 'd' || rawname[i - 3] == 'D') && (rawname[i - 2] == 'l' || rawname[i - 2] == 'L') && (rawname[i - 1] == 'l' || rawname[i - 1] == 'L'))
&& (rawname[i-2]=='l' || rawname[i-2]=='L')
&& (rawname[i-1]=='l' || rawname[i-1]=='L'))
rawname[i-4]=0; rawname[i - 4] = 0;
#else #else
if(rawname[i-3]=='.' && (rawname[i-2]=='s' || rawname[i-2]=='S') if (rawname[i - 3] == '.' && (rawname[i - 2] == 's' || rawname[i - 2] == 'S') && (rawname[i - 1] == 'o' || rawname[i - 1] == 'O'))
&& (rawname[i-1]=='o' || rawname[i-1]=='O'))
rawname[i-3]=0; rawname[i - 3] = 0;
#endif #endif
} }
/* compara prioridades de dos dlls, para el qsort descendente */ /* compara prioridades de dos dlls, para el qsort descendente */
int compara(const void* _a, const void* _b) int compara(const void *_a, const void *_b)
{ {
struct _dlls a=*(struct _dlls*)_a; struct _dlls a = *(struct _dlls *)_a;
struct _dlls b=*(struct _dlls*)_b; struct _dlls b = *(struct _dlls *)_b;
return a.prioridad<b.prioridad?1:(a.prioridad>b.prioridad?-1:0); return a.prioridad < b.prioridad ? 1 : (a.prioridad > b.prioridad ? -1 : 0);
} }
int compara2(const void* _a, const void* _b) int compara2(const void *_a, const void *_b)
{ {
int a=*(int*)_a; int a = *(int *)_a;
int b=*(int*)_b; int b = *(int *)_b;
return dlls[a].prioridad<dlls[b].prioridad?1:(dlls[a].prioridad>dlls[b].prioridad?-1:0); return dlls[a].prioridad < dlls[b].prioridad ? 1 : (dlls[a].prioridad > dlls[b].prioridad ? -1 : 0);
} }
void dll_func() void dll_func()
{ {
char dllkey[256]="dll_priority:"; char dllkey[256] = "dll_priority:";
char rawname[256]; char rawname[256];
int carga=1; int carga = 1;
char *dir=NULL; char *dir = NULL;
int i; int i;
#ifdef _WIN32 #ifdef _WIN32
int buscafich; int buscafich;
struct _finddata_t fichero_dll; /* busqueda de DLLs */ struct _finddata_t fichero_dll; /* busqueda de DLLs */
char mask[256]; char mask[256];
#else #else
DIR *directorio; DIR *directorio;
struct dirent *fichero_dll; struct dirent *fichero_dll;
#endif #endif
numdlls=0; numdlls = 0;
n_externs=0; n_externs = 0;
#ifdef _WIN32 #ifdef _WIN32
/* Inicializa la carga de DLLs */ /* Inicializa la carga de DLLs */
CheckWindowsVersion(); CheckWindowsVersion();
InitializeDLLLoad(); InitializeDLLLoad();
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
if (ini) if (ini)
dir=iniparser_getstr(ini,"dll:windll"); dir = iniparser_getstr(ini, "dll:windll");
if (!dir) if (!dir)
dir="dll"; dir = "dll";
strcpy(mask,dir); strcpy(mask, dir);
strcat(mask,"\\*.dll"); strcat(mask, "\\*.dll");
/* Busca las DLLs que hay en el directorio */ /* Busca las DLLs que hay en el directorio */
buscafich = _findfirst(mask, &fichero_dll); buscafich = _findfirst(mask, &fichero_dll);
if (buscafich==-1) if (buscafich == -1)
printf(translate(43)); /* no hay dlls */ print_translate(43); /* no hay dlls */
#ifdef _DEBUG
printf("dbg: DLL encontrada: %s\n", fichero_dll.name);
#endif
#ifdef _DEBUG sprintf(fichdll, "%s\\%s", dir, fichero_dll.name);
printf("dbg: DLL encontrada: %s\n",fichero_dll.name);
#endif
sprintf(fichdll,"%s\\%s",dir,fichero_dll.name); get_rawname(fichero_dll.name, rawname);
strcat(dllkey, rawname);
get_rawname(fichero_dll.name,rawname);
strcat(dllkey,rawname);
if (ini) if (ini)
if (iniparser_getint(ini,dllkey,0)<=P_NUNCA) if (iniparser_getint(ini, dllkey, 0) <= P_NUNCA)
carga=0; carga = 0;
if (carga) if (carga)
if(!leedll()) { if (!leedll())
dlls[numdlls].prioridad=0; {
dlls[numdlls].prioridad = 0;
/* guarda el nombre de fichero en la tabla de DLLs */ /* guarda el nombre de fichero en la tabla de DLLs */
dlls[0].nombre=(char*)e_malloc(strlen(rawname)+1); dlls[0].nombre = e_malloc(strlen(rawname) + 1);
strcpy(dlls[0].nombre,rawname); strcpy(dlls[0].nombre, rawname);
/* importa las funciones de la DLL */ /* importa las funciones de la DLL */
if (ini) if (ini)
dlls[numdlls].prioridad=iniparser_getint(ini,dllkey,dlls[numdlls].prioridad); dlls[numdlls].prioridad = iniparser_getint(ini, dllkey, dlls[numdlls].prioridad);
numdlls=1; numdlls = 1;
} }
/* hace lo mismo con el resto */ /* hace lo mismo con el resto */
while(1) { while (1)
if(_findnext(buscafich,&fichero_dll)==0) { {
#ifdef _DEBUG if (_findnext(buscafich, &fichero_dll) == 0)
printf("dbg: DLL encontrada: %s\n",fichero_dll.name); {
#endif #ifdef _DEBUG
carga=1; printf("dbg: DLL encontrada: %s\n", fichero_dll.name);
sprintf(fichdll,"%s\\%s",dir,fichero_dll.name); #endif
dlls[numdlls].prioridad=0; carga = 1;
get_rawname(fichero_dll.name,rawname); sprintf(fichdll, "%s\\%s", dir, fichero_dll.name);
strcpy(dllkey,"dll_priority:"); dlls[numdlls].prioridad = 0;
strcat(dllkey,rawname); get_rawname(fichero_dll.name, rawname);
if(ini) if(iniparser_getint(ini,dllkey,0)<=P_NUNCA) carga=0; strcpy(dllkey, "dll_priority:");
if(carga) if(!leedll()) { strcat(dllkey, rawname);
dlls[numdlls].nombre=(char*)e_malloc(strlen(rawname)+1); if (ini)
strcpy(dlls[numdlls].nombre,rawname); if (iniparser_getint(ini, dllkey, 0) <= P_NUNCA)
dlls[numdlls].usado=0; carga = 0;
if(ini) dlls[numdlls].prioridad=iniparser_getint(ini,dllkey,dlls[numdlls].prioridad); if (carga)
if (!leedll())
{
dlls[numdlls].nombre = e_malloc(strlen(rawname) + 1);
strcpy(dlls[numdlls].nombre, rawname);
dlls[numdlls].usado = 0;
if (ini)
dlls[numdlls].prioridad = iniparser_getint(ini, dllkey, dlls[numdlls].prioridad);
numdlls++; numdlls++;
} }
} }
@ -179,19 +182,23 @@ void dll_func()
break; break;
} }
#else /* si estamos en Linux */ #else /* si estamos en Linux */
if(ini) dir=iniparser_getstr(ini,"dll:nixdll"); if (ini)
if(!dir) dir="so"; dir = iniparser_getstr(ini, "dll:nixdll");
if (!dir)
dir = "so";
directorio=opendir(dir); directorio = opendir(dir);
if(!directorio) { if (!directorio)
printf(translate(44),dir); /* no hay directorio so/ */ {
print_translate(44, dir); /* no hay directorio so/ */
exit(1); exit(1);
} }
/* Busca las .so */ /* Busca las .so */
while ((fichero_dll = readdir(directorio)) != 0) { while ((fichero_dll = readdir(directorio)) != 0)
{
/* Salta los directorios actual '.' y padre ".." */ /* Salta los directorios actual '.' y padre ".." */
if (strcmp(fichero_dll->d_name, ".") == 0) if (strcmp(fichero_dll->d_name, ".") == 0)
continue; continue;
@ -199,31 +206,35 @@ void dll_func()
if (strcmp(fichero_dll->d_name, "..") == 0) if (strcmp(fichero_dll->d_name, "..") == 0)
continue; continue;
if(fichero_dll->d_type==DT_REG) { if (fichero_dll->d_type == DT_REG)
char dllkey[256]="dll_priority:"; {
#ifdef _DEBUG char dllkey[256] = "dll_priority:";
printf("dbg: Librería encontrada: %s/%s\n",dir,fichero_dll->d_name); #ifdef _DEBUG
#endif printf("dbg: Librería encontrada: %s/%s\n", dir, fichero_dll->d_name);
carga=1; #endif
sprintf(fichdll,"%s/%s",dir,fichero_dll->d_name); carga = 1;
dlls[numdlls].prioridad=0; sprintf(fichdll, "%s/%s", dir, fichero_dll->d_name);
get_rawname(fichero_dll->d_name,rawname); dlls[numdlls].prioridad = 0;
strcpy(dllkey,"dll_priority:"); get_rawname(fichero_dll->d_name, rawname);
strcat(dllkey,rawname); strcpy(dllkey, "dll_priority:");
strcat(dllkey, rawname);
if (ini) {
if (iniparser_getint(ini,dllkey,0) <= P_NUNCA)
carga=0;
}
if(carga) {
if(!leedll()) {
dlls[numdlls].nombre=(char*)e_malloc(strlen(rawname)+1);
strcpy(dlls[numdlls].nombre,rawname);
dlls[numdlls].usado=0;
if (ini) if (ini)
dlls[numdlls].prioridad=iniparser_getint(ini,dllkey,dlls[numdlls].prioridad); {
if (iniparser_getint(ini, dllkey, 0) <= P_NUNCA)
carga = 0;
}
if (carga)
{
if (!leedll())
{
dlls[numdlls].nombre = e_malloc(strlen(rawname) + 1);
strcpy(dlls[numdlls].nombre, rawname);
dlls[numdlls].usado = 0;
if (ini)
dlls[numdlls].prioridad = iniparser_getint(ini, dllkey, dlls[numdlls].prioridad);
numdlls++; numdlls++;
} }
@ -231,60 +242,64 @@ void dll_func()
} }
} }
#endif #endif
if(numdlls==0) if (numdlls == 0)
printf(translate(43)); /* no hay librerias */ print_translate(43); /* no hay librerias */
nuevo_orden=e_malloc(numdlls*4); nuevo_orden = e_malloc(numdlls * 4);
for(i=0;i<numdlls;i++) for (i = 0; i < numdlls; i++)
nuevo_orden[i]=i; nuevo_orden[i] = i;
qsort(nuevo_orden,numdlls,4,compara2); qsort(nuevo_orden, numdlls, 4, compara2);
qsort(dlls,numdlls,sizeof(struct _dlls),compara); qsort(dlls, numdlls, sizeof(struct _dlls), compara);
#ifdef _DEBUG
for(i=0;i<numdlls;i++)
printf("dbg: %d - %s - prioridad: %d\n",i,dlls[i].nombre,dlls[i].prioridad);
#endif
#ifdef _DEBUG
for (i = 0; i < numdlls; i++)
printf("dbg: %d - %s - prioridad: %d\n", i, dlls[i].nombre, dlls[i].prioridad);
#endif
} }
void dll_func2() void dll_func2()
{ {
int i=numdlls; int i = numdlls;
char* dir=NULL; char *dir = NULL;
n_externs=0; n_externs = 0;
for(i=0;i<numdlls;i++) for (i = 0; i < numdlls; i++)
nuevo_orden[i]=i; nuevo_orden[i] = i;
for(numdlls=0;numdlls<i;numdlls++) { for (numdlls = 0; numdlls < i; numdlls++)
if((dlls[numdlls].prioridad>P_NUNCA) && (dlls[numdlls].usado || dlls[numdlls].prioridad>=P_SIEMPRE)) { {
#ifdef _DEBUG if ((dlls[numdlls].prioridad > P_NUNCA) && (dlls[numdlls].usado || dlls[numdlls].prioridad >= P_SIEMPRE))
printf("dbg: Se requiere %s (id=%d)\n",dlls[numdlls].nombre,numdlls); {
#endif #ifdef _DEBUG
#ifdef _WIN32 printf("dbg: Se requiere %s (id=%d)\n", dlls[numdlls].nombre, numdlls);
if(ini) dir=iniparser_getstr(ini,"dll:windll"); #endif
if(!dir) dir="dll"; #ifdef _WIN32
sprintf(fichdll,"%s\\%s.dll",dir,dlls[numdlls].nombre); if (ini)
#else dir = iniparser_getstr(ini, "dll:windll");
if(ini) dir=iniparser_getstr(ini,"dll:nixdll"); if (!dir)
if(!dir) dir="so"; dir = "dll";
sprintf(fichdll,"%s/%s.so",dir,dlls[numdlls].nombre); sprintf(fichdll, "%s\\%s.dll", dir, dlls[numdlls].nombre);
#endif #else
if (ini)
dir = iniparser_getstr(ini, "dll:nixdll");
if (!dir)
dir = "so";
sprintf(fichdll, "%s/%s.so", dir, dlls[numdlls].nombre);
#endif
if(leedll()) { if (leedll())
printf(translate(45),dlls[numdlls].nombre); /* error al cargar libreria */ {
print_translate(45, dlls[numdlls].nombre); /* error al cargar libreria */
exit(1); exit(1);
} }
} }
} }
} }
int leedll() int leedll()
{ {
TYPEOF_ExportaFuncs *ExportaFuncs; TYPEOF_ExportaFuncs *ExportaFuncs;
@ -292,26 +307,28 @@ int leedll()
HINSTANCE hDLL; HINSTANCE hDLL;
/* Carga la DLL */ /* Carga la DLL */
hDLL=LoadDLL(fichdll); hDLL = LoadDLL(fichdll);
if(hDLL==NULL) { if (hDLL == NULL)
printf(translate(46),fichdll); /* no puedo cargar libreria */ {
print_translate(46, fichdll); /* no puedo cargar libreria */
return 1; return 1;
} }
/* Inicializa y ejecuta la funcion ExportaFuncs de la DLL */ /* Inicializa y ejecuta la funcion ExportaFuncs de la DLL */
ExportaFuncs=NULL; ExportaFuncs = NULL;
ExportaFuncs=(TYPEOF_ExportaFuncs *)GetDLLProcAddress(hDLL,"ExportaFuncs"); ExportaFuncs = (TYPEOF_ExportaFuncs *)GetDLLProcAddress(hDLL, "ExportaFuncs");
if(ExportaFuncs==NULL) { if (ExportaFuncs == NULL)
printf(translate(47),fichdll); /* exportafuncs no encontrado */ {
print_translate(47, fichdll); /* exportafuncs no encontrado */
FreeDLL(hDLL); FreeDLL(hDLL);
return 1; return 1;
} }
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("dbg: ExportaFuncs encontrado!! :D\n"); printf("dbg: ExportaFuncs encontrado!! :D\n");
#endif #endif
ExportaFuncs(EXPORTAFUNCS_PARAMS); ExportaFuncs(EXPORTAFUNCS_PARAMS);
@ -322,28 +339,30 @@ int leedll()
char *errordll; char *errordll;
/* Carga la DLL */ /* Carga la DLL */
hDLL=dlopen(fichdll,RTLD_NOW); hDLL = dlopen(fichdll, RTLD_NOW);
if(!hDLL) { if (!hDLL)
printf(translate(46),fichdll,dlerror()); /* no puedo cargar libreria */ {
print_translate(46, fichdll, dlerror()); /* no puedo cargar libreria */
return 1; return 1;
} }
/* Inicializa y ejecuta la funcion ExportaFuncs de la DLL */ /* Inicializa y ejecuta la funcion ExportaFuncs de la DLL */
ExportaFuncs=NULL; ExportaFuncs = NULL;
ExportaFuncs=(TYPEOF_ExportaFuncs *) dlsym(hDLL,"ExportaFuncs"); ExportaFuncs = (TYPEOF_ExportaFuncs *)dlsym(hDLL, "ExportaFuncs");
if((errordll=dlerror())!=NULL) { if ((errordll = dlerror()) != NULL)
printf(translate(47),fichdll,errordll); /* exportafuncs no encontrado */ {
print_translate(47, fichdll, errordll); /* exportafuncs no encontrado */
dlclose(hDLL); dlclose(hDLL);
return 1; return 1;
} }
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("dbg: ExportaFuncs encontrado!! :D\n"); printf("dbg: ExportaFuncs encontrado!! :D\n");
#endif #endif
ExportaFuncs(EXPORTAFUNCS_PARAMS); ExportaFuncs(EXPORTAFUNCS_PARAMS);
dlclose(hDLL); dlclose(hDLL);

View file

@ -137,10 +137,10 @@ void indexa_variable(tipo_t tipo, char* nombre, int ptr)
#endif #endif
if(varindex) { if(varindex) {
varindex=(varindex_t*)realloc(varindex,sizeof(varindex_t)*(num_indexed_vars+1)); varindex=realloc(varindex,sizeof(varindex_t)*(num_indexed_vars+1));
} }
else { else {
varindex=(varindex_t*)e_malloc(sizeof(varindex_t)*(num_indexed_vars+1)); varindex=e_malloc(sizeof(varindex_t)*(num_indexed_vars+1));
} }
varindex[num_indexed_vars].hash=h; varindex[num_indexed_vars].hash=h;
varindex[num_indexed_vars].tipo=tipo; varindex[num_indexed_vars].tipo=tipo;

View file

@ -137,7 +137,7 @@ void _encriptar(int encode, char * fichero, char * clave)
if ((f=fopen(fichero,"rb"))!=NULL) { if ((f=fopen(fichero,"rb"))!=NULL) {
fseek(f,0,SEEK_END); fseek(f,0,SEEK_END);
size=ftell(f); size=ftell(f);
if ((ptr=(byte *)malloc(size))!=NULL) { if ((ptr=malloc(size))!=NULL) {
fseek(f,0,SEEK_SET); fseek(f,0,SEEK_SET);
if(fread(ptr,1,size,f) ==(unsigned int) size) { if(fread(ptr,1,size,f) ==(unsigned int) size) {
fclose(f); fclose(f);
@ -224,7 +224,7 @@ void _comprimir(int encode, char *fichero)
if ((f=fopen(fichero,"rb"))!=NULL) { if ((f=fopen(fichero,"rb"))!=NULL) {
fseek(f,0,SEEK_END); fseek(f,0,SEEK_END);
size=ftell(f); size=ftell(f);
if ((ptr=(byte *)malloc(size))!=NULL) { if ((ptr=malloc(size))!=NULL) {
fseek(f,0,SEEK_SET); fseek(f,0,SEEK_SET);
if(fread(ptr,1,size,f) == size) { if(fread(ptr,1,size,f) == size) {
fclose(f); fclose(f);
@ -245,7 +245,7 @@ void _comprimir(int encode, char *fichero)
return; return;
stub_size=(int)size; stub_size=(int)size;
size2=size+size/100+256; size2=size+size/100+256;
if ((ptr_dest=(byte *)malloc(size2))==NULL) { if ((ptr_dest=malloc(size2))==NULL) {
free(ptr); free(ptr);
return; return;
} }
@ -268,7 +268,7 @@ void _comprimir(int encode, char *fichero)
return; return;
size2=*(int*)(ptr+8); size2=*(int*)(ptr+8);
stub_size=(int)size2; stub_size=(int)size2;
if ((ptr_dest=(byte *)malloc(size2))==NULL) { if ((ptr_dest=malloc(size2))==NULL) {
free(ptr); free(ptr);
return; return;
} }

View file

@ -124,7 +124,7 @@ static int AddDLLReference(void *pImageBase, char *svName, DWORD dwFlags)
} }
// Add new dll to list // Add new dll to list
cur=(IMAGE_PARAMETERS *)malloc(sizeof(IMAGE_PARAMETERS)); cur=malloc(sizeof(IMAGE_PARAMETERS));
if(cur==NULL) { if(cur==NULL) {
LeaveCriticalSection(&g_DLLCrit); LeaveCriticalSection(&g_DLLCrit);
return -1; return -1;

View file

@ -49,21 +49,22 @@
#define TRANSLATE_RUNTIME_ERROR 7 #define TRANSLATE_RUNTIME_ERROR 7
#define TRANSLATE_CRITICAL_ERROR 8 #define TRANSLATE_CRITICAL_ERROR 8
int idioma; int idioma;
/* comunes */ /* comunes */
int detecta_idioma(); int detecta_idioma();
char* translate(int num); char *translate(int num);
char* translate_dll_error(int num); char *translate_dll_error(int num);
const char *get_translate(int num, ...);
void print_translate(int num, ...);
/* compilador */ /* compilador */
char* translate_error(int num); char *translate_error(int num);
char* translate_warning(int num); char *translate_warning(int num);
char* translate_ltlex_error(int num); char *translate_ltlex_error(int num);
/* stub */ /* stub */
char* translate_runtime_error(int num); char *translate_runtime_error(int num);
char* translate_critical_error(int num); char *translate_critical_error(int num);
#endif /* __EDIV_LANGUAGE_H_ */ #endif /* __EDIV_LANGUAGE_H_ */

View file

@ -124,7 +124,7 @@ static int AddDLLReference(void *pImageBase, char *svName, DWORD dwFlags)
} }
// Add new dll to list // Add new dll to list
cur=(IMAGE_PARAMETERS *)malloc(sizeof(IMAGE_PARAMETERS)); cur=malloc(sizeof(IMAGE_PARAMETERS));
if(cur==NULL) { if(cur==NULL) {
LeaveCriticalSection(&g_DLLCrit); LeaveCriticalSection(&g_DLLCrit);
return -1; return -1;

View file

@ -19,7 +19,7 @@
*/ */
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> #include <windows.h>
#endif #endif
#include <assert.h> #include <assert.h>
@ -44,9 +44,9 @@ struct objeto * ob2;*/
int creaobj; int creaobj;
byte decl_struct=0; // 1 si se está declarando un struct byte decl_struct = 0; // 1 si se está declarando un struct
byte slocal=0; // para las structs. 0=global, 1=local byte slocal = 0; // para las structs. 0=global, 1=local
int nregs; int nregs;
int offset; int offset;
@ -79,24 +79,22 @@ int offset;
return 0; return 0;
}*/ }*/
// Errores específicos en la ejecución de una DLL // Errores específicos en la ejecución de una DLL
void dll_error(int error, ...) void dll_error(int error, ...)
{ {
va_list opparam; va_list opparam;
char mensaje[256]; char mensaje[256];
va_start(opparam,error); va_start(opparam, error);
sprintf(mensaje,translate(3), fichdll); sprintf(mensaje, get_translate(3, fichdll));
vsprintf(mensaje,translate_dll_error(error),opparam); vsprintf(mensaje, get_translate(translate_dll_error(error)), opparam);
#ifdef _WIN32 #ifdef _WIN32
MessageBox(0,mensaje,translate(4),MB_ICONERROR); MessageBox(0,mensaje,print_translate((4),MB_ICONERROR);
#else #else
printf("%s\n",mensaje); printf("%s\n", mensaje);
#endif #endif
//printf("\n"); //printf("\n");
//n_errors++; //n_errors++;
@ -104,25 +102,25 @@ void dll_error(int error, ...)
exit(-1); exit(-1);
} }
int EDIV_Export(char *cadena, int nparam, void *hfuncion)
int EDIV_Export(char* cadena, int nparam, void* hfuncion)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
// creaobj=crea_objeto((byte*)cadena); // creaobj=crea_objeto((byte*)cadena);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_function:\t-- ID FUNCION: %d\n" printf("export_function:\t-- ID FUNCION: %d\n"
"export_function:\tCadena exportada: %s\n" "export_function:\tCadena exportada: %s\n"
"export_function:\tN. parametros: %d\n" "export_function:\tN. parametros: %d\n"
"export_function:\tOffset de la funcion: 0x%X\n",n_externs,cadena,nparam,(unsigned int)hfuncion); "export_function:\tOffset de la funcion: 0x%X\n",
#endif n_externs, cadena, nparam, (unsigned int)hfuncion);
#endif
/* if(creaobj) { /* if(creaobj) {
dll_error(creaobj,cadena); dll_error(creaobj,cadena);
return 0; return 0;
} }
@ -138,56 +136,54 @@ int EDIV_Export(char* cadena, int nparam, void* hfuncion)
ob->fext.codigo=n_externs; ob->fext.codigo=n_externs;
ob->fext.num_par=nparam; // es necesario?*/ ob->fext.num_par=nparam; // es necesario?*/
extfuncs[n_externs]=hfuncion; extfuncs[n_externs] = hfuncion;
extparms[n_externs]=nparam; extparms[n_externs] = nparam;
/* for(i=0;i<numdlls;i++) /* for(i=0;i<numdlls;i++)
for(j=0;j<dlls[i].nfuncs;j++) for(j=0;j<dlls[i].nfuncs;j++)
if(strcmp(cadena,dlls[i].ext_funcs[j].cadena)==0) { if(strcmp(cadena,dlls[i].ext_funcs[j].cadena)==0) {
dll_error(4,cadena); dll_error(4,cadena);
return 0; return 0;
}*/ }*/
/*#define actfunc dlls[numdlls-1].ext_funcs[dlls[numdlls-1].nfuncs] /*#define actfunc dlls[numdlls-1].ext_funcs[dlls[numdlls-1].nfuncs]
actfunc.cadena=(char*)e_malloc(strlen(cadena)+1); actfunc.cadena=e_malloc(strlen(cadena)+1);
strcpy(actfunc.cadena,cadena); strcpy(actfunc.cadena,cadena);
actfunc.nparam = nparam; actfunc.nparam = nparam;
actfunc.hfuncion = hfuncion;*/ actfunc.hfuncion = hfuncion;*/
// dlls[numdlls-1].nfuncs++; // dlls[numdlls-1].nfuncs++;
n_externs++; n_externs++;
return 1; return 1;
} }
int EDIV_Export_Entrypoint(int ep, void *hfuncion)
int EDIV_Export_Entrypoint(int ep, void* hfuncion)
{ {
entrypoints[n_entrypoints].tipo=ep; entrypoints[n_entrypoints].tipo = ep;
entrypoints[n_entrypoints].hfuncion=hfuncion; entrypoints[n_entrypoints].hfuncion = hfuncion;
entrypoints[n_entrypoints++].dll=numdlls; entrypoints[n_entrypoints++].dll = numdlls;
return 0; return 0;
} }
int EDIV_Export_Priority(int priority) int EDIV_Export_Priority(int priority)
{ {
dlls[numdlls].prioridad=priority; dlls[numdlls].prioridad = priority;
return 0; return 0;
} }
int EDIV_Export_Const(char *cadena, int valor)
int EDIV_Export_Const(char* cadena, int valor)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
// sólamente se tendrá que hacer algo en la versión con trazador // sólamente se tendrá que hacer algo en la versión con trazador
/* creaobj=crea_objeto((byte*)cadena); /* creaobj=crea_objeto((byte*)cadena);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_const:\t-- ID OBJETO: %d\n" printf("export_const:\t-- ID OBJETO: %d\n"
@ -215,15 +211,15 @@ int EDIV_Export_Const(char* cadena, int valor)
return 1; return 1;
} }
int EDIV_Export_Global(char *cadena, int valor)
int EDIV_Export_Global(char* cadena, int valor)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
/* creaobj=crea_objeto((byte*)cadena); /* creaobj=crea_objeto((byte*)cadena);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_global:\t-- ID OBJETO: %d\n" printf("export_global:\t-- ID OBJETO: %d\n"
@ -251,15 +247,15 @@ int EDIV_Export_Global(char* cadena, int valor)
return dimem++; return dimem++;
} }
int EDIV_Export_Global_Tab(char *cadena, int numregs)
int EDIV_Export_Global_Tab(char* cadena, int numregs)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
/* creaobj=crea_objeto((byte*)cadena); /* creaobj=crea_objeto((byte*)cadena);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_global_tab:\t-- ID OBJETO: %d\n" printf("export_global_tab:\t-- ID OBJETO: %d\n"
@ -292,23 +288,23 @@ int EDIV_Export_Global_Tab(char* cadena, int numregs)
mem[imem++]=0; mem[imem++]=0;
} while (len--); } while (len--);
*/ */
offset=dimem; offset = dimem;
dimem+=numregs; dimem += numregs;
return offset; return offset;
} }
int EDIV_Export_Global_Struct(char *cadena, int numregs)
int EDIV_Export_Global_Struct(char* cadena, int numregs)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
nregs=numregs; nregs = numregs;
slocal=0; slocal = 0;
/* creaobj=crea_objeto((byte*)cadena); /* creaobj=crea_objeto((byte*)cadena);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_global_struct:\t-- ID OBJETO: %d\n" printf("export_global_struct:\t-- ID OBJETO: %d\n"
@ -340,20 +336,20 @@ int EDIV_Export_Global_Struct(char* cadena, int numregs)
member=ob; member=ob;
len=0; len=0;
*/ */
decl_struct=1; decl_struct = 1;
len=0; len = 0;
return dimem; return dimem;
} }
int EDIV_Export_Member_Int(char *cadena, int valor)
int EDIV_Export_Member_Int(char* cadena, int valor)
{ {
if(!decl_struct) { if (!decl_struct)
dll_error(7,cadena); {
dll_error(7, cadena);
return 0; return 0;
} }
/* creaobj=crea_objeto((byte*)cadena); /* creaobj=crea_objeto((byte*)cadena);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_member_int:\t-- ID OBJETO: %d\n" printf("export_member_int:\t-- ID OBJETO: %d\n"
@ -393,15 +389,15 @@ int EDIV_Export_Member_Int(char* cadena, int valor)
return len++; return len++;
} }
int EDIV_Export_Member_Str(char *cadena, int tamano)
int EDIV_Export_Member_Str(char* cadena, int tamano)
{ {
if(!decl_struct) { if (!decl_struct)
dll_error(7,cadena); {
dll_error(7, cadena);
return 0; return 0;
} }
/* creaobj=crea_objeto((byte*)cadena); /* creaobj=crea_objeto((byte*)cadena);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_member_str:\t-- ID OBJETO: %d\n" printf("export_member_str:\t-- ID OBJETO: %d\n"
@ -467,22 +463,21 @@ int EDIV_Export_Member_Str(char* cadena, int tamano)
return (*ob2).cloc.offset; return (*ob2).cloc.offset;
}*/ }*/
offset=len; offset = len;
len+=tamano; len += tamano;
return offset; return offset;
} }
int EDIV_Export_Member_Tab(char *cadena, int numregs)
int EDIV_Export_Member_Tab(char* cadena, int numregs)
{ {
if(!decl_struct) { if (!decl_struct)
dll_error(7,cadena); {
dll_error(7, cadena);
return 0; return 0;
} }
/* creaobj=crea_objeto((byte*)cadena); /* creaobj=crea_objeto((byte*)cadena);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_member_tab:\t-- ID OBJETO: %d\n" printf("export_member_tab:\t-- ID OBJETO: %d\n"
@ -532,20 +527,20 @@ int EDIV_Export_Member_Tab(char* cadena, int numregs)
return (*ob2).tloc.offset; return (*ob2).tloc.offset;
}*/ }*/
offset=len; offset = len;
len+=numregs; len += numregs;
return offset; return offset;
} }
int EDIV_Export_EndStruct() int EDIV_Export_EndStruct()
{ {
if(!decl_struct) { if (!decl_struct)
{
dll_error(9); dll_error(9);
return 0; return 0;
} }
/* #ifdef DEBUG_DLL /* #ifdef DEBUG_DLL
printf("export_endstruct:\t--- estructura cerrada\n"); printf("export_endstruct:\t--- estructura cerrada\n");
#endif #endif
@ -579,25 +574,28 @@ int EDIV_Export_EndStruct()
// iloc+=ob->sloc.totalitems*ob->sloc.len_item; // iloc+=ob->sloc.totalitems*ob->sloc.len_item;
} }
*/ */
if(len==0) dll_error(10); if (len == 0)
dll_error(10);
if(slocal) diloc+=len*nregs; if (slocal)
else dimem+=len*nregs; diloc += len * nregs;
else
dimem += len * nregs;
decl_struct=0; decl_struct = 0;
return 1; return 1;
} }
int EDIV_Export_Local(char *cadena, int valor)
int EDIV_Export_Local(char* cadena, int valor)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
/* creaobj=crea_objeto((byte*)cadena); /* creaobj=crea_objeto((byte*)cadena);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_local:\t-- ID OBJETO: %d\n" printf("export_local:\t-- ID OBJETO: %d\n"
@ -625,15 +623,15 @@ int EDIV_Export_Local(char* cadena, int valor)
return diloc++; return diloc++;
} }
int EDIV_Export_Local_Tab(char *cadena, int numregs)
int EDIV_Export_Local_Tab(char* cadena, int numregs)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
/* creaobj=crea_objeto((byte*)cadena); /* creaobj=crea_objeto((byte*)cadena);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_local_tab:\t-- ID OBJETO: %d\n" printf("export_local_tab:\t-- ID OBJETO: %d\n"
@ -668,23 +666,23 @@ int EDIV_Export_Local_Tab(char* cadena, int numregs)
return ob->tloc.offset;*/ return ob->tloc.offset;*/
offset=diloc; offset = diloc;
diloc+=numregs; diloc += numregs;
return offset; return offset;
} }
int EDIV_Export_Local_Struct(char *cadena, int numregs)
int EDIV_Export_Local_Struct(char* cadena, int numregs)
{ {
if(decl_struct) { if (decl_struct)
dll_error(6,cadena); {
dll_error(6, cadena);
return 0; return 0;
} }
nregs=numregs; nregs = numregs;
slocal=1; slocal = 1;
/* creaobj=crea_objeto((byte*)cadena); /* creaobj=crea_objeto((byte*)cadena);
#ifdef DEBUG_DLL #ifdef DEBUG_DLL
printf("export_local_struct:\t-- ID OBJETO: %d\n" printf("export_local_struct:\t-- ID OBJETO: %d\n"
@ -716,12 +714,11 @@ int EDIV_Export_Local_Struct(char* cadena, int numregs)
member=ob; member=ob;
len=0; len=0;
*/ */
decl_struct=1; decl_struct = 1;
len=0; len = 0;
return diloc; return diloc;
} }
//////////////// ////////////////
/// Call_Entrypoint /// Call_Entrypoint
////////////// //////////////
@ -729,12 +726,15 @@ int EDIV_Export_Local_Struct(char* cadena, int numregs)
int Call_Entrypoint(int ep, ...) int Call_Entrypoint(int ep, ...)
{ {
va_list opparam; va_list opparam;
int i,c=0; int i, c = 0;
for(i=0;i<n_entrypoints;i++) { for (i = 0; i < n_entrypoints; i++)
if(entrypoints[i].tipo==ep) { {
if (entrypoints[i].tipo == ep)
{
c++; c++;
va_start(opparam,ep); va_start(opparam, ep);
switch(ep) { switch (ep)
{
// void funcion(void) // void funcion(void)
case EDIV_set_video_mode: case EDIV_set_video_mode:
@ -753,16 +753,16 @@ int Call_Entrypoint(int ep, ...)
case EDIV_quit: case EDIV_quit:
{ {
void (*funcion_ep)(void); void (*funcion_ep)(void);
funcion_ep=entrypoints[i].hfuncion; funcion_ep = entrypoints[i].hfuncion;
funcion_ep(); funcion_ep();
} }
break; break;
case EDIV_frame: case EDIV_frame:
case EDIV_first_load: case EDIV_first_load:
{ {
void (*funcion_ep)(struct _fun_params* fp); void (*funcion_ep)(struct _fun_params * fp);
funcion_ep=entrypoints[i].hfuncion; funcion_ep = entrypoints[i].hfuncion;
funcion_ep(&fp) ; funcion_ep(&fp);
} }
break; break;
// void funcion(char*,int) // void funcion(char*,int)
@ -771,30 +771,30 @@ int Call_Entrypoint(int ep, ...)
case EDIV_process_map: case EDIV_process_map:
case EDIV_process_fnt: case EDIV_process_fnt:
{ {
void (*funcion_ep)(char *ptr,int lenght); void (*funcion_ep)(char *ptr, int lenght);
char* _ptr=va_arg(opparam,char*); char *_ptr = va_arg(opparam, char *);
int _lenght=va_arg(opparam,int); int _lenght = va_arg(opparam, int);
funcion_ep=entrypoints[i].hfuncion; funcion_ep = entrypoints[i].hfuncion;
funcion_ep(_ptr,_lenght); funcion_ep(_ptr, _lenght);
} }
break; break;
case EDIV_put_sprite: case EDIV_put_sprite:
{ {
void (*funcion_ep)(unsigned char * si, int x,int y, int an, int al, void (*funcion_ep)(unsigned char *si, int x, int y, int an, int al,
int xg, int yg, int ang, int size, int flags); int xg, int yg, int ang, int size, int flags);
unsigned char* _si=va_arg(opparam,unsigned char*); unsigned char *_si = va_arg(opparam, unsigned char *);
int _x=va_arg(opparam,int); int _x = va_arg(opparam, int);
int _y=va_arg(opparam,int); int _y = va_arg(opparam, int);
int _an=va_arg(opparam,int); int _an = va_arg(opparam, int);
int _al=va_arg(opparam,int); int _al = va_arg(opparam, int);
int _xg=va_arg(opparam,int); int _xg = va_arg(opparam, int);
int _yg=va_arg(opparam,int); int _yg = va_arg(opparam, int);
int _ang=va_arg(opparam,int); int _ang = va_arg(opparam, int);
int _size=va_arg(opparam,int); int _size = va_arg(opparam, int);
int _flags=va_arg(opparam,int); int _flags = va_arg(opparam, int);
funcion_ep=entrypoints[i].hfuncion; funcion_ep = entrypoints[i].hfuncion;
funcion_ep(_si,_x,_y,_an,_al,_xg,_yg,_ang,_size,_flags); funcion_ep(_si, _x, _y, _an, _al, _xg, _yg, _ang, _size, _flags);
} }
#ifdef DBG #ifdef DBG
// entrypoints del trazador // entrypoints del trazador
@ -802,17 +802,16 @@ int Call_Entrypoint(int ep, ...)
case EDIV_trace: case EDIV_trace:
case EDIV_debug: case EDIV_debug:
{ {
void (*funcion_ep)(int imem, char* nombreprg, int* lin, void* dbg); void (*funcion_ep)(int imem, char *nombreprg, int *lin, void *dbg);
int _imem=va_arg(opparam,int); int _imem = va_arg(opparam, int);
char* _nombreprg=va_arg(opparam,char*); char *_nombreprg = va_arg(opparam, char *);
void* _lin=va_arg(opparam,void*); void *_lin = va_arg(opparam, void *);
void* _dbg=va_arg(opparam,void*); void *_dbg = va_arg(opparam, void *);
//assert(0); //assert(0);
funcion_ep=entrypoints[i].hfuncion; funcion_ep = entrypoints[i].hfuncion;
funcion_ep(_imem,_nombreprg,_lin,_dbg); funcion_ep(_imem, _nombreprg, _lin, _dbg);
} }
#endif /* DBG */ #endif /* DBG */
} }
} }
} }

View file

@ -33,7 +33,7 @@
*/ */
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> #include <windows.h>
#else #else
#include <stdarg.h> #include <stdarg.h>
#endif #endif
@ -55,29 +55,28 @@
void error(int num, ...) void error(int num, ...)
{ {
#ifdef _WIN32 #ifdef _WIN32
HWND ventanuka; HWND ventanuka;
#endif #endif
va_list opparam; va_list opparam;
char mensaje[256]; char mensaje[256];
va_start(opparam,num); va_start(opparam, num);
sprintf(mensaje,translate(0), num); sprintf(mensaje, get_translate(0), num);
vsprintf(mensaje,translate_runtime_error(num-100),opparam); vsprintf(mensaje, translate_runtime_error(num - 100), opparam);
#ifdef _WIN32 #ifdef _WIN32
ventanuka=GetActiveWindow(); ventanuka = GetActiveWindow();
//MessageBox( //MessageBox(
MessageBox(ventanuka,mensaje,translate(1),MB_ICONERROR); MessageBox(ventanuka, mensaje, print_translate(1), MB_ICONERROR);
#else #else
printf("%s\n",mensaje); printf("%s\n", mensaje);
#endif #endif
stub_quit(num); stub_quit(num);
} }
/* critical_error ( numero, parametros [...] ) /* critical_error ( numero, parametros [...] )
* *
* Interrumpe el programa con un mensaje de error. No es posible trazar. * Interrumpe el programa con un mensaje de error. No es posible trazar.
@ -90,20 +89,19 @@ void critical_error(int num, ...)
va_list opparam; va_list opparam;
char mensaje[256]; char mensaje[256];
va_start(opparam,num); va_start(opparam, num);
sprintf(mensaje,translate(0), num); sprintf(mensaje, get_translate(0), num);
vsprintf(mensaje,translate_critical_error(num),opparam); vsprintf(mensaje, translate_critical_error(num), opparam);
#ifdef WIN32 #ifdef WIN32
MessageBox(0,mensaje,translate(2),MB_ICONERROR); MessageBox(0, mensaje, print_translate(2), MB_ICONERROR);
#else #else
printf("%s\n",mensaje); printf("%s\n", mensaje);
#endif #endif
stub_quit(num); stub_quit(num);
} }
/* custom_error (tipo, mensaje) /* custom_error (tipo, mensaje)
* *
* Permite a las DLLs generar sus propios errores, para que no dependan de los * Permite a las DLLs generar sus propios errores, para que no dependan de los
@ -119,13 +117,13 @@ void critical_error(int num, ...)
* DESVENTAJA: se pierde la capacidad multilingüe, a menos que la incluya la propia DLL. * DESVENTAJA: se pierde la capacidad multilingüe, a menos que la incluya la propia DLL.
*/ */
void custom_error(tipoerror tipo, char* mensaje) void custom_error(tipoerror tipo, char *mensaje)
{ {
#ifdef WIN32 #ifdef WIN32
MessageBox(0,mensaje,translate(tipo),MB_ICONERROR); MessageBox(0, mensaje, print_translate(tipo), MB_ICONERROR);
#else #else
printf("%s\n",mensaje); printf("%s\n", mensaje);
#endif #endif
stub_quit(500+tipo); stub_quit(500 + tipo);
} }

View file

@ -25,13 +25,11 @@
*/ */
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
//#include <SDL/SDL.h>
#include "extern.h" #include "extern.h"
#include "edivfont.h"
//#include "kernel.h" //#include "kernel.h"
#include "inte.h" #include "inte.h"
#include "main.h" #include "main.h"
@ -48,7 +46,7 @@ int ini_interprete()
first_loaded = 1 ; first_loaded = 1 ;
pila_max = 1024 ; pila_max = 1024 ;
if ((pila=(int*)malloc(4*pila_max))==NULL) if ((pila=malloc(4*pila_max))==NULL)
critical_error(4); // no se pudo reservar memoria para la pila critical_error(4); // no se pudo reservar memoria para la pila
sp = 0 ; //por si acaso sp = 0 ; //por si acaso

View file

@ -18,22 +18,20 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
/**** ¡¡¡ OJO CON LAS COMAS !!! ****/ /**** ¡¡¡ OJO CON LAS COMAS !!! ****/
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> #include <windows.h>
#else #else
# include <stdlib.h> #include <stdlib.h>
# include <string.h> #include <string.h>
#include <stdarg.h>
#endif #endif
#include "shared.h" #include "shared.h"
#include "language.h" #include "language.h"
int detecta_idioma_iso(char *lang)
int detecta_idioma_iso(char* lang)
{ {
int i; int i;
static char getid[NUM_LANGUAGES][3] = { static char getid[NUM_LANGUAGES][3] = {
@ -44,21 +42,23 @@ int detecta_idioma_iso(char* lang)
"ca", // catalán "ca", // catalán
"eu" // euskera "eu" // euskera
}; };
if(lang==NULL) return DEFAULT_LANGUAGE; if (lang == NULL)
if(strlen(lang)>2) lang[2]=0; return DEFAULT_LANGUAGE;
if (strlen(lang) > 2)
lang[2] = 0;
strlwr(lang); strlwr(lang);
for(i=0;i<NUM_LANGUAGES;i++) for (i = 0; i < NUM_LANGUAGES; i++)
if(lang[0]==getid[i][0]) if (lang[0] == getid[i][0])
if(lang[1]==getid[i][1]) if (lang[1] == getid[i][1])
break; break;
if(i==NUM_LANGUAGES) i=DEFAULT_LANGUAGE; if (i == NUM_LANGUAGES)
i = DEFAULT_LANGUAGE;
return i; return i;
} }
int detecta_idioma() int detecta_idioma()
{ {
#ifdef _WIN32 #ifdef _WIN32
int i; int i;
static int getid[NUM_LANGUAGES] = { static int getid[NUM_LANGUAGES] = {
0x0a, // español 0x0a, // español
@ -70,22 +70,25 @@ int detecta_idioma()
}; };
LANGID lang; LANGID lang;
lang=GetSystemDefaultLangID()&0xff; lang = GetSystemDefaultLangID() & 0xff;
for(i=0;i<NUM_LANGUAGES;i++) for (i = 0; i < NUM_LANGUAGES; i++)
if(lang==getid[i]) break; if (lang == getid[i])
if(i==NUM_LANGUAGES) i=DEFAULT_LANGUAGE; break;
if (i == NUM_LANGUAGES)
i = DEFAULT_LANGUAGE;
return i; return i;
#else #else
char* langcfg=getenv("LANG"); char *langcfg = getenv("LANG");
if(langcfg==NULL) return DEFAULT_LANGUAGE; if (langcfg == NULL)
else return detecta_idioma_iso(langcfg); return DEFAULT_LANGUAGE;
#endif else
return detecta_idioma_iso(langcfg);
#endif
} }
char *translate(int id_cadena)
char* translate(int id_cadena)
{ {
static char *msg[NUM_LANGUAGES][5]= { static char *msg[NUM_LANGUAGES][5] = {
#define TRANSLATE TRANSLATE_STUB #define TRANSLATE TRANSLATE_STUB
#include "language_aux.h" #include "language_aux.h"
@ -94,15 +97,14 @@ char* translate(int id_cadena)
return msg[idioma][id_cadena]; return msg[idioma][id_cadena];
} }
/* /*
* NOTA: los huecos vacíos (184..199) son de errores no usados en DIV2, por favor * NOTA: los huecos vacíos (184..199) son de errores no usados en DIV2, por favor
* aprovechadlos para añadir nuevos errores. * aprovechadlos para añadir nuevos errores.
*/ */
char* translate_runtime_error(int num) char *translate_runtime_error(int num)
{ {
static char *e[NUM_LANGUAGES][101]= { static char *e[NUM_LANGUAGES][101] = {
#define TRANSLATE TRANSLATE_RUNTIME_ERROR #define TRANSLATE TRANSLATE_RUNTIME_ERROR
#include "language_aux.h" #include "language_aux.h"
@ -110,11 +112,9 @@ char* translate_runtime_error(int num)
}; };
return e[idioma][num]; return e[idioma][num];
} }
char *translate_critical_error(int num)
char* translate_critical_error(int num)
{ {
static char *e[NUM_LANGUAGES][10] = { static char *e[NUM_LANGUAGES][10] = {
@ -126,8 +126,7 @@ char* translate_critical_error(int num)
return e[idioma][num]; return e[idioma][num];
} }
char *translate_dll_error(int num)
char* translate_dll_error(int num)
{ {
static char *e[NUM_LANGUAGES][10] = { static char *e[NUM_LANGUAGES][10] = {
@ -138,3 +137,31 @@ char* translate_dll_error(int num)
return e[idioma][num]; return e[idioma][num];
} }
void print_translate(int num, ...)
{
va_list arg_ptr;
const char *message = translate(num);
size_t msglen = strlen(message);
char *strbuf = malloc(msglen + 1);
va_start(arg_ptr, message);
vsprintf(strbuf, message, arg_ptr);
va_end(arg_ptr);
printf("%s", strbuf);
free(strbuf);
}
const char *get_translate(int num, ...)
{
va_list arg_ptr;
const char *message = translate(num);
size_t msglen = strlen(message);
char *strbuf = malloc(msglen + 1);
va_start(arg_ptr, message);
vsprintf(strbuf, message, arg_ptr);
va_end(arg_ptr);
return strbuf;
}

View file

@ -68,7 +68,7 @@ void dll_func() // ke original, no? XD
// guarda el nombre de fichero en la tabla de DLLs // guarda el nombre de fichero en la tabla de DLLs
printf("\nGuardando el nombre de la dll..."); printf("\nGuardando el nombre de la dll...");
dlls[0].nombre=(char*)e_malloc(strlen(fichero_dll.name)+1); dlls[0].nombre=e_malloc(strlen(fichero_dll.name)+1);
strcpy(dlls[0].nombre,fichero_dll.name); strcpy(dlls[0].nombre,fichero_dll.name);
printf("\nGuardado el nombre de la dll..."); printf("\nGuardado el nombre de la dll...");
@ -86,7 +86,7 @@ void dll_func() // ke original, no? XD
strcat(fichdll,fichero_dll.name); strcat(fichdll,fichero_dll.name);
// dlls[numdlls].nfuncs=0; // dlls[numdlls].nfuncs=0;
if(!leedll()) { if(!leedll()) {
dlls[numdlls].nombre=(char*)e_malloc(strlen(fichero_dll.name)+1); dlls[numdlls].nombre=e_malloc(strlen(fichero_dll.name)+1);
strcpy(dlls[numdlls].nombre,fichero_dll.name); strcpy(dlls[numdlls].nombre,fichero_dll.name);
dlls[numdlls].usado=0; dlls[numdlls].usado=0;
numdlls++; numdlls++;
@ -126,7 +126,7 @@ void dll_func() // ke original, no? XD
strcat(fichdll,fichero_dll->d_name); strcat(fichdll,fichero_dll->d_name);
// dlls[numdlls].nfuncs=0; // dlls[numdlls].nfuncs=0;
if(!leedll()) { if(!leedll()) {
dlls[numdlls].nombre=(char*)e_malloc(strlen(fichero_dll->d_name)+1); dlls[numdlls].nombre=e_malloc(strlen(fichero_dll->d_name)+1);
strcpy(dlls[numdlls].nombre,fichero_dll->d_name); strcpy(dlls[numdlls].nombre,fichero_dll->d_name);
dlls[numdlls].usado=0; dlls[numdlls].usado=0;
numdlls++; numdlls++;

View file

@ -155,7 +155,7 @@ int main(int argc, char* argv[])
} }
if ((mem=(int*)malloc(4*imem_max+1032*5+16*1025+3))!=NULL){ if ((mem=malloc(4*imem_max+1032*5+16*1025+3))!=NULL){
mem=(int*)((((int)mem+3)/4)*4); mem=(int*)((((int)mem+3)/4)*4);
@ -169,7 +169,7 @@ int main(int argc, char* argv[])
nullstring[3]=imem_max+1+258*3; mem[nullstring[3]-1]=0xDAD00402; nullstring[3]=imem_max+1+258*3; mem[nullstring[3]-1]=0xDAD00402;
memcpy(mem,mimem,40); memcpy(mem,mimem,40);
if ((ptr=(byte*)malloc(len))!=NULL) { if ((ptr=malloc(len))!=NULL) {
read(f,ptr,len); read(f,ptr,len);
@ -205,9 +205,9 @@ int main(int argc, char* argv[])
read(f,&num_indexed_vars,4); read(f,&num_indexed_vars,4);
read(f,&len_descomp,4); read(f,&len_descomp,4);
read(f,&len,4); read(f,&len,4);
ptr=(byte*)e_malloc(len); ptr=e_malloc(len);
read(f,ptr,len); read(f,ptr,len);
vartemp=(byte*)e_malloc(len_descomp); vartemp=e_malloc(len_descomp);
if(uncompress(vartemp,&len_descomp,ptr,len)) { if(uncompress(vartemp,&len_descomp,ptr,len)) {
free(ptr); free(ptr);
free(vartemp); free(vartemp);
@ -215,7 +215,7 @@ int main(int argc, char* argv[])
critical_error(1); // error leyendo el código del programa critical_error(1); // error leyendo el código del programa
} }
varindex=(varindex_t*)e_malloc(num_indexed_vars*sizeof(varindex_t)); varindex=e_malloc(num_indexed_vars*sizeof(varindex_t));
ptr=vartemp; ptr=vartemp;
for(i=0;i<num_indexed_vars;i++) { for(i=0;i<num_indexed_vars;i++) {
@ -244,9 +244,9 @@ int main(int argc, char* argv[])
lseek(f,start_lin,SEEK_SET); lseek(f,start_lin,SEEK_SET);
read(f,&descomp_size,4); read(f,&descomp_size,4);
read(f,&comp_size,4); read(f,&comp_size,4);
progcomp=(char*)e_malloc(comp_size); progcomp=e_malloc(comp_size);
read(f,progcomp,comp_size); read(f,progcomp,comp_size);
prog=(char*)e_malloc(descomp_size); prog=e_malloc(descomp_size);
if(uncompress(prog,&descomp_size,progcomp,comp_size)) { if(uncompress(prog,&descomp_size,progcomp,comp_size)) {
close(f); close(f);
free(prog); free(prog);
@ -255,7 +255,7 @@ int main(int argc, char* argv[])
} }
free(progcomp); free(progcomp);
read(f,&linsize,4); read(f,&linsize,4);
lin=(int*)e_malloc(linsize*4*4+4); lin=e_malloc(linsize*4*4+4);
lin[0]=linsize; lin[0]=linsize;
for(i=0;i<linsize;i++) { for(i=0;i<linsize;i++) {

View file

@ -88,7 +88,7 @@ int main(int argc, char* argv[])
fseek(f,0,SEEK_END); fseek(f,0,SEEK_END);
tamano=ftell(f); tamano=ftell(f);
fseek(f,0,SEEK_SET); fseek(f,0,SEEK_SET);
if((buffer=(char*)malloc(tamano))==NULL) { if((buffer=malloc(tamano))==NULL) {
printf("Error: memoria insuficiente\n"); printf("Error: memoria insuficiente\n");
exit(3); exit(3);
} }
@ -140,7 +140,7 @@ int main(int argc, char* argv[])
tamano=ftell(f); tamano=ftell(f);
fseek(f,0,SEEK_SET); fseek(f,0,SEEK_SET);
if((buffer=(char*)malloc(tamano+1))==NULL) { if((buffer=malloc(tamano+1))==NULL) {
printf("Error: memoria insuficiente\n"); printf("Error: memoria insuficiente\n");
exit(5); exit(5);
} }
@ -253,7 +253,7 @@ void situame(char* actual, char* ant, char* sig, char* sup)
tam=ftell(fi); tam=ftell(fi);
fseek(fi,0,SEEK_SET); fseek(fi,0,SEEK_SET);
if((buf=(char*)malloc(tam+1))==NULL) { if((buf=malloc(tam+1))==NULL) {
printf("Error: memoria insuficiente\n"); printf("Error: memoria insuficiente\n");
exit(14); exit(14);
} }
@ -363,7 +363,7 @@ void lee_titulo(char* fixero1, char* titulo)
tam=ftell(fi); tam=ftell(fi);
fseek(fi,0,SEEK_SET); fseek(fi,0,SEEK_SET);
if((buf=(char*)malloc(tam+1))==NULL) { if((buf=malloc(tam+1))==NULL) {
printf("Error: memoria insuficiente\n"); printf("Error: memoria insuficiente\n");
exit(11); exit(11);
} }
@ -477,7 +477,7 @@ void procesa_subindice(char* actual)
tam=ftell(fi); tam=ftell(fi);
fseek(fi,0,SEEK_SET); fseek(fi,0,SEEK_SET);
if((buf=(char*)malloc(tam+1))==NULL) { if((buf=malloc(tam+1))==NULL) {
printf("Error: memoria insuficiente\n"); printf("Error: memoria insuficiente\n");
exit(20); exit(20);
} }

View file

@ -79,7 +79,7 @@ int main(int argc, char* argv[])
exit(4); exit(4);
} }
ico=(unsigned char*)e_malloc(tamanyo); ico=e_malloc(tamanyo);
fseek(f,0,SEEK_SET); fseek(f,0,SEEK_SET);
fread(ico,tamanyo,1,f); fread(ico,tamanyo,1,f);
fclose(f); fclose(f);
@ -92,7 +92,7 @@ int main(int argc, char* argv[])
fseek(f,0,SEEK_END); fseek(f,0,SEEK_END);
tamanyo=ftell(f); tamanyo=ftell(f);
fseek(f,0,SEEK_SET); fseek(f,0,SEEK_SET);
exe=(unsigned char*)e_malloc(tamanyo); /* no creo ke pase nada por unos 125 kb... exe=e_malloc(tamanyo); /* no creo ke pase nada por unos 125 kb...
eso si, cuando se puedan meter el PAK y eso si, cuando se puedan meter el PAK y
las DLL's en el exe, va a haber ke cambiar las DLL's en el exe, va a haber ke cambiar
esto... */ esto... */