Remove variável não utilizada
[cascardo/declara.git] / lib / sistema.c
1 /*
2  *  Copyright (C) 2015  Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License along
15  *  with this program; if not, write to the Free Software Foundation, Inc.,
16  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #include "sistema.h"
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <errno.h>
24 #include <stdio.h>
25 #include "cmd.h"
26
27 void sistema_free(struct declaracao *dec)
28 {
29         if (dec->sistema.so)
30                 free(dec->sistema.so);
31         if (dec->sistema.so_versao)
32                 free(dec->sistema.so_versao);
33         if (dec->sistema.jvm_versao)
34                 free(dec->sistema.jvm_versao);
35         if (dec->sistema.mac)
36                 free(dec->sistema.mac);
37 }
38
39 static int run_sistema(struct declaracao *dec, char **args, int argc)
40 {
41         int r;
42         if (argc != 5)
43                 return -EINVAL;
44         dec->sistema.so = strdup(args[1]);
45         dec->sistema.so_versao = strdup(args[2]);
46         dec->sistema.jvm_versao = strdup(args[3]);
47         dec->sistema.mac = strdup(args[4]);
48         if (!dec->sistema.so || !dec->sistema.so_versao ||
49             !dec->sistema.jvm_versao || !dec->sistema.mac)
50                 goto out;
51         return 0;
52 out:
53         sistema_free(dec);
54         return -ENOMEM;
55 }
56
57 void sistema_salva(struct declaracao *dec, FILE *f)
58 {
59         fprintf(f, "sistema \"%s\" \"%s\" \"%s\" \"%s\"\n",
60                 dec->sistema.so, dec->sistema.so_versao,
61                 dec->sistema.jvm_versao, dec->sistema.mac);
62 }
63
64 static struct cmd cmd_sistema = {
65         .name = "sistema",
66         .run = run_sistema,
67 };
68
69 int sistema_cmd_init(void)
70 {
71         cmd_add(&cmd_sistema);
72         return 0;
73 }
74
75 #define SISTEMA_SO_DEFAULT "LINUX"
76 #define SISTEMA_SO_VERSAO_DEFAULT "3.16.0"
77 #define SISTEMA_JVM_VERSAO_DEFAULT "1.7.0"
78 #define SISTEMA_MAC_DEFAULT "000000000000"
79
80 char * sistema_get_so(struct declaracao *dec)
81 {
82         if (!dec->sistema.so)
83                 return SISTEMA_SO_DEFAULT;
84         return dec->sistema.so;
85 }
86
87 char * sistema_get_so_versao(struct declaracao *dec)
88 {
89         if (!dec->sistema.so_versao)
90                 return SISTEMA_SO_VERSAO_DEFAULT;
91         return dec->sistema.so_versao;
92 }
93
94 char * sistema_get_jvm_versao(struct declaracao *dec)
95 {
96         if (!dec->sistema.jvm_versao)
97                 return SISTEMA_JVM_VERSAO_DEFAULT;
98         return dec->sistema.jvm_versao;
99 }
100
101 char * sistema_get_mac(struct declaracao *dec)
102 {
103         if (!dec->sistema.mac)
104                 return SISTEMA_MAC_DEFAULT;
105         return dec->sistema.mac;
106 }