|
@@ -153,7 +153,7 @@ err_strdup:
|
153
|
153
|
char **asmsh_compl_cmds(const char *start)
|
154
|
154
|
{
|
155
|
155
|
const size_t ccount = sizeof(asmsh_CMDS)/sizeof(*asmsh_CMDS);
|
156
|
|
- int i, slen, cmp;
|
|
156
|
+ int i, j, slen, cmp;
|
157
|
157
|
char **ret;
|
158
|
158
|
const asmsh_cmd_t *ccmd;
|
159
|
159
|
|
|
@@ -166,19 +166,22 @@ char **asmsh_compl_cmds(const char *start)
|
166
|
166
|
bzero(ret, sizeof(*ret) * (ccount+1));
|
167
|
167
|
|
168
|
168
|
slen = (!start || !*start)?0:strlen(start);
|
|
169
|
+ j=0;
|
169
|
170
|
for(i=0; i<ccount; i++)
|
170
|
171
|
{
|
171
|
172
|
ccmd = &asmsh_CMDS[i];
|
172
|
173
|
if(!ccmd->str) { break; }
|
173
|
|
- if(!slen || !(cmp = strncmp(start, ccmd->str, slen)))
|
|
174
|
+ cmp = slen?strncmp(start, ccmd->str, slen):1;
|
|
175
|
+ if(!slen || !cmp)
|
174
|
176
|
{
|
175
|
|
- if(!(ret[i] = strdup(ccmd->str)))
|
|
177
|
+ if(!(ret[j] = strdup(ccmd->str)))
|
176
|
178
|
{
|
177
|
179
|
perror("Unable to strdup cmd completion");
|
178
|
180
|
goto errdup;
|
179
|
181
|
}
|
|
182
|
+ j++;
|
180
|
183
|
}
|
181
|
|
- if(slen && cmp < 0)
|
|
184
|
+ if(cmp < 0)
|
182
|
185
|
{
|
183
|
186
|
break;
|
184
|
187
|
}
|