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