source: global.c @ fbadb37

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