Changes in global.c [dc1edbd:6383920]
Legend:
- Unmodified
- Added
- Removed
-
global.c
rdc1edbd r6383920 1 #include "owl.h" 1 2 #include <stdio.h> 2 #include <unistd.h>3 #include <stdlib.h>4 #include <string.h>5 #include <netdb.h>6 #include <termios.h>7 3 #include <sys/ioctl.h> 8 #include <time.h>9 #include "owl.h"10 4 11 5 static void _owl_global_init_windows(owl_global *g); … … 15 9 const char *homedir; 16 10 11 #if !GLIB_CHECK_VERSION(2, 35, 0) 17 12 g_type_init(); 13 #endif 14 #if !GLIB_CHECK_VERSION(2, 31, 0) 18 15 g_thread_init(NULL); 16 #endif 19 17 20 18 owl_select_init(); … … 47 45 owl_dict_create(&(g->filters)); 48 46 g->filterlist = NULL; 49 owl_list_create(&(g->puntlist));47 g->puntlist = g_ptr_array_new(); 50 48 g->messagequeue = g_queue_new(); 51 49 owl_dict_create(&(g->styledict)); … … 53 51 g->resizepending=0; 54 52 g->direction=OWL_DIRECTION_DOWNWARDS; 55 g->zaway=0;56 if (has_colors()) {57 g->hascolors=1;58 }59 g->colorpairs=COLOR_PAIRS;60 53 owl_fmtext_init_colorpair_mgr(&(g->cpmgr)); 61 54 g->debug=OWL_DEBUG; … … 69 62 owl_history_init(&(g->msghist)); 70 63 owl_history_init(&(g->cmdhist)); 71 owl_history_set_norepeats(&(g->cmdhist));72 64 g->nextmsgid=0; 73 65 … … 83 75 g->confdir = NULL; 84 76 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); 86 78 owl_global_set_confdir(g, cd); 87 79 g_free(cd); 88 80 89 owl_messagelist_create(&(g->msglist));81 g->msglist = owl_messagelist_new(); 90 82 91 83 _owl_global_init_windows(g); … … 109 101 110 102 owl_message_init_fmtext_cache(); 111 owl_list_create(&(g->io_dispatch_list));112 g->timerlist = NULL;113 103 g->kill_buffer = NULL; 114 104 115 105 g->interrupt_count = 0; 106 #if GLIB_CHECK_VERSION(2, 31, 0) 107 g_mutex_init(&g->interrupt_lock); 108 #else 116 109 g->interrupt_lock = g_mutex_new(); 110 #endif 117 111 } 118 112 … … 123 117 124 118 /* Create the widgets */ 125 owl_mainwin_init(&(g->mw),g->mainpanel.recwin);119 g->mw = owl_mainwin_new(g->mainpanel.recwin); 126 120 owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin); 127 121 owl_sepbar_init(g->mainpanel.sepwin); … … 179 173 /* Pops the current context from the context stack and returns it. Caller is 180 174 * responsible for freeing. */ 181 owl_context *owl_global_pop_context_no_delete(owl_global *g) { 175 CALLER_OWN owl_context *owl_global_pop_context_no_delete(owl_global *g) 176 { 182 177 owl_context *c; 183 178 if (!g->context_stack) … … 254 249 /* windows */ 255 250 256 owl_mainwin *owl_global_get_mainwin(owl_global *g) { 257 return(&(g->mw)); 251 owl_mainwin *owl_global_get_mainwin(owl_global *g) 252 { 253 return g->mw; 258 254 } 259 255 … … 269 265 270 266 owl_messagelist *owl_global_get_msglist(owl_global *g) { 271 return (&(g->msglist));267 return g->msglist; 272 268 } 273 269 … … 371 367 g->confdir = g_strdup(cd); 372 368 g_free(g->startupfile); 373 g->startupfile = g_ strdup_printf("%s/startup", cd);369 g->startupfile = g_build_filename(cd, "startup", NULL); 374 370 } 375 371 … … 512 508 513 509 void owl_global_set_startupargs(owl_global *g, int argc, char **argv) { 514 if (g->startupargs)g_free(g->startupargs);510 g_free(g->startupargs); 515 511 g->startupargs = g_strjoinv(" ", argv); 516 512 } … … 579 575 } 580 576 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 594 577 owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) { 595 578 return(&(g->cpmgr)); … … 598 581 /* puntlist */ 599 582 600 owl_list*owl_global_get_puntlist(owl_global *g) {601 return (&(g->puntlist));583 GPtrArray *owl_global_get_puntlist(owl_global *g) { 584 return g->puntlist; 602 585 } 603 586 604 587 int 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; 614 596 } 615 597 … … 744 726 * necessary. 745 727 */ 746 owl_message *owl_global_messagequeue_popmsg(owl_global *g)728 CALLER_OWN owl_message *owl_global_messagequeue_popmsg(owl_global *g) 747 729 { 748 730 owl_message *out; … … 773 755 } 774 756 775 int owl_global_get_style_names(const owl_global *g, owl_list *l) { 776 return owl_dict_get_keys(&(g->styledict), l); 757 CALLER_OWN GPtrArray *owl_global_get_style_names(const owl_global *g) 758 { 759 return owl_dict_get_keys(&g->styledict); 777 760 } 778 761 … … 858 841 } 859 842 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 870 843 void owl_global_setup_default_filters(owl_global *g) 871 844 { … … 876 849 } filters[] = { 877 850 { "personal", 878 "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message 851 "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message$ ) )" }, 879 852 { "trash", 880 853 "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" }, … … 883 856 { "auto", "opcode ^auto$" }, 884 857 { "login", "not login ^none$" }, 885 { "reply-lockout", "class ^ noc or class ^mail$" },858 { "reply-lockout", "class ^mail$ or class ^filsrv$" }, 886 859 { "out", "direction ^out$" }, 887 860 { "aim", "type ^aim$" }, … … 934 907 } 935 908 909 static 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 936 918 void owl_global_add_interrupt(owl_global *g) { 937 919 /* TODO: This can almost certainly be done with atomic 938 920 * operations. Whatever. */ 939 g_mutex_lock( g->interrupt_lock);921 g_mutex_lock(owl_global_get_interrupt_lock(g)); 940 922 g->interrupt_count++; 941 g_mutex_unlock( g->interrupt_lock);923 g_mutex_unlock(owl_global_get_interrupt_lock(g)); 942 924 } 943 925 944 926 bool owl_global_take_interrupt(owl_global *g) { 945 927 bool ans = false; 946 g_mutex_lock( g->interrupt_lock);928 g_mutex_lock(owl_global_get_interrupt_lock(g)); 947 929 if (g->interrupt_count > 0) { 948 930 ans = true; 949 931 g->interrupt_count--; 950 932 } 951 g_mutex_unlock( g->interrupt_lock);933 g_mutex_unlock(owl_global_get_interrupt_lock(g)); 952 934 return ans; 953 935 }
Note: See TracChangeset
for help on using the changeset viewer.