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