-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharithmetic.bmod
42 lines (37 loc) · 1.23 KB
/
arithmetic.bmod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, June 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/gpl-2.0.html>,
# or in pdf format at <http://www.dhampir.no/stuff/private/gpl-2.0.pdf>
# Copyright 2014 - Øyvind 'bolt' Hvidsten <[email protected]>
! ${GHOST:-false} || return 0
function arithmetic_calc
{
local q="$1"
local res
if
! [[ "$data" =~ [[:digit:]]+\.[[:digit:]]+\. ]] &&
! [[ "$data" =~ \.[[:digit:]]+\.[[:digit:]]+ ]] &&
res=$(awk "BEGIN{ print $q }")
then
if [[ "$res" = "inf" ]]; then
faction "${ARITHMETIC_PRIORITY:-5}" "explodes"
else
freply "${ARITHMETIC_PRIORITY:-5}" "$res"
fi
else
faction "${ARITHMETIC_PRIORITY:-5}" "is confused by this"
fi
}
if [[ -n "$reply" ]]; then
if [[ "$data" =~ ^[[:digit:]^\(\)\.%/*+-]+$ ]]; then
arithmetic_calc "$data"
fi
fi