source: global.c @ 0e3cdf1

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