0 | 0 |
/*
|
1 | 1 |
* Virt Viewer: A virtual machine console viewer
|
2 | 2 |
*
|
3 | |
* Copyright (C) 2007-2012 Red Hat, Inc.
|
|
3 |
* Copyright (C) 2007-2015 Red Hat, Inc.
|
4 | 4 |
* Copyright (C) 2009-2012 Daniel P. Berrange
|
5 | 5 |
*
|
6 | 6 |
* This program is free software; you can redistribute it and/or modify
|
|
438 | 438 |
return accel;
|
439 | 439 |
}
|
440 | 440 |
|
441 | |
/**
|
442 | |
* virt_viewer_compare_version:
|
443 | |
* @s1: a version-like string
|
444 | |
* @s2: a version-like string
|
445 | |
*
|
446 | |
* Compare two version-like strings: 1.1 > 1.0, 1.0.1 > 1.0, 1.10 > 1.7...
|
447 | |
*
|
448 | |
* String suffix (1.0rc1 etc) are not accepted, and will return 0.
|
449 | |
*
|
450 | |
* Returns: negative value if s1 < s2; zero if s1 = s2; positive value if s1 > s2.
|
451 | |
**/
|
452 | |
gint
|
|
441 |
static gboolean str_is_empty(const gchar *str)
|
|
442 |
{
|
|
443 |
return ((str == NULL) || (str[0] == '\0'));
|
|
444 |
}
|
|
445 |
|
|
446 |
static gint
|
453 | 447 |
virt_viewer_compare_version(const gchar *s1, const gchar *s2)
|
454 | 448 |
{
|
455 | 449 |
gint i, retval = 0;
|
456 | 450 |
gchar **v1, **v2;
|
457 | 451 |
|
458 | |
g_return_val_if_fail(s1 != NULL, 0);
|
459 | |
g_return_val_if_fail(s2 != NULL, 0);
|
|
452 |
if (str_is_empty(s1) && str_is_empty(s2)) {
|
|
453 |
return 0;
|
|
454 |
} else if (str_is_empty(s1)) {
|
|
455 |
return -1;
|
|
456 |
} else if (str_is_empty(s2)) {
|
|
457 |
return 1;
|
|
458 |
}
|
460 | 459 |
|
461 | 460 |
v1 = g_strsplit(s1, ".", -1);
|
462 | 461 |
v2 = g_strsplit(s2, ".", -1);
|
|
472 | 471 |
|
473 | 472 |
g_return_val_if_fail(e1 && e2, 0);
|
474 | 473 |
if (*e1 || *e2) {
|
475 | |
g_warning("the version string contains suffix");
|
|
474 |
g_warning("the version string contains a suffix");
|
476 | 475 |
goto end;
|
477 | 476 |
}
|
478 | 477 |
}
|
|
486 | 485 |
g_strfreev(v1);
|
487 | 486 |
g_strfreev(v2);
|
488 | 487 |
return retval;
|
|
488 |
}
|
|
489 |
|
|
490 |
/**
|
|
491 |
* virt_viewer_compare_buildid:
|
|
492 |
* @s1: a version-like string
|
|
493 |
* @s2: a version-like string
|
|
494 |
*
|
|
495 |
* Compare two buildid strings: 1.1-1 > 1.0-1, 1.0-2 > 1.0-1, 1.10 > 1.7...
|
|
496 |
*
|
|
497 |
* String suffix (1.0rc1 etc) are not accepted, and will return 0.
|
|
498 |
*
|
|
499 |
* Returns: negative value if s1 < s2; zero if s1 = s2; positive value if s1 > s2.
|
|
500 |
**/
|
|
501 |
gint
|
|
502 |
virt_viewer_compare_buildid(const gchar *s1, const gchar *s2)
|
|
503 |
{
|
|
504 |
int ret = 0;
|
|
505 |
GStrv split1 = NULL;
|
|
506 |
GStrv split2 = NULL;
|
|
507 |
|
|
508 |
split1 = g_strsplit(s1, "-", 2);
|
|
509 |
split2 = g_strsplit(s2, "-", 2);
|
|
510 |
if ((split1 == NULL) || (split2 == NULL)) {
|
|
511 |
goto end;
|
|
512 |
}
|
|
513 |
/* Compare versions */
|
|
514 |
ret = virt_viewer_compare_version(split1[0], split2[0]);
|
|
515 |
if (ret != 0) {
|
|
516 |
goto end;
|
|
517 |
}
|
|
518 |
if ((split1[0] == NULL) || (split2[0] == NULL)) {
|
|
519 |
goto end;
|
|
520 |
}
|
|
521 |
|
|
522 |
/* Compare -release */
|
|
523 |
ret = virt_viewer_compare_version(split1[1], split2[1]);
|
|
524 |
|
|
525 |
end:
|
|
526 |
g_strfreev(split1);
|
|
527 |
g_strfreev(split2);
|
|
528 |
|
|
529 |
return ret;
|
489 | 530 |
}
|
490 | 531 |
|
491 | 532 |
/* simple sorting of monitors. Primary sort left-to-right, secondary sort from
|