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