Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • global.c

    rdc1edbd r6383920  
     1#include "owl.h"
    12#include <stdio.h>
    2 #include <unistd.h>
    3 #include <stdlib.h>
    4 #include <string.h>
    5 #include <netdb.h>
    6 #include <termios.h>
    73#include <sys/ioctl.h>
    8 #include <time.h>
    9 #include "owl.h"
    104
    115static void _owl_global_init_windows(owl_global *g);
     
    159  const char *homedir;
    1610
     11#if !GLIB_CHECK_VERSION(2, 35, 0)
    1712  g_type_init();
     13#endif
     14#if !GLIB_CHECK_VERSION(2, 31, 0)
    1815  g_thread_init(NULL);
     16#endif
    1917
    2018  owl_select_init();
     
    4745  owl_dict_create(&(g->filters));
    4846  g->filterlist = NULL;
    49   owl_list_create(&(g->puntlist));
     47  g->puntlist = g_ptr_array_new();
    5048  g->messagequeue = g_queue_new();
    5149  owl_dict_create(&(g->styledict));
     
    5351  g->resizepending=0;
    5452  g->direction=OWL_DIRECTION_DOWNWARDS;
    55   g->zaway=0;
    56   if (has_colors()) {
    57     g->hascolors=1;
    58   }
    59   g->colorpairs=COLOR_PAIRS;
    6053  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
    6154  g->debug=OWL_DEBUG;
     
    6962  owl_history_init(&(g->msghist));
    7063  owl_history_init(&(g->cmdhist));
    71   owl_history_set_norepeats(&(g->cmdhist));
    7264  g->nextmsgid=0;
    7365
     
    8375  g->confdir = NULL;
    8476  g->startupfile = NULL;
    85   cd = g_strdup_printf("%s/%s", g->homedir, OWL_CONFIG_DIR);
     77  cd = g_build_filename(g->homedir, OWL_CONFIG_DIR, NULL);
    8678  owl_global_set_confdir(g, cd);
    8779  g_free(cd);
    8880
    89   owl_messagelist_create(&(g->msglist));
     81  g->msglist = owl_messagelist_new();
    9082
    9183  _owl_global_init_windows(g);
     
    109101
    110102  owl_message_init_fmtext_cache();
    111   owl_list_create(&(g->io_dispatch_list));
    112   g->timerlist = NULL;
    113103  g->kill_buffer = NULL;
    114104
    115105  g->interrupt_count = 0;
     106#if GLIB_CHECK_VERSION(2, 31, 0)
     107  g_mutex_init(&g->interrupt_lock);
     108#else
    116109  g->interrupt_lock = g_mutex_new();
     110#endif
    117111}
    118112
     
    123117
    124118  /* Create the widgets */
    125   owl_mainwin_init(&(g->mw), g->mainpanel.recwin);
     119  g->mw = owl_mainwin_new(g->mainpanel.recwin);
    126120  owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
    127121  owl_sepbar_init(g->mainpanel.sepwin);
     
    179173/* Pops the current context from the context stack and returns it. Caller is
    180174 * responsible for freeing. */
    181 owl_context *owl_global_pop_context_no_delete(owl_global *g) {
     175CALLER_OWN owl_context *owl_global_pop_context_no_delete(owl_global *g)
     176{
    182177  owl_context *c;
    183178  if (!g->context_stack)
     
    254249/* windows */
    255250
    256 owl_mainwin *owl_global_get_mainwin(owl_global *g) {
    257   return(&(g->mw));
     251owl_mainwin *owl_global_get_mainwin(owl_global *g)
     252{
     253  return g->mw;
    258254}
    259255
     
    269265
    270266owl_messagelist *owl_global_get_msglist(owl_global *g) {
    271   return(&(g->msglist));
     267  return g->msglist;
    272268}
    273269
     
    371367  g->confdir = g_strdup(cd);
    372368  g_free(g->startupfile);
    373   g->startupfile = g_strdup_printf("%s/startup", cd);
     369  g->startupfile = g_build_filename(cd, "startup", NULL);
    374370}
    375371
     
    512508
    513509void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
    514   if (g->startupargs) g_free(g->startupargs);
     510  g_free(g->startupargs);
    515511  g->startupargs = g_strjoinv(" ", argv);
    516512}
     
    579575}
    580576
    581 /* has colors */
    582 
    583 int owl_global_get_hascolors(const owl_global *g) {
    584   if (g->hascolors) return(1);
    585   return(0);
    586 }
    587 
    588 /* color pairs */
    589 
    590 int owl_global_get_colorpairs(const owl_global *g) {
    591   return(g->colorpairs);
    592 }
    593 
    594577owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
    595578  return(&(g->cpmgr));
     
    598581/* puntlist */
    599582
    600 owl_list *owl_global_get_puntlist(owl_global *g) {
    601   return(&(g->puntlist));
     583GPtrArray *owl_global_get_puntlist(owl_global *g) {
     584  return g->puntlist;
    602585}
    603586
    604587int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
    605   const owl_list *pl;
    606   int i, j;
    607 
    608   pl=owl_global_get_puntlist(g);
    609   j=owl_list_get_size(pl);
    610   for (i=0; i<j; i++) {
    611     if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
    612   }
    613   return(0);
     588  const GPtrArray *pl;
     589  int i;
     590
     591  pl = owl_global_get_puntlist(g);
     592  for (i = 0; i < pl->len; i++) {
     593    if (owl_filter_message_match(pl->pdata[i], m)) return 1;
     594  }
     595  return 0;
    614596}
    615597
     
    744726 * necessary.
    745727 */
    746 owl_message *owl_global_messagequeue_popmsg(owl_global *g)
     728CALLER_OWN owl_message *owl_global_messagequeue_popmsg(owl_global *g)
    747729{
    748730  owl_message *out;
     
    773755}
    774756
    775 int owl_global_get_style_names(const owl_global *g, owl_list *l) {
    776   return owl_dict_get_keys(&(g->styledict), l);
     757CALLER_OWN GPtrArray *owl_global_get_style_names(const owl_global *g)
     758{
     759  return owl_dict_get_keys(&g->styledict);
    777760}
    778761
     
    858841}
    859842
    860 owl_list *owl_global_get_io_dispatch_list(owl_global *g)
    861 {
    862   return &(g->io_dispatch_list);
    863 }
    864 
    865 GList **owl_global_get_timerlist(owl_global *g)
    866 {
    867   return &(g->timerlist);
    868 }
    869 
    870843void owl_global_setup_default_filters(owl_global *g)
    871844{
     
    876849  } filters[] = {
    877850    { "personal",
    878       "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" },
     851      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message$ ) )" },
    879852    { "trash",
    880853      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
     
    883856    { "auto", "opcode ^auto$" },
    884857    { "login", "not login ^none$" },
    885     { "reply-lockout", "class ^noc or class ^mail$" },
     858    { "reply-lockout", "class ^mail$ or class ^filsrv$" },
    886859    { "out", "direction ^out$" },
    887860    { "aim", "type ^aim$" },
     
    934907}
    935908
     909static GMutex *owl_global_get_interrupt_lock(owl_global *g)
     910{
     911#if GLIB_CHECK_VERSION(2, 31, 0)
     912  return &g->interrupt_lock;
     913#else
     914  return g->interrupt_lock;
     915#endif
     916}
     917
    936918void owl_global_add_interrupt(owl_global *g) {
    937919  /* TODO: This can almost certainly be done with atomic
    938920   * operations. Whatever. */
    939   g_mutex_lock(g->interrupt_lock);
     921  g_mutex_lock(owl_global_get_interrupt_lock(g));
    940922  g->interrupt_count++;
    941   g_mutex_unlock(g->interrupt_lock);
     923  g_mutex_unlock(owl_global_get_interrupt_lock(g));
    942924}
    943925
    944926bool owl_global_take_interrupt(owl_global *g) {
    945927  bool ans = false;
    946   g_mutex_lock(g->interrupt_lock);
     928  g_mutex_lock(owl_global_get_interrupt_lock(g));
    947929  if (g->interrupt_count > 0) {
    948930    ans = true;
    949931    g->interrupt_count--;
    950932  }
    951   g_mutex_unlock(g->interrupt_lock);
     933  g_mutex_unlock(owl_global_get_interrupt_lock(g));
    952934  return ans;
    953935}
Note: See TracChangeset for help on using the changeset viewer.