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