source: global.c @ b303ba2

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