token.c token.h \
cmd.c cmd.h pmhash.c pmhash.h \
totais.c totais.h \
+ sistema.c sistema.h \
calcula.c calcula.h \
gera.c gera.h \
base.c base.h \
#include <stdlib.h>
#include <string.h>
#include "list.h"
+#include "sistema.h"
#include "rendimento.h"
#include "isento.h"
#include "pagamento.h"
list_free(dec->pagamentos, pagamento_free);
list_free(dec->bens, bem_free);
pmhash_del(dec->totais);
+ sistema_free(dec);
free(dec);
}
#include "list.h"
#include "contribuinte.h"
+#include "sistema.h"
enum {
SIMPLES,
struct list *pagamentos;
struct list *bens;
struct contribuinte contribuinte;
+ struct sistema sistema;
long long pago;
long long retido;
long long devido;
#include "pagamento.h"
#include "bem.h"
#include "totais.h"
+#include "sistema.h"
static void gera_header(struct declaracao *dec, FILE *f)
{
fprintf(f, "S"); /* TODO: gerada? */
fprintf(f, "%-10.10s", dec->retifica ?: ""); /* recibo retificada ex. atual */
fprintf(f, "2"); /* TODO: PGD */
- fprintf(f, "LINUX "); /* TODO: SO */
- fprintf(f, "3.16.0-"); /* TODO: versao SO */
- fprintf(f, "1.7.0_75 "); /* TODO: versao JVM */
+ fprintf(f, "%-14.14s", sistema_get_so(dec));
+ fprintf(f, "%-7.7s", sistema_get_so_versao(dec));
+ fprintf(f, "%-9.9s", sistema_get_jvm_versao(dec));
fprintf(f, "%-10.10s", ""); /* TODO: última declaração transmitida (pode ser vazio?) */
fprintf(f, "%04d", dec->contribuinte.cd_municipio);
fprintf(f, " "); /* TODO: CPF conjuge */
fprintf(f, "%-40.40s", dec->contribuinte.municipio);
fprintf(f, "%-60.60s", dec->nome);
fprintf(f, "%-11.11s", ""); /* CPF empregada */
- fprintf(f, "000000000000"); /* FIXME: MAC */
+ fprintf(f, "%-12.12s", sistema_get_mac(dec));
fprintf(f, "%08d", 0); /* Data saída */
fprintf(f, "%-11.11s", ""); /* CPF procurador */
fprintf(f, "%03d", dec->obrigatoria); /* criterio obrigatoriedade */
--- /dev/null
+/*
+ * Copyright (C) 2015 Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
+ *
+ * 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 "sistema.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include "cmd.h"
+
+void sistema_free(struct declaracao *dec)
+{
+ if (dec->sistema.so)
+ free(dec->sistema.so);
+ if (dec->sistema.so_versao)
+ free(dec->sistema.so_versao);
+ if (dec->sistema.jvm_versao)
+ free(dec->sistema.jvm_versao);
+ if (dec->sistema.mac)
+ free(dec->sistema.mac);
+}
+
+static int run_sistema(struct declaracao *dec, char **args, int argc)
+{
+ struct rendimento *rendimento;
+ int r;
+ if (argc != 5)
+ return -EINVAL;
+ dec->sistema.so = strdup(args[1]);
+ dec->sistema.so_versao = strdup(args[2]);
+ dec->sistema.jvm_versao = strdup(args[3]);
+ dec->sistema.mac = strdup(args[4]);
+ if (!dec->sistema.so || !dec->sistema.so_versao ||
+ !dec->sistema.jvm_versao || !dec->sistema.mac)
+ goto out;
+ return 0;
+out:
+ sistema_free(dec);
+ return -ENOMEM;
+}
+
+void sistema_salva(struct declaracao *dec, FILE *f)
+{
+ fprintf(f, "sistema \"%s\" \"%s\" \"%s\" \"%s\"\n",
+ dec->sistema.so, dec->sistema.so_versao,
+ dec->sistema.jvm_versao, dec->sistema.mac);
+}
+
+static struct cmd cmd_sistema = {
+ .name = "sistema",
+ .run = run_sistema,
+};
+
+int sistema_cmd_init(void)
+{
+ cmd_add(&cmd_sistema);
+ return 0;
+}
+
+#define SISTEMA_SO_DEFAULT "LINUX"
+#define SISTEMA_SO_VERSAO_DEFAULT "3.16.0"
+#define SISTEMA_JVM_VERSAO_DEFAULT "1.7.0"
+#define SISTEMA_MAC_DEFAULT "000000000000"
+
+char * sistema_get_so(struct declaracao *dec)
+{
+ if (!dec->sistema.so)
+ return SISTEMA_SO_DEFAULT;
+ return dec->sistema.so;
+}
+
+char * sistema_get_so_versao(struct declaracao *dec)
+{
+ if (!dec->sistema.so_versao)
+ return SISTEMA_SO_VERSAO_DEFAULT;
+ return dec->sistema.so_versao;
+}
+
+char * sistema_get_jvm_versao(struct declaracao *dec)
+{
+ if (!dec->sistema.jvm_versao)
+ return SISTEMA_JVM_VERSAO_DEFAULT;
+ return dec->sistema.jvm_versao;
+}
+
+char * sistema_get_mac(struct declaracao *dec)
+{
+ if (!dec->sistema.mac)
+ return SISTEMA_MAC_DEFAULT;
+ return dec->sistema.mac;
+}
--- /dev/null
+/*
+ * Copyright (C) 2015 Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
+ *
+ * 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 _SISTEMA_H
+#define _SISTEMA_H
+
+#include <stdio.h>
+
+struct declaracao;
+
+struct sistema {
+ char *so;
+ char *so_versao;
+ char *jvm_versao;
+ char *mac;
+};
+
+void sistema_free(struct declaracao *dec);
+
+void sistema_salva(struct declaracao *dec, FILE *f);
+
+int sistema_cmd_init(void);
+
+char * sistema_get_so(struct declaracao *dec);
+char * sistema_get_so_versao(struct declaracao *dec);
+char * sistema_get_jvm_versao(struct declaracao *dec);
+char * sistema_get_mac(struct declaracao *dec);
+
+#endif
bem_cmd_init();
calcula_cmd_init();
gera_cmd_init();
+ sistema_cmd_init();
filename = argv[1];
r = process(filename);