Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "PTK 1" | |
132 | .TH PTK 1 "2000-12-30" "perl v5.8.0" "User Contributed Perl Documentation" | |
133 | .SH "NAME" | |
134 | Tk2portableTk \- how to make your \fBTk\fR source portable to other | |
135 | interpreted languages. | |
136 | .SH "Author" | |
137 | .IX Header "Author" | |
138 | Ilya Zakharevich <ilya@math.ohio\-state.edu> has contributed most of | |
139 | this document. Many thanks. | |
140 | .SH "DESCRIPTION" | |
141 | .IX Header "DESCRIPTION" | |
142 | \&\fBPortableTk\fR is an attempt to make \fBTk\fR useful from other | |
143 | languages. Currently tk4.0 runs under Perl using this | |
144 | approach. Below, \fILang\fR is the notation for an external language to | |
145 | which \fBPortableTk\fR glues \fBTk\fR code. | |
146 | .PP | |
147 | The main problem with using the code developed for \fB\s-1TCL\s0\fR with | |
148 | different languages is the absence of data types: almost anything is | |
149 | \&\f(CW\*(C`char*\*(C'\fR. It makes automatic translation hopeless. However, if you | |
150 | \&\f(CW\*(C`typedef\*(C'\fR several new symbols to be \f(CW\*(C`char*\*(C'\fR, you can still use your | |
151 | code in \fB\s-1TCL\s0\fR, \fIand\fR it will make the automatic translation | |
152 | possible. | |
153 | .PP | |
154 | Another problem with the approach that \*(L"everything is a string\*(R" is | |
155 | impossibility to have a result that says \*(L"NotApplicable\*(R" without | |
156 | setting an error. Thus different \fBTk\fR command return different string | |
157 | values that mean \*(L"error happened\*(R", like \f(CW""\fR, \f(CW" "\fR or | |
158 | \&\f(CW"??"\fR. Other languages can be more flexible, so in \fBportableTk\fR you | |
159 | should inform the compiler that what you want to return means \*(L"error\*(R" | |
160 | (see \*(L"Setting variables\*(R"). | |
161 | .PP | |
162 | Currently \fBPortableTk\fR uses several different approachs | |
163 | to simplify translation: several \fB\s-1TCL\s0\fR functions that are especially | |
164 | dangerous to use are undefined, so you can easily find places that | |
165 | need to be updated to use Language-independent functions based on | |
166 | compiler warnings. Eventually a way to use these Language-independent | |
167 | functions under proper \fB\s-1TCL\s0\fR will be also provided. The end of this | |
168 | document provides a starting point for such a project. | |
169 | .SH "Structure of \fBpTk\fP, porting your code" | |
170 | .IX Header "Structure of pTk, porting your code" | |
171 | \&\fBpTk\fR, that is a port of \fBTk\fR, is very special with respect to porting | |
172 | of other code to \fBportableTk\fR. The problem is that currently there is | |
173 | very little hope to merge the modifications back into \fBTk\fR, so a | |
174 | special strategy is needed to maintain this port. Do not use this | |
175 | strategy to port your own code. | |
176 | .PP | |
177 | \&\fBpTk\fR is produced from \fBTk\fR via a two-step process: first, some | |
178 | manual editing (the result is in the subdirectory \f(CW\*(C`mTk\*(C'\fR), and second, | |
179 | automatic conversion by the \f(CW\*(C`munge\*(C'\fR script (written in Perl). Thus the | |
180 | subdirectory \f(CW\*(C`pTk/mTk\*(C'\fR contains code with minimal possible difference | |
181 | from the virgin \fBTk\fR code, so it is easier to \fImerge\fR\|(1) the | |
182 | differences between \fBTk\fR versions into modified code. | |
183 | .PP | |
184 | It looks like the strategy for a portable code should be exactly | |
185 | opposite: starting from \fB\s-1TCL\s0\fR\-based code, apply \f(CW\*(C`munge\*(C'\fR, and then | |
186 | hand-edit the resulting code. Probably it is also possible to target | |
187 | your code to \fBportableTk\fR from scratch, since this will make it | |
188 | possible to run it under a lot of \fILang\fRuages. | |
189 | .PP | |
190 | The only reason anyone would like to look into contents of \f(CW\*(C`pTk/mTk\*(C'\fR | |
191 | directory is to find out which constructs are not supported by | |
192 | \&\f(CW\*(C`munge\*(C'\fR. On the other hand, \f(CW\*(C`pTk\*(C'\fR directory contains code that is | |
193 | conformant to \fBportableTk\fR, so you can look there to find example code. | |
194 | .PP | |
195 | \&\f(CW\*(C`munge\*(C'\fR is the script that converts most common \fBTk\fR constructs to | |
196 | their \f(CW\*(C`portableTk\*(C'\fR equivalent. For your code to qualify, you should | |
197 | follow \fBTk\fR conventions on indentation and names of variables, in | |
198 | particular, the array of arguments for the \f(CW\*(C`...CmdProc\*(C'\fR should be | |
199 | called \f(CW\*(C`argv\*(C'\fR. | |
200 | .PP | |
201 | For details on what \f(CW\*(C`munge\*(C'\fR can do, see | |
202 | \&\*(L"Translation of some \s-1TCL\s0 functions\*(R". | |
203 | .SH "\fBPortableTk\fP API" | |
204 | .IX Header "PortableTk API" | |
205 | .Sh "Checking what you are running under" | |
206 | .IX Subsection "Checking what you are running under" | |
207 | \&\fBPortableTk\fR provides a symbol \f(CW\*(C`????\*(C'\fR. If this symbol is defined, | |
208 | your source is compiled with it. | |
209 | .Sh "New types of configuration options" | |
210 | .IX Subsection "New types of configuration options" | |
211 | \&\fBPortableTk\fR defines several new types of configuration options: | |
212 | .PP | |
213 | .Vb 6 | |
214 | \& TK_CONFIG_CALLBACK | |
215 | \& TK_CONFIG_LANGARG | |
216 | \& TK_CONFIG_SCALARVAR | |
217 | \& TK_CONFIG_HASHVAR | |
218 | \& TK_CONFIG_ARRAYVAR | |
219 | \& TK_CONFIG_IMAGE | |
220 | .Ve | |
221 | .PP | |
222 | You should use them instead of \s-1TK_CONFIG_STRING\s0 whenever | |
223 | appropriate. This allows your application to receive a direct | |
224 | representation of the corresponding resource instead of the string | |
225 | representation, if this is possible under given language. | |
226 | .PP | |
227 | ???? It looks like \f(CW\*(C`TK_CONFIG_IMAGE\*(C'\fR and \f(CW\*(C`TK_CONFIG_SCALARVAR\*(C'\fR set | |
228 | variables of type \f(CW\*(C`char*\*(C'\fR. | |
229 | .Sh "Language data" | |
230 | .IX Subsection "Language data" | |
231 | The following data types are defined: | |
232 | .ie n .IP """Arg""" 4 | |
233 | .el .IP "\f(CWArg\fR" 4 | |
234 | .IX Item "Arg" | |
235 | is the main datatype of the language. This is a type that your C | |
236 | function gets pointers to for arguments when the corresponding \fILang\fR | |
237 | function is called. The corresponding config type is | |
238 | \&\f(CW\*(C`TK_CONFIG_LANGARG\*(C'\fR. | |
239 | .Sp | |
240 | This is also a type that keeps information about contents of \fILang\fR | |
241 | variable. | |
242 | .ie n .IP """Var""" 4 | |
243 | .el .IP "\f(CWVar\fR" 4 | |
244 | .IX Item "Var" | |
245 | Is a substitute for a \f(CW\*(C`char *\*(C'\fR that contains name of variable. In | |
246 | \&\fILang\fR it is an object that contains reference to another \fILang\fR | |
247 | variable. | |
248 | .ie n .IP """LangResultSave""" 4 | |
249 | .el .IP "\f(CWLangResultSave\fR" 4 | |
250 | .IX Item "LangResultSave" | |
251 | ???? | |
252 | .ie n .IP """LangCallback""" 4 | |
253 | .el .IP "\f(CWLangCallback\fR" 4 | |
254 | .IX Item "LangCallback" | |
255 | \&\f(CW\*(C`LangCallback*\*(C'\fR a substitute for a \f(CW\*(C`char *\*(C'\fR that contains command to | |
256 | call. The corresponding config type is \f(CW\*(C`TK_CONFIG_CALLBACK\*(C'\fR. | |
257 | .ie n .IP """LangFreeProc""" 4 | |
258 | .el .IP "\f(CWLangFreeProc\fR" 4 | |
259 | .IX Item "LangFreeProc" | |
260 | It is the type that the \f(CW\*(C`Lang_SplitList\*(C'\fR sets. Before you call it, | |
261 | declare | |
262 | .Sp | |
263 | .Vb 5 | |
264 | \& Args *args; | |
265 | \& LangFreeProc *freeProc = NULL; | |
266 | \& ... | |
267 | \& code = Lang_SplitList(interp, value, | |
268 | \& &argc, &args, &freeProc); | |
269 | .Ve | |
270 | .Sp | |
271 | After you use the split values, call | |
272 | .Sp | |
273 | .Vb 1 | |
274 | \& if (args != NULL && freeProc) (*freeProc)(argc,args); | |
275 | .Ve | |
276 | .Sp | |
277 | It is not guaranteed that the \f(CW\*(C`args\*(C'\fR can survive deletion of \f(CW\*(C`value\*(C'\fR. | |
278 | .Sh "Conversion" | |
279 | .IX Subsection "Conversion" | |
280 | The following macros and functions are used for conversion between | |
281 | strings and the additional types: | |
282 | .PP | |
283 | .Vb 3 | |
284 | \& LangCallback * LangMakeCallback(Arg) | |
285 | \& Arg LangCallbackArg(LangCallback *) | |
286 | \& char * LangString(Arg) | |
287 | .Ve | |
288 | .PP | |
289 | After you use the result of \fILangCallbackArg()\fR, you should free it with | |
290 | \&\f(CW\*(C`freeProc\*(C'\fR \f(CW\*(C`LANG_DYNAMIC\*(C'\fR (it is not guaranteed that any change of | |
291 | \&\f(CW\*(C`Arg\*(C'\fR will not be reflected in <LangCallback>, so you cannot do | |
292 | LangSet...() in between, and you should reset it to \f(CW\*(C`NULL\*(C'\fR if you | |
293 | want to do any further assignments to this \f(CW\*(C`Arg\*(C'\fR). | |
294 | .PP | |
295 | The following function returns the \f(CW\*(C`Arg\*(C'\fR that is a reference to \f(CW\*(C`Var\*(C'\fR: | |
296 | .PP | |
297 | .Vb 1 | |
298 | \& Arg LangVarArg(Var) | |
299 | .Ve | |
300 | .PP | |
301 | ???? It is very anti\-intuitive, I hope the name is changed. | |
302 | .PP | |
303 | .Vb 1 | |
304 | \& int LangCmpCallback(LangCallback *a,Arg b) | |
305 | .Ve | |
306 | .PP | |
307 | (currently only a stub), and, at last, | |
308 | .PP | |
309 | .Vb 1 | |
310 | \& LangCallback * LangCopyCallback(LangCallback *) | |
311 | .Ve | |
312 | .Sh "Callbacks" | |
313 | .IX Subsection "Callbacks" | |
314 | Above we have seen the new datatype \f(CW\*(C`LangCallback\*(C'\fR and the | |
315 | corresponding \fIConfig option\fR \f(CW\*(C`TK_CONFIG_CALLBACK\*(C'\fR. The following | |
316 | functions are provided for manipulation of \f(CW\*(C`LangCallback\*(C'\fRs: | |
317 | .PP | |
318 | .Vb 3 | |
319 | \& void LangFreeCallback(LangCallback *) | |
320 | \& int LangDoCallback(Tcl_Interp *,LangCallback *, | |
321 | \& int result,int argc, char *format,...) | |
322 | .Ve | |
323 | .PP | |
324 | The argument \f(CW\*(C`format\*(C'\fR of \f(CW\*(C`LangDoCallback\*(C'\fR should contain a string that is | |
325 | suitable for \f(CW\*(C`sprintf\*(C'\fR with optional arguments of \f(CW\*(C`LangDoCallback\*(C'\fR. | |
326 | \&\f(CW\*(C`result\*(C'\fR should be false if result of callback is not needed. | |
327 | .PP | |
328 | .Vb 2 | |
329 | \& int LangMethodCall(Tcl_Interp *,Arg,char *method, | |
330 | \& int result,int argc,...) | |
331 | .Ve | |
332 | .PP | |
333 | ???? | |
334 | .PP | |
335 | Conceptually, \f(CW\*(C`LangCallback*\*(C'\fR is a substitute for ubiquitous \f(CW\*(C`char *\*(C'\fR | |
336 | in \fB\s-1TCL\s0\fR. So you should use \f(CW\*(C`LangFreeCallback\*(C'\fR instead of \f(CW\*(C`ckfree\*(C'\fR | |
337 | or \f(CW\*(C`free\*(C'\fR if appropriate. | |
338 | .Sh "Setting variables" | |
339 | .IX Subsection "Setting variables" | |
340 | .Vb 5 | |
341 | \& void LangFreeArg (Arg, Tcl_FreeProc *freeProc) | |
342 | \& Arg LangCopyArg (Arg); | |
343 | \& void Tcl_AppendArg (Tcl_Interp *interp, Arg) | |
344 | \& void LangSetString(Arg *, char *s) | |
345 | \& void LangSetDefault(Arg *, char *s) | |
346 | .Ve | |
347 | .PP | |
348 | These two are equivalent unless s is an empty string. In this case | |
349 | \&\f(CW\*(C`LangSetDefault\*(C'\fR behaves like \f(CW\*(C`LangSetString\*(C'\fR with \f(CW\*(C`s==NULL\*(C'\fR, i.e., | |
350 | it sets the current value of the \fILang\fR variable to be false. | |
351 | .PP | |
352 | .Vb 2 | |
353 | \& void LangSetInt(Arg *,int) | |
354 | \& void LangSetDouble(Arg *,double) | |
355 | .Ve | |
356 | .PP | |
357 | The \fILang\fR functions separate uninitialized and initialized data | |
358 | comparing data with \f(CW\*(C`NULL\*(C'\fR. So the declaration for an \f(CW\*(C`Arg\*(C'\fR should | |
359 | look like | |
360 | .PP | |
361 | .Vb 1 | |
362 | \& Arg arg = NULL; | |
363 | .Ve | |
364 | .PP | |
365 | if you want to use this \f(CW\*(C`arg\*(C'\fR with the above functions. After you are | |
366 | done, you should use \f(CW\*(C`LangFreeArg\*(C'\fR with \f(CW\*(C`TCL_DYNAMIC\*(C'\fR as \f(CW\*(C`freeProc\*(C'\fR. | |
367 | .Sh "Language functions" | |
368 | .IX Subsection "Language functions" | |
369 | Use | |
370 | .ie n .IP """int LangNull(Arg)""" 4 | |
371 | .el .IP "\f(CWint LangNull(Arg)\fR" 4 | |
372 | .IX Item "int LangNull(Arg)" | |
373 | to check that an object is false; | |
374 | .ie n .IP """int LangStringMatch(char *string, Arg match)""" 4 | |
375 | .el .IP "\f(CWint LangStringMatch(char *string, Arg match)\fR" 4 | |
376 | .IX Item "int LangStringMatch(char *string, Arg match)" | |
377 | ???? | |
378 | .ie n .IP """void LangExit(int)""" 4 | |
379 | .el .IP "\f(CWvoid LangExit(int)\fR" 4 | |
380 | .IX Item "void LangExit(int)" | |
381 | to make a proper shutdown; | |
382 | .ie n .IP """int LangEval(Tcl_Interp *interp, char *cmd, int global)""" 4 | |
383 | .el .IP "\f(CWint LangEval(Tcl_Interp *interp, char *cmd, int global)\fR" 4 | |
384 | .IX Item "int LangEval(Tcl_Interp *interp, char *cmd, int global)" | |
385 | to call \fILang\fR \f(CW\*(C`eval\*(C'\fR; | |
386 | .ie n .IP """void Lang_SetErrorCode(Tcl_Interp *interp,char *code)""" 4 | |
387 | .el .IP "\f(CWvoid Lang_SetErrorCode(Tcl_Interp *interp,char *code)\fR" 4 | |
388 | .IX Item "void Lang_SetErrorCode(Tcl_Interp *interp,char *code)" | |
389 | .PD 0 | |
390 | .ie n .IP """char *Lang_GetErrorCode(Tcl_Interp *interp)""" 4 | |
391 | .el .IP "\f(CWchar *Lang_GetErrorCode(Tcl_Interp *interp)\fR" 4 | |
392 | .IX Item "char *Lang_GetErrorCode(Tcl_Interp *interp)" | |
393 | .ie n .IP """char *Lang_GetErrorInfo(Tcl_Interp *interp)""" 4 | |
394 | .el .IP "\f(CWchar *Lang_GetErrorInfo(Tcl_Interp *interp)\fR" 4 | |
395 | .IX Item "char *Lang_GetErrorInfo(Tcl_Interp *interp)" | |
396 | .ie n .IP """void LangCloseHandler(Tcl_Interp *interp,Arg arg,FILE *f,Lang_FileCloseProc *proc)""" 4 | |
397 | .el .IP "\f(CWvoid LangCloseHandler(Tcl_Interp *interp,Arg arg,FILE *f,Lang_FileCloseProc *proc)\fR" 4 | |
398 | .IX Item "void LangCloseHandler(Tcl_Interp *interp,Arg arg,FILE *f,Lang_FileCloseProc *proc)" | |
399 | .PD | |
400 | currently stubs only; | |
401 | .ie n .IP """int LangSaveVar(Tcl_Interp *,Arg arg,Var *varPtr,int type)""" 4 | |
402 | .el .IP "\f(CWint LangSaveVar(Tcl_Interp *,Arg arg,Var *varPtr,int type)\fR" 4 | |
403 | .IX Item "int LangSaveVar(Tcl_Interp *,Arg arg,Var *varPtr,int type)" | |
404 | to save the structure \f(CW\*(C`arg\*(C'\fR into \fILang\fR variable \f(CW*varPtr\fR; | |
405 | .ie n .IP """void LangFreeVar(Var var)""" 4 | |
406 | .el .IP "\f(CWvoid LangFreeVar(Var var)\fR" 4 | |
407 | .IX Item "void LangFreeVar(Var var)" | |
408 | to free the result; | |
409 | .ie n .IP """int LangEventCallback(Tcl_Interp *,LangCallback *,XEvent *,KeySym)""" 4 | |
410 | .el .IP "\f(CWint LangEventCallback(Tcl_Interp *,LangCallback *,XEvent *,KeySym)\fR" 4 | |
411 | .IX Item "int LangEventCallback(Tcl_Interp *,LangCallback *,XEvent *,KeySym)" | |
412 | ???? | |
413 | .ie n .IP """int LangEventHook(int flags)""" 4 | |
414 | .el .IP "\f(CWint LangEventHook(int flags)\fR" 4 | |
415 | .IX Item "int LangEventHook(int flags)" | |
416 | .PD 0 | |
417 | .ie n .IP """void LangBadFile(int fd)""" 4 | |
418 | .el .IP "\f(CWvoid LangBadFile(int fd)\fR" 4 | |
419 | .IX Item "void LangBadFile(int fd)" | |
420 | .ie n .IP """int LangCmpConfig(char *spec, char *arg, size_t length)""" 4 | |
421 | .el .IP "\f(CWint LangCmpConfig(char *spec, char *arg, size_t length)\fR" 4 | |
422 | .IX Item "int LangCmpConfig(char *spec, char *arg, size_t length)" | |
423 | .PD | |
424 | unsupported????; | |
425 | .ie n .IP """void Tcl_AppendArg (Tcl_Interp *interp, Arg)""" 4 | |
426 | .el .IP "\f(CWvoid Tcl_AppendArg (Tcl_Interp *interp, Arg)\fR" 4 | |
427 | .IX Item "void Tcl_AppendArg (Tcl_Interp *interp, Arg)" | |
428 | .PP | |
429 | Another useful construction is | |
430 | .PP | |
431 | .Vb 1 | |
432 | \& Arg variable = LangFindVar(interp, Tk_Window tkwin, char *name); | |
433 | .Ve | |
434 | .PP | |
435 | After using the above function, you should call | |
436 | .PP | |
437 | .Vb 1 | |
438 | \& LangFreeVar(Var variable); | |
439 | .Ve | |
440 | .PP | |
441 | ???? Note discrepancy in types! | |
442 | .PP | |
443 | If you want to find the value of a variable (of type \f(CW\*(C`Arg\*(C'\fR) given the | |
444 | variable name, use \f(CW\*(C`Tcl_GetVar(interp, varName, flags)\*(C'\fR. If you are | |
445 | interested in the string value of this variable, use | |
446 | \&\f(CW\*(C`LangString(Tcl_GetVar(...))\*(C'\fR. | |
447 | .PP | |
448 | To get a \fBC\fR array of \f(CW\*(C`Arg\*(C'\fR of length \f(CW\*(C`n\*(C'\fR, use | |
449 | .PP | |
450 | .Vb 3 | |
451 | \& Arg *args = LangAllocVec(n); | |
452 | \& ... | |
453 | \& LangFreeVec(n,args); | |
454 | .Ve | |
455 | .PP | |
456 | You can set the values of the \f(CW\*(C`Arg\*(C'\fRs using \f(CW\*(C`LangSet...\*(C'\fR functions, | |
457 | and get string value using \f(CW\*(C`LangString\*(C'\fR. | |
458 | .PP | |
459 | If you want to merge an array of \f(CW\*(C`Arg\*(C'\fRs into one \f(CW\*(C`Arg\*(C'\fR (that will | |
460 | be an array variable), use | |
461 | .PP | |
462 | .Vb 1 | |
463 | \& result = Tcl_Merge(listLength, list); | |
464 | .Ve | |
465 | .Sh "Translation of some \s-1TCL\s0 functions" | |
466 | .IX Subsection "Translation of some TCL functions" | |
467 | We mark items that can be dealt with by \f(CW\*(C`munge\*(C'\fR by \fIAutoconverted\fR. | |
468 | .ie n .IP """Tcl_AppendResult""" 4 | |
469 | .el .IP "\f(CWTcl_AppendResult\fR" 4 | |
470 | .IX Item "Tcl_AppendResult" | |
471 | does not take \f(CW\*(C`(char*)NULL\*(C'\fR, but \f(CW\*(C`NULL\*(C'\fR as delimiter. \fIAutoconverted\fR. | |
472 | .ie n .IP """Tcl_CreateCommand""\fR, \f(CW""Tcl_DeleteCommand""" 4 | |
473 | .el .IP "\f(CWTcl_CreateCommand\fR, \f(CWTcl_DeleteCommand\fR" 4 | |
474 | .IX Item "Tcl_CreateCommand, Tcl_DeleteCommand" | |
475 | \&\f(CW\*(C`Tk_CreateWidget\*(C'\fR, \f(CW\*(C`Tk_DeleteWidget\*(C'\fR, the second argument is the | |
476 | window itself, not the pathname. \fIAutoconverted\fR. | |
477 | .ie n .IP """sprintf(interp\->result, ""%d %d %d %d"",...)""" 4 | |
478 | .el .IP "\f(CWsprintf(interp\->result, ``%d %d %d %d'',...)\fR" 4 | |
479 | .IX Item "sprintf(interp->result, ""%d %d %d %d"",...)" | |
480 | \&\f(CW\*(C`Tcl_IntResults(interp,4,0,...)\*(C'\fR. \fIAutoconverted\fR. | |
481 | .ie n .IP """interp\->result = ""1"";""" 4 | |
482 | .el .IP "\f(CWinterp\->result = ``1'';\fR" 4 | |
483 | .IX Item "interp->result = ""1"";" | |
484 | \&\f(CW\*(C`Tcl_SetResult(interp,"1", TCL_STATIC)\*(C'\fR. \fIAutoconverted\fR. | |
485 | .ie n .IP "Reading ""interp\->result""" 4 | |
486 | .el .IP "Reading \f(CWinterp\->result\fR" 4 | |
487 | .IX Item "Reading interp->result" | |
488 | \&\f(CW\*(C`Tcl_GetResult(interp)\*(C'\fR. \fIAutoconverted\fR. | |
489 | .ie n .IP """interp\->result = Tk_PathName(textPtr\->tkwin);""" 4 | |
490 | .el .IP "\f(CWinterp\->result = Tk_PathName(textPtr\->tkwin);\fR" 4 | |
491 | .IX Item "interp->result = Tk_PathName(textPtr->tkwin);" | |
492 | \&\f(CW\*(C`Tk_WidgetResult(interp,textPtr\->tkwin)\*(C'\fR. \fIAutoconverted\fR. | |
493 | .ie n .IP "Sequence ""Tcl_PrintDouble, Tcl_PrintDouble, ..., Tcl_AppendResult""" 4 | |
494 | .el .IP "Sequence \f(CWTcl_PrintDouble, Tcl_PrintDouble, ..., Tcl_AppendResult\fR" 4 | |
495 | .IX Item "Sequence Tcl_PrintDouble, Tcl_PrintDouble, ..., Tcl_AppendResult" | |
496 | Use a single command | |
497 | .Sp | |
498 | .Vb 2 | |
499 | \& void Tcl_DoubleResults(Tcl_Interp *interp, int append, | |
500 | \& int argc,...); | |
501 | .Ve | |
502 | .Sp | |
503 | \&\f(CW\*(C`append\*(C'\fR governs whether it is required to clear the result first. | |
504 | .Sp | |
505 | A similar command for \f(CW\*(C`int\*(C'\fR arguments is \f(CW\*(C`Tcl_IntResults\*(C'\fR. | |
506 | .ie n .IP """Tcl_SplitList""" 4 | |
507 | .el .IP "\f(CWTcl_SplitList\fR" 4 | |
508 | .IX Item "Tcl_SplitList" | |
509 | Use \f(CW\*(C`Lang_SplitList\*(C'\fR (see the description above). | |
510 | .SH "Translation back to TCL" | |
511 | .IX Header "Translation back to TCL" | |
512 | To use your \fBportableTk\fR program with \fB\s-1TCL\s0\fR, put | |
513 | .PP | |
514 | .Vb 1 | |
515 | \& #include "ptcl.h" | |
516 | .Ve | |
517 | .PP | |
518 | \&\fIbefore\fR inclusion of \f(CW\*(C`tk.h\*(C'\fR, and link the resulting code with | |
519 | \&\f(CW\*(C`ptclGlue.c\*(C'\fR. | |
520 | .PP | |
521 | These files currently implement the following: | |
522 | .IP "Additional config types:" 4 | |
523 | .IX Item "Additional config types:" | |
524 | .Vb 6 | |
525 | \& TK_CONFIG_CALLBACK | |
526 | \& TK_CONFIG_LANGARG | |
527 | \& TK_CONFIG_SCALARVAR | |
528 | \& TK_CONFIG_HASHVAR | |
529 | \& TK_CONFIG_ARRAYVAR | |
530 | \& TK_CONFIG_IMAGE | |
531 | .Ve | |
532 | .IP "Types:" 4 | |
533 | .IX Item "Types:" | |
534 | .Vb 1 | |
535 | \& Var, Arg, LangCallback, LangFreeProc. | |
536 | .Ve | |
537 | .IP "Functions and macros:" 4 | |
538 | .IX Item "Functions and macros:" | |
539 | .Vb 6 | |
540 | \& Lang_SplitList, LangString, LangSetString, LangSetDefault, | |
541 | \& LangSetInt, LangSetDouble Tcl_ArgResult, LangCallbackArg, | |
542 | \& LangSaveVar, LangFreeVar, | |
543 | \& LangFreeSplitProc, LangFreeArg, Tcl_DoubleResults, Tcl_IntResults, | |
544 | \& LangDoCallback, Tk_WidgetResult, Tcl_CreateCommand, | |
545 | \& Tcl_DeleteCommand, Tcl_GetResult. | |
546 | .Ve | |
547 | .PP | |
548 | Current implementation contains enough to make it possible to compile | |
549 | \&\f(CW\*(C`mTk/tkText*.[ch]\*(C'\fR with the virgin \fBTk\fR. | |
550 | .Sh "New types of events ????" | |
551 | .IX Subsection "New types of events ????" | |
552 | PortableTk defines following new types of events: | |
553 | .PP | |
554 | .Vb 7 | |
555 | \& TK_EVENTTYPE_NONE | |
556 | \& TK_EVENTTYPE_STRING | |
557 | \& TK_EVENTTYPE_NUMBER | |
558 | \& TK_EVENTTYPE_WINDOW | |
559 | \& TK_EVENTTYPE_ATOM | |
560 | \& TK_EVENTTYPE_DISPLAY | |
561 | \& TK_EVENTTYPE_DATA | |
562 | .Ve | |
563 | .PP | |
564 | and a function | |
565 | .PP | |
566 | .Vb 4 | |
567 | \& char * Tk_EventInfo(int letter, | |
568 | \& Tk_Window tkwin, XEvent *eventPtr, | |
569 | \& KeySym keySym, int *numPtr, int *isNum, int *type, | |
570 | \& int num_size, char *numStorage) | |
571 | .Ve | |
572 | .SH "Checking for trouble" | |
573 | .IX Header "Checking for trouble" | |
574 | If you start with working \s-1TCL\s0 code, you can start convertion using | |
575 | the above hints. Good indication that you are doing is \s-1OK\s0 is absence | |
576 | of \f(CW\*(C`sprintf\*(C'\fR and \f(CW\*(C`sscanf\*(C'\fR in your code (at least in the part that is | |
577 | working with interpreter). | |
578 | .SH "Additional API" | |
579 | .IX Header "Additional API" | |
580 | What is described here is not included into base \fBportableTk\fR | |
581 | distribution. Currently it is coded in \fB\s-1TCL\s0\fR and as Perl macros (core | |
582 | is coded as functions, so theoretically you can use the same object | |
583 | files with different interpreted languages). | |
584 | .ie n .Sh """ListFactory""" | |
585 | .el .Sh "\f(CWListFactory\fP" | |
586 | .IX Subsection "ListFactory" | |
587 | Dynamic arrays in \fB\s-1TCL\s0\fR are used for two different purposes: to | |
588 | construct strings, and to construct lists. These two usages will have | |
589 | separate interfaces in other languages (since list is a different type | |
590 | from a string), so you should use a different interface in your code. | |
591 | .PP | |
592 | The type for construction of dynamic lists is \f(CW\*(C`ListFactory\*(C'\fR. The \s-1API\s0 | |
593 | below is a counterpart of the \s-1API\s0 for construction of dynamic lists | |
594 | in \fB\s-1TCL\s0\fR: | |
595 | .PP | |
596 | .Vb 9 | |
597 | \& void ListFactoryInit(ListFactory *) | |
598 | \& void ListFactoryFinish(ListFactory *) | |
599 | \& void ListFactoryFree(ListFactory *) | |
600 | \& Arg * ListFactoryArg(ListFactory *) | |
601 | \& void ListFactoryAppend(ListFactory *, Arg *arg) | |
602 | \& void ListFactoryAppendCopy(ListFactory *, Arg *arg) | |
603 | \& ListFactory * ListFactoryNewLevel(ListFactory *) | |
604 | \& ListFactory * ListFactoryEndLevel(ListFactory *) | |
605 | \& void ListFactoryResult(Tcl_Interp *, ListFactory *) | |
606 | .Ve | |
607 | .PP | |
608 | The difference is that a call to \f(CW\*(C`ListFactoryFinish\*(C'\fR should precede the | |
609 | actual usage of the value of \f(CW\*(C`ListFactory\*(C'\fR, and there are two | |
610 | different ways to append an \f(CW\*(C`Arg\*(C'\fR to a \f(CW\*(C`ListFactory\*(C'\fR: | |
611 | \&\fIListFactoryAppendCopy()\fR guarantees that the value of \f(CW\*(C`arg\*(C'\fR is copied | |
612 | to the list, but \fIListFactoryAppend()\fR may append to the list a | |
613 | reference to the current value of \f(CW\*(C`arg\*(C'\fR. If you are not going to change | |
614 | the value of \f(CW\*(C`arg\*(C'\fR after appending, the call to ListFactoryAppend may | |
615 | be quicker. | |
616 | .PP | |
617 | As in \fB\s-1TCL\s0\fR, the call to \fIListFactoryFree()\fR does not free the | |
618 | \&\f(CW\*(C`ListFactory\*(C'\fR, only the objects it references. | |
619 | .PP | |
620 | The functions \fIListFactoryNewLevel()\fR and \fIListFactoryEndLevel()\fR return a | |
621 | pointer to a \f(CW\*(C`ListFactory\*(C'\fR to fill. The argument of | |
622 | \&\fIListFactoryEndLevel()\fR cannot be used after a call to this function. | |
623 | .Sh "DStrings" | |
624 | .IX Subsection "DStrings" | |
625 | Production of strings are still supported in \fBportableTk\fR. | |
626 | .ie n .Sh "Accessing ""Arg""s" | |
627 | .el .Sh "Accessing \f(CWArg\fPs" | |
628 | .IX Subsection "Accessing Args" | |
629 | The following functions for getting a value of an \f(CW\*(C`Arg\*(C'\fR \fImay\fR be | |
630 | provided: | |
631 | .PP | |
632 | .Vb 4 | |
633 | \& double LangDouble(Arg) | |
634 | \& int LangInt(Arg) | |
635 | \& long LangLong(Arg) | |
636 | \& int LangIsList(Arg arg) | |
637 | .Ve | |
638 | .PP | |
639 | The function \fILangIsList()\fR is supported only partially under \fB\s-1TCL\s0\fR, | |
640 | since there is no data types. It checks whether there is a space | |
641 | inside the string \f(CW\*(C`arg\*(C'\fR. | |
642 | .ie n .Sh "Assigning numbers to ""Arg""s" | |
643 | .el .Sh "Assigning numbers to \f(CWArg\fPs" | |
644 | .IX Subsection "Assigning numbers to Args" | |
645 | While \fILangSetDouble()\fR and \fILangSetInt()\fR are supported ways to assign | |
646 | numbers to assign an integer value to a variable, for the sake of | |
647 | efficiency under \fB\s-1TCL\s0\fR it is supposed that the destination of these | |
648 | commands was massaged before the call so it contains a long enough | |
649 | string to \fIsprintf()\fR the numbers inside it. If you are going to | |
650 | immediately use the resulting \f(CW\*(C`Arg\*(C'\fR, the best way to do this is to | |
651 | declare a buffer in the beginning of a block by | |
652 | .PP | |
653 | .Vb 1 | |
654 | \& dArgBuffer; | |
655 | .Ve | |
656 | .PP | |
657 | and assign this buffer to the \f(CW\*(C`Arg\*(C'\fR by | |
658 | .PP | |
659 | .Vb 1 | |
660 | \& void LangSetDefaultBuffer(Arg *) | |
661 | .Ve | |
662 | .PP | |
663 | You can also create the buffer(s) manually and assign them using | |
664 | .PP | |
665 | .Vb 1 | |
666 | \& void LangSetBuffer(Arg *, char *) | |
667 | .Ve | |
668 | .PP | |
669 | This is the only choice if you need to assign numeric values to | |
670 | several \f(CW\*(C`Arg\*(C'\fRs simultaneously. The advantage of the first approach is | |
671 | that the above declarations can be made \f(CW\*(C`nop\*(C'\fRs in different languages. | |
672 | .PP | |
673 | Note that if you apply \f(CW\*(C`LangSetDefaultBuffer\*(C'\fR to an \f(CW\*(C`Arg\*(C'\fR that | |
674 | contains some value, you can create a leak if you do not free that | |
675 | \&\f(CW\*(C`Arg\*(C'\fR first. This is a non-problem in real languages, but can be a | |
676 | trouble in \f(CW\*(C`TCL\*(C'\fR, unless you use only the above \s-1API\s0. | |
677 | .ie n .Sh "Creating new ""Arg""s" | |
678 | .el .Sh "Creating new \f(CWArg\fPs" | |
679 | .IX Subsection "Creating new Args" | |
680 | The \s-1API\s0 for creating a new \f(CW\*(C`Arg\*(C'\fR is | |
681 | .PP | |
682 | .Vb 1 | |
683 | \& void LangNewArg(Arg *, LangFreeProc *) | |
684 | .Ve | |
685 | .PP | |
686 | The \s-1API\s0 for creating a new \f(CW\*(C`Arg\*(C'\fR is absent. Just initialize \f(CW\*(C`Arg\*(C'\fR to | |
687 | be \f(CW\*(C`NULL\*(C'\fR, and apply one of \f(CW\*(C`LangSet...\*(C'\fR methods. | |
688 | .PP | |
689 | After you use this \f(CW\*(C`Arg\*(C'\fR, it should be freed thusly: | |
690 | .PP | |
691 | \&\f(CW\*(C`LangFreeArg(arg, freeProc)\*(C'\fR. | |
692 | .Sh "Evaluating a list" | |
693 | .IX Subsection "Evaluating a list" | |
694 | Use | |
695 | .PP | |
696 | .Vb 1 | |
697 | \& int LangArgEval(Tcl_Interp *, Arg arg) | |
698 | .Ve | |
699 | .PP | |
700 | Here \f(CW\*(C`arg\*(C'\fR should be a list to evaluate, in particular, the first | |
701 | element should be a \f(CW\*(C`LangCallback\*(C'\fR massaged to be an \f(CW\*(C`Arg\*(C'\fR. The | |
702 | arguments can be send to the subroutine by reference or by value in | |
703 | different languages. | |
704 | .ie n .Sh "Getting result as ""Arg""" | |
705 | .el .Sh "Getting result as \f(CWArg\fP" | |
706 | .IX Subsection "Getting result as Arg" | |
707 | Use \f(CW\*(C`Tcl_ArgResult\*(C'\fR. It is not guaranteed that result survives this | |
708 | operation, so the \f(CW\*(C`Arg\*(C'\fR you get should be the only mean to access the | |
709 | data from this moment on. After you use this \f(CW\*(C`Arg\*(C'\fR, you should free | |
710 | it with \f(CW\*(C`freeProc\*(C'\fR \f(CW\*(C`LANG_DYNAMIC\*(C'\fR (you can do LangSet...() in between). |