Mercurial > hg > egg-tcls
annotate calc.tcl @ 651:ecd8fb2b9ad3
urllog: Use regexp splitx instead of string split.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 17 Feb 2021 11:00:49 +0200 |
parents | 92aefade4466 |
children | abd05400481d |
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 | |
649 | 34 |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
35 # ------------------------------------------------------------------------ |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
36 proc calc_do {args} { |
0 | 37 |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
38 # This is something rather perverse |
135 | 39 set equ [join [join $args ""] ""] |
0 | 40 |
270 | 41 # Use external binary to calculate the result, but catch any exceptions / errors |
135 | 42 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
|
43 return $uerrmsg |
0 | 44 } else { |
390
fd0635443234
calc: Match output from new version of mfcalc binary.
Matti Hamalainen <ccr@tnsp.org>
parents:
270
diff
changeset
|
45 return "$res" |
0 | 46 } |
47 } | |
48 | |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
49 # ------------------------------------------------------------------------ |
524 | 50 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
|
51 global calc_err_noargs |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
52 |
0 | 53 if {$args == {} || $args == ""} { |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
54 calc_smsg $chan "$calc_err_noargs" |
63 | 55 return 1 |
0 | 56 } |
57 | |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
58 set result [calc_do $args] |
649 | 59 calc_smsg $chan "${nick}, ${result}" |
0 | 60 return 1 |
61 } | |
62 | |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
63 # ------------------------------------------------------------------------- |
524 | 64 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
|
65 global calc_err_noargs |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
66 |
0 | 67 if {$args == {} || $args == ""} { |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
68 calc_smsg $nick "$calc_err_noargs" |
63 | 69 return 1 |
0 | 70 } |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
71 |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
72 set result [calc_do $args] |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
73 calc_smsg $nick "$result" |
0 | 74 return 1 |
75 } | |
76 | |
77 # ------------------------------------------------------------------------- |