void owl_global_init(owl_global *g) { char *cd; const char *homedir; #if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif #if !GLIB_CHECK_VERSION(2, 31, 0) g_thread_init(NULL); #endif owl_select_init(); g->lines=LINES; g->cols=COLS; /* We shouldn't need this if we initialize lines and cols before the first * owl_window_get_screen, but to be safe, we synchronize. */ owl_window_resize(owl_window_get_screen(), g->lines, g->cols); g->context_stack = NULL; owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL); g->curmsg=0; g->topmsg=0; g->markedmsgid=-1; g->startupargs=NULL; owl_variable_dict_setup(&(g->vars)); g->rightshift=0; g->pw = NULL; g->vw = NULL; g->tw = NULL; owl_keyhandler_init(&g->kh); owl_keys_setup_keymaps(&g->kh); owl_dict_create(&(g->filters)); g->filterlist = NULL; g->puntlist = g_ptr_array_new(); g->messagequeue = g_queue_new(); owl_dict_create(&(g->styledict)); g->curmsg_vert_offset=0; g->resizepending=0; g->direction=OWL_DIRECTION_DOWNWARDS; owl_fmtext_init_colorpair_mgr(&(g->cpmgr)); g->debug=OWL_DEBUG; owl_regex_init(&g->search_re); g->starttime=time(NULL); /* assumes we call init only a start time */ g->lastinputtime=g->starttime; g->newmsgproc_pid=0; owl_global_set_config_format(g, 0); owl_global_set_no_have_config(g); owl_history_init(&(g->msghist)); owl_history_init(&(g->cmdhist)); g->nextmsgid=0; /* Fill in some variables which don't have constant defaults */ /* glib's g_get_home_dir prefers passwd entries to $HOME, so we * explicitly check getenv first. */ homedir = getenv("HOME"); if (!homedir) homedir = g_get_home_dir(); g->homedir = g_strdup(homedir); g->confdir = NULL; g->startupfile = NULL; cd = g_build_filename(g->homedir, OWL_CONFIG_DIR, NULL); owl_global_set_confdir(g, cd); g_free(cd); g->msglist = owl_messagelist_new(); _owl_global_init_windows(g); g->aim_screenname=NULL; g->aim_screenname_for_filters=NULL; g->aim_loggedin=0; owl_buddylist_init(&(g->buddylist)); g->havezephyr=0; g->haveaim=0; g->ignoreaimlogin=0; owl_global_set_no_doaimevents(g); owl_errqueue_init(&(g->errqueue)); owl_zbuddylist_create(&(g->zbuddies)); g->zaldlist = NULL; g->pseudologin_notify = 0; owl_message_init_fmtext_cache(); g->kill_buffer = NULL; g->interrupt_count = 0; #if GLIB_CHECK_VERSION(2, 31, 0) g_mutex_init(&g->interrupt_lock); #else g->interrupt_lock = g_mutex_new(); #endif }
int main(int argc, char **argv, char **env) { int argc_copy; char **argv_copy; char *perlout, *perlerr; const owl_style *s; const char *dir; owl_options opts; GSource *source; if (!GLIB_CHECK_VERSION (2, 12, 0)) g_error ("GLib version 2.12.0 or above is needed."); argc_copy = argc; argv_copy = g_strdupv(argv); setlocale(LC_ALL, ""); memset(&opts, 0, sizeof opts); opts.load_initial_subs = 1; owl_parse_options(argc, argv, &opts); g.load_initial_subs = opts.load_initial_subs; owl_start_curses(); /* owl global init */ owl_global_init(&g); if (opts.debug) owl_global_set_debug_on(&g); if (opts.confdir) owl_global_set_confdir(&g, opts.confdir); owl_function_debugmsg("startup: first available debugging message"); owl_global_set_startupargs(&g, argc_copy, argv_copy); g_strfreev(argv_copy); owl_global_set_haveaim(&g); owl_register_signal_handlers(); /* register STDIN dispatch; throw away return, we won't need it */ owl_select_add_io_dispatch(STDIN_FILENO, OWL_IO_READ, &owl_process_input, NULL, NULL); owl_zephyr_initialize(); #if OWL_STDERR_REDIR /* Do this only after we've started curses up... */ owl_function_debugmsg("startup: doing stderr redirection"); owl_select_add_io_dispatch(stderr_replace(), OWL_IO_READ, &stderr_redirect_handler, NULL, NULL); #endif /* create the owl directory, in case it does not exist */ owl_function_debugmsg("startup: creating owl directory, if not present"); dir=owl_global_get_confdir(&g); mkdir(dir, S_IRWXU); /* set the tty, either from the command line, or by figuring it out */ owl_function_debugmsg("startup: setting tty name"); if (opts.tty) { owl_global_set_tty(&g, opts.tty); } else { char *tty = owl_util_get_default_tty(); owl_global_set_tty(&g, tty); g_free(tty); } /* Initialize perl */ owl_function_debugmsg("startup: processing config file"); owl_global_pop_context(&g); owl_global_push_context(&g, OWL_CTX_READCONFIG, NULL, NULL, NULL); perlerr=owl_perlconfig_initperl(opts.configfile, &argc, &argv, &env); if (perlerr) { endwin(); fprintf(stderr, "Internal perl error: %s\n", perlerr); fflush(stderr); printf("Internal perl error: %s\n", perlerr); fflush(stdout); exit(1); } owl_global_complete_setup(&g); owl_global_setup_default_filters(&g); /* set the current view */ owl_function_debugmsg("startup: setting the current view"); owl_view_create(owl_global_get_current_view(&g), "main", owl_global_get_filter(&g, "all"), owl_global_get_style_by_name(&g, "default")); /* AIM init */ owl_function_debugmsg("startup: doing AIM initialization"); owl_aim_init(); /* execute the startup function in the configfile */ owl_function_debugmsg("startup: executing perl startup, if applicable"); perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();"); g_free(perlout); /* welcome message */ owl_function_debugmsg("startup: creating splash message"); owl_function_adminmsg("", "-----------------------------------------------------------------------\n" "Welcome to barnowl version " OWL_VERSION_STRING ".\n" "To see a quick introduction, type ':show quickstart'. \n" "Press 'h' for on-line help. \n" " \n" "BarnOwl is free software. Type ':show license' for more \n" "information. ^ ^ \n" " OvO \n" "Please report any bugs or suggestions to [email protected] ( ) \n" "-----------------------------------------------------------------m-m---\n" ); /* process the startup file */ owl_function_debugmsg("startup: processing startup file"); owl_function_source(NULL); owl_function_debugmsg("startup: set style for the view: %s", owl_global_get_default_style(&g)); s = owl_global_get_style_by_name(&g, owl_global_get_default_style(&g)); if(s) owl_view_set_style(owl_global_get_current_view(&g), s); else owl_function_error("No such style: %s", owl_global_get_default_style(&g)); owl_function_debugmsg("startup: setting context interactive"); owl_global_pop_context(&g); owl_global_push_context(&g, OWL_CTX_INTERACTIVE|OWL_CTX_RECV, NULL, "recv", NULL); source = owl_window_redraw_source_new(); g_source_attach(source, NULL); g_source_unref(source); source = g_source_new(&owl_process_messages_funcs, sizeof(GSource)); g_source_attach(source, NULL); g_source_unref(source); owl_log_init(); owl_function_debugmsg("startup: entering main loop"); owl_select_run_loop(); /* Shut down everything. */ owl_zephyr_shutdown(); owl_signal_shutdown(); owl_shutdown_curses(); owl_log_shutdown(); return 0; }