Um pequeno programa de teste para obter alguns campos de uma declaração.
[cascardo/libreceita.git] / irpf.c
diff --git a/irpf.c b/irpf.c
new file mode 100644 (file)
index 0000000..1a7db5a
--- /dev/null
+++ b/irpf.c
@@ -0,0 +1,63 @@
+/*
+ *  Copyright (C) 2012-2014  Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
+ *  Copyright (C) 2014  Alexandre Oliva <lxoliva@fsfla.org>
+ *  Copyright (C) 2014  Sergio Durigan Junior <sergiodj@sergiodj.net>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "decfile.h"
+
+static char *chop(char *str, int off, int len)
+{
+       char *s;
+       s = malloc(len + 1);
+       if (!s)
+               return NULL;
+       memcpy(s, str + off, len);
+       s[len] = 0;
+       return s;
+}
+
+int main(int argc, char **argv)
+{
+       struct rnet_decfile *decfile;
+
+       char *contrib;
+       char *end;
+
+       decfile = rnet_decfile_open(argv[1]);
+       if (!decfile) {
+               fprintf(stderr, "could not parse file \"%s\": %s\n", argv[1], strerror(errno));
+               exit(1);
+       }
+       fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "nome"));
+       fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "hash"));
+       fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "banco"));
+       fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "agencia"));
+       fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "nr_conta"));
+       fprintf(stdout, "%s\n", rnet_decfile_get_header_field(decfile, "nr_dv_conta"));
+
+       contrib = rnet_decfile_get_line(decfile, 1);
+       end = chop(contrib, 2+11+60+15, 40);
+       fprintf(stdout, "%s\n", end);
+
+       rnet_decfile_close(decfile);
+       return 0;
+}