[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; |
---|
| 66 | g->debug=OWL_DEBUG; |
---|
[1fd0b25] | 67 | g->searchactive=0; |
---|
| 68 | g->searchstring=NULL; |
---|
[7d4fbcd] | 69 | g->starttime=time(NULL); /* assumes we call init only a start time */ |
---|
[700c712] | 70 | g->newmsgproc_pid=0; |
---|
[61e79a9] | 71 | |
---|
[7d4fbcd] | 72 | owl_global_set_config_format(g, 0); |
---|
| 73 | owl_global_set_userclue(g, OWL_USERCLUE_NONE); |
---|
| 74 | owl_global_set_no_have_config(g); |
---|
[10b866d] | 75 | owl_history_init(&(g->msghist)); |
---|
| 76 | owl_history_init(&(g->cmdhist)); |
---|
[5a9f6fe] | 77 | owl_history_set_norepeats(&(g->cmdhist)); |
---|
[7d4fbcd] | 78 | g->nextmsgid=0; |
---|
| 79 | |
---|
| 80 | owl_filterelement_create_true(&(g->fe_true)); |
---|
| 81 | owl_filterelement_create_false(&(g->fe_false)); |
---|
| 82 | owl_filterelement_create_null(&(g->fe_null)); |
---|
| 83 | |
---|
| 84 | _owl_global_setup_windows(g); |
---|
| 85 | |
---|
| 86 | /* Fill in some variables which don't have constant defaults */ |
---|
| 87 | /* TODO: come back later and check passwd file first */ |
---|
[a8938c7] | 88 | g->homedir=owl_strdup(getenv("HOME")); |
---|
[7d4fbcd] | 89 | |
---|
| 90 | owl_messagelist_create(&(g->msglist)); |
---|
| 91 | owl_mainwin_init(&(g->mw)); |
---|
| 92 | owl_popwin_init(&(g->pw)); |
---|
[d09e5a1] | 93 | |
---|
| 94 | g->aim_screenname=NULL; |
---|
| 95 | g->aim_loggedin=0; |
---|
[6a415e9] | 96 | owl_timer_create_countdown(&(g->aim_noop_timer), 30); |
---|
| 97 | owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0); |
---|
[de03334] | 98 | owl_timer_create_countdown(&(g->aim_buddyinfo_timer), 60); |
---|
[aa5f725] | 99 | owl_buddylist_init(&(g->buddylist)); |
---|
[2404c3a] | 100 | |
---|
[09489b89] | 101 | g->havezephyr=0; |
---|
| 102 | g->haveaim=0; |
---|
[a352335c] | 103 | owl_global_set_no_doaimevents(g); |
---|
[ec6ff52] | 104 | |
---|
| 105 | owl_errqueue_init(&(g->errqueue)); |
---|
[c9e72d1] | 106 | g->got_err_signal=0; |
---|
[5a95b69] | 107 | |
---|
| 108 | owl_zbuddylist_create(&(g->zbuddies)); |
---|
| 109 | owl_timer_create_countdown(&(g->zephyr_buddycheck_timer), 60*3); |
---|
[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 | |
---|
[74037d9] | 398 | resizeterm(size.ws_row, size.ws_col); |
---|
[7d4fbcd] | 399 | |
---|
| 400 | /* re-initialize the windows */ |
---|
| 401 | _owl_global_setup_windows(g); |
---|
| 402 | |
---|
[f1e629d] | 403 | /* in case any styles rely on the current width */ |
---|
| 404 | owl_messagelist_invalidate_formats(owl_global_get_msglist(g)); |
---|
| 405 | |
---|
[7d4fbcd] | 406 | /* refresh stuff */ |
---|
| 407 | g->needrefresh=1; |
---|
| 408 | owl_mainwin_redisplay(&(g->mw)); |
---|
| 409 | sepbar(NULL); |
---|
| 410 | |
---|
| 411 | if (owl_global_is_typwin_active(g)) { |
---|
| 412 | owl_editwin_redisplay(&(g->tw), 0); |
---|
| 413 | } |
---|
| 414 | /* TODO: this should handle other forms of popwins */ |
---|
| 415 | if (owl_popwin_is_active(owl_global_get_popwin(g)) |
---|
| 416 | && owl_global_get_viewwin(g)) { |
---|
| 417 | owl_popwin_refresh(owl_global_get_popwin(g)); |
---|
| 418 | owl_viewwin_redisplay(owl_global_get_viewwin(g), 0); |
---|
| 419 | } |
---|
| 420 | |
---|
[ecd5dc5] | 421 | owl_function_debugmsg("New size is %i lines, %i cols.", size.ws_row, size.ws_col); |
---|
[7d4fbcd] | 422 | owl_function_makemsg(""); |
---|
| 423 | g->resizepending=0; |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | /* debug */ |
---|
| 427 | |
---|
| 428 | int owl_global_is_debug_fast(owl_global *g) { |
---|
| 429 | if (g->debug) return(1); |
---|
| 430 | return(0); |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | /* starttime */ |
---|
| 434 | |
---|
| 435 | time_t owl_global_get_starttime(owl_global *g) { |
---|
| 436 | return(g->starttime); |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | time_t owl_global_get_runtime(owl_global *g) { |
---|
| 440 | return(time(NULL)-g->starttime); |
---|
| 441 | } |
---|
| 442 | |
---|
| 443 | void owl_global_get_runtime_string(owl_global *g, char *buff) { |
---|
| 444 | time_t diff; |
---|
| 445 | |
---|
| 446 | diff=time(NULL)-owl_global_get_starttime(g); |
---|
| 447 | |
---|
| 448 | /* print something nicer later */ |
---|
| 449 | sprintf(buff, "%i seconds", (int) diff); |
---|
| 450 | } |
---|
| 451 | |
---|
[61e79a9] | 452 | char *owl_global_get_hostname(owl_global *g) { |
---|
[a8938c7] | 453 | if (g->thishost) return(g->thishost); |
---|
| 454 | return(""); |
---|
[61e79a9] | 455 | } |
---|
| 456 | |
---|
[7d4fbcd] | 457 | /* userclue */ |
---|
| 458 | |
---|
| 459 | void owl_global_set_userclue(owl_global *g, int clue) { |
---|
| 460 | g->userclue=clue; |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | void owl_global_add_userclue(owl_global *g, int clue) { |
---|
| 464 | g->userclue|=clue; |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | int owl_global_get_userclue(owl_global *g) { |
---|
| 468 | return(g->userclue); |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | int owl_global_is_userclue(owl_global *g, int clue) { |
---|
| 472 | if (g->userclue & clue) return(1); |
---|
| 473 | return(0); |
---|
| 474 | } |
---|
| 475 | |
---|
| 476 | /* viewwin */ |
---|
| 477 | |
---|
| 478 | owl_viewwin *owl_global_get_viewwin(owl_global *g) { |
---|
| 479 | return(&(g->vw)); |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | |
---|
| 483 | /* vert offset */ |
---|
| 484 | |
---|
| 485 | int owl_global_get_curmsg_vert_offset(owl_global *g) { |
---|
| 486 | return(g->curmsg_vert_offset); |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | void owl_global_set_curmsg_vert_offset(owl_global *g, int i) { |
---|
| 490 | g->curmsg_vert_offset=i; |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | /* startup args */ |
---|
| 494 | |
---|
| 495 | void owl_global_set_startupargs(owl_global *g, int argc, char **argv) { |
---|
[a8938c7] | 496 | int i, len; |
---|
| 497 | |
---|
| 498 | if (g->startupargs) owl_free(g->startupargs); |
---|
| 499 | |
---|
| 500 | len=0; |
---|
| 501 | for (i=0; i<argc; i++) { |
---|
[591e6aa7] | 502 | len+=strlen(argv[i])+5; |
---|
[a8938c7] | 503 | } |
---|
| 504 | g->startupargs=malloc(len+5); |
---|
[7d4fbcd] | 505 | |
---|
| 506 | strcpy(g->startupargs, ""); |
---|
| 507 | for (i=0; i<argc; i++) { |
---|
| 508 | sprintf(g->startupargs, "%s%s ", g->startupargs, argv[i]); |
---|
| 509 | } |
---|
| 510 | g->startupargs[strlen(g->startupargs)-1]='\0'; |
---|
| 511 | } |
---|
| 512 | |
---|
| 513 | char *owl_global_get_startupargs(owl_global *g) { |
---|
[a8938c7] | 514 | if (g->startupargs) return(g->startupargs); |
---|
| 515 | return(""); |
---|
[7d4fbcd] | 516 | } |
---|
| 517 | |
---|
| 518 | /* history */ |
---|
| 519 | |
---|
[10b866d] | 520 | owl_history *owl_global_get_msg_history(owl_global *g) { |
---|
| 521 | return(&(g->msghist)); |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | owl_history *owl_global_get_cmd_history(owl_global *g) { |
---|
| 525 | return(&(g->cmdhist)); |
---|
[7d4fbcd] | 526 | } |
---|
| 527 | |
---|
[afbf668] | 528 | /* muxevents */ |
---|
| 529 | |
---|
| 530 | owl_muxevents *owl_global_get_muxevents(owl_global *g) { |
---|
| 531 | return(&(g->muxevents)); |
---|
| 532 | } |
---|
| 533 | |
---|
[7d4fbcd] | 534 | /* filterlist */ |
---|
| 535 | |
---|
| 536 | owl_list *owl_global_get_filterlist(owl_global *g) { |
---|
| 537 | return(&(g->filterlist)); |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | owl_filter *owl_global_get_filter(owl_global *g, char *name) { |
---|
| 541 | int i, j; |
---|
| 542 | owl_filter *f; |
---|
| 543 | |
---|
| 544 | j=owl_list_get_size(&(g->filterlist)); |
---|
| 545 | for (i=0; i<j; i++) { |
---|
| 546 | f=owl_list_get_element(&(g->filterlist), i); |
---|
| 547 | if (!strcmp(name, owl_filter_get_name(f))) { |
---|
| 548 | return(f); |
---|
| 549 | } |
---|
| 550 | } |
---|
| 551 | return(NULL); |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | void owl_global_add_filter(owl_global *g, owl_filter *f) { |
---|
| 555 | owl_list_append_element(&(g->filterlist), f); |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | void owl_global_remove_filter(owl_global *g, char *name) { |
---|
| 559 | int i, j; |
---|
| 560 | owl_filter *f; |
---|
| 561 | |
---|
| 562 | j=owl_list_get_size(&(g->filterlist)); |
---|
| 563 | for (i=0; i<j; i++) { |
---|
| 564 | f=owl_list_get_element(&(g->filterlist), i); |
---|
| 565 | if (!strcmp(name, owl_filter_get_name(f))) { |
---|
| 566 | owl_filter_free(f); |
---|
| 567 | owl_list_remove_element(&(g->filterlist), i); |
---|
| 568 | break; |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | /* nextmsgid */ |
---|
| 574 | |
---|
| 575 | int owl_global_get_nextmsgid(owl_global *g) { |
---|
| 576 | return(g->nextmsgid++); |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | /* current view */ |
---|
| 580 | |
---|
| 581 | owl_view *owl_global_get_current_view(owl_global *g) { |
---|
| 582 | return(&(g->current_view)); |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | owl_filterelement *owl_global_get_filterelement_true(owl_global *g) { |
---|
| 586 | return(&(g->fe_true)); |
---|
| 587 | } |
---|
| 588 | |
---|
| 589 | owl_filterelement *owl_global_get_filterelement_false(owl_global *g) { |
---|
| 590 | return(&(g->fe_false)); |
---|
| 591 | } |
---|
| 592 | |
---|
| 593 | owl_filterelement *owl_global_get_filterelement_null(owl_global *g) { |
---|
| 594 | return(&(g->fe_null)); |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | /* has colors */ |
---|
| 598 | |
---|
| 599 | int owl_global_get_hascolors(owl_global *g) { |
---|
| 600 | if (g->hascolors) return(1); |
---|
| 601 | return(0); |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | /* color pairs */ |
---|
| 605 | |
---|
| 606 | int owl_global_get_colorpairs(owl_global *g) { |
---|
| 607 | return(g->colorpairs); |
---|
| 608 | } |
---|
| 609 | |
---|
| 610 | /* puntlist */ |
---|
| 611 | |
---|
| 612 | owl_list *owl_global_get_puntlist(owl_global *g) { |
---|
| 613 | return(&(g->puntlist)); |
---|
| 614 | } |
---|
| 615 | |
---|
| 616 | int owl_global_message_is_puntable(owl_global *g, owl_message *m) { |
---|
| 617 | owl_list *pl; |
---|
| 618 | int i, j; |
---|
| 619 | |
---|
| 620 | pl=owl_global_get_puntlist(g); |
---|
| 621 | j=owl_list_get_size(pl); |
---|
| 622 | for (i=0; i<j; i++) { |
---|
| 623 | if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1); |
---|
| 624 | } |
---|
| 625 | return(0); |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | int owl_global_should_followlast(owl_global *g) { |
---|
| 629 | owl_view *v; |
---|
| 630 | |
---|
| 631 | if (!owl_global_is__followlast(g)) return(0); |
---|
| 632 | |
---|
| 633 | v=owl_global_get_current_view(g); |
---|
| 634 | |
---|
| 635 | if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1); |
---|
| 636 | return(0); |
---|
| 637 | } |
---|
[1fd0b25] | 638 | |
---|
| 639 | int owl_global_is_search_active(owl_global *g) { |
---|
| 640 | if (g->searchactive) return(1); |
---|
| 641 | return(0); |
---|
| 642 | } |
---|
| 643 | |
---|
| 644 | void owl_global_set_search_active(owl_global *g, char *string) { |
---|
| 645 | g->searchactive=1; |
---|
| 646 | if (g->searchstring != NULL) owl_free(g->searchstring); |
---|
| 647 | g->searchstring=owl_strdup(string); |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | void owl_global_set_search_inactive(owl_global *g) { |
---|
| 651 | g->searchactive=0; |
---|
| 652 | } |
---|
| 653 | |
---|
| 654 | char *owl_global_get_search_string(owl_global *g) { |
---|
| 655 | if (g->searchstring==NULL) return(""); |
---|
| 656 | return(g->searchstring); |
---|
| 657 | } |
---|
[700c712] | 658 | |
---|
| 659 | void owl_global_set_newmsgproc_pid(owl_global *g, int i) { |
---|
| 660 | g->newmsgproc_pid=i; |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | int owl_global_get_newmsgproc_pid(owl_global *g) { |
---|
| 664 | return(g->newmsgproc_pid); |
---|
| 665 | } |
---|
| 666 | |
---|
[8262340] | 667 | void owl_global_add_to_malloced(owl_global *g, int i) { |
---|
| 668 | g->malloced+=i; |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | void owl_global_add_to_freed(owl_global *g, int i) { |
---|
| 672 | g->freed+=1; |
---|
| 673 | } |
---|
| 674 | |
---|
| 675 | int owl_global_get_malloced(owl_global *g) { |
---|
| 676 | return(g->malloced); |
---|
| 677 | } |
---|
| 678 | |
---|
| 679 | int owl_global_get_freed(owl_global *g) { |
---|
| 680 | return(g->freed); |
---|
| 681 | } |
---|
| 682 | |
---|
| 683 | int owl_global_get_meminuse(owl_global *g) { |
---|
| 684 | return(g->malloced-g->freed); |
---|
| 685 | } |
---|
[d09e5a1] | 686 | |
---|
| 687 | /* AIM stuff */ |
---|
| 688 | |
---|
[6a415e9] | 689 | int owl_global_is_aimloggedin(owl_global *g) |
---|
| 690 | { |
---|
[d09e5a1] | 691 | if (g->aim_loggedin) return(1); |
---|
| 692 | return(0); |
---|
| 693 | } |
---|
| 694 | |
---|
[6a415e9] | 695 | char *owl_global_get_aim_screenname(owl_global *g) |
---|
| 696 | { |
---|
[a352335c] | 697 | if (owl_global_is_aimloggedin(g)) { |
---|
| 698 | return (g->aim_screenname); |
---|
| 699 | } |
---|
| 700 | return(""); |
---|
[d09e5a1] | 701 | } |
---|
| 702 | |
---|
[6a415e9] | 703 | void owl_global_set_aimloggedin(owl_global *g, char *screenname) |
---|
| 704 | { |
---|
[d09e5a1] | 705 | g->aim_loggedin=1; |
---|
| 706 | if (g->aim_screenname) owl_free(g->aim_screenname); |
---|
| 707 | g->aim_screenname=owl_strdup(screenname); |
---|
| 708 | } |
---|
| 709 | |
---|
[6a415e9] | 710 | void owl_global_set_aimnologgedin(owl_global *g) |
---|
| 711 | { |
---|
[d09e5a1] | 712 | g->aim_loggedin=0; |
---|
| 713 | } |
---|
| 714 | |
---|
[a352335c] | 715 | int owl_global_is_doaimevents(owl_global *g) |
---|
| 716 | { |
---|
| 717 | if (g->aim_doprocessing) return(1); |
---|
| 718 | return(0); |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | void owl_global_set_doaimevents(owl_global *g) |
---|
| 722 | { |
---|
| 723 | g->aim_doprocessing=1; |
---|
| 724 | } |
---|
| 725 | |
---|
| 726 | void owl_global_set_no_doaimevents(owl_global *g) |
---|
| 727 | { |
---|
| 728 | g->aim_doprocessing=0; |
---|
| 729 | } |
---|
| 730 | |
---|
[6a415e9] | 731 | aim_session_t *owl_global_get_aimsess(owl_global *g) |
---|
| 732 | { |
---|
[d09e5a1] | 733 | return(&(g->aimsess)); |
---|
| 734 | } |
---|
| 735 | |
---|
[c15bbfb] | 736 | aim_conn_t *owl_global_get_bosconn(owl_global *g) |
---|
| 737 | { |
---|
| 738 | return(&(g->bosconn)); |
---|
| 739 | } |
---|
| 740 | |
---|
| 741 | void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn) |
---|
[6a415e9] | 742 | { |
---|
[c15bbfb] | 743 | g->bosconn=*conn; |
---|
[d09e5a1] | 744 | } |
---|
| 745 | |
---|
[6a415e9] | 746 | int owl_global_is_aimnop_time(owl_global *g) |
---|
| 747 | { |
---|
| 748 | if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1); |
---|
[d09e5a1] | 749 | return(0); |
---|
| 750 | } |
---|
| 751 | |
---|
[6a415e9] | 752 | void owl_global_aimnop_sent(owl_global *g) |
---|
| 753 | { |
---|
| 754 | owl_timer_reset(&(g->aim_noop_timer)); |
---|
| 755 | } |
---|
[d09e5a1] | 756 | |
---|
[6a415e9] | 757 | owl_timer *owl_global_get_aim_login_timer(owl_global *g) |
---|
| 758 | { |
---|
| 759 | return(&(g->aim_ignorelogin_timer)); |
---|
[d09e5a1] | 760 | } |
---|
| 761 | |
---|
| 762 | /* message queue */ |
---|
| 763 | |
---|
[6a415e9] | 764 | void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m) |
---|
| 765 | { |
---|
[d09e5a1] | 766 | owl_list_append_element(&(g->messagequeue), m); |
---|
| 767 | } |
---|
| 768 | |
---|
| 769 | /* pop off the first message and return it. Return NULL if the queue |
---|
| 770 | * is empty. The caller should free the message after using it, if |
---|
| 771 | * necessary. |
---|
| 772 | */ |
---|
[6a415e9] | 773 | owl_message *owl_global_messageuque_popmsg(owl_global *g) |
---|
| 774 | { |
---|
[d09e5a1] | 775 | owl_message *out; |
---|
| 776 | |
---|
| 777 | if (owl_list_get_size(&(g->messagequeue))==0) return(NULL); |
---|
| 778 | out=owl_list_get_element(&(g->messagequeue), 0); |
---|
| 779 | owl_list_remove_element(&(g->messagequeue), 0); |
---|
| 780 | return(out); |
---|
| 781 | } |
---|
| 782 | |
---|
[6a415e9] | 783 | int owl_global_messagequeue_pending(owl_global *g) |
---|
| 784 | { |
---|
[d09e5a1] | 785 | if (owl_list_get_size(&(g->messagequeue))==0) return(0); |
---|
| 786 | return(1); |
---|
| 787 | } |
---|
[aa5f725] | 788 | |
---|
[6a415e9] | 789 | owl_buddylist *owl_global_get_buddylist(owl_global *g) |
---|
| 790 | { |
---|
[aa5f725] | 791 | return(&(g->buddylist)); |
---|
| 792 | } |
---|
| 793 | |
---|
[bd3f232] | 794 | /* style */ |
---|
| 795 | |
---|
| 796 | /* Return the style with name 'name'. If it does not exist return |
---|
| 797 | * NULL */ |
---|
| 798 | owl_style *owl_global_get_style_by_name(owl_global *g, char *name) |
---|
| 799 | { |
---|
[f1e629d] | 800 | return owl_dict_find_element(&(g->styledict), name); |
---|
| 801 | } |
---|
| 802 | |
---|
| 803 | /* creates a list and fills it in with keys. duplicates the keys, |
---|
| 804 | * so they will need to be freed by the caller. */ |
---|
| 805 | int owl_global_get_style_names(owl_global *g, owl_list *l) { |
---|
| 806 | return owl_dict_get_keys(&(g->styledict), l); |
---|
[bd3f232] | 807 | } |
---|
| 808 | |
---|
[cf83b7a] | 809 | void owl_global_add_style(owl_global *g, owl_style *s) |
---|
| 810 | { |
---|
[f1e629d] | 811 | owl_dict_insert_element(&(g->styledict), owl_style_get_name(s), |
---|
| 812 | s, (void(*)(void*))owl_style_free); |
---|
[bd3f232] | 813 | } |
---|
[cf83b7a] | 814 | |
---|
[09489b89] | 815 | void owl_global_set_haveaim(owl_global *g) |
---|
| 816 | { |
---|
| 817 | g->haveaim=1; |
---|
| 818 | } |
---|
| 819 | |
---|
| 820 | int owl_global_is_haveaim(owl_global *g) |
---|
| 821 | { |
---|
| 822 | if (g->haveaim) return(1); |
---|
| 823 | return(0); |
---|
| 824 | } |
---|
| 825 | |
---|
| 826 | void owl_global_set_havezephyr(owl_global *g) |
---|
| 827 | { |
---|
| 828 | g->havezephyr=1; |
---|
| 829 | } |
---|
| 830 | |
---|
| 831 | int owl_global_is_havezephyr(owl_global *g) |
---|
| 832 | { |
---|
| 833 | if (g->havezephyr) return(1); |
---|
| 834 | return(0); |
---|
| 835 | } |
---|
[de03334] | 836 | |
---|
| 837 | owl_timer *owl_global_get_aim_buddyinfo_timer(owl_global *g) |
---|
| 838 | { |
---|
| 839 | return(&(g->aim_buddyinfo_timer)); |
---|
| 840 | } |
---|
[ec6ff52] | 841 | |
---|
| 842 | owl_errqueue *owl_global_get_errqueue(owl_global *g) |
---|
| 843 | { |
---|
| 844 | return(&(g->errqueue)); |
---|
| 845 | } |
---|
[c9e72d1] | 846 | |
---|
| 847 | void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo) |
---|
| 848 | { |
---|
| 849 | g->got_err_signal = signum; |
---|
| 850 | if (siginfo) { |
---|
| 851 | g->err_signal_info = *siginfo; |
---|
| 852 | } else { |
---|
| 853 | memset(&(g->err_signal_info), 0, sizeof(siginfo_t)); |
---|
| 854 | } |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo) |
---|
| 858 | { |
---|
| 859 | int signum; |
---|
| 860 | if (siginfo && g->got_err_signal) { |
---|
| 861 | *siginfo = g->err_signal_info; |
---|
| 862 | } |
---|
| 863 | signum = g->got_err_signal; |
---|
| 864 | g->got_err_signal = 0; |
---|
| 865 | return signum; |
---|
| 866 | } |
---|
| 867 | |
---|
[5a95b69] | 868 | owl_timer *owl_global_get_zephyr_buddycheck_timer(owl_global *g) |
---|
| 869 | { |
---|
| 870 | return(&(g->zephyr_buddycheck_timer)); |
---|
| 871 | } |
---|
| 872 | |
---|
| 873 | owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g) |
---|
| 874 | { |
---|
| 875 | return(&(g->zbuddies)); |
---|
| 876 | } |
---|
[8232149] | 877 | |
---|
| 878 | struct termios *owl_global_get_startup_tio(owl_global *g) |
---|
| 879 | { |
---|
| 880 | return(&(g->startup_tio)); |
---|
| 881 | } |
---|