source: global.c @ ed62482

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