Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Iniparser
提交
ac05815e
T
Third Party Iniparser
项目概览
OpenHarmony
/
Third Party Iniparser
大约 1 年 前同步成功
通知
0
Star
24
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Iniparser
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ac05815e
编写于
8月 30, 2016
作者:
E
Emmanuel Leblond
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into custom_errback
Conflicts: src/iniparser.c
上级
604af2ba
5720a4cd
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
152 addition
and
7 deletion
+152
-7
src/iniparser.c
src/iniparser.c
+41
-7
src/iniparser.h
src/iniparser.h
+28
-0
test/CuTest.c
test/CuTest.c
+9
-0
test/CuTest.h
test/CuTest.h
+5
-0
test/ressources/bad_ini/ends_well.ini
test/ressources/bad_ini/ends_well.ini
+6
-0
test/test_iniparser.c
test/test_iniparser.c
+63
-0
未找到文件。
src/iniparser.c
浏览文件 @
ac05815e
...
...
@@ -426,11 +426,11 @@ const char * iniparser_getstring(const dictionary * d, const char * key, const c
/*-------------------------------------------------------------------------*/
/**
@brief Get the string associated to a key, convert to an int
@brief Get the string associated to a key, convert to an
long
int
@param d Dictionary to search
@param key Key string to look for
@param notfound Value to return in case of error
@return integer
@return
long
integer
This function queries a dictionary for a key. A key as read from an
ini file is given as "section:key". If the key cannot be found,
...
...
@@ -451,13 +451,46 @@ const char * iniparser_getstring(const dictionary * d, const char * key, const c
Credits: Thanks to A. Becker for suggesting strtol()
*/
/*--------------------------------------------------------------------------*/
int
iniparser_getint
(
const
dictionary
*
d
,
const
char
*
key
,
int
notfound
)
long
int
iniparser_getlongint
(
const
dictionary
*
d
,
const
char
*
key
,
long
int
notfound
)
{
const
char
*
str
;
str
=
iniparser_getstring
(
d
,
key
,
INI_INVALID_KEY
);
if
(
str
==
INI_INVALID_KEY
)
return
notfound
;
return
(
int
)
strtol
(
str
,
NULL
,
0
);
return
strtol
(
str
,
NULL
,
0
);
}
/*-------------------------------------------------------------------------*/
/**
@brief Get the string associated to a key, convert to an int
@param d Dictionary to search
@param key Key string to look for
@param notfound Value to return in case of error
@return integer
This function queries a dictionary for a key. A key as read from an
ini file is given as "section:key". If the key cannot be found,
the notfound value is returned.
Supported values for integers include the usual C notation
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
are supported. Examples:
"42" -> 42
"042" -> 34 (octal -> decimal)
"0x42" -> 66 (hexa -> decimal)
Warning: the conversion may overflow in various ways. Conversion is
totally outsourced to strtol(), see the associated man page for overflow
handling.
Credits: Thanks to A. Becker for suggesting strtol()
*/
/*--------------------------------------------------------------------------*/
int
iniparser_getint
(
const
dictionary
*
d
,
const
char
*
key
,
int
notfound
)
{
return
(
int
)
iniparser_getlongint
(
d
,
key
,
notfound
);
}
/*-------------------------------------------------------------------------*/
...
...
@@ -692,6 +725,7 @@ dictionary * iniparser_load(const char * ininame)
int
len
;
int
lineno
=
0
;
int
errs
=
0
;
int
mem_err
=
0
;
dictionary
*
dict
;
...
...
@@ -750,12 +784,12 @@ dictionary * iniparser_load(const char * ininame)
break
;
case
LINE_SECTION
:
errs
=
dictionary_set
(
dict
,
section
,
NULL
);
mem_err
=
dictionary_set
(
dict
,
section
,
NULL
);
break
;
case
LINE_VALUE
:
sprintf
(
tmp
,
"%s:%s"
,
section
,
key
);
errs
=
dictionary_set
(
dict
,
tmp
,
val
)
;
mem_err
=
dictionary_set
(
dict
,
tmp
,
val
)
;
break
;
case
LINE_ERROR
:
...
...
@@ -772,7 +806,7 @@ dictionary * iniparser_load(const char * ininame)
}
memset
(
line
,
0
,
ASCIILINESZ
);
last
=
0
;
if
(
errs
<
0
)
{
if
(
mem_err
<
0
)
{
iniparser_error_callback
(
"iniparser: memory allocation failure
\n
"
);
break
;
}
...
...
src/iniparser.h
浏览文件 @
ac05815e
...
...
@@ -202,6 +202,34 @@ const char * iniparser_getstring(const dictionary * d, const char * key, const c
/*--------------------------------------------------------------------------*/
int
iniparser_getint
(
const
dictionary
*
d
,
const
char
*
key
,
int
notfound
);
/*-------------------------------------------------------------------------*/
/**
@brief Get the string associated to a key, convert to an long int
@param d Dictionary to search
@param key Key string to look for
@param notfound Value to return in case of error
@return integer
This function queries a dictionary for a key. A key as read from an
ini file is given as "section:key". If the key cannot be found,
the notfound value is returned.
Supported values for integers include the usual C notation
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
are supported. Examples:
- "42" -> 42
- "042" -> 34 (octal -> decimal)
- "0x42" -> 66 (hexa -> decimal)
Warning: the conversion may overflow in various ways. Conversion is
totally outsourced to strtol(), see the associated man page for overflow
handling.
*/
/*--------------------------------------------------------------------------*/
long
int
iniparser_getlongint
(
const
dictionary
*
d
,
const
char
*
key
,
long
int
notfound
);
/*-------------------------------------------------------------------------*/
/**
@brief Get the string associated to a key, convert to a double
...
...
test/CuTest.c
浏览文件 @
ac05815e
...
...
@@ -211,6 +211,15 @@ void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
CuFail_Line
(
tc
,
file
,
line
,
message
,
buf
);
}
void
CuAssertLongIntEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
long
int
expected
,
long
int
actual
)
{
char
buf
[
STRING_MAX
];
if
(
expected
==
actual
)
return
;
sprintf
(
buf
,
"expected <%ld> but was <%ld>"
,
expected
,
actual
);
CuFail_Line
(
tc
,
file
,
line
,
message
,
buf
);
}
void
CuAssertDblEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
double
expected
,
double
actual
,
double
delta
)
{
...
...
test/CuTest.h
浏览文件 @
ac05815e
...
...
@@ -64,6 +64,9 @@ void CuAssertStrEquals_LineMsg(CuTest* tc,
void
CuAssertIntEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
expected
,
int
actual
);
void
CuAssertLongIntEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
long
int
expected
,
long
int
actual
);
void
CuAssertDblEquals_LineMsg
(
CuTest
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
double
expected
,
double
actual
,
double
delta
);
...
...
@@ -81,6 +84,8 @@ void CuAssertPtrEquals_LineMsg(CuTest* tc,
#define CuAssertStrEquals_Msg(tc,ms,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
#define CuAssertIntEquals(tc,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
#define CuAssertIntEquals_Msg(tc,ms,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
#define CuAssertLongIntEquals(tc,ex,ac) CuAssertLongIntEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
#define CuAssertLongIntEquals_Msg(tc,ms,ex,ac) CuAssertLongIntEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
#define CuAssertDblEquals(tc,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac),(dl))
#define CuAssertDblEquals_Msg(tc,ms,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac),(dl))
#define CuAssertPtrEquals(tc,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
...
...
test/ressources/bad_ini/ends_well.ini
0 → 100644
浏览文件 @
ac05815e
#
# This dict contains an error but ends up with a correct entry
#
[section]
error
is
here
a
=
b
test/test_iniparser.c
浏览文件 @
ac05815e
...
...
@@ -338,6 +338,69 @@ void Test_iniparser_getint(CuTest *tc)
dictionary_del
(
dic
);
}
void
Test_iniparser_getlongint
(
CuTest
*
tc
)
{
unsigned
i
;
char
key_name
[
64
];
dictionary
*
dic
;
const
struct
{
long
int
num
;
const
char
*
value
;
}
good_val
[]
=
{
{
0
,
"0"
},
{
1
,
"1"
},
{
-
1
,
"-1"
},
{
1000
,
"1000"
},
{
077
,
"077"
},
{
-
01000
,
"-01000"
},
{
0x7FFFFFFFFFFFFFFF
,
"0x7FFFFFFFFFFFFFFF"
},
{
-
0x7FFFFFFFFFFFFFFF
,
"-0x7FFFFFFFFFFFFFFF"
},
{
0x4242
,
"0x4242"
},
{
0
,
NULL
}
/* must be last */
};
const
char
*
bad_val
[]
=
{
""
,
"notanumber"
,
"0x"
,
"k2000"
,
" "
,
"0xG1"
};
/* NULL test */
CuAssertLongIntEquals
(
tc
,
-
42
,
iniparser_getlongint
(
NULL
,
NULL
,
-
42
));
CuAssertLongIntEquals
(
tc
,
-
42
,
iniparser_getlongint
(
NULL
,
"dummy"
,
-
42
));
/* Check the def return element */
dic
=
dictionary_new
(
10
);
CuAssertLongIntEquals
(
tc
,
42
,
iniparser_getlongint
(
dic
,
"dummy"
,
42
));
CuAssertLongIntEquals
(
tc
,
0x7FFFFFFFFFFFFFFF
,
iniparser_getlongint
(
dic
,
NULL
,
0x7FFFFFFFFFFFFFFF
));
CuAssertLongIntEquals
(
tc
,
-
0x7FFFFFFFFFFFFFFF
,
iniparser_getlongint
(
dic
,
"dummy"
,
-
0x7FFFFFFFFFFFFFFF
));
dictionary_del
(
dic
);
/* Generic dictionary */
dic
=
dictionary_new
(
10
);
for
(
i
=
0
;
good_val
[
i
].
value
!=
NULL
;
++
i
)
{
sprintf
(
key_name
,
"longint:value%d"
,
i
);
dictionary_set
(
dic
,
key_name
,
good_val
[
i
].
value
);
}
for
(
i
=
0
;
good_val
[
i
].
value
!=
NULL
;
++
i
)
{
sprintf
(
key_name
,
"longint:value%d"
,
i
);
CuAssertLongIntEquals
(
tc
,
good_val
[
i
].
num
,
iniparser_getlongint
(
dic
,
key_name
,
0
));
}
dictionary_del
(
dic
);
/* Test bad names */
dic
=
dictionary_new
(
10
);
for
(
i
=
0
;
i
<
sizeof
(
bad_val
)
/
sizeof
(
char
*
);
++
i
)
{
sprintf
(
key_name
,
"longint:bad%d"
,
i
);
dictionary_set
(
dic
,
key_name
,
bad_val
[
i
]);
}
for
(
i
=
0
;
i
<
sizeof
(
bad_val
)
/
sizeof
(
char
*
);
++
i
)
{
sprintf
(
key_name
,
"longint:bad%d"
,
i
);
CuAssertLongIntEquals
(
tc
,
0
,
iniparser_getlongint
(
dic
,
key_name
,
0
));
}
dictionary_del
(
dic
);
}
void
Test_iniparser_getdouble
(
CuTest
*
tc
)
{
dictionary
*
dic
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录