[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 | |
---|
| 11 | #ifndef MAXHOSTNAMELEN |
---|
| 12 | #define MAXHOSTNAMELEN 256 |
---|
| 13 | #endif |
---|
| 14 | |
---|
[571fab7] | 15 | static void _owl_global_init_windows(owl_global *g); |
---|
| 16 | |
---|
[7d4fbcd] | 17 | void owl_global_init(owl_global *g) { |
---|
| 18 | struct hostent *hent; |
---|
| 19 | char hostname[MAXHOSTNAMELEN]; |
---|
[ad15610] | 20 | char *cd; |
---|
[7d4fbcd] | 21 | |
---|
[0be3efd] | 22 | g_type_init(); |
---|
| 23 | |
---|
[7d4fbcd] | 24 | gethostname(hostname, MAXHOSTNAMELEN); |
---|
| 25 | hent=gethostbyname(hostname); |
---|
| 26 | if (!hent) { |
---|
[a8938c7] | 27 | g->thishost=owl_strdup("localhost"); |
---|
[7d4fbcd] | 28 | } else { |
---|
[a8938c7] | 29 | g->thishost=owl_strdup(hent->h_name); |
---|
[7d4fbcd] | 30 | } |
---|
| 31 | |
---|
[5cc7e5e] | 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 | |
---|
[a999d9e] | 38 | g->context_stack = NULL; |
---|
[07b59ea] | 39 | owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL); |
---|
[a999d9e] | 40 | |
---|
[7d4fbcd] | 41 | g->curmsg=0; |
---|
| 42 | g->topmsg=0; |
---|
[bd783db] | 43 | g->markedmsgid=-1; |
---|
[a8938c7] | 44 | g->startupargs=NULL; |
---|
[7d4fbcd] | 45 | |
---|
| 46 | owl_variable_dict_setup(&(g->vars)); |
---|
| 47 | |
---|
| 48 | g->rightshift=0; |
---|
| 49 | |
---|
[03ca005] | 50 | g->pw = NULL; |
---|
[9eb38bb] | 51 | g->vw = NULL; |
---|
[38cc669] | 52 | g->tw = NULL; |
---|
[7d4fbcd] | 53 | |
---|
| 54 | owl_keyhandler_init(&g->kh); |
---|
| 55 | owl_keys_setup_keymaps(&g->kh); |
---|
| 56 | |
---|
[129e609] | 57 | owl_dict_create(&(g->filters)); |
---|
| 58 | g->filterlist = NULL; |
---|
[7d4fbcd] | 59 | owl_list_create(&(g->puntlist)); |
---|
[20aced3] | 60 | g->messagequeue = g_queue_new(); |
---|
[f1e629d] | 61 | owl_dict_create(&(g->styledict)); |
---|
[7d4fbcd] | 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; |
---|
[8fa9562] | 70 | owl_fmtext_init_colorpair_mgr(&(g->cpmgr)); |
---|
[7d4fbcd] | 71 | g->debug=OWL_DEBUG; |
---|
[41c9a96] | 72 | owl_regex_init(&g->search_re); |
---|
[7d4fbcd] | 73 | g->starttime=time(NULL); /* assumes we call init only a start time */ |
---|
[7f792c1] | 74 | g->lastinputtime=g->starttime; |
---|
[700c712] | 75 | g->newmsgproc_pid=0; |
---|
[61e79a9] | 76 | |
---|
[7d4fbcd] | 77 | owl_global_set_config_format(g, 0); |
---|
| 78 | owl_global_set_no_have_config(g); |
---|
[10b866d] | 79 | owl_history_init(&(g->msghist)); |
---|
| 80 | owl_history_init(&(g->cmdhist)); |
---|
[5a9f6fe] | 81 | owl_history_set_norepeats(&(g->cmdhist)); |
---|
[7d4fbcd] | 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 */ |
---|
[a8938c7] | 86 | g->homedir=owl_strdup(getenv("HOME")); |
---|
[7d4fbcd] | 87 | |
---|
[b363d83] | 88 | g->confdir = NULL; |
---|
| 89 | g->startupfile = NULL; |
---|
[ad15610] | 90 | cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR); |
---|
[b363d83] | 91 | owl_global_set_confdir(g, cd); |
---|
| 92 | owl_free(cd); |
---|
| 93 | |
---|
[7d4fbcd] | 94 | owl_messagelist_create(&(g->msglist)); |
---|
[571fab7] | 95 | |
---|
| 96 | _owl_global_init_windows(g); |
---|
[d09e5a1] | 97 | |
---|
| 98 | g->aim_screenname=NULL; |
---|
[81655f8] | 99 | g->aim_screenname_for_filters=NULL; |
---|
[d09e5a1] | 100 | g->aim_loggedin=0; |
---|
[aa5f725] | 101 | owl_buddylist_init(&(g->buddylist)); |
---|
[b7bb454] | 102 | |
---|
[09489b89] | 103 | g->havezephyr=0; |
---|
| 104 | g->haveaim=0; |
---|
[b7bb454] | 105 | g->ignoreaimlogin=0; |
---|
[a352335c] | 106 | owl_global_set_no_doaimevents(g); |
---|
[ec6ff52] | 107 | |
---|
| 108 | owl_errqueue_init(&(g->errqueue)); |
---|
[c9e72d1] | 109 | g->got_err_signal=0; |
---|
[5a95b69] | 110 | |
---|
| 111 | owl_zbuddylist_create(&(g->zbuddies)); |
---|
[8e401cae] | 112 | |
---|
[f25812b] | 113 | g->zaldlist = NULL; |
---|
| 114 | g->pseudologin_notify = 0; |
---|
| 115 | |
---|
[a387d12e] | 116 | owl_message_init_fmtext_cache(); |
---|
[df0138f] | 117 | owl_list_create(&(g->io_dispatch_list)); |
---|
[4f2166b] | 118 | owl_list_create(&(g->psa_list)); |
---|
[58d1f8a] | 119 | g->timerlist = NULL; |
---|
[adee9cc] | 120 | g->interrupted = FALSE; |
---|
[571fab7] | 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); |
---|
[0881cdd] | 132 | |
---|
[4dd115f] | 133 | owl_window_set_default_cursor(g->mainpanel.sepwin); |
---|
[0881cdd] | 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); |
---|
[7d4fbcd] | 140 | } |
---|
| 141 | |
---|
[044f19f] | 142 | void owl_global_sepbar_dirty(owl_global *g) |
---|
| 143 | { |
---|
| 144 | owl_window_dirty(g->mainpanel.sepwin); |
---|
| 145 | } |
---|
| 146 | |
---|
[eb6cedc] | 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 | |
---|
[005eae5] | 153 | owl_context *owl_global_get_context(const owl_global *g) { |
---|
[a999d9e] | 154 | if (!g->context_stack) |
---|
| 155 | return NULL; |
---|
| 156 | return g->context_stack->data; |
---|
| 157 | } |
---|
| 158 | |
---|
[07b59ea] | 159 | static void owl_global_activate_context(owl_global *g, owl_context *c) { |
---|
| 160 | if (!c) |
---|
[a999d9e] | 161 | return; |
---|
| 162 | |
---|
[07b59ea] | 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 | } |
---|
[a999d9e] | 167 | } |
---|
[07b59ea] | 168 | owl_window_set_cursor(c->cursor); |
---|
[7d4fbcd] | 169 | } |
---|
[a999d9e] | 170 | |
---|
[07b59ea] | 171 | void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) { |
---|
[a999d9e] | 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; |
---|
[07b59ea] | 178 | c->cursor = cursor ? g_object_ref(cursor) : NULL; |
---|
[a999d9e] | 179 | c->keymap = owl_strdup(keymap); |
---|
| 180 | g->context_stack = g_list_prepend(g->context_stack, c); |
---|
[07b59ea] | 181 | owl_global_activate_context(g, owl_global_get_context(g)); |
---|
[a999d9e] | 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); |
---|
[07b59ea] | 191 | if (c->cursor) |
---|
| 192 | g_object_unref(c->cursor); |
---|
[a999d9e] | 193 | owl_free(c->keymap); |
---|
| 194 | owl_free(c); |
---|
[07b59ea] | 195 | owl_global_activate_context(g, owl_global_get_context(g)); |
---|
[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 | |
---|
[8bba1ae] | 277 | /* underlying owl_windows */ |
---|
[7d4fbcd] | 278 | |
---|
[8bba1ae] | 279 | owl_window *owl_global_get_typwin_window(const owl_global *g) { |
---|
[f6fae8d] | 280 | return g->mainpanel.typwin; |
---|
[7d4fbcd] | 281 | } |
---|
| 282 | |
---|
| 283 | /* typwin */ |
---|
| 284 | |
---|
[005eae5] | 285 | /* Gets the currently active typwin out of the current context. */ |
---|
[8742840] | 286 | owl_editwin *owl_global_get_typwin(const owl_global *g) { |
---|
[005eae5] | 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; |
---|
[7d4fbcd] | 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) { |
---|
[5b80b87] | 310 | g->rightshift = i; |
---|
[e92e2a1] | 311 | owl_mainwin_redisplay(owl_global_get_mainwin(g)); |
---|
[7d4fbcd] | 312 | } |
---|
| 313 | |
---|
[8742840] | 314 | int owl_global_get_rightshift(const owl_global *g) { |
---|
[7d4fbcd] | 315 | return(g->rightshift); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | /* typwin */ |
---|
| 319 | |
---|
[58d47ca] | 320 | owl_editwin *owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) { |
---|
[38cc669] | 321 | int d; |
---|
| 322 | d = owl_global_get_typewindelta(g); |
---|
[73eda8c] | 323 | if (d > 0 && style == OWL_EDITWIN_STYLE_MULTILINE) |
---|
[da466e0] | 324 | owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d); |
---|
| 325 | |
---|
[f6fae8d] | 326 | if (g->typwin_erase_id) { |
---|
[8bba1ae] | 327 | g_signal_handler_disconnect(owl_global_get_typwin_window(g), g->typwin_erase_id); |
---|
[f6fae8d] | 328 | g->typwin_erase_id = 0; |
---|
| 329 | } |
---|
| 330 | |
---|
[8bba1ae] | 331 | g->tw = owl_editwin_new(owl_global_get_typwin_window(g), |
---|
[38cc669] | 332 | owl_global_get_typwin_lines(g), |
---|
| 333 | g->cols, |
---|
| 334 | style, |
---|
| 335 | hist); |
---|
[58d47ca] | 336 | return g->tw; |
---|
[7d4fbcd] | 337 | } |
---|
| 338 | |
---|
| 339 | void owl_global_set_typwin_inactive(owl_global *g) { |
---|
[da466e0] | 340 | int d = owl_global_get_typewindelta(g); |
---|
[73eda8c] | 341 | if (d > 0 && owl_editwin_get_style(g->tw) == OWL_EDITWIN_STYLE_MULTILINE) |
---|
[da466e0] | 342 | owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d); |
---|
| 343 | |
---|
[f6fae8d] | 344 | if (!g->typwin_erase_id) { |
---|
| 345 | g->typwin_erase_id = |
---|
[8bba1ae] | 346 | g_signal_connect(owl_global_get_typwin_window(g), "redraw", G_CALLBACK(owl_window_erase_cb), NULL); |
---|
[f6fae8d] | 347 | } |
---|
[8bba1ae] | 348 | owl_window_dirty(owl_global_get_typwin_window(g)); |
---|
[f6fae8d] | 349 | |
---|
[38cc669] | 350 | g->tw = NULL; |
---|
[7d4fbcd] | 351 | } |
---|
| 352 | |
---|
| 353 | /* resize */ |
---|
| 354 | |
---|
| 355 | void owl_global_set_resize_pending(owl_global *g) { |
---|
| 356 | g->resizepending=1; |
---|
| 357 | } |
---|
| 358 | |
---|
[8742840] | 359 | const char *owl_global_get_homedir(const owl_global *g) { |
---|
[a8938c7] | 360 | if (g->homedir) return(g->homedir); |
---|
| 361 | return("/"); |
---|
[7d4fbcd] | 362 | } |
---|
| 363 | |
---|
[8742840] | 364 | const char *owl_global_get_confdir(const owl_global *g) { |
---|
[b363d83] | 365 | if (g->confdir) return(g->confdir); |
---|
| 366 | return("/"); |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | /* |
---|
| 370 | * Setting this also sets startupfile to confdir/startup |
---|
| 371 | */ |
---|
[e19eb97] | 372 | void owl_global_set_confdir(owl_global *g, const char *cd) { |
---|
[27f6487] | 373 | owl_free(g->confdir); |
---|
[b363d83] | 374 | g->confdir = owl_strdup(cd); |
---|
[27f6487] | 375 | owl_free(g->startupfile); |
---|
[b363d83] | 376 | g->startupfile = owl_sprintf("%s/startup", cd); |
---|
| 377 | } |
---|
| 378 | |
---|
[8742840] | 379 | const char *owl_global_get_startupfile(const owl_global *g) { |
---|
[b363d83] | 380 | if(g->startupfile) return(g->startupfile); |
---|
| 381 | return("/"); |
---|
| 382 | } |
---|
| 383 | |
---|
[8742840] | 384 | int owl_global_get_direction(const owl_global *g) { |
---|
[7d4fbcd] | 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 | |
---|
[8742840] | 402 | void *owl_global_get_perlinterp(const owl_global *g) { |
---|
[7d4fbcd] | 403 | return(g->perl); |
---|
| 404 | } |
---|
| 405 | |
---|
[8742840] | 406 | int owl_global_is_config_format(const owl_global *g) { |
---|
[7d4fbcd] | 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 | |
---|
[285bc9a] | 432 | /* |
---|
| 433 | * Compute the size of the terminal. Try a ioctl, fallback to other stuff on |
---|
| 434 | * fail. |
---|
| 435 | */ |
---|
[d39f68c] | 436 | void owl_global_get_terminal_size(int *lines, int *cols) { |
---|
[285bc9a] | 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 | |
---|
[99ce51c] | 453 | void owl_global_check_resize(owl_global *g) { |
---|
[3e0147f] | 454 | /* resize the screen. If lines or cols is 0 use the terminal size */ |
---|
[7d4fbcd] | 455 | if (!g->resizepending) return; |
---|
[8479494] | 456 | g->resizepending = 0; |
---|
[7d4fbcd] | 457 | |
---|
[99ce51c] | 458 | owl_global_get_terminal_size(&g->lines, &g->cols); |
---|
[7a6e6c7] | 459 | owl_window_resize(owl_window_get_screen(), g->lines, g->cols); |
---|
[7d4fbcd] | 460 | |
---|
[f9f88f3] | 461 | owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols); |
---|
[7d4fbcd] | 462 | } |
---|
| 463 | |
---|
| 464 | /* debug */ |
---|
| 465 | |
---|
[8742840] | 466 | int owl_global_is_debug_fast(const owl_global *g) { |
---|
[7d4fbcd] | 467 | if (g->debug) return(1); |
---|
| 468 | return(0); |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | /* starttime */ |
---|
| 472 | |
---|
[8742840] | 473 | time_t owl_global_get_starttime(const owl_global *g) { |
---|
[7d4fbcd] | 474 | return(g->starttime); |
---|
| 475 | } |
---|
| 476 | |
---|
[8742840] | 477 | time_t owl_global_get_runtime(const owl_global *g) { |
---|
[7d4fbcd] | 478 | return(time(NULL)-g->starttime); |
---|
| 479 | } |
---|
| 480 | |
---|
[8742840] | 481 | time_t owl_global_get_lastinputtime(const owl_global *g) { |
---|
[7f792c1] | 482 | return(g->lastinputtime); |
---|
| 483 | } |
---|
| 484 | |
---|
[eebef19] | 485 | void owl_global_set_lastinputtime(owl_global *g, time_t time) { |
---|
| 486 | g->lastinputtime = time; |
---|
[7f792c1] | 487 | } |
---|
| 488 | |
---|
[8742840] | 489 | time_t owl_global_get_idletime(const owl_global *g) { |
---|
[7f792c1] | 490 | return(time(NULL)-g->lastinputtime); |
---|
| 491 | } |
---|
| 492 | |
---|
[8742840] | 493 | const char *owl_global_get_hostname(const owl_global *g) { |
---|
[a8938c7] | 494 | if (g->thishost) return(g->thishost); |
---|
| 495 | return(""); |
---|
[61e79a9] | 496 | } |
---|
| 497 | |
---|
[7d4fbcd] | 498 | /* viewwin */ |
---|
| 499 | |
---|
| 500 | owl_viewwin *owl_global_get_viewwin(owl_global *g) { |
---|
[9eb38bb] | 501 | return g->vw; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | void owl_global_set_viewwin(owl_global *g, owl_viewwin *vw) { |
---|
| 505 | g->vw = vw; |
---|
[7d4fbcd] | 506 | } |
---|
| 507 | |
---|
| 508 | |
---|
| 509 | /* vert offset */ |
---|
| 510 | |
---|
[8742840] | 511 | int owl_global_get_curmsg_vert_offset(const owl_global *g) { |
---|
[7d4fbcd] | 512 | return(g->curmsg_vert_offset); |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | void owl_global_set_curmsg_vert_offset(owl_global *g, int i) { |
---|
[5b80b87] | 516 | g->curmsg_vert_offset = i; |
---|
[7d4fbcd] | 517 | } |
---|
| 518 | |
---|
| 519 | /* startup args */ |
---|
| 520 | |
---|
[e19eb97] | 521 | void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) { |
---|
[a8938c7] | 522 | int i, len; |
---|
| 523 | |
---|
| 524 | if (g->startupargs) owl_free(g->startupargs); |
---|
| 525 | |
---|
| 526 | len=0; |
---|
| 527 | for (i=0; i<argc; i++) { |
---|
[591e6aa7] | 528 | len+=strlen(argv[i])+5; |
---|
[a8938c7] | 529 | } |
---|
[34509d5] | 530 | g->startupargs=owl_malloc(len+5); |
---|
[7d4fbcd] | 531 | |
---|
| 532 | strcpy(g->startupargs, ""); |
---|
| 533 | for (i=0; i<argc; i++) { |
---|
[b9cb41b] | 534 | sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]); |
---|
[7d4fbcd] | 535 | } |
---|
| 536 | g->startupargs[strlen(g->startupargs)-1]='\0'; |
---|
| 537 | } |
---|
| 538 | |
---|
[8742840] | 539 | const char *owl_global_get_startupargs(const owl_global *g) { |
---|
[a8938c7] | 540 | if (g->startupargs) return(g->startupargs); |
---|
| 541 | return(""); |
---|
[7d4fbcd] | 542 | } |
---|
| 543 | |
---|
| 544 | /* history */ |
---|
| 545 | |
---|
[10b866d] | 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)); |
---|
[7d4fbcd] | 552 | } |
---|
| 553 | |
---|
| 554 | /* filterlist */ |
---|
[129e609] | 555 | typedef struct _owl_global_filter_ent { /* noproto */ |
---|
| 556 | owl_global *g; |
---|
| 557 | owl_filter *f; |
---|
| 558 | } owl_global_filter_ent; |
---|
[7d4fbcd] | 559 | |
---|
[8742840] | 560 | owl_filter *owl_global_get_filter(const owl_global *g, const char *name) { |
---|
[129e609] | 561 | owl_global_filter_ent *e = owl_dict_find_element(&(g->filters), name); |
---|
| 562 | if (e) return e->f; |
---|
| 563 | return NULL; |
---|
| 564 | } |
---|
[7d4fbcd] | 565 | |
---|
[5294cbf] | 566 | static void owl_global_delete_filter_ent(void *data) |
---|
| 567 | { |
---|
[129e609] | 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); |
---|
[7d4fbcd] | 572 | } |
---|
| 573 | |
---|
| 574 | void owl_global_add_filter(owl_global *g, owl_filter *f) { |
---|
[129e609] | 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), |
---|
[5294cbf] | 580 | e, owl_global_delete_filter_ent); |
---|
[129e609] | 581 | g->filterlist = g_list_append(g->filterlist, f); |
---|
[7d4fbcd] | 582 | } |
---|
| 583 | |
---|
[e19eb97] | 584 | void owl_global_remove_filter(owl_global *g, const char *name) { |
---|
[129e609] | 585 | owl_global_filter_ent *e = owl_dict_remove_element(&(g->filters), name); |
---|
| 586 | if (e) |
---|
[5294cbf] | 587 | owl_global_delete_filter_ent(e); |
---|
[7d4fbcd] | 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 | |
---|
[8742840] | 604 | int owl_global_get_hascolors(const owl_global *g) { |
---|
[7d4fbcd] | 605 | if (g->hascolors) return(1); |
---|
| 606 | return(0); |
---|
| 607 | } |
---|
| 608 | |
---|
| 609 | /* color pairs */ |
---|
| 610 | |
---|
[8742840] | 611 | int owl_global_get_colorpairs(const owl_global *g) { |
---|
[7d4fbcd] | 612 | return(g->colorpairs); |
---|
| 613 | } |
---|
| 614 | |
---|
[8fa9562] | 615 | owl_colorpair_mgr *owl_global_get_colorpair_mgr(owl_global *g) { |
---|
| 616 | return(&(g->cpmgr)); |
---|
| 617 | } |
---|
| 618 | |
---|
[7d4fbcd] | 619 | /* puntlist */ |
---|
| 620 | |
---|
| 621 | owl_list *owl_global_get_puntlist(owl_global *g) { |
---|
| 622 | return(&(g->puntlist)); |
---|
| 623 | } |
---|
| 624 | |
---|
[c08c70a] | 625 | int owl_global_message_is_puntable(owl_global *g, const owl_message *m) { |
---|
[77bced3] | 626 | const owl_list *pl; |
---|
[7d4fbcd] | 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) { |
---|
[9e5c9f3] | 638 | const owl_view *v; |
---|
[7d4fbcd] | 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 | } |
---|
[1fd0b25] | 647 | |
---|
[8742840] | 648 | int owl_global_is_search_active(const owl_global *g) { |
---|
[41c9a96] | 649 | if (owl_regex_is_set(&g->search_re)) return(1); |
---|
[1fd0b25] | 650 | return(0); |
---|
| 651 | } |
---|
| 652 | |
---|
[89b2daf] | 653 | void owl_global_set_search_re(owl_global *g, const owl_regex *re) { |
---|
[41c9a96] | 654 | if (owl_regex_is_set(&g->search_re)) { |
---|
[5cbc929] | 655 | owl_regex_cleanup(&g->search_re); |
---|
[41c9a96] | 656 | owl_regex_init(&g->search_re); |
---|
| 657 | } |
---|
| 658 | if (re != NULL) |
---|
| 659 | owl_regex_copy(re, &g->search_re); |
---|
[5b68c05] | 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)); |
---|
[1fd0b25] | 663 | } |
---|
| 664 | |
---|
[8742840] | 665 | const owl_regex *owl_global_get_search_re(const owl_global *g) { |
---|
[41c9a96] | 666 | return &g->search_re; |
---|
[1fd0b25] | 667 | } |
---|
[700c712] | 668 | |
---|
[0e5afa2] | 669 | void owl_global_set_newmsgproc_pid(owl_global *g, pid_t i) { |
---|
[700c712] | 670 | g->newmsgproc_pid=i; |
---|
| 671 | } |
---|
| 672 | |
---|
[0e5afa2] | 673 | pid_t owl_global_get_newmsgproc_pid(const owl_global *g) { |
---|
[700c712] | 674 | return(g->newmsgproc_pid); |
---|
| 675 | } |
---|
| 676 | |
---|
[d09e5a1] | 677 | /* AIM stuff */ |
---|
| 678 | |
---|
[8742840] | 679 | int owl_global_is_aimloggedin(const owl_global *g) |
---|
[6a415e9] | 680 | { |
---|
[d09e5a1] | 681 | if (g->aim_loggedin) return(1); |
---|
| 682 | return(0); |
---|
| 683 | } |
---|
| 684 | |
---|
[8742840] | 685 | const char *owl_global_get_aim_screenname(const owl_global *g) |
---|
[6a415e9] | 686 | { |
---|
[a352335c] | 687 | if (owl_global_is_aimloggedin(g)) { |
---|
| 688 | return (g->aim_screenname); |
---|
| 689 | } |
---|
| 690 | return(""); |
---|
[d09e5a1] | 691 | } |
---|
| 692 | |
---|
[8742840] | 693 | const char *owl_global_get_aim_screenname_for_filters(const owl_global *g) |
---|
[81655f8] | 694 | { |
---|
| 695 | if (owl_global_is_aimloggedin(g)) { |
---|
| 696 | return (g->aim_screenname_for_filters); |
---|
| 697 | } |
---|
| 698 | return(""); |
---|
| 699 | } |
---|
| 700 | |
---|
[e19eb97] | 701 | void owl_global_set_aimloggedin(owl_global *g, const char *screenname) |
---|
[6a415e9] | 702 | { |
---|
[65b2173] | 703 | char *sn_escaped; |
---|
[e19eb97] | 704 | const char *quote; |
---|
[d09e5a1] | 705 | g->aim_loggedin=1; |
---|
| 706 | if (g->aim_screenname) owl_free(g->aim_screenname); |
---|
[81655f8] | 707 | if (g->aim_screenname_for_filters) owl_free(g->aim_screenname_for_filters); |
---|
[d09e5a1] | 708 | g->aim_screenname=owl_strdup(screenname); |
---|
[81655f8] | 709 | sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
| 710 | quote = owl_getquoting(sn_escaped); |
---|
[9f4e3f8] | 711 | g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote); |
---|
[81655f8] | 712 | owl_free(sn_escaped); |
---|
[d09e5a1] | 713 | } |
---|
| 714 | |
---|
[6a415e9] | 715 | void owl_global_set_aimnologgedin(owl_global *g) |
---|
| 716 | { |
---|
[d09e5a1] | 717 | g->aim_loggedin=0; |
---|
| 718 | } |
---|
| 719 | |
---|
[8742840] | 720 | int owl_global_is_doaimevents(const owl_global *g) |
---|
[a352335c] | 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 | |
---|
[6a415e9] | 736 | aim_session_t *owl_global_get_aimsess(owl_global *g) |
---|
| 737 | { |
---|
[d09e5a1] | 738 | return(&(g->aimsess)); |
---|
| 739 | } |
---|
| 740 | |
---|
[c15bbfb] | 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) |
---|
[6a415e9] | 747 | { |
---|
[c15bbfb] | 748 | g->bosconn=*conn; |
---|
[d09e5a1] | 749 | } |
---|
| 750 | |
---|
| 751 | /* message queue */ |
---|
| 752 | |
---|
[6a415e9] | 753 | void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m) |
---|
| 754 | { |
---|
[20aced3] | 755 | g_queue_push_tail(g->messagequeue, m); |
---|
[d09e5a1] | 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 | */ |
---|
[13a3c1db] | 762 | owl_message *owl_global_messagequeue_popmsg(owl_global *g) |
---|
[6a415e9] | 763 | { |
---|
[d09e5a1] | 764 | owl_message *out; |
---|
| 765 | |
---|
[20aced3] | 766 | if (g_queue_is_empty(g->messagequeue)) |
---|
| 767 | return NULL; |
---|
| 768 | out = g_queue_pop_head(g->messagequeue); |
---|
| 769 | return out; |
---|
[d09e5a1] | 770 | } |
---|
| 771 | |
---|
[6a415e9] | 772 | int owl_global_messagequeue_pending(owl_global *g) |
---|
| 773 | { |
---|
[20aced3] | 774 | return !g_queue_is_empty(g->messagequeue); |
---|
[d09e5a1] | 775 | } |
---|
[aa5f725] | 776 | |
---|
[6a415e9] | 777 | owl_buddylist *owl_global_get_buddylist(owl_global *g) |
---|
| 778 | { |
---|
[aa5f725] | 779 | return(&(g->buddylist)); |
---|
| 780 | } |
---|
| 781 | |
---|
[bd3f232] | 782 | /* style */ |
---|
| 783 | |
---|
| 784 | /* Return the style with name 'name'. If it does not exist return |
---|
| 785 | * NULL */ |
---|
[8742840] | 786 | const owl_style *owl_global_get_style_by_name(const owl_global *g, const char *name) |
---|
[bd3f232] | 787 | { |
---|
[f1e629d] | 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. */ |
---|
[8742840] | 793 | int owl_global_get_style_names(const owl_global *g, owl_list *l) { |
---|
[f1e629d] | 794 | return owl_dict_get_keys(&(g->styledict), l); |
---|
[bd3f232] | 795 | } |
---|
| 796 | |
---|
[cf83b7a] | 797 | void owl_global_add_style(owl_global *g, owl_style *s) |
---|
| 798 | { |
---|
[f1fc47f] | 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), |
---|
[516c27e] | 808 | s, (void (*)(void *))owl_style_delete); |
---|
[bd3f232] | 809 | } |
---|
[cf83b7a] | 810 | |
---|
[09489b89] | 811 | void owl_global_set_haveaim(owl_global *g) |
---|
| 812 | { |
---|
| 813 | g->haveaim=1; |
---|
| 814 | } |
---|
| 815 | |
---|
[8742840] | 816 | int owl_global_is_haveaim(const owl_global *g) |
---|
[09489b89] | 817 | { |
---|
| 818 | if (g->haveaim) return(1); |
---|
| 819 | return(0); |
---|
| 820 | } |
---|
| 821 | |
---|
[b7bb454] | 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 | |
---|
[8742840] | 832 | int owl_global_is_ignore_aimlogin(const owl_global *g) |
---|
[b7bb454] | 833 | { |
---|
| 834 | return g->ignoreaimlogin; |
---|
| 835 | } |
---|
| 836 | |
---|
[09489b89] | 837 | void owl_global_set_havezephyr(owl_global *g) |
---|
| 838 | { |
---|
| 839 | g->havezephyr=1; |
---|
| 840 | } |
---|
| 841 | |
---|
[8742840] | 842 | int owl_global_is_havezephyr(const owl_global *g) |
---|
[09489b89] | 843 | { |
---|
| 844 | if (g->havezephyr) return(1); |
---|
| 845 | return(0); |
---|
| 846 | } |
---|
[de03334] | 847 | |
---|
[ec6ff52] | 848 | owl_errqueue *owl_global_get_errqueue(owl_global *g) |
---|
| 849 | { |
---|
| 850 | return(&(g->errqueue)); |
---|
| 851 | } |
---|
[c9e72d1] | 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 { |
---|
[7892963] | 859 | siginfo_t si; |
---|
| 860 | memset(&si, 0, sizeof(si)); |
---|
| 861 | g->err_signal_info = si; |
---|
[c9e72d1] | 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 | |
---|
[5a95b69] | 876 | |
---|
| 877 | owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g) |
---|
| 878 | { |
---|
| 879 | return(&(g->zbuddies)); |
---|
| 880 | } |
---|
[8232149] | 881 | |
---|
[f25812b] | 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 | |
---|
[8232149] | 897 | struct termios *owl_global_get_startup_tio(owl_global *g) |
---|
| 898 | { |
---|
| 899 | return(&(g->startup_tio)); |
---|
| 900 | } |
---|
[8e401cae] | 901 | |
---|
[df0138f] | 902 | owl_list *owl_global_get_io_dispatch_list(owl_global *g) |
---|
| 903 | { |
---|
| 904 | return &(g->io_dispatch_list); |
---|
| 905 | } |
---|
| 906 | |
---|
[4f2166b] | 907 | owl_list *owl_global_get_psa_list(owl_global *g) |
---|
| 908 | { |
---|
| 909 | return &(g->psa_list); |
---|
| 910 | } |
---|
| 911 | |
---|
[58d1f8a] | 912 | GList **owl_global_get_timerlist(owl_global *g) |
---|
[b7bb454] | 913 | { |
---|
[58d1f8a] | 914 | return &(g->timerlist); |
---|
[b7bb454] | 915 | } |
---|
[adee9cc] | 916 | |
---|
[8742840] | 917 | int owl_global_is_interrupted(const owl_global *g) { |
---|
[0cb6c26] | 918 | return g->interrupted; |
---|
[adee9cc] | 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 | } |
---|
[04b16f8] | 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", |
---|
[efc460e] | 937 | "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message ) )" }, |
---|
[04b16f8] | 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 | } |
---|
[d12a8c7] | 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)) { |
---|
[26ad412] | 965 | char *path; |
---|
[50522b5] | 966 | int fd; |
---|
| 967 | |
---|
[d12a8c7] | 968 | if (g->debug_file) |
---|
| 969 | fclose(g->debug_file); |
---|
[50522b5] | 970 | |
---|
| 971 | g->debug_file = NULL; |
---|
| 972 | |
---|
[26ad412] | 973 | path = owl_sprintf("%s.%d", filename, getpid()); |
---|
| 974 | fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600); |
---|
| 975 | owl_free(path); |
---|
| 976 | |
---|
[50522b5] | 977 | if (fd >= 0) |
---|
| 978 | g->debug_file = fdopen(fd, "a"); |
---|
[d12a8c7] | 979 | |
---|
| 980 | owl_free(open_file); |
---|
| 981 | open_file = owl_strdup(filename); |
---|
| 982 | } |
---|
| 983 | return g->debug_file; |
---|
| 984 | } |
---|