source: global.c @ f907cf0

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since f907cf0 was 41c9a96, checked in by Anders Kaseorg <andersk@mit.edu>, 15 years ago
Reimplement search in terms of owl_regex. The current implementation of stristr has problems and there isn’t a good replacement available. This was its only caller, so we can get rid of it now. Also, this will make it possible to search with arbitrary regexes if someone feels like coming up with a syntax. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 20.2 KB
RevLine 
[7d4fbcd]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];
[ad15610]18  char *cd;
[7d4fbcd]19
[8262340]20  g->malloced=0;
21  g->freed=0;
22
[7d4fbcd]23  gethostname(hostname, MAXHOSTNAMELEN);
24  hent=gethostbyname(hostname);
25  if (!hent) {
[a8938c7]26    g->thishost=owl_strdup("localhost");
[7d4fbcd]27  } else {
[a8938c7]28    g->thishost=owl_strdup(hent->h_name);
[7d4fbcd]29  }
30
31  owl_context_init(&g->ctx);
32  owl_context_set_startup(&g->ctx);
33  g->curmsg=0;
34  g->topmsg=0;
[bd783db]35  g->markedmsgid=-1;
[7d4fbcd]36  g->needrefresh=1;
[a8938c7]37  g->startupargs=NULL;
[7d4fbcd]38
39  owl_variable_dict_setup(&(g->vars));
40
41  g->lines=LINES;
42  g->cols=COLS;
43
44  g->rightshift=0;
45
[a556caa]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);
[7d4fbcd]48
49  owl_keyhandler_init(&g->kh);
50  owl_keys_setup_keymaps(&g->kh);
51
52  owl_list_create(&(g->filterlist));
53  owl_list_create(&(g->puntlist));
[d09e5a1]54  owl_list_create(&(g->messagequeue));
[f1e629d]55  owl_dict_create(&(g->styledict));
[7d4fbcd]56  g->curmsg_vert_offset=0;
57  g->resizepending=0;
58  g->typwinactive=0;
59  g->direction=OWL_DIRECTION_DOWNWARDS;
60  g->zaway=0;
61  if (has_colors()) {
62    g->hascolors=1;
63  }
64  g->colorpairs=COLOR_PAIRS;
[8fa9562]65  owl_fmtext_init_colorpair_mgr(&(g->cpmgr));
[7d4fbcd]66  g->debug=OWL_DEBUG;
[41c9a96]67  owl_regex_init(&g->search_re);
[7d4fbcd]68  g->starttime=time(NULL); /* assumes we call init only a start time */
[7f792c1]69  g->lastinputtime=g->starttime;
[700c712]70  g->newmsgproc_pid=0;
[61e79a9]71 
[7d4fbcd]72  owl_global_set_config_format(g, 0);
73  owl_global_set_userclue(g, OWL_USERCLUE_NONE);
74  owl_global_set_no_have_config(g);
[10b866d]75  owl_history_init(&(g->msghist));
76  owl_history_init(&(g->cmdhist));
[5a9f6fe]77  owl_history_set_norepeats(&(g->cmdhist));
[7d4fbcd]78  g->nextmsgid=0;
79
80  _owl_global_setup_windows(g);
81
82  /* Fill in some variables which don't have constant defaults */
83  /* TODO: come back later and check passwd file first */
[a8938c7]84  g->homedir=owl_strdup(getenv("HOME"));
[7d4fbcd]85
[b363d83]86  g->confdir = NULL;
87  g->startupfile = NULL;
[ad15610]88  cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
[b363d83]89  owl_global_set_confdir(g, cd);
90  owl_free(cd);
91
[7d4fbcd]92  owl_messagelist_create(&(g->msglist));
93  owl_mainwin_init(&(g->mw));
94  owl_popwin_init(&(g->pw));
[d09e5a1]95
96  g->aim_screenname=NULL;
[81655f8]97  g->aim_screenname_for_filters=NULL;
[d09e5a1]98  g->aim_loggedin=0;
[aa5f725]99  owl_buddylist_init(&(g->buddylist));
[b7bb454]100
[09489b89]101  g->havezephyr=0;
102  g->haveaim=0;
[b7bb454]103  g->ignoreaimlogin=0;
[a352335c]104  owl_global_set_no_doaimevents(g);
[ec6ff52]105
106  owl_errqueue_init(&(g->errqueue));
[c9e72d1]107  g->got_err_signal=0;
[5a95b69]108
109  owl_zbuddylist_create(&(g->zbuddies));
[8e401cae]110
111  owl_obarray_init(&(g->obarray));
[a387d12e]112
113  owl_message_init_fmtext_cache();
[9c7a701]114  owl_list_create(&(g->dispatchlist));
[58d1f8a]115  g->timerlist = NULL;
[adee9cc]116  g->interrupted = FALSE;
[7d4fbcd]117}
118
[eb6cedc]119/* Called once perl has been initialized */
120void owl_global_complete_setup(owl_global *g)
121{
122  owl_cmddict_setup(&(g->cmds));
123}
124
[7d4fbcd]125void _owl_global_setup_windows(owl_global *g) {
[ecd5dc5]126  int cols, typwin_lines;
[7d4fbcd]127
128  cols=g->cols;
[ecd5dc5]129  typwin_lines=owl_global_get_typwin_lines(g);
[7d4fbcd]130
131  /* set the new window sizes */
132  g->recwinlines=g->lines-(typwin_lines+2);
[176d3443]133  if (g->recwinlines<0) {
134    /* gotta deal with this */
135    g->recwinlines=0;
[ecd5dc5]136  }
[7d4fbcd]137
[176d3443]138  owl_function_debugmsg("_owl_global_setup_windows: about to call newwin(%i, %i, 0, 0)\n", g->recwinlines, cols);
139
[7d4fbcd]140  /* create the new windows */
141  g->recwin=newwin(g->recwinlines, cols, 0, 0);
[ecd5dc5]142  if (g->recwin==NULL) {
[2b237308]143    owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n");
[ecd5dc5]144    endwin();
145    exit(50);
146  }
147     
[7d4fbcd]148  g->sepwin=newwin(1, cols, g->recwinlines, 0);
149  g->msgwin=newwin(1, cols, g->recwinlines+1, 0);
150  g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0);
151
[a556caa]152  owl_editwin_set_curswin(g->tw, g->typwin, typwin_lines, g->cols);
[7d4fbcd]153
154  idlok(g->typwin, FALSE);
155  idlok(g->recwin, FALSE);
156  idlok(g->sepwin, FALSE);
157  idlok(g->msgwin, FALSE);
158
159  nodelay(g->typwin, 1);
160  keypad(g->typwin, TRUE);
161  wmove(g->typwin, 0, 0);
162
163  meta(g->typwin, TRUE);
164}
165
166owl_context *owl_global_get_context(owl_global *g) {
167  return(&g->ctx);
168}
169                         
170int owl_global_get_lines(owl_global *g) {
171  return(g->lines);
172}
173
174int owl_global_get_cols(owl_global *g) {
175  return(g->cols);
176}
177
178int owl_global_get_recwin_lines(owl_global *g) {
179  return(g->recwinlines);
180}
181
182/* curmsg */
183
184int owl_global_get_curmsg(owl_global *g) {
185  return(g->curmsg);
186}
187
188void owl_global_set_curmsg(owl_global *g, int i) {
189  g->curmsg=i;
190  /* we will reset the vertical offset from here */
191  /* we might want to move this out to the functions later */
192  owl_global_set_curmsg_vert_offset(g, 0);
193}
194
195/* topmsg */
196
197int owl_global_get_topmsg(owl_global *g) {
198  return(g->topmsg);
199}
200
201void owl_global_set_topmsg(owl_global *g, int i) {
202  g->topmsg=i;
203}
204
[70110286]205/* markedmsgid */
206
207int owl_global_get_markedmsgid(owl_global *g) {
208  return(g->markedmsgid);
209}
210
211void owl_global_set_markedmsgid(owl_global *g, int i) {
212  g->markedmsgid=i;
213  /* i; index of message in the current view.
214  owl_message *m;
215  owl_view *v;
216
217  v = owl_global_get_current_view(&g);
218  m = owl_view_get_element(v, i);
219  g->markedmsgid = m ? owl_message_get_id(m) : 0;
220  */
221}
222
[7d4fbcd]223/* windows */
224
225owl_mainwin *owl_global_get_mainwin(owl_global *g) {
226  return(&(g->mw));
227}
228
229owl_popwin *owl_global_get_popwin(owl_global *g) {
230  return(&(g->pw));
231}
232
233/* msglist */
234
235owl_messagelist *owl_global_get_msglist(owl_global *g) {
236  return(&(g->msglist));
237}
238
239/* keyhandler */
240
241owl_keyhandler *owl_global_get_keyhandler(owl_global *g) {
242  return(&(g->kh));
243}
244
245/* curses windows */
246
247WINDOW *owl_global_get_curs_recwin(owl_global *g) {
248  return(g->recwin);
249}
250
251WINDOW *owl_global_get_curs_sepwin(owl_global *g) {
252  return(g->sepwin);
253}
254
255WINDOW *owl_global_get_curs_msgwin(owl_global *g) {
256  return(g->msgwin);
257}
258
259WINDOW *owl_global_get_curs_typwin(owl_global *g) {
260  return(g->typwin);
261}
262
263/* typwin */
264
265owl_editwin *owl_global_get_typwin(owl_global *g) {
[a556caa]266  return(g->tw);
[7d4fbcd]267}
268
269/* buffercommand */
270
271void owl_global_set_buffercommand(owl_global *g, char *command) {
[1b6b2f3]272  owl_editwin_set_command(owl_global_get_typwin(g), command);
[7d4fbcd]273}
274
275char *owl_global_get_buffercommand(owl_global *g) {
[1b6b2f3]276  return owl_editwin_get_command(owl_global_get_typwin(g));
[7d4fbcd]277}
278
[1b6b2f3]279void owl_global_set_buffercallback(owl_global *g, void (*cb)(owl_editwin*)) {
280  owl_editwin_set_callback(owl_global_get_typwin(g), cb);
[4211f50b]281}
282
[1b6b2f3]283void (*owl_global_get_buffercallback(owl_global *g))(owl_editwin*) {
284  return owl_editwin_get_callback(owl_global_get_typwin(g));
[4211f50b]285}
286
[7d4fbcd]287/* refresh */
288
289int owl_global_is_needrefresh(owl_global *g) {
290  if (g->needrefresh==1) return(1);
291  return(0);
292}
293
294void owl_global_set_needrefresh(owl_global *g) {
295  g->needrefresh=1;
296}
297
298void owl_global_set_noneedrefresh(owl_global *g) {
299  g->needrefresh=0;
300}
301
302/* variable dictionary */
303
304owl_vardict *owl_global_get_vardict(owl_global *g) {
305  return &(g->vars);
306}
307
308/* command dictionary */
309
310owl_cmddict *owl_global_get_cmddict(owl_global *g) {
311  return &(g->cmds);
312}
313
314/* rightshift */
315
316void owl_global_set_rightshift(owl_global *g, int i) {
317  g->rightshift=i;
318}
319
320int owl_global_get_rightshift(owl_global *g) {
321  return(g->rightshift);
322}
323
324/* typwin */
325
326int owl_global_is_typwin_active(owl_global *g) {
327  if (g->typwinactive==1) return(1);
328  return(0);
329}
330
331void owl_global_set_typwin_active(owl_global *g) {
[da466e0]332  int d = owl_global_get_typewindelta(g);
333  if (d > 0)
334      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
335
[7d4fbcd]336  g->typwinactive=1;
337}
338
339void owl_global_set_typwin_inactive(owl_global *g) {
[da466e0]340  int d = owl_global_get_typewindelta(g);
341  if (d > 0)
342      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
343
[7d4fbcd]344  g->typwinactive=0;
345}
346
347/* resize */
348
349void owl_global_set_resize_pending(owl_global *g) {
350  g->resizepending=1;
351}
352
353char *owl_global_get_homedir(owl_global *g) {
[a8938c7]354  if (g->homedir) return(g->homedir);
355  return("/");
[7d4fbcd]356}
357
[b363d83]358char *owl_global_get_confdir(owl_global *g) {
359  if (g->confdir) return(g->confdir);
360  return("/");
361}
362
363/*
364 * Setting this also sets startupfile to confdir/startup
365 */
366void owl_global_set_confdir(owl_global *g, char *cd) {
367  free(g->confdir);
368  g->confdir = owl_strdup(cd);
369  free(g->startupfile);
370  g->startupfile = owl_sprintf("%s/startup", cd);
371}
372
373char *owl_global_get_startupfile(owl_global *g) {
374  if(g->startupfile) return(g->startupfile);
375  return("/");
376}
377
[7d4fbcd]378int owl_global_get_direction(owl_global *g) {
379  return(g->direction);
380}
381
382void owl_global_set_direction_downwards(owl_global *g) {
383  g->direction=OWL_DIRECTION_DOWNWARDS;
384}
385
386void owl_global_set_direction_upwards(owl_global *g) {
387  g->direction=OWL_DIRECTION_UPWARDS;
388}
389
390/* perl stuff */
391
392void owl_global_set_perlinterp(owl_global *g, void *p) {
393  g->perl=p;
394}
395
396void *owl_global_get_perlinterp(owl_global *g) {
397  return(g->perl);
398}
399
400int owl_global_is_config_format(owl_global *g) {
401  if (g->config_format) return(1);
402  return(0);
403}
404
405void owl_global_set_config_format(owl_global *g, int state) {
406  if (state==1) {
407    g->config_format=1;
408  } else {
409    g->config_format=0;
410  }
411}
412
413void owl_global_set_have_config(owl_global *g) {
414  g->haveconfig=1;
415}
416
417void owl_global_set_no_have_config(owl_global *g) {
418  g->haveconfig=0;
419}
420
421int owl_global_have_config(owl_global *g) {
422  if (g->haveconfig) return(1);
423  return(0);
424}
425
426void owl_global_resize(owl_global *g, int x, int y) {
427  /* resize the screen.  If x or y is 0 use the terminal size */
428  struct winsize size;
429   
430  if (!g->resizepending) return;
431
432  /* delete the current windows */
433  delwin(g->recwin);
434  delwin(g->sepwin);
435  delwin(g->msgwin);
436  delwin(g->typwin);
437  if (!isendwin()) {
438    endwin();
439  }
440
441  refresh();
442
443  /* get the new size */
444  ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
445  if (x==0) {
[054894e]446    if (size.ws_row) {
447      g->lines=size.ws_row;
448    } else {
449      g->lines=LINES;
450    } 
[7d4fbcd]451  } else {
[054894e]452      g->lines=x;
[7d4fbcd]453  }
454
455  if (y==0) {
[054894e]456    if (size.ws_col) {
457      g->cols=size.ws_col;
458    } else {
459      g->cols=COLS;
460    } 
[7d4fbcd]461  } else {
462    g->cols=y;
463  }
464
[1bdffcb]465#ifdef HAVE_RESIZETERM
[74037d9]466  resizeterm(size.ws_row, size.ws_col);
[1bdffcb]467#endif
[7d4fbcd]468
469  /* re-initialize the windows */
470  _owl_global_setup_windows(g);
471
[f1e629d]472  /* in case any styles rely on the current width */
473  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
474
[c0f9e30]475  /* recalculate the topmsg to make sure the current message is on
476   * screen */
477  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
478
[7d4fbcd]479  /* refresh stuff */
480  g->needrefresh=1;
481  owl_mainwin_redisplay(&(g->mw));
482  sepbar(NULL);
[a556caa]483  owl_editwin_redisplay(g->tw, 0);
[8aa83ea3]484  owl_function_full_redisplay(&g);
[7d4fbcd]485
486  /* TODO: this should handle other forms of popwins */
487  if (owl_popwin_is_active(owl_global_get_popwin(g)) 
488      && owl_global_get_viewwin(g)) {
489    owl_popwin_refresh(owl_global_get_popwin(g));
490    owl_viewwin_redisplay(owl_global_get_viewwin(g), 0);
491  }
492
[ecd5dc5]493  owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col);
[7d4fbcd]494  owl_function_makemsg("");
495  g->resizepending=0;
496}
497
498/* debug */
499
500int owl_global_is_debug_fast(owl_global *g) {
501  if (g->debug) return(1);
502  return(0);
503}
504
505/* starttime */
506
507time_t owl_global_get_starttime(owl_global *g) {
508  return(g->starttime);
509}
510
511time_t owl_global_get_runtime(owl_global *g) {
512  return(time(NULL)-g->starttime);
513}
514
[7f792c1]515time_t owl_global_get_lastinputtime(owl_global *g) {
516  return(g->lastinputtime);
517}
518
[eebef19]519void owl_global_set_lastinputtime(owl_global *g, time_t time) {
520  g->lastinputtime = time;
[7f792c1]521}
522
523time_t owl_global_get_idletime(owl_global *g) {
524  return(time(NULL)-g->lastinputtime);
525}
526
[7d4fbcd]527void owl_global_get_runtime_string(owl_global *g, char *buff) {
528  time_t diff;
529
530  diff=time(NULL)-owl_global_get_starttime(g);
531
532  /* print something nicer later */   
533  sprintf(buff, "%i seconds", (int) diff);
534}
535
[61e79a9]536char *owl_global_get_hostname(owl_global *g) {
[a8938c7]537  if (g->thishost) return(g->thishost);
538  return("");
[61e79a9]539}
540
[7d4fbcd]541/* userclue */
542
543void owl_global_set_userclue(owl_global *g, int clue) {
544  g->userclue=clue;
545}
546
547void owl_global_add_userclue(owl_global *g, int clue) {
548  g->userclue|=clue;
549}
550
551int owl_global_get_userclue(owl_global *g) {
552  return(g->userclue);
553}
554
555int owl_global_is_userclue(owl_global *g, int clue) {
556  if (g->userclue & clue) return(1);
557  return(0);
558}
559
560/* viewwin */
561
562owl_viewwin *owl_global_get_viewwin(owl_global *g) {
563  return(&(g->vw));
564}
565
566
567/* vert offset */
568
569int owl_global_get_curmsg_vert_offset(owl_global *g) {
570  return(g->curmsg_vert_offset);
571}
572
573void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
574  g->curmsg_vert_offset=i;
575}
576
577/* startup args */
578
579void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
[a8938c7]580  int i, len;
581
582  if (g->startupargs) owl_free(g->startupargs);
583 
584  len=0;
585  for (i=0; i<argc; i++) {
[591e6aa7]586    len+=strlen(argv[i])+5;
[a8938c7]587  }
[34509d5]588  g->startupargs=owl_malloc(len+5);
[7d4fbcd]589
590  strcpy(g->startupargs, "");
591  for (i=0; i<argc; i++) {
[b9cb41b]592    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
[7d4fbcd]593  }
594  g->startupargs[strlen(g->startupargs)-1]='\0';
595}
596
597char *owl_global_get_startupargs(owl_global *g) {
[a8938c7]598  if (g->startupargs) return(g->startupargs);
599  return("");
[7d4fbcd]600}
601
602/* history */
603
[10b866d]604owl_history *owl_global_get_msg_history(owl_global *g) {
605  return(&(g->msghist));
606}
607
608owl_history *owl_global_get_cmd_history(owl_global *g) {
609  return(&(g->cmdhist));
[7d4fbcd]610}
611
612/* filterlist */
613
614owl_list *owl_global_get_filterlist(owl_global *g) {
615  return(&(g->filterlist));
616}
617
618owl_filter *owl_global_get_filter(owl_global *g, char *name) {
619  int i, j;
620  owl_filter *f;
621
622  j=owl_list_get_size(&(g->filterlist));
623  for (i=0; i<j; i++) {
624    f=owl_list_get_element(&(g->filterlist), i);
625    if (!strcmp(name, owl_filter_get_name(f))) {
626      return(f);
627    }
628  }
629  return(NULL);
630}
631
632void owl_global_add_filter(owl_global *g, owl_filter *f) {
633  owl_list_append_element(&(g->filterlist), f);
634}
635
636void owl_global_remove_filter(owl_global *g, char *name) {
637  int i, j;
638  owl_filter *f;
639
640  j=owl_list_get_size(&(g->filterlist));
641  for (i=0; i<j; i++) {
642    f=owl_list_get_element(&(g->filterlist), i);
643    if (!strcmp(name, owl_filter_get_name(f))) {
644      owl_filter_free(f);
645      owl_list_remove_element(&(g->filterlist), i);
646      break;
647    }
648  }
649}
650
651/* nextmsgid */
652
653int owl_global_get_nextmsgid(owl_global *g) {
654  return(g->nextmsgid++);
655}
656
657/* current view */
658
659owl_view *owl_global_get_current_view(owl_global *g) {
660  return(&(g->current_view));
661}
662
663/* has colors */
664
665int owl_global_get_hascolors(owl_global *g) {
666  if (g->hascolors) return(1);
667  return(0);
668}
669
670/* color pairs */
671
672int owl_global_get_colorpairs(owl_global *g) {
673  return(g->colorpairs);
674}
675
[8fa9562]676owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
677  return(&(g->cpmgr));
678}
679
[7d4fbcd]680/* puntlist */
681
682owl_list *owl_global_get_puntlist(owl_global *g) {
683  return(&(g->puntlist));
684}
685
686int owl_global_message_is_puntable(owl_global *g, owl_message *m) {
687  owl_list *pl;
688  int i, j;
689
690  pl=owl_global_get_puntlist(g);
691  j=owl_list_get_size(pl);
692  for (i=0; i<j; i++) {
693    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
694  }
695  return(0);
696}
697
698int owl_global_should_followlast(owl_global *g) {
699  owl_view *v;
700 
701  if (!owl_global_is__followlast(g)) return(0);
702 
703  v=owl_global_get_current_view(g);
704 
705  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
706  return(0);
707}
[1fd0b25]708
709int owl_global_is_search_active(owl_global *g) {
[41c9a96]710  if (owl_regex_is_set(&g->search_re)) return(1);
[1fd0b25]711  return(0);
712}
713
[41c9a96]714void owl_global_set_search_re(owl_global *g, owl_regex *re) {
715  if (owl_regex_is_set(&g->search_re)) {
716    owl_regex_free(&g->search_re);
717    owl_regex_init(&g->search_re);
718  }
719  if (re != NULL)
720    owl_regex_copy(re, &g->search_re);
[1fd0b25]721}
722
[41c9a96]723owl_regex *owl_global_get_search_re(owl_global *g) {
724  return &g->search_re;
[1fd0b25]725}
[700c712]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
[d09e5a1]735/* AIM stuff */
736
[6a415e9]737int owl_global_is_aimloggedin(owl_global *g)
738{
[d09e5a1]739  if (g->aim_loggedin) return(1);
740  return(0);
741}
742
[6a415e9]743char *owl_global_get_aim_screenname(owl_global *g)
744{
[a352335c]745  if (owl_global_is_aimloggedin(g)) {
746    return (g->aim_screenname);
747  }
748  return("");
[d09e5a1]749}
750
[81655f8]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
[6a415e9]759void owl_global_set_aimloggedin(owl_global *g, char *screenname)
760{
[81655f8]761  char *sn_escaped, *quote;
[d09e5a1]762  g->aim_loggedin=1;
763  if (g->aim_screenname) owl_free(g->aim_screenname);
[81655f8]764  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
[d09e5a1]765  g->aim_screenname=owl_strdup(screenname);
[81655f8]766  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
767  quote = owl_getquoting(sn_escaped);
[9f4e3f8]768  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
[81655f8]769  owl_free(sn_escaped);
[d09e5a1]770}
771
[6a415e9]772void owl_global_set_aimnologgedin(owl_global *g)
773{
[d09e5a1]774  g->aim_loggedin=0;
775}
776
[a352335c]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
[6a415e9]793aim_session_t *owl_global_get_aimsess(owl_global *g)
794{
[d09e5a1]795  return(&(g->aimsess));
796}
797
[c15bbfb]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)
[6a415e9]804{
[c15bbfb]805  g->bosconn=*conn;
[d09e5a1]806}
807
808/* message queue */
809
[6a415e9]810void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
811{
[d09e5a1]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 */
[13a3c1db]819owl_message *owl_global_messagequeue_popmsg(owl_global *g)
[6a415e9]820{
[d09e5a1]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
[6a415e9]829int owl_global_messagequeue_pending(owl_global *g)
830{
[d09e5a1]831  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
832  return(1);
833}
[aa5f725]834
[6a415e9]835owl_buddylist *owl_global_get_buddylist(owl_global *g)
836{
[aa5f725]837  return(&(g->buddylist));
838}
839 
[bd3f232]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{
[f1e629d]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);
[bd3f232]853}
854
[cf83b7a]855void owl_global_add_style(owl_global *g, owl_style *s)
856{
[f1fc47f]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);
[bd3f232]867}
[cf83b7a]868
[09489b89]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
[b7bb454]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
[09489b89]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}
[de03334]905
[ec6ff52]906owl_errqueue *owl_global_get_errqueue(owl_global *g)
907{
908  return(&(g->errqueue));
909}
[c9e72d1]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
[5a95b69]932
933owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
934{
935  return(&(g->zbuddies));
936}
[8232149]937
938struct termios *owl_global_get_startup_tio(owl_global *g)
939{
940  return(&(g->startup_tio));
941}
[8e401cae]942
943char * owl_global_intern(owl_global *g, char * string)
944{
945  return owl_obarray_insert(&(g->obarray), string);
946}
[9c7a701]947
948owl_list *owl_global_get_dispatchlist(owl_global *g)
949{
950  return &(g->dispatchlist);
951}
[b7bb454]952
[58d1f8a]953GList **owl_global_get_timerlist(owl_global *g)
[b7bb454]954{
[58d1f8a]955  return &(g->timerlist);
[b7bb454]956}
[adee9cc]957
958int owl_global_is_interrupted(owl_global *g) {
[0cb6c26]959  return g->interrupted;
[adee9cc]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.