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