source: global.c @ df0138f

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