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