From 5ca22420e457a92589ea762e9ee77de4ec5d100a Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sat, 10 Dec 2016 11:24:14 -0200 Subject: [PATCH] Adiciona comando help. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit O comando help lê arquivos texto e imprime seu conteúdo na saída padrão. Assim, a documentação pode ser escrita em simples arquivos. --- lib/Makefile.am | 1 + lib/help.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/help.h | 24 +++++++++++++++++ src/declara.c | 2 ++ 4 files changed, 95 insertions(+) create mode 100644 lib/help.c create mode 100644 lib/help.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 1410b20..1d26720 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -9,6 +9,7 @@ libreceita_la_SOURCES = declaracao.c declaracao.h \ base.c base.h \ list.c list.h \ util.c util.h \ + help.c help.h \ contribuinte.c contribuinte.h \ rendimento.c rendimento.h \ isento.c isento.h \ diff --git a/lib/help.c b/lib/help.c new file mode 100644 index 0000000..66573ba --- /dev/null +++ b/lib/help.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2015-2016 Thadeu Lima de Souza Cascardo + * + * 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. + */ + +#define _GNU_SOURCE +#include "sistema.h" +#include +#include +#include +#include +#include +#include "cmd.h" +#include "util.h" + +static const char *helpdir = "help"; + +static int run_help(struct declaracao *dec, char **args, int argc) +{ + int r; + char *filename; + char *basename; + if (argc == 1) + basename = "help"; + else if (argc == 2) + basename = args[1]; + else + return -EINVAL; + r = asprintf(&filename, "%s/%s.txt", helpdir, basename); + if (r < 0) { + return -errno; + } + printf("\n"); + dumpfile(1, filename); + printf("\n"); + free(filename); + return 0; +} + +static struct cmd cmd_help = { + .name = "help", + .run = run_help, +}; + +static struct cmd cmd_ajuda = { + .name = "ajuda", + .run = run_help, +}; + +int help_cmd_init(void) +{ + cmd_add(&cmd_help); + cmd_add(&cmd_ajuda); + return 0; +} diff --git a/lib/help.h b/lib/help.h new file mode 100644 index 0000000..109e653 --- /dev/null +++ b/lib/help.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2015-2016 Thadeu Lima de Souza Cascardo + * + * 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. + */ + +#ifndef _HELP_H +#define _HELP_H + +int help_cmd_init(void); + +#endif diff --git a/src/declara.c b/src/declara.c index 54e1abb..d54451c 100644 --- a/src/declara.c +++ b/src/declara.c @@ -38,6 +38,7 @@ #include "dependente.h" #include "calcula.h" #include "gera.h" +#include "help.h" static int readline_support = 1; @@ -134,6 +135,7 @@ int main(int argc, char **argv) calcula_cmd_init(); gera_cmd_init(); sistema_cmd_init(); + help_cmd_init(); if (argc > 1) filename = argv[1]; -- 2.20.1