247 lines
6.5 KiB
C++
247 lines
6.5 KiB
C++
///////////////////////////////////////////////////////////////////////////
|
||
//// Nombre: CPrinter.CPP ///
|
||
//// Modulo: Perteneciente a Catalogo.CPP ///
|
||
//// Descripci¢n: M¢dulo para imprimir total o parcialmente todo ///
|
||
//// ///
|
||
//// Autor: Jos‚ David Guill‚n Dominguez ///
|
||
//// Fecha: 02 - 01 - 1995 ///
|
||
//// ///
|
||
//// Comentario: ///
|
||
//// ///
|
||
//// ///
|
||
//// Compilador Borland C++ 3.0 ///
|
||
///////////////////////////////////////////////////////////////////////////
|
||
|
||
#include <stdio.h>
|
||
#include <string.h>
|
||
|
||
extern struct JD { char esc; char color[8]; char prog[14]; char nl;
|
||
char rt; char autor[36]; char pt; char ef; };
|
||
|
||
extern struct caddview_inx { unsigned int Fin[4]; unsigned int FinC; };
|
||
|
||
extern struct caddview { unsigned int record_zone; int nombre_zona;
|
||
char nombre[13+1]; char zip[3+1]; int kbytes; };
|
||
|
||
extern struct caddviewComentario {
|
||
int record_zone_init; // Zona de grabaci¢n interna
|
||
char linea[10][32 + 1]; // 32 digitos * 10 lineas
|
||
};
|
||
|
||
// extern struct JD cabecera;
|
||
extern struct caddview JD;
|
||
extern struct caddview_inx JDn;
|
||
extern struct caddviewComentario JD_comment;
|
||
|
||
|
||
extern FILE *JD_f; // Fichero JD
|
||
|
||
extern void BorraViewPort(int view);
|
||
|
||
void Select_archivo(int archivo);
|
||
void Imprimir_Individual(int x);
|
||
void Imprime_Cabecera(int cual);
|
||
void Imprime_Seccion(int cual);
|
||
void Imprime_Mensaje(void);
|
||
int Abre_Lee(void);
|
||
|
||
|
||
extern char ArchivoDatos[13];
|
||
int linea = 0;
|
||
|
||
void Imprimir_Individual(int x) {
|
||
|
||
int xm = x;
|
||
|
||
BorraViewPort(1); BorraViewPort(2); BorraViewPort(3);
|
||
|
||
linea=0;
|
||
|
||
if( xm == 0 ) {
|
||
|
||
while(xm<10){
|
||
|
||
xm++;
|
||
|
||
Select_archivo(xm);
|
||
if( !Abre_Lee() ) {
|
||
Imprime_Cabecera(xm);
|
||
Imprime_Seccion(xm);
|
||
fclose(JD_f);
|
||
|
||
if(linea>=50) { fputc(12, stdprn);
|
||
if (ferror(stdprn)) { clearerr(stdprn); // Mensaje("Error en el dispositivo PRN", 0);
|
||
return; }
|
||
// Mensaje("Inserte un nuevo folio", 0);
|
||
linea = 1;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
Imprime_Mensaje();
|
||
} else {
|
||
|
||
Select_archivo(x);
|
||
if(Abre_Lee()) { //Mensaje("Secci¢n Vacia", 0);
|
||
return; }
|
||
Imprime_Cabecera(x);
|
||
Imprime_Seccion(x);
|
||
fclose(JD_f);
|
||
}
|
||
|
||
fputc(12, stdprn);
|
||
}
|
||
|
||
void Imprime_Cabecera(int cual) {
|
||
|
||
char *texto[] = { "Juegos ", "M£sica ", "P.Textos",
|
||
"Contabil. ", "Electr¢n. ", "Gr ficos",
|
||
"Utilidades", "Lenguajes ", "Windows ",
|
||
"Varios... " };
|
||
|
||
fprintf(stdprn, "\n\r\n\r");
|
||
if (ferror(stdprn)) { clearerr(stdprn);
|
||
// Mensaje("Error en el dispositivo PRN", 0);
|
||
return;
|
||
}
|
||
|
||
fprintf(stdprn, "%s", texto[cual-1] );
|
||
fprintf(stdprn, "\n\r\n\r");
|
||
|
||
linea += 3;
|
||
|
||
|
||
}
|
||
|
||
void Imprime_Seccion(int cual) {
|
||
|
||
int LSJ = sizeof(struct JD);
|
||
int LSI = sizeof(struct caddview_inx);
|
||
int LSC = sizeof(struct caddview);
|
||
int columna=1, x, Inicio;
|
||
|
||
switch ( cual ) { case 1: case 2: case 3: case 4: x = cual - 1; break;
|
||
case 5: case 6: case 7: case 8: x = cual - 5; break;
|
||
case 9: case 10: case 11: case 12: x = cual - 9; break;
|
||
default: break; }
|
||
|
||
if ( x==0 ) Inicio = 0; else Inicio = ( JDn.Fin[ x - 1] + 1 );
|
||
|
||
|
||
fseek(JD_f, (long)LSJ + LSI + ( LSC * Inicio ), SEEK_SET);
|
||
|
||
while (Inicio <= (JDn.Fin[x]) ) {
|
||
fread(&JD, LSC, 1, JD_f);
|
||
fprintf(stdprn, "%-13s %-3s %4d ³ ", (JD. nombre), (JD. zip), (JD. kbytes) );
|
||
columna ++;
|
||
if(columna==4) { fprintf(stdprn, "\n\r");
|
||
if (ferror(stdprn)) { clearerr(stdprn); // Mensaje("Error en el dispositivo PRN", 0);
|
||
return; }
|
||
columna=1; linea++;
|
||
if(linea==60) { fputc(12, stdprn); // Va al principio de la p gina siguiente
|
||
if (ferror(stdprn)) { clearerr(stdprn); // Mensaje("Error en el dispositivo PRN", 0);
|
||
return; }
|
||
// Mensaje("Inserte un nuevo folio", 0);
|
||
linea = 1;
|
||
}
|
||
}
|
||
Inicio++;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
void Select_archivo(int archivo) {
|
||
|
||
switch (archivo) {
|
||
case 1: case 2: case 3: case 4:
|
||
|
||
strcpy(ArchivoDatos, "CATALOG1.DAT");
|
||
// strcpy(ArchivoComentario, "CATALO11.DAT");
|
||
break;
|
||
|
||
case 5: case 6: case 7: case 8:
|
||
|
||
strcpy(ArchivoDatos, "CATALOG2.DAT");
|
||
// strcpy(ArchivoComentario, "CATALO21.DAT");
|
||
break;
|
||
|
||
case 9: case 10: case 11: case 12:
|
||
default:
|
||
|
||
strcpy(ArchivoDatos, "CATALOG3.DAT");
|
||
// strcpy(ArchivoComentario, "CATALO31.DAT");
|
||
break;
|
||
|
||
}
|
||
}
|
||
|
||
int Abre_Lee(void) {
|
||
|
||
int LSJ = sizeof(struct JD);
|
||
int LSI = sizeof(struct caddview_inx);
|
||
int LSC = sizeof(struct caddview);
|
||
|
||
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ//
|
||
//ÛÛ Comprueba apertura correcta de Indice, y Datos ÛÛ//
|
||
//ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ//
|
||
if ( (JD_f = fopen( ArchivoDatos, "r+b"))==NULL) {
|
||
return 1;
|
||
} else {
|
||
|
||
fseek(JD_f, (long)LSJ, SEEK_SET);
|
||
if ( fread(&JDn, LSI, 1, JD_f) != 1 ) {
|
||
//Mensaje("Error de Lectura", 0);
|
||
printf("NO SE PUDO LEER EN EL FICHERO: INDICE");
|
||
return 1;
|
||
}
|
||
|
||
fseek(JD_f, (long)LSJ+LSI, SEEK_SET);
|
||
if ( fread(&JD, LSC, 1, JD_f) != 1 ) {
|
||
//Mensaje("Error de Lectura", 0);
|
||
printf("NO SE PUDO LEER EN EL FICHERO: DATOS");
|
||
return 1;
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
|
||
void Imprime_Mensaje(void) {
|
||
|
||
FILE *JDm_f; // Fichero Mensajes
|
||
char ArchivoMensaje[13]="CMensaje.dat";
|
||
|
||
int LSJ = sizeof(struct JD);
|
||
int LSC = sizeof(struct caddviewComentario);
|
||
|
||
if ( (JDm_f = fopen( ArchivoMensaje, "r+b"))==NULL) {
|
||
// Mensaje("Error de Lectura",0);
|
||
printf("NO SE PUDO ABRIR EL FICHERO COMENTARIO EN LA 2§ PASADA");
|
||
return;
|
||
}
|
||
|
||
fseek(JDm_f, (long)LSJ, SEEK_SET);
|
||
if ( fread(&JD_comment, LSC, 1, JDm_f) != 1 ) {
|
||
// Mensaje("Error de Lectura", 0);
|
||
printf("NO SE PUDO LEER EL FICHERO COMENTARIO");
|
||
return;
|
||
}
|
||
|
||
if(linea<=52) {
|
||
fprintf(stdprn, "\n\r");
|
||
for(int i=0; i<10; i++) {
|
||
fprintf(stdprn, "\n\r");
|
||
fprintf(stdprn, " %s", JD_comment. linea[i] );
|
||
if (ferror(stdprn)) { clearerr(stdprn);
|
||
// Mensaje("Error en el dispositivo PRN", 0);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
fclose( JDm_f );
|
||
|
||
} |