c-ipfs/commands/argument.c

36 lines
1 KiB
C
Raw Normal View History

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