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