Um pequeno programa de teste para obter alguns campos de uma declaração.
[cascardo/libreceita.git] / irpf.c
1 /*
2  *  Copyright (C) 2012-2014  Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
3  *  Copyright (C) 2014  Alexandre Oliva <lxoliva@fsfla.org>
4  *  Copyright (C) 2014  Sergio Durigan Junior <sergiodj@sergiodj.net>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License along
17  *  with this program; if not, write to the Free Software Foundation, Inc.,
18  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <errno.h>
25 #include "decfile.h"
26
27 static char *chop(char *str, int off, int len)
28 {
29         char *s;
30         s = malloc(len + 1);
31         if (!s)
32                 return NULL;
33         memcpy(s, str + off, len);
34         s[len] = 0;
35         return s;
36 }
37
38 int main(int argc, char **argv)
39 {
40         struct rnet_decfile *decfile;
41
42         char *contrib;
43         char *end;
44
45         decfile = rnet_decfile_open(argv[1]);
46         if (!decfile) {
47                 fprintf(stderr, "could not parse file \"%s\": %s\n", argv[1], strerror(errno));
48                 exit(1);
49         }
50         fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "nome"));
51         fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "hash"));
52         fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "banco"));
53         fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "agencia"));
54         fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "nr_conta"));
55         fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "nr_dv_conta"));
56
57         contrib = rnet_decfile_get_line(decfile, 1);
58         end = chop(contrib, 2+11+60+15, 40);
59         fprintf(stdout, "%s\n", end);
60
61         rnet_decfile_close(decfile);
62         return 0;
63 }