refactor(argparse): 将null替换为nullptr以提高C++兼容性
- 在argparse库中将所有null指针常量替换为nullptr - 更新头文件和源文件中的指针初始化和比较操作 - 修改测试文件中的相关断言检查 - 更新AST定义文件中的注释说明
This commit is contained in:
@@ -5,7 +5,7 @@ void scc_argparse_init(scc_argparse_t *parser, const char *program_name,
|
||||
parser->prog_name = program_name;
|
||||
parser->version = "0.1.0";
|
||||
parser->description = description;
|
||||
parser->epilog = null;
|
||||
parser->epilog = nullptr;
|
||||
|
||||
parser->lang = SCC_ARGPARSE_LANG_EN;
|
||||
parser->need_help = true;
|
||||
@@ -26,7 +26,7 @@ void scc_argparse_drop(scc_argparse_t *parser) {
|
||||
static inline scc_argparse_cmd_t *is_subcommand(scc_argparse_cmd_t *cmd,
|
||||
const char *name) {
|
||||
if (!scc_vec_size(cmd->subcmds)) {
|
||||
return null;
|
||||
return nullptr;
|
||||
}
|
||||
scc_vec_foreach(cmd->subcmds, i) {
|
||||
scc_argparse_cmd_t *subcmd = &scc_vec_at(cmd->subcmds, i);
|
||||
@@ -34,7 +34,7 @@ static inline scc_argparse_cmd_t *is_subcommand(scc_argparse_cmd_t *cmd,
|
||||
return subcmd;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static inline void parse_cmd(scc_optparse_t *optparse,
|
||||
@@ -86,7 +86,7 @@ static inline void parse_cmd(scc_optparse_t *optparse,
|
||||
scc_optparse_set(optparse, opts->data);
|
||||
}
|
||||
static void push_help(scc_argparse_cmd_t *cmd) {
|
||||
if (cmd == null) {
|
||||
if (cmd == nullptr) {
|
||||
return;
|
||||
}
|
||||
scc_vec_push(cmd->opts, ((scc_argparse_opt_t){
|
||||
@@ -144,7 +144,8 @@ static int validate_and_cleanup(scc_argparse_context_t *ctx,
|
||||
// 检查必需参数是否都已提供
|
||||
scc_vec_foreach(ctx->current_cmd->args, i) {
|
||||
scc_argparse_arg_t *arg = &scc_vec_at(ctx->current_cmd->args, i);
|
||||
if (arg->spec.flag_required && *arg->spec.store.str_store == NULL) {
|
||||
if (arg->spec.flag_required &&
|
||||
*arg->spec.store.str_store == nullptr) {
|
||||
errcode = SCC_ARGPARSE_ERR_MISSING_ARG;
|
||||
scc_argparse_print_error(ctx, errcode);
|
||||
break;
|
||||
@@ -190,7 +191,7 @@ static int handle_option(scc_argparse_context_t *ctx, scc_argparse_t *parser) {
|
||||
*opt->spec.store.str_store = ctx->result.value;
|
||||
}
|
||||
|
||||
// // opt value == null or value != null
|
||||
// // opt value == nullptr or value != nullptr
|
||||
// scc_argparse_opt_t *org_opt =
|
||||
// (scc_argparse_opt_t *)opt_res.opt->user_data;
|
||||
// if (parser->need_help) {
|
||||
@@ -218,7 +219,7 @@ static int handle_positional_arg(scc_argparse_context_t *ctx,
|
||||
(void)parser; // TODO
|
||||
scc_argparse_cmd_t *subcmd =
|
||||
is_subcommand(ctx->current_cmd, ctx->result.value);
|
||||
if (subcmd != NULL) {
|
||||
if (subcmd != nullptr) {
|
||||
ctx->current_cmd = subcmd;
|
||||
parse_cmd(&ctx->optparse, &ctx->opts, ctx->current_cmd);
|
||||
return SCC_ARGPARSE_ERR_NONE;
|
||||
@@ -239,7 +240,7 @@ static int handle_positional_arg(scc_argparse_context_t *ctx,
|
||||
// scc_argparse_cmd_t *cmd = is_subcommand(current_cmd,
|
||||
// opt_res.value);
|
||||
|
||||
// if (cmd != null) {
|
||||
// if (cmd != nullptr) {
|
||||
// current_cmd = cmd;
|
||||
// parse_cmd(&optparse, &opts, current_cmd);
|
||||
// } else {
|
||||
@@ -275,9 +276,9 @@ int scc_argparse_parse(scc_argparse_t *parser, int argc, const char **argv) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ctx.result.opt != null) {
|
||||
if (ctx.result.opt != nullptr) {
|
||||
errcode = handle_option(&ctx, parser);
|
||||
} else if (ctx.result.value != null) {
|
||||
} else if (ctx.result.value != nullptr) {
|
||||
errcode = handle_positional_arg(&ctx, parser);
|
||||
} else {
|
||||
UNREACHABLE(); // 不应到达此处
|
||||
|
||||
@@ -174,8 +174,8 @@ void scc_argparse_print_help(scc_argparse_t *parser, scc_argparse_cmd_t *cmd) {
|
||||
|
||||
const char *scc_argparse_find_similar_arg(scc_argparse_cmd_t *cmd,
|
||||
const char *arg) {
|
||||
if (arg == null || cmd == null) {
|
||||
return null;
|
||||
if (arg == nullptr || cmd == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (arg[0] == '-' && arg[1] == '-' && arg[2] != '\0') {
|
||||
// opt arg
|
||||
|
||||
Reference in New Issue
Block a user