return 0;
}
-static struct isento * isento_new(char **args)
+static struct isento * isento_new(char **args, int argc)
{
struct isento *isento;
int r = 0;
isento_free(isento);
return NULL;
}
+ if (argc == 6) {
+ r = set_int(&args[4], 2, &isento->dependente);
+ } else {
+ isento->dependente = 0;
+ }
+ if (r < 0 || isento->dependente < 0) {
+ isento_free(isento);
+ return NULL;
+ }
return isento;
}
{
struct isento *isento;
int r;
- if (argc != 5)
+ if (argc != 5 && argc != 6)
return -EINVAL;
- isento = isento_new(args);
+ isento = isento_new(args, argc);
if (!isento)
return -ENOMEM;
+ if (isento->dependente > list_size(dec->dependentes)) {
+ isento_free(isento);
+ return -EINVAL;
+ }
r = list_insert_ordered(&dec->isentos, isento, isento_cmp);
if (r < 0) {
isento_free(isento);
int i;
struct isento *j;
for (i = 0; j = list_get(dec->isentos, i); i++)
- fprintf(f, "isento %d \"%s\" \"%s\" %lld\n",
- j->codigo, j->cnpj, j->nome, j->valor);
+ fprintf(f, "isento %d \"%s\" \"%s\" %lld %d\n",
+ j->codigo, j->cnpj, j->nome, j->valor, j->dependente);
}
static struct cmd cmd_isento = {