项目地址argtable3

本地验证:

  • 编译构建

  • 新增验证

// examples/skull.c
#include "argtable3.h" int main(int argc, char **argv)
{
const char* progname = "skull";
struct arg_lit *help = arg_lit0("h", "help", "this is help info");
struct arg_lit *litn = arg_litn("l", "literal", 0, 5, "./progname -l --literal");
struct arg_int *intn = arg_intn("i", "integer", "<int>", 0, 5, "./program -i 10 -i 20 -i 30");
struct arg_dbl *dbln = arg_dbln("d", "double", "<double>", 0, 5, "./program -d 3.14 -d 2.718 -d 1.414");
struct arg_str *strn = arg_strn("s", "string", "<string>", 0, 5, "./program -s hello -s world");
struct arg_rex *rexn = arg_rexn("r", "regular", "^[A-Za-z0-9]+$", "<regex>", 0, 5, ARG_REX_ICASE, "./program -r [digit] -r [letters]");
struct arg_file *filen = arg_filen("f", "file", "<file>", 0, 5, "./program file1.txt file2.txt file3.txt");
struct arg_date *daten = arg_daten("a", "date", "%Y-%m-%d", "<date>", 0, 5, "./program -a 2023-09-01 -a 2023-09-02 -a 2023-09-03");
struct arg_end *end = arg_end(20);
void* argtable[] = {help, litn, intn, dbln, strn, rexn, filen, daten, end};
int nerrors;
int exitcode=0; /* verify the argtable[] entries were allocated sucessfully */
if (arg_nullcheck(argtable) != 0) {
/* NULL entries were detected, some allocations must have failed */
printf("%s: insufficient memory\n", progname);
exitcode=1;
goto exit;
} /* Parse the command line as defined by argtable[] */
nerrors = arg_parse(argc, argv, argtable); /* If the parser returned any errors then display them and exit */
if (nerrors > 0) {
/* Display the error details contained in the arg_end struct.*/
arg_print_errors(stdout,end,progname);
printf("Try '%s --help' for more information.\n", progname);
exitcode=1;
goto exit;
} /* special case: '--help' takes precedence over error reporting */
if (help->count > 0) {
printf("Usage: %s", progname);
arg_print_syntax(stdout, argtable, "\n");
printf("Print certain system information. With no options, same as -s.\n\n");
arg_print_glossary(stdout, argtable," %-25s %s\n");
printf("\nReport bugs to <foo@bar>.\n");
exitcode=0;
goto exit;
} /* special case: '--version' takes precedence error reporting */
if (litn->count > 0) {
printf("'%s' count: %d.\n", litn->hdr.glossary, litn->count);
exitcode=0;
goto exit;
} if (intn->count > 0) {
printf("'%s' count: %d.\n", intn->hdr.glossary, intn->count);
for (int i = 0; i < intn->count; i++) {
printf("Integer %d: %d\n", i+1, intn->ival[i]);
}
exitcode=0;
goto exit;
} if (dbln->count > 0) {
printf("'%s' count: %d.\n", dbln->hdr.glossary, dbln->count);
for (int i = 0; i < dbln->count; i++) {
printf("Double %d: %lf\n", i+1, dbln->dval[i]);
}
exitcode=0;
goto exit;
} if (strn->count > 0) {
printf("'%s' count: %d.\n", strn->hdr.glossary, strn->count);
for (int i = 0; i < strn->count; i++) {
printf("String %d: %s\n", i+1, strn->sval[i]);
}
exitcode=0;
goto exit;
} if (rexn->count > 0) {
printf("'%s' count: %d.\n", rexn->hdr.glossary, rexn->count);
for (int i = 0; i < rexn->count; i++) {
printf("Regular %d: %s\n", i+1, rexn->sval[i]);
}
exitcode=0;
goto exit;
} if (filen->count > 0) {
printf("'%s' count: %d.\n", filen->hdr.glossary, filen->count);
for (int i = 0; i < filen->count; i++) {
printf("File %d: %s\n", i+1, filen->filename[i]);
}
exitcode=0;
goto exit;
} if (daten->count > 0) {
printf("'%s' count: %d.\n", daten->hdr.glossary, daten->count);
for (int i = 0; i < daten->count; i++) {
printf("Date %d: %04d-%02d-%02d\n", i+1, daten->tmval[i].tm_year, daten->tmval[i].tm_mon, daten->tmval[i].tm_mday);
}
exitcode=0;
goto exit;
} exit:
/* deallocate each non-null entry in argtable[] */
arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0])); return exitcode;
}
  • 源码修改

实测月份少1,年份是基于1900

// src/arg_date.c
char* arg_strptime(const char* buf, const char* fmt, struct tm* tm) {
while ((c = *fmt) != '\0') {
/* Clear `alternate' modifier prior to new conversion. */
alt_format = 0; /* Eat up white-space. */
if (isspace(c)) {
while (isspace((int)(*bp)))
bp++; fmt++;
continue;
} if ((c = *fmt++) != '%')
goto literal; again:
switch (c = *fmt++) {
case 'm': /* The month. */
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &i, 1, 12)))
return (0);
/* tm->tm_mon = i- 1; @skull #2023-9-14 10:18:34 */
tm->tm_mon = i;
break; case 'Y': /* The year. */
LEGAL_ALT(ALT_E);
if (!(conv_num(&bp, &i, 0, 9999)))
return (0);
/* tm->tm_year = i - TM_YEAR_BASE; @skull #2023-9-14 10:19:59 */
tm->tm_year = i;
break;
  • 执行

【ArgParse】一个开源的入参解析库的更多相关文章

  1. postman 上一个接口的返回值作为下一个接口的入参

    在使用postman做接口测试的时候,在多个接口的测试中,如果需要上一个接口的返回值作为下一个接口的入参,其基本思路是: 1.获取上一个接口的返回值 2.将返回值设置成环境变量或者全局变量 3.设置下 ...

  2. MyBatis版本升级导致OffsetDateTime入参解析异常问题复盘

    背景 最近有一个数据统计服务需要升级SpringBoot的版本,由1.5.x.RELEASE直接升级到2.3.0.RELEASE,考虑到没有用到SpringBoot的内建SPI,升级过程算是顺利.但是 ...

  3. Google开源命令行参数解析库gflags

    Google开源命令行参数解析库gflags http://blog.csdn.net/lming_08/article/details/25072899 CMDLINE的解析 http://blog ...

  4. JMeter使用JSON Extractor插件实现将一个接口的JSON返回值作为下一个接口的入参

    ##补充## 接口响应数据,一般为JSON,HTML格式的数据. 对于HTML的响应结果提取,可以使用正则表达式,也可以通过XPath来提取:对于JSON格式的数据,可以用正则表达式,JSON Ext ...

  5. 一个非常棒的Go-Json解析库

    json是一种数据格式,经常被用作数据交换,页面展示,序列化等场景,基本每种语言都有对应的json解析框架,Go语言也不例外,并且内置了json库,基本能够满足一些普通开发场景,但有些复杂场景下就不太 ...

  6. FunDA:一个开源的函数式数据处理工具库,也是Slick的补充

    如果你是一个Slick用户,或者你是一个数据库编程人员正在尝试进入函数式编程模式,那么FunDA可能会帮到你. 目前市面上FRM(Functional Relational Mapper),即函数式的 ...

  7. 介绍一个开源的SIP(VOIP)协议库PJSIP

    本文系转载,出处不可考. 假设你对SIP/VoIP技术感兴趣,哪希望你不要错过:),假设你对写出堪称优美的Code感兴趣 ,那么你也不可错过:) 这期间我想分析一下一个实际的协议栈的设计到实现的相关技 ...

  8. 一个简单的 JSON 生成/解析库

    这是一个单文件的,适用于C语言的, JSON 读写库. 先说明,不想造轮子,代码是从这里拿来的: https://www.codeproject.com/Articles/887604/jWrite- ...

  9. OC封装的TLV数据格式解析库

    作者:朱克锋 邮箱:zhukefeng@iboxpay.com 转载请注明出处:http://blog.csdn.net/linux_zkf TLV是一种可变格式,意思就是: Type类型, Leng ...

  10. C#构造函数在继承时必须要求与父类型构造函数入参相同怎么办?

    摘要 我们都知道,C#中,在类型继承时,由于构造子类必须先构造其父类型的内容,因此,必须子类型的构造函数中调用父类型的构造函数(无参数的不需要显式声明). 但是往往我们会出现,子类型本身的构造函数大于 ...

随机推荐

  1. python tkinter 使用(十)

    python tkinter 使用(十) #!/usr/bin/python3 # -*- coding: UTF-8 -*- """ @Author: zh @Time ...

  2. 【C#】【IO】【实例】接上一个统计的新功能

    先用Python来创建多层级文件夹: import os root_path = r"C:\Users\Desktop\文案整理\Practice" for item in ran ...

  3. React Hook 之 Effect :同步与外部系统的数据

    有时组件中的数据需要与外部系统的数据或操作同步,React提供了Hook Effect. Effect 会在组件渲染后运行一些代码,以便将组件与 React 之外的某些系统同步,包比如浏览器 API. ...

  4. Windows 7更新失败的解决方法

    你好,1.在开始菜单中点击运行,→输入"services.msc"→找到"windows update"右击选择"停止":2.进入C:\wi ...

  5. super只能用在构造方法里面吗?

    super关键字并不仅限于在构造方法中使用.在Java中,super关键字有两个主要的用途: 在子类的构造方法中调用父类的构造方法.这是super的一个常见用法,通常是在子类的构造方法的第一行使用,用 ...

  6. WinDbg实践--入门篇

      WinDbg从字面意思就是Windows+Debug的组合,即Windows平台上的调试工具,可以调试用户模式.内核模式.dump文件等,总之知道它的调试功能非常强大就行了.WinDbg调试命令分 ...

  7. 华为云MetaStudio全新升级,盘古数字人大模型助力数字人自由

    摘要:基于盘古大模型能力,华为云MetaStudio数字内容生产线全新升级,推出数字人模型生成服务和模型驱动服务. 近日,华为开发者大会2023 ( Cloud ) 在东莞拉开帷幕.基于盘古大模型能力 ...

  8. 六步带你完成博流wifi模组对接华为云流程

    摘要:本文主要采用基于博流wifi模组以及我们的SDK移植实现华为云的对接,上报数据以及命令下发等,希望对您有所帮助. 1 简介 首先需要研究透彻博流项目的编译运行流程,首先看其根目录中包括compo ...

  9. 实践案例丨CenterNet-Hourglass论文复现

    摘要:本案例是CenterNet-Hourglass论文复现的体验案例,此模型是对Objects as Points 中提出的CenterNet进行结果复现. 本文分享自华为云社区<Center ...

  10. 带你用VUE实现上传图片效果

    摘要:在逛b站时看到一个上传图片的效果,想着可以自己也做一个,因为原作者是用原生js写的,那我不如就用vue写好了,当然,是一个很小的东西,在HTML文件直接引用vue就好了,详细步骤如下~ 本文分享 ...