1 Star 0 Fork 0

SR达人/msteveb_jimtcl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
make-c-ext.tcl 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env tclsh
# Usage: make-c-ext.tcl source.tcl >jim-source.c
# Converts a Tcl source file into C source suitable
# for loading as a static extension.
lassign $argv source
if {![string match *.tcl $source]} {
error "Source $source is not a .tcl file"
}
# Read the Tcl source and convert to C
# Note that no lines are removed in order to preserve line numbering
set sourcelines {}
set f [open $source]
while {[gets $f buf] >= 0} {
# Remove comment lines
regsub {^[ \t]*#.*$} $buf "" buf
# Escape quotes and backlashes and remove carriage returns
set buf [string map [list \\ \\\\ \" \\" \r ""] $buf]
lappend sourcelines \"$buf\\n\"
}
close $f
lappend lines {/* autogenerated - do not edit */}
lappend lines {#include <jim.h>}
set basename [file tail $source]
set pkgname [file rootname $basename]
lappend lines "int Jim_${pkgname}Init(Jim_Interp *interp)"
lappend lines "\{"
lappend lines "\tif (Jim_PackageProvide(interp, \"$pkgname\", \"1.0\", JIM_ERRMSG)) return JIM_ERR;"
lappend lines "\treturn Jim_EvalSource(interp, \"$basename\", 1, [join $sourcelines \n]);"
lappend lines "\}"
puts [join $lines \n]
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sr-master/msteveb_jimtcl.git
git@gitee.com:sr-master/msteveb_jimtcl.git
sr-master
msteveb_jimtcl
msteveb_jimtcl
master

搜索帮助