328 lines
7.9 KiB
C++
328 lines
7.9 KiB
C++
/////////////////////////////////////////////////////////////////////////////
|
||
//
|
||
// CD_SND
|
||
//
|
||
// Utilidad para CD_Out
|
||
//
|
||
// Se encarga de reunir todos los Waves en un solo archivo para que
|
||
// CD_Out pueda utilizarlos.
|
||
//
|
||
// Parametros de entrada:
|
||
//
|
||
// CD_SND [Command] [Output File] [ ID_Code ]
|
||
//
|
||
// -u:NAME.EXT Uncompress Wave with name: NAME.EXT
|
||
// -ua Uncompress ALL WAVES
|
||
//
|
||
// -c:NAME.EXT Compress Wave with name: NAME.EXT ( Name will be a name valid
|
||
// for CD_Out:
|
||
// CD_OUTXX.WAV )
|
||
// -ca Compress ALL WAVES
|
||
// -e:NAME.EXT Extract Wave File with NAME.EXT
|
||
//
|
||
// Si el fichero no es reconocido por CD_Out necesitara un ID_Code
|
||
// distinto para su utilizaci¢n ( en un futuro ), para futuras vesiones
|
||
// de CD_Out
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
|
||
#include<io.h>
|
||
#include<stdio.h>
|
||
#include<string.h>
|
||
#include<stdlib.h>
|
||
#include<conio.h>
|
||
|
||
#define Extraer_Uno 1
|
||
#define Extraer_Todos 2
|
||
#define Insertar_Uno 3
|
||
#define Insertar_Todos 4
|
||
#define Borra_Uno 5
|
||
|
||
long Longitud( const char *File );
|
||
void Procesa( int Accion, const char *Fich_Origen, char *Fich_Destino );
|
||
void Ayuda(void) ;
|
||
void Indica_progreso(int RESET);
|
||
|
||
|
||
typedef struct
|
||
{
|
||
char Nombre_del_Programa[70];
|
||
char Comentario_Inicial[70];
|
||
|
||
char VerHi, VerLow;
|
||
char Register;
|
||
|
||
long Records;
|
||
} CABECERA;
|
||
|
||
typedef struct
|
||
{
|
||
char Wave_Name[13]; // Nombre del Wave
|
||
char ID_code; // Codigo ID_ del Wave
|
||
unsigned long Pos; // Posici¢n de comienzo dentro del archivo destino
|
||
unsigned long Len; // Longitud
|
||
} CD_SND;
|
||
|
||
|
||
|
||
long la;
|
||
char *Fich_Origen;
|
||
char *Fich_Destino;
|
||
char Accion = 0;
|
||
char ID_Code = -1;
|
||
|
||
const char File[][13] = {
|
||
"CD_OUT00.WAV",
|
||
"CD_OUT01.WAV",
|
||
"CD_OUT02.WAV",
|
||
"CD_OUT03.WAV",
|
||
"CD_OUT04.WAV",
|
||
"CD_OUT05.WAV",
|
||
"CD_OUT06.WAV",
|
||
"CD_OUT07.WAV",
|
||
"CD_OUT08.WAV",
|
||
"CD_OUT09.WAV",
|
||
"CD_OUT0A.WAV",
|
||
"CD_OUT0B.WAV",
|
||
"CD_OUT0C.WAV",
|
||
"CD_OUT0D.WAV",
|
||
"CD_OUT0E.WAV",
|
||
"CD_OUT0F.WAV",
|
||
"CD_OUT10.WAV",
|
||
"CD_OUT11.WAV",
|
||
"CD_OUTFF.WAV"
|
||
};
|
||
|
||
|
||
void main( int argc, char *argv[] )
|
||
{
|
||
int i;
|
||
clrscr();
|
||
gotoxy(1,1); textcolor(WHITE); textbackground(BLUE);
|
||
cprintf("Copyright (c) J.D. System 1995. Jos‚ David Guill‚n Dominguez... CD_Snd vú1.0");
|
||
|
||
// Analizamos parametros
|
||
if ( argc != 3 )
|
||
{
|
||
textbackground(BLACK);
|
||
gotoxy(1,3);
|
||
cprintf("Sintaxis: CD_Snd [Comando] [Archivo_Destino] [ID_Code] ");
|
||
Ayuda();
|
||
return;
|
||
} else {
|
||
|
||
gotoxy(1,2);
|
||
cprintf(" Procesando Argumentos ");
|
||
Indica_progreso(1);
|
||
la = argc;
|
||
|
||
if ( !strncmpi(argv[1], "-U:", 3) )
|
||
{
|
||
Fich_Origen = argv[1];
|
||
Fich_Origen += 3;
|
||
Accion = Extraer_Uno;
|
||
Indica_progreso(0);
|
||
} else
|
||
if ( !strcmpi(argv[1], "-UA") )
|
||
{
|
||
Accion = Extraer_Todos;
|
||
Indica_progreso(0);
|
||
} else
|
||
if ( !strncmpi(argv[1], "-C:", 3) )
|
||
{
|
||
Fich_Origen = argv[1];
|
||
Fich_Origen += 3;
|
||
Accion = Insertar_Uno;
|
||
Indica_progreso(0);
|
||
} else
|
||
if ( !strcmpi(argv[1], "-CA") )
|
||
{
|
||
Accion = Insertar_Todos;
|
||
Indica_progreso(0);
|
||
} else
|
||
if ( !strncmpi(argv[1], "-E:", 3) )
|
||
{
|
||
Fich_Origen = argv[1];
|
||
Fich_Origen += 3;
|
||
Accion = Borra_Uno;
|
||
Indica_progreso(0);
|
||
} else Ayuda();
|
||
|
||
Fich_Destino = argv[2];
|
||
Indica_progreso(0);
|
||
|
||
ID_Code = atoi( argv[3] );
|
||
Indica_progreso(0);
|
||
}
|
||
|
||
Procesa( Accion, File[i], Fich_Destino );
|
||
/*
|
||
swicth ( Accion )
|
||
{
|
||
case Insertar_Todos:
|
||
case Extraer_Todos:
|
||
for ( i=0; i< 19; i++ )
|
||
{
|
||
ID_Code = i;
|
||
Procesa( Accion, &File[i], Fich_Destino );
|
||
}
|
||
break;
|
||
default:
|
||
Procesa( Accion, Fich_Origen, Fich_Destino );
|
||
break;
|
||
}
|
||
*/
|
||
}
|
||
|
||
|
||
void Indica_progreso(int RESET){
|
||
|
||
static int posx=31; // Posici¢n de giro //
|
||
static int giro=0; // Carater para rotar //
|
||
static long contador = 0;
|
||
|
||
if ( RESET ) { contador = 0; gotoxy(1,2); cprintf(" 0%"); return; }
|
||
contador++;
|
||
gotoxy(1,2); cprintf("%3d%%", ( (contador*100)/la ) );
|
||
gotoxy(posx-1,2); posx++;
|
||
switch(giro){
|
||
case 0: cprintf(" /"); break;
|
||
case 1: cprintf(" Ä"); break;
|
||
case 2: cprintf(" \\"); break;
|
||
case 3: cprintf(" ³"); break;
|
||
}
|
||
if(posx==79) posx=30;
|
||
giro++; if(giro==4) giro=0;
|
||
|
||
}
|
||
|
||
|
||
/*CD_OUTxx . WAV
|
||
|
||
00 Inicio del Programa
|
||
FF Fin del Programa
|
||
01 Raton pulsado en algun sitio
|
||
02 Tecla pulsada para nada
|
||
03 Tick Generico
|
||
04 Boton DOS
|
||
05 Boton Windows
|
||
06 Select Icono
|
||
07 Instalar
|
||
08 Configurar
|
||
09 Ejecutar
|
||
0A Ver Dibujo
|
||
|
||
0B Si
|
||
0C No
|
||
0D Imprimiendo
|
||
0E Aceptar
|
||
0F Cancelar
|
||
10 Salvar al Salir
|
||
|
||
11 ERROR DESCONOCIDO
|
||
|
||
*/
|
||
|
||
void Ayuda(void)
|
||
{
|
||
gotoxy(1,5);
|
||
cprintf("[Comando]\r\n");
|
||
cprintf(" * -u: Nombre.EXT Saca una copia del fichero compactado\r\n");
|
||
cprintf(" * -ua Saca una copia de todos los ficheros\r\n") ;
|
||
cprintf(" * -c: Nombre.EXT Introduce el Archivo Nombre.Ext en Destino\r\n");
|
||
cprintf(" -ca Introduce todos los Archivos en Destino\r\n") ;
|
||
cprintf(" * -e: Nombre.EXT Borra el Archivo Nombre.Ext de Destino\r\n\r\n");
|
||
cprintf(" * Comandos desctivados el la versi¢n SHAREWARE\r\n\r\n") ;
|
||
|
||
|
||
}
|
||
|
||
|
||
void Procesa( int Accion, const char *Fich_Origen, char *Fich_Destino )
|
||
{
|
||
FILE *ORIGEN;
|
||
FILE *DESTINO;
|
||
CABECERA Cabecera;
|
||
CD_SND CD_Snd[19];
|
||
long Pos; int i;
|
||
|
||
/*
|
||
if ( ( ORIGEN = fopen( Fich_Origen, "rb") ) == NULL )
|
||
{
|
||
cprintf("\r\nERROR ABRIENDO ORIGEN: %s\r\n", Fich_Origen);
|
||
exit(1);
|
||
}
|
||
*/
|
||
if ( ( DESTINO = fopen( Fich_Destino, "wb") ) == NULL )
|
||
{
|
||
cprintf("\r\nERROR ABRIENDO DESTINO: %s\r\n", Fich_Destino);
|
||
exit(1);
|
||
}
|
||
|
||
sprintf( Cabecera.Nombre_del_Programa, "CD_Snd\nCompactador de Ficheros para CD_Out\n" );
|
||
sprintf( Cabecera.Comentario_Inicial, "\n\nCD_Out es un programa de Jos‚ David\nCD_Snd idem%d%d", 7, 26);
|
||
Cabecera.VerHi = 1;
|
||
Cabecera.VerLow = 0;
|
||
Cabecera.Register = 0;
|
||
Cabecera.Records =19;
|
||
|
||
|
||
fwrite( &Cabecera, sizeof( Cabecera ), 1, DESTINO );
|
||
Pos = sizeof( Cabecera ) + sizeof( CD_SND) * 19;
|
||
Indica_progreso(1); la = 19;
|
||
|
||
gotoxy(1,2);
|
||
cprintf(" Creando Esturcturas ");
|
||
|
||
for ( i=0; i< 19; i++ )
|
||
{
|
||
strcpy(CD_Snd[i].Wave_Name, File[i]); // Nombre del Wave
|
||
CD_Snd[i].ID_code = i; // Codigo ID_ del Wave
|
||
CD_Snd[i].Len = Longitud(File[i]);
|
||
CD_Snd[i].Pos = Pos;
|
||
Pos += CD_Snd[i].Len;
|
||
Indica_progreso(0);
|
||
}
|
||
|
||
fwrite( CD_Snd, sizeof( CD_SND ), 19, DESTINO );
|
||
|
||
for ( i=0; i< 19; i++ )
|
||
{
|
||
// gotoxy(1,4);
|
||
// cprintf(" Pulse una Tecla para siguiente Archivo -- Version SHAREWARE -- ");
|
||
// getch();
|
||
// gotoxy(1,4);
|
||
// cprintf(" ");
|
||
|
||
gotoxy(1,2);
|
||
cprintf(" Uniendo %13s ", File[i]);
|
||
Indica_progreso(1); la = CD_Snd[i].Len;
|
||
gotoxy(1,3);
|
||
cprintf(" Longitud a procesar %ld ", CD_Snd[i].Len);
|
||
|
||
if ( ( ORIGEN = fopen( File[i], "rb") ) != NULL )
|
||
{
|
||
Pos = CD_Snd[i].Len;
|
||
|
||
while ( Pos > 0 ) { fputc(fgetc(ORIGEN), DESTINO); Indica_progreso(0); Pos--; }
|
||
|
||
fclose(ORIGEN);
|
||
}
|
||
}
|
||
|
||
fclose(DESTINO);
|
||
|
||
}
|
||
|
||
long Longitud(const char *File )
|
||
{
|
||
FILE *file;
|
||
long devolver;
|
||
|
||
if ( (file = fopen( File, "rb")) == NULL )
|
||
{
|
||
return 0;
|
||
}
|
||
devolver = filelength(fileno(file));
|
||
fclose(file);
|
||
return devolver;
|
||
} |