do_statusbar_home();
else if (s->scfunc == do_end)
do_statusbar_end();
-
-#ifndef NANO_TINY
- else if (s->scfunc == do_find_bracket)
- do_statusbar_find_bracket();
-#endif
else if (s->scfunc == do_verbatim_input) {
/* If we're using restricted mode, the filename
* isn't blank, and we're at the "Write File"
free(output);
}
-#ifndef NANO_TINY
-/* Search for a match to one of the two characters in bracket_set. If
- * reverse is TRUE, search backwards for the leftmost bracket.
- * Otherwise, search forwards for the rightmost bracket. Return TRUE if
- * we found a match, and FALSE otherwise. */
-bool find_statusbar_bracket_match(bool reverse, const char
- *bracket_set)
-{
- const char *rev_start = NULL, *found = NULL;
-
- assert(mbstrlen(bracket_set) == 2);
-
- /* rev_start might end up 1 character before the start or after the
- * end of the line. This won't be a problem because we'll skip over
- * it below in that case. */
- rev_start = reverse ? answer + (statusbar_x - 1) : answer +
- (statusbar_x + 1);
-
- while (TRUE) {
- /* Look for either of the two characters in bracket_set.
- * rev_start can be 1 character before the start or after the
- * end of the line. In either case, just act as though no match
- * is found. */
- found = ((rev_start > answer && *(rev_start - 1) == '\0') ||
- rev_start < answer) ? NULL : (reverse ?
- mbrevstrpbrk(answer, bracket_set, rev_start) :
- mbstrpbrk(rev_start, bracket_set));
-
- /* We've found a potential match. */
- if (found != NULL)
- break;
-
- /* We've reached the start or end of the statusbar text, so
- * get out. */
- return FALSE;
- }
-
- /* We've definitely found something. */
- statusbar_x = found - answer;
- statusbar_pww = statusbar_xplustabs();
-
- return TRUE;
-}
-
-/* Search for a match to the bracket at the current cursor position, if
- * there is one. */
-void do_statusbar_find_bracket(void)
-{
- size_t statusbar_x_save, pww_save;
- const char *ch;
- /* The location in matchbrackets of the bracket at the current
- * cursor position. */
- int ch_len;
- /* The length of ch in bytes. */
- const char *wanted_ch;
- /* The location in matchbrackets of the bracket complementing
- * the bracket at the current cursor position. */
- int wanted_ch_len;
- /* The length of wanted_ch in bytes. */
- char *bracket_set;
- /* The pair of characters in ch and wanted_ch. */
- size_t i;
- /* Generic loop variable. */
- size_t matchhalf;
- /* The number of single-byte characters in one half of
- * matchbrackets. */
- size_t mbmatchhalf;
- /* The number of multibyte characters in one half of
- * matchbrackets. */
- size_t count = 1;
- /* The initial bracket count. */
- bool reverse;
- /* The direction we search. */
- char *found_ch;
- /* The character we find. */
-
- assert(mbstrlen(matchbrackets) % 2 == 0);
-
- ch = answer + statusbar_x;
-
- if (ch == '\0' || (ch = mbstrchr(matchbrackets, ch)) == NULL)
- return;
-
- /* Save where we are. */
- statusbar_x_save = statusbar_x;
- pww_save = statusbar_pww;
-
- /* If we're on an opening bracket, which must be in the first half
- * of matchbrackets, we want to search forwards for a closing
- * bracket. If we're on a closing bracket, which must be in the
- * second half of matchbrackets, we want to search backwards for an
- * opening bracket. */
- matchhalf = 0;
- mbmatchhalf = mbstrlen(matchbrackets) / 2;
-
- for (i = 0; i < mbmatchhalf; i++)
- matchhalf += parse_mbchar(matchbrackets + matchhalf, NULL,
- NULL);
-
- reverse = ((ch - matchbrackets) >= matchhalf);
-
- /* If we're on an opening bracket, set wanted_ch to the character
- * that's matchhalf characters after ch. If we're on a closing
- * bracket, set wanted_ch to the character that's matchhalf
- * characters before ch. */
- wanted_ch = ch;
-
- while (mbmatchhalf > 0) {
- if (reverse)
- wanted_ch = matchbrackets + move_mbleft(matchbrackets,
- wanted_ch - matchbrackets);
- else
- wanted_ch += move_mbright(wanted_ch, 0);
-
- mbmatchhalf--;
- }
-
- ch_len = parse_mbchar(ch, NULL, NULL);
- wanted_ch_len = parse_mbchar(wanted_ch, NULL, NULL);
-
- /* Fill bracket_set in with the values of ch and wanted_ch. */
- bracket_set = charalloc((mb_cur_max() * 2) + 1);
- strncpy(bracket_set, ch, ch_len);
- strncpy(bracket_set + ch_len, wanted_ch, wanted_ch_len);
- null_at(&bracket_set, ch_len + wanted_ch_len);
-
- found_ch = charalloc(mb_cur_max() + 1);
-
- while (TRUE) {
- if (find_statusbar_bracket_match(reverse, bracket_set)) {
- /* If we found an identical bracket, increment count. If we
- * found a complementary bracket, decrement it. */
- parse_mbchar(answer + statusbar_x, found_ch, NULL);
- count += (strncmp(found_ch, ch, ch_len) == 0) ? 1 : -1;
-
- /* If count is zero, we've found a matching bracket. Update
- * the statusbar prompt and get out. */
- if (count == 0) {
- if (need_statusbar_horizontal_update(pww_save))
- update_statusbar_line(answer, statusbar_x);
- break;
- }
- } else {
- /* We didn't find either an opening or closing bracket.
- * Restore where we were, and get out. */
- statusbar_x = statusbar_x_save;
- statusbar_pww = pww_save;
- break;
- }
- }
-
- /* Clean up. */
- free(bracket_set);
- free(found_ch);
-}
-#endif /* !NANO_TINY */
/* Return the placewewant associated with statusbar_x, i.e. the
* zero-based column position of the cursor. The value will be no