Não considera ano inválido como valor de imposto.
[cascardo/declara.git] / base.c
diff --git a/base.c b/base.c
index fdc7980..1477ca8 100644 (file)
--- a/base.c
+++ b/base.c
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-
-static int set_int(char **args, int *val)
-{
-       char *end = NULL;
-       if (args[0] == NULL || args[1] == NULL)
-               return -EINVAL;
-       errno = 0;
-       *val = strtol(args[1], &end, 0);
-       if (end && *end)
-               return -EINVAL;
-       if (errno == ERANGE)
-               return -ERANGE;
-       return 0;
-}
-
-static int set_string(char **args, char **str)
-{
-       if (args[0] == NULL || args[1] == NULL)
-               return -EINVAL;
-       *str = strdup(args[1]);
-       if (!*str)
-               return -errno;
-       return 0;
-}
-
-#define SET_INT(attr) \
-static int run_##attr(struct declaracao *dec, char **args) \
-{ \
-       int val; \
-       int r = set_int(args, &val); \
-       if (r) \
-               return r; \
-       dec->attr = val; \
-       return 0; \
-} \
-static struct cmd cmd_##attr = { \
-       .name = #attr, \
-       .run = run_##attr, \
-};
-
-#define SET_STRING(attr) \
-static int run_##attr(struct declaracao *dec, char **args) \
-{ \
-       char *val; \
-       int r = set_string(args, &val); \
-       if (r) \
-               return r; \
-       dec->attr = val; \
-       return 0; \
-} \
-static struct cmd cmd_##attr = { \
-       .name = #attr, \
-       .run = run_##attr, \
-}
+#include "rendimento.h"
+#include "util.h"
 
 SET_INT(ano);
 SET_STRING(cpf);
 SET_STRING(nome);
 
-static int run_dump(struct declaracao *dec, char **args)
+static int run_dump(struct declaracao *dec, char **args, int argc)
 {
        printf("ano: %d\n", dec->ano);
        printf("cpf: %s\n", dec->cpf);
        printf("nome: %s\n", dec->nome);
+       rendimento_dump(dec);
+       printf("pago: %lld.%02d\n", dec->pago / 100, dec->pago % 100);
+       printf("devido: %lld.%02d\n", dec->devido / 100, dec->devido % 100);
+       printf("restituicao: %lld.%02d\n", dec->restituicao / 100, dec->restituicao % 100);
        return 0;
 }