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