static char * extract_arg (char *p, char *arg, int size) { char *np; while (*p && (*p == ' ' || *p == '\t' || *p == '\n')) p++; /* support quote space .mnu */ while (*p && (*p != ' ' || *(p - 1) == '\\') && *p != '\t' && *p != '\n') { np = str_get_next_char (p); if (np - p >= size) break; memcpy (arg, p, np - p); arg += np - p; size -= np - p; p = np; } *arg = 0; if (!*p || *p == '\n') str_prev_char (&p); return p; }
char * strip_ctrl_codes (char *s) { char *w; /* Current position where the stripped data is written */ char *r; /* Current position where the original data is read */ if (s == NULL) return NULL; for (w = s, r = s; *r != '\0';) { if (*r == ESC_CHAR) { /* Skip the control sequence's arguments */ ; /* '(' need to avoid strange 'B' letter in *Suse (if mc runs under root user) */ if (*(++r) == '[' || *r == '(') { /* strchr() matches trailing binary 0 */ while (*(++r) != '\0' && strchr ("0123456789;:?", *r) != NULL) ; } else if (*r == ']') { /* * Skip xterm's OSC (Operating System Command) * http://www.xfree86.org/current/ctlseqs.html * OSC P s ; P t ST * OSC P s ; P t BEL */ char *new_r = r; for (; *new_r != '\0'; ++new_r) { switch (*new_r) { /* BEL */ case '\a': r = new_r; goto osc_out; case ESC_CHAR: /* ST */ if (*(new_r + 1) == '\\') { r = new_r + 1; goto osc_out; } default: break; } } osc_out: ; } /* * Now we are at the last character of the sequence. * Skip it unless it's binary 0. */ if (*r != '\0') r++; } else { char *n; n = str_get_next_char (r); if (str_isprint (r)) { memmove (w, r, n - r); w += n - r; } r = n; } } *w = '\0'; return s; }
static cb_ret_t query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { static char buff[MB_LEN_MAX] = ""; static int bl = 0; switch (msg) { case DLG_KEY: switch (parm) { case KEY_LEFT: case KEY_RIGHT: bl = 0; h->ret_value = 0; dlg_stop (h); return MSG_HANDLED; case KEY_BACKSPACE: bl = 0; /* exit from completion list if input line is empty */ if (end == 0) { h->ret_value = 0; dlg_stop (h); } /* Refill the list box and start again */ else if (end == min_end) { end = str_get_prev_char (&input->buffer[end]) - input->buffer; input_handle_char (input, parm); h->ret_value = B_USER; dlg_stop (h); return MSG_HANDLED; } else { int new_end; int i; GList *e; new_end = str_get_prev_char (&input->buffer[end]) - input->buffer; for (i = 0, e = ((WListbox *) h->current->data)->list; e != NULL; i++, e = g_list_next (e)) { WLEntry *le = (WLEntry *) e->data; if (strncmp (input->buffer + start, le->text, new_end - start) == 0) { listbox_select_entry ((WListbox *) h->current->data, i); end = new_end; input_handle_char (input, parm); send_message ((Widget *) h->current->data, WIDGET_DRAW, 0); break; } } } return MSG_HANDLED; default: if (parm < 32 || parm > 255) { bl = 0; if (input_key_is_in_map (input, parm) != 2) return MSG_NOT_HANDLED; if (end == min_end) return MSG_HANDLED; /* This means we want to refill the list box and start again */ h->ret_value = B_USER; dlg_stop (h); return MSG_HANDLED; } else { GList *e; int i; int need_redraw = 0; int low = 4096; char *last_text = NULL; buff[bl++] = (char) parm; buff[bl] = '\0'; switch (str_is_valid_char (buff, bl)) { case -1: bl = 0; /* fallthrough */ case -2: return MSG_HANDLED; } for (i = 0, e = ((WListbox *) h->current->data)->list; e != NULL; i++, e = g_list_next (e)) { WLEntry *le = (WLEntry *) e->data; if (strncmp (input->buffer + start, le->text, end - start) == 0 && strncmp (&le->text[end - start], buff, bl) == 0) { if (need_redraw == 0) { need_redraw = 1; listbox_select_entry ((WListbox *) h->current->data, i); last_text = le->text; } else { char *si, *sl; int si_num = 0; int sl_num = 0; /* count symbols between start and end */ for (si = le->text + start; si < le->text + end; str_next_char (&si), si_num++) ; for (sl = last_text + start; sl < last_text + end; str_next_char (&sl), sl_num++) ; /* pointers to next symbols */ si = &le->text[str_offset_to_pos (le->text, ++si_num)]; sl = &last_text[str_offset_to_pos (last_text, ++sl_num)]; while (si[0] != '\0' && sl[0] != '\0') { char *nexti, *nextl; nexti = str_get_next_char (si); nextl = str_get_next_char (sl); if (nexti - si != nextl - sl || strncmp (si, sl, nexti - si) != 0) break; si = nexti; sl = nextl; si_num++; } last_text = le->text; si = &last_text[str_offset_to_pos (last_text, si_num)]; if (low > si - last_text) low = si - last_text; need_redraw = 2; } } } if (need_redraw == 2) { insert_text (input, last_text, low); send_message ((Widget *) h->current->data, WIDGET_DRAW, 0); } else if (need_redraw == 1) { h->ret_value = B_ENTER; dlg_stop (h); } bl = 0; } return MSG_HANDLED; } break; default: return default_dlg_callback (h, sender, msg, parm, data); } }