source: global.c @ b03c714

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