source: global.c @ d6f2d21

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