[dab82f29] | 1 | /* Copyright (c) 2002,2003,2004,2009 James M. Kretchmar |
---|
| 2 | * |
---|
| 3 | * This file is part of Owl. |
---|
| 4 | * |
---|
| 5 | * Owl is free software: you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
| 7 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 8 | * (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * Owl is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with Owl. If not, see <http://www.gnu.org/licenses/>. |
---|
| 17 | * |
---|
| 18 | * --------------------------------------------------------------- |
---|
| 19 | * |
---|
| 20 | * As of Owl version 2.1.12 there are patches contributed by |
---|
[fa00c5c] | 21 | * developers of the branched BarnOwl project, Copyright (c) |
---|
| 22 | * 2006-2009 The BarnOwl Developers. All rights reserved. |
---|
[dab82f29] | 23 | */ |
---|
| 24 | |
---|
[7d4fbcd] | 25 | #include <stdio.h> |
---|
| 26 | #include <unistd.h> |
---|
| 27 | #include <stdlib.h> |
---|
| 28 | #include <string.h> |
---|
| 29 | #include <netdb.h> |
---|
| 30 | #include <termios.h> |
---|
| 31 | #include <sys/ioctl.h> |
---|
| 32 | #include <time.h> |
---|
| 33 | #include "owl.h" |
---|
| 34 | |
---|
[1aee7d9] | 35 | static const char fileIdent[] = "$Id$"; |
---|
| 36 | |
---|
[7d4fbcd] | 37 | #ifndef MAXHOSTNAMELEN |
---|
| 38 | #define MAXHOSTNAMELEN 256 |
---|
| 39 | #endif |
---|
| 40 | |
---|
| 41 | void owl_global_init(owl_global *g) { |
---|
| 42 | struct hostent *hent; |
---|
| 43 | char hostname[MAXHOSTNAMELEN]; |
---|
| 44 | |
---|
[8262340] | 45 | g->malloced=0; |
---|
| 46 | g->freed=0; |
---|
| 47 | |
---|
[7d4fbcd] | 48 | gethostname(hostname, MAXHOSTNAMELEN); |
---|
| 49 | hent=gethostbyname(hostname); |
---|
| 50 | if (!hent) { |
---|
[a8938c7] | 51 | g->thishost=owl_strdup("localhost"); |
---|
[7d4fbcd] | 52 | } else { |
---|
[a8938c7] | 53 | g->thishost=owl_strdup(hent->h_name); |
---|
[7d4fbcd] | 54 | } |
---|
| 55 | |
---|
| 56 | owl_context_init(&g->ctx); |
---|
| 57 | owl_context_set_startup(&g->ctx); |
---|
| 58 | g->curmsg=0; |
---|
| 59 | g->topmsg=0; |
---|
| 60 | g->needrefresh=1; |
---|
[a8938c7] | 61 | g->startupargs=NULL; |
---|
[7d4fbcd] | 62 | |
---|
| 63 | owl_variable_dict_setup(&(g->vars)); |
---|
| 64 | owl_cmddict_setup(&(g->cmds)); |
---|
| 65 | |
---|
| 66 | g->lines=LINES; |
---|
| 67 | g->cols=COLS; |
---|
| 68 | |
---|
| 69 | g->rightshift=0; |
---|
| 70 | |
---|
[10b866d] | 71 | owl_editwin_init(&(g->tw), NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL); |
---|
[7d4fbcd] | 72 | |
---|
| 73 | owl_keyhandler_init(&g->kh); |
---|
| 74 | owl_keys_setup_keymaps(&g->kh); |
---|
| 75 | |
---|
| 76 | owl_list_create(&(g->filterlist)); |
---|
| 77 | owl_list_create(&(g->puntlist)); |
---|
[d09e5a1] | 78 | owl_list_create(&(g->messagequeue)); |
---|
[f1e629d] | 79 | owl_dict_create(&(g->styledict)); |
---|
[7d4fbcd] | 80 | g->curmsg_vert_offset=0; |
---|
| 81 | g->resizepending=0; |
---|
| 82 | g->typwinactive=0; |
---|
| 83 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
| 84 | g->zaway=0; |
---|
| 85 | if (has_colors()) { |
---|
| 86 | g->hascolors=1; |
---|
| 87 | } |
---|
| 88 | g->colorpairs=COLOR_PAIRS; |
---|
| 89 | g->debug=OWL_DEBUG; |
---|
[1fd0b25] | 90 | g->searchactive=0; |
---|
| 91 | g->searchstring=NULL; |
---|
[7d4fbcd] | 92 | g->starttime=time(NULL); /* assumes we call init only a start time */ |
---|
[a8938c7] | 93 | g->buffercommand=NULL; |
---|
[700c712] | 94 | g->newmsgproc_pid=0; |
---|
[61e79a9] | 95 | |
---|
[7d4fbcd] | 96 | owl_global_set_config_format(g, 0); |
---|
| 97 | owl_global_set_userclue(g, OWL_USERCLUE_NONE); |
---|
| 98 | owl_global_set_no_have_config(g); |
---|
[10b866d] | 99 | owl_history_init(&(g->msghist)); |
---|
| 100 | owl_history_init(&(g->cmdhist)); |
---|
[5a9f6fe] | 101 | owl_history_set_norepeats(&(g->cmdhist)); |
---|
[7d4fbcd] | 102 | g->nextmsgid=0; |
---|
| 103 | |
---|
| 104 | owl_filterelement_create_true(&(g->fe_true)); |
---|
| 105 | owl_filterelement_create_false(&(g->fe_false)); |
---|
| 106 | owl_filterelement_create_null(&(g->fe_null)); |
---|
| 107 | |
---|
| 108 | _owl_global_setup_windows(g); |
---|
| 109 | |
---|
| 110 | /* Fill in some variables which don't have constant defaults */ |
---|
| 111 | /* TODO: come back later and check passwd file first */ |
---|
[a8938c7] | 112 | g->homedir=owl_strdup(getenv("HOME")); |
---|
[7d4fbcd] | 113 | |
---|
| 114 | owl_messagelist_create(&(g->msglist)); |
---|
| 115 | owl_mainwin_init(&(g->mw)); |
---|
| 116 | owl_popwin_init(&(g->pw)); |
---|
[d09e5a1] | 117 | |
---|
| 118 | g->aim_screenname=NULL; |
---|
| 119 | g->aim_loggedin=0; |
---|
[6a415e9] | 120 | owl_timer_create_countdown(&(g->aim_noop_timer), 30); |
---|
| 121 | owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0); |
---|
[de03334] | 122 | owl_timer_create_countdown(&(g->aim_buddyinfo_timer), 60); |
---|
[aa5f725] | 123 | owl_buddylist_init(&(g->buddylist)); |
---|
[2404c3a] | 124 | |
---|
[cf83b7a] | 125 | g->response=NULL; |
---|
[09489b89] | 126 | g->havezephyr=0; |
---|
| 127 | g->haveaim=0; |
---|
[a352335c] | 128 | owl_global_set_no_doaimevents(g); |
---|
[ec6ff52] | 129 | |
---|
| 130 | owl_errqueue_init(&(g->errqueue)); |
---|
[c9e72d1] | 131 | g->got_err_signal=0; |
---|
[5a95b69] | 132 | |
---|
| 133 | owl_zbuddylist_create(&(g->zbuddies)); |
---|
| 134 | owl_timer_create_countdown(&(g->zephyr_buddycheck_timer), 60*3); |
---|
[dab82f29] | 135 | |
---|
| 136 | owl_list_create(&(g->dispatchlist)); |
---|
[7d4fbcd] | 137 | } |
---|
| 138 | |
---|
| 139 | void _owl_global_setup_windows(owl_global *g) { |
---|
[ecd5dc5] | 140 | int cols, typwin_lines; |
---|
[7d4fbcd] | 141 | |
---|
| 142 | cols=g->cols; |
---|
[ecd5dc5] | 143 | typwin_lines=owl_global_get_typwin_lines(g); |
---|
[7d4fbcd] | 144 | |
---|
| 145 | /* set the new window sizes */ |
---|
| 146 | g->recwinlines=g->lines-(typwin_lines+2); |
---|
[176d3443] | 147 | if (g->recwinlines<0) { |
---|
| 148 | /* gotta deal with this */ |
---|
| 149 | g->recwinlines=0; |
---|
[ecd5dc5] | 150 | } |
---|
[7d4fbcd] | 151 | |
---|
[176d3443] | 152 | owl_function_debugmsg("_owl_global_setup_windows: about to call newwin(%i, %i, 0, 0)\n", g->recwinlines, cols); |
---|
| 153 | |
---|
[7d4fbcd] | 154 | /* create the new windows */ |
---|
| 155 | g->recwin=newwin(g->recwinlines, cols, 0, 0); |
---|
[ecd5dc5] | 156 | if (g->recwin==NULL) { |
---|
[176d3443] | 157 | owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n", g->recwinlines, cols); |
---|
[ecd5dc5] | 158 | endwin(); |
---|
| 159 | exit(50); |
---|
| 160 | } |
---|
| 161 | |
---|
[7d4fbcd] | 162 | g->sepwin=newwin(1, cols, g->recwinlines, 0); |
---|
| 163 | g->msgwin=newwin(1, cols, g->recwinlines+1, 0); |
---|
| 164 | g->typwin=newwin(typwin_lines, cols, g->recwinlines+2, 0); |
---|
| 165 | |
---|
| 166 | owl_editwin_set_curswin(&(g->tw), g->typwin, typwin_lines, g->cols); |
---|
| 167 | |
---|
| 168 | idlok(g->typwin, FALSE); |
---|
| 169 | idlok(g->recwin, FALSE); |
---|
| 170 | idlok(g->sepwin, FALSE); |
---|
| 171 | idlok(g->msgwin, FALSE); |
---|
| 172 | |
---|
| 173 | nodelay(g->typwin, 1); |
---|
| 174 | keypad(g->typwin, TRUE); |
---|
| 175 | wmove(g->typwin, 0, 0); |
---|
| 176 | |
---|
| 177 | meta(g->typwin, TRUE); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | owl_context *owl_global_get_context(owl_global *g) { |
---|
| 181 | return(&g->ctx); |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | int owl_global_get_lines(owl_global *g) { |
---|
| 185 | return(g->lines); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | int owl_global_get_cols(owl_global *g) { |
---|
| 189 | return(g->cols); |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | int owl_global_get_recwin_lines(owl_global *g) { |
---|
| 193 | return(g->recwinlines); |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | /* curmsg */ |
---|
| 197 | |
---|
| 198 | int owl_global_get_curmsg(owl_global *g) { |
---|
| 199 | return(g->curmsg); |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | void owl_global_set_curmsg(owl_global *g, int i) { |
---|
| 203 | g->curmsg=i; |
---|
| 204 | /* we will reset the vertical offset from here */ |
---|
| 205 | /* we might want to move this out to the functions later */ |
---|
| 206 | owl_global_set_curmsg_vert_offset(g, 0); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | /* topmsg */ |
---|
| 210 | |
---|
| 211 | int owl_global_get_topmsg(owl_global *g) { |
---|
| 212 | return(g->topmsg); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | void owl_global_set_topmsg(owl_global *g, int i) { |
---|
| 216 | g->topmsg=i; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | /* windows */ |
---|
| 220 | |
---|
| 221 | owl_mainwin *owl_global_get_mainwin(owl_global *g) { |
---|
| 222 | return(&(g->mw)); |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | owl_popwin *owl_global_get_popwin(owl_global *g) { |
---|
| 226 | return(&(g->pw)); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | /* msglist */ |
---|
| 230 | |
---|
| 231 | owl_messagelist *owl_global_get_msglist(owl_global *g) { |
---|
| 232 | return(&(g->msglist)); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | /* keyhandler */ |
---|
| 236 | |
---|
| 237 | owl_keyhandler *owl_global_get_keyhandler(owl_global *g) { |
---|
| 238 | return(&(g->kh)); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | /* curses windows */ |
---|
| 242 | |
---|
| 243 | WINDOW *owl_global_get_curs_recwin(owl_global *g) { |
---|
| 244 | return(g->recwin); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | WINDOW *owl_global_get_curs_sepwin(owl_global *g) { |
---|
| 248 | return(g->sepwin); |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | WINDOW *owl_global_get_curs_msgwin(owl_global *g) { |
---|
| 252 | return(g->msgwin); |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | WINDOW *owl_global_get_curs_typwin(owl_global *g) { |
---|
| 256 | return(g->typwin); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | /* typwin */ |
---|
| 260 | |
---|
| 261 | owl_editwin *owl_global_get_typwin(owl_global *g) { |
---|
| 262 | return(&(g->tw)); |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | /* buffercommand */ |
---|
| 266 | |
---|
| 267 | void owl_global_set_buffercommand(owl_global *g, char *command) { |
---|
[a8938c7] | 268 | if (g->buffercommand) owl_free(g->buffercommand); |
---|
| 269 | g->buffercommand=owl_strdup(command); |
---|
[7d4fbcd] | 270 | } |
---|
| 271 | |
---|
| 272 | char *owl_global_get_buffercommand(owl_global *g) { |
---|
[a8938c7] | 273 | if (g->buffercommand) return(g->buffercommand); |
---|
| 274 | return(""); |
---|
[7d4fbcd] | 275 | } |
---|
| 276 | |
---|
| 277 | /* refresh */ |
---|
| 278 | |
---|
| 279 | int owl_global_is_needrefresh(owl_global *g) { |
---|
| 280 | if (g->needrefresh==1) return(1); |
---|
| 281 | return(0); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | void owl_global_set_needrefresh(owl_global *g) { |
---|
| 285 | g->needrefresh=1; |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | void owl_global_set_noneedrefresh(owl_global *g) { |
---|
| 289 | g->needrefresh=0; |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | /* variable dictionary */ |
---|
| 293 | |
---|
| 294 | owl_vardict *owl_global_get_vardict(owl_global *g) { |
---|
| 295 | return &(g->vars); |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | /* command dictionary */ |
---|
| 299 | |
---|
| 300 | owl_cmddict *owl_global_get_cmddict(owl_global *g) { |
---|
| 301 | return &(g->cmds); |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | /* rightshift */ |
---|
| 305 | |
---|
| 306 | void owl_global_set_rightshift(owl_global *g, int i) { |
---|
| 307 | g->rightshift=i; |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | int owl_global_get_rightshift(owl_global *g) { |
---|
| 311 | return(g->rightshift); |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | /* typwin */ |
---|
| 315 | |
---|
| 316 | int owl_global_is_typwin_active(owl_global *g) { |
---|
| 317 | if (g->typwinactive==1) return(1); |
---|
| 318 | return(0); |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | void owl_global_set_typwin_active(owl_global *g) { |
---|
| 322 | g->typwinactive=1; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | void owl_global_set_typwin_inactive(owl_global *g) { |
---|
| 326 | g->typwinactive=0; |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | /* resize */ |
---|
| 330 | |
---|
| 331 | void owl_global_set_resize_pending(owl_global *g) { |
---|
| 332 | g->resizepending=1; |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | char *owl_global_get_homedir(owl_global *g) { |
---|
[a8938c7] | 336 | if (g->homedir) return(g->homedir); |
---|
| 337 | return("/"); |
---|
[7d4fbcd] | 338 | } |
---|
| 339 | |
---|
| 340 | int owl_global_get_direction(owl_global *g) { |
---|
| 341 | return(g->direction); |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | void owl_global_set_direction_downwards(owl_global *g) { |
---|
| 345 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | void owl_global_set_direction_upwards(owl_global *g) { |
---|
| 349 | g->direction=OWL_DIRECTION_UPWARDS; |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | /* perl stuff */ |
---|
| 353 | |
---|
| 354 | void owl_global_set_perlinterp(owl_global *g, void *p) { |
---|
| 355 | g->perl=p; |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | void *owl_global_get_perlinterp(owl_global *g) { |
---|
| 359 | return(g->perl); |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | int owl_global_is_config_format(owl_global *g) { |
---|
| 363 | if (g->config_format) return(1); |
---|
| 364 | return(0); |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | void owl_global_set_config_format(owl_global *g, int state) { |
---|
| 368 | if (state==1) { |
---|
| 369 | g->config_format=1; |
---|
| 370 | } else { |
---|
| 371 | g->config_format=0; |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | void owl_global_set_have_config(owl_global *g) { |
---|
| 376 | g->haveconfig=1; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | void owl_global_set_no_have_config(owl_global *g) { |
---|
| 380 | g->haveconfig=0; |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | int owl_global_have_config(owl_global *g) { |
---|
| 384 | if (g->haveconfig) return(1); |
---|
| 385 | return(0); |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | void owl_global_resize(owl_global *g, int x, int y) { |
---|
| 389 | /* resize the screen. If x or y is 0 use the terminal size */ |
---|
| 390 | struct winsize size; |
---|
| 391 | |
---|
| 392 | if (!g->resizepending) return; |
---|
| 393 | |
---|
| 394 | /* delete the current windows */ |
---|
| 395 | delwin(g->recwin); |
---|
| 396 | delwin(g->sepwin); |
---|
| 397 | delwin(g->msgwin); |
---|
| 398 | delwin(g->typwin); |
---|
| 399 | if (!isendwin()) { |
---|
| 400 | endwin(); |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | /* get the new size */ |
---|
| 404 | ioctl(STDIN_FILENO, TIOCGWINSZ, &size); |
---|
| 405 | if (x==0) { |
---|
[228326a] | 406 | if (size.ws_row) { |
---|
| 407 | g->lines=size.ws_row; |
---|
| 408 | } else { |
---|
| 409 | g->lines=LINES; |
---|
| 410 | } |
---|
[7d4fbcd] | 411 | } else { |
---|
[228326a] | 412 | g->lines=x; |
---|
[7d4fbcd] | 413 | } |
---|
| 414 | |
---|
| 415 | if (y==0) { |
---|
[228326a] | 416 | if (size.ws_col) { |
---|
| 417 | g->cols=size.ws_col; |
---|
| 418 | } else { |
---|
| 419 | g->cols=COLS; |
---|
| 420 | } |
---|
[7d4fbcd] | 421 | } else { |
---|
| 422 | g->cols=y; |
---|
| 423 | } |
---|
| 424 | |
---|
[dab82f29] | 425 | #ifdef HAVE_RESIZETERM |
---|
[74037d9] | 426 | resizeterm(size.ws_row, size.ws_col); |
---|
[dab82f29] | 427 | #endif |
---|
[228326a] | 428 | refresh(); |
---|
[7d4fbcd] | 429 | |
---|
| 430 | /* re-initialize the windows */ |
---|
| 431 | _owl_global_setup_windows(g); |
---|
| 432 | |
---|
[f1e629d] | 433 | /* in case any styles rely on the current width */ |
---|
| 434 | owl_messagelist_invalidate_formats(owl_global_get_msglist(g)); |
---|
| 435 | |
---|
[dab82f29] | 436 | /* recalculate the topmsg to make sure the current message is on |
---|
| 437 | * screen */ |
---|
| 438 | owl_function_calculate_topmsg(OWL_DIRECTION_NONE); |
---|
| 439 | |
---|
[7d4fbcd] | 440 | /* refresh stuff */ |
---|
| 441 | g->needrefresh=1; |
---|
| 442 | owl_mainwin_redisplay(&(g->mw)); |
---|
| 443 | sepbar(NULL); |
---|
[228326a] | 444 | owl_editwin_redisplay(&(g->tw), 0); |
---|
| 445 | owl_function_full_redisplay(&g); |
---|
[7d4fbcd] | 446 | |
---|
| 447 | /* TODO: this should handle other forms of popwins */ |
---|
| 448 | if (owl_popwin_is_active(owl_global_get_popwin(g)) |
---|
| 449 | && owl_global_get_viewwin(g)) { |
---|
| 450 | owl_popwin_refresh(owl_global_get_popwin(g)); |
---|
| 451 | owl_viewwin_redisplay(owl_global_get_viewwin(g), 0); |
---|
| 452 | } |
---|
| 453 | |
---|
[ecd5dc5] | 454 | owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col); |
---|
[7d4fbcd] | 455 | owl_function_makemsg(""); |
---|
| 456 | g->resizepending=0; |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | /* debug */ |
---|
| 460 | |
---|
| 461 | int owl_global_is_debug_fast(owl_global *g) { |
---|
| 462 | if (g->debug) return(1); |
---|
| 463 | return(0); |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | /* starttime */ |
---|
| 467 | |
---|
| 468 | time_t owl_global_get_starttime(owl_global *g) { |
---|
| 469 | return(g->starttime); |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | time_t owl_global_get_runtime(owl_global *g) { |
---|
| 473 | return(time(NULL)-g->starttime); |
---|
| 474 | } |
---|
| 475 | |
---|
[488ebf6] | 476 | char *owl_global_get_runtime_string(owl_global *g) { |
---|
[7d4fbcd] | 477 | time_t diff; |
---|
| 478 | |
---|
| 479 | diff=time(NULL)-owl_global_get_starttime(g); |
---|
| 480 | |
---|
| 481 | /* print something nicer later */ |
---|
[488ebf6] | 482 | return(owl_sprintf("%i seconds", (int) diff)); |
---|
[7d4fbcd] | 483 | } |
---|
| 484 | |
---|
[61e79a9] | 485 | char *owl_global_get_hostname(owl_global *g) { |
---|
[a8938c7] | 486 | if (g->thishost) return(g->thishost); |
---|
| 487 | return(""); |
---|
[61e79a9] | 488 | } |
---|
| 489 | |
---|
[7d4fbcd] | 490 | /* userclue */ |
---|
| 491 | |
---|
| 492 | void owl_global_set_userclue(owl_global *g, int clue) { |
---|
| 493 | g->userclue=clue; |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | void owl_global_add_userclue(owl_global *g, int clue) { |
---|
| 497 | g->userclue|=clue; |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | int owl_global_get_userclue(owl_global *g) { |
---|
| 501 | return(g->userclue); |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | int owl_global_is_userclue(owl_global *g, int clue) { |
---|
| 505 | if (g->userclue & clue) return(1); |
---|
| 506 | return(0); |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | /* viewwin */ |
---|
| 510 | |
---|
| 511 | owl_viewwin *owl_global_get_viewwin(owl_global *g) { |
---|
| 512 | return(&(g->vw)); |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | |
---|
| 516 | /* vert offset */ |
---|
| 517 | |
---|
| 518 | int owl_global_get_curmsg_vert_offset(owl_global *g) { |
---|
| 519 | return(g->curmsg_vert_offset); |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | void owl_global_set_curmsg_vert_offset(owl_global *g, int i) { |
---|
| 523 | g->curmsg_vert_offset=i; |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | /* startup args */ |
---|
| 527 | |
---|
| 528 | void owl_global_set_startupargs(owl_global *g, int argc, char **argv) { |
---|
[a8938c7] | 529 | int i, len; |
---|
| 530 | |
---|
| 531 | if (g->startupargs) owl_free(g->startupargs); |
---|
| 532 | |
---|
| 533 | len=0; |
---|
| 534 | for (i=0; i<argc; i++) { |
---|
[591e6aa7] | 535 | len+=strlen(argv[i])+5; |
---|
[a8938c7] | 536 | } |
---|
[bc7ebf6] | 537 | g->startupargs=owl_malloc(len+5); |
---|
[7d4fbcd] | 538 | |
---|
| 539 | strcpy(g->startupargs, ""); |
---|
| 540 | for (i=0; i<argc; i++) { |
---|
[bc7ebf6] | 541 | sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]); |
---|
[7d4fbcd] | 542 | } |
---|
| 543 | g->startupargs[strlen(g->startupargs)-1]='\0'; |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | char *owl_global_get_startupargs(owl_global *g) { |
---|
[a8938c7] | 547 | if (g->startupargs) return(g->startupargs); |
---|
| 548 | return(""); |
---|
[7d4fbcd] | 549 | } |
---|
| 550 | |
---|
| 551 | /* history */ |
---|
| 552 | |
---|
[10b866d] | 553 | owl_history *owl_global_get_msg_history(owl_global *g) { |
---|
| 554 | return(&(g->msghist)); |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | owl_history *owl_global_get_cmd_history(owl_global *g) { |
---|
| 558 | return(&(g->cmdhist)); |
---|
[7d4fbcd] | 559 | } |
---|
| 560 | |
---|
| 561 | /* filterlist */ |
---|
| 562 | |
---|
| 563 | owl_list *owl_global_get_filterlist(owl_global *g) { |
---|
| 564 | return(&(g->filterlist)); |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | owl_filter *owl_global_get_filter(owl_global *g, char *name) { |
---|
| 568 | int i, j; |
---|
| 569 | owl_filter *f; |
---|
| 570 | |
---|
| 571 | j=owl_list_get_size(&(g->filterlist)); |
---|
| 572 | for (i=0; i<j; i++) { |
---|
| 573 | f=owl_list_get_element(&(g->filterlist), i); |
---|
| 574 | if (!strcmp(name, owl_filter_get_name(f))) { |
---|
| 575 | return(f); |
---|
| 576 | } |
---|
| 577 | } |
---|
| 578 | return(NULL); |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | void owl_global_add_filter(owl_global *g, owl_filter *f) { |
---|
| 582 | owl_list_append_element(&(g->filterlist), f); |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | void owl_global_remove_filter(owl_global *g, char *name) { |
---|
| 586 | int i, j; |
---|
| 587 | owl_filter *f; |
---|
| 588 | |
---|
| 589 | j=owl_list_get_size(&(g->filterlist)); |
---|
| 590 | for (i=0; i<j; i++) { |
---|
| 591 | f=owl_list_get_element(&(g->filterlist), i); |
---|
| 592 | if (!strcmp(name, owl_filter_get_name(f))) { |
---|
| 593 | owl_filter_free(f); |
---|
| 594 | owl_list_remove_element(&(g->filterlist), i); |
---|
| 595 | break; |
---|
| 596 | } |
---|
| 597 | } |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | /* nextmsgid */ |
---|
| 601 | |
---|
| 602 | int owl_global_get_nextmsgid(owl_global *g) { |
---|
| 603 | return(g->nextmsgid++); |
---|
| 604 | } |
---|
| 605 | |
---|
| 606 | /* current view */ |
---|
| 607 | |
---|
| 608 | owl_view *owl_global_get_current_view(owl_global *g) { |
---|
| 609 | return(&(g->current_view)); |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | owl_filterelement *owl_global_get_filterelement_true(owl_global *g) { |
---|
| 613 | return(&(g->fe_true)); |
---|
| 614 | } |
---|
| 615 | |
---|
| 616 | owl_filterelement *owl_global_get_filterelement_false(owl_global *g) { |
---|
| 617 | return(&(g->fe_false)); |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | owl_filterelement *owl_global_get_filterelement_null(owl_global *g) { |
---|
| 621 | return(&(g->fe_null)); |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | /* has colors */ |
---|
| 625 | |
---|
| 626 | int owl_global_get_hascolors(owl_global *g) { |
---|
| 627 | if (g->hascolors) return(1); |
---|
| 628 | return(0); |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | /* color pairs */ |
---|
| 632 | |
---|
| 633 | int owl_global_get_colorpairs(owl_global *g) { |
---|
| 634 | return(g->colorpairs); |
---|
| 635 | } |
---|
| 636 | |
---|
| 637 | /* puntlist */ |
---|
| 638 | |
---|
| 639 | owl_list *owl_global_get_puntlist(owl_global *g) { |
---|
| 640 | return(&(g->puntlist)); |
---|
| 641 | } |
---|
| 642 | |
---|
| 643 | int owl_global_message_is_puntable(owl_global *g, owl_message *m) { |
---|
| 644 | owl_list *pl; |
---|
| 645 | int i, j; |
---|
| 646 | |
---|
| 647 | pl=owl_global_get_puntlist(g); |
---|
| 648 | j=owl_list_get_size(pl); |
---|
| 649 | for (i=0; i<j; i++) { |
---|
| 650 | if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1); |
---|
| 651 | } |
---|
| 652 | return(0); |
---|
| 653 | } |
---|
| 654 | |
---|
| 655 | int owl_global_should_followlast(owl_global *g) { |
---|
| 656 | owl_view *v; |
---|
| 657 | |
---|
| 658 | if (!owl_global_is__followlast(g)) return(0); |
---|
| 659 | |
---|
| 660 | v=owl_global_get_current_view(g); |
---|
| 661 | |
---|
| 662 | if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1); |
---|
| 663 | return(0); |
---|
| 664 | } |
---|
[1fd0b25] | 665 | |
---|
| 666 | int owl_global_is_search_active(owl_global *g) { |
---|
| 667 | if (g->searchactive) return(1); |
---|
| 668 | return(0); |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | void owl_global_set_search_active(owl_global *g, char *string) { |
---|
| 672 | g->searchactive=1; |
---|
| 673 | if (g->searchstring != NULL) owl_free(g->searchstring); |
---|
| 674 | g->searchstring=owl_strdup(string); |
---|
| 675 | } |
---|
| 676 | |
---|
| 677 | void owl_global_set_search_inactive(owl_global *g) { |
---|
| 678 | g->searchactive=0; |
---|
| 679 | } |
---|
| 680 | |
---|
| 681 | char *owl_global_get_search_string(owl_global *g) { |
---|
| 682 | if (g->searchstring==NULL) return(""); |
---|
| 683 | return(g->searchstring); |
---|
| 684 | } |
---|
[700c712] | 685 | |
---|
| 686 | void owl_global_set_newmsgproc_pid(owl_global *g, int i) { |
---|
| 687 | g->newmsgproc_pid=i; |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | int owl_global_get_newmsgproc_pid(owl_global *g) { |
---|
| 691 | return(g->newmsgproc_pid); |
---|
| 692 | } |
---|
| 693 | |
---|
[8262340] | 694 | void owl_global_add_to_malloced(owl_global *g, int i) { |
---|
| 695 | g->malloced+=i; |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | void owl_global_add_to_freed(owl_global *g, int i) { |
---|
| 699 | g->freed+=1; |
---|
| 700 | } |
---|
| 701 | |
---|
| 702 | int owl_global_get_malloced(owl_global *g) { |
---|
| 703 | return(g->malloced); |
---|
| 704 | } |
---|
| 705 | |
---|
| 706 | int owl_global_get_freed(owl_global *g) { |
---|
| 707 | return(g->freed); |
---|
| 708 | } |
---|
| 709 | |
---|
| 710 | int owl_global_get_meminuse(owl_global *g) { |
---|
| 711 | return(g->malloced-g->freed); |
---|
| 712 | } |
---|
[d09e5a1] | 713 | |
---|
| 714 | /* AIM stuff */ |
---|
| 715 | |
---|
[6a415e9] | 716 | int owl_global_is_aimloggedin(owl_global *g) |
---|
| 717 | { |
---|
[d09e5a1] | 718 | if (g->aim_loggedin) return(1); |
---|
| 719 | return(0); |
---|
| 720 | } |
---|
| 721 | |
---|
[6a415e9] | 722 | char *owl_global_get_aim_screenname(owl_global *g) |
---|
| 723 | { |
---|
[a352335c] | 724 | if (owl_global_is_aimloggedin(g)) { |
---|
| 725 | return (g->aim_screenname); |
---|
| 726 | } |
---|
| 727 | return(""); |
---|
[d09e5a1] | 728 | } |
---|
| 729 | |
---|
[6a415e9] | 730 | void owl_global_set_aimloggedin(owl_global *g, char *screenname) |
---|
| 731 | { |
---|
[d09e5a1] | 732 | g->aim_loggedin=1; |
---|
| 733 | if (g->aim_screenname) owl_free(g->aim_screenname); |
---|
| 734 | g->aim_screenname=owl_strdup(screenname); |
---|
| 735 | } |
---|
| 736 | |
---|
[6a415e9] | 737 | void owl_global_set_aimnologgedin(owl_global *g) |
---|
| 738 | { |
---|
[d09e5a1] | 739 | g->aim_loggedin=0; |
---|
| 740 | } |
---|
| 741 | |
---|
[a352335c] | 742 | int owl_global_is_doaimevents(owl_global *g) |
---|
| 743 | { |
---|
| 744 | if (g->aim_doprocessing) return(1); |
---|
| 745 | return(0); |
---|
| 746 | } |
---|
| 747 | |
---|
| 748 | void owl_global_set_doaimevents(owl_global *g) |
---|
| 749 | { |
---|
| 750 | g->aim_doprocessing=1; |
---|
| 751 | } |
---|
| 752 | |
---|
| 753 | void owl_global_set_no_doaimevents(owl_global *g) |
---|
| 754 | { |
---|
| 755 | g->aim_doprocessing=0; |
---|
| 756 | } |
---|
| 757 | |
---|
[6a415e9] | 758 | aim_session_t *owl_global_get_aimsess(owl_global *g) |
---|
| 759 | { |
---|
[d09e5a1] | 760 | return(&(g->aimsess)); |
---|
| 761 | } |
---|
| 762 | |
---|
[c15bbfb] | 763 | aim_conn_t *owl_global_get_bosconn(owl_global *g) |
---|
| 764 | { |
---|
| 765 | return(&(g->bosconn)); |
---|
| 766 | } |
---|
| 767 | |
---|
| 768 | void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn) |
---|
[6a415e9] | 769 | { |
---|
[c15bbfb] | 770 | g->bosconn=*conn; |
---|
[d09e5a1] | 771 | } |
---|
| 772 | |
---|
[6a415e9] | 773 | int owl_global_is_aimnop_time(owl_global *g) |
---|
| 774 | { |
---|
| 775 | if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1); |
---|
[d09e5a1] | 776 | return(0); |
---|
| 777 | } |
---|
| 778 | |
---|
[6a415e9] | 779 | void owl_global_aimnop_sent(owl_global *g) |
---|
| 780 | { |
---|
| 781 | owl_timer_reset(&(g->aim_noop_timer)); |
---|
| 782 | } |
---|
[d09e5a1] | 783 | |
---|
[6a415e9] | 784 | owl_timer *owl_global_get_aim_login_timer(owl_global *g) |
---|
| 785 | { |
---|
| 786 | return(&(g->aim_ignorelogin_timer)); |
---|
[d09e5a1] | 787 | } |
---|
| 788 | |
---|
| 789 | /* message queue */ |
---|
| 790 | |
---|
[6a415e9] | 791 | void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m) |
---|
| 792 | { |
---|
[d09e5a1] | 793 | owl_list_append_element(&(g->messagequeue), m); |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | /* pop off the first message and return it. Return NULL if the queue |
---|
| 797 | * is empty. The caller should free the message after using it, if |
---|
| 798 | * necessary. |
---|
| 799 | */ |
---|
[6a415e9] | 800 | owl_message *owl_global_messageuque_popmsg(owl_global *g) |
---|
| 801 | { |
---|
[d09e5a1] | 802 | owl_message *out; |
---|
| 803 | |
---|
| 804 | if (owl_list_get_size(&(g->messagequeue))==0) return(NULL); |
---|
| 805 | out=owl_list_get_element(&(g->messagequeue), 0); |
---|
| 806 | owl_list_remove_element(&(g->messagequeue), 0); |
---|
| 807 | return(out); |
---|
| 808 | } |
---|
| 809 | |
---|
[6a415e9] | 810 | int owl_global_messagequeue_pending(owl_global *g) |
---|
| 811 | { |
---|
[d09e5a1] | 812 | if (owl_list_get_size(&(g->messagequeue))==0) return(0); |
---|
| 813 | return(1); |
---|
| 814 | } |
---|
[aa5f725] | 815 | |
---|
[6a415e9] | 816 | owl_buddylist *owl_global_get_buddylist(owl_global *g) |
---|
| 817 | { |
---|
[aa5f725] | 818 | return(&(g->buddylist)); |
---|
| 819 | } |
---|
| 820 | |
---|
[bd3f232] | 821 | /* style */ |
---|
| 822 | |
---|
| 823 | /* Return the style with name 'name'. If it does not exist return |
---|
| 824 | * NULL */ |
---|
| 825 | owl_style *owl_global_get_style_by_name(owl_global *g, char *name) |
---|
| 826 | { |
---|
[f1e629d] | 827 | return owl_dict_find_element(&(g->styledict), name); |
---|
| 828 | } |
---|
| 829 | |
---|
| 830 | /* creates a list and fills it in with keys. duplicates the keys, |
---|
| 831 | * so they will need to be freed by the caller. */ |
---|
| 832 | int owl_global_get_style_names(owl_global *g, owl_list *l) { |
---|
| 833 | return owl_dict_get_keys(&(g->styledict), l); |
---|
[bd3f232] | 834 | } |
---|
| 835 | |
---|
[cf83b7a] | 836 | void owl_global_add_style(owl_global *g, owl_style *s) |
---|
| 837 | { |
---|
[f1e629d] | 838 | owl_dict_insert_element(&(g->styledict), owl_style_get_name(s), |
---|
| 839 | s, (void(*)(void*))owl_style_free); |
---|
[bd3f232] | 840 | } |
---|
[cf83b7a] | 841 | |
---|
| 842 | char *owl_global_get_response(owl_global *g) |
---|
| 843 | { |
---|
| 844 | if (g->response==NULL) return(""); |
---|
| 845 | return(g->response); |
---|
| 846 | } |
---|
| 847 | |
---|
| 848 | void owl_global_set_response(owl_global *g, char *resp) |
---|
| 849 | { |
---|
| 850 | if (g->response) owl_free(g->response); |
---|
[210c261] | 851 | g->response=owl_strdup(resp); |
---|
[cf83b7a] | 852 | } |
---|
[09489b89] | 853 | |
---|
| 854 | |
---|
| 855 | void owl_global_set_haveaim(owl_global *g) |
---|
| 856 | { |
---|
| 857 | g->haveaim=1; |
---|
| 858 | } |
---|
| 859 | |
---|
| 860 | int owl_global_is_haveaim(owl_global *g) |
---|
| 861 | { |
---|
| 862 | if (g->haveaim) return(1); |
---|
| 863 | return(0); |
---|
| 864 | } |
---|
| 865 | |
---|
| 866 | void owl_global_set_havezephyr(owl_global *g) |
---|
| 867 | { |
---|
| 868 | g->havezephyr=1; |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | int owl_global_is_havezephyr(owl_global *g) |
---|
| 872 | { |
---|
| 873 | if (g->havezephyr) return(1); |
---|
| 874 | return(0); |
---|
| 875 | } |
---|
[de03334] | 876 | |
---|
| 877 | owl_timer *owl_global_get_aim_buddyinfo_timer(owl_global *g) |
---|
| 878 | { |
---|
| 879 | return(&(g->aim_buddyinfo_timer)); |
---|
| 880 | } |
---|
[ec6ff52] | 881 | |
---|
| 882 | owl_errqueue *owl_global_get_errqueue(owl_global *g) |
---|
| 883 | { |
---|
| 884 | return(&(g->errqueue)); |
---|
| 885 | } |
---|
[c9e72d1] | 886 | |
---|
| 887 | void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo) |
---|
| 888 | { |
---|
| 889 | g->got_err_signal = signum; |
---|
| 890 | if (siginfo) { |
---|
| 891 | g->err_signal_info = *siginfo; |
---|
| 892 | } else { |
---|
| 893 | memset(&(g->err_signal_info), 0, sizeof(siginfo_t)); |
---|
| 894 | } |
---|
| 895 | } |
---|
| 896 | |
---|
| 897 | int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo) |
---|
| 898 | { |
---|
| 899 | int signum; |
---|
| 900 | if (siginfo && g->got_err_signal) { |
---|
| 901 | *siginfo = g->err_signal_info; |
---|
| 902 | } |
---|
| 903 | signum = g->got_err_signal; |
---|
| 904 | g->got_err_signal = 0; |
---|
| 905 | return signum; |
---|
| 906 | } |
---|
| 907 | |
---|
[5a95b69] | 908 | owl_timer *owl_global_get_zephyr_buddycheck_timer(owl_global *g) |
---|
| 909 | { |
---|
| 910 | return(&(g->zephyr_buddycheck_timer)); |
---|
| 911 | } |
---|
| 912 | |
---|
| 913 | owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g) |
---|
| 914 | { |
---|
| 915 | return(&(g->zbuddies)); |
---|
| 916 | } |
---|
[8232149] | 917 | |
---|
| 918 | struct termios *owl_global_get_startup_tio(owl_global *g) |
---|
| 919 | { |
---|
| 920 | return(&(g->startup_tio)); |
---|
| 921 | } |
---|
[dab82f29] | 922 | |
---|
| 923 | owl_list *owl_global_get_dispatchlist(owl_global *g) |
---|
| 924 | { |
---|
| 925 | return &(g->dispatchlist); |
---|
| 926 | } |
---|