493 lines
17 KiB
C++
493 lines
17 KiB
C++
#include <dos.h>
|
||
#include <math.h>
|
||
#include <ctype.h>
|
||
#include <alloc.h>
|
||
#include <conio.h>
|
||
#include <stdio.h>
|
||
#include <string.h>
|
||
#include <stdlib.h>
|
||
#include <graphics.h>
|
||
|
||
#define OK 1
|
||
#define SIN_MEMORIA 5
|
||
#define ERROR_ABRIENDO 6
|
||
#define ERROR_CERRANDO 7
|
||
|
||
#define EOL 10 // Fin de linea
|
||
|
||
int Secuencias;
|
||
int *n_Botones_Secuencia;
|
||
int memoria_asignada = 0, vez = 0;
|
||
|
||
struct Make_Boton {
|
||
int Left, Up, Right, Down;
|
||
int Cdf, Cb1, Cb2;
|
||
int Ab, Pb;
|
||
int Isc, Sc;
|
||
};
|
||
|
||
struct Make_Boton far *Botones; // Puntero a estructura
|
||
struct Make_Boton Bot_Static;
|
||
|
||
int Analiza_Fichero_Dinamicos(char *f_datos);
|
||
int Analiza_Fichero_Estaticos(char *f_datos);
|
||
|
||
void ErrorOccurred(int errorcode);
|
||
|
||
int lee_objeto(FILE *); // Lee el objeto del disco
|
||
|
||
FILE *MB_out;
|
||
|
||
void main(int argc, char *argv[] ) {
|
||
|
||
char Buffer[80]; int len;
|
||
char *ptr = argv[2];
|
||
|
||
if ( argc != 3 ) {
|
||
|
||
printf("\n");
|
||
printf("FALTAN PARAMETROS\n");
|
||
printf("\n");
|
||
printf(" MB2SRC [Fichero_Fuente] [Destino_CPP.CPP]\n");
|
||
printf("\n");
|
||
|
||
return;
|
||
}
|
||
|
||
/* open a file for update */
|
||
if( (MB_out = fopen(argv[2], "w")) == NULL ) {
|
||
printf("\nError Abriendo Archivo destino");
|
||
return;
|
||
}
|
||
fprintf( MB_out, "/***************************************************************/\n");
|
||
fprintf( MB_out, "/* */\n");
|
||
fprintf( MB_out, "/* Conversi¢n de fuentes de MAKE BOTON en ASCII a fuentes */\n");
|
||
fprintf( MB_out, "/* para CPP, que pueden ser compilados junto al programa. */\n");
|
||
fprintf( MB_out, "/* */\n");
|
||
fprintf( MB_out, "/***************************************************************/\n");
|
||
fprintf( MB_out, "/* */\n");
|
||
fprintf( MB_out, "/* MAKE BOTON es un programa realizado por Jos‚ David Guill‚n */\n");
|
||
fprintf( MB_out, "/* MB a CPP es una utilidad complementaria a Make Boton por */\n");
|
||
fprintf( MB_out, "/* Jos‚ David Guill‚n... */\n");
|
||
fprintf( MB_out, "/* */\n");
|
||
fprintf( MB_out, "/***************************************************************/\n");
|
||
fprintf( MB_out, "/* */\n");
|
||
fprintf( MB_out, "/* GRACIAS POR UTILIZAR MI SOFTWARE... */\n");
|
||
fprintf( MB_out, "/* */\n");
|
||
fprintf( MB_out, "/* JOS<4F> DAVID GUILL<4C>N (c) 1995 */\n");
|
||
fprintf( MB_out, "/* */\n");
|
||
fprintf( MB_out, "/***************************************************************/\n");
|
||
fprintf( MB_out, "\n\n\n");
|
||
fprintf( MB_out, "// Debe indicar el directorio exacto de la Cabecera de MAKE BOTON\n");
|
||
fprintf( MB_out, "#include \"Make_bot.h\"\n");
|
||
fprintf( MB_out, "#include \"stdlib.h\"\n");
|
||
fprintf( MB_out, "#include \"alloc.h\"\n");
|
||
fprintf( MB_out, "#include \"graphics.h\"\n");
|
||
fprintf( MB_out, "\n\n\n");
|
||
fprintf( MB_out, "extern int vez, memoria_asignada, Secuencias, *n_Botones_Secuencia;\n");
|
||
fprintf( MB_out, " struct Make_Boton { int Up, Left, Down, Right; int Cdf, Cb1, Cb2; int Ab, Pb; int Isc, Sc; };\n");
|
||
fprintf( MB_out, "extern struct Make_Boton far *Botones, Bot_Static;\n");
|
||
|
||
|
||
|
||
fprintf( MB_out, "\n\n\n");
|
||
fprintf( MB_out, "extern void Libera_Memoria(void);");
|
||
fprintf( MB_out, "extern void Imprime_Boton(int D_Bord, struct Make_Boton Bot_Imp);");
|
||
fprintf( MB_out, "\n\n\n");
|
||
fprintf( MB_out, "// Esta funci¢n debe ser llamada para la inicializacion de los\n");
|
||
fprintf( MB_out, "// botones en lugar de CARGA_BOTONES(...). \n");
|
||
|
||
fprintf( MB_out, "// Para cargar los botones con parametro 0 y para imprimir \n");
|
||
fprintf( MB_out, "// imprimir los estaticos con parametro [ n§ de secuencia ] \n");
|
||
len = 0;
|
||
while( *ptr++ != NULL && *ptr != '.' ) len++;
|
||
strncpy( Buffer, argv[2], len+1 );
|
||
Buffer[len+1] = '\0' ;
|
||
|
||
fprintf( MB_out, "int Fichero_%s(char Dinamicos_Estaticos);\n\n", Buffer );
|
||
fprintf( MB_out, "int Fichero_%s(char Dinamicos_Estaticos) {\n", Buffer );
|
||
|
||
fprintf( MB_out, "\n");
|
||
|
||
fprintf( MB_out, " switch(Dinamicos_Estaticos) {\n");
|
||
fprintf( MB_out, "\n");
|
||
fprintf( MB_out, " case 0:\n");
|
||
if ( Analiza_Fichero_Dinamicos(argv[1]) != OK ) { printf( "ERROR ANALIZANDO FICHERO EN SECCION DINAMICOS..." ); return; };
|
||
|
||
if ( Analiza_Fichero_Estaticos(argv[1]) != OK ) { printf( "ERROR ANALIZANDO FICHERO EN SECCION ESTATICOS..." ); return; };
|
||
fprintf( MB_out, " break;\n");
|
||
fprintf( MB_out, " default:\n");
|
||
fprintf( MB_out, " break;\n");
|
||
fprintf( MB_out, " }\n");
|
||
fprintf( MB_out, "}\n");
|
||
|
||
fclose(MB_out);
|
||
|
||
}
|
||
|
||
int Analiza_Fichero_Dinamicos(char *f_datos){
|
||
FILE *fichero;
|
||
int error_lectura = OK;
|
||
|
||
fprintf( MB_out, " if( vez == 0 ) {\n");
|
||
fprintf( MB_out, " vez = 1;\n");
|
||
fprintf( MB_out, " atexit( Libera_Memoria );\n");
|
||
fprintf( MB_out, " }\n");
|
||
fprintf( MB_out, " if ( memoria_asignada == 1 ) { \n");
|
||
fprintf( MB_out, " free(n_Botones_Secuencia);\n");
|
||
fprintf( MB_out, " farfree(Botones);\n");
|
||
fprintf( MB_out, " memoria_asignada = 0;\n");
|
||
fprintf( MB_out, " }\n");
|
||
|
||
if ( (fichero=fopen(f_datos,"r"))==NULL ) return ERROR_ABRIENDO;
|
||
|
||
char ch/*, buffer[80]*/;
|
||
int signo,numero, temp_num, temp_b;
|
||
int inc_Botones = -1;
|
||
fprintf( MB_out, " int SiZe_BoToN = 0;\n");
|
||
fprintf( MB_out, " if ( (Botones = (struct Make_Boton far *)farcalloc(1, sizeof( struct Make_Boton ) )) == NULL)\n");
|
||
fprintf( MB_out, " return SIN_MEMORIA;\n");
|
||
fprintf( MB_out, " memoria_asignada = 1;\n");
|
||
fprintf( MB_out, "\n");
|
||
|
||
|
||
ch=fgetc(fichero); //Lee el primer caracter
|
||
while (ch!=EOF) { //Lee hasta fin de fichero
|
||
if (ch=='*') //Linea con comentario
|
||
while (ch!=EOL && ch!=EOF) ch=fgetc(fichero);
|
||
|
||
if (ch=='#') { //Numero de secuencias
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF) {
|
||
if (ch>='0' && ch<='9') numero= (numero*10+ch-48);
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Secuencias = %d;\n", numero);
|
||
fprintf( MB_out, " if (( n_Botones_Secuencia = (int *) malloc( sizeof(int)*Secuencias ) ) == NULL) {\n");
|
||
fprintf( MB_out, " printf(\"\\nNo Hay suficiente Memoria, ni para un Boton\\n\\n\");\n");
|
||
fprintf( MB_out, " return SIN_MEMORIA;\n");
|
||
fprintf( MB_out, " }\n");
|
||
}
|
||
|
||
if (ch=='!') { //Numero de Botones en la secuencia
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero= (numero*10+ch-48);
|
||
ch=fgetc(fichero);
|
||
}
|
||
temp_num = numero;
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero= (numero*10+ch-48);
|
||
ch=fgetc(fichero);
|
||
}
|
||
// fprintf( MB_out, " }\n");
|
||
fprintf( MB_out, " n_Botones_Secuencia[%d - 1] = %d;\n", temp_num, numero);
|
||
fprintf( MB_out, " SiZe_BoToN += ( sizeof( struct Make_Boton ) * %d);\n", numero);
|
||
fprintf( MB_out, " if ( (Botones = (struct Make_Boton far *)farrealloc(Botones, SiZe_BoToN )) == NULL) {\n");
|
||
fprintf( MB_out, " Secuencias = %d;\n", temp_num);
|
||
fprintf( MB_out, " return SIN_MEMORIA;\n");
|
||
fprintf( MB_out, " }\n");
|
||
fprintf( MB_out, " memoria_asignada = 1;\n");
|
||
|
||
}
|
||
if (ch=='$') { //C lculos del boton
|
||
inc_Botones++;
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Botones [%d].Left = %d; ", inc_Botones, numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, "Botones [%d].Up = %d;", inc_Botones, numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, "Botones [%d]. Right = %d;", inc_Botones, numero);
|
||
// Botones [inc_Botones]. Right =numero;
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, "Botones [%d]. Down = %d;\n", inc_Botones, numero);
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Botones [%d]. Cdf = %d;", inc_Botones, numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Botones [%d]. Cb1 = %d;", inc_Botones, numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Botones [%d]. Cb2 = %d;", inc_Botones, numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Botones [%d]. Ab = %d;", inc_Botones, numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Botones [%d]. Pb = %d;", inc_Botones, numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Botones [%d]. Isc = %d;", inc_Botones, numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Botones [%d]. Sc = %d;\n", inc_Botones, numero);
|
||
|
||
}
|
||
|
||
if (ch!=EOF) ch=fgetc(fichero);
|
||
}
|
||
|
||
|
||
|
||
if( fclose(fichero) != 0 ) return ERROR_CERRANDO;
|
||
|
||
// despliega_datos();
|
||
|
||
// while (!kbhit()); // Espera a que se pulse una tecla
|
||
|
||
return error_lectura;
|
||
}
|
||
|
||
|
||
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
|
||
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
|
||
int Analiza_Fichero_Estaticos(char *f_datos){
|
||
|
||
char ch, Relleno = 1;
|
||
int x, y, fuente, size, orientacion, color;
|
||
char buffer[160];
|
||
int signo,numero, temp_num, temp_b;
|
||
int secuencia_activa=-1;
|
||
|
||
FILE* fichero; // Fichero con datos del obj.
|
||
|
||
if ( (fichero=fopen(f_datos,"r"))==NULL ) return ERROR_ABRIENDO;
|
||
|
||
ch=fgetc(fichero); //Lee el primer caracter
|
||
while (ch!=EOF) { //Lee hasta fin de fichero
|
||
|
||
if (ch=='*') //Linea con comentario
|
||
while (ch!=EOL && ch!=EOF) ch=fgetc(fichero);
|
||
|
||
if (ch=='') { //Numero de Botones en la secuencia
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
secuencia_activa = numero;
|
||
fprintf( MB_out, " break;\n");
|
||
fprintf( MB_out, " case %d:\n", secuencia_activa);
|
||
}
|
||
|
||
if (ch=='&' /*&& secuencia_activa == Sec_st*/) { //C lculos del boton estatico
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Bot_Static.Left = %d;", numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Bot_Static.Up = %d;", numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Bot_Static.Right = %d;", numero);
|
||
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Bot_Static.Down = %d;", numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Bot_Static.Cdf = %d;", numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Bot_Static.Cb1 = %d;", numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Bot_Static.Cb2 = %d;", numero);
|
||
|
||
numero=0; Relleno = 1;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48; else
|
||
if(ch == '-' || ch == '-') Relleno = 0;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Bot_Static.Ab = %d;", numero);
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fprintf( MB_out, " Bot_Static.Pb = %d;\n", numero);
|
||
fprintf( MB_out, " Imprime_Boton(%d, Bot_Static);\n", Relleno);
|
||
|
||
}
|
||
if (ch=='|' /*&& secuencia_activa == Sec_st*/) { //C lculos del texto
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
x = numero;
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
y = numero;
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
fuente = numero;
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
size = numero;
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
orientacion = numero;
|
||
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',') {
|
||
if (ch>='0' && ch<='9') numero=numero*10+ch-48;
|
||
ch=fgetc(fichero);
|
||
}
|
||
color = numero;
|
||
|
||
buffer[0] = '\0';
|
||
numero=0;
|
||
ch=fgetc(fichero);
|
||
while (ch!=EOL && ch!=EOF && ch!=',' && numero<150 ) {
|
||
ch=fgetc(fichero);
|
||
if(ch!=',') { buffer[numero] = ch; numero++; }
|
||
}
|
||
|
||
buffer[numero] = '\0';
|
||
fprintf( MB_out, " setcolor(%d);", color);
|
||
|
||
/* select the registered font */
|
||
fprintf( MB_out, " settextstyle( %d, %d, %d);", fuente, orientacion, size);
|
||
fprintf( MB_out, " outtextxy( %d, %d, \"%s\" );\n", x, y, buffer);
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
if (ch!=EOF) ch=fgetc(fichero);
|
||
}
|
||
|
||
if( fclose(fichero) != 0 ) return ERROR_CERRANDO;
|
||
// if( fclose(fichero) != 0 ) return ERROR_CERRANDO;
|
||
return OK;
|
||
}
|
||
|
||
R |