source: global.c @ e2bc8ac

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