/*
¿Porque se ultiliza goto? Porque si, reduzco codigo.
*/
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
using namespace std;
FILE *archivo;
FILE *ccmd;
char *pos;
char caracteres[150];
int main( int argc, char **argv) {
char ArchivoAbrir[21];
char ArchivoSaliente[21];
if ( argc < 3 ) {
cout<<"Ejemplo: programa \"Archivo a Abrir.cmd\" -c \"ArchivoSaliente.c\" "<<endl;
return 1;
}
if ( !strcmp( argv[2], "-c" ) ) {
strncpy( ArchivoAbrir, argv[1], 20 );
ArchivoAbrir[21] = '\0';
strncpy( ArchivoSaliente, argv[3], 20 );
ArchivoSaliente[21] = '\0';
}
archivo = fopen(argv[1],"r");
ccmd = fopen(argv[3],"wt");
if (archivo == NULL)
exit(1);
while (!feof(archivo))
{
fgets( caracteres, 150, archivo );
if ((pos=strchr(caracteres, '\n')) != NULL)
*pos = '\0';
while (!strcmp(caracteres,"PAUSE>NUL"))
{
goto PAUSANULA;
}
while (!strcmp(caracteres,"PAUSE"))
{
fprintf(ccmd,"\tputs(\"Presione una tecla para continuar.\");\n");
PAUSANULA:
fprintf(ccmd,"\tgetchar();\n");
caracteres[0] = '\0';
}
while (!strcmp(caracteres,"EXIT"))
{
fprintf(ccmd,"\treturn 0 ;\n");
caracteres[0] = '\0';
}
while (!strcmp(caracteres,"CLS"))
{
goto LIMPIADO;
}
while (!strcmp(caracteres,"CLEAR"))
{
LIMPIADO:
fprintf(ccmd,"\tputs(\"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\");\n");
caracteres[0] = '\0';
}
while (!strcmp(caracteres,"FIN"))
{
goto FIN;
caracteres[0] = '\0';
}
if (!strcmp(caracteres,"\0"))
{
}else{
fprintf(ccmd,"\tsystem(\"%s\");\n",caracteres);
caracteres[0] = '\0';
}
}
FIN:
fclose(archivo);
fclose(ccmd);
cout<<"Compilado.."<<endl;
getchar();
}
¿Alguna razón para que no sea así?