compare_version.awk 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # tinmop: an humble mastodon client
  2. # Copyright (C) 2020 cage
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program.
  13. # If not, see [[http://www.gnu.org/licenses/][http://www.gnu.org/licenses/]].
  14. BEGIN {
  15. TRUE = 1;
  16. FALSE = 0;
  17. VERSION_SEP = "\\.";
  18. }
  19. function split_version_number (version, parsed) {
  20. split(version, parsed, VERSION_SEP);
  21. for (i in parsed) {
  22. parsed[i] = parsed[i] + 0;
  23. }
  24. }
  25. function version_less_than_p (version_a, version_b, idx) {
  26. for (idx=1; idx <= length(version_a); idx++){
  27. if(version_a[idx] < version_b[idx]){
  28. return TRUE;
  29. } else if(version_a[idx] > version_b[idx]){
  30. return FALSE;
  31. }
  32. }
  33. return FALSE;
  34. }
  35. // {
  36. versions[""]="";
  37. version_a[""]="";
  38. version_b[""]="";
  39. split($0, versions, "[[:space:]]+");
  40. split_version_number(versions[1], version_a);
  41. split_version_number(versions[2], version_b);
  42. print (version_less_than_p(version_a, version_b));
  43. }