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