source: global.c @ 2cca044

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