source: global.c @ a8186dc

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