source: global.c @ 4d86e06

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 4d86e06 was d43edd2, checked in by Anders Kaseorg <andersk@mit.edu>, 15 years ago
Death to RCS keywords. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 20.3 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  g->searchactive=0;
68  g->searchstring=NULL;
69  g->starttime=time(NULL); /* assumes we call init only a start time */
70  g->lastinputtime=g->starttime;
71  g->newmsgproc_pid=0;
72 
73  owl_global_set_config_format(g, 0);
74  owl_global_set_userclue(g, OWL_USERCLUE_NONE);
75  owl_global_set_no_have_config(g);
76  owl_history_init(&(g->msghist));
77  owl_history_init(&(g->cmdhist));
78  owl_history_set_norepeats(&(g->cmdhist));
79  g->nextmsgid=0;
80
81  _owl_global_setup_windows(g);
82
83  /* Fill in some variables which don't have constant defaults */
84  /* TODO: come back later and check passwd file first */
85  g->homedir=owl_strdup(getenv("HOME"));
86
87  g->confdir = NULL;
88  g->startupfile = NULL;
89  cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
90  owl_global_set_confdir(g, cd);
91  owl_free(cd);
92
93  owl_messagelist_create(&(g->msglist));
94  owl_mainwin_init(&(g->mw));
95  owl_popwin_init(&(g->pw));
96
97  g->aim_screenname=NULL;
98  g->aim_screenname_for_filters=NULL;
99  g->aim_loggedin=0;
100  owl_buddylist_init(&(g->buddylist));
101
102  g->havezephyr=0;
103  g->haveaim=0;
104  g->ignoreaimlogin=0;
105  owl_global_set_no_doaimevents(g);
106
107  owl_errqueue_init(&(g->errqueue));
108  g->got_err_signal=0;
109
110  owl_zbuddylist_create(&(g->zbuddies));
111
112  owl_obarray_init(&(g->obarray));
113
114  owl_message_init_fmtext_cache();
115  owl_list_create(&(g->dispatchlist));
116  g->timerlist = NULL;
117  g->interrupted = 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(owl_global *g) {
172  return(g->lines);
173}
174
175int owl_global_get_cols(owl_global *g) {
176  return(g->cols);
177}
178
179int owl_global_get_recwin_lines(owl_global *g) {
180  return(g->recwinlines);
181}
182
183/* curmsg */
184
185int owl_global_get_curmsg(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(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(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  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(owl_global *g) {
249  return(g->recwin);
250}
251
252WINDOW *owl_global_get_curs_sepwin(owl_global *g) {
253  return(g->sepwin);
254}
255
256WINDOW *owl_global_get_curs_msgwin(owl_global *g) {
257  return(g->msgwin);
258}
259
260WINDOW *owl_global_get_curs_typwin(owl_global *g) {
261  return(g->typwin);
262}
263
264/* typwin */
265
266owl_editwin *owl_global_get_typwin(owl_global *g) {
267  return(g->tw);
268}
269
270/* buffercommand */
271
272void owl_global_set_buffercommand(owl_global *g, char *command) {
273  owl_editwin_set_command(owl_global_get_typwin(g), command);
274}
275
276char *owl_global_get_buffercommand(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(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(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(owl_global *g) {
322  return(g->rightshift);
323}
324
325/* typwin */
326
327int owl_global_is_typwin_active(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
354char *owl_global_get_homedir(owl_global *g) {
355  if (g->homedir) return(g->homedir);
356  return("/");
357}
358
359char *owl_global_get_confdir(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, char *cd) {
368  free(g->confdir);
369  g->confdir = owl_strdup(cd);
370  free(g->startupfile);
371  g->startupfile = owl_sprintf("%s/startup", cd);
372}
373
374char *owl_global_get_startupfile(owl_global *g) {
375  if(g->startupfile) return(g->startupfile);
376  return("/");
377}
378
379int owl_global_get_direction(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(owl_global *g) {
398  return(g->perl);
399}
400
401int owl_global_is_config_format(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(&g);
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(owl_global *g) {
502  if (g->debug) return(1);
503  return(0);
504}
505
506/* starttime */
507
508time_t owl_global_get_starttime(owl_global *g) {
509  return(g->starttime);
510}
511
512time_t owl_global_get_runtime(owl_global *g) {
513  return(time(NULL)-g->starttime);
514}
515
516time_t owl_global_get_lastinputtime(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(owl_global *g) {
525  return(time(NULL)-g->lastinputtime);
526}
527
528void owl_global_get_runtime_string(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
537char *owl_global_get_hostname(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(owl_global *g) {
553  return(g->userclue);
554}
555
556int owl_global_is_userclue(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(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, char **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
598char *owl_global_get_startupargs(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(owl_global *g, 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, 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(owl_global *g) {
667  if (g->hascolors) return(1);
668  return(0);
669}
670
671/* color pairs */
672
673int owl_global_get_colorpairs(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, owl_message *m) {
688  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  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(owl_global *g) {
711  if (g->searchactive) return(1);
712  return(0);
713}
714
715void owl_global_set_search_active(owl_global *g, char *string) {
716  g->searchactive=1;
717  if (g->searchstring != NULL) owl_free(g->searchstring);
718  g->searchstring=owl_strdup(string);
719}
720
721void owl_global_set_search_inactive(owl_global *g) {
722  g->searchactive=0;
723}
724
725char *owl_global_get_search_string(owl_global *g) {
726  if (g->searchstring==NULL) return("");
727  return(g->searchstring);
728}
729
730void owl_global_set_newmsgproc_pid(owl_global *g, int i) {
731  g->newmsgproc_pid=i;
732}
733
734int owl_global_get_newmsgproc_pid(owl_global *g) {
735  return(g->newmsgproc_pid);
736}
737
738/* AIM stuff */
739
740int owl_global_is_aimloggedin(owl_global *g)
741{
742  if (g->aim_loggedin) return(1);
743  return(0);
744}
745
746char *owl_global_get_aim_screenname(owl_global *g)
747{
748  if (owl_global_is_aimloggedin(g)) {
749    return (g->aim_screenname);
750  }
751  return("");
752}
753
754char *owl_global_get_aim_screenname_for_filters(owl_global *g)
755{
756  if (owl_global_is_aimloggedin(g)) {
757    return (g->aim_screenname_for_filters);
758  }
759  return("");
760}
761
762void owl_global_set_aimloggedin(owl_global *g, char *screenname)
763{
764  char *sn_escaped, *quote;
765  g->aim_loggedin=1;
766  if (g->aim_screenname) owl_free(g->aim_screenname);
767  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
768  g->aim_screenname=owl_strdup(screenname);
769  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
770  quote = owl_getquoting(sn_escaped);
771  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
772  owl_free(sn_escaped);
773}
774
775void owl_global_set_aimnologgedin(owl_global *g)
776{
777  g->aim_loggedin=0;
778}
779
780int owl_global_is_doaimevents(owl_global *g)
781{
782  if (g->aim_doprocessing) return(1);
783  return(0);
784}
785
786void owl_global_set_doaimevents(owl_global *g)
787{
788  g->aim_doprocessing=1;
789}
790
791void owl_global_set_no_doaimevents(owl_global *g)
792{
793  g->aim_doprocessing=0;
794}
795
796aim_session_t *owl_global_get_aimsess(owl_global *g)
797{
798  return(&(g->aimsess));
799}
800
801aim_conn_t *owl_global_get_bosconn(owl_global *g)
802{
803  return(&(g->bosconn));
804}
805
806void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
807{
808  g->bosconn=*conn;
809}
810
811/* message queue */
812
813void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
814{
815  owl_list_append_element(&(g->messagequeue), m);
816}
817
818/* pop off the first message and return it.  Return NULL if the queue
819 * is empty.  The caller should free the message after using it, if
820 * necessary.
821 */
822owl_message *owl_global_messagequeue_popmsg(owl_global *g)
823{
824  owl_message *out;
825
826  if (owl_list_get_size(&(g->messagequeue))==0) return(NULL);
827  out=owl_list_get_element(&(g->messagequeue), 0);
828  owl_list_remove_element(&(g->messagequeue), 0);
829  return(out);
830}
831
832int owl_global_messagequeue_pending(owl_global *g)
833{
834  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
835  return(1);
836}
837
838owl_buddylist *owl_global_get_buddylist(owl_global *g)
839{
840  return(&(g->buddylist));
841}
842 
843/* style */
844
845/* Return the style with name 'name'.  If it does not exist return
846 * NULL */
847owl_style *owl_global_get_style_by_name(owl_global *g, char *name)
848{
849  return owl_dict_find_element(&(g->styledict), name);
850}
851
852/* creates a list and fills it in with keys.  duplicates the keys,
853 * so they will need to be freed by the caller. */
854int owl_global_get_style_names(owl_global *g, owl_list *l) {
855  return owl_dict_get_keys(&(g->styledict), l);
856}
857
858void owl_global_add_style(owl_global *g, owl_style *s)
859{
860  /*
861   * If we're redefining the current style, make sure to update
862   * pointers to it.
863   */
864  if(g->current_view.style
865     && !strcmp(owl_style_get_name(g->current_view.style),
866                owl_style_get_name(s)))
867    g->current_view.style = s;
868  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
869                          s, (void(*)(void*))owl_style_free);
870}
871
872void owl_global_set_haveaim(owl_global *g)
873{
874  g->haveaim=1;
875}
876
877int owl_global_is_haveaim(owl_global *g)
878{
879  if (g->haveaim) return(1);
880  return(0);
881}
882
883void owl_global_set_ignore_aimlogin(owl_global *g)
884{
885    g->ignoreaimlogin = 1;
886}
887
888void owl_global_unset_ignore_aimlogin(owl_global *g)
889{
890    g->ignoreaimlogin = 0;
891}
892
893int owl_global_is_ignore_aimlogin(owl_global *g)
894{
895    return g->ignoreaimlogin;
896}
897
898void owl_global_set_havezephyr(owl_global *g)
899{
900  g->havezephyr=1;
901}
902
903int owl_global_is_havezephyr(owl_global *g)
904{
905  if (g->havezephyr) return(1);
906  return(0);
907}
908
909owl_errqueue *owl_global_get_errqueue(owl_global *g)
910{
911  return(&(g->errqueue));
912}
913
914void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
915{
916  g->got_err_signal = signum;
917  if (siginfo) {
918    g->err_signal_info = *siginfo;
919  } else {
920    memset(&(g->err_signal_info), 0, sizeof(siginfo_t));
921  }
922}
923
924int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
925{
926  int signum;
927  if (siginfo && g->got_err_signal) {
928    *siginfo = g->err_signal_info;
929  } 
930  signum = g->got_err_signal;
931  g->got_err_signal = 0;
932  return signum;
933}
934
935
936owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
937{
938  return(&(g->zbuddies));
939}
940
941struct termios *owl_global_get_startup_tio(owl_global *g)
942{
943  return(&(g->startup_tio));
944}
945
946char * owl_global_intern(owl_global *g, char * string)
947{
948  return owl_obarray_insert(&(g->obarray), string);
949}
950
951owl_list *owl_global_get_dispatchlist(owl_global *g)
952{
953  return &(g->dispatchlist);
954}
955
956GList **owl_global_get_timerlist(owl_global *g)
957{
958  return &(g->timerlist);
959}
960
961int owl_global_is_interrupted(owl_global *g) {
962  return g->interrupted;
963}
964
965void owl_global_set_interrupted(owl_global *g) {
966  g->interrupted = 1;
967}
968
969void owl_global_unset_interrupted(owl_global *g) {
970  g->interrupted = 0;
971}
Note: See TracBrowser for help on using the repository browser.