source: global.c @ 17e2357

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