File: enum.tcl

package info (click to toggle)
critcl 3.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,680 kB
  • sloc: ansic: 41,058; tcl: 12,090; sh: 7,230; pascal: 3,456; asm: 3,058; ada: 1,681; cpp: 1,001; cs: 879; makefile: 333; perl: 104; xml: 95; f90: 10
file content (77 lines) | stat: -rw-r--r-- 1,809 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# bitmap.tcl --
#
#	A template demonstrating the handling of enum conversions.
#
# Copyright (c) 2014,2022 Andreas Kupries <andreas_kupries@users.sourceforge.net>

# # ## ### ##### ######## ############# #####################
## Requirements

package require Tcl          8.6 9
package require critcl       3.1.11
package require critcl::enum 1

# # ## ### ##### ######## ############# #####################
## Administrivia

critcl::license {Andreas Kupries} BSD

critcl::summary {Enum conversion}

critcl::description {
    This package implements nothing. It serves only as a
    demonstration and template on how to declare an enum
    converter and use it in cproc's or ccommand's.
}

critcl::subject demonstration {enum conversion} {encode enum} \
    {decode enum} {convert enum}

# # ## ### ##### ######## ############# #####################
## C code.

critcl::enum::def demo {
    E_global global
    E_exact  exact
    E_filler filler
}

critcl::cproc encode {Tcl_Interp* ip Tcl_Obj* str} int {
    int val;
    demo_GetFromObj (ip, str, 0, &val);
    return val;
}

critcl::cproc decode {Tcl_Interp* ip int val} object {
    Tcl_Obj* res = demo_ToObj (ip, val);
    Tcl_IncrRefCount (res);
    return res;
}

# Encode hidden in the argtype.
critcl::cproc xencode {Tcl_Interp* ip demo str} int {
    return str;
}

# Encode hidden in the argtype.
critcl::cproc xencode-p {Tcl_Interp* ip demo-prefix str} int {
    return str;
}

# Decode hidden in the resultype
critcl::cproc xdecode {Tcl_Interp* ip int val} demo {
    return val;
}

# encode    exact  => 1
# xencode   filler => 2
# xencode-p glob   => 0
# xencode   glob   => /error/

# decode  2 => filler
# xdecode 0 => global
# decode  8 => panic, abort, core dump

# ### ### ### ######### ######### #########
## Ready
package provide enum 1