]> gitweb.michael.orlitzky.com - hath.git/blob - src/Maskbits.hs
Add some additional GHC warnings to the makefile.
[hath.git] / src / Maskbits.hs
1 module Maskbits
2 ( Maskbits(..),
3 decrement,
4 maskbits_from_string
5 ) where
6
7 -- A type representing the number of bits in a CIDR netmask.
8 data Maskbits = None
9 | Zero
10 | One
11 | Two
12 | Three
13 | Four
14 | Five
15 | Six
16 | Seven
17 | Eight
18 | Nine
19 | Ten
20 | Eleven
21 | Twelve
22 | Thirteen
23 | Fourteen
24 | Fifteen
25 | Sixteen
26 | Seventeen
27 | Eighteen
28 | Nineteen
29 | Twenty
30 | TwentyOne
31 | TwentyTwo
32 | TwentyThree
33 | TwentyFour
34 | TwentyFive
35 | TwentySix
36 | TwentySeven
37 | TwentyEight
38 | TwentyNine
39 | Thirty
40 | ThirtyOne
41 | ThirtyTwo
42 deriving (Eq, Ord)
43
44
45 instance Show Maskbits where
46 show None = "None"
47 show Zero = "0"
48 show One = "1"
49 show Two = "2"
50 show Three = "3"
51 show Four = "4"
52 show Five = "5"
53 show Six = "6"
54 show Seven = "7"
55 show Eight = "8"
56 show Nine = "9"
57 show Ten = "10"
58 show Eleven = "11"
59 show Twelve = "12"
60 show Thirteen = "13"
61 show Fourteen = "14"
62 show Fifteen = "15"
63 show Sixteen = "16"
64 show Seventeen = "17"
65 show Eighteen = "18"
66 show Nineteen = "19"
67 show Twenty = "20"
68 show TwentyOne = "21"
69 show TwentyTwo = "22"
70 show TwentyThree = "23"
71 show TwentyFour = "24"
72 show TwentyFive = "25"
73 show TwentySix = "26"
74 show TwentySeven = "27"
75 show TwentyEight = "28"
76 show TwentyNine = "29"
77 show Thirty = "30"
78 show ThirtyOne = "31"
79 show ThirtyTwo = "32"
80
81
82
83 -- There are only 32 bits in an IPv4 address, so there
84 -- can't be more bits than that in the mask.
85 maskbits_from_int :: Int -> Maskbits
86 maskbits_from_int 0 = Zero
87 maskbits_from_int 1 = One
88 maskbits_from_int 2 = Two
89 maskbits_from_int 3 = Three
90 maskbits_from_int 4 = Four
91 maskbits_from_int 5 = Five
92 maskbits_from_int 6 = Six
93 maskbits_from_int 7 = Seven
94 maskbits_from_int 8 = Eight
95 maskbits_from_int 9 = Nine
96 maskbits_from_int 10 = Ten
97 maskbits_from_int 11 = Eleven
98 maskbits_from_int 12 = Twelve
99 maskbits_from_int 13 = Thirteen
100 maskbits_from_int 14 = Fourteen
101 maskbits_from_int 15 = Fifteen
102 maskbits_from_int 16 = Sixteen
103 maskbits_from_int 17 = Seventeen
104 maskbits_from_int 18 = Eighteen
105 maskbits_from_int 19 = Nineteen
106 maskbits_from_int 20 = Twenty
107 maskbits_from_int 21 = TwentyOne
108 maskbits_from_int 22 = TwentyTwo
109 maskbits_from_int 23 = TwentyThree
110 maskbits_from_int 24 = TwentyFour
111 maskbits_from_int 25 = TwentyFive
112 maskbits_from_int 26 = TwentySix
113 maskbits_from_int 27 = TwentySeven
114 maskbits_from_int 28 = TwentyEight
115 maskbits_from_int 29 = TwentyNine
116 maskbits_from_int 30 = Thirty
117 maskbits_from_int 31 = ThirtyOne
118 maskbits_from_int 32 = ThirtyTwo
119 maskbits_from_int _ = None
120
121
122 maskbits_from_string :: String -> Maskbits
123 maskbits_from_string s =
124 case (reads s :: [(Int, String)]) of
125 [] -> None
126 x:_ -> maskbits_from_int (fst x)
127
128
129
130 decrement :: Maskbits -> Maskbits
131 decrement None = None
132 decrement Zero = None
133 decrement One = Zero
134 decrement Two = One
135 decrement Three = Two
136 decrement Four = Three
137 decrement Five = Four
138 decrement Six = Five
139 decrement Seven = Six
140 decrement Eight = Seven
141 decrement Nine = Eight
142 decrement Ten = Nine
143 decrement Eleven = Ten
144 decrement Twelve = Eleven
145 decrement Thirteen = Twelve
146 decrement Fourteen = Thirteen
147 decrement Fifteen = Fourteen
148 decrement Sixteen = Fifteen
149 decrement Seventeen = Sixteen
150 decrement Eighteen = Seventeen
151 decrement Nineteen = Eighteen
152 decrement Twenty = Nineteen
153 decrement TwentyOne = Twenty
154 decrement TwentyTwo = TwentyOne
155 decrement TwentyThree = TwentyTwo
156 decrement TwentyFour = TwentyThree
157 decrement TwentyFive = TwentyFour
158 decrement TwentySix = TwentyFive
159 decrement TwentySeven = TwentySix
160 decrement TwentyEight = TwentySeven
161 decrement TwentyNine = TwentyEight
162 decrement Thirty = TwentyNine
163 decrement ThirtyOne = Thirty
164 decrement ThirtyTwo = ThirtyOne