mirror of
https://gitee.com/Lamdonn/varch.git
synced 2025-12-06 16:56:42 +08:00
74 lines
1.4 KiB
C
74 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#if defined(TEST_TARGET_str)
|
|
#include <varch/command.h>
|
|
#include <varch/str.h>
|
|
#else
|
|
#include "init.h"
|
|
#include "command.h"
|
|
#include "str.h"
|
|
#endif
|
|
|
|
static void usage(void)
|
|
{
|
|
printf(
|
|
"Usage: str [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("str version %d.%d.%d\r\n", STR_V_MAJOR, STR_V_MINOR, STR_V_PATCH);
|
|
return 0;
|
|
case '?':
|
|
printf("Unknown option `%c`\r\n", command_optopt);
|
|
return -1;
|
|
case 'h' :
|
|
default:
|
|
usage();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
str_t s = str("0123456789");
|
|
str_replace(s, 9, 10, "AAAAAAAAAA");
|
|
printf("len %d, %d\r\n", str_length(s), str_capacity(s));
|
|
printf("%s\r\n", _S(s));
|
|
_str(s);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#if defined(TEST_TARGET_str)
|
|
int main(int argc, char *argv[])
|
|
{
|
|
return test(argc, argv);
|
|
}
|
|
#else
|
|
void test_str(void)
|
|
{
|
|
command_export("str", test);
|
|
}
|
|
init_export_app(test_str);
|
|
#endif
|