+2009-01-24 Chris Allegretta <chrisa@asty.org>
+ * Add interruptability to search functions. New functions enable_nodelay and
+ disable_nodelay and changes to the routines to handle checking for pending
+ searches. Fixes Savnnah bug 24946: Need interrrupt for search.
+
2009-01-19 Chris Allegretta <chrisa@asty.org>
- * Change funcion definitions to shorts instead of (void *)s. New mapping function
+ * Change function definitions to shorts instead of (void *)s. New mapping function
iso_me_harder_funcmap(). Fixes compilation complaints with -pedantic,
reported by Eitan Adler <eitanadlerlist@gmail.com>.
#endif
#endif
+bool nodelay_mode = FALSE;
+ /* Are we in nodelay mode (checking for a cancel wile doing something */
+
char *answer = NULL;
/* The answer string used by the statusbar prompt. */
extern size_t quotelen;
#endif
#endif
-
+bool nodelay_mode;
extern char *answer;
extern ssize_t tabsize;
void do_replace_highlight(bool highlight, const char *word);
char *flagtostr(int flag);
const subnfunc *sctofunc(sc *s);
+const subnfunc *getfuncfromkey(WINDOW *win);
void print_sclist(void);
sc *strtosc(int menu, char *input);
function_type strtokeytype(char *str);
const char *gototext_msg;
const char *new_buffer_msg;
void iso_me_harder_funcmap(short func);
+void enable_nodelay(void);
+void disable_nodelay(void);
#ifdef HAVE_REGEX_H
const char *regexp_msg;
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
+#include <time.h>
static bool search_last_line = FALSE;
/* Have we gone past the last line while searching? */
ssize_t current_y_find = openfile->current_y;
filestruct *fileptr = openfile->current;
const char *rev_start = fileptr->data, *found = NULL;
+ const subnfunc *f;
+ time_t lastkbcheck = time(NULL);
/* rev_start might end up 1 character before the start or after the
* end of the line. This won't be a problem because strstrwrapper()
openfile->current_x + 1;
/* Look for needle in the current line we're searching. */
+ enable_nodelay();
while (TRUE) {
+ if (time(NULL) - lastkbcheck > 1) {
+ lastkbcheck = time(NULL);
+ f = getfuncfromkey(edit);
+ if (f && f->scfunc == CANCEL_MSG) {
+ statusbar(_("Cancelled"));
+ return FALSE;
+ }
+ }
+
found = strstrwrapper(fileptr->data, needle, rev_start);
/* We've found a potential match. */
/* We've finished processing the file, so get out. */
if (search_last_line) {
not_found_msg(needle);
+ disable_nodelay();
return FALSE;
}
#endif
) {
not_found_msg(needle);
+ disable_nodelay();
return FALSE;
}
+ disable_nodelay();
/* We've definitely found something. */
openfile->current = fileptr;
openfile->current_x = current_x_find;
-
/* $Id$ */
/**************************************************************************
* winio.c *
doupdate();
errcount = 0;
- while ((input = wgetch(win)) == ERR) {
- errcount++;
-
- /* If we've failed to get a character MAX_BUF_SIZE times in a
- * row, assume that the input source we were using is gone and
- * die gracefully. We could check if errno is set to EIO
- * ("Input/output error") and die gracefully in that case, but
- * it's not always set properly. Argh. */
- if (errcount == MAX_BUF_SIZE)
- handle_hupterm(0);
- }
+ if (nodelay_mode) {
+ if ((input = wgetch(win)) == ERR)
+ return;
+ } else
+ while ((input = wgetch(win)) == ERR) {
+ errcount++;
+
+ /* If we've failed to get a character MAX_BUF_SIZE times in a
+ * row, assume that the input source we were using is gone and
+ * die gracefully. We could check if errno is set to EIO
+ * ("Input/output error") and die gracefully in that case, but
+ * it's not always set properly. Argh. */
+ if (errcount == MAX_BUF_SIZE)
+ handle_hupterm(0);
+ }
#ifndef NANO_TINY
allow_pending_sigwinch(FALSE);
*func_key = FALSE;
/* Read in a character. */
- while ((kbinput = get_input(win, 1)) == NULL);
+ if (nodelay_mode) {
+ kbinput = get_input(win, 1);
+ if (kbinput == 0)
+ return 0;
+ } else
+ while ((kbinput = get_input(win, 1)) == NULL);
switch (*kbinput) {
case ERR:
return NULL;
}
+
+/* Try to get a function back from a window. Just a wrapper so
+ functions to need to create function_key meta_key blah blah
+ mmenu - what menu name to look through for valid funcs */
+const subnfunc *getfuncfromkey(WINDOW *win)
+{
+ int kbinput;
+ bool func_key = FALSE, meta_key = FALSE;
+ const sc *s;
+ const subnfunc *f;
+
+ kbinput = parse_kbinput(win, &meta_key, &func_key);
+ if (kbinput == 0)
+ return NULL;
+
+ s = get_shortcut(currmenu, &kbinput, &meta_key, &func_key);
+ if (!s)
+ return NULL;
+
+ f = sctofunc((sc *) s);
+ return f;
+
+}
+
+
+
/* Move to (x, y) in win, and display a line of n spaces with the
* current attributes. */
void blank_line(WINDOW *win, int y, int x, int n)
do_cursorpos(FALSE);
}
+void enable_nodelay(void)
+{
+ nodelay_mode = TRUE;
+ nodelay(edit, TRUE);
+}
+
+void disable_nodelay(void)
+{
+ nodelay_mode = FALSE;
+ nodelay(edit, FALSE);
+}
+
+
/* Highlight the current word being replaced or spell checked. We
* expect word to have tabs and control characters expanded. */
void do_replace_highlight(bool highlight, const char *word)