source: global.c @ db4b293

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