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