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