--- /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 "cmd.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "rendimento.h"
+#include "util.h"
+
+SET_INT(ano);
+SET_STRING(cpf);
+SET_STRING(nome);
+SET_STRING(recibo);
+SET_STRING(retifica);
+
+SET_STRING(banco);
+SET_STRING(agencia);
+SET_STRING(contacorrente);
+SET_STRING(dvconta);
+
+static int run_resumo(struct declaracao *dec, char **args, int argc)
+{
+ if (dec->retifica)
+ printf("retificadora\n");
+ if (dec->obrigatoria)
+ printf("obrigatoria\n");
+ printf("pago: %lld.%02d\n", reais(dec->pago), centavos(dec->pago));
+ printf("retido: %lld.%02d\n", reais(dec->retido),
+ centavos(dec->retido));
+ printf("devido: %lld.%02d\n", reais(dec->devido),
+ centavos(dec->devido));
+ if (dec->restituicao > 0)
+ printf("restituicao: %lld.%02d\n", reais(dec->restituicao),
+ centavos(dec->restituicao));
+ if (dec->pagar > 0)
+ printf("a pagar: %lld.%02d\n", reais(dec->pagar),
+ centavos(dec->pagar));
+ return 0;
+}
+
+static void salva(struct declaracao *dec, FILE *f)
+{
+ fprintf(f, "ano %d\n", dec->ano);
+ if (dec->cpf)
+ fprintf(f, "cpf \"%s\"\n", dec->cpf);
+ if (dec->nome)
+ fprintf(f, "nome \"%s\"\n", dec->nome);
+ if (dec->recibo)
+ fprintf(f, "recibo \"%s\"\n", dec->recibo);
+ if (dec->retifica)
+ fprintf(f, "retifica \"%s\"\n", dec->retifica);
+ contribuinte_salva(dec, f);
+ rendimento_salva(dec, f);
+}
+
+static int run_salva(struct declaracao *dec, char **args, int argc)
+{
+ FILE *f;
+ char *filename;
+ if (argc != 2)
+ return -EINVAL;
+ filename = args[1];
+ f = fopen(filename, "w");
+ if (!f)
+ return -errno;
+ salva(dec, f);
+ fclose(f);
+ return 0;
+}
+
+static struct cmd cmd_salva = {
+ .name = "salva",
+ .run = run_salva,
+};
+
+static struct cmd cmd_resumo = {
+ .name = "resumo",
+ .run = run_resumo,
+};
+
+int base_cmd_init(void)
+{
+ cmd_add(&cmd_salva);
+ cmd_add(&cmd_resumo);
+
+ cmd_add(&cmd_ano);
+ cmd_add(&cmd_cpf);
+ cmd_add(&cmd_recibo);
+ cmd_add(&cmd_retifica);
+ cmd_add(&cmd_nome);
+
+ cmd_add(&cmd_banco);
+ cmd_add(&cmd_agencia);
+ cmd_add(&cmd_contacorrente);
+ cmd_add(&cmd_dvconta);
+
+ return 0;
+}