2016-10-27 18:11:34 +00:00
|
|
|
//
|
|
|
|
// command.c
|
|
|
|
// c-ipfs
|
|
|
|
//
|
|
|
|
// Created by John Jones on 10/27/16.
|
|
|
|
// Copyright © 2016 JMJAtlanta. All rights reserved.
|
|
|
|
//
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2016-11-07 21:29:30 +00:00
|
|
|
#include "ipfs/commands/command.h"
|
2016-10-27 18:11:34 +00:00
|
|
|
|
2016-11-10 13:28:51 +00:00
|
|
|
int commands_command_init(struct Command* cmd) {
|
2016-10-27 18:11:34 +00:00
|
|
|
// allocate memory for Argument array
|
|
|
|
cmd->arguments = malloc(cmd->argument_count * sizeof(struct Argument*));
|
|
|
|
if (cmd->arguments == NULL)
|
|
|
|
return 0;
|
|
|
|
// allocate memory for each argument
|
|
|
|
for(int i = 0; i < cmd->argument_count; i++)
|
|
|
|
cmd->arguments[i] = malloc(sizeof(struct Argument));
|
|
|
|
// allocate memory for CommandOption array
|
|
|
|
cmd->options = malloc(cmd->option_count * sizeof(struct CommandOption*));
|
|
|
|
if (cmd->options == NULL)
|
|
|
|
return 0;
|
|
|
|
// allocate memory for each CommandOption
|
|
|
|
for(int i = 0; i < cmd->option_count; i++)
|
|
|
|
cmd->options[i] = malloc(sizeof(struct CommandOption));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-10 13:28:51 +00:00
|
|
|
int commands_command_free(struct Command* cmd) {
|
|
|
|
// arguments
|
2016-10-27 18:11:34 +00:00
|
|
|
for(int i = 0; i < cmd->argument_count; i++)
|
2016-11-10 13:28:51 +00:00
|
|
|
commands_argument_free(cmd->arguments[i]);
|
2016-10-27 18:11:34 +00:00
|
|
|
free(cmd->arguments);
|
2016-11-10 13:28:51 +00:00
|
|
|
//command options
|
2016-10-27 18:11:34 +00:00
|
|
|
for(int i = 0; i < cmd->option_count; i++)
|
2016-11-10 13:28:51 +00:00
|
|
|
commands_command_option_free(cmd->options[i]);
|
2016-10-27 18:11:34 +00:00
|
|
|
free(cmd->options);
|
|
|
|
return 0;
|
|
|
|
}
|