*/
#include "idx.h"
-#include "tipo3.h"
+
+#define EMUFS_IDX_EXT ".idx"
+
+typedef struct emufs_idx_t {
+ int block;
+ long int id_reg;
+} EMUFS_IDX;
int emufs_idx_buscar_mayor_id(EMUFS *emu)
{
int id, max = -1;
FILE *f_idx;
- BLOCK_REG_T reg;
- char name_f_idx[255];
+ EMUFS_IDX reg;
+ char name_f_idx[255]; /* TODO usar malloc para no limitar el tamaƱo de nombre de archivo */
strcpy(name_f_idx,emu->nombre);
- strcat(name_f_idx,".idx");
+ strcat(name_f_idx, EMUFS_IDX_EXT);
if ( (f_idx = fopen(name_f_idx,"r")) == NULL) return -1; /*ERROR*/
id = -1;
while ( !feof(f_idx) ){
/* Me aseguro de leer la cantidad de bytes correcta */
- if (fread(®,sizeof(BLOCK_REG_T),1,f_idx) != 1) continue;
+ if (fread(®,sizeof(EMUFS_IDX),1,f_idx) != 1) continue;
if ( reg.id_reg >= max )
max = reg.id_reg;
}
int emufs_idx_buscar_registro(EMUFS *emu, int ID)
{
FILE* f_idx;
- BLOCK_REG_T reg;
+ EMUFS_IDX reg;
char name_f_idx[255];
strcpy(name_f_idx,emu->nombre);
- strcat(name_f_idx,".idx");
+ strcat(name_f_idx, EMUFS_IDX_EXT);
if ( (f_idx = fopen(name_f_idx,"r")) == NULL) return -1; /*ERROR*/
while ( !feof(f_idx) ){
- if (fread(®,sizeof(BLOCK_REG_T),1,f_idx) != 1) continue;
+ if (fread(®,sizeof(EMUFS_IDX),1,f_idx) != 1) continue;
if ( reg.id_reg == ID ){
fclose(f_idx);
return reg.block;
}
/* agrega un registro al final del archivo */
-emufs_idx_agregar(EMUFS *emu, int num_bloque, int ID_aux)
+int emufs_idx_agregar(EMUFS *emu, int num_bloque, int ID_aux)
{
FILE *f_idx;
- BLOCK_REG_T reg;
+ EMUFS_IDX reg;
char name_f_idx[255];
strcpy(name_f_idx,emu->nombre);
- strcat(name_f_idx,".idx");
+ strcat(name_f_idx, EMUFS_IDX_EXT);
if ( (f_idx = fopen(name_f_idx,"ab+"))==NULL ) return -1;
reg.block = num_bloque;
reg.id_reg = ID_aux;
- fwrite(®,sizeof(BLOCK_REG_T),1,f_idx);
+ fwrite(®,sizeof(EMUFS_IDX),1,f_idx);
fclose(f_idx);
return 0;
}