source: global.c @ 95b52d1

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