source: global.c @ 9efa5bd

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