source: global.c @ 86f740e

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