source: global.c @ f3678c3

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