source: global.c @ 70110286

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