Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions trabalho3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ NAME=programaTrab2
# Directories
INCDIR=include
LIBDIR=lib
BLDDIR=build
BLDDIR=bin
SRCDIR=src
OBJDIR=$(SRCDIR)/obj
OBJDIR=$(SRCDIR)

# Can use any debbuger (like gdb) or overlay (like valgrind) (though gdb is an overlay too)
DEBUGGER=
Expand Down
File renamed without changes.
Binary file added trabalho3/bin/programaTrab2
Binary file not shown.
Binary file removed trabalho3/build/programaTrab2
Binary file not shown.
25 changes: 4 additions & 21 deletions trabalho3/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
TRABALHO 3 - ORGANIZAÇÃO DE ARQUIVOS

Nome: Michelle Wingter da Silva nUSP: 10783243
Juliano Fantozzi xxxxxxxx
Juliano Fantozzi 9791218

*/

Expand Down Expand Up @@ -121,31 +121,17 @@ void remove_registro(){
char nomeCampo[MAX];
char valorCampo[MAX];

//int n_rem = 0;
//REG_REM* listaRem = NULL;

scanf(" %s %d", nomeBin, &n);

//criando lista de removidos
//NO_REG_REM* lista_rem;

for (int i = 0; i < n; ++i)
{
//scanf("%s %s", nomeCampo, valorCampo);
for (int i = 0; i < n; ++i){
scanf("%s", nomeCampo);
scan_quote_string(valorCampo);
//printf("nome e valor|%s|%s|\n", nomeCampo, valorCampo);
//lista_rem = calloc(1, sizeof(NO_REG_REM));
busca_RemoveReg(nomeBin, nomeCampo, valorCampo);
}
//fclose(bin);

binarioNaTela2(nomeBin);
//printf("\nListar o arquivo binário %s.", nomeBin);


//free(lista_rem);

//printf("\nListar o arquivo binário %s.", nomeBin);
}

/*
Expand All @@ -158,13 +144,11 @@ void insere_registro(){
scanf(" %s %d", nomeBin, &n);

char idStr[MAX], salStr[MAX], tel[MAX], nome[MAX], cargo[MAX];
//int id; double sal;
REGDADOS *rd;

long int ultimo_reg = -1;

for (int i = 0; i < n; ++i)
{
for (int i = 0; i < n; ++i){
scanf("%s ", idStr);
scanf("%s ", salStr);
scan_quote_string(tel);
Expand All @@ -173,7 +157,6 @@ void insere_registro(){
//printf("id|%s|, sal|%s|, tel|%s|, nome|%s|, cargo|%s|\n", idStr, salStr, tel, nome, cargo);

rd = calloc(1, sizeof(REGDADOS));
//criaNovoRegDados(rd, id, sal, tel, nome, cargo);
criaNovoRegDados2(rd, idStr, salStr, tel, nome, cargo);
// printf("\n==========INSERINDO: \n\tid|%d|, sal|%lf|, tel|%s|, nome|%s|, cargo|%s|\n", rd->idServidor, rd->salarioServidor, rd->telefoneServidor, rd->nomeServidor, rd->cargoServidor);
// printf("TAMANHOS: \n\ttel = %ld\n\tnome = %d\n\tcargo = %d\n\t", strlen(tel), rd->tamNomeServidor, rd->tamCargoServidor);
Expand Down
2 changes: 1 addition & 1 deletion trabalho3/src/manipulaReg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
TRABALHO 3 - ORGANIZAÇÃO DE ARQUIVOS

Nome: Michelle Wingter da Silva nUSP: 10783243
Juliano Fantozzi xxxxxxxx
Juliano Fantozzi 9791218

*/

Expand Down
134 changes: 106 additions & 28 deletions trabalho3/src/organizaArq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
TRABALHO 3 - ORGANIZAÇÃO DE ARQUIVOS

Nome: Michelle Wingter da Silva nUSP: 10783243
Juliano Fantozzi xxxxxxxx
Juliano Fantozzi 9791218

*/

Expand Down Expand Up @@ -71,61 +71,139 @@ void ordena_por_id(char *nomeBin_in, char *nomeBin_out){

fclose(bin_in);
fclose(bin_out);
}

//========================== MERGING DE DOIS ARQUIVOS ======================
void read_andMerge(char *nomeBin_in1, char *nomeBin_in2, char *nomeBin_out){
//========= checando arquivo 1 ============
FILE* bin_in1 = fopen(nomeBin_in1, "rb");
fileCheck(bin_in1);

FILE* bin_in2 = fopen(nomeBin_in2, "rb");
fileCheck(bin_in2);

FILE* bin_out = fopen(nomeBin_out, "wb");
fileCheck(bin_out);

REGCAB* rc = calloc(1, sizeof(REGCAB));
REGDADOS *rd1 = NULL;
REGDADOS *rd2 = NULL;


leCabecalho(nomeBin_in1, rc);
regCabToArqBin(rc, bin_out);

do{
rd1 = pegarProximoRegistro(bin_in1);
rd2 = pegarProximoRegistro(bin_in2);
pegaRegistroNoOffset

if(rd1.idServidor > rd2.idServidor && rd1 && rd2){
REGDADOS *aux = rd2;
rd2 = rd1;
rd1 = aux;
}

escreveRegDados(bin_out, rd1);
if(rd1.idServidor != rd2.idServidor) escreveRegDados(bin_out, rd2);

if (rd1) free(rd1);
if (rd2) free(rd2);
}
while(rd1 || rd2);

free(rc);
fclose(bin_in1);
fclose(bin_in2);
fclose(bin_out);
}

//========================== MATCHING DE DOIS ARQUIVOS ======================
void read_andMatch(char *nomeBin_in1, char *nomeBin_in2, char *nomeBin_out){
}

//========================== FUNCOES AUXILIARES =============================

int int_compare_id(const void *A, const void *B) { // para ordenar de forma crescente
REGDADOS *pA, *pB;
pA = (REGDADOS *) A;
pB = (REGDADOS *) B;
return pB->idServidor - pA->idServidor;
}

//========================== MERGING DE DOIS ARQUIVOS ======================
void read_andMerge(char *nomeBin_in1, char *nomeBin_in2, char *nomeBin_out){
//========= checando arquivo 1 ============
FILE* bin_in1 = fopen(nomeBin_in1, "rb");
if(bin_in1 == NULL){
void fileCheck(FILE *fp){
if(fp == NULL){
printf("Falha no processamento do arquivo.\n");
exit(0);
}

char status1;
fread(&status1, STATUS_TAM, 1, bin_in1);
char status;
fread(&status, STATUS_TAM, 1, fp);
//printf("status = %c\n", status);

if (status1 == '0') {
printf("Falha no processamento do arquivo.\n");
fclose(bin_in1);
exit(0);
}
//========= checando arquivo 2 ============
FILE* bin_in2 = fopen(nomeBin_in2, "rb");
if(bin_in2 == NULL){
if (status == '0') {
printf("Falha no processamento do arquivo.\n");
fclose(fp);
exit(0);
}
}

char status2;
fread(&status2, STATUS_TAM, 1, bin_in2);
//printf("status = %c\n", status);
REGDADOS *pegarProximoRegistro(FILE *fp){
if(feof(fp)) return NULL;

if (status2 == '0') {
printf("Falha no processamento do arquivo.\n");
fclose(bin_in2);
exit(0);
}

void escreveRegDados(int* tamPagina, int *tamRegAnterior, REGDADOS* r, REGCAB* c, FILE* bin){
if (r->idServidor == -1){
return;
}
//========================================

//merge dos dois arquivos de entrada para o arquivo de saida
int aux = r->tamanhoRegistro + 5;

if((*tamPagina - aux) < 0){
char arroba = '@';

for(int i = 0; i < *tamPagina; i++){
fwrite(&arroba, sizeof(char), 1, bin);
(*tamRegAnterior) = (*tamRegAnterior) + 1;
}

}
//adicionar o tamanho desses arrobas no ultimo registro da pagina
fseek(bin, -(*tamRegAnterior + 4), SEEK_CUR);
fwrite(&(*tamRegAnterior), sizeof(int), 1, bin);

fseek(bin, 0, SEEK_END);

*tamPagina = 32000;
}

//========================== MATCHING DE DOIS ARQUIVOS ======================
void read_andMatch(char *nomeBin_in1, char *nomeBin_in2, char *nomeBin_out){
*tamPagina -= aux;

fwrite(&r->removido, REM_TAM, 1, bin);
fwrite(&r->tamanhoRegistro, TAM_TAM, 1, bin);
fwrite(&r->encadeamentoLista, ENC_TAM, 1, bin);
fwrite(&r->idServidor, ID_TAM, 1, bin);
fwrite(&r->salarioServidor, SAL_TAM, 1, bin);
fwrite(&r->telefoneServidor, TEL_TAM * sizeof(char), 1, bin);

if(r->nomeServidor[0] != '\0'){
int tamanho2 = strlen(r->nomeServidor) + 2;
fwrite(&tamanho2, TAM_TAM, 1, bin);
fwrite(&c->tags[3], TAG_TAM, 1, bin);
fwrite(&r->nomeServidor, strlen(r->nomeServidor) * sizeof(char) + 1, 1, bin);
}

if(r->cargoServidor[0] != '\0'){
int tamanho = strlen(r->cargoServidor) + 2;
fwrite(&tamanho, TAM_TAM, 1, bin);
fwrite(&c->tags[4], TAG_TAM, 1, bin);
fwrite(&r->cargoServidor, strlen(r->cargoServidor) * sizeof(char) + 1, 1, bin);
}

if(*tamPagina == 0){
*tamPagina = 32000;
}

(*tamRegAnterior) = r->tamanhoRegistro;
}
}
2 changes: 1 addition & 1 deletion trabalho3/src/rcab.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
TRABALHO 3 - ORGANIZAÇÃO DE ARQUIVOS

Nome: Michelle Wingter da Silva nUSP: 10783243
Juliano Fantozzi xxxxxxxx
Juliano Fantozzi 9791218

*/

Expand Down
2 changes: 1 addition & 1 deletion trabalho3/src/rdados.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
TRABALHO 3 - ORGANIZAÇÃO DE ARQUIVOS

Nome: Michelle Wingter da Silva nUSP: 10783243
Juliano Fantozzi xxxxxxxx
Juliano Fantozzi 9791218

*/

Expand Down