source: global.c @ 8dfb59c

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