2
# # ## ### ##### ######## ############# #####################
3
# Pragmas for MetaData Scanner.
6
# CriTcl Utility Commands.
8
package provide critcl::util 1
10
# # ## ### ##### ######## ############# #####################
13
package require Tcl 8.4 ; # Min supported version.
16
package require critcl 3
18
package require critcl 2.1 ; # Only this and higher has the enhanced check, and checklink.
21
namespace eval ::critcl::util {}
23
# # ## ### ##### ######## ############# #####################
24
## Implementation -- API: Embed C Code
26
proc ::critcl::util::checkfun {name {label {}}} {
28
if {$label eq {}} { set label "Checking for function '$name'" }
29
return [critcl::checklink $label [string map [list @@@ $name] $cftemplate]]
32
proc ::critcl::util::def {configfile define {value 1}} {
33
set result [file join [critcl::cache] [file tail $configfile]]
35
Put $result "[Get $result]\n\#define $define $value\n"
39
proc ::critcl::util::undef {configfile define} {
40
set result [file join [critcl::cache] [file tail $configfile]]
42
Put $result "[Get $result]\n\#undef $define\n"
46
# # ## ### ##### ######## ############# #####################
48
proc ::critcl::util::Get {path} {
59
proc ::critcl::util::Put {path data} {
60
# Write changes back, via temp file. Commit via atomic rename.
61
set c [open $path.[pid] w]
62
puts -nonewline $c $data
64
file rename -force $path.[pid] $path
68
# # ## ### ##### ######## ############# #####################
71
namespace eval ::critcl::util {
73
/* The header <limits.h> may declare @@@. To avoid a clash
74
* redefine it to something aside. As an example, gettimeofday()
75
* is declared in the <limits.h> provided by HP-UX 11i. Regardless,
76
* we pull in a system header defining the __stub macros, and a
77
* few prototypes only possibly in conflict with @@@, we hope.
78
* As <limits.h> exists even on free-standing compilers its use
79
* is preferred when __STDC__ is active.
82
#define @@@ innocuous_@@@
90
/* Next up a declaration to override whatever internal prototype
91
* was declared by GCC, to prevent an error. As the return type
92
* 'int' might match such a GCC builtin, and thus causing the application
93
* of the argument prototype despite this we use 'char' instead.
101
/* Lastly the GNU libc defines a few special names for its functions,
102
* these will always fail with ENONSYS. Further, some functions
103
* actually start with __, with the normal name (we are looking for)
104
* an alias of it. Regardless, for these we bail.
107
#if defined __stub_@@@ || defined __stub___@@@
120
# # ## ### ##### ######## ############# #####################
123
namespace eval ::critcl::util {
124
namespace export checkfun def undef
125
catch { namespace ensemble create }
128
# # ## ### ##### ######## ############# #####################