source: global.c @ 38e2250

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