mirror of
https://github.com/xHyroM/gimi.git
synced 2024-11-21 23:41:06 +01:00
refactor: dont use typedef struct
This commit is contained in:
parent
8b522693a7
commit
7a34db763c
3 changed files with 24 additions and 13 deletions
|
@ -5,9 +5,11 @@
|
|||
#define INIT_CONFIG "[providers]\n"
|
||||
|
||||
void cli_command_config(int argc, char **argv) {
|
||||
gimi_config *cfg = config_read();
|
||||
struct gimi_config *cfg = config_read();
|
||||
for (int i = 0; i < cfg->providers_size; i++) {
|
||||
gimi_config_provider *provider = cfg->providers[i];
|
||||
struct gimi_config_provider *provider = cfg->providers[i];
|
||||
printf("ssh: %s | primary: %d\n", provider->ssh, provider->primary);
|
||||
}
|
||||
|
||||
config_free(cfg);
|
||||
}
|
||||
|
|
18
src/config.c
18
src/config.c
|
@ -5,7 +5,7 @@
|
|||
#include <string.h>
|
||||
#include <toml.h>
|
||||
|
||||
gimi_config *config_read() {
|
||||
struct gimi_config *config_read() {
|
||||
FILE *file_ptr;
|
||||
char errbuf[200];
|
||||
|
||||
|
@ -22,18 +22,21 @@ gimi_config *config_read() {
|
|||
size++;
|
||||
}
|
||||
|
||||
gimi_config *cfg = (gimi_config *)malloc(sizeof(gimi_config));
|
||||
struct gimi_config *cfg =
|
||||
(struct gimi_config *)malloc(sizeof(struct gimi_config));
|
||||
|
||||
cfg->providers_size = size;
|
||||
cfg->providers = malloc(cfg->providers_size * sizeof(gimi_config_provider));
|
||||
cfg->providers =
|
||||
malloc(cfg->providers_size * sizeof(struct gimi_config_provider));
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
const char *key = toml_key_in(toml_providers, i);
|
||||
|
||||
toml_table_t *toml_provider = toml_table_in(toml_providers, key);
|
||||
|
||||
gimi_config_provider *provider =
|
||||
(gimi_config_provider *)malloc(sizeof(gimi_config_provider));
|
||||
struct gimi_config_provider *provider =
|
||||
(struct gimi_config_provider *)malloc(
|
||||
sizeof(struct gimi_config_provider));
|
||||
|
||||
toml_datum_t ssh = toml_string_in(toml_provider, "ssh");
|
||||
provider->ssh = strdup(ssh.u.s);
|
||||
|
@ -54,3 +57,8 @@ gimi_config *config_read() {
|
|||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
void config_free(struct gimi_config *cfg) {
|
||||
free(cfg->providers);
|
||||
free(cfg);
|
||||
}
|
||||
|
|
13
src/config.h
13
src/config.h
|
@ -1,13 +1,14 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
struct gimi_config_provider {
|
||||
char *ssh;
|
||||
bool primary;
|
||||
} gimi_config_provider;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct gimi_config {
|
||||
int providers_size;
|
||||
gimi_config_provider **providers;
|
||||
} gimi_config;
|
||||
struct gimi_config_provider **providers;
|
||||
};
|
||||
|
||||
gimi_config *config_read();
|
||||
struct gimi_config *config_read();
|
||||
void config_free(struct gimi_config *cfg);
|
||||
|
|
Loading…
Reference in a new issue