const char * version_get_version_with_git () { const char *git_version; static char version[256]; git_version = version_get_git (); snprintf (version, sizeof (version), "%s%s%s%s", version_get_version (), (git_version && git_version[0]) ? " (git: " : "", (git_version && git_version[0]) ? git_version : "", (git_version && git_version[0]) ? ")" : ""); return version; }
void gui_main_init () { struct t_gui_buffer *ptr_buffer; struct t_gui_bar *ptr_bar; struct t_gui_bar_window *ptr_bar_win; char title[256]; initscr (); if (CONFIG_BOOLEAN(config_look_eat_newline_glitch)) gui_term_set_eat_newline_glitch (0); curs_set (1); noecho (); nodelay (stdscr, TRUE); raw (); gui_color_init (); /* build prefixes according to configuration */ gui_chat_prefix_build (); refresh (); gui_term_cols = COLS; gui_term_lines = LINES; gui_window_read_terminal_size (); /* init clipboard buffer */ gui_input_clipboard = NULL; /* get time length */ gui_chat_time_length = gui_chat_get_time_length (); /* init bar items */ gui_bar_item_init (); gui_init_ok = 0; /* create core buffer */ ptr_buffer = gui_buffer_new (NULL, GUI_BUFFER_MAIN, NULL, NULL, NULL, NULL); if (ptr_buffer) { gui_init_ok = 1; ptr_buffer->num_displayed = 1; /* set short name */ if (!ptr_buffer->short_name) ptr_buffer->short_name = strdup (GUI_BUFFER_MAIN); /* set title for core buffer */ snprintf (title, sizeof (title), "WeeChat %s %s - %s", version_get_version (), WEECHAT_COPYRIGHT_DATE, WEECHAT_WEBSITE); gui_buffer_set_title (ptr_buffer, title); /* create main window (using full space) */ if (gui_window_new (NULL, ptr_buffer, 0, 0, gui_term_cols, gui_term_lines, 100, 100)) { gui_current_window = gui_windows; if (CONFIG_STRING(config_look_window_title) && CONFIG_STRING(config_look_window_title)[0]) { gui_window_set_title (CONFIG_STRING(config_look_window_title)); } } /* * create bar windows for root bars (they were read from config, * but no window was created, GUI was not initialized) */ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) { if ((CONFIG_INTEGER(ptr_bar->options[GUI_BAR_OPTION_TYPE]) == GUI_BAR_TYPE_ROOT) && (!ptr_bar->bar_window)) { gui_bar_window_new (ptr_bar, NULL); } } for (ptr_bar_win = gui_windows->bar_windows; ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window) { gui_bar_window_calculate_pos_size (ptr_bar_win, gui_windows); gui_bar_window_create_win (ptr_bar_win); } } if (CONFIG_BOOLEAN(config_look_mouse)) gui_mouse_enable (); else gui_mouse_disable (); gui_window_set_bracketed_paste_mode (CONFIG_BOOLEAN(config_look_paste_bracketed)); }
const char * plugin_api_info_get_internal (void *data, const char *info_name, const char *arguments) { time_t inactivity; static char value[32], version_number[32] = { '\0' }; static char weechat_dir_absolute_path[PATH_MAX] = { '\0' }; int rgb, limit; char *pos, *color; /* make C compiler happy */ (void) data; if (!info_name) return NULL; if (string_strcasecmp (info_name, "version") == 0) { return version_get_version (); } else if (string_strcasecmp (info_name, "version_number") == 0) { if (!version_number[0]) { snprintf (version_number, sizeof (version_number), "%d", util_version_number (version_get_version ())); } return version_number; } else if (string_strcasecmp (info_name, "version_git") == 0) { return version_get_git (); } else if (string_strcasecmp (info_name, "date") == 0) { return version_get_compilation_date (); } else if (string_strcasecmp (info_name, "dir_separator") == 0) { return DIR_SEPARATOR; } else if (string_strcasecmp (info_name, "weechat_dir") == 0) { if (!weechat_dir_absolute_path[0]) { if (!realpath (weechat_home, weechat_dir_absolute_path)) return NULL; } return (weechat_dir_absolute_path[0]) ? weechat_dir_absolute_path : weechat_home; } else if (string_strcasecmp (info_name, "weechat_libdir") == 0) { return WEECHAT_LIBDIR; } else if (string_strcasecmp (info_name, "weechat_sharedir") == 0) { return WEECHAT_SHAREDIR; } else if (string_strcasecmp (info_name, "weechat_localedir") == 0) { return LOCALEDIR; } else if (string_strcasecmp (info_name, "weechat_site") == 0) { return WEECHAT_WEBSITE; } else if (string_strcasecmp (info_name, "weechat_site_download") == 0) { return WEECHAT_WEBSITE_DOWNLOAD; } else if (string_strcasecmp (info_name, "weechat_upgrading") == 0) { snprintf (value, sizeof (value), "%d", weechat_upgrading); return value; } else if (string_strcasecmp (info_name, "charset_terminal") == 0) { return weechat_local_charset; } else if (string_strcasecmp (info_name, "charset_internal") == 0) { return WEECHAT_INTERNAL_CHARSET; } else if (string_strcasecmp (info_name, "locale") == 0) { return setlocale (LC_MESSAGES, NULL); } else if (string_strcasecmp (info_name, "inactivity") == 0) { if (gui_key_last_activity_time == 0) inactivity = 0; else inactivity = time (NULL) - gui_key_last_activity_time; snprintf (value, sizeof (value), "%ld", (long int)inactivity); return value; } else if (string_strcasecmp (info_name, "filters_enabled") == 0) { snprintf (value, sizeof (value), "%d", gui_filters_enabled); return value; } else if (string_strcasecmp (info_name, "cursor_mode") == 0) { snprintf (value, sizeof (value), "%d", gui_cursor_mode); return value; } else if (string_strcasecmp (info_name, "term_width") == 0) { snprintf (value, sizeof (value), "%d", gui_window_get_width ()); return value; } else if (string_strcasecmp (info_name, "term_height") == 0) { snprintf (value, sizeof (value), "%d", gui_window_get_height ()); return value; } else if (string_strcasecmp (info_name, "color_ansi_regex") == 0) { return GUI_COLOR_REGEX_ANSI_DECODE; } else if (string_strcasecmp (info_name, "color_term2rgb") == 0) { if (arguments && arguments[0]) { snprintf (value, sizeof (value), "%d", gui_color_convert_term_to_rgb (atoi (arguments))); return value; } } else if (string_strcasecmp (info_name, "color_rgb2term") == 0) { if (arguments && arguments[0]) { limit = 256; pos = strchr (arguments, ','); if (pos) { color = string_strndup (arguments, pos - arguments); if (!color) return NULL; rgb = atoi (color); limit = atoi (pos + 1); free (color); } else rgb = atoi (arguments); snprintf (value, sizeof (value), "%d", gui_color_convert_rgb_to_term (rgb, limit)); return value; } } /* info not found */ return NULL; }
void weechat_parse_args (int argc, char *argv[]) { int i; weechat_argv0 = (argv && argv[0]) ? strdup (argv[0]) : NULL; weechat_upgrading = 0; weechat_home = NULL; weechat_server_cmd_line = 0; weechat_auto_load_plugins = 1; weechat_plugin_no_dlclose = 0; for (i = 1; i < argc; i++) { if ((strcmp (argv[i], "-c") == 0) || (strcmp (argv[i], "--colors") == 0)) { gui_color_display_terminal_colors (); weechat_shutdown (EXIT_SUCCESS, 0); } else if ((strcmp (argv[i], "-d") == 0) || (strcmp (argv[i], "--dir") == 0)) { if (i + 1 < argc) weechat_home = strdup (argv[++i]); else { string_iconv_fprintf (stderr, _("Error: missing argument for \"%s\" " "option\n"), argv[i]); weechat_shutdown (EXIT_FAILURE, 0); } } else if ((strcmp (argv[i], "-h") == 0) || (strcmp (argv[i], "--help") == 0)) { weechat_display_usage (argv[0]); weechat_shutdown (EXIT_SUCCESS, 0); } else if ((strcmp (argv[i], "-l") == 0) || (strcmp (argv[i], "--license") == 0)) { weechat_display_copyright (); string_iconv_fprintf (stdout, "\n"); string_iconv_fprintf (stdout, "%s%s", WEECHAT_LICENSE_TEXT); weechat_shutdown (EXIT_SUCCESS, 0); } else if (strcmp (argv[i], "--no-dlclose") == 0) { /* * Valgrind works better when dlclose() is not done after plugins * are unloaded, it can display stack for plugins,* otherwise * you'll see "???" in stack for functions of unloaded plugins. * This option disables the call to dlclose(), * it must NOT be used for other purposes! */ weechat_plugin_no_dlclose = 1; } else if (strcmp (argv[i], "--no-gnutls") == 0) { /* * Electric-fence is not working fine when gnutls loads * certificates and Valgrind reports many memory errors with gnutls. * This option disables the init/deinit of gnutls, * it must NOT be used for other purposes! */ weechat_no_gnutls = 1; } else if (strcmp (argv[i], "--no-gcrypt") == 0) { /* * Valgrind reports many memory errors with gcrypt. * This option disables the init/deinit of gcrypt, * it must NOT be used for other purposes! */ weechat_no_gcrypt = 1; } else if ((strcmp (argv[i], "-p") == 0) || (strcmp (argv[i], "--no-plugin") == 0)) { weechat_auto_load_plugins = 0; } else if ((strcmp (argv[i], "-r") == 0) || (strcmp (argv[i], "--run-command") == 0)) { if (i + 1 < argc) weechat_startup_commands = strdup (argv[++i]); else { string_iconv_fprintf (stderr, _("Error: missing argument for \"%s\" " "option\n"), argv[i]); weechat_shutdown (EXIT_FAILURE, 0); } } else if (strcmp (argv[i], "--upgrade") == 0) { weechat_upgrading = 1; } else if ((strcmp (argv[i], "-v") == 0) || (strcmp (argv[i], "--version") == 0)) { string_iconv_fprintf (stdout, version_get_version ()); fprintf (stdout, "\n"); weechat_shutdown (EXIT_SUCCESS, 0); } } }
void version_test_get_version(void) { version_get_version(); CU_ASSERT(0 == 0); }
TEST(Eval, EvalExpression) { struct t_hashtable *pointers, *extra_vars, *options; struct t_config_option *ptr_option; char *value, str_value[256]; pointers = NULL; extra_vars = hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); CHECK(extra_vars); hashtable_set (extra_vars, "test", "value"); options = NULL; POINTERS_EQUAL(NULL, eval_expression (NULL, NULL, NULL, NULL)); /* test with simple strings */ WEE_CHECK_EVAL("", ""); WEE_CHECK_EVAL("a b c", "a b c"); WEE_CHECK_EVAL("$", "$"); WEE_CHECK_EVAL("", "${"); WEE_CHECK_EVAL("}", "}"); WEE_CHECK_EVAL("", "${}"); WEE_CHECK_EVAL("", "${xyz}"); /* test eval of substring */ WEE_CHECK_EVAL("\t", "${eval:${\\t}}"); /* test value from extra_vars */ WEE_CHECK_EVAL("value", "${test}"); /* test escaped chars */ WEE_CHECK_EVAL("\t", "${\\t}"); WEE_CHECK_EVAL("\t", "${esc:\t}"); /* test hidden chars */ WEE_CHECK_EVAL("********", "${hide:*,password}"); WEE_CHECK_EVAL("\u2603\u2603\u2603", "${hide:${esc:\u2603},abc}"); /* test color */ WEE_CHECK_EVAL(gui_color_get_custom ("green"), "${color:green}"); WEE_CHECK_EVAL(gui_color_get_custom ("*214"), "${color:*214}"); snprintf (str_value, sizeof (str_value), "%s-test-", gui_color_from_option (config_color_chat_delimiters)); WEE_CHECK_EVAL(str_value, "${color:chat_delimiters}-test-"); config_file_search_with_string ("irc.color.message_join", NULL, NULL, &ptr_option, NULL); if (!ptr_option) { FAIL("ERROR: option irc.color.message_join not found."); } snprintf (str_value, sizeof (str_value), "%s-test-", gui_color_from_option (ptr_option)); WEE_CHECK_EVAL(str_value, "${color:irc.color.message_join}-test-"); WEE_CHECK_EVAL("test", "${option.not.found}test"); /* test info */ WEE_CHECK_EVAL(version_get_version (), "${info:version}"); /* test date */ value = eval_expression ("${date}", pointers, extra_vars, options); LONGS_EQUAL(19, strlen (value)); free (value); value = eval_expression ("${date:%H:%M:%S}", pointers, extra_vars, options); LONGS_EQUAL(8, strlen (value)); free (value); /* test option */ snprintf (str_value, sizeof (str_value), "%d", CONFIG_INTEGER(config_look_scroll_amount)); WEE_CHECK_EVAL(str_value, "${weechat.look.scroll_amount}"); WEE_CHECK_EVAL(str_value, "${${window.buffer.name}.look.scroll_amount}"); /* test hdata */ WEE_CHECK_EVAL("x", "x${buffer.number"); WEE_CHECK_EVAL("x${buffer.number}1", "x\\${buffer.number}${buffer.number}"); WEE_CHECK_EVAL("1", "${buffer.number}"); WEE_CHECK_EVAL("1", "${window.buffer.number}"); WEE_CHECK_EVAL("core.weechat", "${buffer.full_name}"); WEE_CHECK_EVAL("core.weechat", "${window.buffer.full_name}"); hashtable_free (extra_vars); }