Mercurial > hg > egg-tcls
annotate calc.tcl @ 698:6ba9f961e463 default tip
quotedb: Bump version and copyright.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 18 Sep 2023 11:38:41 +0300 |
parents | abd05400481d |
children |
rev | line source |
---|---|
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
1 ########################################################################## |
0 | 2 # |
114
593874678e45
Clarify authorship by doing sed "s/ccr\/TNSP/Matti 'ccr' Hamalainen/g".
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
3 # Calc v0.4 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
578 | 4 # (C) Copyright 2008-2021 Tecnic Software productions (TNSP) |
0 | 5 # |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
6 # A simple calculator for Eggdrop. |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
7 # |
0 | 8 # This script is freely distributable under GNU GPL (version 2) license. |
9 # | |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
10 ########################################################################## |
0 | 11 |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
12 # Error message for when no arguments given to the command |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
13 set calc_err_noargs "Laalis?" |
72
fd300fe87f59
Renamed laske.tcl to calc.tcl
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
14 |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
15 set calc_preferredmsg "PRIVMSG" |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
16 |
0 | 17 |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
18 ########################################################################## |
0 | 19 # No need to look below this line |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
20 ########################################################################## |
79
fccfbcbb06e4
calc: Old script name had been left in the startup message, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
72
diff
changeset
|
21 set calc_message "Calc v0.4 by ccr/TNSP" |
fccfbcbb06e4
calc: Old script name had been left in the startup message, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
72
diff
changeset
|
22 |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
23 putlog "$calc_message" |
524 | 24 bind pub - !laske calc_cmd_pub |
25 bind msg - !laske calc_cmd_msg | |
0 | 26 |
27 | |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
28 # ------------------------------------------------------------------------ |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
29 proc calc_smsg {udest umsg} { |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
30 global calc_preferredmsg |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
31 putserv "$calc_preferredmsg $udest :$umsg" |
0 | 32 } |
33 | |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
34 # ------------------------------------------------------------------------ |
695 | 35 proc calc_exec {args} { |
0 | 36 |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
37 # This is something rather perverse |
135 | 38 set equ [join [join $args ""] ""] |
0 | 39 |
270 | 40 # Use external binary to calculate the result, but catch any exceptions / errors |
135 | 41 if {[catch {set res [exec -- "/usr/local/bin/mfcalc" "$equ"]} uerrmsg]} { |
130
88ce9376f22d
calc: Use external Perl interpreter for the computation .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
42 return $uerrmsg |
0 | 43 } else { |
390
fd0635443234
calc: Match output from new version of mfcalc binary.
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
44 return "$res" |
0 | 45 } |
46 } | |
47 | |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
48 # ------------------------------------------------------------------------ |
524 | 49 proc calc_cmd_pub {nick uhost hand chan args} { |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
50 global calc_err_noargs |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
51 |
0 | 52 if {$args == {} || $args == ""} { |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
53 calc_smsg $chan "$calc_err_noargs" |
63 | 54 return 1 |
0 | 55 } |
56 | |
695 | 57 set result [calc_exec $args] |
649 | 58 calc_smsg $chan "${nick}, ${result}" |
0 | 59 return 1 |
60 } | |
61 | |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
62 # ------------------------------------------------------------------------- |
524 | 63 proc calc_cmd_msg {nick uhost hand args} { |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
64 global calc_err_noargs |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
65 |
0 | 66 if {$args == {} || $args == ""} { |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
67 calc_smsg $nick "$calc_err_noargs" |
63 | 68 return 1 |
0 | 69 } |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
70 |
695 | 71 set result [calc_exec $args] |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
72 calc_smsg $nick "$result" |
0 | 73 return 1 |
74 } | |
75 | |
76 # ------------------------------------------------------------------------- |