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.
31 void bem_free(void *pointer)
33 struct bem *bem = pointer;
37 pmhash_del(bem->attr);
41 static int bem_cmp(void *p1, void *p2)
45 /* O bem de valor maior vem primeiro. */
46 if (b1->valor > b2->valor)
48 else if (b1->valor < b2->valor)
53 static struct bem * bem_new(char **args, int argc)
58 bem = malloc(sizeof(*bem));
59 memset(bem, 0, sizeof(*bem));
60 bem->attr = pmhash_new();
66 r += set_int(args[1], &bem->codigo);
67 r += set_string(args[2], &bem->descricao);
68 r += set_llong(args[3], &bem->valor_anterior);
69 r += set_llong(args[4], &bem->valor);
71 for (i = 5; i < argc; i++) {
72 printf("parsing arg %s\n", args[i]);
73 r = attr_parse(&bem->attr, args[i]);
80 bem->dependente = 0; /* TODO */
82 if (r < 0 || bem->codigo < 0 ||
83 bem->valor_anterior < 0 || bem->valor < 0) {
90 static int run_bem(struct declaracao *dec, char **args, int argc)
96 bem = bem_new(args, argc);
99 r = list_insert_ordered(&dec->bens, bem, bem_cmp);
104 r = totais_add(dec, "BENSANTERIOR", bem->valor_anterior);
105 r += totais_add(dec, "BENS", bem->valor);
113 void bem_salva(struct declaracao *dec, FILE *f)
117 for (i = 0; j = list_get(dec->bens, i); i++) {
118 fprintf(f, "bem %d \"%s\" %lld %lld",
119 j->codigo, j->descricao, j->valor_anterior, j->valor);
120 //attr_printf(f, bem->attr);
125 static struct cmd cmd_bem = {
130 int bem_cmd_init(void)