Skip to content

Commit

Permalink
Estrutura de dados da tabela de parâmetros #26
Browse files Browse the repository at this point in the history
Estabelece a estrutura de dados tabela, para guardar os parâmetros
lidos do arquivo itf em pares chave=valor e ler os valores a partir
da chave com a função getvalue.

Esta função irá permitir buscar os valores da tabela e preencher a
estrutura de dados que modela o arquivo itf. Após preencher esta
estrutura com todos os parâmetros necessários, a conversão para binário
poderá ser realizada.
  • Loading branch information
Dirack committed Apr 6, 2020
1 parent 6f8fdef commit b07274e
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions lib/tabelaParametros.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* tabelaParametros.h (C)
*
* Objetivo: Define a estrutura da tabela de parâmetros lida do arquivo itf.
* Os parâmetros serão lidos na forma chave=valor e organizados em uma tabela
* de parâmetros, que é uma estrutura do tipo pilha.
*
* Site: https://dirack.github.io
*
* Versão 1.0
*
* Programador: Rodolfo A C Neves (Dirack) 06/04/2020
*
* Email: [email protected]
*
* Licença: GPL-3.0 <https://www.gnu.org/licenses/gpl-3.0.txt>.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Par{
char* chave;
char* valor;
struct Par* prox;
} par;

typedef struct Par* tabela;

void init(tabela* t){
*t = NULL;
}

void push(tabela* t, char* chave, char* valor){
par* tmp;
tmp = (par*) malloc(sizeof(par));
if(tmp==NULL) return;
tmp->chave=chave;
tmp->valor=valor;
tmp->prox = *t;
*t = tmp;
}

int isempty(tabela t){
return (t==NULL);
}

void pop(tabela* t){
par* tmp = *t;
if(isempty(*t)) return;
*t = (*t)->prox;
free(tmp);
}

char* top(tabela t){
if(isempty(t)) return NULL;
return t->chave;
}

char* getvalue(tabela t,char* chave){
if((strcmp(t->chave,chave))==0) return t->valor;
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 b07274e

Please sign in to comment.