Changeset 4e4847c


Ignore:
Timestamp:
Sep 14, 2009, 9:19:08 AM (11 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
3d9f4d3
Parents:
f350fc3
git-author:
Nelson Elhage <nelhage@mit.edu> (09/14/09 09:16:16)
git-committer:
Nelson Elhage <nelhage@mit.edu> (09/14/09 09:19:08)
Message:
Don't include owl.c when running codelist.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • codelist.pl

    r0982901 r4e4847c  
    88
    99foreach $file (@ARGV) {
    10     next if $file eq 'perlglue.c';
     10    next if $file eq 'perlglue.c' || $file eq 'owl.c';
    1111    open(FILE, $file);
    1212
  • owl.c

    rf350fc3 r4e4847c  
    3737owl_global g;
    3838
    39 typedef struct _owl_options {           /* noproto */
     39typedef struct _owl_options {
    4040  bool load_initial_subs;
    4141  char *configfile;
     
    4646} owl_options;
    4747
     48void usage()
     49{
     50  fprintf(stderr, "Barnowl version %s\n", OWL_VERSION_STRING);
     51  fprintf(stderr, "Usage: barnowl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-s <confdir>] [-t <ttyname>]\n");
     52  fprintf(stderr, "  -n,--no-subs        don't load zephyr subscriptions\n");
     53  fprintf(stderr, "  -d,--debug          enable debugging\n");
     54  fprintf(stderr, "  -D,--remove-debug   enable debugging and delete previous debug file\n");
     55  fprintf(stderr, "  -v,--version        print the Barnowl version number and exit\n");
     56  fprintf(stderr, "  -h,--help           print this help message\n");
     57  fprintf(stderr, "  -c,--config-file    specify an alternate config file\n");
     58  fprintf(stderr, "  -s,--config-dir     specify an alternate config dir (default ~/.owl)\n");
     59  fprintf(stderr, "  -t,--tty            set the tty name\n");
     60}
     61
    4862/* TODO: free owl_options after init is done? */
    49 void owl_parse_options(int argc, char *argv[], owl_options *opts) /* noproto */ {
     63void owl_parse_options(int argc, char *argv[], owl_options *opts) {
    5064  static const struct option long_options[] = {
    5165    { "no-subs",         0, 0, 'n' },
     
    93107}
    94108
    95 void owl_register_signal_handlers(void) /* noproto */ {
    96   struct sigaction sigact;
    97 
    98   /* signal handler */
    99   /*sigact.sa_handler=sig_handler;*/
    100   sigact.sa_sigaction=sig_handler;
    101   sigemptyset(&sigact.sa_mask);
    102   sigact.sa_flags=SA_SIGINFO;
    103   sigaction(SIGWINCH, &sigact, NULL);
    104   sigaction(SIGALRM, &sigact, NULL);
    105   sigaction(SIGPIPE, &sigact, NULL);
    106   sigaction(SIGTERM, &sigact, NULL);
    107   sigaction(SIGHUP, &sigact, NULL);
    108 
    109   sigact.sa_sigaction=sigint_handler;
    110   sigaction(SIGINT, &sigact, NULL);
    111 
    112 }
    113 
    114 void owl_start_color(void) /* noproto */ {
     109void owl_start_color(void) {
    115110  start_color();
    116111#ifdef HAVE_USE_DEFAULT_COLORS
     
    135130}
    136131
    137 void owl_start_curses(void) /* noproto */ {
     132void owl_start_curses(void) {
    138133  struct termios tio;
    139134  /* save initial terminal settings */
     
    154149}
    155150
    156 void owl_setup_default_filters(void) /* noproto */ {
     151void owl_setup_default_filters(void) {
    157152  owl_filter *f;
    158153
     
    206201  owl_filter_init_fromstring(f, "all", "true");
    207202  owl_list_append_element(owl_global_get_filterlist(&g), f);
    208 }
    209 
    210 int main(int argc, char **argv, char **env)
    211 {
    212   WINDOW *recwin, *sepwin, *typwin, *msgwin;
    213   owl_editwin *tw;
    214   owl_popwin *pw;
    215   int argcsave, followlast;
    216   int newmsgs, nexttimediff;
    217   const char *const *argvsave;
    218   char *perlout, *perlerr;
    219   const owl_style *s;
    220   time_t nexttime, now;
    221   struct tm *today;
    222   const char *dir;
    223   owl_message *m;
    224   owl_options opts;
    225 
    226   if (!GLIB_CHECK_VERSION (2, 12, 0))
    227     g_error ("GLib version 2.12.0 or above is needed.");
    228 
    229   argcsave=argc;
    230   argvsave=strs(argv);
    231 
    232   setlocale(LC_ALL, "");
    233 
    234   memset(&opts, 0, sizeof opts);
    235   opts.load_initial_subs = 1;
    236   owl_parse_options(argc, argv, &opts);
    237   g.load_initial_subs = opts.load_initial_subs;
    238 
    239   owl_function_debugmsg("startup: Finished parsing arguments");
    240 
    241   owl_register_signal_handlers();
    242   owl_start_curses();
    243 
    244   /* owl global init */
    245   owl_global_init(&g);
    246   if (opts.rm_debug) unlink(OWL_DEBUG_FILE);
    247   if (opts.debug) owl_global_set_debug_on(&g);
    248   if (opts.confdir) owl_global_set_confdir(&g, opts.confdir);
    249   owl_function_debugmsg("startup: first available debugging message");
    250   owl_global_set_startupargs(&g, argcsave, argvsave);
    251   owl_global_set_haveaim(&g);
    252 
    253   /* prepare stdin dispatch */
    254   {
    255     owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
    256     d->fd = STDIN;
    257     d->cfunc = &owl_process_input;
    258     d->destroy = NULL;
    259     owl_select_add_dispatch(d);
    260   }
    261 
    262   owl_zephyr_initialize();
    263 
    264 #if OWL_STDERR_REDIR
    265   /* Do this only after we've started curses up... */
    266   {
    267     owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
    268     owl_function_debugmsg("startup: doing stderr redirection");
    269     d->fd = stderr_replace();
    270     d->cfunc = stderr_redirect_handler;
    271     d->destroy = NULL;
    272     owl_select_add_dispatch(d);
    273   }
    274 #endif
    275 
    276   /* create the owl directory, in case it does not exist */
    277   owl_function_debugmsg("startup: creating owl directory, if not present");
    278   dir=owl_global_get_confdir(&g);
    279   mkdir(dir, S_IRWXU);
    280 
    281   /* set the tty, either from the command line, or by figuring it out */
    282   owl_function_debugmsg("startup: setting tty name");
    283   if (opts.tty) {
    284     owl_global_set_tty(&g, opts.tty);
    285   } else {
    286     owl_global_set_tty(&g, owl_util_get_default_tty());
    287   }
    288 
    289   /* Initialize perl */
    290   owl_function_debugmsg("startup: processing config file");
    291   owl_context_set_readconfig(owl_global_get_context(&g));
    292   perlerr=owl_perlconfig_initperl(opts.configfile, &argc, &argv, &env);
    293   if (perlerr) {
    294     endwin();
    295     fprintf(stderr, "Internal perl error: %s\n", perlerr);
    296     fflush(stderr);
    297     printf("Internal perl error: %s\n", perlerr);
    298     fflush(stdout);
    299     exit(1);
    300   }
    301 
    302   owl_global_complete_setup(&g);
    303 
    304   owl_setup_default_filters();
    305 
    306   /* set the current view */
    307   owl_function_debugmsg("startup: setting the current view");
    308   owl_view_create(owl_global_get_current_view(&g), "main",
    309                   owl_global_get_filter(&g, "all"),
    310                   owl_global_get_style_by_name(&g, "default"));
    311 
    312   /* AIM init */
    313   owl_function_debugmsg("startup: doing AIM initialization");
    314   owl_aim_init();
    315 
    316   /* execute the startup function in the configfile */
    317   owl_function_debugmsg("startup: executing perl startup, if applicable");
    318   perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();");
    319   if (perlout) owl_free(perlout);
    320 
    321   /* hold on to the window names for convenience */
    322   msgwin=owl_global_get_curs_msgwin(&g);
    323   recwin=owl_global_get_curs_recwin(&g);
    324   sepwin=owl_global_get_curs_sepwin(&g);
    325   typwin=owl_global_get_curs_typwin(&g);
    326   tw=owl_global_get_typwin(&g);
    327 
    328   /* welcome message */
    329   owl_function_debugmsg("startup: creating splash message");
    330   owl_function_adminmsg("",
    331     "-----------------------------------------------------------------------\n"
    332     "Welcome to barnowl version " OWL_VERSION_STRING ".  Press 'h' for on-line help.\n"
    333     "To see a quick introduction, type ':show quickstart'.                  \n"
    334     "                                                                       \n"
    335     "BarnOwl is free software. Type ':show license' for more                \n"
    336     "information.                                                     ^ ^   \n"
    337     "                                                                 OvO   \n"
    338     "Please report any bugs or suggestions to bug-barnowl@mit.edu    (   )  \n"
    339     "-----------------------------------------------------------------m-m---\n"
    340   );
    341   sepbar(NULL);
    342 
    343   /* process the startup file */
    344   owl_function_debugmsg("startup: processing startup file");
    345   owl_function_source(NULL);
    346 
    347   wrefresh(sepwin);
    348 
    349   /* Set the default style */
    350   owl_function_debugmsg("startup: setting startup and default style");
    351   if (0 != strcmp(owl_global_get_default_style(&g), "__unspecified__")) {
    352     /* the style was set by the user: leave it alone */
    353   } else {
    354     owl_global_set_default_style(&g, "default");
    355   }
    356 
    357   owl_function_debugmsg("startup: set style for the view: %s", owl_global_get_default_style(&g));
    358   s = owl_global_get_style_by_name(&g, owl_global_get_default_style(&g));
    359   if(s)
    360       owl_view_set_style(owl_global_get_current_view(&g), s);
    361   else
    362       owl_function_error("No such style: %s", owl_global_get_default_style(&g));
    363 
    364   owl_function_debugmsg("startup: setting context interactive");
    365   owl_context_set_interactive(owl_global_get_context(&g));
    366 
    367   nexttimediff=10;
    368   nexttime=time(NULL);
    369 
    370   owl_select_add_timer(180, 180, owl_zephyr_buddycheck_timer, NULL, NULL);
    371 
    372   /* If we ever deprecate the mainloop hook, remove this. */
    373   owl_select_add_timer(0, 1, owl_perlconfig_mainloop, NULL, NULL);
    374 
    375   owl_function_debugmsg("startup: entering main loop");
    376   /* main loop */
    377   while (1) {
    378 
    379     /* if a resize has been scheduled, deal with it */
    380     owl_global_resize(&g, 0, 0);
    381 
    382     /* these are here in case a resize changes the windows */
    383     msgwin=owl_global_get_curs_msgwin(&g);
    384     recwin=owl_global_get_curs_recwin(&g);
    385     sepwin=owl_global_get_curs_sepwin(&g);
    386     typwin=owl_global_get_curs_typwin(&g);
    387 
    388     followlast=owl_global_should_followlast(&g);
    389 
    390     /* little hack */
    391     now=time(NULL);
    392     today=localtime(&now);
    393     if (today->tm_mon==9 && today->tm_mday==31 && owl_global_get_runtime(&g)<600) {
    394       if (time(NULL)>nexttime) {
    395         if (nexttimediff==1) {
    396           nexttimediff=10;
    397         } else {
    398           nexttimediff=1;
    399         }
    400         nexttime+=nexttimediff;
    401         owl_hack_animate();
    402       }
    403     }
    404 
    405     /* Grab incoming messages. */
    406     newmsgs=0;
    407     while(owl_global_messagequeue_pending(&g)) {
    408 
    409       m = owl_global_messagequeue_popmsg(&g);
    410 
    411       if(owl_process_message(m))
    412         newmsgs = 1;
    413     }
    414 
    415     /* follow the last message if we're supposed to */
    416     if (newmsgs && followlast) {
    417       owl_function_lastmsg_noredisplay();
    418     }
    419 
    420     /* do the newmsgproc thing */
    421     if (newmsgs) {
    422       owl_function_do_newmsgproc();
    423     }
    424    
    425     /* redisplay if necessary */
    426     /* this should be optimized to not run if the new messages won't be displayed */
    427     if (newmsgs) {
    428       owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    429       sepbar(NULL);
    430       if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
    431         owl_popwin_refresh(owl_global_get_popwin(&g));
    432         /* TODO: this is a broken kludge */
    433         if (owl_global_get_viewwin(&g)) {
    434           owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0);
    435         }
    436       }
    437       owl_global_set_needrefresh(&g);
    438     }
    439 
    440     /* if a popwin just came up, refresh it */
    441     pw=owl_global_get_popwin(&g);
    442     if (owl_popwin_is_active(pw) && owl_popwin_needs_first_refresh(pw)) {
    443       owl_popwin_refresh(pw);
    444       owl_popwin_no_needs_first_refresh(pw);
    445       owl_global_set_needrefresh(&g);
    446       /* TODO: this is a broken kludge */
    447       if (owl_global_get_viewwin(&g)) {
    448         owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0);
    449       }
    450     }
    451 
    452     /* update the terminal if we need to */
    453     if (owl_global_is_needrefresh(&g)) {
    454       /* leave the cursor in the appropriate window */
    455       if (owl_global_is_typwin_active(&g)) {
    456         owl_function_set_cursor(typwin);
    457       } else {
    458         owl_function_set_cursor(sepwin);
    459       }
    460       doupdate();
    461       owl_global_set_noneedrefresh(&g);
    462     }
    463 
    464     /* Some calls into libzephyr call Z_WaitForNotice(), which has its
    465      * own select loop and may leave zephyrs on the queue. Check for
    466      * them now, and process any we find. */
    467     owl_zephyr_process_events(NULL);
    468 
    469     /* select on FDs we know about. */
    470     owl_select();
    471 
    472     /* Log any error signals */
    473     {
    474       siginfo_t si;
    475       int signum;
    476       if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) {
    477         owl_function_error("Got unexpected signal: %d %s  (code: %d band: %ld  errno: %d)",
    478                            signum, signum==SIGPIPE?"SIGPIPE":"SIG????",
    479                            si.si_code, si.si_band, si.si_errno);
    480       }
    481     }
    482 
    483   }
    484203}
    485204
     
    659378}
    660379
    661 void usage()
    662 {
    663   fprintf(stderr, "Barnowl version %s\n", OWL_VERSION_STRING);
    664   fprintf(stderr, "Usage: barnowl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-s <confdir>] [-t <ttyname>]\n");
    665   fprintf(stderr, "  -n,--no-subs        don't load zephyr subscriptions\n");
    666   fprintf(stderr, "  -d,--debug          enable debugging\n");
    667   fprintf(stderr, "  -D,--remove-debug   enable debugging and delete previous debug file\n");
    668   fprintf(stderr, "  -v,--version        print the Barnowl version number and exit\n");
    669   fprintf(stderr, "  -h,--help           print this help message\n");
    670   fprintf(stderr, "  -c,--config-file    specify an alternate config file\n");
    671   fprintf(stderr, "  -s,--config-dir     specify an alternate config dir (default ~/.owl)\n");
    672   fprintf(stderr, "  -t,--tty            set the tty name\n");
     380void owl_register_signal_handlers(void) {
     381  struct sigaction sigact;
     382
     383  /* signal handler */
     384  /*sigact.sa_handler=sig_handler;*/
     385  sigact.sa_sigaction=sig_handler;
     386  sigemptyset(&sigact.sa_mask);
     387  sigact.sa_flags=SA_SIGINFO;
     388  sigaction(SIGWINCH, &sigact, NULL);
     389  sigaction(SIGALRM, &sigact, NULL);
     390  sigaction(SIGPIPE, &sigact, NULL);
     391  sigaction(SIGTERM, &sigact, NULL);
     392  sigaction(SIGHUP, &sigact, NULL);
     393
     394  sigact.sa_sigaction=sigint_handler;
     395  sigaction(SIGINT, &sigact, NULL);
     396
    673397}
    674398
     
    731455  }
    732456}
     457
     458
     459int main(int argc, char **argv, char **env)
     460{
     461  WINDOW *recwin, *sepwin, *typwin, *msgwin;
     462  owl_editwin *tw;
     463  owl_popwin *pw;
     464  int argcsave, followlast;
     465  int newmsgs, nexttimediff;
     466  const char *const *argvsave;
     467  char *perlout, *perlerr;
     468  const owl_style *s;
     469  time_t nexttime, now;
     470  struct tm *today;
     471  const char *dir;
     472  owl_message *m;
     473  owl_options opts;
     474
     475  if (!GLIB_CHECK_VERSION (2, 12, 0))
     476    g_error ("GLib version 2.12.0 or above is needed.");
     477
     478  argcsave=argc;
     479  argvsave=strs(argv);
     480
     481  setlocale(LC_ALL, "");
     482
     483  memset(&opts, 0, sizeof opts);
     484  opts.load_initial_subs = 1;
     485  owl_parse_options(argc, argv, &opts);
     486  g.load_initial_subs = opts.load_initial_subs;
     487
     488  owl_function_debugmsg("startup: Finished parsing arguments");
     489
     490  owl_register_signal_handlers();
     491  owl_start_curses();
     492
     493  /* owl global init */
     494  owl_global_init(&g);
     495  if (opts.rm_debug) unlink(OWL_DEBUG_FILE);
     496  if (opts.debug) owl_global_set_debug_on(&g);
     497  if (opts.confdir) owl_global_set_confdir(&g, opts.confdir);
     498  owl_function_debugmsg("startup: first available debugging message");
     499  owl_global_set_startupargs(&g, argcsave, argvsave);
     500  owl_global_set_haveaim(&g);
     501
     502  /* prepare stdin dispatch */
     503  {
     504    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
     505    d->fd = STDIN;
     506    d->cfunc = &owl_process_input;
     507    d->destroy = NULL;
     508    owl_select_add_dispatch(d);
     509  }
     510
     511  owl_zephyr_initialize();
     512
     513#if OWL_STDERR_REDIR
     514  /* Do this only after we've started curses up... */
     515  {
     516    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
     517    owl_function_debugmsg("startup: doing stderr redirection");
     518    d->fd = stderr_replace();
     519    d->cfunc = stderr_redirect_handler;
     520    d->destroy = NULL;
     521    owl_select_add_dispatch(d);
     522  }
     523#endif
     524
     525  /* create the owl directory, in case it does not exist */
     526  owl_function_debugmsg("startup: creating owl directory, if not present");
     527  dir=owl_global_get_confdir(&g);
     528  mkdir(dir, S_IRWXU);
     529
     530  /* set the tty, either from the command line, or by figuring it out */
     531  owl_function_debugmsg("startup: setting tty name");
     532  if (opts.tty) {
     533    owl_global_set_tty(&g, opts.tty);
     534  } else {
     535    owl_global_set_tty(&g, owl_util_get_default_tty());
     536  }
     537
     538  /* Initialize perl */
     539  owl_function_debugmsg("startup: processing config file");
     540  owl_context_set_readconfig(owl_global_get_context(&g));
     541  perlerr=owl_perlconfig_initperl(opts.configfile, &argc, &argv, &env);
     542  if (perlerr) {
     543    endwin();
     544    fprintf(stderr, "Internal perl error: %s\n", perlerr);
     545    fflush(stderr);
     546    printf("Internal perl error: %s\n", perlerr);
     547    fflush(stdout);
     548    exit(1);
     549  }
     550
     551  owl_global_complete_setup(&g);
     552
     553  owl_setup_default_filters();
     554
     555  /* set the current view */
     556  owl_function_debugmsg("startup: setting the current view");
     557  owl_view_create(owl_global_get_current_view(&g), "main",
     558                  owl_global_get_filter(&g, "all"),
     559                  owl_global_get_style_by_name(&g, "default"));
     560
     561  /* AIM init */
     562  owl_function_debugmsg("startup: doing AIM initialization");
     563  owl_aim_init();
     564
     565  /* execute the startup function in the configfile */
     566  owl_function_debugmsg("startup: executing perl startup, if applicable");
     567  perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();");
     568  if (perlout) owl_free(perlout);
     569
     570  /* hold on to the window names for convenience */
     571  msgwin=owl_global_get_curs_msgwin(&g);
     572  recwin=owl_global_get_curs_recwin(&g);
     573  sepwin=owl_global_get_curs_sepwin(&g);
     574  typwin=owl_global_get_curs_typwin(&g);
     575  tw=owl_global_get_typwin(&g);
     576
     577  /* welcome message */
     578  owl_function_debugmsg("startup: creating splash message");
     579  owl_function_adminmsg("",
     580    "-----------------------------------------------------------------------\n"
     581    "Welcome to barnowl version " OWL_VERSION_STRING ".  Press 'h' for on-line help.\n"
     582    "To see a quick introduction, type ':show quickstart'.                  \n"
     583    "                                                                       \n"
     584    "BarnOwl is free software. Type ':show license' for more                \n"
     585    "information.                                                     ^ ^   \n"
     586    "                                                                 OvO   \n"
     587    "Please report any bugs or suggestions to bug-barnowl@mit.edu    (   )  \n"
     588    "-----------------------------------------------------------------m-m---\n"
     589  );
     590  sepbar(NULL);
     591
     592  /* process the startup file */
     593  owl_function_debugmsg("startup: processing startup file");
     594  owl_function_source(NULL);
     595
     596  wrefresh(sepwin);
     597
     598  /* Set the default style */
     599  owl_function_debugmsg("startup: setting startup and default style");
     600  if (0 != strcmp(owl_global_get_default_style(&g), "__unspecified__")) {
     601    /* the style was set by the user: leave it alone */
     602  } else {
     603    owl_global_set_default_style(&g, "default");
     604  }
     605
     606  owl_function_debugmsg("startup: set style for the view: %s", owl_global_get_default_style(&g));
     607  s = owl_global_get_style_by_name(&g, owl_global_get_default_style(&g));
     608  if(s)
     609      owl_view_set_style(owl_global_get_current_view(&g), s);
     610  else
     611      owl_function_error("No such style: %s", owl_global_get_default_style(&g));
     612
     613  owl_function_debugmsg("startup: setting context interactive");
     614  owl_context_set_interactive(owl_global_get_context(&g));
     615
     616  nexttimediff=10;
     617  nexttime=time(NULL);
     618
     619  owl_select_add_timer(180, 180, owl_zephyr_buddycheck_timer, NULL, NULL);
     620
     621  /* If we ever deprecate the mainloop hook, remove this. */
     622  owl_select_add_timer(0, 1, owl_perlconfig_mainloop, NULL, NULL);
     623
     624  owl_function_debugmsg("startup: entering main loop");
     625  /* main loop */
     626  while (1) {
     627
     628    /* if a resize has been scheduled, deal with it */
     629    owl_global_resize(&g, 0, 0);
     630
     631    /* these are here in case a resize changes the windows */
     632    msgwin=owl_global_get_curs_msgwin(&g);
     633    recwin=owl_global_get_curs_recwin(&g);
     634    sepwin=owl_global_get_curs_sepwin(&g);
     635    typwin=owl_global_get_curs_typwin(&g);
     636
     637    followlast=owl_global_should_followlast(&g);
     638
     639    /* little hack */
     640    now=time(NULL);
     641    today=localtime(&now);
     642    if (today->tm_mon==9 && today->tm_mday==31 && owl_global_get_runtime(&g)<600) {
     643      if (time(NULL)>nexttime) {
     644        if (nexttimediff==1) {
     645          nexttimediff=10;
     646        } else {
     647          nexttimediff=1;
     648        }
     649        nexttime+=nexttimediff;
     650        owl_hack_animate();
     651      }
     652    }
     653
     654    /* Grab incoming messages. */
     655    newmsgs=0;
     656    while(owl_global_messagequeue_pending(&g)) {
     657
     658      m = owl_global_messagequeue_popmsg(&g);
     659
     660      if(owl_process_message(m))
     661        newmsgs = 1;
     662    }
     663
     664    /* follow the last message if we're supposed to */
     665    if (newmsgs && followlast) {
     666      owl_function_lastmsg_noredisplay();
     667    }
     668
     669    /* do the newmsgproc thing */
     670    if (newmsgs) {
     671      owl_function_do_newmsgproc();
     672    }
     673   
     674    /* redisplay if necessary */
     675    /* this should be optimized to not run if the new messages won't be displayed */
     676    if (newmsgs) {
     677      owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     678      sepbar(NULL);
     679      if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
     680        owl_popwin_refresh(owl_global_get_popwin(&g));
     681        /* TODO: this is a broken kludge */
     682        if (owl_global_get_viewwin(&g)) {
     683          owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0);
     684        }
     685      }
     686      owl_global_set_needrefresh(&g);
     687    }
     688
     689    /* if a popwin just came up, refresh it */
     690    pw=owl_global_get_popwin(&g);
     691    if (owl_popwin_is_active(pw) && owl_popwin_needs_first_refresh(pw)) {
     692      owl_popwin_refresh(pw);
     693      owl_popwin_no_needs_first_refresh(pw);
     694      owl_global_set_needrefresh(&g);
     695      /* TODO: this is a broken kludge */
     696      if (owl_global_get_viewwin(&g)) {
     697        owl_viewwin_redisplay(owl_global_get_viewwin(&g), 0);
     698      }
     699    }
     700
     701    /* update the terminal if we need to */
     702    if (owl_global_is_needrefresh(&g)) {
     703      /* leave the cursor in the appropriate window */
     704      if (owl_global_is_typwin_active(&g)) {
     705        owl_function_set_cursor(typwin);
     706      } else {
     707        owl_function_set_cursor(sepwin);
     708      }
     709      doupdate();
     710      owl_global_set_noneedrefresh(&g);
     711    }
     712
     713    /* Some calls into libzephyr call Z_WaitForNotice(), which has its
     714     * own select loop and may leave zephyrs on the queue. Check for
     715     * them now, and process any we find. */
     716    owl_zephyr_process_events(NULL);
     717
     718    /* select on FDs we know about. */
     719    owl_select();
     720
     721    /* Log any error signals */
     722    {
     723      siginfo_t si;
     724      int signum;
     725      if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) {
     726        owl_function_error("Got unexpected signal: %d %s  (code: %d band: %ld  errno: %d)",
     727                           signum, signum==SIGPIPE?"SIGPIPE":"SIG????",
     728                           si.si_code, si.si_band, si.si_errno);
     729      }
     730    }
     731
     732  }
     733}
Note: See TracChangeset for help on using the changeset viewer.