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