OSDN Git Service

こっそり、気持ち程度の日本語化しました (UTF-8 / Windows 環境用)。
[ring-lang-081/annotated-ring-with-OmegaT.git] / source / ringpm / core / version.ring
1 /*
2         Title : The Ring Package Manager 
3         Date  : 2018.10.19
4         Author: Mahmoud Fayed <msfclipper@yahoo.com>
5 */
6
7 # Load Global Libraries 
8         load "stdlibcore.ring"
9
10 # Load Application Files 
11         load "packages.ring"
12         load "globals.ring"
13
14 if isMainSourceFile()
15         TestProcessVersion()
16 ok
17
18 func TestProcessVersion
19         ? 1.9 > 1.10                    # 1 (True)
20         ? ProcessVersion("1.9")         # "1.9" --> "001009"   -->  1009
21         ? ProcessVersion("1.10")        # "1.10" ---> "001010" -->  1010
22         ? ProcessVersion("1.9") > ProcessVersion("1.10")        # 0 (False)
23
24 func CheckRingVersion aPackageInfo
25         # 1.0   1.1     ....    1.8 1.9 1.10
26         # 1.8 < 1.9 
27         # 1.9 < 1.10
28         if ProcessVersion(version()) >= ProcessVersion(aPackageInfo[:ringversion])
29                  return True ok 
30         return False 
31
32 func ProcessVersion cVersion
33         //      1.9             ---->  001009
34         //      1.10            ---->  001010
35         //      1.9     <       1.10    ----> Ring Output (False)
36         //      001009  <       001010  ----> Ring Output (True)
37         # "1.9" ---> ["1","9"]
38         aVersion = Split(cVersion,".")          # List of Numbers 
39         # 1.9 ---> [ "001" , "009"]
40                 for cNumber in aVersion
41                         nSize = len(cNumber)
42                         if nSize < C_VERSIONSECTIONSIZE 
43                                 cNumber = Copy("0",C_VERSIONSECTIONSIZE-nSize) + cNumber 
44                         ok
45                 next 
46         cVersion = List2Str(aVersion)   # [ "001" , "009"] ---> "001" + nl + "009"
47         cVersion = substr(cVersion,nl,"")
48         return 0+cVersion               # "001009" ---> 1009 
49
50 func GetMajorVersionNumber cVersion
51         nPos = substr(cVersion,".")
52         if nPos 
53                 cVersion = left(cVersion,nPos-1)
54         ok
55         return 0 + cVersion 
56
57 func GetMajorVersionText cVersion
58         # Before version 1.0.0 ---> We return the package version 
59         # From version 1.0.0 < 2.0.0 ---> We return empty string 
60         # From 2.0.0 ---> We return the major version (v2, v3, etc)
61         nMajor = GetMajorVersionNumber(cVersion)
62         if nMajor = 0
63                 return "-"+cVersion
64         but nMajor = 1 
65                 return 
66         else 
67                 return "-"+nMajor
68         ok
69
70 func IsCompatible cVersion1,cVersion2
71         if cVersion1 != cVersion2
72                 if GetMajorVersionNumber(cVersion1) = 0 or
73                         GetMajorVersionNumber(cVersion1) != GetMajorVersionNumber(cVersion2)
74                         return False
75                 else 
76                         return True
77                 ok
78         ok
79         return True