X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=lib%2Fdeclaracao.c;h=affe8d687fbb4cbe87606ef977068be788fbe2aa;hb=a99b09340e6b9c46268dfe2685d6997dd751212e;hp=7eef34c57506c26b1a1ec652a6ae9becf61607ca;hpb=687bc57d97d703decd2a41f224a3de0b41f5881d;p=cascardo%2Fdeclara.git diff --git a/lib/declaracao.c b/lib/declaracao.c index 7eef34c..affe8d6 100644 --- a/lib/declaracao.c +++ b/lib/declaracao.c @@ -16,19 +16,28 @@ * 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 "carne.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; @@ -40,6 +49,9 @@ struct declaracao * declaracao_new(int ano) dec->rendimento = list_new(); if (!dec->rendimento) goto out_rendimento; + dec->carne = list_new(); + if (!dec->carne) + goto out_carne; dec->isentos = list_new(); if (!dec->isentos) goto out_isentos; @@ -59,6 +71,7 @@ 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); @@ -69,6 +82,8 @@ out_bens: out_pagamentos: list_free(dec->isentos, isento_free); out_isentos: + list_free(dec->carne, carne_free); +out_carne: list_free(dec->rendimento, rendimento_free); out_rendimento: free(dec); @@ -94,6 +109,7 @@ void declaracao_free(struct declaracao *dec) if (dec->dvconta) free(dec->dvconta); list_free(dec->rendimento, rendimento_free); + list_free(dec->carne, carne_free); list_free(dec->isentos, isento_free); list_free(dec->pagamentos, pagamento_free); list_free(dec->bens, bem_free); @@ -101,5 +117,36 @@ void declaracao_free(struct declaracao *dec) 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(); + carne_cmd_init(); + isento_cmd_init(); + pagamento_cmd_init(); + bem_cmd_init(); + dependente_cmd_init(); + calcula_cmd_init(); + gera_cmd_init(); + importa_cmd_init(); + sistema_cmd_init(); + help_cmd_init(); +}