| 1 |
'\" |
| 2 |
'\" Generated from file 'critcl_emap\&.man' by tcllib/doctools with format 'nroff' |
| 3 |
'\" Copyright (c) 2011-2024 Andreas Kupries |
| 4 |
'\" |
| 5 |
.TH "critcl::emap" n 1\&.3 doc "C Runtime In Tcl (CriTcl)" |
| 6 |
.\" The -*- nroff -*- definitions below are for supplemental macros used |
| 7 |
.\" in Tcl/Tk manual entries. |
| 8 |
.\" |
| 9 |
.\" .AP type name in/out ?indent? |
| 10 |
.\" Start paragraph describing an argument to a library procedure. |
| 11 |
.\" type is type of argument (int, etc.), in/out is either "in", "out", |
| 12 |
.\" or "in/out" to describe whether procedure reads or modifies arg, |
| 13 |
.\" and indent is equivalent to second arg of .IP (shouldn't ever be |
| 14 |
.\" needed; use .AS below instead) |
| 15 |
.\" |
| 16 |
.\" .AS ?type? ?name? |
| 17 |
.\" Give maximum sizes of arguments for setting tab stops. Type and |
| 18 |
.\" name are examples of largest possible arguments that will be passed |
| 19 |
.\" to .AP later. If args are omitted, default tab stops are used. |
| 20 |
.\" |
| 21 |
.\" .BS |
| 22 |
.\" Start box enclosure. From here until next .BE, everything will be |
| 23 |
.\" enclosed in one large box. |
| 24 |
.\" |
| 25 |
.\" .BE |
| 26 |
.\" End of box enclosure. |
| 27 |
.\" |
| 28 |
.\" .CS |
| 29 |
.\" Begin code excerpt. |
| 30 |
.\" |
| 31 |
.\" .CE |
| 32 |
.\" End code excerpt. |
| 33 |
.\" |
| 34 |
.\" .VS ?version? ?br? |
| 35 |
.\" Begin vertical sidebar, for use in marking newly-changed parts |
| 36 |
.\" of man pages. The first argument is ignored and used for recording |
| 37 |
.\" the version when the .VS was added, so that the sidebars can be |
| 38 |
.\" found and removed when they reach a certain age. If another argument |
| 39 |
.\" is present, then a line break is forced before starting the sidebar. |
| 40 |
.\" |
| 41 |
.\" .VE |
| 42 |
.\" End of vertical sidebar. |
| 43 |
.\" |
| 44 |
.\" .DS |
| 45 |
.\" Begin an indented unfilled display. |
| 46 |
.\" |
| 47 |
.\" .DE |
| 48 |
.\" End of indented unfilled display. |
| 49 |
.\" |
| 50 |
.\" .SO ?manpage? |
| 51 |
.\" Start of list of standard options for a Tk widget. The manpage |
| 52 |
.\" argument defines where to look up the standard options; if |
| 53 |
.\" omitted, defaults to "options". The options follow on successive |
| 54 |
.\" lines, in three columns separated by tabs. |
| 55 |
.\" |
| 56 |
.\" .SE |
| 57 |
.\" End of list of standard options for a Tk widget. |
| 58 |
.\" |
| 59 |
.\" .OP cmdName dbName dbClass |
| 60 |
.\" Start of description of a specific option. cmdName gives the |
| 61 |
.\" option's name as specified in the class command, dbName gives |
| 62 |
.\" the option's name in the option database, and dbClass gives |
| 63 |
.\" the option's class in the option database. |
| 64 |
.\" |
| 65 |
.\" .UL arg1 arg2 |
| 66 |
.\" Print arg1 underlined, then print arg2 normally. |
| 67 |
.\" |
| 68 |
.\" .QW arg1 ?arg2? |
| 69 |
.\" Print arg1 in quotes, then arg2 normally (for trailing punctuation). |
| 70 |
.\" |
| 71 |
.\" .PQ arg1 ?arg2? |
| 72 |
.\" Print an open parenthesis, arg1 in quotes, then arg2 normally |
| 73 |
.\" (for trailing punctuation) and then a closing parenthesis. |
| 74 |
.\" |
| 75 |
.\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages. |
| 76 |
.if t .wh -1.3i ^B |
| 77 |
.nr ^l \n(.l |
| 78 |
.ad b |
| 79 |
.\" # Start an argument description |
| 80 |
.de AP |
| 81 |
.ie !"\\$4"" .TP \\$4 |
| 82 |
.el \{\ |
| 83 |
. ie !"\\$2"" .TP \\n()Cu |
| 84 |
. el .TP 15 |
| 85 |
.\} |
| 86 |
.ta \\n()Au \\n()Bu |
| 87 |
.ie !"\\$3"" \{\ |
| 88 |
\&\\$1 \\fI\\$2\\fP (\\$3) |
| 89 |
.\".b |
| 90 |
.\} |
| 91 |
.el \{\ |
| 92 |
.br |
| 93 |
.ie !"\\$2"" \{\ |
| 94 |
\&\\$1 \\fI\\$2\\fP |
| 95 |
.\} |
| 96 |
.el \{\ |
| 97 |
\&\\fI\\$1\\fP |
| 98 |
.\} |
| 99 |
.\} |
| 100 |
.. |
| 101 |
.\" # define tabbing values for .AP |
| 102 |
.de AS |
| 103 |
.nr )A 10n |
| 104 |
.if !"\\$1"" .nr )A \\w'\\$1'u+3n |
| 105 |
.nr )B \\n()Au+15n |
| 106 |
.\" |
| 107 |
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n |
| 108 |
.nr )C \\n()Bu+\\w'(in/out)'u+2n |
| 109 |
.. |
| 110 |
.AS Tcl_Interp Tcl_CreateInterp in/out |
| 111 |
.\" # BS - start boxed text |
| 112 |
.\" # ^y = starting y location |
| 113 |
.\" # ^b = 1 |
| 114 |
.de BS |
| 115 |
.br |
| 116 |
.mk ^y |
| 117 |
.nr ^b 1u |
| 118 |
.if n .nf |
| 119 |
.if n .ti 0 |
| 120 |
.if n \l'\\n(.lu\(ul' |
| 121 |
.if n .fi |
| 122 |
.. |
| 123 |
.\" # BE - end boxed text (draw box now) |
| 124 |
.de BE |
| 125 |
.nf |
| 126 |
.ti 0 |
| 127 |
.mk ^t |
| 128 |
.ie n \l'\\n(^lu\(ul' |
| 129 |
.el \{\ |
| 130 |
.\" Draw four-sided box normally, but don't draw top of |
| 131 |
.\" box if the box started on an earlier page. |
| 132 |
.ie !\\n(^b-1 \{\ |
| 133 |
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' |
| 134 |
.\} |
| 135 |
.el \}\ |
| 136 |
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' |
| 137 |
.\} |
| 138 |
.\} |
| 139 |
.fi |
| 140 |
.br |
| 141 |
.nr ^b 0 |
| 142 |
.. |
| 143 |
.\" # VS - start vertical sidebar |
| 144 |
.\" # ^Y = starting y location |
| 145 |
.\" # ^v = 1 (for troff; for nroff this doesn't matter) |
| 146 |
.de VS |
| 147 |
.if !"\\$2"" .br |
| 148 |
.mk ^Y |
| 149 |
.ie n 'mc \s12\(br\s0 |
| 150 |
.el .nr ^v 1u |
| 151 |
.. |
| 152 |
.\" # VE - end of vertical sidebar |
| 153 |
.de VE |
| 154 |
.ie n 'mc |
| 155 |
.el \{\ |
| 156 |
.ev 2 |
| 157 |
.nf |
| 158 |
.ti 0 |
| 159 |
.mk ^t |
| 160 |
\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' |
| 161 |
.sp -1 |
| 162 |
.fi |
| 163 |
.ev |
| 164 |
.\} |
| 165 |
.nr ^v 0 |
| 166 |
.. |
| 167 |
.\" # Special macro to handle page bottom: finish off current |
| 168 |
.\" # box/sidebar if in box/sidebar mode, then invoked standard |
| 169 |
.\" # page bottom macro. |
| 170 |
.de ^B |
| 171 |
.ev 2 |
| 172 |
'ti 0 |
| 173 |
'nf |
| 174 |
.mk ^t |
| 175 |
.if \\n(^b \{\ |
| 176 |
.\" Draw three-sided box if this is the box's first page, |
| 177 |
.\" draw two sides but no top otherwise. |
| 178 |
.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c |
| 179 |
.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c |
| 180 |
.\} |
| 181 |
.if \\n(^v \{\ |
| 182 |
.nr ^x \\n(^tu+1v-\\n(^Yu |
| 183 |
\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c |
| 184 |
.\} |
| 185 |
.bp |
| 186 |
'fi |
| 187 |
.ev |
| 188 |
.if \\n(^b \{\ |
| 189 |
.mk ^y |
| 190 |
.nr ^b 2 |
| 191 |
.\} |
| 192 |
.if \\n(^v \{\ |
| 193 |
.mk ^Y |
| 194 |
.\} |
| 195 |
.. |
| 196 |
.\" # DS - begin display |
| 197 |
.de DS |
| 198 |
.RS |
| 199 |
.nf |
| 200 |
.sp |
| 201 |
.. |
| 202 |
.\" # DE - end display |
| 203 |
.de DE |
| 204 |
.fi |
| 205 |
.RE |
| 206 |
.sp |
| 207 |
.. |
| 208 |
.\" # SO - start of list of standard options |
| 209 |
.de SO |
| 210 |
'ie '\\$1'' .ds So \\fBoptions\\fR |
| 211 |
'el .ds So \\fB\\$1\\fR |
| 212 |
.SH "STANDARD OPTIONS" |
| 213 |
.LP |
| 214 |
.nf |
| 215 |
.ta 5.5c 11c |
| 216 |
.ft B |
| 217 |
.. |
| 218 |
.\" # SE - end of list of standard options |
| 219 |
.de SE |
| 220 |
.fi |
| 221 |
.ft R |
| 222 |
.LP |
| 223 |
See the \\*(So manual entry for details on the standard options. |
| 224 |
.. |
| 225 |
.\" # OP - start of full description for a single option |
| 226 |
.de OP |
| 227 |
.LP |
| 228 |
.nf |
| 229 |
.ta 4c |
| 230 |
Command-Line Name: \\fB\\$1\\fR |
| 231 |
Database Name: \\fB\\$2\\fR |
| 232 |
Database Class: \\fB\\$3\\fR |
| 233 |
.fi |
| 234 |
.IP |
| 235 |
.. |
| 236 |
.\" # CS - begin code excerpt |
| 237 |
.de CS |
| 238 |
.RS |
| 239 |
.nf |
| 240 |
.ta .25i .5i .75i 1i |
| 241 |
.. |
| 242 |
.\" # CE - end code excerpt |
| 243 |
.de CE |
| 244 |
.fi |
| 245 |
.RE |
| 246 |
.. |
| 247 |
.\" # UL - underline word |
| 248 |
.de UL |
| 249 |
\\$1\l'|0\(ul'\\$2 |
| 250 |
.. |
| 251 |
.\" # QW - apply quotation marks to word |
| 252 |
.de QW |
| 253 |
.ie '\\*(lq'"' ``\\$1''\\$2 |
| 254 |
.\"" fix emacs highlighting |
| 255 |
.el \\*(lq\\$1\\*(rq\\$2 |
| 256 |
.. |
| 257 |
.\" # PQ - apply parens and quotation marks to word |
| 258 |
.de PQ |
| 259 |
.ie '\\*(lq'"' (``\\$1''\\$2)\\$3 |
| 260 |
.\"" fix emacs highlighting |
| 261 |
.el (\\*(lq\\$1\\*(rq\\$2)\\$3 |
| 262 |
.. |
| 263 |
.\" # QR - quoted range |
| 264 |
.de QR |
| 265 |
.ie '\\*(lq'"' ``\\$1''\\-``\\$2''\\$3 |
| 266 |
.\"" fix emacs highlighting |
| 267 |
.el \\*(lq\\$1\\*(rq\\-\\*(lq\\$2\\*(rq\\$3 |
| 268 |
.. |
| 269 |
.\" # MT - "empty" string |
| 270 |
.de MT |
| 271 |
.QW "" |
| 272 |
.. |
| 273 |
.BS |
| 274 |
.SH NAME |
| 275 |
critcl::emap \- CriTcl - Wrap Support - Enum en- and decoding |
| 276 |
.SH SYNOPSIS |
| 277 |
package require \fBTcl 8\&.6\fR |
| 278 |
.sp |
| 279 |
package require \fBcritcl ?3\&.2?\fR |
| 280 |
.sp |
| 281 |
package require \fBcritcl::emap ?1\&.3?\fR |
| 282 |
.sp |
| 283 |
\fB::critcl::emap::def\fR \fIname\fR \fIdefinition\fR ?\fB-nocase\fR? ?\fB-mode\fR \fImode\fR? |
| 284 |
.sp |
| 285 |
.BE |
| 286 |
.SH DESCRIPTION |
| 287 |
.PP |
| 288 |
Be welcome to the \fIC Runtime In Tcl\fR (short: \fICriTcl\fR), a system for embedding and using C |
| 289 |
code from within \fITcl\fR [http://core\&.tcl-lang\&.org/tcl] scripts\&. |
| 290 |
.PP |
| 291 |
This document is the reference manpage for the |
| 292 |
\fBcritcl::emap\fR package\&. This package provides convenience |
| 293 |
commands for advanced functionality built on top of both critcl core |
| 294 |
and package \fBcritcl::iassoc\fR\&. |
| 295 |
.PP |
| 296 |
C level libraries often use enumerations or integer values to encode |
| 297 |
information, like the state of a system\&. Tcl bindings to such libraries now |
| 298 |
have the task of converting a Tcl representation, i\&.e\&. a string into such |
| 299 |
state, and back\&. |
| 300 |
\fINote\fR here that the C-level information has to be something which |
| 301 |
already exists\&. The package does \fInot\fR create these values\&. This is |
| 302 |
in contrast to the package \fBcritcl::enum\fR which creates an |
| 303 |
enumeration based on the specified symbolic names\&. |
| 304 |
.PP |
| 305 |
This package was written to make the declaration and management |
| 306 |
of such enumerations and their associated conversions functions easy, |
| 307 |
hiding all attendant complexity from the user\&. |
| 308 |
.PP |
| 309 |
Its intended audience are mainly developers wishing to write |
| 310 |
Tcl packages with embedded C code\&. |
| 311 |
.PP |
| 312 |
This package resides in the Core Package Layer of CriTcl\&. |
| 313 |
.PP |
| 314 |
.PS |
| 315 |
.nf |
| 316 |
+----------------+ |
| 317 |
|Applications | |
| 318 |
| critcl | |
| 319 |
| critcl::app | |
| 320 |
+----------------+ |
| 321 |
|
| 322 |
*================* |
| 323 |
|Core Packages | |
| 324 |
| critcl | |
| 325 |
| critcl::util | |
| 326 |
*================* |
| 327 |
|
| 328 |
+----------------+ |
| 329 |
|Support Packages| |
| 330 |
| stubs::* | |
| 331 |
| md5, platform | |
| 332 |
| \&.\&.\&. | |
| 333 |
+----------------+ |
| 334 |
|
| 335 |
.fi |
| 336 |
.PE |
| 337 |
.PP |
| 338 |
.SH API |
| 339 |
.TP |
| 340 |
\fB::critcl::emap::def\fR \fIname\fR \fIdefinition\fR ?\fB-nocase\fR? ?\fB-mode\fR \fImode\fR? |
| 341 |
This command defines C functions for the conversion of the \fIname\fRd |
| 342 |
state code into a Tcl string, and vice versa\&. |
| 343 |
The underlying mapping tables are automatically initialized on first |
| 344 |
access (if not fully constant), and finalized on interpreter |
| 345 |
destruction\&. |
| 346 |
.sp |
| 347 |
The \fIdefinition\fR dictionary provides the mapping from the |
| 348 |
Tcl-level symbolic names of the state to their C expressions (often |
| 349 |
the name of the macro specifying the actual value)\&. |
| 350 |
\fINote\fR here that the C-level information has to be something which |
| 351 |
already exists\&. The package does \fInot\fR create these values\&. This is |
| 352 |
in contrast to the package \fBcritcl::enum\fR which creates an |
| 353 |
enumeration based on the specified symbolic names\&. |
| 354 |
.sp |
| 355 |
Further note that multiple strings can be mapped to the same C |
| 356 |
expression\&. When converting to Tcl the first string for the mapping is |
| 357 |
returned\&. An important thing to know: If all C expressions are |
| 358 |
recognizable as integer numbers and their covered range is not too |
| 359 |
large (at most 50) the package will generate code using direct and |
| 360 |
fast mapping tables instead of using a linear search\&. |
| 361 |
.sp |
| 362 |
If the option \fB-nocase\fR is specified then the encoder |
| 363 |
will match strings case-insensitively, and the decoder will always |
| 364 |
return a lower-case string, regardless of the string's case in the |
| 365 |
\fIdefinition\fR\&. |
| 366 |
.sp |
| 367 |
If the option \fB-mode\fR is specified its contents will |
| 368 |
interpreted as a list of access modes to support\&. The two allowed |
| 369 |
modes are \fBc\fR and \fBtcl\fR\&. Both modes can be used |
| 370 |
together\&. The default mode is \fBtcl\fR\&. |
| 371 |
.sp |
| 372 |
The package generates multiple things (declarations and |
| 373 |
definitions) with names derived from \fIname\fR, which has to be a |
| 374 |
proper C identifier\&. Some of the things are generated conditional on |
| 375 |
the chosen \fImode\fRs\&. |
| 376 |
.RS |
| 377 |
.TP |
| 378 |
\fIname\fR_encode |
| 379 |
The \fBtcl\fR-mode function for encoding a Tcl string into the |
| 380 |
equivalent state code\&. |
| 381 |
Its signature is |
| 382 |
.sp |
| 383 |
.CS |
| 384 |
|
| 385 |
|
| 386 |
int \fIname\fR_encode (Tcl_Interp* interp, Tcl_Obj* state, int* result); |
| 387 |
|
| 388 |
.CE |
| 389 |
.sp |
| 390 |
The return value of the function is a Tcl error code, |
| 391 |
i\&.e\&. \fBTCL_OK\fR, \fBTCL_ERROR\fR, etc\&. |
| 392 |
.TP |
| 393 |
\fIname\fR_encode_cstr |
| 394 |
The \fBc\fR-mode function for encoding a C string into the |
| 395 |
equivalent state code\&. |
| 396 |
Its signature is |
| 397 |
.sp |
| 398 |
.CS |
| 399 |
|
| 400 |
|
| 401 |
int \fIname\fR_encode_cstr (const char* state); |
| 402 |
|
| 403 |
.CE |
| 404 |
.sp |
| 405 |
The return value of the function is the encoded state, or -1 if |
| 406 |
the argument is not a vlaid state\&. |
| 407 |
.TP |
| 408 |
\fIname\fR_decode |
| 409 |
The \fBtcl\fR-mode function for decoding a state code into the |
| 410 |
equivalent Tcl string\&. |
| 411 |
Its signature is |
| 412 |
.sp |
| 413 |
.CS |
| 414 |
|
| 415 |
|
| 416 |
Tcl_Obj* \fIname\fR_decode (Tcl_Interp* interp, int state); |
| 417 |
|
| 418 |
.CE |
| 419 |
.TP |
| 420 |
\fIname\fR_decode_cstr |
| 421 |
The \fBc\fR-mode function for decoding a state code into the |
| 422 |
equivalent C string\&. |
| 423 |
Its signature is |
| 424 |
.sp |
| 425 |
.CS |
| 426 |
|
| 427 |
|
| 428 |
const char* \fIname\fR_decode_cstr (int state); |
| 429 |
|
| 430 |
.CE |
| 431 |
.sp |
| 432 |
The return value of the function is the C string for the state, |
| 433 |
or \fBNULL\fR if the \fIstate\fR argument does not contain a valid |
| 434 |
state value\&. |
| 435 |
.TP |
| 436 |
\fIname\fR\&.h |
| 437 |
A header file containing the declarations for the conversion |
| 438 |
functions, for use by other parts of the system, if necessary\&. |
| 439 |
.sp |
| 440 |
The generated file is stored in a place where it will not |
| 441 |
interfere with the overall system outside of the package, yet also be |
| 442 |
available for easy inclusion by package files (\fBcsources\fR)\&. |
| 443 |
.TP |
| 444 |
\fIname\fR |
| 445 |
For mode \fBtcl\fR the command registers a new argument-type for |
| 446 |
\fBcritcl::cproc\fR with critcl, encapsulating the encoder function\&. |
| 447 |
.TP |
| 448 |
\fIname\fR |
| 449 |
For mode \fBtcl\fR the command registers a new result-type for |
| 450 |
\fBcritcl::cproc\fR with critcl, encapsulating the decoder function\&. |
| 451 |
.RE |
| 452 |
.PP |
| 453 |
.SH EXAMPLE |
| 454 |
The example shown below is the specification for the possible modes of |
| 455 |
entry (normal, no feedback, stars) used by the Tcl binding to the |
| 456 |
linenoise library\&. |
| 457 |
.CS |
| 458 |
|
| 459 |
|
| 460 |
package require Tcl 8\&.6 |
| 461 |
package require critcl 3\&.2 |
| 462 |
|
| 463 |
critcl::buildrequirement { |
| 464 |
package require critcl::emap |
| 465 |
} |
| 466 |
|
| 467 |
critcl::emap::def hiddenmode { |
| 468 |
no 0 n 0 off 0 false 0 0 0 |
| 469 |
all 1 yes 1 y 1 on 1 true 1 1 1 |
| 470 |
stars 2 |
| 471 |
} -nocase |
| 472 |
|
| 473 |
# Declarations: hiddenmode\&.h |
| 474 |
# Encoder: int hiddenmode_encode (Tcl_Interp* interp, Tcl_Obj* state, int* result); |
| 475 |
# Decoder: Tcl_Obj* hiddenmode_decode (Tcl_Interp* interp, int state); |
| 476 |
# ResultType: hiddenmode |
| 477 |
# ArgumentType: hiddenmode |
| 478 |
|
| 479 |
.CE |
| 480 |
.SH AUTHORS |
| 481 |
Andreas Kupries |
| 482 |
.SH "BUGS, IDEAS, FEEDBACK" |
| 483 |
This document, and the package it describes, will undoubtedly contain |
| 484 |
bugs and other problems\&. |
| 485 |
Please report such at \fIhttps://github\&.com/andreas-kupries/critcl\fR\&. |
| 486 |
Please also report any ideas for enhancements you may have for either |
| 487 |
package and/or documentation\&. |
| 488 |
.SH KEYWORDS |
| 489 |
C code, Embedded C Code, Tcl Interp Association, bitmask, bitset, code generator, compile & run, compiler, dynamic code generation, dynamic compilation, flags, generate package, linker, on demand compilation, on-the-fly compilation, singleton |
| 490 |
.SH CATEGORY |
| 491 |
Glueing/Embedded C code |
| 492 |
.SH COPYRIGHT |
| 493 |
.nf |
| 494 |
Copyright (c) 2011-2024 Andreas Kupries |
| 495 |
|
| 496 |
.fi |