First commit 11/11/1991
This commit is contained in:
134
SV_REF_X.CPP
Normal file
134
SV_REF_X.CPP
Normal file
@ -0,0 +1,134 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graphics.h>
|
||||
#include <string.h>
|
||||
#include <alloc.h>
|
||||
#include "sv_ref_x.h"
|
||||
|
||||
|
||||
struct direccion far *Addr;
|
||||
|
||||
int *Ref_inx_addr;
|
||||
int Ref_no_valid;
|
||||
char Memory_ok;
|
||||
char Uso_de_la_Memoria;
|
||||
|
||||
|
||||
void BuscaReferencia(int Referencia){
|
||||
|
||||
int LSJ = sizeof(struct JD);
|
||||
int LSI = sizeof(struct Ref_inx);
|
||||
int LSC = sizeof(struct Referencias);
|
||||
|
||||
|
||||
if( Uso_de_la_Memoria == 1 ) {
|
||||
|
||||
Ref_no_valid = 0;
|
||||
int ok=0;
|
||||
int i, Direccion;
|
||||
|
||||
for(i=0; i<(Ref1_inx.Fin+1) && ok==0; i++)
|
||||
|
||||
if ( Addr[i].Ref_inx_Ref == Referencia ) { ok=1; Direccion = i; }
|
||||
|
||||
if ( ok == 0 ) {
|
||||
strcpy(Ref1.Concepto, "REFERENCIA NO VALIDA");
|
||||
Ref1.P_und = 0;
|
||||
Ref_no_valid = 1;
|
||||
} else {
|
||||
fseek(Ref, (long)LSJ + LSI + ( LSC * ( Addr[Direccion].Ref_inx_Addr - 1) ), SEEK_SET); // Se coloca
|
||||
fread(&Ref1, LSC, 1, Ref); // Y lee
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if(Ref_inx_addr[Referencia] == 0){
|
||||
strcpy(Ref1.Concepto, "REFERENCIA NO VALIDA");
|
||||
Ref1.P_und = 0;
|
||||
Ref_no_valid = 1;
|
||||
} else {
|
||||
|
||||
fseek(Ref, (long)LSJ + LSI + ( LSC * (Ref_inx_addr[Referencia]-1) ), SEEK_SET); // Se coloca
|
||||
fread(&Ref1, LSC, 1, Ref); // Y lee
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Carga_Referencias(void){
|
||||
|
||||
int i;
|
||||
int LSJ = sizeof(struct JD);
|
||||
int LSI = sizeof(struct Ref_inx);
|
||||
int LSC = sizeof(struct Referencias);
|
||||
|
||||
|
||||
if( Ref1_inx.Fin >= 5000 ) Uso_de_la_Memoria = 0; else Uso_de_la_Memoria = 1;
|
||||
|
||||
|
||||
if( Uso_de_la_Memoria == 1 ) {
|
||||
// Comienza proceso de carga de las Referencias.
|
||||
// 1<> Comprobamos la memoria disponible, y si hay, asignamos suficiente.
|
||||
if( (Addr = (struct direccion far *)farmalloc( (sizeof(struct direccion) * (Ref1_inx.Fin+1) ) ) ) == NULL ) {
|
||||
Memory_ok = 0;
|
||||
restorecrtmode();
|
||||
exit(1);
|
||||
} else {
|
||||
|
||||
i = 0;
|
||||
// Cargamos las posiciones de las referencias en el archivo.
|
||||
|
||||
while(i <= Ref1_inx.Fin ){
|
||||
|
||||
fseek(Ref, (long)LSJ + LSI + ( LSC * i ), SEEK_SET); // Se coloca
|
||||
fread(&Ref1, LSC, 1, Ref); // Y lee
|
||||
Addr[i].Ref_inx_Ref = Ref1.Ref;
|
||||
Addr[i].Ref_inx_Addr = (i+1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if( (Ref_inx_addr = (int *)malloc( (sizeof(int) * (10001) ) ) ) == NULL ) {
|
||||
Memory_ok = 0;
|
||||
restorecrtmode();
|
||||
exit(1);
|
||||
} else {
|
||||
|
||||
for(i=0; i<10000; i++) Ref_inx_addr[i] = 0;
|
||||
|
||||
i = 0;
|
||||
// Cargamos las posiciones de las referencias en el archivo.
|
||||
|
||||
while(i <= Ref1_inx.Fin ){
|
||||
fseek(Ref, (long)LSJ + LSI + ( LSC * i ), SEEK_SET); // Se coloca
|
||||
fread(&Ref1, LSC, 1, Ref); // Y lee
|
||||
Ref_inx_addr[Ref1.Ref]=(i+1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Existe_Referencia(int Referencia){
|
||||
|
||||
if( Uso_de_la_Memoria == 1 ) {
|
||||
|
||||
Ref_no_valid = 0;
|
||||
int ok=0;
|
||||
int i;
|
||||
|
||||
for(i=0; i<(Ref1_inx.Fin+1) && ok==0; i++)
|
||||
if ( Addr[i].Ref_inx_Ref == Referencia ) ok=1;
|
||||
|
||||
if ( ok == 0 ) return 0; else return 1;
|
||||
|
||||
} else {
|
||||
|
||||
if(Ref_inx_addr[Referencia] == 0) return 0; else return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user