ParamterParsing.c
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> // 包含getopt函数
#include <ctype.h>
#include "JZsdkLib.h"
#include "./ParamterParsing.h"
static int Timeout_flag = JZ_FLAGCODE_OFF; //超时标记位,默认关闭
static int Timeout_time = 60; //超时时间
int JZsdk_ParamterParsing_GetTimeOutFlag()
{
return Timeout_flag;
}
int JZsdk_ParamterParsing_GetTimeOutTime()
{
return Timeout_time;
}
/*************************************
*
* * 程序参数解析
* * 输入:参数字符串
*
*
* ********************************/
T_JZsdkReturnCode JZsdk_ParamterParsing(int argc, char *argv[])
{
JZSDK_LOG_INFO("参数解析");
int c;
// getopt_long 需要长选项,但这里我们只使用短选项
// getopt循环将逐个处理选项,直到没有更多选项
while ((c = getopt(argc, argv, "f:t:")) != -1)
{
switch (c) {
case 'f': //超时标记位
Timeout_flag = atoi(optarg);
break;
case 't': //超时时间
Timeout_time = atoi(optarg);
break;
case '?':
// 如果getopt遇到一个它不认识的选项,它会打印一个消息到stderr
// 并返回'?'。然后我们可以选择退出或给出更多帮助。
if (isprint(optopt))
JZSDK_LOG_ERROR("Unknown option `-%c'.", optopt);
else
JZSDK_LOG_ERROR("Unknown option character `\\x%x'.", optopt);
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
default:
break;
}
}
JZSDK_LOG_INFO("参数解析成功");
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}