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