#include "stdio.h"
#include "argpase.h"

enum Opt {
    T0 = 0, T1, T2, T3, T4, T5
};
Option Opts[6] = {{"T0", T0},
                  {"T1", T1},
                  {"T2", T2},
                  {"T3", T3},
                  {"T4", T4},
                  {"T5", T5}};

int Test_argpase(void *pVoid) {
    OptList *Head = Options_Creat("Head", -1);
    OptList *t;
    int i;
    for (i = 0; i < 6; i++) {
        t = Options_CreatOpt(&Opts[i]);
        Options_Add(Head, t);
    }
    Options_Print(Head);

    char *s = "T1 52 T2 64 T5 72";//模拟串口参数传入
    char *argv[20];
    size_t argc;

    argc = Str_To_Args(s, argv);
    printf("\nargs\n");
    for (i = 0; i < argc; ++i) {
        printf("arg[%d]:%s\n", i, argv[i]);//打印参数拆分情况
    }

    OptId optid;
    while ((optid = Options_Load(Head, argv, argc)) != -1) {//开始匹配 Optarg为匹配的参数(字符类型可atoi等转换)
        switch (optid) {
            case T0:
            case T1:
            case T2:
            case T3:
            case T4:
            case T5:
                printf("Opt_%s[%d]:%s\n", Optstr, optid, Optarg);
                break;
            default:
                break;
        }
    }
}
