source: global.c @ a60edf2

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