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