MCPcopy Create free account
hub / github.com/F-Stack/f-stack / cmdline_parse_num

Function cmdline_parse_num

dpdk/lib/cmdline/cmdline_parse_num.c:95–312  ·  view source on GitHub ↗

parse an int */

Source from the content-addressed store, hash-verified

93
94/* parse an int */
95int
96cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res,
97 unsigned ressize)
98{
99 struct cmdline_token_num_data nd;
100 enum num_parse_state_t st = START;
101 const char * buf;
102 char c;
103 uint64_t res1 = 0;
104
105 if (!tk)
106 return -1;
107
108 if (!srcbuf || !*srcbuf)
109 return -1;
110
111 buf = srcbuf;
112 c = *buf;
113
114 memcpy(&nd, &((struct cmdline_token_num *)tk)->num_data, sizeof(nd));
115
116 /* check that we have enough room in res */
117 if (res) {
118 if (check_res_size(&nd, ressize) < 0)
119 return -1;
120 }
121
122 while (st != ERROR && c && !cmdline_isendoftoken(c)) {
123 debug_printf("%c %x -> ", c, c);
124 switch (st) {
125 case START:
126 if (c == '-') {
127 st = DEC_NEG;
128 }
129 else if (c == '0') {
130 st = ZERO_OK;
131 }
132 else if (c >= '1' && c <= '9') {
133 if (add_to_res(c - '0', &res1, 10) < 0)
134 st = ERROR;
135 else
136 st = DEC_POS_OK;
137 }
138 else {
139 st = ERROR;
140 }
141 break;
142
143 case ZERO_OK:
144 if (c == 'x') {
145 st = HEX;
146 }
147 else if (c == 'b') {
148 st = BIN;
149 }
150 else if (c >= '0' && c <= '7') {
151 if (add_to_res(c - '0', &res1, 10) < 0)
152 st = ERROR;

Callers 3

test_parse_num_validFunction · 0.85

Calls 4

check_res_sizeFunction · 0.85
cmdline_isendoftokenFunction · 0.85
add_to_resFunction · 0.85
memcpyFunction · 0.50

Tested by 3

test_parse_num_validFunction · 0.68