source: global.c @ fb6e8e3

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