source: global.c @ 52761cc

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