[seahorse] libseahorse: Add version string parsing
- From: Adam Schreiber <sadam src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [seahorse] libseahorse: Add version string parsing
- Date: Sun, 7 Feb 2010 21:06:56 +0000 (UTC)
commit e992586c5058b4639c422c02818bd0665030791f
Author: nobled <nobled dreamwidth org>
Date: Wed Jan 20 23:09:47 2010 +0000
libseahorse: Add version string parsing
libseahorse/seahorse-util.c | 28 +++++++++++++++++++++++++++-
libseahorse/seahorse-util.h | 4 ++++
2 files changed, 31 insertions(+), 1 deletions(-)
---
diff --git a/libseahorse/seahorse-util.c b/libseahorse/seahorse-util.c
index acaca7e..b5c7a78 100644
--- a/libseahorse/seahorse-util.c
+++ b/libseahorse/seahorse-util.c
@@ -1598,7 +1598,33 @@ seahorse_util_determine_popup_menu_position (GtkMenu *menu, int *x, int *y,
*x = menu_xpos;
*y = menu_ypos;
*push_in = TRUE;
-}
+}
+
+/**
+ * seahorse_util_parse_version:
+ *
+ * @version: Version number string in the form xx.yy.zz
+ *
+ * Converts an (up to) four-part version number into a 64-bit
+ * unsigned integer for simple comparison.
+ *
+ * Returns: SeahorseVersion
+ **/
+SeahorseVersion
+seahorse_util_parse_version (const char *version)
+{
+ SeahorseVersion ret = 0, tmp = 0;
+ int offset = 48;
+ gchar **tokens = g_strsplit(version, ".", 5);
+ int i;
+ for (i=0; tokens[i] && offset >= 0; i++) {
+ tmp = atoi(tokens[i]);
+ ret += tmp << offset;
+ offset -= 16;
+ }
+ g_strfreev(tokens);
+ return ret;
+}
/* -----------------------------------------------------------------------------
* DNS-SD Stuff
diff --git a/libseahorse/seahorse-util.h b/libseahorse/seahorse-util.h
index fddfe19..e863852 100644
--- a/libseahorse/seahorse-util.h
+++ b/libseahorse/seahorse-util.h
@@ -45,6 +45,8 @@ typedef enum {
SEAHORSE_SIG_SUFFIX,
} SeahorseSuffix;
+typedef guint64 SeahorseVersion;
+
#define SEAHORSE_EXT_ASC ".asc"
#define SEAHORSE_EXT_SIG ".sig"
#define SEAHORSE_EXT_PGP ".pgp"
@@ -176,6 +178,8 @@ void seahorse_util_determine_popup_menu_position (GtkMenu *menu,
gboolean *push_in,
gpointer gdata);
+SeahorseVersion seahorse_util_parse_version (const char *version);
+
#define seahorse_util_wait_until(expr) \
while (!(expr)) { \
while (g_main_context_pending(NULL) && !(expr)) \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]