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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
14dfb925a64a Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 525
diff changeset
4 # (C) Copyright 2008-2021 Tecnic Software productions (TNSP)
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 # This script is freely distributable under GNU GPL (version 2) license.
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #
71
50cbd24feadf laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
10 ##########################################################################
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
71
50cbd24feadf laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
18 ##########################################################################
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
b45fc205f425 calc: Rename functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 424
diff changeset
24 bind pub - !laske calc_cmd_pub
b45fc205f425 calc: Rename functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 424
diff changeset
25 bind msg - !laske calc_cmd_msg
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
71
50cbd24feadf laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
34 # ------------------------------------------------------------------------
695
abd05400481d calc: Rename proc.
Matti Hamalainen <ccr@tnsp.org>
parents: 649
diff changeset
35 proc calc_exec {args} {
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
50bf17f1ba39 Use MFCalc.
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
38 set equ [join [join $args ""] ""]
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
270
d3ba5847cbda calc: Update comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
40 # Use external binary to calculate the result, but catch any exceptions / errors
135
50bf17f1ba39 Use MFCalc.
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
71
50cbd24feadf laske: Rename functions, add a bit of comments, cosmetics, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
48 # ------------------------------------------------------------------------
524
b45fc205f425 calc: Rename functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 424
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
54 return 1
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
695
abd05400481d calc: Rename proc.
Matti Hamalainen <ccr@tnsp.org>
parents: 649
diff changeset
57 set result [calc_exec $args]
649
92aefade4466 calc: Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 578
diff changeset
58 calc_smsg $chan "${nick}, ${result}"
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 return 1
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
424
825cac46b1cb Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 390
diff changeset
62 # -------------------------------------------------------------------------
524
b45fc205f425 calc: Rename functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 424
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
68 return 1
0
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 }
424
825cac46b1cb Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 390
diff changeset
70
695
abd05400481d calc: Rename proc.
Matti Hamalainen <ccr@tnsp.org>
parents: 649
diff changeset
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
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 return 1
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 }
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
1c4e2814cd41 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 # -------------------------------------------------------------------------