Skip to content

Commit

Permalink
Tranforma as definições das estruturas em bibliotecas #26
Browse files Browse the repository at this point in the history
As estruturas da tabela de parâmetros e do modelo são carregadas no
programa principal, o conversor itf2bin.c

Lê os pares chave=valor do arquivo itf em looping
  • Loading branch information
Dirack committed Apr 7, 2020
1 parent 315fe73 commit 101d4a1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 70 deletions.
17 changes: 1 addition & 16 deletions lib/estruturaModeloItf.c → lib/estruturaModeloItf.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* estruturaModeloItf.c (C)
* estruturaModeloItf.h (C)
*
* Objetivo: Define a estrutura de dados do modelo itf.
*
Expand Down Expand Up @@ -104,18 +104,3 @@ void printInterface(interface* i){
printf("0\n");

}

int main(void){

header* h;
interface* i;
float x[2]={0,12};
float z[2]={1,1.5};
float s[3]={0.5,0.5,0.6};

h = initHeader(1,0,12,0,3.5);
printHeader(h);

i = initInterface(x,z,s);
printInterface(i);
}
73 changes: 36 additions & 37 deletions lib/itf2bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,56 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void error(size_t nerror,const char* msg){
fprintf(stderr,"%s: ERRO(%ld): %s\n",__FILE__,nerror,msg);
exit(nerror);
}

struct Header{
float xmin;
float xmax;
float zmin;
float zmax;
};

typedef struct Header *header;
#include "estruturaModeloItf.h"
#include "tabelaParametros.h"

int main(int argc, char* argv[]){

FILE *fp;
char ch[50];
int i;
header h = (header) malloc(sizeof(*h));
char* eq;
float v[4];
char* valor;
char* chave;
char* value;
size_t keylen;
size_t valen;
char ch[50];
tabela tab;
init(&tab);

if(argv[1]==NULL)
error(1,"O usuário não passou nenhum arquivo!");
/* Abrir arquivo itf */
if(argv[1]==NULL){
fprintf(stderr,"O usuário não passou nenhum arquivo!\n");
exit(1);
}

if((fp=fopen(argv[1],"r"))==NULL)
error(2,"Não foi possível abrir o arquivo passado!");
if((fp=fopen(argv[1],"r"))==NULL){
fprintf(stderr,"Não foi possível abrir o arquivo passado!\n");
exit(2);
}

/* Ler até a tag de marcação <tm> */
while(strstr(ch,"<tm>")==NULL)
fscanf(fp,"%s\n",ch);

for(i=0;i<4;i++){

/* Começa a ler os parâmetros chave=valor */
while(strstr(ch,"</tm>")==NULL){
fscanf(fp,"%s\n",ch);
eq = strchr(ch,'=');
if(eq==NULL)
valor = strchr(ch,'=');
if(valor==NULL)
continue;
eq++;
v[i]=strtof(eq,NULL);
valor++;
value = (char*) malloc(strlen(valor)*sizeof(char));
value = strcpy(value,valor);
keylen = (size_t) (valor-ch);
chave = (char*) malloc(keylen*sizeof(char));
memcpy(chave,ch,keylen);
chave[keylen-1]='\0';
push(&tab,chave,value);
}

h->xmin=v[0];
h->xmax=v[1];
h->zmin=v[2];
h->zmax=v[3];
printf("xmin=%f\nxmax=%f\nzmin=%f\nzmax=%f\n",
h->xmin,
h->xmax,
h->zmin,
h->zmax);
print(tab);

printf("zmax=%s\n",getvalue(tab,"zmax"));

fclose(fp);
}
17 changes: 0 additions & 17 deletions lib/tabelaParametros.c → lib/tabelaParametros.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,3 @@ char* getvalue(tabela t,char* chave){
if(isempty(t)) return NULL;
getvalue(t->prox,chave);
}

int main(void){
tabela tab;
init(&tab);
push(&tab,"k1","val1");
push(&tab,"k2","val2");
printf("%s\n",getvalue(tab,"k1"));
}









0 comments on commit 101d4a1

Please sign in to comment.