source: global.c @ 898eb15

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