varch/test/test_vector.c
2024-11-16 13:36:54 +08:00

67 lines
1.3 KiB
C

#include <stdio.h>
#include <string.h>
#if defined(TEST_TARGET_vector)
#include <varch/command.h>
#include <varch/vector.h>
#else
#include "init.h"
#include "command.h"
#include "vector.h"
#endif
static void usage(void)
{
printf(
"Usage: vector [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("vector version %d.%d.%d\r\n", VECTOR_V_MAJOR, VECTOR_V_MINOR, VECTOR_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
return 0;
}
#if defined(TEST_TARGET_vector)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_vector(void)
{
command_export("vector", test);
}
init_export_app(test_vector);
#endif