spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 8050f82afe39839eb02f15550ead4c0095f18783
parent 77ce3851d684f70c54135f6d28ba772100cd4cd6
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Tue, 28 Aug 2012 09:57:53 -0700

Proper version number comparison

Diffstat:
M.gitignore | 1+
Mlib/Makefile.am | 4+++-
Alib/spek-utils.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alib/spek-utils.h | 33+++++++++++++++++++++++++++++++++
Mpo/spek.pot | 52++++++++++++++++++++++++++--------------------------
Msrc/spek-window.cc | 4+++-
Mtests/Makefile.am | 6++++--
Atests/test-utils.c | 44++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 179 insertions(+), 30 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -38,6 +38,7 @@ samples/ src/*.stamp src/spek stamp-h1 +tests/test-utils tests/test web/version xmldocs.make diff --git a/lib/Makefile.am b/lib/Makefile.am @@ -8,7 +8,9 @@ libspek_a_SOURCES = \ spek-palette.c \ spek-palette.h \ spek-pipeline.c \ - spek-pipeline.h + spek-pipeline.h \ + spek-utils.c \ + spek-utils.h libspek_a_CPPFLAGS = \ -include config.h \ diff --git a/lib/spek-utils.c b/lib/spek-utils.c @@ -0,0 +1,65 @@ +/* spek-utils.c + * + * Copyright (C) 2012 Alexander Kojevnikov <alexander@kojevnikov.com> + * + * Spek is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Spek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Spek. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <assert.h> +#include <limits.h> +#include <stdlib.h> + +#include "spek-utils.h" + +int spek_vercmp(const char *a, const char *b) +{ + assert(a && b); + + if (!*a && !*b) { + return 0; + } + if (!*a) { + return -1; + } + if (!*b) { + return 1; + } + + char *i, *j; + while(1) { + i = j = NULL; + long x = strtol(a, &i, 10); + long y = strtol(b, &j, 10); + + if (x < y) { + return -1; + } + if (x > y) { + return 1; + } + + if (!*i && !*j) { + return 0; + } + if (!*i) { + return -1; + } + if (!*j) { + return 1; + } + + a = i + 1; + b = j + 1; + } +} diff --git a/lib/spek-utils.h b/lib/spek-utils.h @@ -0,0 +1,33 @@ +/* spek-utils.h + * + * Copyright (C) 2012 Alexander Kojevnikov <alexander@kojevnikov.com> + * + * Spek is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Spek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Spek. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SPEK_UTILS_H_ +#define SPEK_UTILS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// Compare version numbers, e.g. 1.9.2 < 1.10.0 +int spek_vercmp(const char *a, const char *b); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/po/spek.pot b/po/spek.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-08-27 21:55-0700\n" +"POT-Creation-Date: 2012-08-28 09:54-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -96,113 +96,113 @@ msgstr "" msgid "%s: %s" msgstr "" -#: ../src/spek-preferences-dialog.cc:62 +#: ../src/spek-preferences-dialog.cc:57 msgid "Preferences" msgstr "" -#: ../src/spek-preferences-dialog.cc:67 +#: ../src/spek-preferences-dialog.cc:62 msgid "(system default)" msgstr "" #. TRANSLATORS: The name of a section in the Preferences dialog. -#: ../src/spek-preferences-dialog.cc:74 +#: ../src/spek-preferences-dialog.cc:69 msgid "General" msgstr "" -#: ../src/spek-preferences-dialog.cc:82 +#: ../src/spek-preferences-dialog.cc:77 msgid "Language:" msgstr "" -#: ../src/spek-preferences-dialog.cc:97 +#: ../src/spek-preferences-dialog.cc:92 msgid "Check for &updates" msgstr "" -#: ../src/spek-spectrogram.cc:152 +#: ../src/spek-spectrogram.cc:153 #, c-format msgid "%d kHz" msgstr "" -#: ../src/spek-spectrogram.cc:157 +#: ../src/spek-spectrogram.cc:158 #, c-format msgid "%d dB" msgstr "" #. TRANSLATORS: keep "00" unchanged, it's used to calc the text width -#: ../src/spek-spectrogram.cc:259 +#: ../src/spek-spectrogram.cc:260 msgid "00 kHz" msgstr "" #. TRANSLATORS: keep "-00" unchanged, it's used to calc the text width -#: ../src/spek-spectrogram.cc:287 +#: ../src/spek-spectrogram.cc:288 msgid "-00 dB" msgstr "" -#: ../src/spek-window.cc:71 +#: ../src/spek-window.cc:73 msgid "Spek - Acoustic Spectrum Analyser" msgstr "" -#: ../src/spek-window.cc:85 +#: ../src/spek-window.cc:87 msgid "&File" msgstr "" -#: ../src/spek-window.cc:92 +#: ../src/spek-window.cc:94 msgid "&Edit" msgstr "" -#: ../src/spek-window.cc:99 +#: ../src/spek-window.cc:101 msgid "&Help" msgstr "" -#: ../src/spek-window.cc:126 +#: ../src/spek-window.cc:128 msgid "A new version of Spek is available, click to download." msgstr "" #. TRANSLATORS: window title, %s is replaced with the file name -#: ../src/spek-window.cc:165 +#: ../src/spek-window.cc:167 #, c-format msgid "Spek - %s" msgstr "" -#: ../src/spek-window.cc:212 +#: ../src/spek-window.cc:214 msgid "All files" msgstr "" -#: ../src/spek-window.cc:214 +#: ../src/spek-window.cc:216 msgid "Audio files" msgstr "" -#: ../src/spek-window.cc:228 +#: ../src/spek-window.cc:230 msgid "Open File" msgstr "" -#: ../src/spek-window.cc:250 +#: ../src/spek-window.cc:252 msgid "PNG images" msgstr "" -#: ../src/spek-window.cc:256 +#: ../src/spek-window.cc:258 msgid "Save Spectrogram" msgstr "" #. Suggested name is <file_name>.png -#: ../src/spek-window.cc:264 +#: ../src/spek-window.cc:266 msgid "Untitled" msgstr "" #. TRANSLATORS: Add your name here -#: ../src/spek-window.cc:301 +#: ../src/spek-window.cc:303 msgid "translator-credits" msgstr "" -#: ../src/spek-window.cc:307 +#: ../src/spek-window.cc:309 msgid "Copyright (c) 2010-2012 Alexander Kojevnikov and contributors" msgstr "" -#: ../src/spek-window.cc:310 +#: ../src/spek-window.cc:312 msgid "Spek Website" msgstr "" #. TRANSLATORS: the %s is the package version. -#: ../src/spek.cc:90 +#: ../src/spek.cc:91 #, c-format msgid "Spek version %s" msgstr "" diff --git a/src/spek-window.cc b/src/spek-window.cc @@ -26,6 +26,8 @@ // WX on WIN doesn't like it when pthread.h is included first. #include <pthread.h> +#include <spek-utils.h> + #include "spek-preferences-dialog.hh" #include "spek-preferences.hh" #include "spek-spectrogram.hh" @@ -372,7 +374,7 @@ static void * check_version(void *p) return NULL; } - if (version > wxT(PACKAGE_VERSION)) { + if (1 == spek_vercmp(version.mb_str(wxConvLibc), PACKAGE_VERSION)) { SpekWindow *self = (SpekWindow *)p; wxCommandEvent event(SPEK_NOTIFY_EVENT, -1); event.SetEventObject(self); diff --git a/tests/Makefile.am b/tests/Makefile.am @@ -1,4 +1,5 @@ TESTS = \ + test-utils \ test check_PROGRAMS = $(TESTS) @@ -8,13 +9,14 @@ noinst_HEADERS = \ AM_CPPFLAGS = \ -include config.h \ - -I$(top_builddir)/src \ + -I$(top_builddir)/lib \ -pthread AM_CFLAGS = \ $(FFMPEG_CFLAGS) -AM_LDADD = \ +LDADD = \ + ../lib/libspek.a \ $(FFMPEG_LIBS) AM_LDFLAGS = \ diff --git a/tests/test-utils.c b/tests/test-utils.c @@ -0,0 +1,44 @@ +/* test-utils.c + * + * Copyright (C) 2012 Alexander Kojevnikov <alexander@kojevnikov.com> + * + * Spek is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Spek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Spek. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <spek-utils.h> + +#include "test.h" + +int main() +{ + ensure(0 == spek_vercmp("1.2.3", "1.2.3"), "1.2.3 == 1.2.3"); + ensure(1 == spek_vercmp("1.2.3", "1.2.2"), "1.2.3 > 1.2.2"); + ensure(-1 == spek_vercmp("1.2.2", "1.2.3"), "1.2.2 < 1.2.3"); + ensure(1 == spek_vercmp("1.2.3", "1"), "1.2.3 > 1"); + ensure(1 == spek_vercmp("1.2.3", "1."), "1.2.3 > 1."); + ensure(1 == spek_vercmp("1.2.3", "1.2"), "1.2.3 > 1.2"); + ensure(1 == spek_vercmp("1.2.3", "1.2."), "1.2.3 > 1.2."); + ensure(1 == spek_vercmp("1.15.3", "1.2"), "1.15.3 > 1.2"); + ensure(1 == spek_vercmp("2", "1.2.2"), "2 > 1.2.2"); + ensure(1 == spek_vercmp("1.2.3", ""), "1.2.3 > ''"); + ensure(0 == spek_vercmp("", ""), "'' == ''"); + ensure(0 == spek_vercmp("123", "123"), "123 == 123"); + ensure(-1 == spek_vercmp("0.2.3", "1"), "0.2.3 < 1"); + ensure(-1 == spek_vercmp("0.9.8", "0.10.1"), "0.9.8 < 0.10.1"); + ensure(-1 == spek_vercmp("1.200", "2.20"), "1.200 < 2.20"); + ensure(-1 == spek_vercmp("1.0.0", "2.0.0"), "1.0.0 < 2.0.0"); + ensure(-1 == spek_vercmp("1.0.0", "1.0.1"), "1.0.0 < 1.0.1"); + + return 0; +}