source: global.c @ c0ddaea

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