-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Estrutura de dados da tabela de parâmetros #26
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
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|