From 015082dbe5af702473dfb658b5f0bd1038d26da2 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sat, 14 Jan 2017 14:35:02 -0200 Subject: [PATCH] Adiciona mensagens de erro ao comando gera. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Mensagens ao validar parâmetros, verificar o ano suportado e erro ao abrir arquivo são emitidas. --- lib/gera.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/gera.c b/lib/gera.c index a496190..ae5c1a0 100644 --- a/lib/gera.c +++ b/lib/gera.c @@ -839,7 +839,7 @@ static void insert_hash(struct declaracao *dec, char *irpf) static int gera(struct declaracao *dec, char *filename) { FILE *f; - int r; + int r = 0; int i; struct rendimento *rendimento; struct isento *isento; @@ -864,8 +864,12 @@ static int gera(struct declaracao *dec, char *filename) } while (0); f = fopen(filename, "w"); - if (!f) + if (!f) { + r = -errno; + dec_set_error(dec, "Não foi possível abrir arquivo %s: %s.", + filename, strerror(errno)); goto out_file; + } memset(dec->linhas, 0, sizeof(dec->linhas)); W(gera_header); W(gera_contribuinte); @@ -935,10 +939,16 @@ out_file: static int run_gera(struct declaracao *dec, char **args, int argc) { - if (argc != 2) + if (argc != 2) { + dec_set_error(dec, "Comando %s recebe um nome de arquivo como parâmetro.", + args[0]); return -EINVAL; - if (!ANO_VALIDO(dec->ano)) + } + if (!ANO_VALIDO(dec->ano)) { + dec_set_error(dec, "Comando %s não suporta ano %d.", + args[0], dec->ano); return -EINVAL; + } return gera(dec, args[1]); } -- 2.20.1