下了windows的安装包。
一、在wish85里运行一下简单的测试。e:/tcl/test.tcl
%source e:/tcl/test.tcl
目录的斜杠方向跟UNIX一样哦。
test.tcl 内容
proc tgrep {pattern filename } {
set f [open $filename r]
while {[gets $f line]} {
if {[regexp $pattern $line]} {
puts stdout $line
} else {
puts "not found $pattern."
}
}
close $f
}
tgrep word e:/tcl/test.txt
因为while {[gets $f line]} ,gets读取一行并返回该行的字符数,文件尾返回-1,所以这种格式的判断,遇到空白行就停止循环了,后面的行不在读入。
另外,如果最后一行之后没有回车,有时候wish85控制台就没有响应,呆在那不动弹了。加上回车就好了。但这种情况也不是每次都出现。也有可能是别的原因。
二、在VC用TCL库函数写TCLsh解释器。
主要碰到的问题是老提示TCL_init()没有定义。发现原因是虽然包含了tcl.h等头文件,但是没有加入tcl85.lib.
VC中要把tcl.h,tcl85.lib加入到工程,并且在tools,options里的derictiories加入两个文件的路径。
#include "tcl.h"
#include "stdio.h"
#include "stdlib.h"
int Tcl_AppInit(Tcl_Interp *interp);
main(int argc, char *argv[])
{
Tcl_Main(argc, argv,Tcl_AppInit);
exit(0);
}
int Tcl_AppInit(Tcl_Interp *interp)
{
if (Tcl_Init(interp) == TCL_ERROR)
{
return TCL_ERROR;
}
return TCL_OK;
}
发现这个链接有很详细的介绍。
http://www.51testing.com/?uid-35-action-viewspace-itemid-11699