]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Aggiunta la funzione SolipaUtils::compare_version. 0.4.0 gtk2
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 6 Feb 2014 14:54:52 +0000 (15:54 +0100)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 6 Feb 2014 14:54:52 +0000 (15:54 +0100)
.project
src/utils.c
src/utils.h
tests/Makefile.am
tests/utils_compare_version.c [new file with mode: 0644]

index 20175df2c2017c392d8846065f5fbe9d49fb98cc..eca435d7a3fc269209701b409bd2ef24bd67da03 100644 (file)
--- a/.project
+++ b/.project
@@ -69,7 +69,7 @@
        </natures>
        <filteredResources>
                <filter>
-                       <id>1325156677028</id>
+                       <id>1391696678342</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -78,7 +78,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677034</id>
+                       <id>1391696678346</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -87,7 +87,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677038</id>
+                       <id>1391696678351</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -96,7 +96,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677042</id>
+                       <id>1391696678356</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677046</id>
+                       <id>1391696678361</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677050</id>
+                       <id>1391696678365</id>
                        <name></name>
                        <type>30</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677053</id>
+                       <id>1391696678370</id>
                        <name></name>
                        <type>30</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677056</id>
+                       <id>1391696678376</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677059</id>
+                       <id>1391696678381</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677062</id>
+                       <id>1391696678386</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677066</id>
+                       <id>1391696678398</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677069</id>
+                       <id>1391696678402</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677073</id>
+                       <id>1391696678406</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677076</id>
+                       <id>1391696678410</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677079</id>
+                       <id>1391696678414</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677083</id>
+                       <id>1391696678548</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677086</id>
+                       <id>1391696678551</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677094</id>
+                       <id>1391696678555</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677099</id>
+                       <id>1391696678559</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677103</id>
+                       <id>1391696678563</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677107</id>
+                       <id>1391696678567</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677111</id>
+                       <id>1391696678570</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677114</id>
+                       <id>1391696678574</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1325156677119</id>
+                       <id>1391696678578</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                                <arguments>1.0-name-matches-false-false-libtool</arguments>
                        </matcher>
                </filter>
+               <filter>
+                       <id>1391696678582</id>
+                       <name></name>
+                       <type>22</type>
+                       <matcher>
+                               <id>org.eclipse.ui.ide.multiFilter</id>
+                               <arguments>1.0-name-matches-false-false-*.dll</arguments>
+                       </matcher>
+               </filter>
+               <filter>
+                       <id>1391696678588</id>
+                       <name></name>
+                       <type>22</type>
+                       <matcher>
+                               <id>org.eclipse.ui.ide.multiFilter</id>
+                               <arguments>1.0-name-matches-false-false-*.a</arguments>
+                       </matcher>
+               </filter>
        </filteredResources>
 </projectDescription>
index da10b123f6482aef1b1c489f911cb125e54829cb..0df8d6b6caa55c1b3381da5a110dedb8e3b76a8d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2012 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2014 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1921,6 +1921,79 @@ solipa_apri_collegamento (GtkWindow *transient, const gchar *indirizzo)
 #endif
 }
 
+int
+solipa_compare_version (const gchar *ver1, const gchar *ver2, const gchar *delimiters, guint *part)
+{
+       gchar **_ver1;
+       gchar **_ver2;
+
+       gchar *_delimiters;
+
+       guint i;
+       guint l;
+
+       if (ver1 == NULL)
+               {
+                       return -1;
+               }
+       if (ver2 == NULL)
+               {
+                       return 1;
+               }
+
+       if (delimiters == NULL)
+               {
+                       _delimiters = g_strdup (".");
+               }
+       else
+               {
+                       _delimiters = g_strstrip (g_strdup (delimiters));
+                       if (g_strcmp0 (_delimiters, "") == 0)
+                               {
+                                       g_free (_delimiters);
+                                       _delimiters = g_strdup (".");
+                               }
+               }
+
+       _ver1 = g_strsplit (g_strstrip (g_strdup (ver1)), _delimiters, -1);
+       _ver2 = g_strsplit (g_strstrip (g_strdup (ver2)), _delimiters, -1);
+
+       l = MIN (g_strv_length (_ver1), g_strv_length (_ver2));
+       for (i = 0; i < l; i++)
+               {
+                       if (strtol (_ver1[i], NULL, 10) < strtol (_ver2[i], NULL, 10))
+                               {
+                                       if (part != NULL)
+                                               {
+                                                       *part = i;
+                                               }
+                                       return -1;
+                               }
+                       else if (strtol (_ver1[i], NULL, 10) > strtol (_ver2[i], NULL, 10))
+                               {
+                                       if (part != NULL)
+                                               {
+                                                       *part = i;
+                                               }
+                                       return 1;
+                               }
+               }
+
+       if (g_strv_length (_ver1) < g_strv_length (_ver2))
+               {
+                       *part = g_strv_length (_ver1) + 1;
+                       return -1;
+               }
+       else if (g_strv_length (_ver1) > g_strv_length (_ver2))
+               {
+                       *part = g_strv_length (_ver2) + 1;
+                       return 1;
+               }
+
+       *part = 0;
+       return 0;
+}
+
 /**
  * This function is copied from
  * http://bugzilla.gnome.org/show_bug.cgi?id=524831.
index d6b6817ee81dca9f2732b43deb4005971f523c84..1176a647e6623fb45519c361fa8050f597af5a55 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2011 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2014 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -105,6 +105,8 @@ void solipa_gstring_initial_capital (GString *gstring);
 
 void solipa_apri_collegamento (GtkWindow *transient, const gchar *indirizzo);
 
+int solipa_compare_version (const gchar *ver1, const gchar *ver2, const gchar *delimiters, guint *part);
+
 gchar *g_mkdtemp (gchar *tmpl);
 
 
index 1dc28b68388e216810dd413c90a6291a281ad909..66e5bbc3e397beb97bd71fd985fd04bb1c56fc96 100644 (file)
@@ -23,6 +23,7 @@ noinst_PROGRAMS = allegato \
                   utils \
                   utils_apri_collegamento \
                   utils_codfisc_piva \
+                  utils_compare_version \
                   utils_format_money \
                   utils_gdatetime \
                   utils_gstring_initial_capital \
diff --git a/tests/utils_compare_version.c b/tests/utils_compare_version.c
new file mode 100644 (file)
index 0000000..7c85be0
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2014 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <solipa.h>
+#include <utils.h>
+
+int
+main (int argc, char *argv[])
+{
+       int ret;
+       guint part;
+
+       g_type_init ();
+
+       if (argc == 3)
+               {
+                       ret = solipa_compare_version (argv[1], argv[2], NULL, &part);
+                       g_message ("%s รจ %s %s (%d)",
+                                  argv[1],
+                                  ret == -1 ? "minore di" : ret == 0 ? "uguale a" : "maggiore di",
+                                  argv[2],
+                                  part);
+               }
+       else
+               {
+                       g_message ("Usage: utils_compare_version <ver1> <ver2>");
+                       return 0;
+               }
+
+       return 0;
+}