source: global.c @ 08e9842

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