/* * m_quote_capture() is similar to m_capture(), but it removes * quotes from either end of the string. */ void m_quote_capture(char **str, int start, int end) { int i, e; char *s; e = token[end].start_index + token[end].length - 1; *str = gp_realloc(*str, (e - token[start].start_index + 1), "string"); s = *str; for (i = token[start].start_index + 1; i < e && gp_input_line[i] != NUL; i++) *s++ = gp_input_line[i]; *s = NUL; if (gp_input_line[token[start].start_index] == '"') parse_esc(*str); else parse_sq(*str); }
/* * quote_str() does the same thing as copy_str, except it ignores the * quotes at both ends. This seems redundant, but is done for * efficency. */ void quote_str(char *str, int t_num, int max) { int i = 0; int start = token[t_num].start_index + 1; int count; if ((count = token[t_num].length - 2) >= max) { count = max - 1; FPRINTF((stderr, "str buffer overflow in quote_str")); } if (count > 0) { do { str[i++] = gp_input_line[start++]; } while (i != count); } str[i] = NUL; /* convert \t and \nnn (octal) to char if in double quotes */ if (gp_input_line[token[t_num].start_index] == '"') parse_esc(str); else parse_sq(str); }
static gboolean parse(void) { GByteArray *bytes; guchar buffer[64]; gsize i, length; gboolean ret = FALSE; bytes = g_byte_array_new(); if ((length = read(STDIN_FILENO, buffer, sizeof(buffer))) > 0) { g_byte_array_append(bytes, buffer, length); } i = 0; while (i < bytes->len) { switch (bytes->data[i]) { case 'A': case 'a': tracking_mode = (tracking_mode == tracking_x10) ? 0 : tracking_x10; i++; break; case 'B': case 'b': tracking_mode = (tracking_mode == tracking_mouse) ? 0 : tracking_mouse; i++; break; case 'C': case 'c': tracking_mode = (tracking_mode == tracking_hilite) ? 0 : tracking_hilite; i++; break; case 'D': case 'd': tracking_mode = (tracking_mode == tracking_cell_motion) ? 0 : tracking_cell_motion; i++; break; case 'E': case 'e': tracking_mode = (tracking_mode == tracking_all_motion) ? 0 : tracking_all_motion; i++; break; case 'F': case 'f': tracking_mode = (tracking_mode == tracking_xterm_ext) ? 0 : tracking_xterm_ext; i++; break; case 'G': case 'g': tracking_mode = (tracking_mode == tracking_urxvt) ? 0 : tracking_urxvt; i++; break; case 'I': case 'i': tracking_focus_mode = !tracking_focus_mode; decset(tracking_focus, tracking_focus_mode); i++; break; case 'Q': case 'q': ret = TRUE; i++; break; case '\033': { gsize consumed = parse_esc(&bytes->data[i], bytes->len - i); if (consumed > 0) { i += consumed; break; } /* else fall-trough */ } default: i += print_data(&bytes->data[i], bytes->len - i); fprintf(stdout, "\r\n"); break; } } fflush(stdout); g_byte_array_free(bytes, TRUE); return ret; }