--- /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 "rendimento.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"
+
+struct rendimento {
+ char *cnpj;
+ char *nome;
+ long long rendimento;
+ long long previdencia;
+ long long decimoterceiro;
+ long long imposto;
+ char *saida;
+};
+
+void rendimento_free(void *pointer)
+{
+ struct rendimento *rendimento = pointer;
+ if (rendimento->cnpj)
+ free(rendimento->cnpj);
+ if (rendimento->nome)
+ free(rendimento->nome);
+ if (rendimento->saida)
+ free(rendimento->saida);
+ free(rendimento);
+}
+
+static struct rendimento * rendimento_new(char **args)
+{
+ struct rendimento *rendimento;
+ int r = 0;
+ rendimento = malloc(sizeof(*rendimento));
+ rendimento->cnpj = strdup(args[1]);
+ rendimento->nome = strdup(args[2]);
+ rendimento->saida = strdup(args[7]);
+ r += set_llong(args[3], &rendimento->rendimento);
+ r += set_llong(args[4], &rendimento->previdencia);
+ r += set_llong(args[5], &rendimento->decimoterceiro);
+ r += set_llong(args[6], &rendimento->imposto);
+ if (!rendimento->cnpj || !rendimento->nome || !rendimento->saida) {
+ rendimento_free(rendimento);
+ return NULL;
+ }
+ if (r < 0 || rendimento->rendimento < 0 || rendimento->previdencia < 0 ||
+ rendimento->decimoterceiro < 0 || rendimento->imposto < 0) {
+ rendimento_free(rendimento);
+ return NULL;
+ }
+ return rendimento;
+}
+
+static int run_rendimento(struct declaracao *dec, char **args, int argc)
+{
+ struct rendimento *rendimento;
+ int r;
+ if (argc != 8)
+ return -EINVAL;
+ rendimento = rendimento_new(args);
+ if (!rendimento)
+ return -ENOMEM;
+ r = list_add(&dec->rendimento, rendimento);
+ if (r < 0) {
+ rendimento_free(rendimento);
+ return r;
+ }
+ return 0;
+}
+
+void rendimento_dump(struct declaracao *dec)
+{
+ int i;
+ struct rendimento *j;
+ for (i = 0; j = list_get(dec->rendimento, i); i++)
+ printf("rendimento: %s %s %013lld %013lld %013lld %013lld %s\n",
+ j->cnpj, j->nome, j->rendimento, j->previdencia,
+ j->decimoterceiro, j->imposto, j->saida);
+}
+
+static struct cmd cmd_rendimento = {
+ .name = "rendimento",
+ .run = run_rendimento,
+};
+
+int rendimento_cmd_init(void)
+{
+ cmd_add(&cmd_rendimento);
+ 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 _RENDIMENTO_H
+#define _RENDIMENTO_H
+
+#include "declaracao.h"
+
+struct rendimento;
+
+void rendimento_dump(struct declaracao *dec);
+void rendimento_free(void *pointer);
+
+int rendimento_cmd_init(void);
+
+#endif