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