[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 | |
---|
[571fab7] | 11 | static void _owl_global_init_windows(owl_global *g); |
---|
| 12 | |
---|
[7d4fbcd] | 13 | void owl_global_init(owl_global *g) { |
---|
[ad15610] | 14 | char *cd; |
---|
[8510d5b] | 15 | const char *homedir; |
---|
[7d4fbcd] | 16 | |
---|
[0be3efd] | 17 | g_type_init(); |
---|
[3535a6e] | 18 | g_thread_init(NULL); |
---|
[0be3efd] | 19 | |
---|
[2c79eae] | 20 | owl_select_init(); |
---|
[0be3efd] | 21 | |
---|
[5cc7e5e] | 22 | g->lines=LINES; |
---|
| 23 | g->cols=COLS; |
---|
| 24 | /* We shouldn't need this if we initialize lines and cols before the first |
---|
| 25 | * owl_window_get_screen, but to be safe, we synchronize. */ |
---|
| 26 | owl_window_resize(owl_window_get_screen(), g->lines, g->cols); |
---|
| 27 | |
---|
[a999d9e] | 28 | g->context_stack = NULL; |
---|
[07b59ea] | 29 | owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL); |
---|
[a999d9e] | 30 | |
---|
[7d4fbcd] | 31 | g->curmsg=0; |
---|
| 32 | g->topmsg=0; |
---|
[bd783db] | 33 | g->markedmsgid=-1; |
---|
[a8938c7] | 34 | g->startupargs=NULL; |
---|
[7d4fbcd] | 35 | |
---|
| 36 | owl_variable_dict_setup(&(g->vars)); |
---|
| 37 | |
---|
| 38 | g->rightshift=0; |
---|
| 39 | |
---|
[03ca005] | 40 | g->pw = NULL; |
---|
[9eb38bb] | 41 | g->vw = NULL; |
---|
[38cc669] | 42 | g->tw = NULL; |
---|
[7d4fbcd] | 43 | |
---|
| 44 | owl_keyhandler_init(&g->kh); |
---|
| 45 | owl_keys_setup_keymaps(&g->kh); |
---|
| 46 | |
---|
[129e609] | 47 | owl_dict_create(&(g->filters)); |
---|
| 48 | g->filterlist = NULL; |
---|
[7d4fbcd] | 49 | owl_list_create(&(g->puntlist)); |
---|
[20aced3] | 50 | g->messagequeue = g_queue_new(); |
---|
[f1e629d] | 51 | owl_dict_create(&(g->styledict)); |
---|
[7d4fbcd] | 52 | g->curmsg_vert_offset=0; |
---|
| 53 | g->resizepending=0; |
---|
| 54 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
| 55 | g->zaway=0; |
---|
[8fa9562] | 56 | owl_fmtext_init_colorpair_mgr(&(g->cpmgr)); |
---|
[7d4fbcd] | 57 | g->debug=OWL_DEBUG; |
---|
[41c9a96] | 58 | owl_regex_init(&g->search_re); |
---|
[7d4fbcd] | 59 | g->starttime=time(NULL); /* assumes we call init only a start time */ |
---|
[7f792c1] | 60 | g->lastinputtime=g->starttime; |
---|
[700c712] | 61 | g->newmsgproc_pid=0; |
---|
[61e79a9] | 62 | |
---|
[7d4fbcd] | 63 | owl_global_set_config_format(g, 0); |
---|
| 64 | owl_global_set_no_have_config(g); |
---|
[10b866d] | 65 | owl_history_init(&(g->msghist)); |
---|
| 66 | owl_history_init(&(g->cmdhist)); |
---|
[5a9f6fe] | 67 | owl_history_set_norepeats(&(g->cmdhist)); |
---|
[7d4fbcd] | 68 | g->nextmsgid=0; |
---|
| 69 | |
---|
| 70 | /* Fill in some variables which don't have constant defaults */ |
---|
[8510d5b] | 71 | |
---|
| 72 | /* glib's g_get_home_dir prefers passwd entries to $HOME, so we |
---|
| 73 | * explicitly check getenv first. */ |
---|
| 74 | homedir = getenv("HOME"); |
---|
| 75 | if (!homedir) |
---|
| 76 | homedir = g_get_home_dir(); |
---|
[d4927a7] | 77 | g->homedir = g_strdup(homedir); |
---|
[7d4fbcd] | 78 | |
---|
[b363d83] | 79 | g->confdir = NULL; |
---|
| 80 | g->startupfile = NULL; |
---|
[3472845] | 81 | cd = g_strdup_printf("%s/%s", g->homedir, OWL_CONFIG_DIR); |
---|
[b363d83] | 82 | owl_global_set_confdir(g, cd); |
---|
[ddbbcffa] | 83 | g_free(cd); |
---|
[b363d83] | 84 | |
---|
[7d4fbcd] | 85 | owl_messagelist_create(&(g->msglist)); |
---|
[571fab7] | 86 | |
---|
| 87 | _owl_global_init_windows(g); |
---|
[d09e5a1] | 88 | |
---|
| 89 | g->aim_screenname=NULL; |
---|
[81655f8] | 90 | g->aim_screenname_for_filters=NULL; |
---|
[d09e5a1] | 91 | g->aim_loggedin=0; |
---|
[aa5f725] | 92 | owl_buddylist_init(&(g->buddylist)); |
---|
[b7bb454] | 93 | |
---|
[09489b89] | 94 | g->havezephyr=0; |
---|
| 95 | g->haveaim=0; |
---|
[b7bb454] | 96 | g->ignoreaimlogin=0; |
---|
[a352335c] | 97 | owl_global_set_no_doaimevents(g); |
---|
[ec6ff52] | 98 | |
---|
| 99 | owl_errqueue_init(&(g->errqueue)); |
---|
[5a95b69] | 100 | |
---|
| 101 | owl_zbuddylist_create(&(g->zbuddies)); |
---|
[8e401cae] | 102 | |
---|
[f25812b] | 103 | g->zaldlist = NULL; |
---|
| 104 | g->pseudologin_notify = 0; |
---|
| 105 | |
---|
[a387d12e] | 106 | owl_message_init_fmtext_cache(); |
---|
[5f8ec6b] | 107 | g->kill_buffer = NULL; |
---|
[47128d9] | 108 | |
---|
| 109 | g->interrupt_count = 0; |
---|
| 110 | g->interrupt_lock = g_mutex_new(); |
---|
[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 */ |
---|
| 119 | owl_mainwin_init(&(g->mw), g->mainpanel.recwin); |
---|
| 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. */ |
---|
[d427f08] | 175 | G_GNUC_WARN_UNUSED_RESULT owl_context *owl_global_pop_context_no_delete(owl_global *g) |
---|
| 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 | |
---|
| 251 | owl_mainwin *owl_global_get_mainwin(owl_global *g) { |
---|
| 252 | return(&(g->mw)); |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | owl_popwin *owl_global_get_popwin(owl_global *g) { |
---|
[03ca005] | 256 | return g->pw; |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | void owl_global_set_popwin(owl_global *g, owl_popwin *pw) { |
---|
| 260 | g->pw = pw; |
---|
[7d4fbcd] | 261 | } |
---|
| 262 | |
---|
| 263 | /* msglist */ |
---|
| 264 | |
---|
| 265 | owl_messagelist *owl_global_get_msglist(owl_global *g) { |
---|
| 266 | return(&(g->msglist)); |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | /* keyhandler */ |
---|
| 270 | |
---|
| 271 | owl_keyhandler *owl_global_get_keyhandler(owl_global *g) { |
---|
| 272 | return(&(g->kh)); |
---|
| 273 | } |
---|
| 274 | |
---|
[005eae5] | 275 | /* Gets the currently active typwin out of the current context. */ |
---|
[818f19c] | 276 | owl_editwin *owl_global_current_typwin(const owl_global *g) { |
---|
[005eae5] | 277 | owl_context *ctx = owl_global_get_context(g); |
---|
[c394de8] | 278 | return owl_editcontext_get_editwin(ctx); |
---|
[7d4fbcd] | 279 | } |
---|
| 280 | |
---|
| 281 | /* variable dictionary */ |
---|
| 282 | |
---|
| 283 | owl_vardict *owl_global_get_vardict(owl_global *g) { |
---|
| 284 | return &(g->vars); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | /* command dictionary */ |
---|
| 288 | |
---|
| 289 | owl_cmddict *owl_global_get_cmddict(owl_global *g) { |
---|
| 290 | return &(g->cmds); |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | /* rightshift */ |
---|
| 294 | |
---|
| 295 | void owl_global_set_rightshift(owl_global *g, int i) { |
---|
[5b80b87] | 296 | g->rightshift = i; |
---|
[e92e2a1] | 297 | owl_mainwin_redisplay(owl_global_get_mainwin(g)); |
---|
[7d4fbcd] | 298 | } |
---|
| 299 | |
---|
[8742840] | 300 | int owl_global_get_rightshift(const owl_global *g) { |
---|
[7d4fbcd] | 301 | return(g->rightshift); |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | /* typwin */ |
---|
| 305 | |
---|
[58d47ca] | 306 | owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) { |
---|
[38cc669] | 307 | int d; |
---|
| 308 | d = owl_global_get_typewindelta(g); |
---|
[73eda8c] | 309 | if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE) |
---|
[da466e0] | 310 | owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d); |
---|
| 311 | |
---|
[f6fae8d] | 312 | if (g->typwin_erase_id) { |
---|
[08263a8] | 313 | g_signal_handler_disconnect(g->mainpanel.typwin, g->typwin_erase_id); |
---|
[f6fae8d] | 314 | g->typwin_erase_id = 0; |
---|
| 315 | } |
---|
| 316 | |
---|
[08263a8] | 317 | g->tw = owl_editwin_new(g->mainpanel.typwin, |
---|
[38cc669] | 318 | owl_global_get_typwin_lines(g), |
---|
| 319 | g->cols, |
---|
| 320 | style, |
---|
| 321 | hist); |
---|
[58d47ca] | 322 | return g->tw; |
---|
[7d4fbcd] | 323 | } |
---|
| 324 | |
---|
[fc5eef4] | 325 | void owl_global_deactivate_editcontext(owl_context *ctx) { |
---|
| 326 | owl_global *g = ctx->cbdata; |
---|
| 327 | owl_global_set_typwin_inactive(g); |
---|
| 328 | } |
---|
| 329 | |
---|
[7d4fbcd] | 330 | void owl_global_set_typwin_inactive(owl_global *g) { |
---|
[da466e0] | 331 | int d = owl_global_get_typewindelta(g); |
---|
[73eda8c] | 332 | if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE) |
---|
[da466e0] | 333 | owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d); |
---|
| 334 | |
---|
[f6fae8d] | 335 | if (!g->typwin_erase_id) { |
---|
| 336 | g->typwin_erase_id = |
---|
[08263a8] | 337 | g_signal_connect(g->mainpanel.typwin, "redraw", G_CALLBACK(owl_window_erase_cb), NULL); |
---|
[f6fae8d] | 338 | } |
---|
[08263a8] | 339 | owl_window_dirty(g->mainpanel.typwin); |
---|
[f6fae8d] | 340 | |
---|
[c394de8] | 341 | owl_editwin_unref(g->tw); |
---|
[38cc669] | 342 | g->tw = NULL; |
---|
[7d4fbcd] | 343 | } |
---|
| 344 | |
---|
| 345 | /* resize */ |
---|
| 346 | |
---|
| 347 | void owl_global_set_resize_pending(owl_global *g) { |
---|
[3535a6e] | 348 | g->resizepending = true; |
---|
[7d4fbcd] | 349 | } |
---|
| 350 | |
---|
[8742840] | 351 | const char *owl_global_get_homedir(const owl_global *g) { |
---|
[a8938c7] | 352 | if (g->homedir) return(g->homedir); |
---|
| 353 | return("/"); |
---|
[7d4fbcd] | 354 | } |
---|
| 355 | |
---|
[8742840] | 356 | const char *owl_global_get_confdir(const owl_global *g) { |
---|
[b363d83] | 357 | if (g->confdir) return(g->confdir); |
---|
| 358 | return("/"); |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | /* |
---|
| 362 | * Setting this also sets startupfile to confdir/startup |
---|
| 363 | */ |
---|
[e19eb97] | 364 | void owl_global_set_confdir(owl_global *g, const char *cd) { |
---|
[ddbbcffa] | 365 | g_free(g->confdir); |
---|
[d4927a7] | 366 | g->confdir = g_strdup(cd); |
---|
[ddbbcffa] | 367 | g_free(g->startupfile); |
---|
[3472845] | 368 | g->startupfile = g_strdup_printf("%s/startup", cd); |
---|
[b363d83] | 369 | } |
---|
| 370 | |
---|
[8742840] | 371 | const char *owl_global_get_startupfile(const owl_global *g) { |
---|
[b363d83] | 372 | if(g->startupfile) return(g->startupfile); |
---|
| 373 | return("/"); |
---|
| 374 | } |
---|
| 375 | |
---|
[8742840] | 376 | int owl_global_get_direction(const owl_global *g) { |
---|
[7d4fbcd] | 377 | return(g->direction); |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | void owl_global_set_direction_downwards(owl_global *g) { |
---|
| 381 | g->direction=OWL_DIRECTION_DOWNWARDS; |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | void owl_global_set_direction_upwards(owl_global *g) { |
---|
| 385 | g->direction=OWL_DIRECTION_UPWARDS; |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | /* perl stuff */ |
---|
| 389 | |
---|
| 390 | void owl_global_set_perlinterp(owl_global *g, void *p) { |
---|
| 391 | g->perl=p; |
---|
| 392 | } |
---|
| 393 | |
---|
[8742840] | 394 | void *owl_global_get_perlinterp(const owl_global *g) { |
---|
[7d4fbcd] | 395 | return(g->perl); |
---|
| 396 | } |
---|
| 397 | |
---|
[8742840] | 398 | int owl_global_is_config_format(const owl_global *g) { |
---|
[7d4fbcd] | 399 | if (g->config_format) return(1); |
---|
| 400 | return(0); |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | void owl_global_set_config_format(owl_global *g, int state) { |
---|
| 404 | if (state==1) { |
---|
| 405 | g->config_format=1; |
---|
| 406 | } else { |
---|
| 407 | g->config_format=0; |
---|
| 408 | } |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | void owl_global_set_have_config(owl_global *g) { |
---|
| 412 | g->haveconfig=1; |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | void owl_global_set_no_have_config(owl_global *g) { |
---|
| 416 | g->haveconfig=0; |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | int owl_global_have_config(owl_global *g) { |
---|
| 420 | if (g->haveconfig) return(1); |
---|
| 421 | return(0); |
---|
| 422 | } |
---|
| 423 | |
---|
[285bc9a] | 424 | /* |
---|
| 425 | * Compute the size of the terminal. Try a ioctl, fallback to other stuff on |
---|
| 426 | * fail. |
---|
| 427 | */ |
---|
[d39f68c] | 428 | void owl_global_get_terminal_size(int *lines, int *cols) { |
---|
[285bc9a] | 429 | struct winsize size; |
---|
| 430 | /* get the new size */ |
---|
| 431 | ioctl(STDIN_FILENO, TIOCGWINSZ, &size); |
---|
| 432 | if (size.ws_row) { |
---|
| 433 | *lines = size.ws_row; |
---|
| 434 | } else { |
---|
| 435 | *lines = LINES; |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | if (size.ws_col) { |
---|
| 439 | *cols = size.ws_col; |
---|
| 440 | } else { |
---|
| 441 | *cols = COLS; |
---|
| 442 | } |
---|
| 443 | } |
---|
| 444 | |
---|
[99ce51c] | 445 | void owl_global_check_resize(owl_global *g) { |
---|
[3e0147f] | 446 | /* resize the screen. If lines or cols is 0 use the terminal size */ |
---|
[7d4fbcd] | 447 | if (!g->resizepending) return; |
---|
[3535a6e] | 448 | g->resizepending = false; |
---|
[7d4fbcd] | 449 | |
---|
[99ce51c] | 450 | owl_global_get_terminal_size(&g->lines, &g->cols); |
---|
[7a6e6c7] | 451 | owl_window_resize(owl_window_get_screen(), g->lines, g->cols); |
---|
[7d4fbcd] | 452 | |
---|
[f9f88f3] | 453 | owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols); |
---|
[7d4fbcd] | 454 | } |
---|
| 455 | |
---|
| 456 | /* debug */ |
---|
| 457 | |
---|
[8742840] | 458 | int owl_global_is_debug_fast(const owl_global *g) { |
---|
[7d4fbcd] | 459 | if (g->debug) return(1); |
---|
| 460 | return(0); |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | /* starttime */ |
---|
| 464 | |
---|
[8742840] | 465 | time_t owl_global_get_starttime(const owl_global *g) { |
---|
[7d4fbcd] | 466 | return(g->starttime); |
---|
| 467 | } |
---|
| 468 | |
---|
[8742840] | 469 | time_t owl_global_get_runtime(const owl_global *g) { |
---|
[7d4fbcd] | 470 | return(time(NULL)-g->starttime); |
---|
| 471 | } |
---|
| 472 | |
---|
[8742840] | 473 | time_t owl_global_get_lastinputtime(const owl_global *g) { |
---|
[7f792c1] | 474 | return(g->lastinputtime); |
---|
| 475 | } |
---|
| 476 | |
---|
[eebef19] | 477 | void owl_global_set_lastinputtime(owl_global *g, time_t time) { |
---|
| 478 | g->lastinputtime = time; |
---|
[7f792c1] | 479 | } |
---|
| 480 | |
---|
[8742840] | 481 | time_t owl_global_get_idletime(const owl_global *g) { |
---|
[7f792c1] | 482 | return(time(NULL)-g->lastinputtime); |
---|
| 483 | } |
---|
| 484 | |
---|
[7d4fbcd] | 485 | /* viewwin */ |
---|
| 486 | |
---|
| 487 | owl_viewwin *owl_global_get_viewwin(owl_global *g) { |
---|
[9eb38bb] | 488 | return g->vw; |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | void owl_global_set_viewwin(owl_global *g, owl_viewwin *vw) { |
---|
| 492 | g->vw = vw; |
---|
[7d4fbcd] | 493 | } |
---|
| 494 | |
---|
| 495 | |
---|
| 496 | /* vert offset */ |
---|
| 497 | |
---|
[8742840] | 498 | int owl_global_get_curmsg_vert_offset(const owl_global *g) { |
---|
[7d4fbcd] | 499 | return(g->curmsg_vert_offset); |
---|
| 500 | } |
---|
| 501 | |
---|
| 502 | void owl_global_set_curmsg_vert_offset(owl_global *g, int i) { |
---|
[5b80b87] | 503 | g->curmsg_vert_offset = i; |
---|
[7d4fbcd] | 504 | } |
---|
| 505 | |
---|
| 506 | /* startup args */ |
---|
| 507 | |
---|
[d3941a0] | 508 | void owl_global_set_startupargs(owl_global *g, int argc, char **argv) { |
---|
[3b8a563] | 509 | g_free(g->startupargs); |
---|
[d3941a0] | 510 | g->startupargs = g_strjoinv(" ", argv); |
---|
[7d4fbcd] | 511 | } |
---|
| 512 | |
---|
[8742840] | 513 | const char *owl_global_get_startupargs(const owl_global *g) { |
---|
[a8938c7] | 514 | if (g->startupargs) return(g->startupargs); |
---|
| 515 | return(""); |
---|
[7d4fbcd] | 516 | } |
---|
| 517 | |
---|
| 518 | /* history */ |
---|
| 519 | |
---|
[10b866d] | 520 | owl_history *owl_global_get_msg_history(owl_global *g) { |
---|
| 521 | return(&(g->msghist)); |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | owl_history *owl_global_get_cmd_history(owl_global *g) { |
---|
| 525 | return(&(g->cmdhist)); |
---|
[7d4fbcd] | 526 | } |
---|
| 527 | |
---|
| 528 | /* filterlist */ |
---|
[129e609] | 529 | typedef struct _owl_global_filter_ent { /* noproto */ |
---|
| 530 | owl_global *g; |
---|
| 531 | owl_filter *f; |
---|
| 532 | } owl_global_filter_ent; |
---|
[7d4fbcd] | 533 | |
---|
[8742840] | 534 | owl_filter *owl_global_get_filter(const owl_global *g, const char *name) { |
---|
[129e609] | 535 | owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name); |
---|
| 536 | if (e) return e->f; |
---|
| 537 | return NULL; |
---|
| 538 | } |
---|
[7d4fbcd] | 539 | |
---|
[5294cbf] | 540 | static void owl_global_delete_filter_ent(void *data) |
---|
| 541 | { |
---|
[129e609] | 542 | owl_global_filter_ent *e = data; |
---|
| 543 | e->g->filterlist = g_list_remove(e->g->filterlist, e->f); |
---|
| 544 | owl_filter_delete(e->f); |
---|
[ddbbcffa] | 545 | g_free(e); |
---|
[7d4fbcd] | 546 | } |
---|
| 547 | |
---|
| 548 | void owl_global_add_filter(owl_global *g, owl_filter *f) { |
---|
[96828e4] | 549 | owl_global_filter_ent *e = g_new(owl_global_filter_ent, 1); |
---|
[129e609] | 550 | e->g = g; |
---|
| 551 | e->f = f; |
---|
| 552 | |
---|
| 553 | owl_dict_insert_element(&(g->filters), owl_filter_get_name(f), |
---|
[5294cbf] | 554 | e, owl_global_delete_filter_ent); |
---|
[129e609] | 555 | g->filterlist = g_list_append(g->filterlist, f); |
---|
[7d4fbcd] | 556 | } |
---|
| 557 | |
---|
[e19eb97] | 558 | void owl_global_remove_filter(owl_global *g, const char *name) { |
---|
[129e609] | 559 | owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name); |
---|
| 560 | if (e) |
---|
[5294cbf] | 561 | owl_global_delete_filter_ent(e); |
---|
[7d4fbcd] | 562 | } |
---|
| 563 | |
---|
| 564 | /* nextmsgid */ |
---|
| 565 | |
---|
| 566 | int owl_global_get_nextmsgid(owl_global *g) { |
---|
| 567 | return(g->nextmsgid++); |
---|
| 568 | } |
---|
| 569 | |
---|
| 570 | /* current view */ |
---|
| 571 | |
---|
| 572 | owl_view *owl_global_get_current_view(owl_global *g) { |
---|
| 573 | return(&(g->current_view)); |
---|
| 574 | } |
---|
| 575 | |
---|
[8fa9562] | 576 | owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) { |
---|
| 577 | return(&(g->cpmgr)); |
---|
| 578 | } |
---|
| 579 | |
---|
[7d4fbcd] | 580 | /* puntlist */ |
---|
| 581 | |
---|
| 582 | owl_list *owl_global_get_puntlist(owl_global *g) { |
---|
| 583 | return(&(g->puntlist)); |
---|
| 584 | } |
---|
| 585 | |
---|
[c08c70a] | 586 | int owl_global_message_is_puntable(owl_global *g, const owl_message *m) { |
---|
[77bced3] | 587 | const owl_list *pl; |
---|
[7d4fbcd] | 588 | int i, j; |
---|
| 589 | |
---|
| 590 | pl=owl_global_get_puntlist(g); |
---|
| 591 | j=owl_list_get_size(pl); |
---|
| 592 | for (i=0; i<j; i++) { |
---|
| 593 | if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1); |
---|
| 594 | } |
---|
| 595 | return(0); |
---|
| 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 | */ |
---|
[d427f08] | 728 | owl_message G_GNUC_WARN_UNUSED_RESULT *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 | |
---|
[351c535] | 757 | void owl_global_get_style_names(const owl_global *g, owl_list *l) { |
---|
| 758 | owl_dict_get_keys(&(g->styledict), l); |
---|
[bd3f232] | 759 | } |
---|
| 760 | |
---|
[cf83b7a] | 761 | void owl_global_add_style(owl_global *g, owl_style *s) |
---|
| 762 | { |
---|
[f1fc47f] | 763 | /* |
---|
| 764 | * If we're redefining the current style, make sure to update |
---|
| 765 | * pointers to it. |
---|
| 766 | */ |
---|
| 767 | if(g->current_view.style |
---|
| 768 | && !strcmp(owl_style_get_name(g->current_view.style), |
---|
| 769 | owl_style_get_name(s))) |
---|
| 770 | g->current_view.style = s; |
---|
| 771 | owl_dict_insert_element(&(g->styledict), owl_style_get_name(s), |
---|
[516c27e] | 772 | s, (void (*)(void *))owl_style_delete); |
---|
[bd3f232] | 773 | } |
---|
[cf83b7a] | 774 | |
---|
[09489b89] | 775 | void owl_global_set_haveaim(owl_global *g) |
---|
| 776 | { |
---|
| 777 | g->haveaim=1; |
---|
| 778 | } |
---|
| 779 | |
---|
[8742840] | 780 | int owl_global_is_haveaim(const owl_global *g) |
---|
[09489b89] | 781 | { |
---|
| 782 | if (g->haveaim) return(1); |
---|
| 783 | return(0); |
---|
| 784 | } |
---|
| 785 | |
---|
[b7bb454] | 786 | void owl_global_set_ignore_aimlogin(owl_global *g) |
---|
| 787 | { |
---|
| 788 | g->ignoreaimlogin = 1; |
---|
| 789 | } |
---|
| 790 | |
---|
| 791 | void owl_global_unset_ignore_aimlogin(owl_global *g) |
---|
| 792 | { |
---|
| 793 | g->ignoreaimlogin = 0; |
---|
| 794 | } |
---|
| 795 | |
---|
[8742840] | 796 | int owl_global_is_ignore_aimlogin(const owl_global *g) |
---|
[b7bb454] | 797 | { |
---|
| 798 | return g->ignoreaimlogin; |
---|
| 799 | } |
---|
| 800 | |
---|
[09489b89] | 801 | void owl_global_set_havezephyr(owl_global *g) |
---|
| 802 | { |
---|
| 803 | g->havezephyr=1; |
---|
| 804 | } |
---|
| 805 | |
---|
[8742840] | 806 | int owl_global_is_havezephyr(const owl_global *g) |
---|
[09489b89] | 807 | { |
---|
| 808 | if (g->havezephyr) return(1); |
---|
| 809 | return(0); |
---|
| 810 | } |
---|
[de03334] | 811 | |
---|
[ec6ff52] | 812 | owl_errqueue *owl_global_get_errqueue(owl_global *g) |
---|
| 813 | { |
---|
| 814 | return(&(g->errqueue)); |
---|
| 815 | } |
---|
[c9e72d1] | 816 | |
---|
[5a95b69] | 817 | owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g) |
---|
| 818 | { |
---|
| 819 | return(&(g->zbuddies)); |
---|
| 820 | } |
---|
[8232149] | 821 | |
---|
[f25812b] | 822 | GList **owl_global_get_zaldlist(owl_global *g) |
---|
| 823 | { |
---|
| 824 | return &(g->zaldlist); |
---|
| 825 | } |
---|
| 826 | |
---|
| 827 | int owl_global_get_pseudologin_notify(owl_global *g) |
---|
| 828 | { |
---|
| 829 | return g->pseudologin_notify; |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | void owl_global_set_pseudologin_notify(owl_global *g, int notify) |
---|
| 833 | { |
---|
| 834 | g->pseudologin_notify = notify; |
---|
| 835 | } |
---|
| 836 | |
---|
[8232149] | 837 | struct termios *owl_global_get_startup_tio(owl_global *g) |
---|
| 838 | { |
---|
| 839 | return(&(g->startup_tio)); |
---|
| 840 | } |
---|
[8e401cae] | 841 | |
---|
[04b16f8] | 842 | void owl_global_setup_default_filters(owl_global *g) |
---|
| 843 | { |
---|
| 844 | int i; |
---|
| 845 | static const struct { |
---|
| 846 | const char *name; |
---|
| 847 | const char *desc; |
---|
| 848 | } filters[] = { |
---|
| 849 | { "personal", |
---|
[efc460e] | 850 | "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message ) )" }, |
---|
[04b16f8] | 851 | { "trash", |
---|
| 852 | "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" }, |
---|
| 853 | { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" }, |
---|
| 854 | { "ping", "opcode ^ping$" }, |
---|
| 855 | { "auto", "opcode ^auto$" }, |
---|
| 856 | { "login", "not login ^none$" }, |
---|
| 857 | { "reply-lockout", "class ^noc or class ^mail$" }, |
---|
| 858 | { "out", "direction ^out$" }, |
---|
| 859 | { "aim", "type ^aim$" }, |
---|
| 860 | { "zephyr", "type ^zephyr$" }, |
---|
| 861 | { "none", "false" }, |
---|
| 862 | { "all", "true" }, |
---|
| 863 | { NULL, NULL } |
---|
| 864 | }; |
---|
| 865 | |
---|
| 866 | owl_function_debugmsg("startup: creating default filters"); |
---|
| 867 | |
---|
| 868 | for (i = 0; filters[i].name != NULL; i++) |
---|
| 869 | owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name, |
---|
| 870 | filters[i].desc)); |
---|
| 871 | } |
---|
[d12a8c7] | 872 | |
---|
| 873 | FILE *owl_global_get_debug_file_handle(owl_global *g) { |
---|
| 874 | static char *open_file = NULL; |
---|
| 875 | const char *filename = owl_global_get_debug_file(g); |
---|
| 876 | if (g->debug_file == NULL || |
---|
| 877 | (open_file && strcmp(filename, open_file) != 0)) { |
---|
[26ad412] | 878 | char *path; |
---|
[50522b5] | 879 | int fd; |
---|
| 880 | |
---|
[d12a8c7] | 881 | if (g->debug_file) |
---|
| 882 | fclose(g->debug_file); |
---|
[50522b5] | 883 | |
---|
| 884 | g->debug_file = NULL; |
---|
| 885 | |
---|
[3472845] | 886 | path = g_strdup_printf("%s.%d", filename, getpid()); |
---|
[26ad412] | 887 | fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600); |
---|
[ddbbcffa] | 888 | g_free(path); |
---|
[26ad412] | 889 | |
---|
[50522b5] | 890 | if (fd >= 0) |
---|
| 891 | g->debug_file = fdopen(fd, "a"); |
---|
[d12a8c7] | 892 | |
---|
[ddbbcffa] | 893 | g_free(open_file); |
---|
[d4927a7] | 894 | open_file = g_strdup(filename); |
---|
[d12a8c7] | 895 | } |
---|
| 896 | return g->debug_file; |
---|
| 897 | } |
---|
[5f8ec6b] | 898 | |
---|
[47e0a6a] | 899 | const char *owl_global_get_kill_buffer(owl_global *g) { |
---|
[5f8ec6b] | 900 | return g->kill_buffer; |
---|
| 901 | } |
---|
| 902 | |
---|
[47e0a6a] | 903 | void owl_global_set_kill_buffer(owl_global *g, const char *kill, int len) { |
---|
| 904 | g_free(g->kill_buffer); |
---|
| 905 | g->kill_buffer = g_strndup(kill, len); |
---|
[5f8ec6b] | 906 | } |
---|
[47128d9] | 907 | |
---|
| 908 | void owl_global_add_interrupt(owl_global *g) { |
---|
| 909 | /* TODO: This can almost certainly be done with atomic |
---|
| 910 | * operations. Whatever. */ |
---|
| 911 | g_mutex_lock(g->interrupt_lock); |
---|
| 912 | g->interrupt_count++; |
---|
| 913 | g_mutex_unlock(g->interrupt_lock); |
---|
| 914 | } |
---|
| 915 | |
---|
| 916 | bool owl_global_take_interrupt(owl_global *g) { |
---|
| 917 | bool ans = false; |
---|
| 918 | g_mutex_lock(g->interrupt_lock); |
---|
| 919 | if (g->interrupt_count > 0) { |
---|
| 920 | ans = true; |
---|
| 921 | g->interrupt_count--; |
---|
| 922 | } |
---|
| 923 | g_mutex_unlock(g->interrupt_lock); |
---|
| 924 | return ans; |
---|
| 925 | } |
---|