source: global.c @ 18fdd5f9

release-1.10release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 18fdd5f9 was df0138f, checked in by Alejandro R. Sedeño <asedeno@mit.edu>, 15 years ago
Add a new I/O Dispatch API Signed-off-by: Alejandro R. Sedeño <asedeno@mit.edu>
  • Property mode set to 100644
File size: 20.9 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));
[df0138f]115  owl_list_create(&(g->io_dispatch_list));
[4f2166b]116  owl_list_create(&(g->psa_list));
[58d1f8a]117  g->timerlist = NULL;
[adee9cc]118  g->interrupted = FALSE;
[40bda84]119  g->got_sigtstp = FALSE;
[7d4fbcd]120}
121
[eb6cedc]122/* Called once perl has been initialized */
123void owl_global_complete_setup(owl_global *g)
124{
125  owl_cmddict_setup(&(g->cmds));
126}
127
[7d4fbcd]128void _owl_global_setup_windows(owl_global *g) {
[ecd5dc5]129  int cols, typwin_lines;
[7d4fbcd]130
131  cols=g->cols;
[ecd5dc5]132  typwin_lines=owl_global_get_typwin_lines(g);
[7d4fbcd]133
134  /* set the new window sizes */
135  g->recwinlines=g->lines-(typwin_lines+2);
[176d3443]136  if (g->recwinlines<0) {
137    /* gotta deal with this */
138    g->recwinlines=0;
[ecd5dc5]139  }
[7d4fbcd]140
[176d3443]141  owl_function_debugmsg("_owl_global_setup_windows: about to call newwin(%i, %i, 0, 0)\n", g->recwinlines, cols);
142
[7d4fbcd]143  /* create the new windows */
144  g->recwin=newwin(g->recwinlines, cols, 0, 0);
[ecd5dc5]145  if (g->recwin==NULL) {
[2b237308]146    owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n");
[ecd5dc5]147    endwin();
148    exit(50);
149  }
150     
[7d4fbcd]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
[a556caa]155  owl_editwin_set_curswin(g->tw, g->typwin, typwin_lines, g->cols);
[7d4fbcd]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                         
[8742840]173int owl_global_get_lines(const owl_global *g) {
[7d4fbcd]174  return(g->lines);
175}
176
[8742840]177int owl_global_get_cols(const owl_global *g) {
[7d4fbcd]178  return(g->cols);
179}
180
[8742840]181int owl_global_get_recwin_lines(const owl_global *g) {
[7d4fbcd]182  return(g->recwinlines);
183}
184
185/* curmsg */
186
[8742840]187int owl_global_get_curmsg(const owl_global *g) {
[7d4fbcd]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
[8742840]200int owl_global_get_topmsg(const owl_global *g) {
[7d4fbcd]201  return(g->topmsg);
202}
203
204void owl_global_set_topmsg(owl_global *g, int i) {
205  g->topmsg=i;
206}
207
[70110286]208/* markedmsgid */
209
[8742840]210int owl_global_get_markedmsgid(const owl_global *g) {
[70110286]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.
[c08c70a]217  const owl_message *m;
[70110286]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
[7d4fbcd]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
[8742840]250WINDOW *owl_global_get_curs_recwin(const owl_global *g) {
[7d4fbcd]251  return(g->recwin);
252}
253
[8742840]254WINDOW *owl_global_get_curs_sepwin(const owl_global *g) {
[7d4fbcd]255  return(g->sepwin);
256}
257
[8742840]258WINDOW *owl_global_get_curs_msgwin(const owl_global *g) {
[7d4fbcd]259  return(g->msgwin);
260}
261
[8742840]262WINDOW *owl_global_get_curs_typwin(const owl_global *g) {
[7d4fbcd]263  return(g->typwin);
264}
265
266/* typwin */
267
[8742840]268owl_editwin *owl_global_get_typwin(const owl_global *g) {
[a556caa]269  return(g->tw);
[7d4fbcd]270}
271
272/* buffercommand */
273
[e19eb97]274void owl_global_set_buffercommand(owl_global *g, const char *command) {
[1b6b2f3]275  owl_editwin_set_command(owl_global_get_typwin(g), command);
[7d4fbcd]276}
277
[8742840]278const char *owl_global_get_buffercommand(const owl_global *g) {
[1b6b2f3]279  return owl_editwin_get_command(owl_global_get_typwin(g));
[7d4fbcd]280}
281
[1b6b2f3]282void owl_global_set_buffercallback(owl_global *g, void (*cb)(owl_editwin*)) {
283  owl_editwin_set_callback(owl_global_get_typwin(g), cb);
[4211f50b]284}
285
[8742840]286void (*owl_global_get_buffercallback(const owl_global *g))(owl_editwin*) {
[1b6b2f3]287  return owl_editwin_get_callback(owl_global_get_typwin(g));
[4211f50b]288}
289
[7d4fbcd]290/* refresh */
291
[8742840]292int owl_global_is_needrefresh(const owl_global *g) {
[7d4fbcd]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
[8742840]323int owl_global_get_rightshift(const owl_global *g) {
[7d4fbcd]324  return(g->rightshift);
325}
326
327/* typwin */
328
[8742840]329int owl_global_is_typwin_active(const owl_global *g) {
[7d4fbcd]330  if (g->typwinactive==1) return(1);
331  return(0);
332}
333
334void owl_global_set_typwin_active(owl_global *g) {
[da466e0]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
[7d4fbcd]339  g->typwinactive=1;
340}
341
342void owl_global_set_typwin_inactive(owl_global *g) {
[da466e0]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
[7d4fbcd]347  g->typwinactive=0;
348}
349
350/* resize */
351
352void owl_global_set_resize_pending(owl_global *g) {
353  g->resizepending=1;
354}
355
[8742840]356const char *owl_global_get_homedir(const owl_global *g) {
[a8938c7]357  if (g->homedir) return(g->homedir);
358  return("/");
[7d4fbcd]359}
360
[8742840]361const char *owl_global_get_confdir(const owl_global *g) {
[b363d83]362  if (g->confdir) return(g->confdir);
363  return("/");
364}
365
366/*
367 * Setting this also sets startupfile to confdir/startup
368 */
[e19eb97]369void owl_global_set_confdir(owl_global *g, const char *cd) {
[27f6487]370  owl_free(g->confdir);
[b363d83]371  g->confdir = owl_strdup(cd);
[27f6487]372  owl_free(g->startupfile);
[b363d83]373  g->startupfile = owl_sprintf("%s/startup", cd);
374}
375
[8742840]376const char *owl_global_get_startupfile(const owl_global *g) {
[b363d83]377  if(g->startupfile) return(g->startupfile);
378  return("/");
379}
380
[8742840]381int owl_global_get_direction(const owl_global *g) {
[7d4fbcd]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
[8742840]399void *owl_global_get_perlinterp(const owl_global *g) {
[7d4fbcd]400  return(g->perl);
401}
402
[8742840]403int owl_global_is_config_format(const owl_global *g) {
[7d4fbcd]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) {
[054894e]449    if (size.ws_row) {
450      g->lines=size.ws_row;
451    } else {
452      g->lines=LINES;
453    } 
[7d4fbcd]454  } else {
[054894e]455      g->lines=x;
[7d4fbcd]456  }
457
458  if (y==0) {
[054894e]459    if (size.ws_col) {
460      g->cols=size.ws_col;
461    } else {
462      g->cols=COLS;
463    } 
[7d4fbcd]464  } else {
465    g->cols=y;
466  }
467
[1bdffcb]468#ifdef HAVE_RESIZETERM
[74037d9]469  resizeterm(size.ws_row, size.ws_col);
[1bdffcb]470#endif
[7d4fbcd]471
472  /* re-initialize the windows */
473  _owl_global_setup_windows(g);
474
[f1e629d]475  /* in case any styles rely on the current width */
476  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
477
[c0f9e30]478  /* recalculate the topmsg to make sure the current message is on
479   * screen */
480  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
481
[7d4fbcd]482  /* refresh stuff */
483  g->needrefresh=1;
484  owl_mainwin_redisplay(&(g->mw));
485  sepbar(NULL);
[a556caa]486  owl_editwin_redisplay(g->tw, 0);
[8240bce]487  owl_function_full_redisplay();
[7d4fbcd]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
[ecd5dc5]496  owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col);
[7d4fbcd]497  owl_function_makemsg("");
498  g->resizepending=0;
499}
500
501/* debug */
502
[8742840]503int owl_global_is_debug_fast(const owl_global *g) {
[7d4fbcd]504  if (g->debug) return(1);
505  return(0);
506}
507
508/* starttime */
509
[8742840]510time_t owl_global_get_starttime(const owl_global *g) {
[7d4fbcd]511  return(g->starttime);
512}
513
[8742840]514time_t owl_global_get_runtime(const owl_global *g) {
[7d4fbcd]515  return(time(NULL)-g->starttime);
516}
517
[8742840]518time_t owl_global_get_lastinputtime(const owl_global *g) {
[7f792c1]519  return(g->lastinputtime);
520}
521
[eebef19]522void owl_global_set_lastinputtime(owl_global *g, time_t time) {
523  g->lastinputtime = time;
[7f792c1]524}
525
[8742840]526time_t owl_global_get_idletime(const owl_global *g) {
[7f792c1]527  return(time(NULL)-g->lastinputtime);
528}
529
[8742840]530const char *owl_global_get_hostname(const owl_global *g) {
[a8938c7]531  if (g->thishost) return(g->thishost);
532  return("");
[61e79a9]533}
534
[7d4fbcd]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
[8742840]545int owl_global_get_userclue(const owl_global *g) {
[7d4fbcd]546  return(g->userclue);
547}
548
[8742840]549int owl_global_is_userclue(const owl_global *g, int clue) {
[7d4fbcd]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
[8742840]563int owl_global_get_curmsg_vert_offset(const owl_global *g) {
[7d4fbcd]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
[e19eb97]573void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
[a8938c7]574  int i, len;
575
576  if (g->startupargs) owl_free(g->startupargs);
577 
578  len=0;
579  for (i=0; i<argc; i++) {
[591e6aa7]580    len+=strlen(argv[i])+5;
[a8938c7]581  }
[34509d5]582  g->startupargs=owl_malloc(len+5);
[7d4fbcd]583
584  strcpy(g->startupargs, "");
585  for (i=0; i<argc; i++) {
[b9cb41b]586    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
[7d4fbcd]587  }
588  g->startupargs[strlen(g->startupargs)-1]='\0';
589}
590
[8742840]591const char *owl_global_get_startupargs(const owl_global *g) {
[a8938c7]592  if (g->startupargs) return(g->startupargs);
593  return("");
[7d4fbcd]594}
595
596/* history */
597
[10b866d]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));
[7d4fbcd]604}
605
606/* filterlist */
607
608owl_list *owl_global_get_filterlist(owl_global *g) {
609  return(&(g->filterlist));
610}
611
[8742840]612owl_filter *owl_global_get_filter(const owl_global *g, const char *name) {
[7d4fbcd]613  int i, j;
614  owl_filter *f;
615
616  j=owl_list_get_size(&(g->filterlist));
617  for (i=0; i<j; i++) {
618    f=owl_list_get_element(&(g->filterlist), i);
619    if (!strcmp(name, owl_filter_get_name(f))) {
620      return(f);
621    }
622  }
623  return(NULL);
624}
625
626void owl_global_add_filter(owl_global *g, owl_filter *f) {
627  owl_list_append_element(&(g->filterlist), f);
628}
629
[e19eb97]630void owl_global_remove_filter(owl_global *g, const char *name) {
[7d4fbcd]631  int i, j;
632  owl_filter *f;
633
634  j=owl_list_get_size(&(g->filterlist));
635  for (i=0; i<j; i++) {
636    f=owl_list_get_element(&(g->filterlist), i);
637    if (!strcmp(name, owl_filter_get_name(f))) {
[23fddad]638      owl_filter_delete(f);
[7d4fbcd]639      owl_list_remove_element(&(g->filterlist), i);
640      break;
641    }
642  }
643}
644
645/* nextmsgid */
646
647int owl_global_get_nextmsgid(owl_global *g) {
648  return(g->nextmsgid++);
649}
650
651/* current view */
652
653owl_view *owl_global_get_current_view(owl_global *g) {
654  return(&(g->current_view));
655}
656
657/* has colors */
658
[8742840]659int owl_global_get_hascolors(const owl_global *g) {
[7d4fbcd]660  if (g->hascolors) return(1);
661  return(0);
662}
663
664/* color pairs */
665
[8742840]666int owl_global_get_colorpairs(const owl_global *g) {
[7d4fbcd]667  return(g->colorpairs);
668}
669
[8fa9562]670owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) {
671  return(&(g->cpmgr));
672}
673
[7d4fbcd]674/* puntlist */
675
676owl_list *owl_global_get_puntlist(owl_global *g) {
677  return(&(g->puntlist));
678}
679
[c08c70a]680int owl_global_message_is_puntable(owl_global *g, const owl_message *m) {
[77bced3]681  const owl_list *pl;
[7d4fbcd]682  int i, j;
683
684  pl=owl_global_get_puntlist(g);
685  j=owl_list_get_size(pl);
686  for (i=0; i<j; i++) {
687    if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1);
688  }
689  return(0);
690}
691
692int owl_global_should_followlast(owl_global *g) {
[9e5c9f3]693  const owl_view *v;
[7d4fbcd]694 
695  if (!owl_global_is__followlast(g)) return(0);
696 
697  v=owl_global_get_current_view(g);
698 
699  if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1);
700  return(0);
701}
[1fd0b25]702
[8742840]703int owl_global_is_search_active(const owl_global *g) {
[41c9a96]704  if (owl_regex_is_set(&g->search_re)) return(1);
[1fd0b25]705  return(0);
706}
707
[89b2daf]708void owl_global_set_search_re(owl_global *g, const owl_regex *re) {
[41c9a96]709  if (owl_regex_is_set(&g->search_re)) {
710    owl_regex_free(&g->search_re);
711    owl_regex_init(&g->search_re);
712  }
713  if (re != NULL)
714    owl_regex_copy(re, &g->search_re);
[1fd0b25]715}
716
[8742840]717const owl_regex *owl_global_get_search_re(const owl_global *g) {
[41c9a96]718  return &g->search_re;
[1fd0b25]719}
[700c712]720
[0e5afa2]721void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) {
[700c712]722  g->newmsgproc_pid=i;
723}
724
[0e5afa2]725pid_t owl_global_get_newmsgproc_pid(const owl_global *g) {
[700c712]726  return(g->newmsgproc_pid);
727}
728
[d09e5a1]729/* AIM stuff */
730
[8742840]731int owl_global_is_aimloggedin(const owl_global *g)
[6a415e9]732{
[d09e5a1]733  if (g->aim_loggedin) return(1);
734  return(0);
735}
736
[8742840]737const char *owl_global_get_aim_screenname(const owl_global *g)
[6a415e9]738{
[a352335c]739  if (owl_global_is_aimloggedin(g)) {
740    return (g->aim_screenname);
741  }
742  return("");
[d09e5a1]743}
744
[8742840]745const char *owl_global_get_aim_screenname_for_filters(const owl_global *g)
[81655f8]746{
747  if (owl_global_is_aimloggedin(g)) {
748    return (g->aim_screenname_for_filters);
749  }
750  return("");
751}
752
[e19eb97]753void owl_global_set_aimloggedin(owl_global *g, const char *screenname)
[6a415e9]754{
[65b2173]755  char *sn_escaped;
[e19eb97]756  const char *quote;
[d09e5a1]757  g->aim_loggedin=1;
758  if (g->aim_screenname) owl_free(g->aim_screenname);
[81655f8]759  if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters);
[d09e5a1]760  g->aim_screenname=owl_strdup(screenname);
[81655f8]761  sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
762  quote = owl_getquoting(sn_escaped);
[9f4e3f8]763  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
[81655f8]764  owl_free(sn_escaped);
[d09e5a1]765}
766
[6a415e9]767void owl_global_set_aimnologgedin(owl_global *g)
768{
[d09e5a1]769  g->aim_loggedin=0;
770}
771
[8742840]772int owl_global_is_doaimevents(const owl_global *g)
[a352335c]773{
774  if (g->aim_doprocessing) return(1);
775  return(0);
776}
777
778void owl_global_set_doaimevents(owl_global *g)
779{
780  g->aim_doprocessing=1;
781}
782
783void owl_global_set_no_doaimevents(owl_global *g)
784{
785  g->aim_doprocessing=0;
786}
787
[6a415e9]788aim_session_t *owl_global_get_aimsess(owl_global *g)
789{
[d09e5a1]790  return(&(g->aimsess));
791}
792
[c15bbfb]793aim_conn_t *owl_global_get_bosconn(owl_global *g)
794{
795  return(&(g->bosconn));
796}
797
798void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn)
[6a415e9]799{
[c15bbfb]800  g->bosconn=*conn;
[d09e5a1]801}
802
803/* message queue */
804
[6a415e9]805void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
806{
[d09e5a1]807  owl_list_append_element(&(g->messagequeue), m);
808}
809
810/* pop off the first message and return it.  Return NULL if the queue
811 * is empty.  The caller should free the message after using it, if
812 * necessary.
813 */
[13a3c1db]814owl_message *owl_global_messagequeue_popmsg(owl_global *g)
[6a415e9]815{
[d09e5a1]816  owl_message *out;
817
818  if (owl_list_get_size(&(g->messagequeue))==0) return(NULL);
819  out=owl_list_get_element(&(g->messagequeue), 0);
820  owl_list_remove_element(&(g->messagequeue), 0);
821  return(out);
822}
823
[6a415e9]824int owl_global_messagequeue_pending(owl_global *g)
825{
[d09e5a1]826  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
827  return(1);
828}
[aa5f725]829
[6a415e9]830owl_buddylist *owl_global_get_buddylist(owl_global *g)
831{
[aa5f725]832  return(&(g->buddylist));
833}
834 
[bd3f232]835/* style */
836
837/* Return the style with name 'name'.  If it does not exist return
838 * NULL */
[8742840]839const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name)
[bd3f232]840{
[f1e629d]841  return owl_dict_find_element(&(g->styledict), name);
842}
843
844/* creates a list and fills it in with keys.  duplicates the keys,
845 * so they will need to be freed by the caller. */
[8742840]846int owl_global_get_style_names(const owl_global *g, owl_list *l) {
[f1e629d]847  return owl_dict_get_keys(&(g->styledict), l);
[bd3f232]848}
849
[cf83b7a]850void owl_global_add_style(owl_global *g, owl_style *s)
851{
[f1fc47f]852  /*
853   * If we're redefining the current style, make sure to update
854   * pointers to it.
855   */
856  if(g->current_view.style
857     && !strcmp(owl_style_get_name(g->current_view.style),
858                owl_style_get_name(s)))
859    g->current_view.style = s;
860  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
861                          s, (void(*)(void*))owl_style_free);
[bd3f232]862}
[cf83b7a]863
[09489b89]864void owl_global_set_haveaim(owl_global *g)
865{
866  g->haveaim=1;
867}
868
[8742840]869int owl_global_is_haveaim(const owl_global *g)
[09489b89]870{
871  if (g->haveaim) return(1);
872  return(0);
873}
874
[b7bb454]875void owl_global_set_ignore_aimlogin(owl_global *g)
876{
877    g->ignoreaimlogin = 1;
878}
879
880void owl_global_unset_ignore_aimlogin(owl_global *g)
881{
882    g->ignoreaimlogin = 0;
883}
884
[8742840]885int owl_global_is_ignore_aimlogin(const owl_global *g)
[b7bb454]886{
887    return g->ignoreaimlogin;
888}
889
[09489b89]890void owl_global_set_havezephyr(owl_global *g)
891{
892  g->havezephyr=1;
893}
894
[8742840]895int owl_global_is_havezephyr(const owl_global *g)
[09489b89]896{
897  if (g->havezephyr) return(1);
898  return(0);
899}
[de03334]900
[ec6ff52]901owl_errqueue *owl_global_get_errqueue(owl_global *g)
902{
903  return(&(g->errqueue));
904}
[c9e72d1]905
906void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
907{
908  g->got_err_signal = signum;
909  if (siginfo) {
910    g->err_signal_info = *siginfo;
911  } else {
912    memset(&(g->err_signal_info), 0, sizeof(siginfo_t));
913  }
914}
915
916int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
917{
918  int signum;
919  if (siginfo && g->got_err_signal) {
920    *siginfo = g->err_signal_info;
921  } 
922  signum = g->got_err_signal;
923  g->got_err_signal = 0;
924  return signum;
925}
926
[5a95b69]927
928owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
929{
930  return(&(g->zbuddies));
931}
[8232149]932
933struct termios *owl_global_get_startup_tio(owl_global *g)
934{
935  return(&(g->startup_tio));
936}
[8e401cae]937
[e19eb97]938const char * owl_global_intern(owl_global *g, const char * string)
[8e401cae]939{
940  return owl_obarray_insert(&(g->obarray), string);
941}
[9c7a701]942
943owl_list *owl_global_get_dispatchlist(owl_global *g)
944{
945  return &(g->dispatchlist);
946}
[b7bb454]947
[df0138f]948owl_list *owl_global_get_io_dispatch_list(owl_global *g)
949{
950  return &(g->io_dispatch_list);
951}
952
[4f2166b]953owl_list *owl_global_get_psa_list(owl_global *g)
954{
955  return &(g->psa_list);
956}
957
[58d1f8a]958GList **owl_global_get_timerlist(owl_global *g)
[b7bb454]959{
[58d1f8a]960  return &(g->timerlist);
[b7bb454]961}
[adee9cc]962
[8742840]963int owl_global_is_interrupted(const owl_global *g) {
[0cb6c26]964  return g->interrupted;
[adee9cc]965}
966
967void owl_global_set_interrupted(owl_global *g) {
968  g->interrupted = 1;
969}
970
971void owl_global_unset_interrupted(owl_global *g) {
972  g->interrupted = 0;
973}
[40bda84]974
975int owl_global_is_sigstp(const owl_global *g) {
976  return g->got_sigtstp;
977}
978
979void owl_global_set_got_sigstp(owl_global *g) {
980  g->got_sigtstp = 1;
981}
982
983void owl_global_unset_got_sigstp(owl_global *g) {
984  g->got_sigtstp = 0;
985}
Note: See TracBrowser for help on using the repository browser.