From 35630c3647185be255acc1b0f32a3b0bd5e5bdbc Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Tue, 13 May 2014 08:01:54 -0300 Subject: [PATCH] =?utf8?q?Um=20pequeno=20programa=20de=20teste=20para=20ob?= =?utf8?q?ter=20alguns=20campos=20de=20uma=20declara=C3=A7=C3=A3o.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Makefile.am | 6 ++--- decfile.c | 7 ++++++ decfile.h | 1 + irpf.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 irpf.c diff --git a/Makefile.am b/Makefile.am index 20fe476..cc5b848 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/decfile.c b/decfile.c index 0baf5d2..26ef3bc 100644 --- a/decfile.c +++ b/decfile.c @@ -553,3 +553,10 @@ char * rnet_decfile_get_header(struct rnet_decfile *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; +} diff --git a/decfile.h b/decfile.h index c70874f..e3f341f 100644 --- 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_line(struct rnet_decfile *decfile, int i); #endif diff --git a/irpf.c b/irpf.c new file mode 100644 index 0000000..1a7db5a --- /dev/null +++ b/irpf.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2012-2014 Thadeu Lima de Souza Cascardo + * Copyright (C) 2014 Alexandre Oliva + * Copyright (C) 2014 Sergio Durigan Junior + * + * 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 +#include +#include +#include +#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; +} -- 2.20.1