[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(); |
---|
[df0138f] | 107 | owl_list_create(&(g->io_dispatch_list)); |
---|
[58d1f8a] | 108 | g->timerlist = NULL; |
---|
[5f8ec6b] | 109 | g->kill_buffer = NULL; |
---|
[47128d9] | 110 | |
---|
| 111 | g->interrupt_count = 0; |
---|
| 112 | g->interrupt_lock = g_mutex_new(); |
---|
[571fab7] | 113 | } |
---|
| 114 | |
---|
| 115 | static void _owl_global_init_windows(owl_global *g) |
---|
| 116 | { |
---|
| 117 | /* Create the main window */ |
---|
| 118 | owl_mainpanel_init(&(g->mainpanel)); |
---|
| 119 | |
---|
| 120 | /* Create the widgets */ |
---|
| 121 | owl_mainwin_init(&(g->mw), g->mainpanel.recwin); |
---|
| 122 | owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin); |
---|
| 123 | owl_sepbar_init(g->mainpanel.sepwin); |
---|
[0881cdd] | 124 | |
---|
[4dd115f] | 125 | owl_window_set_default_cursor(g->mainpanel.sepwin); |
---|
[0881cdd] | 126 | |
---|
| 127 | /* set up a pad for input */ |
---|
| 128 | g->input_pad = newpad(1, 1); |
---|
| 129 | nodelay(g->input_pad, 1); |
---|
| 130 | keypad(g->input_pad, 1); |
---|
| 131 | meta(g->input_pad, 1); |
---|
[7d4fbcd] | 132 | } |
---|
| 133 | |
---|
[044f19f] | 134 | void owl_global_sepbar_dirty(owl_global *g) |
---|
| 135 | { |
---|
| 136 | owl_window_dirty(g->mainpanel.sepwin); |
---|
| 137 | } |
---|
| 138 | |
---|
[eb6cedc] | 139 | /* Called once perl has been initialized */ |
---|
| 140 | void owl_global_complete_setup(owl_global *g) |
---|
| 141 | { |
---|
| 142 | owl_cmddict_setup(&(g->cmds)); |
---|
| 143 | } |
---|
| 144 | |
---|
[005eae5] | 145 | owl_context *owl_global_get_context(const owl_global *g) { |
---|
[a999d9e] | 146 | if (!g->context_stack) |
---|
| 147 | return NULL; |
---|
| 148 | return g->context_stack->data; |
---|
| 149 | } |
---|
| 150 | |
---|
[07b59ea] | 151 | static void owl_global_activate_context(owl_global *g, owl_context *c) { |
---|
| 152 | if (!c) |
---|
[a999d9e] | 153 | return; |
---|
| 154 | |
---|
[07b59ea] | 155 | if (c->keymap) { |
---|
| 156 | if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) { |
---|
| 157 | owl_function_error("Unable to activate keymap '%s'", c->keymap); |
---|
| 158 | } |
---|
[a999d9e] | 159 | } |
---|
[07b59ea] | 160 | owl_window_set_cursor(c->cursor); |
---|
[7d4fbcd] | 161 | } |
---|
[a999d9e] | 162 | |
---|
[07b59ea] | 163 | void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) { |
---|
[a999d9e] | 164 | owl_context *c; |
---|
[cb81570] | 165 | c = owl_context_new(mode, data, keymap, cursor); |
---|
[1d74663] | 166 | owl_global_push_context_obj(g, c); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | void owl_global_push_context_obj(owl_global *g, owl_context *c) |
---|
| 170 | { |
---|
[a999d9e] | 171 | g->context_stack = g_list_prepend(g->context_stack, c); |
---|
[07b59ea] | 172 | owl_global_activate_context(g, owl_global_get_context(g)); |
---|
[a999d9e] | 173 | } |
---|
| 174 | |
---|
[1d74663] | 175 | /* Pops the current context from the context stack and returns it. Caller is |
---|
| 176 | * responsible for freeing. */ |
---|
| 177 | owl_context *owl_global_pop_context_no_delete(owl_global *g) { |
---|
[a999d9e] | 178 | owl_context *c; |
---|
| 179 | if (!g->context_stack) |
---|
[1d74663] | 180 | return NULL; |
---|
[a999d9e] | 181 | c = owl_global_get_context(g); |
---|
[1d74663] | 182 | owl_context_deactivate(c); |
---|
[a999d9e] | 183 | g->context_stack = g_list_delete_link(g->context_stack, |
---|
| 184 | g->context_stack); |
---|
[07b59ea] | 185 | owl_global_activate_context(g, owl_global_get_context(g)); |
---|
[1d74663] | 186 | return c; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | /* Pops the current context from the context stack and deletes it. */ |
---|
| 190 | void owl_global_pop_context(owl_global *g) { |
---|
| 191 | owl_context *c; |
---|
| 192 | c = owl_global_pop_context_no_delete(g); |
---|
| 193 | if (c) |
---|
| 194 | owl_context_delete(c); |
---|
[a999d9e] | 195 | } |
---|
| 196 | |
---|
[8742840] | 197 | int owl_global_get_lines(const owl_global *g) { |
---|
[7d4fbcd] | 198 | return(g->lines); |
---|
| 199 | } |
---|
| 200 | |
---|
[8742840] | 201 | int owl_global_get_cols(const owl_global *g) { |
---|
[7d4fbcd] | 202 | return(g->cols); |
---|
| 203 | } |
---|
| 204 | |
---|
[8742840] | 205 | int owl_global_get_recwin_lines(const owl_global *g) { |
---|
[d2a4534] | 206 | return g->mainpanel.recwinlines; |
---|
[7d4fbcd] | 207 | } |
---|
| 208 | |
---|
| 209 | /* curmsg */ |
---|
| 210 | |
---|
[8742840] | 211 | int owl_global_get_curmsg(const owl_global *g) { |
---|
[7d4fbcd] | 212 | return(g->curmsg); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | void owl_global_set_curmsg(owl_global *g, int i) { |
---|
| 216 | g->curmsg=i; |
---|
| 217 | /* we will reset the vertical offset from here */ |
---|
| 218 | /* we might want to move this out to the functions later */ |
---|
| 219 | owl_global_set_curmsg_vert_offset(g, 0); |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | /* topmsg */ |
---|
| 223 | |
---|
[8742840] | 224 | int owl_global_get_topmsg(const owl_global *g) { |
---|
[7d4fbcd] | 225 | return(g->topmsg); |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | void owl_global_set_topmsg(owl_global *g, int i) { |
---|
| 229 | g->topmsg=i; |
---|
| 230 | } |
---|
| 231 | |
---|
[70110286] | 232 | /* markedmsgid */ |
---|
| 233 | |
---|
[8742840] | 234 | int owl_global_get_markedmsgid(const owl_global *g) { |
---|
[70110286] | 235 | return(g->markedmsgid); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | void owl_global_set_markedmsgid(owl_global *g, int i) { |
---|
| 239 | g->markedmsgid=i; |
---|
| 240 | /* i; index of message in the current view. |
---|
[c08c70a] | 241 | const owl_message *m; |
---|
[70110286] | 242 | owl_view *v; |
---|
| 243 | |
---|
| 244 | v = owl_global_get_current_view(&g); |
---|
| 245 | m = owl_view_get_element(v, i); |
---|
| 246 | g->markedmsgid = m ? owl_message_get_id(m) : 0; |
---|
| 247 | */ |
---|
| 248 | } |
---|
| 249 | |
---|
[7d4fbcd] | 250 | /* windows */ |
---|
| 251 | |
---|
| 252 | owl_mainwin *owl_global_get_mainwin(owl_global *g) { |
---|
| 253 | return(&(g->mw)); |
---|
| 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) { |
---|
| 267 | return(&(g->msglist)); |
---|
| 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); |
---|
[3472845] | 369 | g->startupfile = g_strdup_printf("%s/startup", cd); |
---|
[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 | |
---|
| 583 | owl_list *owl_global_get_puntlist(owl_global *g) { |
---|
| 584 | return(&(g->puntlist)); |
---|
| 585 | } |
---|
| 586 | |
---|
[c08c70a] | 587 | int owl_global_message_is_puntable(owl_global *g, const owl_message *m) { |
---|
[77bced3] | 588 | const owl_list *pl; |
---|
[7d4fbcd] | 589 | int i, j; |
---|
| 590 | |
---|
| 591 | pl=owl_global_get_puntlist(g); |
---|
| 592 | j=owl_list_get_size(pl); |
---|
| 593 | for (i=0; i<j; i++) { |
---|
| 594 | if (owl_filter_message_match(owl_list_get_element(pl, i), m)) return(1); |
---|
| 595 | } |
---|
| 596 | return(0); |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | int owl_global_should_followlast(owl_global *g) { |
---|
[9e5c9f3] | 600 | const owl_view *v; |
---|
[7d4fbcd] | 601 | |
---|
| 602 | if (!owl_global_is__followlast(g)) return(0); |
---|
| 603 | |
---|
| 604 | v=owl_global_get_current_view(g); |
---|
| 605 | |
---|
| 606 | if (owl_global_get_curmsg(g)==owl_view_get_size(v)-1) return(1); |
---|
| 607 | return(0); |
---|
| 608 | } |
---|
[1fd0b25] | 609 | |
---|
[8742840] | 610 | int owl_global_is_search_active(const owl_global *g) { |
---|
[41c9a96] | 611 | if (owl_regex_is_set(&g->search_re)) return(1); |
---|
[1fd0b25] | 612 | return(0); |
---|
| 613 | } |
---|
| 614 | |
---|
[89b2daf] | 615 | void owl_global_set_search_re(owl_global *g, const owl_regex *re) { |
---|
[41c9a96] | 616 | if (owl_regex_is_set(&g->search_re)) { |
---|
[5cbc929] | 617 | owl_regex_cleanup(&g->search_re); |
---|
[41c9a96] | 618 | owl_regex_init(&g->search_re); |
---|
| 619 | } |
---|
| 620 | if (re != NULL) |
---|
| 621 | owl_regex_copy(re, &g->search_re); |
---|
[2ec737f] | 622 | /* TODO: Emit a signal so we don't depend on the viewwin and mainwin */ |
---|
[5b68c05] | 623 | if (owl_global_get_viewwin(g)) |
---|
| 624 | owl_viewwin_dirty(owl_global_get_viewwin(g)); |
---|
[2ec737f] | 625 | owl_mainwin_redisplay(owl_global_get_mainwin(g)); |
---|
[1fd0b25] | 626 | } |
---|
| 627 | |
---|
[8742840] | 628 | const owl_regex *owl_global_get_search_re(const owl_global *g) { |
---|
[41c9a96] | 629 | return &g->search_re; |
---|
[1fd0b25] | 630 | } |
---|
[700c712] | 631 | |
---|
[0e5afa2] | 632 | void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) { |
---|
[700c712] | 633 | g->newmsgproc_pid=i; |
---|
| 634 | } |
---|
| 635 | |
---|
[0e5afa2] | 636 | pid_t owl_global_get_newmsgproc_pid(const owl_global *g) { |
---|
[700c712] | 637 | return(g->newmsgproc_pid); |
---|
| 638 | } |
---|
| 639 | |
---|
[d09e5a1] | 640 | /* AIM stuff */ |
---|
| 641 | |
---|
[8742840] | 642 | int owl_global_is_aimloggedin(const owl_global *g) |
---|
[6a415e9] | 643 | { |
---|
[d09e5a1] | 644 | if (g->aim_loggedin) return(1); |
---|
| 645 | return(0); |
---|
| 646 | } |
---|
| 647 | |
---|
[8742840] | 648 | const char *owl_global_get_aim_screenname(const owl_global *g) |
---|
[6a415e9] | 649 | { |
---|
[a352335c] | 650 | if (owl_global_is_aimloggedin(g)) { |
---|
| 651 | return (g->aim_screenname); |
---|
| 652 | } |
---|
| 653 | return(""); |
---|
[d09e5a1] | 654 | } |
---|
| 655 | |
---|
[8742840] | 656 | const char *owl_global_get_aim_screenname_for_filters(const owl_global *g) |
---|
[81655f8] | 657 | { |
---|
| 658 | if (owl_global_is_aimloggedin(g)) { |
---|
| 659 | return (g->aim_screenname_for_filters); |
---|
| 660 | } |
---|
| 661 | return(""); |
---|
| 662 | } |
---|
| 663 | |
---|
[e19eb97] | 664 | void owl_global_set_aimloggedin(owl_global *g, const char *screenname) |
---|
[6a415e9] | 665 | { |
---|
[65b2173] | 666 | char *sn_escaped; |
---|
[d09e5a1] | 667 | g->aim_loggedin=1; |
---|
[ddbbcffa] | 668 | if (g->aim_screenname) g_free(g->aim_screenname); |
---|
| 669 | if (g->aim_screenname_for_filters) g_free(g->aim_screenname_for_filters); |
---|
[d4927a7] | 670 | g->aim_screenname=g_strdup(screenname); |
---|
[81655f8] | 671 | sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
[d222c44] | 672 | g->aim_screenname_for_filters = owl_arg_quote(sn_escaped); |
---|
[ddbbcffa] | 673 | g_free(sn_escaped); |
---|
[d09e5a1] | 674 | } |
---|
| 675 | |
---|
[6a415e9] | 676 | void owl_global_set_aimnologgedin(owl_global *g) |
---|
| 677 | { |
---|
[d09e5a1] | 678 | g->aim_loggedin=0; |
---|
| 679 | } |
---|
| 680 | |
---|
[dc1edbd] | 681 | bool owl_global_is_doaimevents(const owl_global *g) |
---|
[a352335c] | 682 | { |
---|
[dc1edbd] | 683 | return g->aim_event_source != NULL; |
---|
[a352335c] | 684 | } |
---|
| 685 | |
---|
| 686 | void owl_global_set_doaimevents(owl_global *g) |
---|
| 687 | { |
---|
[dc1edbd] | 688 | if (g->aim_event_source) |
---|
| 689 | return; |
---|
| 690 | g->aim_event_source = owl_aim_event_source_new(owl_global_get_aimsess(g)); |
---|
| 691 | g_source_attach(g->aim_event_source, NULL); |
---|
[a352335c] | 692 | } |
---|
| 693 | |
---|
| 694 | void owl_global_set_no_doaimevents(owl_global *g) |
---|
| 695 | { |
---|
[dc1edbd] | 696 | if (!g->aim_event_source) |
---|
| 697 | return; |
---|
| 698 | g_source_destroy(g->aim_event_source); |
---|
| 699 | g_source_unref(g->aim_event_source); |
---|
| 700 | g->aim_event_source = NULL; |
---|
[a352335c] | 701 | } |
---|
| 702 | |
---|
[6a415e9] | 703 | aim_session_t *owl_global_get_aimsess(owl_global *g) |
---|
| 704 | { |
---|
[d09e5a1] | 705 | return(&(g->aimsess)); |
---|
| 706 | } |
---|
| 707 | |
---|
[c15bbfb] | 708 | aim_conn_t *owl_global_get_bosconn(owl_global *g) |
---|
| 709 | { |
---|
| 710 | return(&(g->bosconn)); |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | void owl_global_set_bossconn(owl_global *g, aim_conn_t *conn) |
---|
[6a415e9] | 714 | { |
---|
[c15bbfb] | 715 | g->bosconn=*conn; |
---|
[d09e5a1] | 716 | } |
---|
| 717 | |
---|
| 718 | /* message queue */ |
---|
| 719 | |
---|
[6a415e9] | 720 | void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m) |
---|
| 721 | { |
---|
[20aced3] | 722 | g_queue_push_tail(g->messagequeue, m); |
---|
[d09e5a1] | 723 | } |
---|
| 724 | |
---|
| 725 | /* pop off the first message and return it. Return NULL if the queue |
---|
| 726 | * is empty. The caller should free the message after using it, if |
---|
| 727 | * necessary. |
---|
| 728 | */ |
---|
[13a3c1db] | 729 | owl_message *owl_global_messagequeue_popmsg(owl_global *g) |
---|
[6a415e9] | 730 | { |
---|
[d09e5a1] | 731 | owl_message *out; |
---|
| 732 | |
---|
[20aced3] | 733 | if (g_queue_is_empty(g->messagequeue)) |
---|
| 734 | return NULL; |
---|
| 735 | out = g_queue_pop_head(g->messagequeue); |
---|
| 736 | return out; |
---|
[d09e5a1] | 737 | } |
---|
| 738 | |
---|
[6a415e9] | 739 | int owl_global_messagequeue_pending(owl_global *g) |
---|
| 740 | { |
---|
[20aced3] | 741 | return !g_queue_is_empty(g->messagequeue); |
---|
[d09e5a1] | 742 | } |
---|
[aa5f725] | 743 | |
---|
[6a415e9] | 744 | owl_buddylist *owl_global_get_buddylist(owl_global *g) |
---|
| 745 | { |
---|
[aa5f725] | 746 | return(&(g->buddylist)); |
---|
| 747 | } |
---|
| 748 | |
---|
[bd3f232] | 749 | /* style */ |
---|
| 750 | |
---|
| 751 | /* Return the style with name 'name'. If it does not exist return |
---|
| 752 | * NULL */ |
---|
[8742840] | 753 | const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name) |
---|
[bd3f232] | 754 | { |
---|
[f1e629d] | 755 | return owl_dict_find_element(&(g->styledict), name); |
---|
| 756 | } |
---|
| 757 | |
---|
[351c535] | 758 | void owl_global_get_style_names(const owl_global *g, owl_list *l) { |
---|
| 759 | owl_dict_get_keys(&(g->styledict), l); |
---|
[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 | |
---|
[df0138f] | 843 | owl_list *owl_global_get_io_dispatch_list(owl_global *g) |
---|
| 844 | { |
---|
| 845 | return &(g->io_dispatch_list); |
---|
| 846 | } |
---|
| 847 | |
---|
[58d1f8a] | 848 | GList **owl_global_get_timerlist(owl_global *g) |
---|
[b7bb454] | 849 | { |
---|
[58d1f8a] | 850 | return &(g->timerlist); |
---|
[b7bb454] | 851 | } |
---|
[adee9cc] | 852 | |
---|
[04b16f8] | 853 | void owl_global_setup_default_filters(owl_global *g) |
---|
| 854 | { |
---|
| 855 | int i; |
---|
| 856 | static const struct { |
---|
| 857 | const char *name; |
---|
| 858 | const char *desc; |
---|
| 859 | } filters[] = { |
---|
| 860 | { "personal", |
---|
[efc460e] | 861 | "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message ) )" }, |
---|
[04b16f8] | 862 | { "trash", |
---|
| 863 | "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" }, |
---|
| 864 | { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" }, |
---|
| 865 | { "ping", "opcode ^ping$" }, |
---|
| 866 | { "auto", "opcode ^auto$" }, |
---|
| 867 | { "login", "not login ^none$" }, |
---|
| 868 | { "reply-lockout", "class ^noc or class ^mail$" }, |
---|
| 869 | { "out", "direction ^out$" }, |
---|
| 870 | { "aim", "type ^aim$" }, |
---|
| 871 | { "zephyr", "type ^zephyr$" }, |
---|
| 872 | { "none", "false" }, |
---|
| 873 | { "all", "true" }, |
---|
| 874 | { NULL, NULL } |
---|
| 875 | }; |
---|
| 876 | |
---|
| 877 | owl_function_debugmsg("startup: creating default filters"); |
---|
| 878 | |
---|
| 879 | for (i = 0; filters[i].name != NULL; i++) |
---|
| 880 | owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name, |
---|
| 881 | filters[i].desc)); |
---|
| 882 | } |
---|
[d12a8c7] | 883 | |
---|
| 884 | FILE *owl_global_get_debug_file_handle(owl_global *g) { |
---|
| 885 | static char *open_file = NULL; |
---|
| 886 | const char *filename = owl_global_get_debug_file(g); |
---|
| 887 | if (g->debug_file == NULL || |
---|
| 888 | (open_file && strcmp(filename, open_file) != 0)) { |
---|
[26ad412] | 889 | char *path; |
---|
[50522b5] | 890 | int fd; |
---|
| 891 | |
---|
[d12a8c7] | 892 | if (g->debug_file) |
---|
| 893 | fclose(g->debug_file); |
---|
[50522b5] | 894 | |
---|
| 895 | g->debug_file = NULL; |
---|
| 896 | |
---|
[3472845] | 897 | path = g_strdup_printf("%s.%d", filename, getpid()); |
---|
[26ad412] | 898 | fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600); |
---|
[ddbbcffa] | 899 | g_free(path); |
---|
[26ad412] | 900 | |
---|
[50522b5] | 901 | if (fd >= 0) |
---|
| 902 | g->debug_file = fdopen(fd, "a"); |
---|
[d12a8c7] | 903 | |
---|
[ddbbcffa] | 904 | g_free(open_file); |
---|
[d4927a7] | 905 | open_file = g_strdup(filename); |
---|
[d12a8c7] | 906 | } |
---|
| 907 | return g->debug_file; |
---|
| 908 | } |
---|
[5f8ec6b] | 909 | |
---|
[47e0a6a] | 910 | const char *owl_global_get_kill_buffer(owl_global *g) { |
---|
[5f8ec6b] | 911 | return g->kill_buffer; |
---|
| 912 | } |
---|
| 913 | |
---|
[47e0a6a] | 914 | void owl_global_set_kill_buffer(owl_global *g, const char *kill, int len) { |
---|
| 915 | g_free(g->kill_buffer); |
---|
| 916 | g->kill_buffer = g_strndup(kill, len); |
---|
[5f8ec6b] | 917 | } |
---|
[47128d9] | 918 | |
---|
| 919 | void owl_global_add_interrupt(owl_global *g) { |
---|
| 920 | /* TODO: This can almost certainly be done with atomic |
---|
| 921 | * operations. Whatever. */ |
---|
| 922 | g_mutex_lock(g->interrupt_lock); |
---|
| 923 | g->interrupt_count++; |
---|
| 924 | g_mutex_unlock(g->interrupt_lock); |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | bool owl_global_take_interrupt(owl_global *g) { |
---|
| 928 | bool ans = false; |
---|
| 929 | g_mutex_lock(g->interrupt_lock); |
---|
| 930 | if (g->interrupt_count > 0) { |
---|
| 931 | ans = true; |
---|
| 932 | g->interrupt_count--; |
---|
| 933 | } |
---|
| 934 | g_mutex_unlock(g->interrupt_lock); |
---|
| 935 | return ans; |
---|
| 936 | } |
---|