source: global.c @ 3535a6e

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