Digi3D



Entidad.CPP


#include <stdio.h>

#include <stdlib.h>

#include <fcntl.h>

#include <io.h>

#include <sys\stat.h>

#include <conio.h>

#define     RESTO   6


   typedef struct lpoint3d LPOINT3D;

   struct lpoint3d{

        long x,y,z ;

   };


   typedef struct tipo_dat TIPO_DAT;

   struct tipo_dat {

         char          tipo[2];

         char          cod[7];

         unsigned char atr;         /* numero de atributos */

         unsigned short  npuntos;

   };


   typedef struct tipo_dat ATR;

   struct atr {

         short tabla;       /* numero de la tabla de BD */

         long registro;     /* numero del registro de la BD enlazado */

         char resto[RESTO] ;    /* disponible */

   };


   typedef struct tipo_max TIPO_MAX;

   struct tipo_max {

         long  xmin, ymin, zmin;

         long  xmax, ymax, zmax;

         long  xlib, ylib, zlib;

         };


   typedef struct cab_digi CAB_DIGI ;

   struct cab_digi {

       TIPO_DAT dat;

       TIPO_MAX max;

   };


   typedef struct TpEntidad Entidad;

   struct TpEntidad {

        int          ID;

        CAB_DIGI  cab;

        LPOINT3D  *coor;

        ATR       *atr;

        struct TpEntidad *Siguiente;

   };


   Entidad *ListaDeEntidades = NULL;


void CargaEntidad(Entidad dato,Entidad ** Lista)

{

        Entidad *Lista_aux;

        Lista_aux = (Entidad*)malloc(sizeof(Entidad));

        *Lista_aux = dato;

        Lista_aux->Siguiente = *Lista;

        *Lista = Lista_aux;

}


void CargaBIN(char *bin_arch)   {

   char asc_arch[80];

   FILE *fichero_ASCII;

   int fichero_BIN;


   if ((fichero_BIN = open(bin_arch,O_RDONLY|O_BINARY,S_IREAD))==-1) {

      printf("No se puede abrir el archivo... %s\n",bin_arch);

      exit(1);

   }

   else {

        int n=1;

        Entidad dato;

        lseek(fichero_BIN,0L,SEEK_SET);

        for(;;) {

        if (read(fichero_BIN,?= 0) break;

        dato.ID=n++;

        dato.coor = (LPOINT3D*)malloc(sizeof(LPOINT3D)*dato.cab.dat.npuntos);

        dato.atr = (ATR*)malloc(sizeof(ATR)*dato.cab.dat.npuntos);

        if (((dato.coor==NULL)?0))|

            ((dato.atr==NULL)?0)))

        {

             puts("Insuficiente memoria disponible \n");

             exit(1);

        }

        read(fichero_BIN,dato.coor,dato.cab.dat.npuntos * sizeof(LPOINT3D));

        read(fichero_BIN,dato.atr,dato.cab.dat.atr * sizeof(ATR));

        CargaEntidad(dato,?

        }

  close (fichero_BIN);

  }

}


void GuardaBIN(char *bin_arch)   {

   char asc_arch[80];

   FILE *fichero_ASCII;

   int fichero_BIN;


   if ((fichero_BIN = open(bin_arch,O_WRONLY|O_BINARY,S_IWRITE))==-1) {

      printf("No se puede abrir el archivo... %s\n",bin_arch);

      exit(1);

   }

   else {

        Entidad *dato;

        dato = ListaDeEntidades;

        lseek(fichero_BIN,0L,SEEK_SET);

        for(;dato!=NULL;dato=dato->Siguiente) {

        write(fichero_BIN,?cab),sizeof(CAB_DIGI));

        write(fichero_BIN,dato->coor,(*dato).cab.dat.npuntos * sizeof(LPOINT3D));

        write(fichero_BIN,dato->atr,(*dato).cab.dat.atr * sizeof(ATR));

        }

  close (fichero_BIN);

  }

}


void main(){

CargaBIN("c:\\kk.bin");

GuardaBIN("c:\\ll.bin");

};




Fecha de última modificación: viernes, 17 de Enero de 2003