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