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