source: global.c @ b363d83

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