source: global.c @ f7cf6c2

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