Lines Matching refs:cmd

49 cmdbuf_shiftr(mdb_cmdbuf_t *cmd, size_t nbytes)
51 bcopy(&cmd->cmd_buf[cmd->cmd_bufidx],
52 &cmd->cmd_buf[cmd->cmd_bufidx + nbytes],
53 cmd->cmd_buflen - cmd->cmd_bufidx);
57 mdb_cmdbuf_allocchunk(mdb_cmdbuf_t *cmd)
61 ssize_t newhalloc = cmd->cmd_halloc + MDB_DEF_HISTLEN;
63 if (newhalloc > cmd->cmd_histlen)
64 newhalloc = cmd->cmd_histlen;
66 bcopy(cmd->cmd_history, newhistory, cmd->cmd_halloc * sizeof (char *));
67 mdb_free(cmd->cmd_history, cmd->cmd_halloc * sizeof (char *));
68 for (i = cmd->cmd_halloc; i < newhalloc; i++)
70 cmd->cmd_history = newhistory;
71 cmd->cmd_halloc = newhalloc;
75 mdb_cmdbuf_create(mdb_cmdbuf_t *cmd)
79 cmd->cmd_halloc = MDB_DEF_HISTLEN < mdb.m_histlen ?
82 cmd->cmd_history = mdb_alloc(cmd->cmd_halloc * sizeof (char *),
84 cmd->cmd_linebuf = mdb_alloc(CMDBUF_LINELEN, UM_SLEEP);
86 for (i = 0; i < cmd->cmd_halloc; i++)
87 cmd->cmd_history[i] = mdb_alloc(CMDBUF_LINELEN, UM_SLEEP);
89 cmd->cmd_buf = cmd->cmd_history[0];
90 cmd->cmd_linelen = CMDBUF_LINELEN;
91 cmd->cmd_histlen = mdb.m_histlen;
92 cmd->cmd_buflen = 0;
93 cmd->cmd_bufidx = 0;
94 cmd->cmd_hold = 0;
95 cmd->cmd_hnew = 0;
96 cmd->cmd_hcur = 0;
97 cmd->cmd_hlen = 0;
101 mdb_cmdbuf_destroy(mdb_cmdbuf_t *cmd)
105 for (i = 0; i < cmd->cmd_halloc; i++)
106 mdb_free(cmd->cmd_history[i], CMDBUF_LINELEN);
108 mdb_free(cmd->cmd_linebuf, CMDBUF_LINELEN);
109 mdb_free(cmd->cmd_history, cmd->cmd_halloc * sizeof (char *));
113 mdb_cmdbuf_caninsert(mdb_cmdbuf_t *cmd, size_t nbytes)
115 return (cmd->cmd_buflen + nbytes < cmd->cmd_linelen);
119 mdb_cmdbuf_atstart(mdb_cmdbuf_t *cmd)
121 return (cmd->cmd_bufidx == 0);
125 mdb_cmdbuf_atend(mdb_cmdbuf_t *cmd)
127 return (cmd->cmd_bufidx == cmd->cmd_buflen);
131 mdb_cmdbuf_insert(mdb_cmdbuf_t *cmd, int c)
134 if (cmd->cmd_buflen + CMDBUF_TABLEN < cmd->cmd_linelen) {
137 if (cmd->cmd_buflen != cmd->cmd_bufidx)
138 cmdbuf_shiftr(cmd, CMDBUF_TABLEN);
141 cmd->cmd_buf[cmd->cmd_bufidx++] = ' ';
143 cmd->cmd_buflen += CMDBUF_TABLEN;
153 if (cmd->cmd_buflen < cmd->cmd_linelen) {
154 if (cmd->cmd_buflen != cmd->cmd_bufidx)
155 cmdbuf_shiftr(cmd, 1);
157 cmd->cmd_buf[cmd->cmd_bufidx++] = (char)c;
158 cmd->cmd_buflen++;
167 mdb_cmdbuf_accept(mdb_cmdbuf_t *cmd)
169 if (cmd->cmd_bufidx < cmd->cmd_linelen) {
172 cmd->cmd_buf[cmd->cmd_buflen++] = '\0';
173 (void) strcpy(cmd->cmd_linebuf, cmd->cmd_buf);
175 if (cmd->cmd_hold != cmd->cmd_hnew) {
176 int lastidx = cmd->cmd_hnew == 0 ? cmd->cmd_halloc - 1 :
177 cmd->cmd_hnew - 1;
179 is_repeating = strcmp(cmd->cmd_buf,
180 cmd->cmd_history[lastidx]) == 0;
187 if (cmd->cmd_buflen > 1 && !is_repeating) {
188 cmd->cmd_hnew = (cmd->cmd_hnew + 1) % cmd->cmd_histlen;
189 if (cmd->cmd_hnew >= cmd->cmd_halloc)
190 mdb_cmdbuf_allocchunk(cmd);
192 cmd->cmd_buf = cmd->cmd_history[cmd->cmd_hnew];
193 cmd->cmd_hcur = cmd->cmd_hnew;
195 if (cmd->cmd_hlen + 1 == cmd->cmd_histlen)
196 cmd->cmd_hold =
197 (cmd->cmd_hold + 1) % cmd->cmd_histlen;
199 cmd->cmd_hlen++;
201 cmd->cmd_hcur = cmd->cmd_hnew;
204 cmd->cmd_bufidx = 0;
205 cmd->cmd_buflen = 0;
207 return ((const char *)cmd->cmd_linebuf);
215 mdb_cmdbuf_backspace(mdb_cmdbuf_t *cmd, int c)
217 if (cmd->cmd_bufidx > 0) {
218 if (cmd->cmd_buflen != cmd->cmd_bufidx) {
219 bcopy(&cmd->cmd_buf[cmd->cmd_bufidx],
220 &cmd->cmd_buf[cmd->cmd_bufidx - 1],
221 cmd->cmd_buflen - cmd->cmd_bufidx);
224 cmd->cmd_bufidx--;
225 cmd->cmd_buflen--;
235 mdb_cmdbuf_delchar(mdb_cmdbuf_t *cmd, int c)
237 if (cmd->cmd_bufidx < cmd->cmd_buflen) {
238 if (cmd->cmd_bufidx < --cmd->cmd_buflen) {
239 bcopy(&cmd->cmd_buf[cmd->cmd_bufidx + 1],
240 &cmd->cmd_buf[cmd->cmd_bufidx],
241 cmd->cmd_buflen - cmd->cmd_bufidx);
252 mdb_cmdbuf_fwdchar(mdb_cmdbuf_t *cmd, int c)
254 if (cmd->cmd_bufidx < cmd->cmd_buflen) {
255 cmd->cmd_bufidx++;
264 mdb_cmdbuf_backchar(mdb_cmdbuf_t *cmd, int c)
266 if (cmd->cmd_bufidx > 0) {
267 cmd->cmd_bufidx--;
275 mdb_cmdbuf_transpose(mdb_cmdbuf_t *cmd, int c)
277 if (cmd->cmd_bufidx > 0 && cmd->cmd_buflen > 1) {
278 c = cmd->cmd_buf[cmd->cmd_bufidx - 1];
280 if (cmd->cmd_bufidx == cmd->cmd_buflen) {
281 cmd->cmd_buf[cmd->cmd_bufidx - 1] =
282 cmd->cmd_buf[cmd->cmd_bufidx - 2];
283 cmd->cmd_buf[cmd->cmd_bufidx - 2] = (char)c;
285 cmd->cmd_buf[cmd->cmd_bufidx - 1] =
286 cmd->cmd_buf[cmd->cmd_bufidx];
287 cmd->cmd_buf[cmd->cmd_bufidx++] = (char)c;
298 mdb_cmdbuf_home(mdb_cmdbuf_t *cmd, int c)
300 cmd->cmd_bufidx = 0;
306 mdb_cmdbuf_end(mdb_cmdbuf_t *cmd, int c)
308 cmd->cmd_bufidx = cmd->cmd_buflen;
313 fwdword_index(mdb_cmdbuf_t *cmd)
315 size_t i = cmd->cmd_bufidx + 1;
317 ASSERT(cmd->cmd_bufidx < cmd->cmd_buflen);
319 while (i < cmd->cmd_buflen && isspace(cmd->cmd_buf[i]))
322 while (i < cmd->cmd_buflen && !isspace(cmd->cmd_buf[i]) &&
323 !isalnum(cmd->cmd_buf[i]) && cmd->cmd_buf[i] != '_')
326 while (i < cmd->cmd_buflen &&
327 (isalnum(cmd->cmd_buf[i]) || cmd->cmd_buf[i] == '_'))
335 mdb_cmdbuf_fwdword(mdb_cmdbuf_t *cmd, int c)
337 if (cmd->cmd_bufidx == cmd->cmd_buflen)
340 cmd->cmd_bufidx = fwdword_index(cmd);
347 mdb_cmdbuf_killfwdword(mdb_cmdbuf_t *cmd, int c)
351 if (cmd->cmd_bufidx == cmd->cmd_buflen)
354 i = fwdword_index(cmd);
356 bcopy(&cmd->cmd_buf[i], &cmd->cmd_buf[cmd->cmd_bufidx],
357 cmd->cmd_buflen - i);
359 cmd->cmd_buflen -= i - cmd->cmd_bufidx;
365 backword_index(mdb_cmdbuf_t *cmd)
367 size_t i = cmd->cmd_bufidx - 1;
369 ASSERT(cmd->cmd_bufidx != 0);
371 while (i != 0 && isspace(cmd->cmd_buf[i]))
374 while (i != 0 && !isspace(cmd->cmd_buf[i]) &&
375 !isalnum(cmd->cmd_buf[i]) && cmd->cmd_buf[i] != '_')
378 while (i != 0 && (isalnum(cmd->cmd_buf[i]) || cmd->cmd_buf[i] == '_'))
389 mdb_cmdbuf_backword(mdb_cmdbuf_t *cmd, int c)
391 if (cmd->cmd_bufidx == 0)
394 cmd->cmd_bufidx = backword_index(cmd);
401 mdb_cmdbuf_killbackword(mdb_cmdbuf_t *cmd, int c)
405 if (cmd->cmd_bufidx == 0)
408 i = backword_index(cmd);
410 bcopy(&cmd->cmd_buf[cmd->cmd_bufidx], &cmd->cmd_buf[i],
411 cmd->cmd_buflen - cmd->cmd_bufidx);
413 cmd->cmd_buflen -= cmd->cmd_bufidx - i;
414 cmd->cmd_bufidx = i;
421 mdb_cmdbuf_kill(mdb_cmdbuf_t *cmd, int c)
423 cmd->cmd_buflen = cmd->cmd_bufidx;
429 mdb_cmdbuf_reset(mdb_cmdbuf_t *cmd, int c)
431 cmd->cmd_buflen = 0;
432 cmd->cmd_bufidx = 0;
438 mdb_cmdbuf_prevhist(mdb_cmdbuf_t *cmd, int c)
440 if (cmd->cmd_hcur != cmd->cmd_hold) {
441 if (cmd->cmd_hcur-- == cmd->cmd_hnew) {
442 cmd->cmd_buf[cmd->cmd_buflen] = 0;
443 (void) strcpy(cmd->cmd_linebuf, cmd->cmd_buf);
446 if (cmd->cmd_hcur < 0)
447 cmd->cmd_hcur = cmd->cmd_halloc - 1;
449 (void) strcpy(cmd->cmd_buf, cmd->cmd_history[cmd->cmd_hcur]);
450 cmd->cmd_bufidx = strlen(cmd->cmd_buf);
451 cmd->cmd_buflen = cmd->cmd_bufidx;
461 mdb_cmdbuf_nexthist(mdb_cmdbuf_t *cmd, int c)
463 if (cmd->cmd_hcur != cmd->cmd_hnew) {
464 cmd->cmd_hcur = (cmd->cmd_hcur + 1) % cmd->cmd_halloc;
466 if (cmd->cmd_hcur == cmd->cmd_hnew) {
467 (void) strcpy(cmd->cmd_buf, cmd->cmd_linebuf);
469 (void) strcpy(cmd->cmd_buf,
470 cmd->cmd_history[cmd->cmd_hcur]);
473 cmd->cmd_bufidx = strlen(cmd->cmd_buf);
474 cmd->cmd_buflen = cmd->cmd_bufidx;
484 mdb_cmdbuf_findhist(mdb_cmdbuf_t *cmd, int c)
488 if (cmd->cmd_buflen != 0) {
489 cmd->cmd_hcur = cmd->cmd_hnew;
490 cmd->cmd_buf[cmd->cmd_buflen] = 0;
491 (void) strcpy(cmd->cmd_linebuf, cmd->cmd_buf);
494 for (i = cmd->cmd_hcur, n = 0; n < cmd->cmd_hlen; n++) {
496 i = cmd->cmd_halloc - 1;
498 if (strstr(cmd->cmd_history[i], cmd->cmd_linebuf) != NULL) {
499 (void) strcpy(cmd->cmd_buf, cmd->cmd_history[i]);
500 cmd->cmd_bufidx = strlen(cmd->cmd_buf);
501 cmd->cmd_buflen = cmd->cmd_bufidx;
502 cmd->cmd_hcur = i;
508 cmd->cmd_hcur = cmd->cmd_hnew;
510 cmd->cmd_bufidx = 0;
511 cmd->cmd_buflen = 0;