HERM/HERM_UTL.CPP
2021-09-12 20:06:36 +02:00

502 lines
10 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdarg.h>
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <alloc.h>
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <dos.h>
#include <io.h>
#include <bios.h>
#include "..\libs\make_bot\make_bot.h"
#include "herm.h"
extern CONFIG Config;
void BEEP(void);
void Escr_Mensaje(char *Encabezado, char lineas, char Mensaje[][50] );
int DifDate( struct date FechaF, struct date FechaO, struct date *FechaD );
int InputCadenaG_T5(char *s, int numalp, int lmax, int cc, int cf, int X0, int Y0, int X1, int Y1)
{
// A todas las y les sumaba antes +RoW*12 parametro que indica la linea
int ls; // longitud cadena
char Status = 0;
char *s1; // puntero a cadena inicial
int c, ok;
s1 = s; // inicio cadena
setfillstyle(SOLID_FILL, cf);
bar(X0, Y0, X1, Y1);
setcolor(cc); outtextxy( X0, Y0, s1 );
ls = strlen ( s ); // Longitud de actual
if ( ls < lmax ) {
setcolor(BLANCO);
outtextxy( X0+textwidth( s1 ), Y0, "þ");
}
s += ls; // se coloca en el final
do{
c = getch(); // obtiene tecla
if ( c == 27 ) Status = 1;
ok = ( c == 27 || c == 13 || c == 0); // 13 = INTRO || Especiales
if ( c == 8 && ls > 0 && !ok ) { // 8 = Back Space
ls--;
s--;
*s = '\0';
setfillstyle(SOLID_FILL, cf);
bar(X0, Y0, X1, Y1);
setcolor(cc); outtextxy( X0, Y0, s1 );
setcolor(BLANCO);
outtextxy( X0+textwidth( s1 ), Y0, "þ");
setcolor(cc);
} else {
if ( !numalp && c >= 32 && c <= 254 && ls < lmax) {
*s++ = c;
ls++;
*s = '\0';
setfillstyle(SOLID_FILL, cf);
bar(X0, Y0, X1, Y1);
setcolor(cc); outtextxy( X0, Y0, s1 );
if ( ls < lmax ) {
setcolor(BLANCO);
outtextxy( X0+textwidth( s1 ), Y0, "þ");
}
} else {
if ( numalp && isdigit(c) && ls < lmax) {
*s++ = c;
ls++;
*s = '\0'; // Cero final
setfillstyle(SOLID_FILL, cf);
bar(X0, Y0, X1, Y1);
setcolor(cc); outtextxy( X0, Y0, s1 );
if ( ls < lmax ) {
setcolor(BLANCO);
outtextxy( X0+textwidth( s1 ), Y0, "þ");
}
}
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
else if( c == 27 ) {*s='\0'; ok = 1; }
/*ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ*/
else BEEP();
}
}
}while(!ok);
ok = 1;
*s = ' ';
while( ok && ls >= 0 ) {
if(*s==' ') { *s = '\0'; s--; ls--;
} else { s++; ok = 0; }
}
*s = '\0';
while(kbhit()) getch(); // Vacia Buffer impidiendo falsas
// pulsaciones...
return ( (Status<<8) + (ls&0x00FF) );
}
void BEEP(void){
sound(440);
delay(50);
nosound();
}
/*
char Optar( char *texto1, char *texto2, char *texto3 )
{
int ok = 0, inst = 0;
struct textsettingstype textinfo;
void *C_Texto, *C_Aceptar, *C_Cancelar;
C_Texto = malloc( JD_imagesize(200, 212, 440, 267) );
C_Aceptar = malloc( JD_imagesize(200, 270, 280, 295) );
C_Cancelar = malloc( JD_imagesize(360, 270, 440, 295) );
if( C_Texto == NULL || C_Aceptar == NULL || C_Cancelar == NULL) {
closegraph();
cprintf("\n\rSALIENDO");
cprintf("\n\rImposible encontrar %ldKbytes en el Heap",
( JD_imagesize(118, 160, 521, 335) +
JD_imagesize(118, 160, 521, 335) +
JD_imagesize(118, 160, 521, 335)
)
);
exit(SIN_MEMORIA);
}
gettextsettings(&textinfo);
settextstyle(SMALL_FONT, HORIZ_DIR, 5 );
// settextjustify(CENTER_TEXT, CENTER_TEXT);
getimage(200, 212, 440, 267, C_Texto);
getimage(200, 270, 280, 295, C_Aceptar);
getimage(360, 270, 440, 295, C_Cancelar);
Imprime_Estaticos(100, "herm.img"); // Imprime botones estaticos 'Seccion 20'
Imprime_Secuencia(2); // Imprime secuencia 4.
Imprime_Estaticos(101, "herm.img"); // Imprime textos estaticos 'Seccion 5'
setcolor( AZUL );
outtextxy( 210+( ( 230 - textwidth(texto1) ) / 2 ), 220, texto1 );
outtextxy( 210+( ( 230 - textwidth(texto2) ) / 2 ), 235, texto2 );
outtextxy( 210+( ( 230 - textwidth(texto3) ) / 2 ), 250, texto3 );
while(!ok){ // Bucle infinito
switch( Comprueba_Secuencia( 2, NULL ) ) { // Iniciamos comprobacion de 2¦ sec
case 0: // No se pulso ningun BOTON
// Pero el raton fue presionado en
// algun sitio...
break;
case -2: // Hay una tecla normal en BUFFER
switch( getch() ) { // La utilizamos
// ESC ( CANCELAR )
case 14:
inst = 0;
ok = 1;
break;
default:
break;
}
break;
case -1: // Hay una tecla especial en BUFFER
getch(); // La eliminamos
break;
// Boton Aceptar
case 1:
inst = 1;
ok = 1;
break;
// Boton Cancelar
case 2:
inst = 0;
ok = 1;
break;
default:
while( kbhit() ) getch(); // Limpiamos posibles teclas en BUFFER
break;
}
}
putimage(200, 212, C_Texto, COPY_PUT);
putimage(200, 270, C_Aceptar, COPY_PUT);
putimage(360, 270, C_Cancelar, COPY_PUT);
free ( C_Texto );
free ( C_Aceptar );
free ( C_Cancelar );
settextstyle(textinfo.font, textinfo.direction, textinfo.charsize );
settextjustify(textinfo.horiz, textinfo.vert);
return inst;
}
*/
int file_exists(char *filename)
{
return (access(filename, 0) == 0);
}
int Comprueba_Impresora(void){
/*
unsigned int tmp;
union REGS Impresora_in, Impresora_out;
struct byte {
int a : 1;
int b : 1;
int c : 1;
int d : 1;
int e : 1;
int f : 1;
int g : 1;
int h : 1;
};
union bits {
char ch;
struct byte bit;
} Imp_out;
Impresora_in.h.ah = 0x02;
Impresora_in.x.dx = 0x0;
int86(0x17, &Impresora_in, &Impresora_out);
return ( Impresora_out.h.ah ? 1 : 0 );
*/
return ( biosprint(2, 0, 0) & 0x80 );
}
void CodigoImpresora( char *codigo )
{
int i = 0; char code_hex[3], *endptr;
code_hex[2] = '\0';
for( i=0; codigo[i+1] != '\0'; i+=2 )
{
code_hex[1] = codigo[i];
code_hex[2] = codigo[i+1];
fputc( (int)strtol(code_hex, &endptr, 16), stdprn );
}
}
#define IGNORE 0
#define RETRY 1
#define ABORT 2
/*
pragma warn -par reduces warnings which occur
due to the non use of the parameters errval,
bp and si to the handler.
*/
#pragma warn -par
int handler(int errval,int ax,int bp,int si)
{
static char msg[80];
unsigned di;
int drive;
int errorno;
di= _DI;
/*
if this is not a disk error then it was
another device having trouble
*/
if (ax < 0)
{
while ( !kbhit() )
{
sound(1000); delay(5000); nosound();
}
getch();
/* and return to the program directly requesting abort */
hardresume(RETRY);
} else {
/*
return to the program via dos interrupt 0x23 with abort, retry,
or ignore as input by the user.
*/
hardretn(ABORT);
}
return ABORT;
}
#pragma warn +par
#define SEC_OPTAR 5
int Optar( int optar, ... )
{
static void far *fondo, far *fd_aceptar, far *fd_cancelar;
static char Memoria = 0;
int DEV = 0, ok = 0, linea = 0;
int Center; char *buff;
struct textsettingstype texttypeinfo;
va_list ap;
va_start( ap, &optar );
if ( Memoria == 1 )
{
putimage( 170, 165, fondo , COPY_PUT );
putimage( 170, 320, fd_aceptar , COPY_PUT );
putimage( 370, 320, fd_cancelar, COPY_PUT );
farfree( fondo );
farfree( fd_aceptar );
farfree( fd_cancelar );
Memoria = 0;
if ( optar == ENCUADRE ) return DEV;
}
if ( ( fondo = farmalloc( JD_imagesize( 170, 165, 470, 315 ) ) ) != NULL &&
( fd_aceptar = farmalloc( JD_imagesize( 170, 320, 270, 350 ) ) ) != NULL &&
( fd_cancelar = farmalloc( JD_imagesize( 370, 320, 470, 350 ) ) ) != NULL )
{
Memoria = 1;
getimage( 170, 165, 470, 315, fondo );
getimage( 170, 320, 270, 350, fd_aceptar );
getimage( 370, 320, 470, 350, fd_cancelar);
gettextsettings( &texttypeinfo );
Imprime_Estaticos( 150, "herm.img" );
settextstyle( SMALL_FONT, HORIZ_DIR, 6 );
setcolor( 63 );
while ( (buff = va_arg(ap, char *)) != NULL )
{
Center = (296 - textwidth( buff ) ) / 2;
outtextxy( 172+Center, ( (linea == 0 ) ? 167 : 200 + 20*linea ), buff );
linea++;
}
va_end(ap);
settextstyle( texttypeinfo.font, texttypeinfo.direction, texttypeinfo.charsize );
if ( optar != ENCUADRE )
{
ok = 0; while( kbhit() ) getch(); // Limpiamos posibles teclas en BUFFER
do {
switch( Comprueba_Secuencia( SEC_OPTAR, NULL ) )
{
case 0: // No se pulso ningun BOTON
case -2:
case -1:
while( kbhit() ) getch(); // Limpiamos posibles teclas en BUFFER
if ( optar == 0 ) ok = 1;
break;
case 1:
DEV = 1; ok = 1;
break;
case 2:
DEV = 0; ok = 1;
break;
}
}while( !ok );
putimage( 170, 165, fondo , COPY_PUT );
putimage( 170, 320, fd_aceptar , COPY_PUT );
putimage( 370, 320, fd_cancelar, COPY_PUT );
farfree( fondo );
farfree( fd_aceptar );
farfree( fd_cancelar );
Memoria = 0;
}
}
return DEV;
}
int DifDate( struct date FechaF, struct date FechaO, struct date *FechaD )
{
struct date FechaTmp;
FechaF.da_mon = Config.MesVotacion;
if ( FechaO.da_year >= FechaF.da_year && FechaO.da_mon >= FechaF.da_mon )
{
if ( FechaD != NULL )
{
FechaD -> da_day = 0;
FechaD -> da_mon = 0;
FechaD -> da_year = 0;
}
return 0;
}
if ( FechaO.da_year == FechaF.da_year )
{
if ( FechaD != NULL )
{
FechaD -> da_day = 0;
FechaD -> da_mon = FechaF.da_mon - FechaO.da_mon;
FechaD -> da_year = 0;
}
return 0;
}
FechaTmp.da_day = 0;
FechaTmp.da_year = 0;
FechaTmp.da_mon = 12 - FechaO.da_mon;
FechaTmp.da_mon += FechaF.da_mon;
FechaTmp.da_year = FechaF.da_year - (FechaO.da_year + 1);
FechaTmp.da_year+= FechaTmp.da_mon / 12;
FechaTmp.da_mon = FechaTmp.da_mon % 12;
if ( FechaD != NULL )
*FechaD = FechaTmp;
// Esto es incorecto pero asi funcionar  ( Devuelvo los a¤os + 1 si hay
// alg£n mes suelto... )
return ( (FechaD -> da_mon != 0 ? 1 : 0) + FechaTmp . da_year );
}