2 * Copyright (C) 2015 Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 void bem_free(void *pointer)
32 struct bem *bem = pointer;
37 free(bem->logradouro);
41 free(bem->complemento);
60 static int bem_cmp(void *p1, void *p2)
64 /* O bem de valor maior vem primeiro. */
65 if (b1->valor > b2->valor)
67 else if (b1->valor < b2->valor)
72 static struct bem * bem_new(char **args)
76 bem = malloc(sizeof(*bem));
77 bem->descricao = strdup(args[2]);
78 /* TODO: consertar set_int para funcionar como set_llong */
79 r += set_int(args, 2, &bem->codigo);
80 r += set_llong(args[3], &bem->valor_anterior);
81 r += set_llong(args[4], &bem->valor);
82 if (!bem->descricao) {
86 if (r < 0 || bem->codigo < 0 ||
87 bem->valor_anterior < 0 || bem->valor < 0) {
94 static int run_bem(struct declaracao *dec, char **args, int argc)
103 r = list_insert_ordered(&dec->bens, bem, bem_cmp);
108 r = totais_add(dec, "BENSANTERIOR", bem->valor_anterior);
109 r += totais_add(dec, "BENS", bem->valor);
117 void bem_salva(struct declaracao *dec, FILE *f)
121 for (i = 0; j = list_get(dec->bens, i); i++)
122 fprintf(f, "bem %d \"%s\" %lld %lld\n",
123 j->codigo, j->descricao, j->valor_anterior, j->valor);
126 static struct cmd cmd_bem = {
131 int bem_cmd_init(void)