rendimento.c rendimento.h \
isento.c isento.h \
pagamento.c pagamento.h \
- bem.c bem.h
+ bem.c bem.h \
+ dependente.c dependente.h
#include "isento.h"
#include "pagamento.h"
#include "bem.h"
+#include "dependente.h"
#include "pmhash.h"
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;
dec->tipo = SIMPLES;
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);
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);
sistema_free(dec);
free(dec);
struct list *isentos;
struct list *pagamentos;
struct list *bens;
+ struct list *dependentes;
struct contribuinte contribuinte;
struct sistema sistema;
long long pago;
--- /dev/null
+/*
+ * Copyright (C) 2015 Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "dependente.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include "cmd.h"
+#include "list.h"
+#include "util.h"
+
+void dependente_free(void *pointer)
+{
+ struct dependente *dependente = pointer;
+ if (dependente->nome)
+ free(dependente->nome);
+ if (dependente->dn)
+ free(dependente->dn);
+ if (dependente->cpf)
+ free(dependente->cpf);
+ free(dependente);
+}
+
+static struct dependente * dependente_new(char **args)
+{
+ struct dependente *dependente;
+ int r = 0;
+ dependente = malloc(sizeof(*dependente));
+ /* TODO: consertar set_int para funcionar como set_llong */
+ r += set_int(args, 2, &dependente->codigo);
+ dependente->nome = strdup(args[2]);
+ dependente->dn = strdup(args[3]);
+ dependente->cpf = strdup(args[4]);
+ if (!dependente->nome || !dependente->dn || !dependente->cpf) {
+ dependente_free(dependente);
+ return NULL;
+ }
+ if (r < 0 || dependente->codigo < 0) {
+ dependente_free(dependente);
+ return NULL;
+ }
+ return dependente;
+}
+
+static int run_dependente(struct declaracao *dec, char **args, int argc)
+{
+ struct dependente *dependente;
+ int r;
+ if (argc != 5)
+ return -EINVAL;
+ dependente = dependente_new(args);
+ if (!dependente)
+ return -ENOMEM;
+ r = list_add(&dec->dependentes, dependente);
+ if (r < 0) {
+ dependente_free(dependente);
+ return r;
+ }
+ return 0;
+}
+
+void dependente_salva(struct declaracao *dec, FILE *f)
+{
+ int i;
+ struct dependente *j;
+ for (i = 0; j = list_get(dec->dependentes, i); i++) {
+ fprintf(f, "dependente %d \"%s\" \"%s\" \"%s\"\n",
+ j->codigo, j->nome, j->dn, j->cpf);
+ }
+}
+
+static struct cmd cmd_dependente = {
+ .name = "dependente",
+ .run = run_dependente,
+};
+
+int dependente_cmd_init(void)
+{
+ cmd_add(&cmd_dependente);
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (C) 2015 Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _DEPENDENTE_H
+#define _DEPENDENTE_H
+
+#include <stdio.h>
+#include "declaracao.h"
+
+struct dependente {
+ int codigo;
+ char *nome;
+ char *dn;
+ char *cpf;
+};
+
+void dependente_salva(struct declaracao *dec, FILE *f);
+void dependente_free(void *pointer);
+
+int dependente_cmd_init(void);
+
+#endif
#include "isento.h"
#include "pagamento.h"
#include "bem.h"
+#include "dependente.h"
#include "totais.h"
#include "sistema.h"
gera_isento(dec, f, 98);
}
+static void gera_dependente(struct declaracao *dec, FILE *f)
+{
+ struct dependente *d;
+ d = list_get(dec->dependentes, dec->linhas[25]);
+
+ fprintf(f, "25");
+ fprintf(f, "%s", dec->cpf);
+ fprintf(f, "%05d", dec->linhas[25] + 1);
+ fprintf(f, "%02d", d->codigo);
+ fprintf(f, "%-60.60s", d->nome);
+ fprintf(f, "%-8.8s", d->dn);
+ fprintf(f, "%-11.11s", d->cpf);
+ /* TODO: Indicador de saída */
+ fprintf(f, " ");
+}
+
static void gera_bem(struct declaracao *dec, FILE *f)
{
struct bem *b;
struct isento *isento;
struct pagamento *pagamento;
struct bem *bem;
+ struct dependente *dependente;
struct list *linhas;
char *buf;
W(gera_isentos);
W(gera_exclusivos);
+ for (i = 0; (dependente = list_get(dec->dependentes, i)); i++) {
+ W(gera_dependente);
+ }
for (i = 0; (pagamento = list_get(dec->pagamentos, i)); i++) {
W(gera_pagamento);
}
#include "isento.h"
#include "pagamento.h"
#include "bem.h"
+#include "dependente.h"
#include "calcula.h"
#include "gera.h"
isento_cmd_init();
pagamento_cmd_init();
bem_cmd_init();
+ dependente_cmd_init();
calcula_cmd_init();
gera_cmd_init();
sistema_cmd_init();