X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=lib%2Fdeclaracao.c;h=39bca5da9b3a49c2e0b9b06832c8b73cd9e791bc;hb=7e23a845d3862f8e54e02b99b42276b435ea5247;hp=e4afe91981f320acc5aee0feda252d0155440471;hpb=a1330946e9aeb8b1d6760ae77522f10ec28fd097;p=cascardo%2Fdeclara.git diff --git a/lib/declaracao.c b/lib/declaracao.c index e4afe91..39bca5d 100644 --- a/lib/declaracao.c +++ b/lib/declaracao.c @@ -16,17 +16,27 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _GNU_SOURCE #include "declaracao.h" +#include #include #include +#include #include "list.h" +#include "conjuge.h" #include "sistema.h" #include "rendimento.h" #include "isento.h" #include "pagamento.h" #include "bem.h" +#include "dependente.h" #include "pmhash.h" +#include "base.h" +#include "calcula.h" +#include "gera.h" +#include "help.h" + struct declaracao * declaracao_new(int ano) { struct declaracao *dec; @@ -47,6 +57,9 @@ struct declaracao * declaracao_new(int ano) dec->bens = list_new(); if (!dec->bens) goto out_bens; + dec->dependentes = list_new(); + if (!dec->dependentes) + goto out_dependentes; dec->totais = pmhash_new(); if (!dec->totais) goto out_totais; @@ -54,8 +67,11 @@ struct declaracao * declaracao_new(int ano) dec->devido = 0; dec->restituicao = 0; dec->tipo = SIMPLES; + dec->error = NULL; return dec; out_totais: + list_free(dec->dependentes, dependente_free); +out_dependentes: list_free(dec->bens, bem_free); out_bens: list_free(dec->pagamentos, pagamento_free); @@ -90,7 +106,38 @@ void declaracao_free(struct declaracao *dec) list_free(dec->isentos, isento_free); list_free(dec->pagamentos, pagamento_free); list_free(dec->bens, bem_free); + list_free(dec->dependentes, dependente_free); pmhash_del(dec->totais); + conjuge_free(dec); sistema_free(dec); + if (dec->error) + free(dec->error); free(dec); } + +void dec_set_error(struct declaracao *dec, char *fmt, ...) +{ + va_list ap; + if (dec->error) + free(dec->error); + dec->error = NULL; + va_start(ap, fmt); + vasprintf(&dec->error, fmt, ap); + va_end(ap); +} + +void dec_cmd_init(void) +{ + base_cmd_init(); + contribuinte_cmd_init(); + conjuge_cmd_init(); + rendimento_cmd_init(); + isento_cmd_init(); + pagamento_cmd_init(); + bem_cmd_init(); + dependente_cmd_init(); + calcula_cmd_init(); + gera_cmd_init(); + sistema_cmd_init(); + help_cmd_init(); +}