Index: codelist.pl
===================================================================
--- codelist.pl	(revision 0982901b3611e8a795d8e1630bcbfe1925feefe5)
+++ codelist.pl	(revision 4e4847c43520c792fa6e17596790361ca5db61a9)
@@ -8,5 +8,5 @@
 
 foreach $file (@ARGV) {
-    next if $file eq 'perlglue.c';
+    next if $file eq 'perlglue.c' || $file eq 'owl.c';
     open(FILE, $file);
 
Index: owl.c
===================================================================
--- owl.c	(revision f350fc3bddacf13d36d24752c68a0cc932ba18a9)
+++ owl.c	(revision 4e4847c43520c792fa6e17596790361ca5db61a9)
@@ -37,5 +37,5 @@
 owl_global g;
 
-typedef struct _owl_options {           /* noproto */
+typedef struct _owl_options {
   bool load_initial_subs;
   char *configfile;
@@ -46,6 +46,20 @@
 } owl_options;
 
+void usage()
+{
+  fprintf(stderr, "Barnowl version %s\n", OWL_VERSION_STRING);
+  fprintf(stderr, "Usage: barnowl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-s <confdir>] [-t <ttyname>]\n");
+  fprintf(stderr, "  -n,--no-subs        don't load zephyr subscriptions\n");
+  fprintf(stderr, "  -d,--debug          enable debugging\n");
+  fprintf(stderr, "  -D,--remove-debug   enable debugging and delete previous debug file\n");
+  fprintf(stderr, "  -v,--version        print the Barnowl version number and exit\n");
+  fprintf(stderr, "  -h,--help           print this help message\n");
+  fprintf(stderr, "  -c,--config-file    specify an alternate config file\n");
+  fprintf(stderr, "  -s,--config-dir     specify an alternate config dir (default ~/.owl)\n");
+  fprintf(stderr, "  -t,--tty            set the tty name\n");
+}
+
 /* TODO: free owl_options after init is done? */
-void owl_parse_options(int argc, char *argv[], owl_options *opts) /* noproto */ {
+void owl_parse_options(int argc, char *argv[], owl_options *opts) {
   static const struct option long_options[] = {
     { "no-subs",         0, 0, 'n' },
@@ -93,24 +107,5 @@
 }
 
-void owl_register_signal_handlers(void) /* noproto */ {
-  struct sigaction sigact;
-
-  /* signal handler */
-  /*sigact.sa_handler=sig_handler;*/
-  sigact.sa_sigaction=sig_handler;
-  sigemptyset(&sigact.sa_mask);
-  sigact.sa_flags=SA_SIGINFO;
-  sigaction(SIGWINCH, &sigact, NULL);
-  sigaction(SIGALRM, &sigact, NULL);
-  sigaction(SIGPIPE, &sigact, NULL);
-  sigaction(SIGTERM, &sigact, NULL);
-  sigaction(SIGHUP, &sigact, NULL);
-
-  sigact.sa_sigaction=sigint_handler;
-  sigaction(SIGINT, &sigact, NULL);
-
-}
-
-void owl_start_color(void) /* noproto */ {
+void owl_start_color(void) {
   start_color();
 #ifdef HAVE_USE_DEFAULT_COLORS
@@ -135,5 +130,5 @@
 }
 
-void owl_start_curses(void) /* noproto */ {
+void owl_start_curses(void) {
   struct termios tio;
   /* save initial terminal settings */
@@ -154,5 +149,5 @@
 }
 
-void owl_setup_default_filters(void) /* noproto */ {
+void owl_setup_default_filters(void) {
   owl_filter *f;
 
@@ -206,280 +201,4 @@
   owl_filter_init_fromstring(f, "all", "true");
   owl_list_append_element(owl_global_get_filterlist(&g), f);
-}
-
-int main(int argc, char **argv, char **env)
-{
-  WINDOW *recwin, *sepwin, *typwin, *msgwin;
-  owl_editwin *tw;
-  owl_popwin *pw;
-  int argcsave, followlast;
-  int newmsgs, nexttimediff;
-  const char *const *argvsave;
-  char *perlout, *perlerr;
-  const owl_style *s;
-  time_t nexttime, now;
-  struct tm *today;
-  const char *dir;
-  owl_message *m;
-  owl_options opts;
-
-  if (!GLIB_CHECK_VERSION (2, 12, 0))
-    g_error ("GLib version 2.12.0 or above is needed.");
-
-  argcsave=argc;
-  argvsave=strs(argv);
-
-  setlocale(LC_ALL, "");
-
-  memset(&opts, 0, sizeof opts);
-  opts.load_initial_subs = 1;
-  owl_parse_options(argc, argv, &opts);
-  g.load_initial_subs = opts.load_initial_subs;
-
-  owl_function_debugmsg("startup: Finished parsing arguments");
-
-  owl_register_signal_handlers();
-  owl_start_curses();
-
-  /* owl global init */
-  owl_global_init(&g);
-  if (opts.rm_debug) unlink(OWL_DEBUG_FILE);
-  if (opts.debug) owl_global_set_debug_on(&g);
-  if (opts.confdir) owl_global_set_confdir(&g, opts.confdir);
-  owl_function_debugmsg("startup: first available debugging message");
-  owl_global_set_startupargs(&g, argcsave, argvsave);
-  owl_global_set_haveaim(&g);
-
-  /* prepare stdin dispatch */
-  {
-    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
-    d->fd = STDIN;
-    d->cfunc = &owl_process_input;
-    d->destroy = NULL;
-    owl_select_add_dispatch(d);
-  }
-
-  owl_zephyr_initialize();
-
-#if OWL_STDERR_REDIR
-  /* Do this only after we've started curses up... */
-  {
-    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
-    owl_function_debugmsg("startup: doing stderr redirection");
-    d->fd = stderr_replace();
-    d->cfunc = stderr_redirect_handler;
-    d->destroy = NULL;
-    owl_select_add_dispatch(d);
-  }
-#endif
-
-  /* create the owl directory, in case it does not exist */
-  owl_function_debugmsg("startup: creating owl directory, if not present");
-  dir=owl_global_get_confdir(&g);
-  mkdir(dir, S_IRWXU);
-
-  /* set the tty, either from the command line, or by figuring it out */
-  owl_function_debugmsg("startup: setting tty name");
-  if (opts.tty) {
-    owl_global_set_tty(&g, opts.tty);
-  } else {
-    owl_global_set_tty(&g, owl_util_get_default_tty());
-  }
-
-  /* Initialize perl */
-  owl_function_debugmsg("startup: processing config file");
-  owl_context_set_readconfig(owl_global_get_context(&g));
-  perlerr=owl_perlconfig_initperl(opts.configfile, &argc, &argv, &env);
-  if (perlerr) {
-    endwin();
-    fprintf(stderr, "Internal perl error: %s\n", perlerr);
-    fflush(stderr);
-    printf("Internal perl error: %s\n", perlerr);
-    fflush(stdout);
-    exit(1);
-  }
-
-  owl_global_complete_setup(&g);
-
-  owl_setup_default_filters();
-
-  /* set the current view */
-  owl_function_debugmsg("startup: setting the current view");
-  owl_view_create(owl_global_get_current_view(&g), "main",
-                  owl_global_get_filter(&g, "all"),
-                  owl_global_get_style_by_name(&g, "default"));
-
-  /* AIM init */
-  owl_function_debugmsg("startup: doing AIM initialization");
-  owl_aim_init();
-
-  /* execute the startup function in the configfile */
-  owl_function_debugmsg("startup: executing perl startup, if applicable");
-  perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();");
-  if (perlout) owl_free(perlout);
-
-  /* hold on to the window names for convenience */
-  msgwin=owl_global_get_curs_msgwin(&g);
-  recwin=owl_global_get_curs_recwin(&g);
-  sepwin=owl_global_get_curs_sepwin(&g);
-  typwin=owl_global_get_curs_typwin(&g);
-  tw=owl_global_get_typwin(&g);
-
-  /* welcome message */
-  owl_function_debugmsg("startup: creating splash message");
-  owl_function_adminmsg("",
-    "-----------------------------------------------------------------------\n"
-    "Welcome to barnowl version " OWL_VERSION_STRING ".  Press 'h' for on-line help.\n"
-    "To see a quick introduction, type ':show quickstart'.                  \n"
-    "                                                                       \n"
-    "BarnOwl is free software. Type ':show license' for more                \n"
-    "information.                                                     ^ ^   \n"
-    "                                                                 OvO   \n"
-    "Please report any bugs or suggestions to bug-barnowl@mit.edu    (   )  \n"
-    "-----------------------------------------------------------------m-m---\n"
-  );
-  sepbar(NULL);
-
-  /* process the startup file */
-  owl_function_debugmsg("startup: processing startup file");
-  owl_function_source(NULL);
-
-  wrefresh(sepwin);
-
-  /* Set the default style */
-  owl_function_debugmsg("startup: setting startup and default style");
-  if (0 != strcmp(owl_global_get_default_style(&g), "__unspecified__")) {
-    /* the style was set by the user: leave it alone */
-  } else {
-    owl_global_set_default_style(&g, "default");
-  }
-
-  owl_function_debugmsg("startup: set style for the view: %s", owl_global_get_default_style(&g));
-  s = owl_global_get_style_by_name(&g, owl_global_get_default_style(&g));
-  if(s)
-      owl_view_set_style(owl_global_get_current_view(&g), s);
-  else
-      owl_function_error("No such style: %s", owl_global_get_default_style(&g));
-
-  owl_function_debugmsg("startup: setting context interactive");
-  owl_context_set_interactive(owl_global_get_context(&g));
-
-  nexttimediff=10;
-  nexttime=time(NULL);
-
-  owl_select_add_timer(180, 180, owl_zephyr_buddycheck_timer, NULL, NULL);
-
-  /* If we ever deprecate the mainloop hook, remove this. */
-  owl_select_add_timer(0, 1, owl_perlconfig_mainloop, NULL, NULL);
-
-  owl_function_debugmsg("startup: entering main loop");
-  /* main loop */
-  while (1) {
-
-    /* if a resize has been scheduled, deal with it */
-    owl_global_resize(&g, 0, 0);
-
-    /* these are here in case a resize changes the windows */
-    msgwin=owl_global_get_curs_msgwin(&g);
-    recwin=owl_global_get_curs_recwin(&g);
-    sepwin=owl_global_get_curs_sepwin(&g);
-    typwin=owl_global_get_curs_typwin(&g);
-
-    followlast=owl_global_should_followlast(&g);
-
-    /* little hack */
-    now=time(NULL);
-    today=localtime(&now);
-    if (today->tm_mon==9 && today->tm_mday==31 && owl_global_get_runtime(&g)<600) {
-      if (time(NULL)>nexttime) {
-	if (nexttimediff==1) {
-	  nexttimediff=10;
-	} else {
-	  nexttimediff=1;
-	}
-	nexttime+=nexttimediff;
-	owl_hack_animate();
-      }
-    }
-
-    /* Grab incoming messages. */
-    newmsgs=0;
-    while(owl_global_messagequeue_pending(&g)) {
-
-      m = owl_global_messagequeue_popmsg(&g);
-
-      if(owl_process_message(m))
-        newmsgs = 1;
-    }
-
-    /* follow the last message if we're supposed to */
-    if (newmsgs && followlast) {
-      owl_function_lastmsg_noredisplay();
-    }
-
-    /* do the newmsgproc thing */
-    if (newmsgs) {
-      owl_function_do_newmsgproc();
-    }
-    
-    /* redisplay if necessary */
-    /* this should be optimized to not run if the new messages won't be displayed */
-    if (newmsgs) {
-      owl_mainwin_redisplay(owl_global_get_mainwin(&g));
-      sepbar(NULL);
-      if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
-	owl_popwin_refresh(owl_global_get_popwin(&g));
-	/* TODO: this is a broken kludge */
-	if (owl_global_get_viewwin(&g)) {
-	  owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0);
-	}
-      }
-      owl_global_set_needrefresh(&g);
-    }
-
-    /* if a popwin just came up, refresh it */
-    pw=owl_global_get_popwin(&g);
-    if (owl_popwin_is_active(pw) && owl_popwin_needs_first_refresh(pw)) {
-      owl_popwin_refresh(pw);
-      owl_popwin_no_needs_first_refresh(pw);
-      owl_global_set_needrefresh(&g);
-      /* TODO: this is a broken kludge */
-      if (owl_global_get_viewwin(&g)) {
-	owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0);
-      }
-    }
-
-    /* update the terminal if we need to */
-    if (owl_global_is_needrefresh(&g)) {
-      /* leave the cursor in the appropriate window */
-      if (owl_global_is_typwin_active(&g)) {
-	owl_function_set_cursor(typwin);
-      } else {
-	owl_function_set_cursor(sepwin);
-      }
-      doupdate();
-      owl_global_set_noneedrefresh(&g);
-    }
-
-    /* Some calls into libzephyr call Z_WaitForNotice(), which has its
-     * own select loop and may leave zephyrs on the queue. Check for
-     * them now, and process any we find. */
-    owl_zephyr_process_events(NULL);
-
-    /* select on FDs we know about. */
-    owl_select();
-
-    /* Log any error signals */
-    {
-      siginfo_t si;
-      int signum;
-      if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) {
-	owl_function_error("Got unexpected signal: %d %s  (code: %d band: %ld  errno: %d)",
-			   signum, signum==SIGPIPE?"SIGPIPE":"SIG????",
-			   si.si_code, si.si_band, si.si_errno);
-      }
-    }
-
-  }
 }
 
@@ -659,16 +378,21 @@
 }
 
-void usage()
-{
-  fprintf(stderr, "Barnowl version %s\n", OWL_VERSION_STRING);
-  fprintf(stderr, "Usage: barnowl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-s <confdir>] [-t <ttyname>]\n");
-  fprintf(stderr, "  -n,--no-subs        don't load zephyr subscriptions\n");
-  fprintf(stderr, "  -d,--debug          enable debugging\n");
-  fprintf(stderr, "  -D,--remove-debug   enable debugging and delete previous debug file\n");
-  fprintf(stderr, "  -v,--version        print the Barnowl version number and exit\n");
-  fprintf(stderr, "  -h,--help           print this help message\n");
-  fprintf(stderr, "  -c,--config-file    specify an alternate config file\n");
-  fprintf(stderr, "  -s,--config-dir     specify an alternate config dir (default ~/.owl)\n");
-  fprintf(stderr, "  -t,--tty            set the tty name\n");
+void owl_register_signal_handlers(void) {
+  struct sigaction sigact;
+
+  /* signal handler */
+  /*sigact.sa_handler=sig_handler;*/
+  sigact.sa_sigaction=sig_handler;
+  sigemptyset(&sigact.sa_mask);
+  sigact.sa_flags=SA_SIGINFO;
+  sigaction(SIGWINCH, &sigact, NULL);
+  sigaction(SIGALRM, &sigact, NULL);
+  sigaction(SIGPIPE, &sigact, NULL);
+  sigaction(SIGTERM, &sigact, NULL);
+  sigaction(SIGHUP, &sigact, NULL);
+
+  sigact.sa_sigaction=sigint_handler;
+  sigaction(SIGINT, &sigact, NULL);
+
 }
 
@@ -731,2 +455,279 @@
   }
 }
+
+
+int main(int argc, char **argv, char **env)
+{
+  WINDOW *recwin, *sepwin, *typwin, *msgwin;
+  owl_editwin *tw;
+  owl_popwin *pw;
+  int argcsave, followlast;
+  int newmsgs, nexttimediff;
+  const char *const *argvsave;
+  char *perlout, *perlerr;
+  const owl_style *s;
+  time_t nexttime, now;
+  struct tm *today;
+  const char *dir;
+  owl_message *m;
+  owl_options opts;
+
+  if (!GLIB_CHECK_VERSION (2, 12, 0))
+    g_error ("GLib version 2.12.0 or above is needed.");
+
+  argcsave=argc;
+  argvsave=strs(argv);
+
+  setlocale(LC_ALL, "");
+
+  memset(&opts, 0, sizeof opts);
+  opts.load_initial_subs = 1;
+  owl_parse_options(argc, argv, &opts);
+  g.load_initial_subs = opts.load_initial_subs;
+
+  owl_function_debugmsg("startup: Finished parsing arguments");
+
+  owl_register_signal_handlers();
+  owl_start_curses();
+
+  /* owl global init */
+  owl_global_init(&g);
+  if (opts.rm_debug) unlink(OWL_DEBUG_FILE);
+  if (opts.debug) owl_global_set_debug_on(&g);
+  if (opts.confdir) owl_global_set_confdir(&g, opts.confdir);
+  owl_function_debugmsg("startup: first available debugging message");
+  owl_global_set_startupargs(&g, argcsave, argvsave);
+  owl_global_set_haveaim(&g);
+
+  /* prepare stdin dispatch */
+  {
+    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
+    d->fd = STDIN;
+    d->cfunc = &owl_process_input;
+    d->destroy = NULL;
+    owl_select_add_dispatch(d);
+  }
+
+  owl_zephyr_initialize();
+
+#if OWL_STDERR_REDIR
+  /* Do this only after we've started curses up... */
+  {
+    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
+    owl_function_debugmsg("startup: doing stderr redirection");
+    d->fd = stderr_replace();
+    d->cfunc = stderr_redirect_handler;
+    d->destroy = NULL;
+    owl_select_add_dispatch(d);
+  }
+#endif
+
+  /* create the owl directory, in case it does not exist */
+  owl_function_debugmsg("startup: creating owl directory, if not present");
+  dir=owl_global_get_confdir(&g);
+  mkdir(dir, S_IRWXU);
+
+  /* set the tty, either from the command line, or by figuring it out */
+  owl_function_debugmsg("startup: setting tty name");
+  if (opts.tty) {
+    owl_global_set_tty(&g, opts.tty);
+  } else {
+    owl_global_set_tty(&g, owl_util_get_default_tty());
+  }
+
+  /* Initialize perl */
+  owl_function_debugmsg("startup: processing config file");
+  owl_context_set_readconfig(owl_global_get_context(&g));
+  perlerr=owl_perlconfig_initperl(opts.configfile, &argc, &argv, &env);
+  if (perlerr) {
+    endwin();
+    fprintf(stderr, "Internal perl error: %s\n", perlerr);
+    fflush(stderr);
+    printf("Internal perl error: %s\n", perlerr);
+    fflush(stdout);
+    exit(1);
+  }
+
+  owl_global_complete_setup(&g);
+
+  owl_setup_default_filters();
+
+  /* set the current view */
+  owl_function_debugmsg("startup: setting the current view");
+  owl_view_create(owl_global_get_current_view(&g), "main",
+                  owl_global_get_filter(&g, "all"),
+                  owl_global_get_style_by_name(&g, "default"));
+
+  /* AIM init */
+  owl_function_debugmsg("startup: doing AIM initialization");
+  owl_aim_init();
+
+  /* execute the startup function in the configfile */
+  owl_function_debugmsg("startup: executing perl startup, if applicable");
+  perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();");
+  if (perlout) owl_free(perlout);
+
+  /* hold on to the window names for convenience */
+  msgwin=owl_global_get_curs_msgwin(&g);
+  recwin=owl_global_get_curs_recwin(&g);
+  sepwin=owl_global_get_curs_sepwin(&g);
+  typwin=owl_global_get_curs_typwin(&g);
+  tw=owl_global_get_typwin(&g);
+
+  /* welcome message */
+  owl_function_debugmsg("startup: creating splash message");
+  owl_function_adminmsg("",
+    "-----------------------------------------------------------------------\n"
+    "Welcome to barnowl version " OWL_VERSION_STRING ".  Press 'h' for on-line help.\n"
+    "To see a quick introduction, type ':show quickstart'.                  \n"
+    "                                                                       \n"
+    "BarnOwl is free software. Type ':show license' for more                \n"
+    "information.                                                     ^ ^   \n"
+    "                                                                 OvO   \n"
+    "Please report any bugs or suggestions to bug-barnowl@mit.edu    (   )  \n"
+    "-----------------------------------------------------------------m-m---\n"
+  );
+  sepbar(NULL);
+
+  /* process the startup file */
+  owl_function_debugmsg("startup: processing startup file");
+  owl_function_source(NULL);
+
+  wrefresh(sepwin);
+
+  /* Set the default style */
+  owl_function_debugmsg("startup: setting startup and default style");
+  if (0 != strcmp(owl_global_get_default_style(&g), "__unspecified__")) {
+    /* the style was set by the user: leave it alone */
+  } else {
+    owl_global_set_default_style(&g, "default");
+  }
+
+  owl_function_debugmsg("startup: set style for the view: %s", owl_global_get_default_style(&g));
+  s = owl_global_get_style_by_name(&g, owl_global_get_default_style(&g));
+  if(s)
+      owl_view_set_style(owl_global_get_current_view(&g), s);
+  else
+      owl_function_error("No such style: %s", owl_global_get_default_style(&g));
+
+  owl_function_debugmsg("startup: setting context interactive");
+  owl_context_set_interactive(owl_global_get_context(&g));
+
+  nexttimediff=10;
+  nexttime=time(NULL);
+
+  owl_select_add_timer(180, 180, owl_zephyr_buddycheck_timer, NULL, NULL);
+
+  /* If we ever deprecate the mainloop hook, remove this. */
+  owl_select_add_timer(0, 1, owl_perlconfig_mainloop, NULL, NULL);
+
+  owl_function_debugmsg("startup: entering main loop");
+  /* main loop */
+  while (1) {
+
+    /* if a resize has been scheduled, deal with it */
+    owl_global_resize(&g, 0, 0);
+
+    /* these are here in case a resize changes the windows */
+    msgwin=owl_global_get_curs_msgwin(&g);
+    recwin=owl_global_get_curs_recwin(&g);
+    sepwin=owl_global_get_curs_sepwin(&g);
+    typwin=owl_global_get_curs_typwin(&g);
+
+    followlast=owl_global_should_followlast(&g);
+
+    /* little hack */
+    now=time(NULL);
+    today=localtime(&now);
+    if (today->tm_mon==9 && today->tm_mday==31 && owl_global_get_runtime(&g)<600) {
+      if (time(NULL)>nexttime) {
+	if (nexttimediff==1) {
+	  nexttimediff=10;
+	} else {
+	  nexttimediff=1;
+	}
+	nexttime+=nexttimediff;
+	owl_hack_animate();
+      }
+    }
+
+    /* Grab incoming messages. */
+    newmsgs=0;
+    while(owl_global_messagequeue_pending(&g)) {
+
+      m = owl_global_messagequeue_popmsg(&g);
+
+      if(owl_process_message(m))
+        newmsgs = 1;
+    }
+
+    /* follow the last message if we're supposed to */
+    if (newmsgs && followlast) {
+      owl_function_lastmsg_noredisplay();
+    }
+
+    /* do the newmsgproc thing */
+    if (newmsgs) {
+      owl_function_do_newmsgproc();
+    }
+    
+    /* redisplay if necessary */
+    /* this should be optimized to not run if the new messages won't be displayed */
+    if (newmsgs) {
+      owl_mainwin_redisplay(owl_global_get_mainwin(&g));
+      sepbar(NULL);
+      if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
+	owl_popwin_refresh(owl_global_get_popwin(&g));
+	/* TODO: this is a broken kludge */
+	if (owl_global_get_viewwin(&g)) {
+	  owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0);
+	}
+      }
+      owl_global_set_needrefresh(&g);
+    }
+
+    /* if a popwin just came up, refresh it */
+    pw=owl_global_get_popwin(&g);
+    if (owl_popwin_is_active(pw) && owl_popwin_needs_first_refresh(pw)) {
+      owl_popwin_refresh(pw);
+      owl_popwin_no_needs_first_refresh(pw);
+      owl_global_set_needrefresh(&g);
+      /* TODO: this is a broken kludge */
+      if (owl_global_get_viewwin(&g)) {
+	owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0);
+      }
+    }
+
+    /* update the terminal if we need to */
+    if (owl_global_is_needrefresh(&g)) {
+      /* leave the cursor in the appropriate window */
+      if (owl_global_is_typwin_active(&g)) {
+	owl_function_set_cursor(typwin);
+      } else {
+	owl_function_set_cursor(sepwin);
+      }
+      doupdate();
+      owl_global_set_noneedrefresh(&g);
+    }
+
+    /* Some calls into libzephyr call Z_WaitForNotice(), which has its
+     * own select loop and may leave zephyrs on the queue. Check for
+     * them now, and process any we find. */
+    owl_zephyr_process_events(NULL);
+
+    /* select on FDs we know about. */
+    owl_select();
+
+    /* Log any error signals */
+    {
+      siginfo_t si;
+      int signum;
+      if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) {
+	owl_function_error("Got unexpected signal: %d %s  (code: %d band: %ld  errno: %d)",
+			   signum, signum==SIGPIPE?"SIGPIPE":"SIG????",
+			   si.si_code, si.si_band, si.si_errno);
+      }
+    }
+
+  }
+}
