c-ipfs/commands/argument.c
2016-10-26 21:13:32 -05:00

35 lines
1 KiB
C

#include <stdlib.h>
#include <string.h>
#include "argument.h"
int uninit_argument(struct argument* argument) {
free(argument->name);
return 1;
}
int init_argument(struct argument* argument, char* name, int required, int variadic, char* description) {
argument->name = name == NULL ? NULL : strdup(name);
if (argument->name == NULL)
return 0;
strncpy(argument->name, name, strlen(name));
argument->name = name;
argument->required = required;
argument->variadic = variadic;
argument->description = description;
return 1;
}
int init_string_argument(struct argument* argument, char* name, int required, int variadic, char* description) {
int retVal = init_argument(argument, name, required, variadic, description);
if (retVal)
argument->type = string;
return retVal;
}
int init_file_argument(struct argument* argument, char* name, int required, int variadic, char* description) {
int retVal = init_argument(argument, name, required, variadic, description);
if (retVal)
argument->type = file;
return retVal;
}