1 /*
2  * tclegg.h
3  *   stuff used by tcl.c and tclhash.c
4  */
5 /*
6  * Copyright (C) 1997 Robey Pointer
7  * Copyright (C) 1999 - 2021 Eggheads Development Team
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  */
23 
24 #ifndef _EGG_TCLEGG_H
25 #define _EGG_TCLEGG_H
26 
27 #include "lush.h"
28 
29 #ifndef MAKING_MODS
30 #  include "proto.h"
31 #endif
32 
33 
34 /*
35  * Wow, this is old...CMD_LEAVE goes back to before version 0.9.
36  * This is for partyline and filesys 'quit'.
37  */
38 #define CMD_LEAVE (Function)(-1)
39 
40 
41 /* Match types for check_tcl_bind(). */
42 #define MATCH_PARTIAL   0
43 #define MATCH_EXACT     1
44 #define MATCH_MASK      2
45 #define MATCH_CASE      3
46 #define MATCH_MODE      4
47 #define MATCH_CRON      5
48 
49 /*
50  * Bitwise 'or' these:
51  */
52 
53 /* Check flags; make sure the user has the flags required. */
54 #define BIND_USE_ATTR       0x010
55 
56 /* Bind is stackable; more than one bind can have the same name. */
57 #define BIND_STACKABLE      0x020
58 
59 /* Additional flag checking; check for +d, +k, etc.
60  * Currently used for dcc, fil, msg, and pub bind types.
61  * Note that this just causes the flag checking to use flagrec_ok()
62  * instead of flagrec_eq().
63  */
64 /* FIXME: Should this really be used for the dcc and fil types since
65  *        they are only available to the partyline/filesys (+p/+x)?
66  *        Eggdrop's revenge code does not add default flags when
67  *        adding a user record for +d or +k flags.
68  */
69 /* FIXME: This type actually seems to be obsolete. This was originally
70  *        used to check built-in types in Eggdrop version 1.0.
71  */
72 #define BIND_HAS_BUILTINS   0x040
73 
74 /* Want return; we want to know if the proc returns 1.
75  * Side effect: immediate return; don't do any further
76  * processing of stacked binds.
77  */
78 #define BIND_WANTRET        0x080
79 
80 /* Alternate args; replace args with the return result from the Tcl proc. */
81 #define BIND_ALTER_ARGS     0x100
82 
83 /* Stacked return; we want to know if any proc returns 1,
84  * and also want to process all stacked binds.
85  */
86 #define BIND_STACKRET       0x200
87 
88 
89 /* Return values. */
90 #define BIND_NOMATCH    0
91 #define BIND_AMBIGUOUS  1
92 #define BIND_MATCHED    2       /* But the proc couldn't be found */
93 #define BIND_EXECUTED   3
94 #define BIND_EXEC_LOG   4       /* Proc returned 1 -> wants to be logged */
95 #define BIND_QUIT       5       /* CMD_LEAVE 'quit' from partyline or filesys */
96 
97 /* Extra commands are stored in Tcl hash tables (one hash table for each type
98  * of command: msg, dcc, etc).
99  */
100 typedef struct timer_str {
101   struct timer_str *next;
102   unsigned int mins;            /* Time remaining                       */
103   unsigned int count;           /* Number of repeats                    */
104   unsigned int interval;        /* Time to elapse                       */
105   char *cmd;                    /* Command linked to                    */
106   unsigned long id;             /* Used to remove timers                */
107 } tcl_timer_t;
108 
109 
110 /* Used for Tcl stub functions */
111 #define STDVAR (ClientData cd, Tcl_Interp *irp, int argc, char *argv[])
112 
113 #define STDOBJVAR (ClientData cd, Tcl_Interp *irp, int objc, Tcl_Obj *const objv[])
114 
115 #define BADARGS(nl, nh, example) do {                                   \
116         if ((argc < (nl)) || ((argc > (nh)) && ((nh) != -1))) {         \
117                 Tcl_AppendResult(irp, "wrong # args: should be \"",     \
118                                  argv[0], (example), "\"", NULL);       \
119                 return TCL_ERROR;                                       \
120         }                                                               \
121 } while (0)
122 
123 #define BADOBJARGS(nl, nh, prefix, example) do {                        \
124         if ((objc < (nl)) || ((objc > (nh)) && ((nh) != -1))) {         \
125                 Tcl_WrongNumArgs(irp, prefix, objv, example);           \
126                 return TCL_ERROR;                                       \
127         }                                                               \
128 } while (0)
129 
130 #define CHECKVALIDITY(a)        do {                                    \
131         if (!check_validity(argv[0], (a))) {                            \
132                 Tcl_AppendResult(irp, "bad builtin command call!",      \
133                                  NULL);                                 \
134                 return TCL_ERROR;                                       \
135         }                                                               \
136 } while (0)
137 
138 unsigned long add_timer(tcl_timer_t **, int, int, char *, unsigned long);
139 int remove_timer(tcl_timer_t **, unsigned long);
140 void list_timers(Tcl_Interp *, tcl_timer_t *);
141 void wipe_timers(Tcl_Interp *, tcl_timer_t **);
142 void do_check_timers(tcl_timer_t **);
143 
144 typedef struct _tcl_strings {
145   char *name;
146   char *buf;
147   int length;
148   int flags;
149 } tcl_strings;
150 
151 typedef struct _tcl_int {
152   char *name;
153   int *val;
154   int readonly;
155 } tcl_ints;
156 
157 typedef struct _tcl_coups {
158   char *name;
159   int *lptr;
160   int *rptr;
161 } tcl_coups;
162 
163 typedef struct _tcl_cmds {
164   char *name;
165   IntFunc func;
166 } tcl_cmds;
167 
168 typedef struct _cd_tcl_cmd {
169   char *name;
170   IntFunc callback;
171   void *cdata;
172 } cd_tcl_cmd;
173 
174 void add_tcl_commands(tcl_cmds *);
175 void add_tcl_objcommands(tcl_cmds *);
176 void add_cd_tcl_cmds(cd_tcl_cmd *);
177 void rem_tcl_commands(tcl_cmds *);
178 void add_tcl_strings(tcl_strings *);
179 void rem_tcl_strings(tcl_strings *);
180 void add_tcl_coups(tcl_coups *);
181 void rem_tcl_coups(tcl_coups *);
182 void add_tcl_ints(tcl_ints *);
183 void rem_tcl_ints(tcl_ints *);
184 const char *tcl_resultstring();
185 int tcl_resultint();
186 int tcl_resultempty();
187 int tcl_threaded();
188 int fork_before_tcl();
189 time_t get_expire_time(Tcl_Interp *, const char *);
190 
191 /* From Tcl's tclUnixInit.c */
192 /* The following table is used to map from Unix locale strings to
193  * encoding files.
194  */
195 typedef struct LocaleTable {
196   const char *lang;
197   const char *encoding;
198 } LocaleTable;
199 
200 static const LocaleTable localeTable[] = {
201   {"ja_JP.SJIS",    "shiftjis"},
202   {"ja_JP.EUC",       "euc-jp"},
203   {"ja_JP.JIS",   "iso2022-jp"},
204   {"ja_JP.mscode",  "shiftjis"},
205   {"ja_JP.ujis",      "euc-jp"},
206   {"ja_JP",           "euc-jp"},
207   {"Ja_JP",         "shiftjis"},
208   {"Jp_JP",         "shiftjis"},
209   {"japan",           "euc-jp"},
210 #ifdef hpux
211   {"japanese",      "shiftjis"},
212   {"ja",            "shiftjis"},
213 #else
214   {"japanese",        "euc-jp"},
215   {"ja",              "euc-jp"},
216 #endif
217   {"japanese.sjis", "shiftjis"},
218   {"japanese.euc",    "euc-jp"},
219   {"japanese-sjis", "shiftjis"},
220   {"japanese-ujis",   "euc-jp"},
221 
222   {"ko",              "euc-kr"},
223   {"ko_KR",           "euc-kr"},
224   {"ko_KR.EUC",       "euc-kr"},
225   {"ko_KR.euc",       "euc-kr"},
226   {"ko_KR.eucKR",     "euc-kr"},
227   {"korean",          "euc-kr"},
228 
229   {"ru",           "iso8859-5"},
230   {"ru_RU",        "iso8859-5"},
231   {"ru_SU",        "iso8859-5"},
232 
233   {"zh",               "cp936"},
234 
235   {NULL,                  NULL}
236 };
237 
238 #endif /* _EGG_TCLEGG_H */
239