-
Notifications
You must be signed in to change notification settings - Fork 0
/
support.tcl
138 lines (120 loc) · 3.54 KB
/
support.tcl
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# -*- tcl -*-
# CRIMP Build Support Code
#
# (c) 2011-2016 Andreas Kupries http://wiki.tcl.tk/andreas%20kupries
# # ## ### ##### ######## #############
## Operator definitions
proc crimp_primitive {name args result body} {
critcl::at::caller
critcl::at::incrt $name
critcl::at::incrt $args
set bodylocation [critcl::at::get*]
set args [linsert $args 0 Tcl_Interp* interp]
::critcl::cproc ::crimp::$name $args $result $bodylocation$body
}
# # ## ### ##### ######## #############
## Sourcing by patterns
proc crimp_source {args} {
set rej {}
set glob glob
foreach pattern $args {
if {[string match !* $pattern]} {
lappend rej [string range $pattern 1 end]
} else {
lappend glob $pattern
}
}
foreach path [lsort -dict [eval $glob]] {
if {[crimp_Rejected $rej $path]} continue
#critcl::msg -nonewline " \[[file rootname [file tail $path]]\]"
critcl::msg -nonewline .
critcl::source $path
}
return
}
proc crimp_Rejected {patterns path} {
foreach pattern $patterns {
if {[string match $pattern $path]} { return 1 }
}
return 0
}
# # ## ### ##### ######## #############
## Custom image argument and result types.
apply {{} {
# Skip if already done
if {[critcl::has-argtype image]} return
foreach type {
rgba rgb hsv
grey8 grey16 grey32
bw float fpcomplex
} {
set map [list <<type>> $type]
critcl::argtype image_$type [string map $map {
if (crimp_get_image_from_obj (interp, @@, &@A) != TCL_OK) {
return TCL_ERROR;
}
if (@A->itype != crimp_imagetype_find ("crimp::image::<<type>>")) {
Tcl_SetObjResult (interp,
Tcl_NewStringObj ("expected image type <<type>>",
-1));
return TCL_ERROR;
}
}] crimp_image* crimp_image*
critcl::argtype image_obj_$type [string map $map {
if (crimp_get_image_from_obj (interp, @@, &@A.i) != TCL_OK) {
return TCL_ERROR;
}
if (@A.i->itype != crimp_imagetype_find ("crimp::image::<<type>>")) {
Tcl_SetObjResult (interp,
Tcl_NewStringObj ("expected image type <<type>>",
-1));
return TCL_ERROR;
}
@A.o = @@;
}] crimp_image_obj crimp_image_obj
# Note, the support structure is shared with image_obj below,
# and the guard is specified to reflect that.
critcl::argtypesupport image_obj_$type {
typedef struct crimp_image_obj {
Tcl_Obj* o;
crimp_image* i;
} crimp_image_obj;
} image_obj
}
critcl::argtype image {
if (crimp_get_image_from_obj (interp, @@, &@A) != TCL_OK) {
return TCL_ERROR;
}
} crimp_image* crimp_image*
critcl::argtype image_obj {
if (crimp_get_image_from_obj (interp, @@, &@A.i) != TCL_OK) {
return TCL_ERROR;
}
@A.o = @@;
} crimp_image_obj crimp_image_obj
# Note, the support structure is shared with image_obj_<<type>>
# above, and the guard above was specified to match us here.
critcl::argtypesupport image_obj {
typedef struct crimp_image_obj {
Tcl_Obj* o;
crimp_image* i;
} crimp_image_obj;
} image_obj
critcl::resulttype image {
if (rv == NULL) { return TCL_ERROR; }
Tcl_SetObjResult (interp, crimp_new_image_obj(rv));
return TCL_OK;
} crimp_image*
critcl::resulttype image_type {
Tcl_SetObjResult (interp, crimp_new_imagetype_obj(rv));
return TCL_OK;
} {const crimp_imagetype*}
critcl::argtype photo {
@A = Tk_FindPhoto(interp, Tcl_GetString(@@));
if (!@A) {
Tcl_AppendResult(interp, "image \"", Tcl_GetString(@@), "\" doesn't exist", NULL);
return TCL_ERROR;
}
} Tk_PhotoHandle Tk_PhotoHandle
}}
# # ## ### ##### ######## #############