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);
62 static int bem_cmp(void *p1, void *p2)
66 /* O bem de valor maior vem primeiro. */
67 if (b1->valor > b2->valor)
69 else if (b1->valor < b2->valor)
74 static struct bem * bem_new(char **args)
78 bem = malloc(sizeof(*bem));
79 memset(bem, 0, sizeof(*bem));
80 r += set_int(args[1], &bem->codigo);
81 r += set_string(args[2], &bem->descricao);
82 r += set_llong(args[3], &bem->valor_anterior);
83 r += set_llong(args[4], &bem->valor);
84 if (r < 0 || bem->codigo < 0 ||
85 bem->valor_anterior < 0 || bem->valor < 0) {
92 static int run_bem(struct declaracao *dec, char **args, int argc)
101 r = list_insert_ordered(&dec->bens, bem, bem_cmp);
106 r = totais_add(dec, "BENSANTERIOR", bem->valor_anterior);
107 r += totais_add(dec, "BENS", bem->valor);
115 void bem_salva(struct declaracao *dec, FILE *f)
119 for (i = 0; j = list_get(dec->bens, i); i++)
120 fprintf(f, "bem %d \"%s\" %lld %lld\n",
121 j->codigo, j->descricao, j->valor_anterior, j->valor);
124 static struct cmd cmd_bem = {
129 int bem_cmd_init(void)