Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=gfpm/.git;a=commitdiff;h=5a6d7135d9b87c8fa37304377c9eea4f990a1045

commit 5a6d7135d9b87c8fa37304377c9eea4f990a1045
Author: Priyank <[EMAIL PROTECTED]>
Date:   Thu Aug 2 19:46:49 2007 +0530

gfpm-util: new function gfpm_vercmp() to compare versions of packages.

diff --git a/src/gfpm-util.c b/src/gfpm-util.c
index 2a4a632..928d77d 100644
--- a/src/gfpm-util.c
+++ b/src/gfpm-util.c
@@ -41,4 +41,49 @@ gfpm_pmlist_to_glist (PM_LIST *list)

return ret;
}
+
+gint
+gfpm_vercmp (const char *str1, const char *str2)
+{
+       int             l1 = 0, l2 = 0;
+       char            st1[l1];
+       char            st2[l2];
+       register int    i;
+       int             j = 0;
+       int             v1, v2;
+
+       if (str1 == NULL || str2 == NULL)
+               return -1;
+       l1 = strlen(str1);
+       l2 = strlen(str2);
+       for (i=0;i<l1;i++)
+       {
+               if (isdigit(str1[i]))
+               {
+                       st1[j] = str1[i];
+                       j++;
+               }
+       }
+       st1[j] = 0;
+       for (i=0,j=0;i<l2;i++)
+       {
+               if (isdigit(str1[i]))
+               {
+                       st2[j] = str2[i];
+                       j++;
+               }
+       }
+       st2[j] = 0;
+
+       v1 = atoi (st1);
+       v2 = atoi (st2);
+       if (v1 == v2)
+               return 0;
+       if (v1 < v2)
+               return -1;
+       if (v1 > v2)
+               return 1;
+
+       return -1;
+}

\ No newline at end of file
diff --git a/src/gfpm-util.h b/src/gfpm-util.h
index 1d49cd7..fbe5849 100644
--- a/src/gfpm-util.h
+++ b/src/gfpm-util.h
@@ -4,6 +4,7 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <ctype.h>
#include <unistd.h>
#include <locale.h>
#include <libintl.h>
@@ -15,4 +16,6 @@ char * gfpm_bold (const char *);

GList * gfpm_pmlist_to_glist (PM_LIST *);

+gint gfpm_vercmp (const char *, const char *);
+
#endif
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to