DoctorD90

VersChk.tcl

Apr 22nd, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 2.18 KB | None | 0 0
  1. ### VersChk.tcl 1.5.0 mQARWRMG
  2.  
  3. #REQUIREMENTS
  4. # PBinSrc.tcl fMrtKqyq
  5.  
  6. #LICENSE
  7. # Copyright © 2013 Alberto Dietze "DoctorD90"
  8. #
  9. #    This program is free software: you can redistribute it and/or modify
  10. #    it under the terms of the GNU General Public License as published by
  11. #    the Free Software Foundation, either version 3 of the License, or
  12. #    (at your option) any later version.
  13. #
  14. #    This program is distributed in the hope that it will be useful,
  15. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. #    GNU General Public License for more details.
  18. #
  19. #    You should have received a copy of the GNU General Public License
  20. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # Full GPLv3 Text: http://www.gnu.org/licenses/gpl.txt
  23.  
  24. #PATERNITY
  25. #Coder: DoctorD90
  26. #Network: irc.OnlineGamesNet.net
  27. #Chan: #eHito
  28.  
  29. #PURPOSE
  30. #Compare 2 versions number made up of theorically infinity numbers, and know if 2nd is newer/older/equal than 1st basing
  31. #to used proc.
  32.  
  33. #USAGE
  34. #Split versions numbers in lists of
  35. #elements (ex. 1.0.0 -> [split "1.0.0" "."]).
  36. #To know if 2nd is newer than 1st use [vers_newer v1st v2nd]. If it is, it returns 1.
  37. #To know if 2nd is older than 1st use [vers_older v1st v2nd]. If it is, it returns 1.
  38. #To know if 2nd is equal than 1st use [vers_equer v1st v2nd]. If it is, it returns 1.
  39.  
  40.  
  41. ### DON'T EDIT ANYTHING BELOW ###
  42.  
  43. proc vers_newer {v1 v2} {
  44.   return [vers_chker $v1 $v2]
  45. }
  46.  
  47. proc vers_older {v1 v2} {
  48.   return [vers_chker $v2 $v1]
  49. }
  50.  
  51. proc vers_equer {v1 v2} {
  52.   set s 0
  53.   if {![vers_chker $v1 $v2] && ![vers_chker $v2 $v1]} {
  54.     set s 1
  55.   }
  56.   return $s
  57. }
  58.  
  59. proc vers_chker {v1 v2} {
  60.   set l1 [llength $v1]
  61.   set l2 [llength $v2]
  62.   if {$l1 > $l2} {
  63.     set l $l1
  64.     while {$l != $l2} {
  65.       lappend v2 0
  66.       incr l2
  67.     }
  68.   } else {
  69.     set l $l2
  70.     while {$l != $l1} {
  71.       lappend v1 0
  72.       incr l1
  73.     }
  74.   }
  75.   set s 0
  76.   set n 0
  77.   while {!$s && $l > $n} {
  78.     if {[lindex $v2 $n] > [lindex $v1 $n]} { set s 1 }
  79.     incr n
  80.   }
  81.   return $s
  82. }
  83.  
  84. ###
  85. putlog "VersChk.tcl LOADED"
Advertisement