feat(argparse): 添加列表类型参数支持
新增 scc_argparse_list_t 类型用于处理多个字符串值的参数, 并添加相应的配置函数 scc_argparse_spec_setup_list。 fix(lexer): 调整关键字标记处理逻辑 将关键字子类型从 SCC_TOK_SUBTYPE_KEYWORD 改为 SCC_TOK_SUBTYPE_IDENTIFIER,并移除相关的枚举定义。 refactor(lexer): 优化跳过换行功能实现 修改 scc_lexer_skip_until_newline 函数实现,改进循环逻辑和错误处理。 feat(pproc): 完善预处理器条件编译支持 重构条件编译状态管理,添加对 #ifdef、#ifndef、#elifdef、 #else、#endif 等指令的支持,并实现嵌套条件处理。 refactor(pproc): 优化文件包含路径处理 添加最大包含深度限制,改进包含路径添加功能, 修复文件状态结构命名。 docs(log): 更新日志模块标准库依赖 调整 stdarg.h 包含逻辑,更新编译器内置宏定义名称。 feat(core): 扩展核心类型定义 添加基础数据类型别名定义,完善类型系统支持。 feat(main): 实现命令行包含路径参数 添加 -I/--include 参数支持,允许用户指定额外的头文件搜索路径。
This commit is contained in:
@@ -43,6 +43,7 @@ typedef enum scc_argparse_err {
|
||||
SCC_ARGPARSE_ERR_UNKNOWN_VALUE,
|
||||
} scc_argparse_err_t;
|
||||
|
||||
typedef SCC_VEC(const char *) scc_argparse_list_t;
|
||||
// 约束规范结构体
|
||||
struct scc_argparse_spec {
|
||||
scc_argparse_val_type_t value_type; // 值类型
|
||||
@@ -50,12 +51,13 @@ struct scc_argparse_spec {
|
||||
|
||||
// 存储位置
|
||||
union {
|
||||
cbool *bool_store; // 布尔值存储
|
||||
int *int_store; // 整数存储
|
||||
float *float_store; // 浮点数存储
|
||||
const char **str_store; // 字符串存储
|
||||
char **str_alloc_store; // 字符串存储(使用alloc,需要free)
|
||||
void **ptr_store; // 通用指针存储
|
||||
cbool *bool_store; // 布尔值存储
|
||||
int *int_store; // 整数存储
|
||||
float *float_store; // 浮点数存储
|
||||
const char **str_store; // 字符串存储
|
||||
char **str_alloc_store; // 字符串存储(使用alloc,需要free)
|
||||
void **ptr_store; // 通用指针存储
|
||||
scc_argparse_list_t *vec_store; // 新增:指向字符串向量的指针
|
||||
} store;
|
||||
|
||||
// 枚举值约束
|
||||
@@ -215,6 +217,15 @@ static inline void scc_argparse_spec_setup_choices(scc_argparse_spec_t *spec,
|
||||
spec->choices.count = count;
|
||||
}
|
||||
|
||||
// 添加设置列表的辅助函数(内联)
|
||||
static inline void scc_argparse_spec_setup_list(scc_argparse_spec_t *spec,
|
||||
scc_argparse_list_t *vec) {
|
||||
spec->value_type = SCC_ARGPARSE_VAL_TYPE_LIST;
|
||||
spec->store.vec_store = vec;
|
||||
// 自动设置 flag_takes_multiple 为 true,因为列表需要多个值
|
||||
spec->flag_takes_multiple = true;
|
||||
}
|
||||
|
||||
#define SCC_ARGPARSE_MACRO_SETTER(attr) \
|
||||
static inline void scc_argparse_spec_set_##attr(scc_argparse_spec_t *spec, \
|
||||
cbool flag) { \
|
||||
|
||||
@@ -63,6 +63,10 @@ static inline void parse_cmd(scc_optparse_t *optparse,
|
||||
min_args = 0;
|
||||
max_args = 0;
|
||||
break;
|
||||
case SCC_ARGPARSE_VAL_TYPE_LIST: // 列表类型
|
||||
min_args = 1;
|
||||
max_args = 65535; // FIXME maybe INT_MAX ?
|
||||
break;
|
||||
default:
|
||||
min_args = 0;
|
||||
max_args = 0;
|
||||
@@ -161,6 +165,10 @@ static int handle_option(scc_argparse_context_t *ctx, scc_argparse_t *parser) {
|
||||
return SCC_ARGPARSE_ERR_PNT_DEFAULT;
|
||||
}
|
||||
|
||||
if (parser->need_version && scc_strcmp(opt->long_name, "version") == 0) {
|
||||
// TODO default version print
|
||||
}
|
||||
|
||||
if (opt->spec.flag_store_as_count) {
|
||||
(*opt->spec.store.int_store)++;
|
||||
}
|
||||
@@ -169,8 +177,14 @@ static int handle_option(scc_argparse_context_t *ctx, scc_argparse_t *parser) {
|
||||
*opt->spec.store.bool_store = true;
|
||||
}
|
||||
|
||||
if (ctx->result.value) {
|
||||
opt->spec.raw_value = ctx->result.value;
|
||||
if (!ctx->result.value) {
|
||||
return SCC_ARGPARSE_ERR_NONE;
|
||||
}
|
||||
opt->spec.raw_value = ctx->result.value;
|
||||
|
||||
if (opt->spec.value_type == SCC_ARGPARSE_VAL_TYPE_LIST) {
|
||||
scc_vec_push(*opt->spec.store.vec_store, ctx->result.value);
|
||||
} else {
|
||||
*opt->spec.store.str_store = ctx->result.value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user