예제 #1
0
파일: logging.c 프로젝트: andersk/barnowl
/* This is now the one function that should be called to log a
 * message.  It will do all the work necessary by calling the other
 * functions in this file as necessary.
 */
void owl_log_message(const owl_message *m) {
  owl_function_debugmsg("owl_log_message: entering");

  if (m == NULL) {
    owl_function_debugmsg("owl_log_message: passed null message");
    return;
  }

  /* should we be logging this message? */
  if (!owl_log_shouldlog_message(m)) {
    owl_function_debugmsg("owl_log_message: not logging message");
    return;
  }

  /* handle incmoing messages */
  if (owl_message_is_direction_in(m)) {
    owl_log_incoming(m);
    owl_function_debugmsg("owl_log_message: leaving");
    return;
  }

  /* handle outgoing messages */
  owl_log_outgoing(m);

  owl_function_debugmsg("owl_log_message: leaving");
}
예제 #2
0
파일: zephyr.c 프로젝트: arlynap/barnowl
void owl_zephyr_load_initial_subs() {
  int ret_sd, ret_bd, ret_u;

  owl_function_debugmsg("startup: loading initial zephyr subs");

  /* load default subscriptions */
  ret_sd = owl_zephyr_loaddefaultsubs();

  /* load Barnowl default subscriptions */
  ret_bd = owl_zephyr_loadbarnowldefaultsubs();

  /* load subscriptions from subs file */
  ret_u = owl_zephyr_loadsubs(NULL, 0);

  if (ret_sd || ret_bd || ret_u) {
    owl_function_error("Error loading zephyr subscriptions");
  } else if (ret_u!=-1) {
    owl_global_add_userclue(&g, OWL_USERCLUE_CLASSES);
  }

  /* load login subscriptions */
  if (owl_global_is_loginsubs(&g)) {
    owl_function_debugmsg("startup: loading login subs");
    owl_function_loadloginsubs(NULL);
  }
}
예제 #3
0
파일: zephyr.c 프로젝트: aglasgall/barnowl
void owl_zephyr_finish_initialization(const owl_io_dispatch *d, void *data) {
  Code_t code;
  char *perl;
  GSource *event_source;

  owl_select_remove_io_dispatch(d);

  ZClosePort();

  if ((code = ZInitialize()) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(code));
    return;
  }

  if ((code = ZOpenPort(NULL)) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(code));
    return;
  }

  event_source = owl_zephyr_event_source_new(ZGetFD());
  g_source_attach(event_source, NULL);
  g_source_unref(event_source);

  owl_global_set_havezephyr(&g);

  if(g.load_initial_subs) {
    owl_zephyr_load_initial_subs();
  }
  while(deferred_subs != NULL) {
    owl_sub_list *subs = deferred_subs->data;
    owl_function_debugmsg("Loading %d deferred subs.", subs->nsubs);
    owl_zephyr_loadsubs_helper(subs->subs, subs->nsubs);
    deferred_subs = g_list_delete_link(deferred_subs, deferred_subs);
    g_free(subs);
  }

  /* zlog in if we need to */
  if (owl_global_is_startuplogin(&g)) {
    owl_function_debugmsg("startup: doing zlog in");
    owl_zephyr_zlog_in();
  }
  /* check pseudo-logins if we need to */
  if (owl_global_is_pseudologins(&g)) {
    owl_function_debugmsg("startup: checking pseudo-logins");
    owl_function_zephyr_buddy_check(0);
  }

  perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()");
  g_free(perl);
}
예제 #4
0
파일: owl.c 프로젝트: aglasgall/barnowl
/* Replaces stderr with a pipe so that we can read from it. 
 * Returns the fd of the pipe from which stderr can be read. */
int stderr_replace(void)
{
  int pipefds[2];
  if (0 != pipe(pipefds)) {
    perror("pipe");
    owl_function_debugmsg("stderr_replace: pipe FAILED\n");
    return -1;
  }
    owl_function_debugmsg("stderr_replace: pipe: %d,%d\n", pipefds[0], pipefds[1]);
  if (-1 == dup2(pipefds[1], 2 /*stderr*/)) {
    owl_function_debugmsg("stderr_replace: dup2 FAILED (%s)\n", strerror(errno));
    perror("dup2");
    return -1;
  }
  return pipefds[0];
}
예제 #5
0
/* sets up a new keybinding for a command */
CALLER_OWN owl_keybinding *owl_keybinding_new(const char *keyseq, const char *command, void (*function_fn)(void), const char *desc)
{
  owl_keybinding *kb = g_new(owl_keybinding, 1);

  owl_function_debugmsg("owl_keybinding_init: creating binding for <%s> with desc: <%s>", keyseq, desc);
  if (command && function_fn) {
    g_free(kb);
    return NULL;
  } else if (command && !function_fn) {
    kb->type = OWL_KEYBINDING_COMMAND;
  } else if (!command && function_fn) {
    kb->type = OWL_KEYBINDING_FUNCTION;
  } else {
    kb->type = OWL_KEYBINDING_NOOP;
  }

  if (owl_keybinding_make_keys(kb, keyseq) != 0) {
    g_free(kb);
    return NULL;
  }

  kb->command = g_strdup(command);
  kb->function_fn = function_fn;
  kb->desc = g_strdup(desc);
  return kb;
}
예제 #6
0
파일: global.c 프로젝트: davidben/barnowl
void owl_global_setup_default_filters(owl_global *g)
{
  int i;
  static const struct {
    const char *name;
    const char *desc;
  } filters[] = {
    { "personal",
      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" },
    { "trash",
      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
    { "ping", "opcode ^ping$" },
    { "auto", "opcode ^auto$" },
    { "login", "not login ^none$" },
    { "reply-lockout", "class ^mail$" },
    { "out", "direction ^out$" },
    { "aim", "type ^aim$" },
    { "zephyr", "type ^zephyr$" },
    { "none", "false" },
    { "all", "true" },
    { NULL, NULL }
  };

  owl_function_debugmsg("startup: creating default filters");

  for (i = 0; filters[i].name != NULL; i++)
    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
                                                       filters[i].desc));
}
예제 #7
0
파일: fmtext.c 프로젝트: arlynap/barnowl
/* Assign pairs by request */
short owl_fmtext_get_colorpair(int fg, int bg)
{
  owl_colorpair_mgr *cpmgr;
  short pair, default_bg;

  /* Sanity (Bounds) Check */
  if (fg > COLORS || fg < OWL_COLOR_DEFAULT) fg = OWL_COLOR_DEFAULT;
  if (bg > COLORS || bg < OWL_COLOR_DEFAULT) bg = OWL_COLOR_DEFAULT;
	    
#ifdef HAVE_USE_DEFAULT_COLORS
  if (fg == OWL_COLOR_DEFAULT) fg = -1;
  default_bg = OWL_COLOR_DEFAULT;
#else
  if (fg == OWL_COLOR_DEFAULT) fg = 0;
  if (bg == OWL_COLOR_DEFAULT) bg = 0;
  default_bg = COLOR_BLACK;
#endif

  /* looking for a pair we already set up for this draw. */
  cpmgr = owl_global_get_colorpair_mgr(&g);
  pair = cpmgr->pairs[fg+1][bg+1];
  if (!(pair != -1 && pair < cpmgr->next)) {
    /* If we didn't find a pair, search for a free one to assign. */
    pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1;
    if (pair != -1) {
      /* We found a free pair, initialize it. */
      init_pair(pair, fg, bg);
      cpmgr->pairs[fg+1][bg+1] = pair;
      cpmgr->next++;
    }
    else if (bg != OWL_COLOR_DEFAULT) {
      /* We still don't have a pair, drop the background color. Too bad. */
      owl_function_debugmsg("colorpairs: color shortage - dropping background color.");
      pair = owl_fmtext_get_colorpair(fg, OWL_COLOR_DEFAULT);
    }
    else {
      /* We still don't have a pair, defaults all around. */
      owl_function_debugmsg("colorpairs: color shortage - dropping foreground and background color.");
      pair = 0;
    }
  }
  return pair;
}
예제 #8
0
파일: global.c 프로젝트: davidben/barnowl
void owl_global_check_resize(owl_global *g) {
  /* resize the screen.  If lines or cols is 0 use the terminal size */
  if (!g->resizepending) return;
  g->resizepending = false;

  owl_global_get_terminal_size(&g->lines, &g->cols);
  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);

  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
}
예제 #9
0
파일: zephyr.c 프로젝트: arlynap/barnowl
void owl_zephyr_finish_initialization(owl_dispatch *d) {
  Code_t code;

  owl_select_remove_dispatch(d->fd);

  ZClosePort();

  if ((code = ZInitialize()) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(code));
    return;
  }

  if ((code = ZOpenPort(NULL)) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(code));
    return;
  }

  d = owl_malloc(sizeof(owl_dispatch));
  d->fd = ZGetFD();
  d->cfunc = &owl_zephyr_process_events;
  d->destroy = NULL;
  owl_select_add_dispatch(d);
  owl_global_set_havezephyr(&g);

  if(g.load_initial_subs) {
    owl_zephyr_load_initial_subs();
  }
  while(deferred_subs != NULL) {
    owl_sub_list *subs = deferred_subs->data;
    owl_function_debugmsg("Loading %d deferred subs.", subs->nsubs);
    owl_zephyr_loadsubs_helper(subs->subs, subs->nsubs);
    deferred_subs = g_list_delete_link(deferred_subs, deferred_subs);
    owl_free(subs);
  }

  /* zlog in if we need to */
  if (owl_global_is_startuplogin(&g)) {
    owl_function_debugmsg("startup: doing zlog in");
    owl_zephyr_zlog_in();
  }
}
예제 #10
0
파일: owl.c 프로젝트: aglasgall/barnowl
static void sig_handler_main_thread(void *data) {
  int sig = GPOINTER_TO_INT(data);

  owl_function_debugmsg("Got signal %d", sig);
  if (sig == SIGWINCH) {
    owl_function_resize();
  } else if (sig == SIGTERM || sig == SIGHUP) {
    owl_function_quit();
  } else if (sig == SIGINT && owl_global_take_interrupt(&g)) {
    owl_input in;
    in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR];
    owl_process_input_char(in);
  }
}
예제 #11
0
파일: zephyr.c 프로젝트: JasonGross/barnowl
int owl_zephyr_zqlength(void)
{
#ifdef HAVE_LIBZEPHYR
  Code_t code;
  if(owl_global_is_havezephyr(&g)) {
    if((code = ZQLength()) < 0) {
      owl_function_debugmsg("Error (%s) in ZQLength()\n",
                            error_message(code));
      return 0;
    }
    return code;
  }
#endif
  return 0;
}
예제 #12
0
파일: zephyr.c 프로젝트: JasonGross/barnowl
void owl_zephyr_load_initial_subs(void) {
  int ret_sd, ret_bd, ret_u;

  owl_function_debugmsg("startup: loading initial zephyr subs");

  /* load default subscriptions */
  ret_sd = owl_zephyr_loaddefaultsubs();

  /* load BarnOwl default subscriptions */
  ret_bd = owl_zephyr_loadbarnowldefaultsubs();

  /* load subscriptions from subs file */
  ret_u = owl_zephyr_loadsubs(NULL, 0);

  if (ret_sd || ret_bd || ret_u) {
    owl_function_error("Error loading zephyr subscriptions");
  }

  /* load login subscriptions */
  if (owl_global_is_loginsubs(&g)) {
    owl_function_debugmsg("startup: loading login subs");
    owl_function_loadloginsubs(NULL);
  }
}
예제 #13
0
파일: select.c 프로젝트: aglasgall/barnowl
static gboolean owl_io_dispatch_check(GSource *source) {
  int i, len;
  const owl_list *dl;

  dl = owl_global_get_io_dispatch_list(&g);
  len = owl_list_get_size(dl);
  for(i = 0; i < len; i++) {
    owl_io_dispatch *d = owl_list_get_element(dl, i);
    if (!d->valid) continue;
    if (d->pollfd.revents & G_IO_NVAL) {
      owl_function_debugmsg("Pruning defunct dispatch on fd %d.", d->fd);
      owl_select_invalidate_io_dispatch(d);
    }
    if (d->pollfd.revents & d->pollfd.events)
      return TRUE;
  }
  return FALSE;
}
예제 #14
0
파일: keybinding.c 프로젝트: dxiao/barnowl
/* sets up a new keybinding for a command */
int owl_keybinding_init(owl_keybinding *kb, const char *keyseq, const char *command, void (*function_fn)(void), const char *desc)
{
  owl_function_debugmsg("owl_keybinding_init: creating binding for <%s> with desc: <%s>", keyseq, desc);
  if (command && !function_fn) {
    kb->type = OWL_KEYBINDING_COMMAND;
  } else if (!command && function_fn) {
    kb->type = OWL_KEYBINDING_FUNCTION;
  } else {
    return(-1);
  }

  if (owl_keybinding_make_keys(kb, keyseq) != 0) {
    return(-1);
  }

  if (command) kb->command = g_strdup(command);
  kb->function_fn = function_fn;
  if (desc) kb->desc = g_strdup(desc);
  else kb->desc = NULL;
  return(0);
}
예제 #15
0
파일: owl.c 프로젝트: dxiao/barnowl
static int owl_refresh_pre_select_action(owl_ps_action *a, void *data)
{
  owl_colorpair_mgr *cpmgr;

  /* if a resize has been scheduled, deal with it */
  owl_global_check_resize(&g);
  /* update the terminal if we need to */
  owl_window_redraw_scheduled();
  /* On colorpair shortage, reset and redraw /everything/. NOTE: if
   * the current screen uses too many colorpairs, this draws
   * everything twice. But this is unlikely; COLOR_PAIRS is 64 with
   * 8+1 colors, and 256^2 with 256+1 colors. (+1 for default.) */
  cpmgr = owl_global_get_colorpair_mgr(&g);
  if (cpmgr->overflow) {
    owl_function_debugmsg("colorpairs: color shortage; reset pairs and redraw. COLOR_PAIRS = %d", COLOR_PAIRS);
    owl_fmtext_reset_colorpairs(cpmgr);
    owl_function_full_redisplay();
    owl_window_redraw_scheduled();
  }
  return 0;
}
예제 #16
0
파일: owl.c 프로젝트: aglasgall/barnowl
int main(int argc, char **argv, char **env)
{
  int argc_copy;
  char **argv_copy;
  char *perlout, *perlerr;
  const owl_style *s;
  const char *dir;
  owl_options opts;
  GSource *source;

  if (!GLIB_CHECK_VERSION (2, 12, 0))
    g_error ("GLib version 2.12.0 or above is needed.");

  argc_copy = argc;
  argv_copy = g_strdupv(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_start_curses();

  /* owl global init */
  owl_global_init(&g);
  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, argc_copy, argv_copy);
  g_strfreev(argv_copy);
  owl_global_set_haveaim(&g);

  owl_register_signal_handlers();

  /* register STDIN dispatch; throw away return, we won't need it */
  owl_select_add_io_dispatch(STDIN_FILENO, OWL_IO_READ, &owl_process_input, NULL, NULL);
  owl_zephyr_initialize();

#if OWL_STDERR_REDIR
  /* Do this only after we've started curses up... */
  owl_function_debugmsg("startup: doing stderr redirection");
  owl_select_add_io_dispatch(stderr_replace(), OWL_IO_READ, &stderr_redirect_handler, NULL, NULL);
#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 {
    char *tty = owl_util_get_default_tty();
    owl_global_set_tty(&g, tty);
    g_free(tty);
  }

  /* Initialize perl */
  owl_function_debugmsg("startup: processing config file");

  owl_global_pop_context(&g);
  owl_global_push_context(&g, OWL_CTX_READCONFIG, NULL, NULL, NULL);

  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_global_setup_default_filters(&g);

  /* 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();");
  g_free(perlout);

  /* welcome message */
  owl_function_debugmsg("startup: creating splash message");
  owl_function_adminmsg("",
    "-----------------------------------------------------------------------\n"
    "Welcome to barnowl version " OWL_VERSION_STRING ".\n"
    "To see a quick introduction, type ':show quickstart'.                  \n"
    "Press 'h' for on-line help.                                            \n"
    "                                                                       \n"
    "BarnOwl is free software. Type ':show license' for more                \n"
    "information.                                                     ^ ^   \n"
    "                                                                 OvO   \n"
    "Please report any bugs or suggestions to [email protected]    (   )  \n"
    "-----------------------------------------------------------------m-m---\n"
  );

  /* process the startup file */
  owl_function_debugmsg("startup: processing startup file");
  owl_function_source(NULL);

  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_global_pop_context(&g);
  owl_global_push_context(&g, OWL_CTX_INTERACTIVE|OWL_CTX_RECV, NULL, "recv", NULL);

  source = owl_window_redraw_source_new();
  g_source_attach(source, NULL);
  g_source_unref(source);

  source = g_source_new(&owl_process_messages_funcs, sizeof(GSource));
  g_source_attach(source, NULL);
  g_source_unref(source);

  owl_log_init();

  owl_function_debugmsg("startup: entering main loop");
  owl_select_run_loop();

  /* Shut down everything. */
  owl_zephyr_shutdown();
  owl_signal_shutdown();
  owl_shutdown_curses();
  owl_log_shutdown();
  return 0;
}
예제 #17
0
파일: fmtext.c 프로젝트: alexmv/barnowl
/* add the formatted text to the curses window 'w'.  The window 'w'
 * must already be initiatlized with curses
 */
static void _owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w, int do_search)
{
  /* char *tmpbuff; */
  /* int position, trans1, trans2, trans3, len, lastsame; */
  char *s, *p;
  char attr;
  short fg, bg, pair = 0;
  
  if (w==NULL) {
    owl_function_debugmsg("Hit a null window in owl_fmtext_curs_waddstr.");
    return;
  }

  s = f->textbuff;
  /* Set default attributes. */
  attr = f->default_attrs;
  fg = f->default_fgcolor;
  bg = f->default_bgcolor;
  _owl_fmtext_wattrset(w, attr);
  _owl_fmtext_update_colorpair(fg, bg, &pair);
  _owl_fmtext_wcolor_set(w, pair);

  /* Find next possible format character. */
  p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
  while(p) {
    if (owl_fmtext_is_format_char(g_utf8_get_char(p))) {
      /* Deal with all text from last insert to here. */
      char tmp;
   
      tmp = p[0];
      p[0] = '\0';
      if (owl_global_is_search_active(&g)) {
	/* Search is active, so highlight search results. */
	char tmp2;
	int start, end;
	while (owl_regex_compare(owl_global_get_search_re(&g), s, &start, &end) == 0) {
	  /* Prevent an infinite loop matching the empty string. */
	  if (end == 0)
	    break;

	  /* Found search string, highlight it. */

	  tmp2 = s[start];
	  s[start] = '\0';
	  waddstr(w, s);
	  s[start] = tmp2;

	  _owl_fmtext_wattrset(w, attr ^ OWL_FMTEXT_ATTR_REVERSE);
	  _owl_fmtext_wcolor_set(w, pair);
	  
	  tmp2 = s[end];
	  s[end] = '\0';
	  waddstr(w, s + start);
	  s[end] = tmp2;

	  _owl_fmtext_wattrset(w, attr);
	  _owl_fmtext_wcolor_set(w, pair);

	  s += end;
	}
      }
      /* Deal with remaining part of string. */
      waddstr(w, s);
      p[0] = tmp;

      /* Deal with new attributes. Initialize to defaults, then
	 process all consecutive formatting characters. */
      attr = f->default_attrs;
      fg = f->default_fgcolor;
      bg = f->default_bgcolor;
      while (owl_fmtext_is_format_char(g_utf8_get_char(p))) {
	_owl_fmtext_update_attributes(g_utf8_get_char(p), &attr, &fg, &bg);
	p = g_utf8_next_char(p);
      }
      _owl_fmtext_wattrset(w, attr | f->default_attrs);
      if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor;
      if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor;
      _owl_fmtext_update_colorpair(fg, bg, &pair);
      _owl_fmtext_wcolor_set(w, pair);

      /* Advance to next non-formatting character. */
      s = p;
      p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    }
    else {
      p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    }
  }
  if (s) {
    waddstr(w, s);
  }
  wbkgdset(w, 0);
}
예제 #18
0
static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data)
{
  owl_message *m;
  int i, lines, isfull, viewsize;
  int x, y, savey, recwinlines, start;
  int topmsg, curmsg, markedmsgid, fgcolor, bgcolor;
  const owl_view *v;
  GList *fl;
  const owl_filter *f;
  owl_mainwin *mw = user_data;

  topmsg = owl_global_get_topmsg(&g);
  curmsg = owl_global_get_curmsg(&g);
  markedmsgid = owl_global_get_markedmsgid(&g);
  v = owl_global_get_current_view(&g);

  if (v==NULL) {
    owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay.");
    return;
  }

  werase(recwin);

  recwinlines=owl_global_get_recwin_lines(&g);
  viewsize=owl_view_get_size(v);

  /* if there are no messages or if topmsg is past the end of the messages,
   * just draw a blank screen */
  if (viewsize==0 || topmsg>=viewsize) {
    if (viewsize==0) {
      owl_global_set_topmsg(&g, 0);
    }
    mw->curtruncated=0;
    mw->lastdisplayed=-1;
    return;
  }

  /* write the messages out */
  isfull=0;
  mw->curtruncated=0;
  mw->lasttruncated=0;

  for (i=topmsg; i<viewsize; i++) {
    if (isfull) break;
    m=owl_view_get_element(v, i);

    /* hold on to y in case this is the current message or deleted */
    getyx(recwin, y, x);
    savey=y;

    /* if it's the current message, account for a vert_offset */
    if (i==owl_global_get_curmsg(&g)) {
      start=owl_global_get_curmsg_vert_offset(&g);
      lines=owl_message_get_numlines(m)-start;
    } else {
      start=0;
      lines=owl_message_get_numlines(m);
    }

    /* if we match filters set the color */
    fgcolor=OWL_COLOR_DEFAULT;
    bgcolor=OWL_COLOR_DEFAULT;
    for (fl = g.filterlist; fl; fl = g_list_next(fl)) {
      f = fl->data;
      if ((owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) ||
          (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT)) {
        if (owl_filter_message_match(f, m)) {
          if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
          if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
	}
      }
    }

    /* if we'll fill the screen print a partial message */
    if ((y+lines > recwinlines) && (i==owl_global_get_curmsg(&g))) mw->curtruncated=1;
    if (y+lines > recwinlines) mw->lasttruncated=1;
    if (y+lines > recwinlines-1) {
      isfull=1;
      owl_message_curs_waddstr(m, recwin,
			       start,
			       start+recwinlines-y,
			       owl_global_get_rightshift(&g),
			       owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
			       fgcolor, bgcolor);
    } else {
      /* otherwise print the whole thing */
      owl_message_curs_waddstr(m, recwin,
			       start,
			       start+lines,
			       owl_global_get_rightshift(&g),
			       owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
			       fgcolor, bgcolor);
    }


    /* is it the current message and/or deleted? */
    getyx(recwin, y, x);
    wattrset(recwin, A_NORMAL);
    if (owl_global_get_rightshift(&g)==0) {   /* this lame and should be fixed */
      if (m==owl_view_get_element(v, curmsg)) {
	wmove(recwin, savey, 0);
	wattron(recwin, A_BOLD);	
	if (owl_global_get_curmsg_vert_offset(&g)>0) {
	  waddstr(recwin, "+");
	} else {
	  waddstr(recwin, "-");
	}
	if (owl_message_is_delete(m)) {
	  waddstr(recwin, "D");
	} else if (markedmsgid == owl_message_get_id(m)) {
	  waddstr(recwin, "*");
	} else {
	  waddstr(recwin, ">");
	}
	wmove(recwin, y, x);
	wattroff(recwin, A_BOLD);
      } else if (owl_message_is_delete(m)) {
	wmove(recwin, savey, 0);
	waddstr(recwin, " D");
	wmove(recwin, y, x);
      } else if (markedmsgid == owl_message_get_id(m)) {
	wmove(recwin, savey, 0);
	waddstr(recwin, " *");
	wmove(recwin, y, x);
      }
    }
    wattroff(recwin, A_BOLD);
  }
  mw->lastdisplayed=i-1;
}
예제 #19
0
파일: fmtext.c 프로젝트: arlynap/barnowl
/* add the formatted text to the curses window 'w'.  The window 'w'
 * must already be initiatlized with curses
 */
void _owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w, int do_search) /*noproto*/
{
  /* char *tmpbuff; */
  /* int position, trans1, trans2, trans3, len, lastsame; */
  char *s, *p;
  char attr;
  short fg, bg, pair;
  int search_results, search_len;
  
  if (w==NULL) {
    owl_function_debugmsg("Hit a null window in owl_fmtext_curs_waddstr.");
    return;
  }

  search_results = (do_search
		    ? owl_fmtext_search(f, owl_global_get_search_string(&g))
		    : 0);
  search_len = (search_results
		? strlen(owl_global_get_search_string(&g))
		: 0);
  s = f->textbuff;
  /* Set default attributes. */
  attr = f->default_attrs;
  fg = f->default_fgcolor;
  bg = f->default_bgcolor;
  _owl_fmtext_wattrset(w, attr);
  _owl_fmtext_update_colorpair(fg, bg, &pair);
  _owl_fmtext_wcolor_set(w, pair);

  /* Find next possible format character. */
  p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
  while(p) {
    if (owl_fmtext_is_format_char(g_utf8_get_char(p))) {
      /* Deal with all text from last insert to here. */
      char tmp;
   
      tmp = p[0];
      p[0] = '\0';
      if (search_results) {
	/* Search is active, so highlight search results. */
	char tmp2, *ss;
	ss = stristr(s, owl_global_get_search_string(&g));
	while (ss) {
	  /* Found search string, highlight it. */

	  tmp2 = ss[0];
	  ss[0] = '\0';
	  waddstr(w, s);
	  ss[0] = tmp2;

	  _owl_fmtext_wattrset(w, attr ^ OWL_FMTEXT_ATTR_REVERSE);
	  _owl_fmtext_wcolor_set(w, pair);
	  
	  tmp2 = ss[search_len];
	  ss[search_len] = '\0';
	  waddstr(w, ss);
	  ss[search_len] = tmp2;

	  _owl_fmtext_wattrset(w, attr);
	  _owl_fmtext_wcolor_set(w, pair);

	  s = ss + search_len;
	  ss = stristr(s, owl_global_get_search_string(&g));
	}
      }
      /* Deal with remaining part of string. */
      waddstr(w, s);
      p[0] = tmp;

      /* Deal with new attributes. Initialize to defaults, then
	 process all consecutive formatting characters. */
      attr = f->default_attrs;
      fg = f->default_fgcolor;
      bg = f->default_bgcolor;
      while (p && owl_fmtext_is_format_char(g_utf8_get_char(p))) {
	_owl_fmtext_update_attributes(g_utf8_get_char(p), &attr, &fg, &bg);
	p = g_utf8_next_char(p);
      }
      _owl_fmtext_wattrset(w, attr | f->default_attrs);
      if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor;
      if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor;
      _owl_fmtext_update_colorpair(fg, bg, &pair);
      _owl_fmtext_wcolor_set(w, pair);

      /* Advance to next non-formatting character. */
      s = p;
      p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    }
    else {
      p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    }
  }
  if (s) {
    waddstr(w, s);
  }
}