source: global.c @ 06e04a9

release-1.10
Last change on this file since 06e04a9 was 0792d99, checked in by Anders Kaseorg <andersk@mit.edu>, 12 years ago
Replace deprecated GLib < 2.31.0 thread APIs As of GLib 2.31.0, - threading is now always enabled in GLib - libgthread is now an empty shell and g_thread_init() is no longer required (and has been deprecated) - simplified new thread creation API with the old API deprecated. The concept of joinability has disappeared (all threads are joinable) as have priority levels, 'bound'ness (ie: kernel vs. userspace threads) and ability to manipulate the stack size. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 21.3 KB
Line 
1#include "owl.h"
2#include <stdio.h>
3#include <sys/ioctl.h>
4
5static void _owl_global_init_windows(owl_global *g);
6
7void owl_global_init(owl_global *g) {
8  char *cd;
9  const char *homedir;
10
11  g_type_init();
12#if !GLIB_CHECK_VERSION(2, 31, 0)
13  g_thread_init(NULL);
14#endif
15
16  owl_select_init();
17
18  g->lines=LINES;
19  g->cols=COLS;
20  /* We shouldn't need this if we initialize lines and cols before the first
21   * owl_window_get_screen, but to be safe, we synchronize. */
22  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
23
24  g->context_stack = NULL;
25  owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL);
26
27  g->curmsg=0;
28  g->topmsg=0;
29  g->markedmsgid=-1;
30  g->startupargs=NULL;
31
32  owl_variable_dict_setup(&(g->vars));
33
34  g->rightshift=0;
35
36  g->pw = NULL;
37  g->vw = NULL;
38  g->tw = NULL;
39
40  owl_keyhandler_init(&g->kh);
41  owl_keys_setup_keymaps(&g->kh);
42
43  owl_dict_create(&(g->filters));
44  g->filterlist = NULL;
45  g->puntlist = g_ptr_array_new();
46  g->messagequeue = g_queue_new();
47  owl_dict_create(&(g->styledict));
48  g->curmsg_vert_offset=0;
49  g->resizepending=0;
50  g->direction=OWL_DIRECTION_DOWNWARDS;
51  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
52  g->debug=OWL_DEBUG;
53  owl_regex_init(&g->search_re);
54  g->starttime=time(NULL); /* assumes we call init only a start time */
55  g->lastinputtime=g->starttime;
56  g->newmsgproc_pid=0;
57 
58  owl_global_set_config_format(g, 0);
59  owl_global_set_no_have_config(g);
60  owl_history_init(&(g->msghist));
61  owl_history_init(&(g->cmdhist));
62  g->nextmsgid=0;
63
64  /* Fill in some variables which don't have constant defaults */
65
66  /* glib's g_get_home_dir prefers passwd entries to $HOME, so we
67   * explicitly check getenv first. */
68  homedir = getenv("HOME");
69  if (!homedir)
70    homedir = g_get_home_dir();
71  g->homedir = g_strdup(homedir);
72
73  g->confdir = NULL;
74  g->startupfile = NULL;
75  cd = g_build_filename(g->homedir, OWL_CONFIG_DIR, NULL);
76  owl_global_set_confdir(g, cd);
77  g_free(cd);
78
79  g->msglist = owl_messagelist_new();
80
81  _owl_global_init_windows(g);
82
83  g->aim_screenname=NULL;
84  g->aim_screenname_for_filters=NULL;
85  g->aim_loggedin=0;
86  owl_buddylist_init(&(g->buddylist));
87
88  g->havezephyr=0;
89  g->haveaim=0;
90  g->ignoreaimlogin=0;
91  owl_global_set_no_doaimevents(g);
92
93  owl_errqueue_init(&(g->errqueue));
94
95  owl_zbuddylist_create(&(g->zbuddies));
96
97  g->zaldlist = NULL;
98  g->pseudologin_notify = 0;
99
100  owl_message_init_fmtext_cache();
101  g->kill_buffer = NULL;
102
103  g->interrupt_count = 0;
104#if GLIB_CHECK_VERSION(2, 31, 0)
105  g_mutex_init(&g->interrupt_lock);
106#else
107  g->interrupt_lock = g_mutex_new();
108#endif
109}
110
111static void _owl_global_init_windows(owl_global *g)
112{
113  /* Create the main window */
114  owl_mainpanel_init(&(g->mainpanel));
115
116  /* Create the widgets */
117  g->mw = owl_mainwin_new(g->mainpanel.recwin);
118  owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
119  owl_sepbar_init(g->mainpanel.sepwin);
120
121  owl_window_set_default_cursor(g->mainpanel.sepwin);
122
123  /* set up a pad for input */
124  g->input_pad = newpad(1, 1);
125  nodelay(g->input_pad, 1);
126  keypad(g->input_pad, 1);
127  meta(g->input_pad, 1);
128}
129
130void owl_global_sepbar_dirty(owl_global *g)
131{
132  owl_window_dirty(g->mainpanel.sepwin);
133}
134
135/* Called once perl has been initialized */
136void owl_global_complete_setup(owl_global *g)
137{
138  owl_cmddict_setup(&(g->cmds));
139}
140
141owl_context *owl_global_get_context(const owl_global *g) {
142  if (!g->context_stack)
143    return NULL;
144  return g->context_stack->data;
145}
146
147static void owl_global_activate_context(owl_global *g, owl_context *c) {
148  if (!c)
149    return;
150
151  if (c->keymap) {
152    if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
153      owl_function_error("Unable to activate keymap '%s'", c->keymap);
154    }
155  }
156  owl_window_set_cursor(c->cursor);
157}
158
159void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) {
160  owl_context *c;
161  c = owl_context_new(mode, data, keymap, cursor);
162  owl_global_push_context_obj(g, c);
163}
164
165void owl_global_push_context_obj(owl_global *g, owl_context *c)
166{
167  g->context_stack = g_list_prepend(g->context_stack, c);
168  owl_global_activate_context(g, owl_global_get_context(g));
169}
170
171/* Pops the current context from the context stack and returns it. Caller is
172 * responsible for freeing. */
173CALLER_OWN owl_context *owl_global_pop_context_no_delete(owl_global *g)
174{
175  owl_context *c;
176  if (!g->context_stack)
177    return NULL;
178  c = owl_global_get_context(g);
179  owl_context_deactivate(c);
180  g->context_stack = g_list_delete_link(g->context_stack,
181                                        g->context_stack);
182  owl_global_activate_context(g, owl_global_get_context(g));
183  return c;
184}
185
186/* Pops the current context from the context stack and deletes it. */
187void owl_global_pop_context(owl_global *g) {
188  owl_context *c;
189  c = owl_global_pop_context_no_delete(g);
190  if (c)
191    owl_context_delete(c);
192}
193
194int owl_global_get_lines(const owl_global *g) {
195  return(g->lines);
196}
197
198int owl_global_get_cols(const owl_global *g) {
199  return(g->cols);
200}
201
202int owl_global_get_recwin_lines(const owl_global *g) {
203  return g->mainpanel.recwinlines;
204}
205
206/* curmsg */
207
208int owl_global_get_curmsg(const owl_global *g) {
209  return(g->curmsg);
210}
211
212void owl_global_set_curmsg(owl_global *g, int i) {
213  g->curmsg=i;
214  /* we will reset the vertical offset from here */
215  /* we might want to move this out to the functions later */
216  owl_global_set_curmsg_vert_offset(g, 0);
217}
218
219/* topmsg */
220
221int owl_global_get_topmsg(const owl_global *g) {
222  return(g->topmsg);
223}
224
225void owl_global_set_topmsg(owl_global *g, int i) {
226  g->topmsg=i;
227}
228
229/* markedmsgid */
230
231int owl_global_get_markedmsgid(const owl_global *g) {
232  return(g->markedmsgid);
233}
234
235void owl_global_set_markedmsgid(owl_global *g, int i) {
236  g->markedmsgid=i;
237  /* i; index of message in the current view.
238  const owl_message *m;
239  owl_view *v;
240
241  v = owl_global_get_current_view(&g);
242  m = owl_view_get_element(v, i);
243  g->markedmsgid = m ? owl_message_get_id(m) : 0;
244  */
245}
246
247/* windows */
248
249owl_mainwin *owl_global_get_mainwin(owl_global *g)
250{
251  return g->mw;
252}
253
254owl_popwin *owl_global_get_popwin(owl_global *g) {
255  return g->pw;
256}
257
258void owl_global_set_popwin(owl_global *g, owl_popwin *pw) {
259  g->pw = pw;
260}
261
262/* msglist */
263
264owl_messagelist *owl_global_get_msglist(owl_global *g) {
265  return g->msglist;
266}
267
268/* keyhandler */
269
270owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
271  return(&(g->kh));
272}
273
274/* Gets the currently active typwin out of the current context. */
275owl_editwin *owl_global_current_typwin(const owl_global *g) {
276  owl_context *ctx = owl_global_get_context(g);
277  return owl_editcontext_get_editwin(ctx);
278}
279
280/* variable dictionary */
281
282owl_vardict *owl_global_get_vardict(owl_global *g) {
283  return &(g->vars);
284}
285
286/* command dictionary */
287
288owl_cmddict *owl_global_get_cmddict(owl_global *g) {
289  return &(g->cmds);
290}
291
292/* rightshift */
293
294void owl_global_set_rightshift(owl_global *g, int i) {
295  g->rightshift = i;
296  owl_mainwin_redisplay(owl_global_get_mainwin(g));
297}
298
299int owl_global_get_rightshift(const owl_global *g) {
300  return(g->rightshift);
301}
302
303/* typwin */
304
305owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) {
306  int d;
307  d = owl_global_get_typewindelta(g);
308  if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE)
309      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
310
311  if (g->typwin_erase_id) {
312    g_signal_handler_disconnect(g->mainpanel.typwin, g->typwin_erase_id);
313    g->typwin_erase_id = 0;
314  }
315
316  g->tw = owl_editwin_new(g->mainpanel.typwin,
317                          owl_global_get_typwin_lines(g),
318                          g->cols,
319                          style,
320                          hist);
321  return g->tw;
322}
323
324void owl_global_deactivate_editcontext(owl_context *ctx) {
325  owl_global *g = ctx->cbdata;
326  owl_global_set_typwin_inactive(g);
327}
328
329void owl_global_set_typwin_inactive(owl_global *g) {
330  int d = owl_global_get_typewindelta(g);
331  if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE)
332      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
333
334  if (!g->typwin_erase_id) {
335    g->typwin_erase_id =
336      g_signal_connect(g->mainpanel.typwin, "redraw", G_CALLBACK(owl_window_erase_cb), NULL);
337  }
338  owl_window_dirty(g->mainpanel.typwin);
339
340  owl_editwin_unref(g->tw);
341  g->tw = NULL;
342}
343
344/* resize */
345
346void owl_global_set_resize_pending(owl_global *g) {
347  g->resizepending = true;
348}
349
350const char *owl_global_get_homedir(const owl_global *g) {
351  if (g->homedir) return(g->homedir);
352  return("/");
353}
354
355const char *owl_global_get_confdir(const owl_global *g) {
356  if (g->confdir) return(g->confdir);
357  return("/");
358}
359
360/*
361 * Setting this also sets startupfile to confdir/startup
362 */
363void owl_global_set_confdir(owl_global *g, const char *cd) {
364  g_free(g->confdir);
365  g->confdir = g_strdup(cd);
366  g_free(g->startupfile);
367  g->startupfile = g_build_filename(cd, "startup", NULL);
368}
369
370const char *owl_global_get_startupfile(const owl_global *g) {
371  if(g->startupfile) return(g->startupfile);
372  return("/");
373}
374
375int owl_global_get_direction(const owl_global *g) {
376  return(g->direction);
377}
378
379void owl_global_set_direction_downwards(owl_global *g) {
380  g->direction=OWL_DIRECTION_DOWNWARDS;
381}
382
383void owl_global_set_direction_upwards(owl_global *g) {
384  g->direction=OWL_DIRECTION_UPWARDS;
385}
386
387/* perl stuff */
388
389void owl_global_set_perlinterp(owl_global *g, void *p) {
390  g->perl=p;
391}
392
393void *owl_global_get_perlinterp(const owl_global *g) {
394  return(g->perl);
395}
396
397int owl_global_is_config_format(const owl_global *g) {
398  if (g->config_format) return(1);
399  return(0);
400}
401
402void owl_global_set_config_format(owl_global *g, int state) {
403  if (state==1) {
404    g->config_format=1;
405  } else {
406    g->config_format=0;
407  }
408}
409
410void owl_global_set_have_config(owl_global *g) {
411  g->haveconfig=1;
412}
413
414void owl_global_set_no_have_config(owl_global *g) {
415  g->haveconfig=0;
416}
417
418int owl_global_have_config(owl_global *g) {
419  if (g->haveconfig) return(1);
420  return(0);
421}
422
423/*
424 * Compute the size of the terminal. Try a ioctl, fallback to other stuff on
425 * fail.
426 */
427void owl_global_get_terminal_size(int *lines, int *cols) {
428  struct winsize size;
429  /* get the new size */
430  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
431  if (size.ws_row) {
432    *lines = size.ws_row;
433  } else {
434    *lines = LINES;
435  }
436
437  if (size.ws_col) {
438    *cols = size.ws_col;
439  } else {
440    *cols = COLS;
441  }
442}
443
444void owl_global_check_resize(owl_global *g) {
445  /* resize the screen.  If lines or cols is 0 use the terminal size */
446  if (!g->resizepending) return;
447  g->resizepending = false;
448
449  owl_global_get_terminal_size(&g->lines, &g->cols);
450  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
451
452  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
453}
454
455/* debug */
456
457int owl_global_is_debug_fast(const owl_global *g) {
458  if (g->debug) return(1);
459  return(0);
460}
461
462/* starttime */
463
464time_t owl_global_get_starttime(const owl_global *g) {
465  return(g->starttime);
466}
467
468time_t owl_global_get_runtime(const owl_global *g) {
469  return(time(NULL)-g->starttime);
470}
471
472time_t owl_global_get_lastinputtime(const owl_global *g) {
473  return(g->lastinputtime);
474}
475
476void owl_global_set_lastinputtime(owl_global *g, time_t time) {
477  g->lastinputtime = time;
478}
479
480time_t owl_global_get_idletime(const owl_global *g) {
481  return(time(NULL)-g->lastinputtime);
482}
483
484/* viewwin */
485
486owl_viewwin *owl_global_get_viewwin(owl_global *g) {
487  return g->vw;
488}
489
490void owl_global_set_viewwin(owl_global *g, owl_viewwin *vw) {
491  g->vw = vw;
492}
493
494
495/* vert offset */
496
497int owl_global_get_curmsg_vert_offset(const owl_global *g) {
498  return(g->curmsg_vert_offset);
499}
500
501void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
502  g->curmsg_vert_offset = i;
503}
504
505/* startup args */
506
507void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
508  g_free(g->startupargs);
509  g->startupargs = g_strjoinv(" ", argv);
510}
511
512const char *owl_global_get_startupargs(const owl_global *g) {
513  if (g->startupargs) return(g->startupargs);
514  return("");
515}
516
517/* history */
518
519owl_history *owl_global_get_msg_history(owl_global *g) {
520  return(&(g->msghist));
521}
522
523owl_history *owl_global_get_cmd_history(owl_global *g) {
524  return(&(g->cmdhist));
525}
526
527/* filterlist */
528typedef struct _owl_global_filter_ent {         /* noproto */
529  owl_global *g;
530  owl_filter *f;
531} owl_global_filter_ent;
532
533owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
534  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
535  if (e) return e->f;
536  return NULL;
537}
538
539static void owl_global_delete_filter_ent(void *data)
540{
541  owl_global_filter_ent *e = data;
542  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
543  owl_filter_delete(e->f);
544  g_free(e);
545}
546
547void owl_global_add_filter(owl_global *g, owl_filter *f) {
548  owl_global_filter_ent *e = g_new(owl_global_filter_ent, 1);
549  e->g = g;
550  e->f = f;
551
552  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
553                          e, owl_global_delete_filter_ent);
554  g->filterlist = g_list_append(g->filterlist, f);
555}
556
557void owl_global_remove_filter(owl_global *g, const char *name) {
558  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
559  if (e)
560    owl_global_delete_filter_ent(e);
561}
562
563/* nextmsgid */
564
565int owl_global_get_nextmsgid(owl_global *g) {
566  return(g->nextmsgid++);
567}
568
569/* current view */
570
571owl_view *owl_global_get_current_view(owl_global *g) {
572  return(&(g->current_view));
573}
574
575owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
576  return(&(g->cpmgr));
577}
578
579/* puntlist */
580
581GPtrArray *owl_global_get_puntlist(owl_global *g) {
582  return g->puntlist;
583}
584
585int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
586  const GPtrArray *pl;
587  int i;
588
589  pl = owl_global_get_puntlist(g);
590  for (i = 0; i < pl->len; i++) {
591    if (owl_filter_message_match(pl->pdata[i], m)) return 1;
592  }
593  return 0;
594}
595
596int owl_global_should_followlast(owl_global *g) {
597  const owl_view *v;
598 
599  if (!owl_global_is__followlast(g)) return(0);
600 
601  v=owl_global_get_current_view(g);
602 
603  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
604  return(0);
605}
606
607int owl_global_is_search_active(const owl_global *g) {
608  if (owl_regex_is_set(&g->search_re)) return(1);
609  return(0);
610}
611
612void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
613  if (owl_regex_is_set(&g->search_re)) {
614    owl_regex_cleanup(&g->search_re);
615    owl_regex_init(&g->search_re);
616  }
617  if (re != NULL)
618    owl_regex_copy(re, &g->search_re);
619  /* TODO: Emit a signal so we don't depend on the viewwin and mainwin */
620  if (owl_global_get_viewwin(g))
621    owl_viewwin_dirty(owl_global_get_viewwin(g));
622  owl_mainwin_redisplay(owl_global_get_mainwin(g));
623}
624
625const owl_regex *owl_global_get_search_re(const owl_global *g) {
626  return &g->search_re;
627}
628
629void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
630  g->newmsgproc_pid=i;
631}
632
633pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
634  return(g->newmsgproc_pid);
635}
636
637/* AIM stuff */
638
639int owl_global_is_aimloggedin(const owl_global *g)
640{
641  if (g->aim_loggedin) return(1);
642  return(0);
643}
644
645const char *owl_global_get_aim_screenname(const owl_global *g)
646{
647  if (owl_global_is_aimloggedin(g)) {
648    return (g->aim_screenname);
649  }
650  return("");
651}
652
653const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
654{
655  if (owl_global_is_aimloggedin(g)) {
656    return (g->aim_screenname_for_filters);
657  }
658  return("");
659}
660
661void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
662{
663  char *sn_escaped;
664  g->aim_loggedin=1;
665  if (g->aim_screenname) g_free(g->aim_screenname);
666  if (g->aim_screenname_for_filters) g_free(g->aim_screenname_for_filters);
667  g->aim_screenname=g_strdup(screenname);
668  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
669  g->aim_screenname_for_filters = owl_arg_quote(sn_escaped);
670  g_free(sn_escaped);
671}
672
673void owl_global_set_aimnologgedin(owl_global *g)
674{
675  g->aim_loggedin=0;
676}
677
678bool owl_global_is_doaimevents(const owl_global *g)
679{
680  return g->aim_event_source != NULL;
681}
682
683void owl_global_set_doaimevents(owl_global *g)
684{
685  if (g->aim_event_source)
686    return;
687  g->aim_event_source = owl_aim_event_source_new(owl_global_get_aimsess(g));
688  g_source_attach(g->aim_event_source, NULL);
689}
690
691void owl_global_set_no_doaimevents(owl_global *g)
692{
693  if (!g->aim_event_source)
694    return;
695  g_source_destroy(g->aim_event_source);
696  g_source_unref(g->aim_event_source);
697  g->aim_event_source = NULL;
698}
699
700aim_session_t *owl_global_get_aimsess(owl_global *g)
701{
702  return(&(g->aimsess));
703}
704
705aim_conn_t *owl_global_get_bosconn(owl_global *g)
706{
707  return(&(g->bosconn));
708}
709
710void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
711{
712  g->bosconn=*conn;
713}
714
715/* message queue */
716
717void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
718{
719  g_queue_push_tail(g->messagequeue, m);
720}
721
722/* pop off the first message and return it.  Return NULL if the queue
723 * is empty.  The caller should free the message after using it, if
724 * necessary.
725 */
726CALLER_OWN owl_message *owl_global_messagequeue_popmsg(owl_global *g)
727{
728  owl_message *out;
729
730  if (g_queue_is_empty(g->messagequeue))
731    return NULL;
732  out = g_queue_pop_head(g->messagequeue);
733  return out;
734}
735
736int owl_global_messagequeue_pending(owl_global *g)
737{
738  return !g_queue_is_empty(g->messagequeue);
739}
740
741owl_buddylist *owl_global_get_buddylist(owl_global *g)
742{
743  return(&(g->buddylist));
744}
745 
746/* style */
747
748/* Return the style with name 'name'.  If it does not exist return
749 * NULL */
750const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
751{
752  return owl_dict_find_element(&(g->styledict), name);
753}
754
755CALLER_OWN GPtrArray *owl_global_get_style_names(const owl_global *g)
756{
757  return owl_dict_get_keys(&g->styledict);
758}
759
760void owl_global_add_style(owl_global *g, owl_style *s)
761{
762  /*
763   * If we're redefining the current style, make sure to update
764   * pointers to it.
765   */
766  if(g->current_view.style
767     && !strcmp(owl_style_get_name(g->current_view.style),
768                owl_style_get_name(s)))
769    g->current_view.style = s;
770  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
771                          s, (void (*)(void *))owl_style_delete);
772}
773
774void owl_global_set_haveaim(owl_global *g)
775{
776  g->haveaim=1;
777}
778
779int owl_global_is_haveaim(const owl_global *g)
780{
781  if (g->haveaim) return(1);
782  return(0);
783}
784
785void owl_global_set_ignore_aimlogin(owl_global *g)
786{
787    g->ignoreaimlogin = 1;
788}
789
790void owl_global_unset_ignore_aimlogin(owl_global *g)
791{
792    g->ignoreaimlogin = 0;
793}
794
795int owl_global_is_ignore_aimlogin(const owl_global *g)
796{
797    return g->ignoreaimlogin;
798}
799
800void owl_global_set_havezephyr(owl_global *g)
801{
802  g->havezephyr=1;
803}
804
805int owl_global_is_havezephyr(const owl_global *g)
806{
807  if (g->havezephyr) return(1);
808  return(0);
809}
810
811owl_errqueue *owl_global_get_errqueue(owl_global *g)
812{
813  return(&(g->errqueue));
814}
815
816owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
817{
818  return(&(g->zbuddies));
819}
820
821GList **owl_global_get_zaldlist(owl_global *g)
822{
823  return &(g->zaldlist);
824}
825
826int owl_global_get_pseudologin_notify(owl_global *g)
827{
828  return g->pseudologin_notify;
829}
830
831void owl_global_set_pseudologin_notify(owl_global *g, int notify)
832{
833  g->pseudologin_notify = notify;
834}
835
836struct termios *owl_global_get_startup_tio(owl_global *g)
837{
838  return(&(g->startup_tio));
839}
840
841void owl_global_setup_default_filters(owl_global *g)
842{
843  int i;
844  static const struct {
845    const char *name;
846    const char *desc;
847  } filters[] = {
848    { "personal",
849      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" },
850    { "trash",
851      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
852    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
853    { "ping", "opcode ^ping$" },
854    { "auto", "opcode ^auto$" },
855    { "login", "not login ^none$" },
856    { "reply-lockout", "class ^mail$" },
857    { "out", "direction ^out$" },
858    { "aim", "type ^aim$" },
859    { "zephyr", "type ^zephyr$" },
860    { "none", "false" },
861    { "all", "true" },
862    { NULL, NULL }
863  };
864
865  owl_function_debugmsg("startup: creating default filters");
866
867  for (i = 0; filters[i].name != NULL; i++)
868    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
869                                                       filters[i].desc));
870}
871
872FILE *owl_global_get_debug_file_handle(owl_global *g) {
873  static char *open_file = NULL;
874  const char *filename = owl_global_get_debug_file(g);
875  if (g->debug_file == NULL ||
876      (open_file && strcmp(filename, open_file) != 0)) {
877    char *path;
878    int fd;
879
880    if (g->debug_file)
881      fclose(g->debug_file);
882
883    g->debug_file = NULL;
884
885    path = g_strdup_printf("%s.%d", filename, getpid());
886    fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600);
887    g_free(path);
888
889    if (fd >= 0)
890      g->debug_file = fdopen(fd, "a");
891
892    g_free(open_file);
893    open_file = g_strdup(filename);
894  }
895  return g->debug_file;
896}
897
898const char *owl_global_get_kill_buffer(owl_global *g) {
899  return g->kill_buffer;
900}
901
902void owl_global_set_kill_buffer(owl_global *g, const char *kill, int len) {
903  g_free(g->kill_buffer);
904  g->kill_buffer = g_strndup(kill, len);
905}
906
907static GMutex *owl_global_get_interrupt_lock(owl_global *g)
908{
909#if GLIB_CHECK_VERSION(2, 31, 0)
910  return &g->interrupt_lock;
911#else
912  return g->interrupt_lock;
913#endif
914}
915
916void owl_global_add_interrupt(owl_global *g) {
917  /* TODO: This can almost certainly be done with atomic
918   * operations. Whatever. */
919  g_mutex_lock(owl_global_get_interrupt_lock(g));
920  g->interrupt_count++;
921  g_mutex_unlock(owl_global_get_interrupt_lock(g));
922}
923
924bool owl_global_take_interrupt(owl_global *g) {
925  bool ans = false;
926  g_mutex_lock(owl_global_get_interrupt_lock(g));
927  if (g->interrupt_count > 0) {
928    ans = true;
929    g->interrupt_count--;
930  }
931  g_mutex_unlock(owl_global_get_interrupt_lock(g));
932  return ans;
933}
Note: See TracBrowser for help on using the repository browser.