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