static void wr_command_load(wi_array_t *arguments) { wi_mutable_string_t *path; wi_file_t *file; path = wi_user_home(); path = wi_string_by_appending_path_component(path, WI_STR(WB_WIREBOT_USER_PATH)); path = wi_string_by_appending_path_component(path, WI_ARRAY(arguments, 0)); file = wi_file_for_reading(path); if(file) wr_commands_parse_file(file); else wr_printf_prefix(WI_STR("load: %@: %m"), path); }
static void wr_command_save(wi_array_t *arguments) { wi_file_t *file; wi_string_t *path, *login, *password, *port; path = wi_user_home(); path = wi_string_by_appending_path_component(path, WI_STR(WB_WIREBOT_USER_PATH)); path = wi_string_by_appending_path_component(path, WI_ARRAY(arguments, 0)); file = wi_file_for_writing(path); if(!file) { wr_printf_prefix(WI_STR("save: %@: %m"), path); return; } wi_file_write_format(file, WI_STR("charset %@\n"), wi_string_encoding_charset(wr_client_string_encoding)); wi_file_write_format(file, WI_STR("timestamp %@\n"), wr_timestamp_format); wi_file_write_format(file, WI_STR("nick %@\n"), wr_nick); if(wi_string_length(wr_status) > 0) wi_file_write_format(file, WI_STR("status %@\n"), wr_status); if(wr_icon_path) wi_file_write_format(file, WI_STR("icon %@\n"), wr_icon_path); if(wr_connected) { if(wi_string_length(wi_p7_socket_user_name(wr_p7_socket)) > 0) login = wi_string_with_format(WI_STR("-l %@"), wi_p7_socket_user_name(wr_p7_socket)); else login = NULL; if(wi_string_length(wr_password) > 0) password = wi_string_with_format(WI_STR("-p %@"), wr_password); else password = NULL; if(wi_address_port(wi_socket_address(wr_socket)) != WR_PORT) port = wi_string_with_format(WI_STR("-P %u"), wi_address_port(wi_socket_address(wr_socket))); else port = NULL; wi_file_write_format(file, WI_STR("open %#@ %#@ %#@ %@\n"), login, password, port, wi_address_string(wi_socket_address(wr_socket))); } wr_printf_prefix(WI_STR("save: \"%@\" saved"), path); }
static void wr_command_log(wi_array_t *arguments) { wi_mutable_string_t *string; wi_string_t *path; path = wi_user_home(); path = wi_string_by_appending_path_component(path, WI_ARRAY(arguments, 0)); string = wi_mutable_copy(wi_terminal_buffer_string(wr_window_buffer(wr_current_window))); wi_mutable_string_append_string(string, WI_STR("\n")); if(!wi_string_write_to_file(string, path)) wr_printf_prefix(WI_STR("log: %@: %m"), path); else wr_printf_prefix(WI_STR("log: \"%@\" saved"), path); wi_release(string); }
void wi_test_system(void) { wi_array_t *backtrace; WI_TEST_ASSERT_TRUE(wi_user_id() >= 0, ""); WI_TEST_ASSERT_TRUE(wi_string_length(wi_user_name()) > 0, ""); WI_TEST_ASSERT_TRUE(wi_string_length(wi_user_home()) > 0, ""); WI_TEST_ASSERT_TRUE(wi_group_id() >= 0, ""); WI_TEST_ASSERT_TRUE(wi_string_length(wi_group_name()) > 0, ""); WI_TEST_ASSERT_TRUE(wi_page_size() > 0, ""); backtrace = wi_backtrace(); if(backtrace) { WI_TEST_ASSERT_TRUE(wi_array_count(backtrace) > 0, ""); WI_TEST_ASSERT_NOT_EQUALS(wi_string_index_of_string(wi_array_components_joined_by_string(backtrace, WI_STR("\n")), WI_STR("test"), 0), WI_NOT_FOUND, ""); } WI_TEST_ASSERT_TRUE(wi_string_length(wi_getenv(WI_STR("HOME"))) > 0, ""); }
int main(int argc, const char **argv) { wi_pool_t *pool; wi_string_t *homepath, *wirepath, *path, *component; wi_file_t *file; int ch; /* init libwired */ wi_initialize(); wi_load(argc, argv); pool = wi_pool_init(wi_pool_alloc()); wi_log_callback = wr_wi_log_callback; /* init core systems */ wr_version_init(); wr_start_date = wi_date_init(wi_date_alloc()); /* set defaults */ wr_nick = wi_retain(wi_user_name()); homepath = wi_user_home(); wr_timestamp_format = wi_retain(WI_STR("%H:%M")); /* parse command line switches */ while((ch = getopt(argc, (char * const *) argv, "DhVv")) != -1) { switch(ch) { case 'D': wr_debug = true; wi_log_level = WI_LOG_DEBUG; wi_log_file = true; wi_log_path = WI_STR("wire.out"); wi_log_callback = NULL; break; case 'V': case 'v': wr_version(); break; case '?': case 'h': default: wr_usage(); break; } } argc -= optind; argv += optind; /* open log */ wi_log_open(); /* create ~/.wire */ wirepath = wi_string_by_appending_path_component(homepath, WI_STR(WR_WIRE_PATH)); wi_file_create_directory(wirepath, 0700); /* init subsystems */ wr_signals_init(); wr_terminal_init(); wr_readline_init(); wr_chats_init(); wr_windows_init(); wr_client_init(); wr_runloop_init(); wr_users_init(); wr_ignores_init(); wr_files_init(); wr_transfers_init(); wr_servers_init(); /* open default settings */ path = wi_string_by_appending_path_component(homepath, WI_STR(WR_WIRE_CONFIG_PATH)); file = wi_file_for_reading(path); if(file) wr_parse_file(file); else wr_printf_prefix(WI_STR("%@: %m"), path); /* read specified bookmark */ if(*argv) { component = wi_string_with_cstring(*argv); path = wi_string_by_appending_path_component(wirepath, component); file = wi_file_for_reading(path); if(file) wr_parse_file(file); else wr_printf_prefix(WI_STR("%@: %m"), path); } /* clean up pool after startup */ wi_pool_drain(pool); /* enter event loop */ wr_runloop_run(); /* clean up */ wr_cleanup(); wi_release(pool); return 0; }
void wr_client_reload_icon(void) { wi_data_t *data; wi_string_t *icon_path; if(wr_icon) wi_release(wr_icon), wr_icon = NULL; if(wr_icon_path) wi_release(wr_icon_path), wr_icon_path = NULL; icon_path = wi_config_path_for_name(wd_config, WI_STR("icon path")); if(!wi_string_has_prefix(icon_path, WI_STR("/"))) wr_icon_path = wi_retain(wi_string_by_appending_path_component(wi_string_by_appending_path_component(wi_user_home(), WI_STR(".wirebot")), icon_path)); else { wr_icon_path = wi_retain(icon_path); } if(wi_fs_path_exists(wr_icon_path, false)) { wr_icon = wi_data_init_with_contents_of_file(wi_data_alloc(), wr_icon_path); } else { wr_icon = wi_data_init_with_base64(wi_data_alloc(), wi_string_with_cstring(wr_default_icon)); } }