RT-Thread RTOS
1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
msh_parse.c
浏览该文件的文档.
1
/*
2
* Copyright (c) 2006-2021, RT-Thread Development Team
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*
6
* Change Logs:
7
* Date Author Notes
8
* 2022-05-25 WangQiang the first verion for msh parse
9
*/
10
11
#include <
rtthread.h
>
12
#include <ctype.h>
13
14
#define forstrloop(str) for (; '\0' != *(str); (str)++)
15
23
rt_bool_t
msh_isint
(
char
*strvalue)
24
{
25
if
((
RT_NULL
== strvalue) || (
'\0'
== strvalue[0]))
26
{
27
return
RT_FALSE
;
28
}
29
if
((
'+'
== *strvalue) || (
'-'
== *strvalue))
30
{
31
strvalue++;
32
}
33
forstrloop
(strvalue)
34
{
35
if
(!isdigit((
int
)(*strvalue)))
36
{
37
return
RT_FALSE
;
38
}
39
}
40
return
RT_TRUE
;
41
}
42
50
rt_bool_t
msh_ishex
(
char
*strvalue)
51
{
52
int
c;
53
if
((
RT_NULL
== strvalue) || (
'\0'
== strvalue[0]))
54
{
55
return
RT_FALSE
;
56
}
57
if
(
'0'
!= *(strvalue++))
58
{
59
return
RT_FALSE
;
60
}
61
if
(
'x'
!= *(strvalue++))
62
{
63
return
RT_FALSE
;
64
}
65
66
forstrloop
(strvalue)
67
{
68
c = tolower(*strvalue);
69
if
(!isxdigit(c))
70
{
71
return
RT_FALSE
;
72
}
73
}
74
return
RT_TRUE
;
75
}
76
84
int
msh_strtohex
(
char
*strvalue)
85
{
86
char
c = 0;
87
int
value = 0;
88
strvalue += 2;
89
forstrloop
(strvalue)
90
{
91
value *= 16;
92
c = tolower(*strvalue);
93
value += isdigit(c) ? c -
'0'
: c -
'a'
+ 10;
94
}
95
return
value;
96
}
msh_strtohex
int msh_strtohex(char *strvalue)
定义
msh_parse.c:84
msh_isint
rt_bool_t msh_isint(char *strvalue)
定义
msh_parse.c:23
forstrloop
#define forstrloop(str)
定义
msh_parse.c:14
msh_ishex
rt_bool_t msh_ishex(char *strvalue)
定义
msh_parse.c:50
rtthread.h
rt_bool_t
int rt_bool_t
定义
rttypes.h:35
RT_TRUE
#define RT_TRUE
定义
rttypes.h:110
RT_FALSE
#define RT_FALSE
定义
rttypes.h:111
RT_NULL
#define RT_NULL
定义
rttypes.h:114
components
finsh
msh_parse.c
制作者
1.13.1