source: global.c @ f5f6ec0

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