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

Function match_inst

dpdk/lib/cmdline/cmdline_parse.c:101–183  ·  view source on GitHub ↗

* try to match the buffer with an instruction (only the first * nb_match_token tokens if != 0). Return 0 if we match all the * tokens, else the number of matched tokens, else -1. */

Source from the content-addressed store, hash-verified

99 * tokens, else the number of matched tokens, else -1.
100 */
101static int
102match_inst(cmdline_parse_inst_t *inst, const char *buf,
103 unsigned int nb_match_token, void *resbuf, unsigned resbuf_size)
104{
105 cmdline_parse_token_hdr_t *token_p = NULL;
106 unsigned int i=0;
107 int n = 0;
108 struct cmdline_token_hdr token_hdr;
109
110 if (resbuf != NULL)
111 memset(resbuf, 0, resbuf_size);
112 /* check if we match all tokens of inst */
113 while (!nb_match_token || i < nb_match_token) {
114 token_p = get_token(inst, i);
115 if (!token_p)
116 break;
117 memcpy(&token_hdr, token_p, sizeof(token_hdr));
118
119 debug_printf("TK\n");
120 /* skip spaces */
121 while (isblank2(*buf)) {
122 buf++;
123 }
124
125 /* end of buf */
126 if ( isendofline(*buf) || iscomment(*buf) )
127 break;
128
129 if (resbuf == NULL) {
130 n = token_hdr.ops->parse(token_p, buf, NULL, 0);
131 } else {
132 unsigned rb_sz;
133
134 if (token_hdr.offset > resbuf_size) {
135 printf("Parse error(%s:%d): Token offset(%u) "
136 "exceeds maximum size(%u)\n",
137 __FILE__, __LINE__,
138 token_hdr.offset, resbuf_size);
139 return -ENOBUFS;
140 }
141 rb_sz = resbuf_size - token_hdr.offset;
142
143 n = token_hdr.ops->parse(token_p, buf, (char *)resbuf +
144 token_hdr.offset, rb_sz);
145 }
146
147 if (n < 0)
148 break;
149
150 debug_printf("TK parsed (len=%d)\n", n);
151 i++;
152 buf += n;
153 }
154
155 /* does not match */
156 if (i==0)
157 return -1;
158

Callers 2

__cmdline_parseFunction · 0.85
cmdline_completeFunction · 0.85

Calls 7

memsetFunction · 0.85
isendoflineFunction · 0.85
iscommentFunction · 0.85
get_tokenFunction · 0.70
isblank2Function · 0.70
memcpyFunction · 0.50
printfFunction · 0.50

Tested by

no test coverage detected