source: global.c @ 5f3168a

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