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 memset(bem, 0, sizeof(*bem));
78 bem->descricao = strdup(args[2]);
79 /* TODO: consertar set_int para funcionar como set_llong */
80 r += set_int(args, 2, &bem->codigo);
81 r += set_llong(args[3], &bem->valor_anterior);
82 r += set_llong(args[4], &bem->valor);
83 if (!bem->descricao) {
87 if (r < 0 || bem->codigo < 0 ||
88 bem->valor_anterior < 0 || bem->valor < 0) {
95 static int run_bem(struct declaracao *dec, char **args, int argc)
104 r = list_insert_ordered(&dec->bens, bem, bem_cmp);
109 r = totais_add(dec, "BENSANTERIOR", bem->valor_anterior);
110 r += totais_add(dec, "BENS", bem->valor);
118 void bem_salva(struct declaracao *dec, FILE *f)
122 for (i = 0; j = list_get(dec->bens, i); i++)
123 fprintf(f, "bem %d \"%s\" %lld %lld\n",
124 j->codigo, j->descricao, j->valor_anterior, j->valor);
127 static struct cmd cmd_bem = {
132 int bem_cmd_init(void)