+/*
+ * 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;
+}