Mercurial > hg > egg-tcls
annotate calc.tcl @ 424:825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 08 Jan 2017 03:55:55 +0200 |
parents | fd0635443234 |
children | b45fc205f425 |
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> |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
390
diff
changeset
|
4 # (C) Copyright 2008-2011 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" |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
24 bind pub - !laske calc_pubmsg |
216 | 25 bind msg - !laske calc_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 # ------------------------------------------------------------------------ |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
35 proc calc_do {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 # ------------------------------------------------------------------------ |
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
49 proc calc_pubmsg {nick uhost hand chan args} { |
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 | |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
57 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
|
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 # ------------------------------------------------------------------------- |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
63 proc calc_msg {nick uhost hand args} { |
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 |
71
50cbd24feadf
laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
71 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
|
72 calc_smsg $nick "$result" |
0 | 73 return 1 |
74 } | |
75 | |
76 # ------------------------------------------------------------------------- |