source: global.c @ ad0dedd

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