source: global.c @ 38cc669

release-1.6release-1.7release-1.8release-1.9
Last change on this file since 38cc669 was 38cc669, checked in by Nelson Elhage <nelhage@ksplice.com>, 11 years ago
Create/destroy editwins rather than reusing a single one.
  • Property mode set to 100644
File size: 21.8 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 = NULL;
48
49  owl_keyhandler_init(&g->kh);
50  owl_keys_setup_keymaps(&g->kh);
51
52  owl_dict_create(&(g->filters));
53  g->filterlist = NULL;
54  owl_list_create(&(g->puntlist));
55  owl_list_create(&(g->messagequeue));
56  owl_dict_create(&(g->styledict));
57  g->curmsg_vert_offset=0;
58  g->resizepending=0;
59  g->typwinactive=0;
60  g->direction=OWL_DIRECTION_DOWNWARDS;
61  g->zaway=0;
62  if (has_colors()) {
63    g->hascolors=1;
64  }
65  g->colorpairs=COLOR_PAIRS;
66  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
67  g->debug=OWL_DEBUG;
68  owl_regex_init(&g->search_re);
69  g->starttime=time(NULL); /* assumes we call init only a start time */
70  g->lastinputtime=g->starttime;
71  g->newmsgproc_pid=0;
72 
73  owl_global_set_config_format(g, 0);
74  owl_global_set_userclue(g, OWL_USERCLUE_NONE);
75  owl_global_set_no_have_config(g);
76  owl_history_init(&(g->msghist));
77  owl_history_init(&(g->cmdhist));
78  owl_history_set_norepeats(&(g->cmdhist));
79  g->nextmsgid=0;
80
81  _owl_global_setup_windows(g);
82
83  /* Fill in some variables which don't have constant defaults */
84  /* TODO: come back later and check passwd file first */
85  g->homedir=owl_strdup(getenv("HOME"));
86
87  g->confdir = NULL;
88  g->startupfile = NULL;
89  cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
90  owl_global_set_confdir(g, cd);
91  owl_free(cd);
92
93  owl_messagelist_create(&(g->msglist));
94  owl_mainwin_init(&(g->mw));
95  owl_popwin_init(&(g->pw));
96
97  g->aim_screenname=NULL;
98  g->aim_screenname_for_filters=NULL;
99  g->aim_loggedin=0;
100  owl_buddylist_init(&(g->buddylist));
101
102  g->havezephyr=0;
103  g->haveaim=0;
104  g->ignoreaimlogin=0;
105  owl_global_set_no_doaimevents(g);
106
107  owl_errqueue_init(&(g->errqueue));
108  g->got_err_signal=0;
109
110  owl_zbuddylist_create(&(g->zbuddies));
111
112  owl_obarray_init(&(g->obarray));
113
114  owl_message_init_fmtext_cache();
115  owl_list_create(&(g->io_dispatch_list));
116  owl_list_create(&(g->psa_list));
117  g->timerlist = NULL;
118  g->interrupted = FALSE;
119}
120
121/* Called once perl has been initialized */
122void owl_global_complete_setup(owl_global *g)
123{
124  owl_cmddict_setup(&(g->cmds));
125}
126
127/* If *pan does not exist, we create a new panel, otherwise we replace the
128   window in *pan with win.
129
130   libpanel PANEL objects cannot exist without owner a valid window. This
131   maintains the invariant for _owl_global_setup_windows. */
132void _owl_panel_set_window(PANEL **pan, WINDOW *win)
133{
134  WINDOW *oldwin;
135
136  if (win == NULL) {
137    owl_function_debugmsg("_owl_panel_set_window: passed NULL win (failed to allocate?)\n");
138    endwin();
139    exit(50);
140  }
141
142  if (*pan) {
143    oldwin = panel_window(*pan);
144    replace_panel(*pan, win);
145    delwin(oldwin);
146  } else {
147    *pan = new_panel(win);
148  }
149}
150
151void _owl_global_setup_windows(owl_global *g) {
152  int cols, typwin_lines;
153
154  cols=g->cols;
155  typwin_lines=owl_global_get_typwin_lines(g);
156
157  /* set the new window sizes */
158  g->recwinlines=g->lines-(typwin_lines+2);
159  if (g->recwinlines<0) {
160    /* gotta deal with this */
161    g->recwinlines=0;
162  }
163
164  owl_function_debugmsg("_owl_global_setup_windows: about to call newwin(%i, %i, 0, 0)\n", g->recwinlines, cols);
165
166  /* create the new windows */
167  _owl_panel_set_window(&g->recpan, newwin(g->recwinlines, cols, 0, 0));
168  _owl_panel_set_window(&g->seppan, newwin(1, cols, g->recwinlines, 0));
169  _owl_panel_set_window(&g->msgpan, newwin(1, cols, g->recwinlines+1, 0));
170  _owl_panel_set_window(&g->typpan, newwin(typwin_lines, cols, g->recwinlines+2, 0));
171
172  if (g->tw)
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, int style, owl_history *hist) {
371  int d;
372  d = owl_global_get_typewindelta(g);
373  if (d > 0)
374      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
375
376  g->tw = owl_editwin_new(owl_global_get_curs_typwin(g),
377                          owl_global_get_typwin_lines(g),
378                          g->cols,
379                          style,
380                          hist);
381  g->typwinactive=1;
382}
383
384void owl_global_set_typwin_inactive(owl_global *g) {
385  int d = owl_global_get_typewindelta(g);
386  if (d > 0)
387      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
388
389  g->typwinactive=0;
390
391  owl_editwin_delete(g->tw);
392  werase(owl_global_get_curs_typwin(g));
393  g->tw = NULL;
394}
395
396/* resize */
397
398void owl_global_set_resize_pending(owl_global *g) {
399  g->resizepending=1;
400}
401
402const char *owl_global_get_homedir(const owl_global *g) {
403  if (g->homedir) return(g->homedir);
404  return("/");
405}
406
407const char *owl_global_get_confdir(const owl_global *g) {
408  if (g->confdir) return(g->confdir);
409  return("/");
410}
411
412/*
413 * Setting this also sets startupfile to confdir/startup
414 */
415void owl_global_set_confdir(owl_global *g, const char *cd) {
416  owl_free(g->confdir);
417  g->confdir = owl_strdup(cd);
418  owl_free(g->startupfile);
419  g->startupfile = owl_sprintf("%s/startup", cd);
420}
421
422const char *owl_global_get_startupfile(const owl_global *g) {
423  if(g->startupfile) return(g->startupfile);
424  return("/");
425}
426
427int owl_global_get_direction(const owl_global *g) {
428  return(g->direction);
429}
430
431void owl_global_set_direction_downwards(owl_global *g) {
432  g->direction=OWL_DIRECTION_DOWNWARDS;
433}
434
435void owl_global_set_direction_upwards(owl_global *g) {
436  g->direction=OWL_DIRECTION_UPWARDS;
437}
438
439/* perl stuff */
440
441void owl_global_set_perlinterp(owl_global *g, void *p) {
442  g->perl=p;
443}
444
445void *owl_global_get_perlinterp(const owl_global *g) {
446  return(g->perl);
447}
448
449int owl_global_is_config_format(const owl_global *g) {
450  if (g->config_format) return(1);
451  return(0);
452}
453
454void owl_global_set_config_format(owl_global *g, int state) {
455  if (state==1) {
456    g->config_format=1;
457  } else {
458    g->config_format=0;
459  }
460}
461
462void owl_global_set_have_config(owl_global *g) {
463  g->haveconfig=1;
464}
465
466void owl_global_set_no_have_config(owl_global *g) {
467  g->haveconfig=0;
468}
469
470int owl_global_have_config(owl_global *g) {
471  if (g->haveconfig) return(1);
472  return(0);
473}
474
475void owl_global_resize(owl_global *g, int x, int y) {
476  /* resize the screen.  If x or y is 0 use the terminal size */
477  struct winsize size;
478   
479  if (!g->resizepending) return;
480
481  if (!isendwin()) {
482    endwin();
483  }
484
485  /* get the new size */
486  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
487  if (x==0) {
488    if (size.ws_row) {
489      g->lines=size.ws_row;
490    } else {
491      g->lines=LINES;
492    } 
493  } else {
494      g->lines=x;
495  }
496
497  if (y==0) {
498    if (size.ws_col) {
499      g->cols=size.ws_col;
500    } else {
501      g->cols=COLS;
502    } 
503  } else {
504    g->cols=y;
505  }
506
507#ifdef HAVE_RESIZETERM
508  resizeterm(size.ws_row, size.ws_col);
509#endif
510
511  /* re-initialize the windows */
512  _owl_global_setup_windows(g);
513
514  /* in case any styles rely on the current width */
515  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
516
517  /* recalculate the topmsg to make sure the current message is on
518   * screen */
519  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
520
521  /* refresh stuff */
522  g->needrefresh=1;
523  owl_mainwin_redisplay(&(g->mw));
524  sepbar(NULL);
525  if (g->tw)
526      owl_editwin_redisplay(g->tw);
527  owl_function_full_redisplay();
528
529  owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col);
530  owl_function_makemsg("");
531  g->resizepending=0;
532}
533
534/* debug */
535
536int owl_global_is_debug_fast(const owl_global *g) {
537  if (g->debug) return(1);
538  return(0);
539}
540
541/* starttime */
542
543time_t owl_global_get_starttime(const owl_global *g) {
544  return(g->starttime);
545}
546
547time_t owl_global_get_runtime(const owl_global *g) {
548  return(time(NULL)-g->starttime);
549}
550
551time_t owl_global_get_lastinputtime(const owl_global *g) {
552  return(g->lastinputtime);
553}
554
555void owl_global_set_lastinputtime(owl_global *g, time_t time) {
556  g->lastinputtime = time;
557}
558
559time_t owl_global_get_idletime(const owl_global *g) {
560  return(time(NULL)-g->lastinputtime);
561}
562
563const char *owl_global_get_hostname(const owl_global *g) {
564  if (g->thishost) return(g->thishost);
565  return("");
566}
567
568/* userclue */
569
570void owl_global_set_userclue(owl_global *g, int clue) {
571  g->userclue=clue;
572}
573
574void owl_global_add_userclue(owl_global *g, int clue) {
575  g->userclue|=clue;
576}
577
578int owl_global_get_userclue(const owl_global *g) {
579  return(g->userclue);
580}
581
582int owl_global_is_userclue(const owl_global *g, int clue) {
583  if (g->userclue & clue) return(1);
584  return(0);
585}
586
587/* viewwin */
588
589owl_viewwin *owl_global_get_viewwin(owl_global *g) {
590  return(&(g->vw));
591}
592
593
594/* vert offset */
595
596int owl_global_get_curmsg_vert_offset(const owl_global *g) {
597  return(g->curmsg_vert_offset);
598}
599
600void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
601  g->curmsg_vert_offset=i;
602}
603
604/* startup args */
605
606void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
607  int i, len;
608
609  if (g->startupargs) owl_free(g->startupargs);
610 
611  len=0;
612  for (i=0; i<argc; i++) {
613    len+=strlen(argv[i])+5;
614  }
615  g->startupargs=owl_malloc(len+5);
616
617  strcpy(g->startupargs, "");
618  for (i=0; i<argc; i++) {
619    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
620  }
621  g->startupargs[strlen(g->startupargs)-1]='\0';
622}
623
624const char *owl_global_get_startupargs(const owl_global *g) {
625  if (g->startupargs) return(g->startupargs);
626  return("");
627}
628
629/* history */
630
631owl_history *owl_global_get_msg_history(owl_global *g) {
632  return(&(g->msghist));
633}
634
635owl_history *owl_global_get_cmd_history(owl_global *g) {
636  return(&(g->cmdhist));
637}
638
639/* filterlist */
640typedef struct _owl_global_filter_ent {         /* noproto */
641  owl_global *g;
642  owl_filter *f;
643} owl_global_filter_ent;
644
645owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
646  owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name);
647  if (e) return e->f;
648  return NULL;
649}
650
651static void owl_global_delete_filter_ent(void *data)
652{
653  owl_global_filter_ent *e = data;
654  e->g->filterlist = g_list_remove(e->g->filterlist, e->f);
655  owl_filter_delete(e->f);
656  owl_free(e);
657}
658
659void owl_global_add_filter(owl_global *g, owl_filter *f) {
660  owl_global_filter_ent *e = owl_malloc(sizeof *e);
661  e->g = g;
662  e->f = f;
663
664  owl_dict_insert_element(&(g->filters), owl_filter_get_name(f),
665                          e, owl_global_delete_filter_ent);
666  g->filterlist = g_list_append(g->filterlist, f);
667}
668
669void owl_global_remove_filter(owl_global *g, const char *name) {
670  owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name);
671  if (e)
672    owl_global_delete_filter_ent(e);
673}
674
675/* nextmsgid */
676
677int owl_global_get_nextmsgid(owl_global *g) {
678  return(g->nextmsgid++);
679}
680
681/* current view */
682
683owl_view *owl_global_get_current_view(owl_global *g) {
684  return(&(g->current_view));
685}
686
687/* has colors */
688
689int owl_global_get_hascolors(const owl_global *g) {
690  if (g->hascolors) return(1);
691  return(0);
692}
693
694/* color pairs */
695
696int owl_global_get_colorpairs(const owl_global *g) {
697  return(g->colorpairs);
698}
699
700owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
701  return(&(g->cpmgr));
702}
703
704/* puntlist */
705
706owl_list *owl_global_get_puntlist(owl_global *g) {
707  return(&(g->puntlist));
708}
709
710int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
711  const owl_list *pl;
712  int i, j;
713
714  pl=owl_global_get_puntlist(g);
715  j=owl_list_get_size(pl);
716  for (i=0; i<j; i++) {
717    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
718  }
719  return(0);
720}
721
722int owl_global_should_followlast(owl_global *g) {
723  const owl_view *v;
724 
725  if (!owl_global_is__followlast(g)) return(0);
726 
727  v=owl_global_get_current_view(g);
728 
729  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
730  return(0);
731}
732
733int owl_global_is_search_active(const owl_global *g) {
734  if (owl_regex_is_set(&g->search_re)) return(1);
735  return(0);
736}
737
738void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
739  if (owl_regex_is_set(&g->search_re)) {
740    owl_regex_cleanup(&g->search_re);
741    owl_regex_init(&g->search_re);
742  }
743  if (re != NULL)
744    owl_regex_copy(re, &g->search_re);
745}
746
747const owl_regex *owl_global_get_search_re(const owl_global *g) {
748  return &g->search_re;
749}
750
751void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
752  g->newmsgproc_pid=i;
753}
754
755pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
756  return(g->newmsgproc_pid);
757}
758
759/* AIM stuff */
760
761int owl_global_is_aimloggedin(const owl_global *g)
762{
763  if (g->aim_loggedin) return(1);
764  return(0);
765}
766
767const char *owl_global_get_aim_screenname(const owl_global *g)
768{
769  if (owl_global_is_aimloggedin(g)) {
770    return (g->aim_screenname);
771  }
772  return("");
773}
774
775const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
776{
777  if (owl_global_is_aimloggedin(g)) {
778    return (g->aim_screenname_for_filters);
779  }
780  return("");
781}
782
783void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
784{
785  char *sn_escaped;
786  const char *quote;
787  g->aim_loggedin=1;
788  if (g->aim_screenname) owl_free(g->aim_screenname);
789  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
790  g->aim_screenname=owl_strdup(screenname);
791  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
792  quote = owl_getquoting(sn_escaped);
793  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
794  owl_free(sn_escaped);
795}
796
797void owl_global_set_aimnologgedin(owl_global *g)
798{
799  g->aim_loggedin=0;
800}
801
802int owl_global_is_doaimevents(const owl_global *g)
803{
804  if (g->aim_doprocessing) return(1);
805  return(0);
806}
807
808void owl_global_set_doaimevents(owl_global *g)
809{
810  g->aim_doprocessing=1;
811}
812
813void owl_global_set_no_doaimevents(owl_global *g)
814{
815  g->aim_doprocessing=0;
816}
817
818aim_session_t *owl_global_get_aimsess(owl_global *g)
819{
820  return(&(g->aimsess));
821}
822
823aim_conn_t *owl_global_get_bosconn(owl_global *g)
824{
825  return(&(g->bosconn));
826}
827
828void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
829{
830  g->bosconn=*conn;
831}
832
833/* message queue */
834
835void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
836{
837  owl_list_append_element(&(g->messagequeue), m);
838}
839
840/* pop off the first message and return it.  Return NULL if the queue
841 * is empty.  The caller should free the message after using it, if
842 * necessary.
843 */
844owl_message *owl_global_messagequeue_popmsg(owl_global *g)
845{
846  owl_message *out;
847
848  if (owl_list_get_size(&(g->messagequeue))==0) return(NULL);
849  out=owl_list_get_element(&(g->messagequeue), 0);
850  owl_list_remove_element(&(g->messagequeue), 0);
851  return(out);
852}
853
854int owl_global_messagequeue_pending(owl_global *g)
855{
856  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
857  return(1);
858}
859
860owl_buddylist *owl_global_get_buddylist(owl_global *g)
861{
862  return(&(g->buddylist));
863}
864 
865/* style */
866
867/* Return the style with name 'name'.  If it does not exist return
868 * NULL */
869const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
870{
871  return owl_dict_find_element(&(g->styledict), name);
872}
873
874/* creates a list and fills it in with keys.  duplicates the keys,
875 * so they will need to be freed by the caller. */
876int owl_global_get_style_names(const owl_global *g, owl_list *l) {
877  return owl_dict_get_keys(&(g->styledict), l);
878}
879
880void owl_global_add_style(owl_global *g, owl_style *s)
881{
882  /*
883   * If we're redefining the current style, make sure to update
884   * pointers to it.
885   */
886  if(g->current_view.style
887     && !strcmp(owl_style_get_name(g->current_view.style),
888                owl_style_get_name(s)))
889    g->current_view.style = s;
890  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
891                          s, (void (*)(void *))owl_style_delete);
892}
893
894void owl_global_set_haveaim(owl_global *g)
895{
896  g->haveaim=1;
897}
898
899int owl_global_is_haveaim(const owl_global *g)
900{
901  if (g->haveaim) return(1);
902  return(0);
903}
904
905void owl_global_set_ignore_aimlogin(owl_global *g)
906{
907    g->ignoreaimlogin = 1;
908}
909
910void owl_global_unset_ignore_aimlogin(owl_global *g)
911{
912    g->ignoreaimlogin = 0;
913}
914
915int owl_global_is_ignore_aimlogin(const owl_global *g)
916{
917    return g->ignoreaimlogin;
918}
919
920void owl_global_set_havezephyr(owl_global *g)
921{
922  g->havezephyr=1;
923}
924
925int owl_global_is_havezephyr(const owl_global *g)
926{
927  if (g->havezephyr) return(1);
928  return(0);
929}
930
931owl_errqueue *owl_global_get_errqueue(owl_global *g)
932{
933  return(&(g->errqueue));
934}
935
936void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
937{
938  g->got_err_signal = signum;
939  if (siginfo) {
940    g->err_signal_info = *siginfo;
941  } else {
942    memset(&(g->err_signal_info), 0, sizeof(siginfo_t));
943  }
944}
945
946int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
947{
948  int signum;
949  if (siginfo && g->got_err_signal) {
950    *siginfo = g->err_signal_info;
951  } 
952  signum = g->got_err_signal;
953  g->got_err_signal = 0;
954  return signum;
955}
956
957
958owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
959{
960  return(&(g->zbuddies));
961}
962
963struct termios *owl_global_get_startup_tio(owl_global *g)
964{
965  return(&(g->startup_tio));
966}
967
968const char * owl_global_intern(owl_global *g, const char * string)
969{
970  return owl_obarray_insert(&(g->obarray), string);
971}
972
973owl_list *owl_global_get_io_dispatch_list(owl_global *g)
974{
975  return &(g->io_dispatch_list);
976}
977
978owl_list *owl_global_get_psa_list(owl_global *g)
979{
980  return &(g->psa_list);
981}
982
983GList **owl_global_get_timerlist(owl_global *g)
984{
985  return &(g->timerlist);
986}
987
988int owl_global_is_interrupted(const owl_global *g) {
989  return g->interrupted;
990}
991
992void owl_global_set_interrupted(owl_global *g) {
993  g->interrupted = 1;
994}
995
996void owl_global_unset_interrupted(owl_global *g) {
997  g->interrupted = 0;
998}
Note: See TracBrowser for help on using the repository browser.