From 3799d2c2a5357429507dd4b24eeee256a60c599b Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Wed, 10 Feb 2010 11:21:25 +0100 Subject: [PATCH] Add "version_number" for API function weechat_info_get to get WeeChat version as number --- doc/en/autogen/plugin_api/infos.txt | 2 + doc/fr/autogen/plugin_api/infos.txt | 2 + doc/it/autogen/plugin_api/infos.txt | 2 + po/cs.po | 6 ++- po/de.po | 6 ++- po/es.po | 6 ++- po/fr.po | 7 +++- po/hu.po | 6 ++- po/it.po | 6 ++- po/pl.po | 6 ++- po/ru.po | 6 ++- po/weechat.pot | 5 ++- src/core/wee-util.c | 59 +++++++++++++++++++++++++++++ src/core/wee-util.h | 1 + src/plugins/plugin-api.c | 16 +++++++- 15 files changed, 124 insertions(+), 12 deletions(-) diff --git a/doc/en/autogen/plugin_api/infos.txt b/doc/en/autogen/plugin_api/infos.txt index 92d107eae..e1b883e2e 100644 --- a/doc/en/autogen/plugin_api/infos.txt +++ b/doc/en/autogen/plugin_api/infos.txt @@ -27,6 +27,8 @@ | weechat | version | WeeChat version +| weechat | version_number | WeeChat version (as number) + | weechat | weechat_dir | WeeChat directory | weechat | weechat_libdir | WeeChat "lib" directory diff --git a/doc/fr/autogen/plugin_api/infos.txt b/doc/fr/autogen/plugin_api/infos.txt index f547d9080..6d96ace99 100644 --- a/doc/fr/autogen/plugin_api/infos.txt +++ b/doc/fr/autogen/plugin_api/infos.txt @@ -27,6 +27,8 @@ | weechat | version | version de WeeChat +| weechat | version_number | version de WeeChat (sous forme de nombre) + | weechat | weechat_dir | répertoire de WeeChat | weechat | weechat_libdir | répertoire "lib" de WeeChat diff --git a/doc/it/autogen/plugin_api/infos.txt b/doc/it/autogen/plugin_api/infos.txt index 506983610..a8897b9b1 100644 --- a/doc/it/autogen/plugin_api/infos.txt +++ b/doc/it/autogen/plugin_api/infos.txt @@ -27,6 +27,8 @@ | weechat | version | versione di WeeChat +| weechat | version_number | WeeChat version (as number) + | weechat | weechat_dir | cartella WeeChat | weechat | weechat_libdir | cartella "lib" di WeeChat diff --git a/po/cs.po b/po/cs.po index 29fca076e..f2978bd04 100644 --- a/po/cs.po +++ b/po/cs.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-02-09 16:35+0100\n" +"POT-Creation-Date: 2010-02-10 10:33+0100\n" "PO-Revision-Date: 2010-01-23 11:56+0100\n" "Last-Translator: Jiri Golembiovsky \n" "Language-Team: weechat-dev \n" @@ -5083,6 +5083,10 @@ msgstr "seznam logovacích bufferů" msgid "WeeChat version" msgstr "verze WeeChat" +#, fuzzy +msgid "WeeChat version (as number)" +msgstr "verze WeeChat" + msgid "WeeChat compilation date" msgstr "datum kompilace WeeChat" diff --git a/po/de.po b/po/de.po index 1514f899c..69048ba4d 100644 --- a/po/de.po +++ b/po/de.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-02-09 16:35+0100\n" +"POT-Creation-Date: 2010-02-10 10:33+0100\n" "PO-Revision-Date: 2010-01-26 22:35+0100\n" "Last-Translator: Nils G \n" "Language-Team: weechat-dev \n" @@ -5277,6 +5277,10 @@ msgstr "Liste der protokollierten Buffer" msgid "WeeChat version" msgstr "WeeChat Version" +#, fuzzy +msgid "WeeChat version (as number)" +msgstr "WeeChat Version" + msgid "WeeChat compilation date" msgstr "Datum der WeeChat Kompilierung" diff --git a/po/es.po b/po/es.po index 25e337172..ec7f3c272 100644 --- a/po/es.po +++ b/po/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-02-09 16:35+0100\n" +"POT-Creation-Date: 2010-02-10 10:33+0100\n" "PO-Revision-Date: 2010-01-23 11:56+0100\n" "Last-Translator: Elián Hanisch \n" "Language-Team: weechat-dev \n" @@ -5185,6 +5185,10 @@ msgstr "lista de buffers con registro" msgid "WeeChat version" msgstr "versión de WeeChat" +#, fuzzy +msgid "WeeChat version (as number)" +msgstr "versión de WeeChat" + msgid "WeeChat compilation date" msgstr "fecha de compilación de WeeChat" diff --git a/po/fr.po b/po/fr.po index c559adbfe..53f17f9a9 100644 --- a/po/fr.po +++ b/po/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-02-09 16:35+0100\n" -"PO-Revision-Date: 2010-02-09 16:36+0100\n" +"POT-Creation-Date: 2010-02-10 10:33+0100\n" +"PO-Revision-Date: 2010-02-10 10:33+0100\n" "Last-Translator: FlashCode \n" "Language-Team: weechat-dev \n" "MIME-Version: 1.0\n" @@ -5227,6 +5227,9 @@ msgstr "liste des enregistreurs de tampons (loggers)" msgid "WeeChat version" msgstr "version de WeeChat" +msgid "WeeChat version (as number)" +msgstr "version de WeeChat (sous forme de nombre)" + msgid "WeeChat compilation date" msgstr "date de compilation de WeeChat" diff --git a/po/hu.po b/po/hu.po index d007faaf2..26fdd6147 100644 --- a/po/hu.po +++ b/po/hu.po @@ -12,7 +12,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-02-09 16:35+0100\n" +"POT-Creation-Date: 2010-02-10 10:33+0100\n" "PO-Revision-Date: 2010-01-23 11:57+0100\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -4971,6 +4971,10 @@ msgstr "a pufferek időbélyege" msgid "WeeChat version" msgstr "WeeChat szlogen" +#, fuzzy +msgid "WeeChat version (as number)" +msgstr "WeeChat szlogen" + #, fuzzy msgid "WeeChat compilation date" msgstr "Konfigurációs fájl elmentve\n" diff --git a/po/it.po b/po/it.po index da92aee57..d46121648 100644 --- a/po/it.po +++ b/po/it.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Weechat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-02-09 16:35+0100\n" +"POT-Creation-Date: 2010-02-10 10:33+0100\n" "PO-Revision-Date: 2010-01-23 11:57+0100\n" "Last-Translator: Marco Paolone \n" "Language-Team: weechat-dev \n" @@ -5178,6 +5178,10 @@ msgstr "elenco dei buffer logger" msgid "WeeChat version" msgstr "versione di WeeChat" +#, fuzzy +msgid "WeeChat version (as number)" +msgstr "versione di WeeChat" + msgid "WeeChat compilation date" msgstr "data di compilazione di WeeChat" diff --git a/po/pl.po b/po/pl.po index c829a95f5..4dde1e5d0 100644 --- a/po/pl.po +++ b/po/pl.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-02-09 16:35+0100\n" +"POT-Creation-Date: 2010-02-10 10:33+0100\n" "PO-Revision-Date: 2010-01-23 11:57+0100\n" "Last-Translator: Krzysztof Koroscik \n" "Language-Team: Polish\n" @@ -5152,6 +5152,10 @@ msgstr "lista logowanych buforów" msgid "WeeChat version" msgstr "wersja WeeChat" +#, fuzzy +msgid "WeeChat version (as number)" +msgstr "wersja WeeChat" + msgid "WeeChat compilation date" msgstr "data kompilacji WeeChat" diff --git a/po/ru.po b/po/ru.po index a12396c59..58d8870b0 100644 --- a/po/ru.po +++ b/po/ru.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.2-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-02-09 16:35+0100\n" +"POT-Creation-Date: 2010-02-10 10:33+0100\n" "PO-Revision-Date: 2010-01-23 11:57+0100\n" "Last-Translator: Pavel Shevchuk \n" "Language-Team: weechat-dev \n" @@ -4975,6 +4975,10 @@ msgstr "время в буферах" msgid "WeeChat version" msgstr "слоган WeeChat" +#, fuzzy +msgid "WeeChat version (as number)" +msgstr "слоган WeeChat" + #, fuzzy msgid "WeeChat compilation date" msgstr "Конфигурационный файл сохранён\n" diff --git a/po/weechat.pot b/po/weechat.pot index 6af76bfde..793e81920 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-02-09 16:35+0100\n" +"POT-Creation-Date: 2010-02-10 10:33+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -4306,6 +4306,9 @@ msgstr "" msgid "WeeChat version" msgstr "" +msgid "WeeChat version (as number)" +msgstr "" + msgid "WeeChat compilation date" msgstr "" diff --git a/src/core/wee-util.c b/src/core/wee-util.c index 82f565c13..e1bdc453d 100644 --- a/src/core/wee-util.c +++ b/src/core/wee-util.c @@ -38,6 +38,7 @@ #include "wee-util.h" #include "wee-config.h" #include "wee-string.h" +#include "wee-utf8.h" /* @@ -408,3 +409,61 @@ util_file_get_content (const char *filename) return buffer; } + +/* + * util_version_number: get version number (integer) with version as string + * (non-digit chars like "-dev" are ignored) + * for example: + * "0.3.2-dev" ==> 197120 (== 0x00030200) + * "0.3.2" ==> 197120 (== 0x00030200) + * "0.3.1.1" ==> 196865 (== 0x00030101) + * "0.3.1" ==> 196864 (== 0x00030100) + * "0.3.0" ==> 196608 (== 0x00030000) + */ + +int +util_version_number (const char *version) +{ + char **items, buf[64], *ptr_item, *error; + int num_items, i, version_int[4], index_buf; + long number; + + items = string_split (version, ".", 0, 4, &num_items); + for (i = 0; i < 4; i++) + { + version_int[i] = 0; + if (items && (i < num_items)) + { + ptr_item = items[i]; + index_buf = 0; + while (ptr_item && ptr_item[0] && (index_buf < (int)sizeof (buf) - 1)) + { + if (isdigit (ptr_item[0])) + { + buf[index_buf] = ptr_item[0]; + index_buf++; + } + ptr_item = utf8_next_char (ptr_item); + } + buf[index_buf] = '\0'; + if (buf[0]) + { + error = NULL; + number = strtol (buf, &error, 10); + if (error && !error[0]) + { + if (number < 0) + number = 0; + else if (number > 0xFF) + number = 0xFF; + version_int[i] = number; + } + } + } + } + if (items) + string_free_split (items); + + return (version_int[0] << 24) | (version_int[1] << 16) + | (version_int[2] << 8) | version_int[3]; +} diff --git a/src/core/wee-util.h b/src/core/wee-util.h index 5f74e15eb..6dab94619 100644 --- a/src/core/wee-util.h +++ b/src/core/wee-util.h @@ -36,4 +36,5 @@ extern void util_exec_on_files (const char *directory, int hidden_files, extern char *util_search_full_lib_name (const char *filename, const char *sys_directory); extern char *util_file_get_content (const char *filename); +extern int util_version_number (const char *version); #endif /* wee-util.h */ diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index af92863c0..77aa2844c 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -38,6 +38,7 @@ #include "../core/wee-infolist.h" #include "../core/wee-input.h" #include "../core/wee-string.h" +#include "../core/wee-util.h" #include "../gui/gui-bar.h" #include "../gui/gui-bar-item.h" #include "../gui/gui-bar-window.h" @@ -258,7 +259,7 @@ plugin_api_info_get_internal (void *data, const char *info_name, const char *arguments) { time_t inactivity; - static char value[32]; + static char value[32], version_number[32] = { '\0' }; /* make C compiler happy */ (void) data; @@ -271,7 +272,16 @@ plugin_api_info_get_internal (void *data, const char *info_name, { return PACKAGE_VERSION; } - if (string_strcasecmp (info_name, "date") == 0) + else if (string_strcasecmp (info_name, "version_number") == 0) + { + if (!version_number[0]) + { + snprintf (version_number, sizeof (version_number), "%d", + util_version_number (PACKAGE_VERSION)); + } + return version_number; + } + else if (string_strcasecmp (info_name, "date") == 0) { return __DATE__; } @@ -920,6 +930,8 @@ plugin_api_init () /* WeeChat core info hooks */ hook_info (NULL, "version", N_("WeeChat version"), &plugin_api_info_get_internal, NULL); + hook_info (NULL, "version_number", N_("WeeChat version (as number)"), + &plugin_api_info_get_internal, NULL); hook_info (NULL, "date", N_("WeeChat compilation date"), &plugin_api_info_get_internal, NULL); hook_info (NULL, "dir_separator", N_("directory separator"),