Um pequeno programa de teste para obter alguns campos de uma declaração. test
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Tue, 13 May 2014 11:01:54 +0000 (08:01 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Tue, 13 May 2014 11:01:54 +0000 (08:01 -0300)
Makefile.am
decfile.c
decfile.h
irpf.c [new file with mode: 0644]

index 20fe476..cc5b848 100644 (file)
@@ -1,3 +1,3 @@
-bin_PROGRAMS = rnetclient
-rnetclient_SOURCES = rnetclient.c decfile.c decfile.h pmhash.c pmhash.h \
-       rnet_message.c rnet_message.h rnet_encode.c rnet_encode.h
+bin_PROGRAMS = irpf
+irpf_SOURCES = irpf.c decfile.c decfile.h pmhash.c pmhash.h \
+       rnet_message.c rnet_message.h
index 0baf5d2..26ef3bc 100644 (file)
--- a/decfile.c
+++ b/decfile.c
@@ -553,3 +553,10 @@ char * rnet_decfile_get_header(struct rnet_decfile *decfile)
 {
        return get_header(decfile);
 }
 {
        return get_header(decfile);
 }
+
+char * rnet_decfile_get_line(struct rnet_decfile *decfile, int i)
+{
+       if (i < decfile->lines_len)
+               return decfile->lines[i];
+       return NULL;
+}
index c70874f..e3f341f 100644 (file)
--- a/decfile.h
+++ b/decfile.h
@@ -37,5 +37,6 @@ char *rnet_decfile_get_header_field(struct rnet_decfile *decfile, char *field);
 char * rnet_decfile_get_header(struct rnet_decfile *decfile);
 struct rnet_message * rnet_decfile_get_file(struct rnet_decfile *decfile);
 char * rnet_decfile_get_file_hash(struct rnet_decfile *decfile);
 char * rnet_decfile_get_header(struct rnet_decfile *decfile);
 struct rnet_message * rnet_decfile_get_file(struct rnet_decfile *decfile);
 char * rnet_decfile_get_file_hash(struct rnet_decfile *decfile);
+char *rnet_decfile_get_line(struct rnet_decfile *decfile, int i);
 
 #endif
 
 #endif
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;
+}