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