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