source: global.c @ cb81570

release-1.7release-1.8release-1.9
Last change on this file since cb81570 was cb81570, checked in by David Benjamin <davidben@mit.edu>, 11 years ago
Add a separate owl_context_new and remove owl_context_init The latter is unused anyway.
  • Property mode set to 100644
File size: 22.3 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/* underlying owl_windows */
285
286owl_window *owl_global_get_typwin_window(const owl_global *g) {
287  return g->mainpanel.typwin;
288}
289
290/* typwin */
291
292/* Gets the currently active typwin out of the current context. */
293owl_editwin *owl_global_current_typwin(const owl_global *g) {
294  owl_context *ctx = owl_global_get_context(g);
295  /* Get the current editwin from the context. */
296  if (ctx && owl_context_matches(ctx, OWL_CTX_TYPWIN)) {
297    return owl_context_get_data(ctx);
298  }
299  return NULL;
300}
301
302/* variable dictionary */
303
304owl_vardict *owl_global_get_vardict(owl_global *g) {
305  return &(g->vars);
306}
307
308/* command dictionary */
309
310owl_cmddict *owl_global_get_cmddict(owl_global *g) {
311  return &(g->cmds);
312}
313
314/* rightshift */
315
316void owl_global_set_rightshift(owl_global *g, int i) {
317  g->rightshift = i;
318  owl_mainwin_redisplay(owl_global_get_mainwin(g));
319}
320
321int owl_global_get_rightshift(const owl_global *g) {
322  return(g->rightshift);
323}
324
325/* typwin */
326
327owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) {
328  int d;
329  d = owl_global_get_typewindelta(g);
330  if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE)
331      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
332
333  if (g->typwin_erase_id) {
334    g_signal_handler_disconnect(owl_global_get_typwin_window(g), g->typwin_erase_id);
335    g->typwin_erase_id = 0;
336  }
337
338  g->tw = owl_editwin_new(owl_global_get_typwin_window(g),
339                          owl_global_get_typwin_lines(g),
340                          g->cols,
341                          style,
342                          hist);
343  return g->tw;
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(owl_global_get_typwin_window(g), "redraw", G_CALLBACK(owl_window_erase_cb), NULL);
354  }
355  owl_window_dirty(owl_global_get_typwin_window(g));
356
357  g->tw = NULL;
358}
359
360/* resize */
361
362void owl_global_set_resize_pending(owl_global *g) {
363  g->resizepending=1;
364}
365
366const char *owl_global_get_homedir(const owl_global *g) {
367  if (g->homedir) return(g->homedir);
368  return("/");
369}
370
371const char *owl_global_get_confdir(const owl_global *g) {
372  if (g->confdir) return(g->confdir);
373  return("/");
374}
375
376/*
377 * Setting this also sets startupfile to confdir/startup
378 */
379void owl_global_set_confdir(owl_global *g, const char *cd) {
380  owl_free(g->confdir);
381  g->confdir = owl_strdup(cd);
382  owl_free(g->startupfile);
383  g->startupfile = owl_sprintf("%s/startup", cd);
384}
385
386const char *owl_global_get_startupfile(const owl_global *g) {
387  if(g->startupfile) return(g->startupfile);
388  return("/");
389}
390
391int owl_global_get_direction(const owl_global *g) {
392  return(g->direction);
393}
394
395void owl_global_set_direction_downwards(owl_global *g) {
396  g->direction=OWL_DIRECTION_DOWNWARDS;
397}
398
399void owl_global_set_direction_upwards(owl_global *g) {
400  g->direction=OWL_DIRECTION_UPWARDS;
401}
402
403/* perl stuff */
404
405void owl_global_set_perlinterp(owl_global *g, void *p) {
406  g->perl=p;
407}
408
409void *owl_global_get_perlinterp(const owl_global *g) {
410  return(g->perl);
411}
412
413int owl_global_is_config_format(const owl_global *g) {
414  if (g->config_format) return(1);
415  return(0);
416}
417
418void owl_global_set_config_format(owl_global *g, int state) {
419  if (state==1) {
420    g->config_format=1;
421  } else {
422    g->config_format=0;
423  }
424}
425
426void owl_global_set_have_config(owl_global *g) {
427  g->haveconfig=1;
428}
429
430void owl_global_set_no_have_config(owl_global *g) {
431  g->haveconfig=0;
432}
433
434int owl_global_have_config(owl_global *g) {
435  if (g->haveconfig) return(1);
436  return(0);
437}
438
439/*
440 * Compute the size of the terminal. Try a ioctl, fallback to other stuff on
441 * fail.
442 */
443void owl_global_get_terminal_size(int *lines, int *cols) {
444  struct winsize size;
445  /* get the new size */
446  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
447  if (size.ws_row) {
448    *lines = size.ws_row;
449  } else {
450    *lines = LINES;
451  }
452
453  if (size.ws_col) {
454    *cols = size.ws_col;
455  } else {
456    *cols = COLS;
457  }
458}
459
460void owl_global_check_resize(owl_global *g) {
461  /* resize the screen.  If lines or cols is 0 use the terminal size */
462  if (!g->resizepending) return;
463  g->resizepending = 0;
464
465  owl_global_get_terminal_size(&g->lines, &g->cols);
466  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
467
468  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
469}
470
471/* debug */
472
473int owl_global_is_debug_fast(const owl_global *g) {
474  if (g->debug) return(1);
475  return(0);
476}
477
478/* starttime */
479
480time_t owl_global_get_starttime(const owl_global *g) {
481  return(g->starttime);
482}
483
484time_t owl_global_get_runtime(const owl_global *g) {
485  return(time(NULL)-g->starttime);
486}
487
488time_t owl_global_get_lastinputtime(const owl_global *g) {
489  return(g->lastinputtime);
490}
491
492void owl_global_set_lastinputtime(owl_global *g, time_t time) {
493  g->lastinputtime = time;
494}
495
496time_t owl_global_get_idletime(const owl_global *g) {
497  return(time(NULL)-g->lastinputtime);
498}
499
500const char *owl_global_get_hostname(const owl_global *g) {
501  if (g->thishost) return(g->thishost);
502  return("");
503}
504
505/* viewwin */
506
507owl_viewwin *owl_global_get_viewwin(owl_global *g) {
508  return g->vw;
509}
510
511void owl_global_set_viewwin(owl_global *g, owl_viewwin *vw) {
512  g->vw = vw;
513}
514
515
516/* vert offset */
517
518int owl_global_get_curmsg_vert_offset(const owl_global *g) {
519  return(g->curmsg_vert_offset);
520}
521
522void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
523  g->curmsg_vert_offset = i;
524}
525
526/* startup args */
527
528void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
529  int i, len;
530
531  if (g->startupargs) owl_free(g->startupargs);
532 
533  len=0;
534  for (i=0; i<argc; i++) {
535    len+=strlen(argv[i])+5;
536  }
537  g->startupargs=owl_malloc(len+5);
538
539  strcpy(g->startupargs, "");
540  for (i=0; i<argc; i++) {
541    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
542  }
543  g->startupargs[strlen(g->startupargs)-1]='\0';
544}
545
546const char *owl_global_get_startupargs(const owl_global *g) {
547  if (g->startupargs) return(g->startupargs);
548  return("");
549}
550
551/* history */
552
553owl_history *owl_global_get_msg_history(owl_global *g) {
554  return(&(g->msghist));
555}
556
557owl_history *owl_global_get_cmd_history(owl_global *g) {
558  return(&(g->cmdhist));
559}
560
561/* filterlist */
562typedef struct _owl_global_filter_ent {         /* noproto */
563  owl_global *g;
564  owl_filter *f;
565} owl_global_filter_ent;
566
567owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
568  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
569  if (e) return e->f;
570  return NULL;
571}
572
573static void owl_global_delete_filter_ent(void *data)
574{
575  owl_global_filter_ent *e = data;
576  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
577  owl_filter_delete(e->f);
578  owl_free(e);
579}
580
581void owl_global_add_filter(owl_global *g, owl_filter *f) {
582  owl_global_filter_ent *e = owl_malloc(sizeof *e);
583  e->g = g;
584  e->f = f;
585
586  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
587                          e, owl_global_delete_filter_ent);
588  g->filterlist = g_list_append(g->filterlist, f);
589}
590
591void owl_global_remove_filter(owl_global *g, const char *name) {
592  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
593  if (e)
594    owl_global_delete_filter_ent(e);
595}
596
597/* nextmsgid */
598
599int owl_global_get_nextmsgid(owl_global *g) {
600  return(g->nextmsgid++);
601}
602
603/* current view */
604
605owl_view *owl_global_get_current_view(owl_global *g) {
606  return(&(g->current_view));
607}
608
609/* has colors */
610
611int owl_global_get_hascolors(const owl_global *g) {
612  if (g->hascolors) return(1);
613  return(0);
614}
615
616/* color pairs */
617
618int owl_global_get_colorpairs(const owl_global *g) {
619  return(g->colorpairs);
620}
621
622owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
623  return(&(g->cpmgr));
624}
625
626/* puntlist */
627
628owl_list *owl_global_get_puntlist(owl_global *g) {
629  return(&(g->puntlist));
630}
631
632int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
633  const owl_list *pl;
634  int i, j;
635
636  pl=owl_global_get_puntlist(g);
637  j=owl_list_get_size(pl);
638  for (i=0; i<j; i++) {
639    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
640  }
641  return(0);
642}
643
644int owl_global_should_followlast(owl_global *g) {
645  const owl_view *v;
646 
647  if (!owl_global_is__followlast(g)) return(0);
648 
649  v=owl_global_get_current_view(g);
650 
651  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
652  return(0);
653}
654
655int owl_global_is_search_active(const owl_global *g) {
656  if (owl_regex_is_set(&g->search_re)) return(1);
657  return(0);
658}
659
660void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
661  if (owl_regex_is_set(&g->search_re)) {
662    owl_regex_cleanup(&g->search_re);
663    owl_regex_init(&g->search_re);
664  }
665  if (re != NULL)
666    owl_regex_copy(re, &g->search_re);
667  /* TODO: Emit a signal so we don't depend on the viewwin here. */
668  if (owl_global_get_viewwin(g))
669    owl_viewwin_dirty(owl_global_get_viewwin(g));
670}
671
672const owl_regex *owl_global_get_search_re(const owl_global *g) {
673  return &g->search_re;
674}
675
676void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
677  g->newmsgproc_pid=i;
678}
679
680pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
681  return(g->newmsgproc_pid);
682}
683
684/* AIM stuff */
685
686int owl_global_is_aimloggedin(const owl_global *g)
687{
688  if (g->aim_loggedin) return(1);
689  return(0);
690}
691
692const char *owl_global_get_aim_screenname(const owl_global *g)
693{
694  if (owl_global_is_aimloggedin(g)) {
695    return (g->aim_screenname);
696  }
697  return("");
698}
699
700const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
701{
702  if (owl_global_is_aimloggedin(g)) {
703    return (g->aim_screenname_for_filters);
704  }
705  return("");
706}
707
708void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
709{
710  char *sn_escaped;
711  const char *quote;
712  g->aim_loggedin=1;
713  if (g->aim_screenname) owl_free(g->aim_screenname);
714  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
715  g->aim_screenname=owl_strdup(screenname);
716  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
717  quote = owl_getquoting(sn_escaped);
718  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
719  owl_free(sn_escaped);
720}
721
722void owl_global_set_aimnologgedin(owl_global *g)
723{
724  g->aim_loggedin=0;
725}
726
727int owl_global_is_doaimevents(const owl_global *g)
728{
729  if (g->aim_doprocessing) return(1);
730  return(0);
731}
732
733void owl_global_set_doaimevents(owl_global *g)
734{
735  g->aim_doprocessing=1;
736}
737
738void owl_global_set_no_doaimevents(owl_global *g)
739{
740  g->aim_doprocessing=0;
741}
742
743aim_session_t *owl_global_get_aimsess(owl_global *g)
744{
745  return(&(g->aimsess));
746}
747
748aim_conn_t *owl_global_get_bosconn(owl_global *g)
749{
750  return(&(g->bosconn));
751}
752
753void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
754{
755  g->bosconn=*conn;
756}
757
758/* message queue */
759
760void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
761{
762  g_queue_push_tail(g->messagequeue, m);
763}
764
765/* pop off the first message and return it.  Return NULL if the queue
766 * is empty.  The caller should free the message after using it, if
767 * necessary.
768 */
769owl_message *owl_global_messagequeue_popmsg(owl_global *g)
770{
771  owl_message *out;
772
773  if (g_queue_is_empty(g->messagequeue))
774    return NULL;
775  out = g_queue_pop_head(g->messagequeue);
776  return out;
777}
778
779int owl_global_messagequeue_pending(owl_global *g)
780{
781  return !g_queue_is_empty(g->messagequeue);
782}
783
784owl_buddylist *owl_global_get_buddylist(owl_global *g)
785{
786  return(&(g->buddylist));
787}
788 
789/* style */
790
791/* Return the style with name 'name'.  If it does not exist return
792 * NULL */
793const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
794{
795  return owl_dict_find_element(&(g->styledict), name);
796}
797
798/* creates a list and fills it in with keys.  duplicates the keys,
799 * so they will need to be freed by the caller. */
800int owl_global_get_style_names(const owl_global *g, owl_list *l) {
801  return owl_dict_get_keys(&(g->styledict), l);
802}
803
804void owl_global_add_style(owl_global *g, owl_style *s)
805{
806  /*
807   * If we're redefining the current style, make sure to update
808   * pointers to it.
809   */
810  if(g->current_view.style
811     && !strcmp(owl_style_get_name(g->current_view.style),
812                owl_style_get_name(s)))
813    g->current_view.style = s;
814  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
815                          s, (void (*)(void *))owl_style_delete);
816}
817
818void owl_global_set_haveaim(owl_global *g)
819{
820  g->haveaim=1;
821}
822
823int owl_global_is_haveaim(const owl_global *g)
824{
825  if (g->haveaim) return(1);
826  return(0);
827}
828
829void owl_global_set_ignore_aimlogin(owl_global *g)
830{
831    g->ignoreaimlogin = 1;
832}
833
834void owl_global_unset_ignore_aimlogin(owl_global *g)
835{
836    g->ignoreaimlogin = 0;
837}
838
839int owl_global_is_ignore_aimlogin(const owl_global *g)
840{
841    return g->ignoreaimlogin;
842}
843
844void owl_global_set_havezephyr(owl_global *g)
845{
846  g->havezephyr=1;
847}
848
849int owl_global_is_havezephyr(const owl_global *g)
850{
851  if (g->havezephyr) return(1);
852  return(0);
853}
854
855owl_errqueue *owl_global_get_errqueue(owl_global *g)
856{
857  return(&(g->errqueue));
858}
859
860void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
861{
862  g->got_err_signal = signum;
863  if (siginfo) {
864    g->err_signal_info = *siginfo;
865  } else {
866    siginfo_t si;
867    memset(&si, 0, sizeof(si));
868    g->err_signal_info = si;
869  }
870}
871
872int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
873{
874  int signum;
875  if (siginfo && g->got_err_signal) {
876    *siginfo = g->err_signal_info;
877  } 
878  signum = g->got_err_signal;
879  g->got_err_signal = 0;
880  return signum;
881}
882
883
884owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
885{
886  return(&(g->zbuddies));
887}
888
889GList **owl_global_get_zaldlist(owl_global *g)
890{
891  return &(g->zaldlist);
892}
893
894int owl_global_get_pseudologin_notify(owl_global *g)
895{
896  return g->pseudologin_notify;
897}
898
899void owl_global_set_pseudologin_notify(owl_global *g, int notify)
900{
901  g->pseudologin_notify = notify;
902}
903
904struct termios *owl_global_get_startup_tio(owl_global *g)
905{
906  return(&(g->startup_tio));
907}
908
909owl_list *owl_global_get_io_dispatch_list(owl_global *g)
910{
911  return &(g->io_dispatch_list);
912}
913
914owl_list *owl_global_get_psa_list(owl_global *g)
915{
916  return &(g->psa_list);
917}
918
919GList **owl_global_get_timerlist(owl_global *g)
920{
921  return &(g->timerlist);
922}
923
924int owl_global_is_interrupted(const owl_global *g) {
925  return g->interrupted;
926}
927
928void owl_global_set_interrupted(owl_global *g) {
929  g->interrupted = 1;
930}
931
932void owl_global_unset_interrupted(owl_global *g) {
933  g->interrupted = 0;
934}
935
936void owl_global_setup_default_filters(owl_global *g)
937{
938  int i;
939  static const struct {
940    const char *name;
941    const char *desc;
942  } filters[] = {
943    { "personal",
944      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" },
945    { "trash",
946      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
947    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
948    { "ping", "opcode ^ping$" },
949    { "auto", "opcode ^auto$" },
950    { "login", "not login ^none$" },
951    { "reply-lockout", "class ^noc or class ^mail$" },
952    { "out", "direction ^out$" },
953    { "aim", "type ^aim$" },
954    { "zephyr", "type ^zephyr$" },
955    { "none", "false" },
956    { "all", "true" },
957    { NULL, NULL }
958  };
959
960  owl_function_debugmsg("startup: creating default filters");
961
962  for (i = 0; filters[i].name != NULL; i++)
963    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
964                                                       filters[i].desc));
965}
966
967FILE *owl_global_get_debug_file_handle(owl_global *g) {
968  static char *open_file = NULL;
969  const char *filename = owl_global_get_debug_file(g);
970  if (g->debug_file == NULL ||
971      (open_file && strcmp(filename, open_file) != 0)) {
972    char *path;
973    int fd;
974
975    if (g->debug_file)
976      fclose(g->debug_file);
977
978    g->debug_file = NULL;
979
980    path = owl_sprintf("%s.%d", filename, getpid());
981    fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600);
982    owl_free(path);
983
984    if (fd >= 0)
985      g->debug_file = fdopen(fd, "a");
986
987    owl_free(open_file);
988    open_file = owl_strdup(filename);
989  }
990  return g->debug_file;
991}
Note: See TracBrowser for help on using the repository browser.