static int bad_line_start (WEdit * edit, long p) { int c; c = edit_get_byte (edit, p); if (c == '.') { /* `...' is acceptable */ if (edit_get_byte (edit, p + 1) == '.') if (edit_get_byte (edit, p + 2) == '.') return 0; return 1; } if (c == '-') { if (edit_get_byte (edit, p + 1) == '-') if (edit_get_byte (edit, p + 2) == '-') return 0; /* `---' is acceptable */ return 1; } if (strchr (NO_FORMAT_CHARS_START, c)) return 1; return 0; }
static int test_indent (WEdit * edit, long p, long q) { int indent; indent = edit_indent_width (edit, p++); if (!indent) return 0; for (; p < q; p++) if (edit_get_byte (edit, p - 1) == '\n') if (indent != edit_indent_width (edit, p)) return 0; return indent; }
/* replaces a block of text */ static void put_paragraph (WEdit * edit, unsigned char *t, long p, int indent, int size) { long cursor; int i, c = 0; cursor = edit->curs1; if (indent) while (strchr ("\t ", edit_get_byte (edit, p))) p++; for (i = 0; i < size; i++, p++) { if (i && indent) { if (t[i - 1] == '\n' && c == '\n') { while (strchr ("\t ", edit_get_byte (edit, p))) p++; } else if (t[i - 1] == '\n') { long curs; edit_cursor_move (edit, p - edit->curs1); curs = edit->curs1; edit_insert_indent (edit, indent); if (cursor >= curs) cursor += edit->curs1 - p; p = edit->curs1; } else if (c == '\n') { edit_cursor_move (edit, p - edit->curs1); while (strchr ("\t ", edit_get_byte (edit, p))) { edit_delete (edit, 1); if (cursor > edit->curs1) cursor--; } p = edit->curs1; } } c = edit_get_byte (edit, p); if (c != t[i]) replace_at (edit, p, t[i]); } edit_cursor_move (edit, cursor - edit->curs1); /* restore cursor position */ }
static unsigned char * get_paragraph (WEdit *edit, long p, long q, int indent, int *size) { unsigned char *s, *t; #if 0 t = g_malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length + 10); #else t = g_malloc (2 * (q - p) + 100); #endif if (!t) return 0; for (s = t; p < q; p++, s++) { if (indent) if (edit_get_byte (edit, p - 1) == '\n') while (strchr ("\t ", edit_get_byte (edit, p))) p++; *s = edit_get_byte (edit, p); } *size = (unsigned long) s - (unsigned long) t; t[*size] = '\n'; return t; }
static long line_start (WEdit *edit, long line) { long p, l; l = edit->curs_line; p = edit->curs1; if (line < l) p = edit_move_backward (edit, p, l - line); else if (line > l) p = edit_move_forward (edit, p, line - l, 0); p = edit_bol (edit, p); while (strchr ("\t ", edit_get_byte (edit, p))) p++; return p; }
static void status_string (WEdit * edit, char *s, int w) { char byte_str[16]; /* * If we are at the end of file, print <EOF>, * otherwise print the current character as is (if printable), * as decimal and as hex. */ if (edit->curs1 < edit->last_byte) { unsigned char cur_byte = edit_get_byte (edit, edit->curs1); g_snprintf (byte_str, sizeof (byte_str), "%c %3d 0x%02X", is_printable (cur_byte) ? cur_byte : '.', (int) cur_byte, (unsigned) cur_byte); } else { strcpy (byte_str, "<EOF>"); } /* The field lengths just prevent the status line from shortening too much */ g_snprintf (s, w, "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb)= %s", edit->mark1 != edit->mark2 ? ( column_highlighting ? 'C' : 'B') : '-', edit->modified ? 'M' : '-', edit->macro_i < 0 ? '-' : 'R', edit->overwrite == 0 ? '-' : 'O', edit->curs_col, edit->start_line + 1, edit->curs_row, edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str); }
static struct syntax_rule apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule) { struct context_rule *r; int c; gboolean contextchanged = FALSE; gboolean found_left = FALSE, found_right = FALSE; gboolean keyword_foundleft = FALSE, keyword_foundright = FALSE; gboolean is_end; long end = 0; struct syntax_rule _rule = rule; c = xx_tolower (edit, edit_get_byte (edit, i)); if (c == 0) return rule; is_end = (rule.end == (unsigned char) i); /* check to turn off a keyword */ if (_rule.keyword) { if (edit_get_byte (edit, i - 1) == '\n') _rule.keyword = 0; if (is_end) { _rule.keyword = 0; keyword_foundleft = TRUE; } } /* check to turn off a context */ if (_rule.context && !_rule.keyword) { long e; r = edit->rules[_rule.context]; if (r->first_right == c && !(rule.border & RULE_ON_RIGHT_BORDER) && (e = compare_word_to_right (edit, i, r->right, r->whole_word_chars_left, r->whole_word_chars_right, r->line_start_right)) > 0) { _rule.end = e; found_right = TRUE; _rule.border = RULE_ON_RIGHT_BORDER; if (r->between_delimiters) _rule.context = 0; } else if (is_end && rule.border & RULE_ON_RIGHT_BORDER) { /* always turn off a context at 4 */ found_left = TRUE; _rule.border = 0; if (!keyword_foundleft) _rule.context = 0; } else if (is_end && rule.border & RULE_ON_LEFT_BORDER) { /* never turn off a context at 2 */ found_left = TRUE; _rule.border = 0; } } /* check to turn on a keyword */ if (!_rule.keyword) { const char *p; r = edit->rules[_rule.context]; p = r->keyword_first_chars; if (p != NULL) while (*(p = xx_strchr (edit, (unsigned char *) p + 1, c)) != '\0') { struct key_word *k; int count; long e; count = p - r->keyword_first_chars; k = r->keyword[count]; e = compare_word_to_right (edit, i, k->keyword, k->whole_word_chars_left, k->whole_word_chars_right, k->line_start); if (e > 0) { end = e; _rule.end = e; _rule.keyword = count; keyword_foundright = TRUE; break; } } } /* check to turn on a context */ if (!_rule.context) { if (!found_left && is_end) { if (rule.border & RULE_ON_RIGHT_BORDER) { _rule.border = 0; _rule.context = 0; contextchanged = TRUE; _rule.keyword = 0; } else if (rule.border & RULE_ON_LEFT_BORDER) { r = edit->rules[_rule._context]; _rule.border = 0; if (r->between_delimiters) { _rule.context = _rule._context; contextchanged = TRUE; _rule.keyword = 0; if (r->first_right == c) { long e; e = compare_word_to_right (edit, i, r->right, r->whole_word_chars_left, r->whole_word_chars_right, r->line_start_right); if (e >= end) { _rule.end = e; found_right = TRUE; _rule.border = RULE_ON_RIGHT_BORDER; _rule.context = 0; } } } } } if (!found_right) { int count; struct context_rule **rules = edit->rules; for (count = 1; rules[count]; count++) { r = rules[count]; if (r->first_left == c) { long e; e = compare_word_to_right (edit, i, r->left, r->whole_word_chars_left, r->whole_word_chars_right, r->line_start_left); if (e >= end && (!_rule.keyword || keyword_foundright)) { _rule.end = e; found_right = TRUE; _rule.border = RULE_ON_LEFT_BORDER; _rule._context = count; if (!r->between_delimiters && !_rule.keyword) { _rule.context = count; contextchanged = TRUE; } break; } } } } } /* check again to turn on a keyword if the context switched */ if (contextchanged && !_rule.keyword) { const char *p; r = edit->rules[_rule.context]; p = r->keyword_first_chars; while (*(p = xx_strchr (edit, (unsigned char *) p + 1, c)) != '\0') { struct key_word *k; int count; long e; count = p - r->keyword_first_chars; k = r->keyword[count]; e = compare_word_to_right (edit, i, k->keyword, k->whole_word_chars_left, k->whole_word_chars_right, k->line_start); if (e > 0) { _rule.end = e; _rule.keyword = count; break; } } } return _rule; }
static long compare_word_to_right (WEdit * edit, long i, const char *text, const char *whole_left, const char *whole_right, int line_start) { const unsigned char *p, *q; int c, d, j; if (*text == '\0') return -1; c = xx_tolower (edit, edit_get_byte (edit, i - 1)); if (line_start != 0 && c != '\n') return -1; if (whole_left != NULL && strchr (whole_left, c) != NULL) return -1; for (p = (unsigned char *) text, q = p + str_term_width1 ((char *) p); p < q; p++, i++) { switch (*p) { case SYNTAX_TOKEN_STAR: if (++p > q) return -1; for (;;) { c = xx_tolower (edit, edit_get_byte (edit, i)); if (*p == '\0' && whole_right != NULL && strchr (whole_right, c) == NULL) break; if (c == *p) break; if (c == '\n') return -1; i++; } break; case SYNTAX_TOKEN_PLUS: if (++p > q) return -1; j = 0; for (;;) { c = xx_tolower (edit, edit_get_byte (edit, i)); if (c == *p) { j = i; if (*p == *text && p[1] == '\0') /* handle eg '+' and @+@ keywords properly */ break; } if (j && strchr ((char *) p + 1, c)) /* c exists further down, so it will get matched later */ break; if (c == '\n' || c == '\t' || c == ' ') { if (!*p) { i--; break; } if (j == 0) return -1; i = j; break; } if (whole_right != NULL && (strchr (whole_right, c) == NULL)) { if (*p == '\0') { i--; break; } if (j == 0) return -1; i = j; break; } i++; } break; case SYNTAX_TOKEN_BRACKET: if (++p > q) return -1; c = -1; for (;; i++) { d = c; c = xx_tolower (edit, edit_get_byte (edit, i)); for (j = 0; p[j] != SYNTAX_TOKEN_BRACKET && p[j]; j++) if (c == p[j]) goto found_char2; break; found_char2: ; /* dummy command */ } i--; while (*p != SYNTAX_TOKEN_BRACKET && p <= q) p++; if (p > q) return -1; if (p[1] == d) i--; break; case SYNTAX_TOKEN_BRACE: if (++p > q) return -1; c = xx_tolower (edit, edit_get_byte (edit, i)); for (; *p != SYNTAX_TOKEN_BRACE && *p; p++) if (c == *p) goto found_char3; return -1; found_char3: while (*p != SYNTAX_TOKEN_BRACE && p < q) p++; break; default: if (*p != xx_tolower (edit, edit_get_byte (edit, i))) return -1; } } if (whole_right != NULL && strchr (whole_right, xx_tolower (edit, edit_get_byte (edit, i))) != NULL) return -1; return i; }
static inline void status_string (WEdit * edit, char *s, int w) { char byte_str[16]; unsigned char cur_byte = 0; unsigned int cur_utf = 0; int cw = 1; /* * If we are at the end of file, print <EOF>, * otherwise print the current character as is (if printable), * as decimal and as hex. */ if (edit->curs1 < edit->last_byte) { if (!edit->utf8) { cur_byte = edit_get_byte (edit, edit->curs1); g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X", (int) cur_byte, (unsigned) cur_byte); } else { cur_utf = edit_get_utf (edit, edit->curs1, &cw); if (cw > 0) { g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X", (unsigned) cur_utf, (unsigned) cur_utf); } else { cur_utf = edit_get_byte (edit, edit->curs1); g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X", (int) cur_utf, (unsigned) cur_utf); } } } else { strcpy (byte_str, "<EOF> "); } /* The field lengths just prevent the status line from shortening too much */ if (simple_statusbar) g_snprintf (s, w, "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s", edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-', edit->modified ? 'M' : '-', macro_index < 0 ? '-' : 'R', edit->overwrite == 0 ? '-' : 'O', edit->curs_col + edit->over_col, edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str, #ifdef HAVE_CHARSET mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : "" #else "" #endif ); else g_snprintf (s, w, "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb) %s %s", edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-', edit->modified ? 'M' : '-', macro_index < 0 ? '-' : 'R', edit->overwrite == 0 ? '-' : 'O', edit->curs_col + edit->over_col, edit->start_line + 1, edit->curs_row, edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str, #ifdef HAVE_CHARSET mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : "" #else "" #endif ); }
static void edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_col) { struct line_s line[MAX_LINE_LEN]; struct line_s *p = line; long m1 = 0, m2 = 0, q, c1, c2; int col, start_col_real; unsigned int c; int color; int abn_style; int i; int utf8lag = 0; unsigned int cur_line = 0; int book_mark = 0; char line_stat[LINE_STATE_WIDTH + 1] = "\0"; if (row > edit->widget.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET) return; if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR)) book_mark = BOOK_MARK_COLOR; else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR)) book_mark = BOOK_MARK_FOUND_COLOR; if (book_mark) abn_style = book_mark << 16; else abn_style = MOD_ABNORMAL; end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width; edit_get_syntax_color (edit, b - 1, &color); q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0); start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col; if (option_line_state) { cur_line = edit->start_line + row; if (cur_line <= (unsigned int) edit->total_lines) { g_snprintf (line_stat, LINE_STATE_WIDTH + 1, "%7i ", cur_line + 1); } else { memset (line_stat, ' ', LINE_STATE_WIDTH); line_stat[LINE_STATE_WIDTH] = '\0'; } if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR)) { g_snprintf (line_stat, 2, "*"); } } if (col + 16 > -edit->start_col) { eval_marks (edit, &m1, &m2); if (row <= edit->total_lines - edit->start_line) { long tws = 0; if (tty_use_colors () && visible_tws) { tws = edit_eol (edit, b); while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' ' || c == '\t')) tws--; } while (col <= end_col - edit->start_col) { int cw = 1; p->ch = 0; p->style = 0; if (q == edit->curs1) p->style |= MOD_CURSOR; if (q >= m1 && q < m2) { if (edit->column_highlight) { int x; x = edit_move_forward3 (edit, b, 0, q); c1 = min (edit->column1, edit->column2); c2 = max (edit->column1, edit->column2); if (x >= c1 && x < c2) p->style |= MOD_MARKED; } else p->style |= MOD_MARKED; } if (q == edit->bracket) p->style |= MOD_BOLD; if (q >= edit->found_start && q < edit->found_start + edit->found_len) p->style |= MOD_BOLD; if (!edit->utf8) { c = edit_get_byte (edit, q); } else { c = edit_get_utf (edit, q, &cw); } /* we don't use bg for mc - fg contains both */ if (book_mark) { p->style |= book_mark << 16; } else { edit_get_syntax_color (edit, q, &color); p->style |= color << 16; } switch (c) { case '\n': col = (end_col + utf8lag) - edit->start_col + 1; /* quit */ break; case '\t': i = TAB_SIZE - ((int) col % TAB_SIZE); col += i; if (tty_use_colors () && ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws)) { if (p->style & MOD_MARKED) c = p->style; else if (book_mark) c |= book_mark << 16; else c = p->style | MOD_WHITESPACE; if (i > 2) { p->ch = '<'; p->style = c; p++; while (--i > 1) { p->ch = '-'; p->style = c; p++; } p->ch = '>'; p->style = c; p++; } else if (i > 1) { p->ch = '<'; p->style = c; p++; p->ch = '>'; p->style = c; p++; } else { p->ch = '>'; p->style = c; p++; } } else if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws) { p->ch = '.'; p->style |= MOD_WHITESPACE; c = p->style & ~MOD_CURSOR; p++; while (--i) { p->ch = ' '; p->style = c; p++; } } else { p->ch |= ' '; c = p->style & ~MOD_CURSOR; p++; while (--i) { p->ch = ' '; p->style = c; p++; } } break; case ' ': if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws) { p->ch = '.'; p->style |= MOD_WHITESPACE; p++; col++; break; } /* fallthrough */ default: #ifdef HAVE_CHARSET if (mc_global.utf8_display) { if (!edit->utf8) { c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter); } } else if (edit->utf8) c = convert_from_utf_to_current_c (c, edit->converter); else #endif c = convert_to_display_c (c); /* Caret notation for control characters */ if (c < 32) { p->ch = '^'; p->style = abn_style; p++; p->ch = c + 0x40; p->style = abn_style; p++; col += 2; break; } if (c == 127) { p->ch = '^'; p->style = abn_style; p++; p->ch = '?'; p->style = abn_style; p++; col += 2; break; } if (!edit->utf8) { if ((mc_global.utf8_display && g_unichar_isprint (c)) || (!mc_global.utf8_display && is_printable (c))) { p->ch = c; p++; } else { p->ch = '.'; p->style = abn_style; p++; } } else { if (g_unichar_isprint (c)) { p->ch = c; p++; } else { p->ch = '.'; p->style = abn_style; p++; } } col++; break; } /* case */ q++; if (cw > 1) { q += cw - 1; } } } } else { start_col_real = start_col = 0; } p->ch = '\0'; print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark); }
/* b is a pointer to the beginning of the line */ static void edit_draw_this_line (WEdit *edit, long b, long row, long start_col, long end_col) { static unsigned int line[MAX_LINE_LEN]; unsigned int *p = line; long m1 = 0, m2 = 0, q, c1, c2; int col, start_col_real; unsigned int c; int color; int i; edit_get_syntax_color (edit, b - 1, &color); q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0); start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col; c1 = min (edit->column1, edit->column2); c2 = max (edit->column1, edit->column2); if (col + 16 > -edit->start_col) { eval_marks (edit, &m1, &m2); if (row <= edit->total_lines - edit->start_line) { long tws; if (use_colors && visible_tws) { tws = edit_eol (edit, b); while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' ' || c == '\t')) tws--; } while (col <= end_col - edit->start_col) { *p = 0; if (q == edit->curs1) *p |= MOD_CURSOR; if (q >= m1 && q < m2) { if (column_highlighting) { int x; x = edit_move_forward3 (edit, b, 0, q); if (x >= c1 && x < c2) *p |= MOD_MARKED; } else *p |= MOD_MARKED; } if (q == edit->bracket) *p |= MOD_BOLD; if (q >= edit->found_start && q < edit->found_start + edit->found_len) *p |= MOD_BOLD; c = edit_get_byte (edit, q); /* we don't use bg for mc - fg contains both */ edit_get_syntax_color (edit, q, &color); *p |= color << 16; switch (c) { case '\n': col = end_col - edit->start_col + 1; /* quit */ *(p++) |= ' '; break; case '\t': i = TAB_SIZE - ((int) col % TAB_SIZE); col += i; if (use_colors && visible_tabs) { c = (*p & ~MOD_CURSOR) | MOD_WHITESPACE; if (i > 2) { *(p++) |= '<' | MOD_WHITESPACE; while (--i > 1) *(p++) = c | '-'; *(p++) = c | '>'; } else if (i > 1) { *(p++) |= '<' | MOD_WHITESPACE; *(p++) = c | '>'; } else *(p++) |= '>' | MOD_WHITESPACE; } else if (use_colors && visible_tws && q >= tws) { *p |= '.' | MOD_WHITESPACE; c = *(p++) & ~MOD_CURSOR; while (--i) *(p++) = c; } else { *p |= ' '; c = *(p++) & ~MOD_CURSOR; while (--i) *(p++) = c; } break; case ' ': if (use_colors && visible_tws && q >= tws) { *(p++) |= '.' | MOD_WHITESPACE; col++; break; } /* fallthrough */ default: c = convert_to_display_c (c); /* Caret notation for control characters */ if (c < 32) { *(p++) = '^' | MOD_ABNORMAL; *(p++) = (c + 0x40) | MOD_ABNORMAL; col += 2; break; } if (c == 127) { *(p++) = '^' | MOD_ABNORMAL; *(p++) = '?' | MOD_ABNORMAL; col += 2; break; } if (is_printable (c)) { *(p++) |= c; } else { *(p++) = '.' | MOD_ABNORMAL; } col++; break; } q++; } } } else { start_col_real = start_col = 0; } *p = 0; print_to_widget (edit, row, start_col, start_col_real, end_col, line); }
static inline void edit_status_window (WEdit * edit) { int y, x; int cols = edit->widget.cols; tty_setcolor (STATUSBAR_COLOR); if (cols > 5) { const char *fname = N_("NoName"); char *full_fname = NULL; if (edit->filename_vpath != NULL) { full_fname = vfs_path_to_str (edit->filename_vpath); fname = x_basename (full_fname); } #ifdef ENABLE_NLS else fname = _(fname); #endif edit_move (2, 0); tty_printf ("[%s]", str_term_trim (fname, edit->widget.cols - 8 - 6)); g_free (full_fname); } tty_getyx (&y, &x); x -= edit->widget.x; x += 4; if (x + 6 <= cols - 2 - 6) { edit_move (x, 0); tty_printf ("[%c%c%c%c]", edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-', edit->modified ? 'M' : '-', macro_index < 0 ? '-' : 'R', edit->overwrite == 0 ? '-' : 'O'); } if (cols > 30) { edit_move (2, edit->widget.lines - 1); tty_printf ("%3ld %5ld/%ld %6ld/%ld", edit->curs_col + edit->over_col, edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte); } /* * If we are at the end of file, print <EOF>, * otherwise print the current character as is (if printable), * as decimal and as hex. */ if (cols > 46) { edit_move (32, edit->widget.lines - 1); if (edit->curs1 >= edit->last_byte) tty_print_string ("[<EOF> ]"); #ifdef HAVE_CHARSET else if (edit->utf8) { unsigned int cur_utf; int cw = 1; cur_utf = edit_get_utf (edit, edit->curs1, &cw); if (cw <= 0) cur_utf = edit_get_byte (edit, edit->curs1); tty_printf ("[%05d 0x%04X]", cur_utf, cur_utf); } #endif else { unsigned char cur_byte; cur_byte = edit_get_byte (edit, edit->curs1); tty_printf ("[%05d 0x%04X]", (unsigned int) cur_byte, (unsigned int) cur_byte); } } }
static long compare_word_to_right (WEdit *edit, long i, const char *text, const char *whole_left, const char *whole_right, int line_start) { const unsigned char *p, *q; int stok, etok; int c, d, j; if (!*text) return -1; c = edit_get_byte (edit, i - 1); if (line_start) if (c != '\n') return -1; if (whole_left) if (strchr (whole_left, c)) return -1; for (p = (unsigned char *) text, q = p + strlen ((char *) p); p < q; p++, i++) { switch (*p) { case SYNTAX_TOKEN_STAR: if (++p > q) return -1; for (;;) { c = edit_get_byte (edit, i); if (!*p) if (whole_right) if (!strchr (whole_right, c)) break; if (c == *p) break; if (c == '\n') { if (!*p) { i--; break; } return -1; } i++; } break; case SYNTAX_TOKEN_PLUS: if (++p > q) return -1; j = 0; for (;;) { c = edit_get_byte (edit, i); if (c == *p) { j = i; if (*p == *text && !p[1]) /* handle eg '+' and @+@ keywords properly */ break; } if (j && strchr ((char *) p + 1, c)) /* c exists further down, so it will get matched later */ break; if (c == '\n' || c == '\t' || c == ' ') { if (!*p) { i--; break; } if (!j) return -1; i = j; break; } if (whole_right) if (!strchr (whole_right, c)) { if (!*p) { i--; break; } if (!j) return -1; i = j; break; } i++; } break; case SYNTAX_TOKEN_BRACKET: if (++p > q) return -1; c = -1; for (;; i++) { d = c; c = edit_get_byte (edit, i); for (j = 0; p[j] != SYNTAX_TOKEN_BRACKET && p[j]; j++) if (c == p[j]) goto found_char2; break; found_char2: ; /* dummy command */ } i--; while (*p != SYNTAX_TOKEN_BRACKET && p <= q) p++; if (p > q) return -1; if (p[1] == d) i--; break; case SYNTAX_TOKEN_BRACE: case SYNTAX_TOKEN_CHEVRON: stok = *p; etok = *p; if (++p > q) return -1; c = edit_get_byte (edit, i); for (; *p != etok && *p; p++) if (c == *p) goto found_char3; return -1; found_char3: while (*p != etok && p < q) p++; i -= (stok == SYNTAX_TOKEN_CHEVRON); break; default: if (*p != edit_get_byte (edit, i)) return -1; } } if (whole_right) if (strchr (whole_right, edit_get_byte (edit, i))) return -1; return i; }