[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 | |
---|
| 11 | #ifndef MAXHOSTNAMELEN |
---|
| 12 | #define MAXHOSTNAMELEN 256 |
---|
| 13 | #endif |
---|
| 14 | |
---|
[571fab7] | 15 | static void _owl_global_init_windows(owl_global *g); |
---|
| 16 | |
---|
[7d4fbcd] | 17 | void owl_global_init(owl_global *g) { |
---|
| 18 | struct hostent *hent; |
---|
| 19 | char hostname[MAXHOSTNAMELEN]; |
---|
[ad15610] | 20 | char *cd; |
---|
[7d4fbcd] | 21 | |
---|
[0be3efd] | 22 | g_type_init(); |
---|
| 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 | |
---|
[5cc7e5e] | 32 | g->lines=LINES; |
---|
| 33 | g->cols=COLS; |
---|
| 34 | /* We shouldn't need this if we initialize lines and cols before the first |
---|
| 35 | * owl_window_get_screen, but to be safe, we synchronize. */ |
---|
| 36 | owl_window_resize(owl_window_get_screen(), g->lines, g->cols); |
---|
| 37 | |
---|
[a999d9e] | 38 | g->context_stack = NULL; |
---|
[07b59ea] | 39 | owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL); |
---|
[a999d9e] | 40 | |
---|
[7d4fbcd] | 41 | g->curmsg=0; |
---|
| 42 | g->topmsg=0; |
---|
[bd783db] | 43 | g->markedmsgid=-1; |
---|
[a8938c7] | 44 | g->startupargs=NULL; |
---|
[7d4fbcd] | 45 | |
---|
| 46 | owl_variable_dict_setup(&(g->vars)); |
---|
| 47 | |
---|
| 48 | g->rightshift=0; |
---|
| 49 | |
---|
[03ca005] | 50 | g->pw = NULL; |
---|
[9eb38bb] | 51 | g->vw = NULL; |
---|
[38cc669] | 52 | g->tw = NULL; |
---|
[7d4fbcd] | 53 | |
---|
| 54 | owl_keyhandler_init(&g->kh); |
---|
| 55 | owl_keys_setup_keymaps(&g->kh); |
---|
| 56 | |
---|
[129e609] | 57 | owl_dict_create(&(g->filters)); |
---|
| 58 | g->filterlist = NULL; |
---|
[7d4fbcd] | 59 | owl_list_create(&(g->puntlist)); |
---|
[20aced3] | 60 | g->messagequeue = g_queue_new(); |
---|
[f1e629d] | 61 | owl_dict_create(&(g->styledict)); |
---|
[7d4fbcd] | 62 | g->curmsg_vert_offset=0; |
---|
| 63 | g->resizepending=0; |
---|
| 64 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
| 65 | g->zaway=0; |
---|
| 66 | if (has_colors()) { |
---|
| 67 | g->hascolors=1; |
---|
| 68 | } |
---|
| 69 | g->colorpairs=COLOR_PAIRS; |
---|
[8fa9562] | 70 | owl_fmtext_init_colorpair_mgr(&(g->cpmgr)); |
---|
[7d4fbcd] | 71 | g->debug=OWL_DEBUG; |
---|
[41c9a96] | 72 | owl_regex_init(&g->search_re); |
---|
[7d4fbcd] | 73 | g->starttime=time(NULL); /* assumes we call init only a start time */ |
---|
[7f792c1] | 74 | g->lastinputtime=g->starttime; |
---|
[700c712] | 75 | g->newmsgproc_pid=0; |
---|
[61e79a9] | 76 | |
---|
[7d4fbcd] | 77 | owl_global_set_config_format(g, 0); |
---|
| 78 | owl_global_set_no_have_config(g); |
---|
[10b866d] | 79 | owl_history_init(&(g->msghist)); |
---|
| 80 | owl_history_init(&(g->cmdhist)); |
---|
[5a9f6fe] | 81 | owl_history_set_norepeats(&(g->cmdhist)); |
---|
[7d4fbcd] | 82 | g->nextmsgid=0; |
---|
| 83 | |
---|
| 84 | /* Fill in some variables which don't have constant defaults */ |
---|
| 85 | /* TODO: come back later and check passwd file first */ |
---|
[a8938c7] | 86 | g->homedir=owl_strdup(getenv("HOME")); |
---|
[7d4fbcd] | 87 | |
---|
[b363d83] | 88 | g->confdir = NULL; |
---|
| 89 | g->startupfile = NULL; |
---|
[ad15610] | 90 | cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR); |
---|
[b363d83] | 91 | owl_global_set_confdir(g, cd); |
---|
| 92 | owl_free(cd); |
---|
| 93 | |
---|
[7d4fbcd] | 94 | owl_messagelist_create(&(g->msglist)); |
---|
[571fab7] | 95 | |
---|
| 96 | _owl_global_init_windows(g); |
---|
[d09e5a1] | 97 | |
---|
| 98 | g->aim_screenname=NULL; |
---|
[81655f8] | 99 | g->aim_screenname_for_filters=NULL; |
---|
[d09e5a1] | 100 | g->aim_loggedin=0; |
---|
[aa5f725] | 101 | owl_buddylist_init(&(g->buddylist)); |
---|
[b7bb454] | 102 | |
---|
[09489b89] | 103 | g->havezephyr=0; |
---|
| 104 | g->haveaim=0; |
---|
[b7bb454] | 105 | g->ignoreaimlogin=0; |
---|
[a352335c] | 106 | owl_global_set_no_doaimevents(g); |
---|
[ec6ff52] | 107 | |
---|
| 108 | owl_errqueue_init(&(g->errqueue)); |
---|
[c9e72d1] | 109 | g->got_err_signal=0; |
---|
[5a95b69] | 110 | |
---|
| 111 | owl_zbuddylist_create(&(g->zbuddies)); |
---|
[8e401cae] | 112 | |
---|
[f25812b] | 113 | g->zaldlist = NULL; |
---|
| 114 | g->pseudologin_notify = 0; |
---|
| 115 | |
---|
[a387d12e] | 116 | owl_message_init_fmtext_cache(); |
---|
[df0138f] | 117 | owl_list_create(&(g->io_dispatch_list)); |
---|
[4f2166b] | 118 | owl_list_create(&(g->psa_list)); |
---|
[58d1f8a] | 119 | g->timerlist = NULL; |
---|
[adee9cc] | 120 | g->interrupted = FALSE; |
---|
[571fab7] | 121 | } |
---|
| 122 | |
---|
| 123 | static void _owl_global_init_windows(owl_global *g) |
---|
| 124 | { |
---|
| 125 | /* Create the main window */ |
---|
| 126 | owl_mainpanel_init(&(g->mainpanel)); |
---|
| 127 | |
---|
| 128 | /* Create the widgets */ |
---|
| 129 | owl_mainwin_init(&(g->mw), g->mainpanel.recwin); |
---|
| 130 | owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin); |
---|
| 131 | owl_sepbar_init(g->mainpanel.sepwin); |
---|
[0881cdd] | 132 | |
---|
[4dd115f] | 133 | owl_window_set_default_cursor(g->mainpanel.sepwin); |
---|
[0881cdd] | 134 | |
---|
| 135 | /* set up a pad for input */ |
---|
| 136 | g->input_pad = newpad(1, 1); |
---|
| 137 | nodelay(g->input_pad, 1); |
---|
| 138 | keypad(g->input_pad, 1); |
---|
| 139 | meta(g->input_pad, 1); |
---|
[7d4fbcd] | 140 | } |
---|
| 141 | |
---|
[044f19f] | 142 | void owl_global_sepbar_dirty(owl_global *g) |
---|
| 143 | { |
---|
| 144 | owl_window_dirty(g->mainpanel.sepwin); |
---|
| 145 | } |
---|
| 146 | |
---|
[eb6cedc] | 147 | /* Called once perl has been initialized */ |
---|
| 148 | void owl_global_complete_setup(owl_global *g) |
---|
| 149 | { |
---|
| 150 | owl_cmddict_setup(&(g->cmds)); |
---|
| 151 | } |
---|
| 152 | |
---|
[005eae5] | 153 | owl_context *owl_global_get_context(const owl_global *g) { |
---|
[a999d9e] | 154 | if (!g->context_stack) |
---|
| 155 | return NULL; |
---|
| 156 | return g->context_stack->data; |
---|
| 157 | } |
---|
| 158 | |
---|
[07b59ea] | 159 | static void owl_global_activate_context(owl_global *g, owl_context *c) { |
---|
| 160 | if (!c) |
---|
[a999d9e] | 161 | return; |
---|
| 162 | |
---|
[07b59ea] | 163 | if (c->keymap) { |
---|
| 164 | if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) { |
---|
| 165 | owl_function_error("Unable to activate keymap '%s'", c->keymap); |
---|
| 166 | } |
---|
[a999d9e] | 167 | } |
---|
[07b59ea] | 168 | owl_window_set_cursor(c->cursor); |
---|
[7d4fbcd] | 169 | } |
---|
[a999d9e] | 170 | |
---|
[07b59ea] | 171 | void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) { |
---|
[a999d9e] | 172 | owl_context *c; |
---|
[cb81570] | 173 | c = owl_context_new(mode, data, keymap, cursor); |
---|
[1d74663] | 174 | owl_global_push_context_obj(g, c); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | void owl_global_push_context_obj(owl_global *g, owl_context *c) |
---|
| 178 | { |
---|
[a999d9e] | 179 | g->context_stack = g_list_prepend(g->context_stack, c); |
---|
[07b59ea] | 180 | owl_global_activate_context(g, owl_global_get_context(g)); |
---|
[a999d9e] | 181 | } |
---|
| 182 | |
---|
[1d74663] | 183 | /* Pops the current context from the context stack and returns it. Caller is |
---|
| 184 | * responsible for freeing. */ |
---|
| 185 | owl_context *owl_global_pop_context_no_delete(owl_global *g) { |
---|
[a999d9e] | 186 | owl_context *c; |
---|
| 187 | if (!g->context_stack) |
---|
[1d74663] | 188 | return NULL; |
---|
[a999d9e] | 189 | c = owl_global_get_context(g); |
---|
[1d74663] | 190 | owl_context_deactivate(c); |
---|
[a999d9e] | 191 | g->context_stack = g_list_delete_link(g->context_stack, |
---|
| 192 | g->context_stack); |
---|
[07b59ea] | 193 | owl_global_activate_context(g, owl_global_get_context(g)); |
---|
[1d74663] | 194 | return c; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | /* Pops the current context from the context stack and deletes it. */ |
---|
| 198 | void owl_global_pop_context(owl_global *g) { |
---|
| 199 | owl_context *c; |
---|
| 200 | c = owl_global_pop_context_no_delete(g); |
---|
| 201 | if (c) |
---|
| 202 | owl_context_delete(c); |
---|
[a999d9e] | 203 | } |
---|
| 204 | |
---|
[8742840] | 205 | int owl_global_get_lines(const owl_global *g) { |
---|
[7d4fbcd] | 206 | return(g->lines); |
---|
| 207 | } |
---|
| 208 | |
---|
[8742840] | 209 | int owl_global_get_cols(const owl_global *g) { |
---|
[7d4fbcd] | 210 | return(g->cols); |
---|
| 211 | } |
---|
| 212 | |
---|
[8742840] | 213 | int owl_global_get_recwin_lines(const owl_global *g) { |
---|
[d2a4534] | 214 | return g->mainpanel.recwinlines; |
---|
[7d4fbcd] | 215 | } |
---|
| 216 | |
---|
| 217 | /* curmsg */ |
---|
| 218 | |
---|
[8742840] | 219 | int owl_global_get_curmsg(const owl_global *g) { |
---|
[7d4fbcd] | 220 | return(g->curmsg); |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | void owl_global_set_curmsg(owl_global *g, int i) { |
---|
| 224 | g->curmsg=i; |
---|
| 225 | /* we will reset the vertical offset from here */ |
---|
| 226 | /* we might want to move this out to the functions later */ |
---|
| 227 | owl_global_set_curmsg_vert_offset(g, 0); |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | /* topmsg */ |
---|
| 231 | |
---|
[8742840] | 232 | int owl_global_get_topmsg(const owl_global *g) { |
---|
[7d4fbcd] | 233 | return(g->topmsg); |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | void owl_global_set_topmsg(owl_global *g, int i) { |
---|
| 237 | g->topmsg=i; |
---|
| 238 | } |
---|
| 239 | |
---|
[70110286] | 240 | /* markedmsgid */ |
---|
| 241 | |
---|
[8742840] | 242 | int owl_global_get_markedmsgid(const owl_global *g) { |
---|
[70110286] | 243 | return(g->markedmsgid); |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | void owl_global_set_markedmsgid(owl_global *g, int i) { |
---|
| 247 | g->markedmsgid=i; |
---|
| 248 | /* i; index of message in the current view. |
---|
[c08c70a] | 249 | const owl_message *m; |
---|
[70110286] | 250 | owl_view *v; |
---|
| 251 | |
---|
| 252 | v = owl_global_get_current_view(&g); |
---|
| 253 | m = owl_view_get_element(v, i); |
---|
| 254 | g->markedmsgid = m ? owl_message_get_id(m) : 0; |
---|
| 255 | */ |
---|
| 256 | } |
---|
| 257 | |
---|
[7d4fbcd] | 258 | /* windows */ |
---|
| 259 | |
---|
| 260 | owl_mainwin *owl_global_get_mainwin(owl_global *g) { |
---|
| 261 | return(&(g->mw)); |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | owl_popwin *owl_global_get_popwin(owl_global *g) { |
---|
[03ca005] | 265 | return g->pw; |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | void owl_global_set_popwin(owl_global *g, owl_popwin *pw) { |
---|
| 269 | g->pw = pw; |
---|
[7d4fbcd] | 270 | } |
---|
| 271 | |
---|
| 272 | /* msglist */ |
---|
| 273 | |
---|
| 274 | owl_messagelist *owl_global_get_msglist(owl_global *g) { |
---|
| 275 | return(&(g->msglist)); |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | /* keyhandler */ |
---|
| 279 | |
---|
| 280 | owl_keyhandler *owl_global_get_keyhandler(owl_global *g) { |
---|
| 281 | return(&(g->kh)); |
---|
| 282 | } |
---|
| 283 | |
---|
[005eae5] | 284 | /* Gets the currently active typwin out of the current context. */ |
---|
[818f19c] | 285 | owl_editwin *owl_global_current_typwin(const owl_global *g) { |
---|
[005eae5] | 286 | owl_context *ctx = owl_global_get_context(g); |
---|
[c394de8] | 287 | return owl_editcontext_get_editwin(ctx); |
---|
[7d4fbcd] | 288 | } |
---|
| 289 | |
---|
| 290 | /* variable dictionary */ |
---|
| 291 | |
---|
| 292 | owl_vardict *owl_global_get_vardict(owl_global *g) { |
---|
| 293 | return &(g->vars); |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | /* command dictionary */ |
---|
| 297 | |
---|
| 298 | owl_cmddict *owl_global_get_cmddict(owl_global *g) { |
---|
| 299 | return &(g->cmds); |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | /* rightshift */ |
---|
| 303 | |
---|
| 304 | void owl_global_set_rightshift(owl_global *g, int i) { |
---|
[5b80b87] | 305 | g->rightshift = i; |
---|
[e92e2a1] | 306 | owl_mainwin_redisplay(owl_global_get_mainwin(g)); |
---|
[7d4fbcd] | 307 | } |
---|
| 308 | |
---|
[8742840] | 309 | int owl_global_get_rightshift(const owl_global *g) { |
---|
[7d4fbcd] | 310 | return(g->rightshift); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | /* typwin */ |
---|
| 314 | |
---|
[58d47ca] | 315 | owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) { |
---|
[38cc669] | 316 | int d; |
---|
| 317 | d = owl_global_get_typewindelta(g); |
---|
[73eda8c] | 318 | if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE) |
---|
[da466e0] | 319 | owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d); |
---|
| 320 | |
---|
[f6fae8d] | 321 | if (g->typwin_erase_id) { |
---|
[08263a8] | 322 | g_signal_handler_disconnect(g->mainpanel.typwin, g->typwin_erase_id); |
---|
[f6fae8d] | 323 | g->typwin_erase_id = 0; |
---|
| 324 | } |
---|
| 325 | |
---|
[08263a8] | 326 | g->tw = owl_editwin_new(g->mainpanel.typwin, |
---|
[38cc669] | 327 | owl_global_get_typwin_lines(g), |
---|
| 328 | g->cols, |
---|
| 329 | style, |
---|
| 330 | hist); |
---|
[58d47ca] | 331 | return g->tw; |
---|
[7d4fbcd] | 332 | } |
---|
| 333 | |
---|
| 334 | void owl_global_set_typwin_inactive(owl_global *g) { |
---|
[da466e0] | 335 | int d = owl_global_get_typewindelta(g); |
---|
[73eda8c] | 336 | if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE) |
---|
[da466e0] | 337 | owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d); |
---|
| 338 | |
---|
[f6fae8d] | 339 | if (!g->typwin_erase_id) { |
---|
| 340 | g->typwin_erase_id = |
---|
[08263a8] | 341 | g_signal_connect(g->mainpanel.typwin, "redraw", G_CALLBACK(owl_window_erase_cb), NULL); |
---|
[f6fae8d] | 342 | } |
---|
[08263a8] | 343 | owl_window_dirty(g->mainpanel.typwin); |
---|
[f6fae8d] | 344 | |
---|
[c394de8] | 345 | owl_editwin_unref(g->tw); |
---|
[38cc669] | 346 | g->tw = NULL; |
---|
[7d4fbcd] | 347 | } |
---|
| 348 | |
---|
| 349 | /* resize */ |
---|
| 350 | |
---|
| 351 | void owl_global_set_resize_pending(owl_global *g) { |
---|
| 352 | g->resizepending=1; |
---|
| 353 | } |
---|
| 354 | |
---|
[8742840] | 355 | const char *owl_global_get_homedir(const owl_global *g) { |
---|
[a8938c7] | 356 | if (g->homedir) return(g->homedir); |
---|
| 357 | return("/"); |
---|
[7d4fbcd] | 358 | } |
---|
| 359 | |
---|
[8742840] | 360 | const char *owl_global_get_confdir(const owl_global *g) { |
---|
[b363d83] | 361 | if (g->confdir) return(g->confdir); |
---|
| 362 | return("/"); |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | /* |
---|
| 366 | * Setting this also sets startupfile to confdir/startup |
---|
| 367 | */ |
---|
[e19eb97] | 368 | void owl_global_set_confdir(owl_global *g, const char *cd) { |
---|
[27f6487] | 369 | owl_free(g->confdir); |
---|
[b363d83] | 370 | g->confdir = owl_strdup(cd); |
---|
[27f6487] | 371 | owl_free(g->startupfile); |
---|
[b363d83] | 372 | g->startupfile = owl_sprintf("%s/startup", cd); |
---|
| 373 | } |
---|
| 374 | |
---|
[8742840] | 375 | const char *owl_global_get_startupfile(const owl_global *g) { |
---|
[b363d83] | 376 | if(g->startupfile) return(g->startupfile); |
---|
| 377 | return("/"); |
---|
| 378 | } |
---|
| 379 | |
---|
[8742840] | 380 | int owl_global_get_direction(const owl_global *g) { |
---|
[7d4fbcd] | 381 | return(g->direction); |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | void owl_global_set_direction_downwards(owl_global *g) { |
---|
| 385 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | void owl_global_set_direction_upwards(owl_global *g) { |
---|
| 389 | g->direction=OWL_DIRECTION_UPWARDS; |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | /* perl stuff */ |
---|
| 393 | |
---|
| 394 | void owl_global_set_perlinterp(owl_global *g, void *p) { |
---|
| 395 | g->perl=p; |
---|
| 396 | } |
---|
| 397 | |
---|
[8742840] | 398 | void *owl_global_get_perlinterp(const owl_global *g) { |
---|
[7d4fbcd] | 399 | return(g->perl); |
---|
| 400 | } |
---|
| 401 | |
---|
[8742840] | 402 | int owl_global_is_config_format(const owl_global *g) { |
---|
[7d4fbcd] | 403 | if (g->config_format) return(1); |
---|
| 404 | return(0); |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | void owl_global_set_config_format(owl_global *g, int state) { |
---|
| 408 | if (state==1) { |
---|
| 409 | g->config_format=1; |
---|
| 410 | } else { |
---|
| 411 | g->config_format=0; |
---|
| 412 | } |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | void owl_global_set_have_config(owl_global *g) { |
---|
| 416 | g->haveconfig=1; |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | void owl_global_set_no_have_config(owl_global *g) { |
---|
| 420 | g->haveconfig=0; |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | int owl_global_have_config(owl_global *g) { |
---|
| 424 | if (g->haveconfig) return(1); |
---|
| 425 | return(0); |
---|
| 426 | } |
---|
| 427 | |
---|
[285bc9a] | 428 | /* |
---|
| 429 | * Compute the size of the terminal. Try a ioctl, fallback to other stuff on |
---|
| 430 | * fail. |
---|
| 431 | */ |
---|
[d39f68c] | 432 | void owl_global_get_terminal_size(int *lines, int *cols) { |
---|
[285bc9a] | 433 | struct winsize size; |
---|
| 434 | /* get the new size */ |
---|
| 435 | ioctl(STDIN_FILENO, TIOCGWINSZ, &size); |
---|
| 436 | if (size.ws_row) { |
---|
| 437 | *lines = size.ws_row; |
---|
| 438 | } else { |
---|
| 439 | *lines = LINES; |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | if (size.ws_col) { |
---|
| 443 | *cols = size.ws_col; |
---|
| 444 | } else { |
---|
| 445 | *cols = COLS; |
---|
| 446 | } |
---|
| 447 | } |
---|
| 448 | |
---|
[99ce51c] | 449 | void owl_global_check_resize(owl_global *g) { |
---|
[3e0147f] | 450 | /* resize the screen. If lines or cols is 0 use the terminal size */ |
---|
[7d4fbcd] | 451 | if (!g->resizepending) return; |
---|
[8479494] | 452 | g->resizepending = 0; |
---|
[7d4fbcd] | 453 | |
---|
[99ce51c] | 454 | owl_global_get_terminal_size(&g->lines, &g->cols); |
---|
[7a6e6c7] | 455 | owl_window_resize(owl_window_get_screen(), g->lines, g->cols); |
---|
[7d4fbcd] | 456 | |
---|
[f9f88f3] | 457 | owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols); |
---|
[7d4fbcd] | 458 | } |
---|
| 459 | |
---|
| 460 | /* debug */ |
---|
| 461 | |
---|
[8742840] | 462 | int owl_global_is_debug_fast(const owl_global *g) { |
---|
[7d4fbcd] | 463 | if (g->debug) return(1); |
---|
| 464 | return(0); |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | /* starttime */ |
---|
| 468 | |
---|
[8742840] | 469 | time_t owl_global_get_starttime(const owl_global *g) { |
---|
[7d4fbcd] | 470 | return(g->starttime); |
---|
| 471 | } |
---|
| 472 | |
---|
[8742840] | 473 | time_t owl_global_get_runtime(const owl_global *g) { |
---|
[7d4fbcd] | 474 | return(time(NULL)-g->starttime); |
---|
| 475 | } |
---|
| 476 | |
---|
[8742840] | 477 | time_t owl_global_get_lastinputtime(const owl_global *g) { |
---|
[7f792c1] | 478 | return(g->lastinputtime); |
---|
| 479 | } |
---|
| 480 | |
---|
[eebef19] | 481 | void owl_global_set_lastinputtime(owl_global *g, time_t time) { |
---|
| 482 | g->lastinputtime = time; |
---|
[7f792c1] | 483 | } |
---|
| 484 | |
---|
[8742840] | 485 | time_t owl_global_get_idletime(const owl_global *g) { |
---|
[7f792c1] | 486 | return(time(NULL)-g->lastinputtime); |
---|
| 487 | } |
---|
| 488 | |
---|
[8742840] | 489 | const char *owl_global_get_hostname(const owl_global *g) { |
---|
[a8938c7] | 490 | if (g->thishost) return(g->thishost); |
---|
| 491 | return(""); |
---|
[61e79a9] | 492 | } |
---|
| 493 | |
---|
[7d4fbcd] | 494 | /* viewwin */ |
---|
| 495 | |
---|
| 496 | owl_viewwin *owl_global_get_viewwin(owl_global *g) { |
---|
[9eb38bb] | 497 | return g->vw; |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | void owl_global_set_viewwin(owl_global *g, owl_viewwin *vw) { |
---|
| 501 | g->vw = vw; |
---|
[7d4fbcd] | 502 | } |
---|
| 503 | |
---|
| 504 | |
---|
| 505 | /* vert offset */ |
---|
| 506 | |
---|
[8742840] | 507 | int owl_global_get_curmsg_vert_offset(const owl_global *g) { |
---|
[7d4fbcd] | 508 | return(g->curmsg_vert_offset); |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | void owl_global_set_curmsg_vert_offset(owl_global *g, int i) { |
---|
[5b80b87] | 512 | g->curmsg_vert_offset = i; |
---|
[7d4fbcd] | 513 | } |
---|
| 514 | |
---|
| 515 | /* startup args */ |
---|
| 516 | |
---|
[e19eb97] | 517 | void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) { |
---|
[a8938c7] | 518 | int i, len; |
---|
| 519 | |
---|
| 520 | if (g->startupargs) owl_free(g->startupargs); |
---|
| 521 | |
---|
| 522 | len=0; |
---|
| 523 | for (i=0; i<argc; i++) { |
---|
[591e6aa7] | 524 | len+=strlen(argv[i])+5; |
---|
[a8938c7] | 525 | } |
---|
[34509d5] | 526 | g->startupargs=owl_malloc(len+5); |
---|
[7d4fbcd] | 527 | |
---|
| 528 | strcpy(g->startupargs, ""); |
---|
| 529 | for (i=0; i<argc; i++) { |
---|
[b9cb41b] | 530 | sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]); |
---|
[7d4fbcd] | 531 | } |
---|
| 532 | g->startupargs[strlen(g->startupargs)-1]='\0'; |
---|
| 533 | } |
---|
| 534 | |
---|
[8742840] | 535 | const char *owl_global_get_startupargs(const owl_global *g) { |
---|
[a8938c7] | 536 | if (g->startupargs) return(g->startupargs); |
---|
| 537 | return(""); |
---|
[7d4fbcd] | 538 | } |
---|
| 539 | |
---|
| 540 | /* history */ |
---|
| 541 | |
---|
[10b866d] | 542 | owl_history *owl_global_get_msg_history(owl_global *g) { |
---|
| 543 | return(&(g->msghist)); |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | owl_history *owl_global_get_cmd_history(owl_global *g) { |
---|
| 547 | return(&(g->cmdhist)); |
---|
[7d4fbcd] | 548 | } |
---|
| 549 | |
---|
| 550 | /* filterlist */ |
---|
[129e609] | 551 | typedef struct _owl_global_filter_ent { /* noproto */ |
---|
| 552 | owl_global *g; |
---|
| 553 | owl_filter *f; |
---|
| 554 | } owl_global_filter_ent; |
---|
[7d4fbcd] | 555 | |
---|
[8742840] | 556 | owl_filter *owl_global_get_filter(const owl_global *g, const char *name) { |
---|
[129e609] | 557 | owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name); |
---|
| 558 | if (e) return e->f; |
---|
| 559 | return NULL; |
---|
| 560 | } |
---|
[7d4fbcd] | 561 | |
---|
[5294cbf] | 562 | static void owl_global_delete_filter_ent(void *data) |
---|
| 563 | { |
---|
[129e609] | 564 | owl_global_filter_ent *e = data; |
---|
| 565 | e->g->filterlist = g_list_remove(e->g->filterlist, e->f); |
---|
| 566 | owl_filter_delete(e->f); |
---|
| 567 | owl_free(e); |
---|
[7d4fbcd] | 568 | } |
---|
| 569 | |
---|
| 570 | void owl_global_add_filter(owl_global *g, owl_filter *f) { |
---|
[129e609] | 571 | owl_global_filter_ent *e = owl_malloc(sizeof *e); |
---|
| 572 | e->g = g; |
---|
| 573 | e->f = f; |
---|
| 574 | |
---|
| 575 | owl_dict_insert_element(&(g->filters), owl_filter_get_name(f), |
---|
[5294cbf] | 576 | e, owl_global_delete_filter_ent); |
---|
[129e609] | 577 | g->filterlist = g_list_append(g->filterlist, f); |
---|
[7d4fbcd] | 578 | } |
---|
| 579 | |
---|
[e19eb97] | 580 | void owl_global_remove_filter(owl_global *g, const char *name) { |
---|
[129e609] | 581 | owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name); |
---|
| 582 | if (e) |
---|
[5294cbf] | 583 | owl_global_delete_filter_ent(e); |
---|
[7d4fbcd] | 584 | } |
---|
| 585 | |
---|
| 586 | /* nextmsgid */ |
---|
| 587 | |
---|
| 588 | int owl_global_get_nextmsgid(owl_global *g) { |
---|
| 589 | return(g->nextmsgid++); |
---|
| 590 | } |
---|
| 591 | |
---|
| 592 | /* current view */ |
---|
| 593 | |
---|
| 594 | owl_view *owl_global_get_current_view(owl_global *g) { |
---|
| 595 | return(&(g->current_view)); |
---|
| 596 | } |
---|
| 597 | |
---|
| 598 | /* has colors */ |
---|
| 599 | |
---|
[8742840] | 600 | int owl_global_get_hascolors(const owl_global *g) { |
---|
[7d4fbcd] | 601 | if (g->hascolors) return(1); |
---|
| 602 | return(0); |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | /* color pairs */ |
---|
| 606 | |
---|
[8742840] | 607 | int owl_global_get_colorpairs(const owl_global *g) { |
---|
[7d4fbcd] | 608 | return(g->colorpairs); |
---|
| 609 | } |
---|
| 610 | |
---|
[8fa9562] | 611 | owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) { |
---|
| 612 | return(&(g->cpmgr)); |
---|
| 613 | } |
---|
| 614 | |
---|
[7d4fbcd] | 615 | /* puntlist */ |
---|
| 616 | |
---|
| 617 | owl_list *owl_global_get_puntlist(owl_global *g) { |
---|
| 618 | return(&(g->puntlist)); |
---|
| 619 | } |
---|
| 620 | |
---|
[c08c70a] | 621 | int owl_global_message_is_puntable(owl_global *g, const owl_message *m) { |
---|
[77bced3] | 622 | const owl_list *pl; |
---|
[7d4fbcd] | 623 | int i, j; |
---|
| 624 | |
---|
| 625 | pl=owl_global_get_puntlist(g); |
---|
| 626 | j=owl_list_get_size(pl); |
---|
| 627 | for (i=0; i<j; i++) { |
---|
| 628 | if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1); |
---|
| 629 | } |
---|
| 630 | return(0); |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | int owl_global_should_followlast(owl_global *g) { |
---|
[9e5c9f3] | 634 | const owl_view *v; |
---|
[7d4fbcd] | 635 | |
---|
| 636 | if (!owl_global_is__followlast(g)) return(0); |
---|
| 637 | |
---|
| 638 | v=owl_global_get_current_view(g); |
---|
| 639 | |
---|
| 640 | if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1); |
---|
| 641 | return(0); |
---|
| 642 | } |
---|
[1fd0b25] | 643 | |
---|
[8742840] | 644 | int owl_global_is_search_active(const owl_global *g) { |
---|
[41c9a96] | 645 | if (owl_regex_is_set(&g->search_re)) return(1); |
---|
[1fd0b25] | 646 | return(0); |
---|
| 647 | } |
---|
| 648 | |
---|
[89b2daf] | 649 | void owl_global_set_search_re(owl_global *g, const owl_regex *re) { |
---|
[41c9a96] | 650 | if (owl_regex_is_set(&g->search_re)) { |
---|
[5cbc929] | 651 | owl_regex_cleanup(&g->search_re); |
---|
[41c9a96] | 652 | owl_regex_init(&g->search_re); |
---|
| 653 | } |
---|
| 654 | if (re != NULL) |
---|
| 655 | owl_regex_copy(re, &g->search_re); |
---|
[5b68c05] | 656 | /* TODO: Emit a signal so we don't depend on the viewwin here. */ |
---|
| 657 | if (owl_global_get_viewwin(g)) |
---|
| 658 | owl_viewwin_dirty(owl_global_get_viewwin(g)); |
---|
[1fd0b25] | 659 | } |
---|
| 660 | |
---|
[8742840] | 661 | const owl_regex *owl_global_get_search_re(const owl_global *g) { |
---|
[41c9a96] | 662 | return &g->search_re; |
---|
[1fd0b25] | 663 | } |
---|
[700c712] | 664 | |
---|
[0e5afa2] | 665 | void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) { |
---|
[700c712] | 666 | g->newmsgproc_pid=i; |
---|
| 667 | } |
---|
| 668 | |
---|
[0e5afa2] | 669 | pid_t owl_global_get_newmsgproc_pid(const owl_global *g) { |
---|
[700c712] | 670 | return(g->newmsgproc_pid); |
---|
| 671 | } |
---|
| 672 | |
---|
[d09e5a1] | 673 | /* AIM stuff */ |
---|
| 674 | |
---|
[8742840] | 675 | int owl_global_is_aimloggedin(const owl_global *g) |
---|
[6a415e9] | 676 | { |
---|
[d09e5a1] | 677 | if (g->aim_loggedin) return(1); |
---|
| 678 | return(0); |
---|
| 679 | } |
---|
| 680 | |
---|
[8742840] | 681 | const char *owl_global_get_aim_screenname(const owl_global *g) |
---|
[6a415e9] | 682 | { |
---|
[a352335c] | 683 | if (owl_global_is_aimloggedin(g)) { |
---|
| 684 | return (g->aim_screenname); |
---|
| 685 | } |
---|
| 686 | return(""); |
---|
[d09e5a1] | 687 | } |
---|
| 688 | |
---|
[8742840] | 689 | const char *owl_global_get_aim_screenname_for_filters(const owl_global *g) |
---|
[81655f8] | 690 | { |
---|
| 691 | if (owl_global_is_aimloggedin(g)) { |
---|
| 692 | return (g->aim_screenname_for_filters); |
---|
| 693 | } |
---|
| 694 | return(""); |
---|
| 695 | } |
---|
| 696 | |
---|
[e19eb97] | 697 | void owl_global_set_aimloggedin(owl_global *g, const char *screenname) |
---|
[6a415e9] | 698 | { |
---|
[65b2173] | 699 | char *sn_escaped; |
---|
[e19eb97] | 700 | const char *quote; |
---|
[d09e5a1] | 701 | g->aim_loggedin=1; |
---|
| 702 | if (g->aim_screenname) owl_free(g->aim_screenname); |
---|
[81655f8] | 703 | if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters); |
---|
[d09e5a1] | 704 | g->aim_screenname=owl_strdup(screenname); |
---|
[81655f8] | 705 | sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
| 706 | quote = owl_getquoting(sn_escaped); |
---|
[9f4e3f8] | 707 | g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote); |
---|
[81655f8] | 708 | owl_free(sn_escaped); |
---|
[d09e5a1] | 709 | } |
---|
| 710 | |
---|
[6a415e9] | 711 | void owl_global_set_aimnologgedin(owl_global *g) |
---|
| 712 | { |
---|
[d09e5a1] | 713 | g->aim_loggedin=0; |
---|
| 714 | } |
---|
| 715 | |
---|
[8742840] | 716 | int owl_global_is_doaimevents(const owl_global *g) |
---|
[a352335c] | 717 | { |
---|
| 718 | if (g->aim_doprocessing) return(1); |
---|
| 719 | return(0); |
---|
| 720 | } |
---|
| 721 | |
---|
| 722 | void owl_global_set_doaimevents(owl_global *g) |
---|
| 723 | { |
---|
| 724 | g->aim_doprocessing=1; |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | void owl_global_set_no_doaimevents(owl_global *g) |
---|
| 728 | { |
---|
| 729 | g->aim_doprocessing=0; |
---|
| 730 | } |
---|
| 731 | |
---|
[6a415e9] | 732 | aim_session_t *owl_global_get_aimsess(owl_global *g) |
---|
| 733 | { |
---|
[d09e5a1] | 734 | return(&(g->aimsess)); |
---|
| 735 | } |
---|
| 736 | |
---|
[c15bbfb] | 737 | aim_conn_t *owl_global_get_bosconn(owl_global *g) |
---|
| 738 | { |
---|
| 739 | return(&(g->bosconn)); |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn) |
---|
[6a415e9] | 743 | { |
---|
[c15bbfb] | 744 | g->bosconn=*conn; |
---|
[d09e5a1] | 745 | } |
---|
| 746 | |
---|
| 747 | /* message queue */ |
---|
| 748 | |
---|
[6a415e9] | 749 | void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m) |
---|
| 750 | { |
---|
[20aced3] | 751 | g_queue_push_tail(g->messagequeue, m); |
---|
[d09e5a1] | 752 | } |
---|
| 753 | |
---|
| 754 | /* pop off the first message and return it. Return NULL if the queue |
---|
| 755 | * is empty. The caller should free the message after using it, if |
---|
| 756 | * necessary. |
---|
| 757 | */ |
---|
[13a3c1db] | 758 | owl_message *owl_global_messagequeue_popmsg(owl_global *g) |
---|
[6a415e9] | 759 | { |
---|
[d09e5a1] | 760 | owl_message *out; |
---|
| 761 | |
---|
[20aced3] | 762 | if (g_queue_is_empty(g->messagequeue)) |
---|
| 763 | return NULL; |
---|
| 764 | out = g_queue_pop_head(g->messagequeue); |
---|
| 765 | return out; |
---|
[d09e5a1] | 766 | } |
---|
| 767 | |
---|
[6a415e9] | 768 | int owl_global_messagequeue_pending(owl_global *g) |
---|
| 769 | { |
---|
[20aced3] | 770 | return !g_queue_is_empty(g->messagequeue); |
---|
[d09e5a1] | 771 | } |
---|
[aa5f725] | 772 | |
---|
[6a415e9] | 773 | owl_buddylist *owl_global_get_buddylist(owl_global *g) |
---|
| 774 | { |
---|
[aa5f725] | 775 | return(&(g->buddylist)); |
---|
| 776 | } |
---|
| 777 | |
---|
[bd3f232] | 778 | /* style */ |
---|
| 779 | |
---|
| 780 | /* Return the style with name 'name'. If it does not exist return |
---|
| 781 | * NULL */ |
---|
[8742840] | 782 | const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name) |
---|
[bd3f232] | 783 | { |
---|
[f1e629d] | 784 | return owl_dict_find_element(&(g->styledict), name); |
---|
| 785 | } |
---|
| 786 | |
---|
| 787 | /* creates a list and fills it in with keys. duplicates the keys, |
---|
| 788 | * so they will need to be freed by the caller. */ |
---|
[8742840] | 789 | int owl_global_get_style_names(const owl_global *g, owl_list *l) { |
---|
[f1e629d] | 790 | return owl_dict_get_keys(&(g->styledict), l); |
---|
[bd3f232] | 791 | } |
---|
| 792 | |
---|
[cf83b7a] | 793 | void owl_global_add_style(owl_global *g, owl_style *s) |
---|
| 794 | { |
---|
[f1fc47f] | 795 | /* |
---|
| 796 | * If we're redefining the current style, make sure to update |
---|
| 797 | * pointers to it. |
---|
| 798 | */ |
---|
| 799 | if(g->current_view.style |
---|
| 800 | && !strcmp(owl_style_get_name(g->current_view.style), |
---|
| 801 | owl_style_get_name(s))) |
---|
| 802 | g->current_view.style = s; |
---|
| 803 | owl_dict_insert_element(&(g->styledict), owl_style_get_name(s), |
---|
[516c27e] | 804 | s, (void (*)(void *))owl_style_delete); |
---|
[bd3f232] | 805 | } |
---|
[cf83b7a] | 806 | |
---|
[09489b89] | 807 | void owl_global_set_haveaim(owl_global *g) |
---|
| 808 | { |
---|
| 809 | g->haveaim=1; |
---|
| 810 | } |
---|
| 811 | |
---|
[8742840] | 812 | int owl_global_is_haveaim(const owl_global *g) |
---|
[09489b89] | 813 | { |
---|
| 814 | if (g->haveaim) return(1); |
---|
| 815 | return(0); |
---|
| 816 | } |
---|
| 817 | |
---|
[b7bb454] | 818 | void owl_global_set_ignore_aimlogin(owl_global *g) |
---|
| 819 | { |
---|
| 820 | g->ignoreaimlogin = 1; |
---|
| 821 | } |
---|
| 822 | |
---|
| 823 | void owl_global_unset_ignore_aimlogin(owl_global *g) |
---|
| 824 | { |
---|
| 825 | g->ignoreaimlogin = 0; |
---|
| 826 | } |
---|
| 827 | |
---|
[8742840] | 828 | int owl_global_is_ignore_aimlogin(const owl_global *g) |
---|
[b7bb454] | 829 | { |
---|
| 830 | return g->ignoreaimlogin; |
---|
| 831 | } |
---|
| 832 | |
---|
[09489b89] | 833 | void owl_global_set_havezephyr(owl_global *g) |
---|
| 834 | { |
---|
| 835 | g->havezephyr=1; |
---|
| 836 | } |
---|
| 837 | |
---|
[8742840] | 838 | int owl_global_is_havezephyr(const owl_global *g) |
---|
[09489b89] | 839 | { |
---|
| 840 | if (g->havezephyr) return(1); |
---|
| 841 | return(0); |
---|
| 842 | } |
---|
[de03334] | 843 | |
---|
[ec6ff52] | 844 | owl_errqueue *owl_global_get_errqueue(owl_global *g) |
---|
| 845 | { |
---|
| 846 | return(&(g->errqueue)); |
---|
| 847 | } |
---|
[c9e72d1] | 848 | |
---|
| 849 | void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo) |
---|
| 850 | { |
---|
| 851 | g->got_err_signal = signum; |
---|
| 852 | if (siginfo) { |
---|
| 853 | g->err_signal_info = *siginfo; |
---|
| 854 | } else { |
---|
[7892963] | 855 | siginfo_t si; |
---|
| 856 | memset(&si, 0, sizeof(si)); |
---|
| 857 | g->err_signal_info = si; |
---|
[c9e72d1] | 858 | } |
---|
| 859 | } |
---|
| 860 | |
---|
| 861 | int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo) |
---|
| 862 | { |
---|
| 863 | int signum; |
---|
| 864 | if (siginfo && g->got_err_signal) { |
---|
| 865 | *siginfo = g->err_signal_info; |
---|
| 866 | } |
---|
| 867 | signum = g->got_err_signal; |
---|
| 868 | g->got_err_signal = 0; |
---|
| 869 | return signum; |
---|
| 870 | } |
---|
| 871 | |
---|
[5a95b69] | 872 | |
---|
| 873 | owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g) |
---|
| 874 | { |
---|
| 875 | return(&(g->zbuddies)); |
---|
| 876 | } |
---|
[8232149] | 877 | |
---|
[f25812b] | 878 | GList **owl_global_get_zaldlist(owl_global *g) |
---|
| 879 | { |
---|
| 880 | return &(g->zaldlist); |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | int owl_global_get_pseudologin_notify(owl_global *g) |
---|
| 884 | { |
---|
| 885 | return g->pseudologin_notify; |
---|
| 886 | } |
---|
| 887 | |
---|
| 888 | void owl_global_set_pseudologin_notify(owl_global *g, int notify) |
---|
| 889 | { |
---|
| 890 | g->pseudologin_notify = notify; |
---|
| 891 | } |
---|
| 892 | |
---|
[8232149] | 893 | struct termios *owl_global_get_startup_tio(owl_global *g) |
---|
| 894 | { |
---|
| 895 | return(&(g->startup_tio)); |
---|
| 896 | } |
---|
[8e401cae] | 897 | |
---|
[df0138f] | 898 | owl_list *owl_global_get_io_dispatch_list(owl_global *g) |
---|
| 899 | { |
---|
| 900 | return &(g->io_dispatch_list); |
---|
| 901 | } |
---|
| 902 | |
---|
[4f2166b] | 903 | owl_list *owl_global_get_psa_list(owl_global *g) |
---|
| 904 | { |
---|
| 905 | return &(g->psa_list); |
---|
| 906 | } |
---|
| 907 | |
---|
[58d1f8a] | 908 | GList **owl_global_get_timerlist(owl_global *g) |
---|
[b7bb454] | 909 | { |
---|
[58d1f8a] | 910 | return &(g->timerlist); |
---|
[b7bb454] | 911 | } |
---|
[adee9cc] | 912 | |
---|
[8742840] | 913 | int owl_global_is_interrupted(const owl_global *g) { |
---|
[0cb6c26] | 914 | return g->interrupted; |
---|
[adee9cc] | 915 | } |
---|
| 916 | |
---|
| 917 | void owl_global_set_interrupted(owl_global *g) { |
---|
| 918 | g->interrupted = 1; |
---|
| 919 | } |
---|
| 920 | |
---|
| 921 | void owl_global_unset_interrupted(owl_global *g) { |
---|
| 922 | g->interrupted = 0; |
---|
| 923 | } |
---|
[04b16f8] | 924 | |
---|
| 925 | void owl_global_setup_default_filters(owl_global *g) |
---|
| 926 | { |
---|
| 927 | int i; |
---|
| 928 | static const struct { |
---|
| 929 | const char *name; |
---|
| 930 | const char *desc; |
---|
| 931 | } filters[] = { |
---|
| 932 | { "personal", |
---|
[efc460e] | 933 | "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message ) )" }, |
---|
[04b16f8] | 934 | { "trash", |
---|
| 935 | "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" }, |
---|
| 936 | { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" }, |
---|
| 937 | { "ping", "opcode ^ping$" }, |
---|
| 938 | { "auto", "opcode ^auto$" }, |
---|
| 939 | { "login", "not login ^none$" }, |
---|
| 940 | { "reply-lockout", "class ^noc or class ^mail$" }, |
---|
| 941 | { "out", "direction ^out$" }, |
---|
| 942 | { "aim", "type ^aim$" }, |
---|
| 943 | { "zephyr", "type ^zephyr$" }, |
---|
| 944 | { "none", "false" }, |
---|
| 945 | { "all", "true" }, |
---|
| 946 | { NULL, NULL } |
---|
| 947 | }; |
---|
| 948 | |
---|
| 949 | owl_function_debugmsg("startup: creating default filters"); |
---|
| 950 | |
---|
| 951 | for (i = 0; filters[i].name != NULL; i++) |
---|
| 952 | owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name, |
---|
| 953 | filters[i].desc)); |
---|
| 954 | } |
---|
[d12a8c7] | 955 | |
---|
| 956 | FILE *owl_global_get_debug_file_handle(owl_global *g) { |
---|
| 957 | static char *open_file = NULL; |
---|
| 958 | const char *filename = owl_global_get_debug_file(g); |
---|
| 959 | if (g->debug_file == NULL || |
---|
| 960 | (open_file && strcmp(filename, open_file) != 0)) { |
---|
[26ad412] | 961 | char *path; |
---|
[50522b5] | 962 | int fd; |
---|
| 963 | |
---|
[d12a8c7] | 964 | if (g->debug_file) |
---|
| 965 | fclose(g->debug_file); |
---|
[50522b5] | 966 | |
---|
| 967 | g->debug_file = NULL; |
---|
| 968 | |
---|
[26ad412] | 969 | path = owl_sprintf("%s.%d", filename, getpid()); |
---|
| 970 | fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600); |
---|
| 971 | owl_free(path); |
---|
| 972 | |
---|
[50522b5] | 973 | if (fd >= 0) |
---|
| 974 | g->debug_file = fdopen(fd, "a"); |
---|
[d12a8c7] | 975 | |
---|
| 976 | owl_free(open_file); |
---|
| 977 | open_file = owl_strdup(filename); |
---|
| 978 | } |
---|
| 979 | return g->debug_file; |
---|
| 980 | } |
---|