Chinaunix首页 | 论坛 | 博客
  • 博客访问: 392593
  • 博文数量: 77
  • 博客积分: 2031
  • 博客等级: 大尉
  • 技术积分: 855
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 19:54
文章分类

全部博文(77)

文章存档

2011年(1)

2009年(52)

2008年(24)

我的朋友

分类: LINUX

2008-10-23 21:24:00

代码见下,比较简单,就不再分析了。调用实例见前面的文章。

#************************************************
# get a line from file, skip blank lines and
# comment lines, return the reading line in
# parameter 'line'.
#
# @PARAMS
# fd     - file fd
# line   - var used to return the line
#
# @RETURN
# return 1 if read successfully, otherwise 0
#************************************************
proc getLine {fd line} {
    upvar $line ln

    # read a line from fd
    while {[set lineLen [gets $fd ln]] >= 0} {
        # blank line
        if { $lineLen == 0 } continue
 
        # trim whitespace
        set ln [string trim $ln]
        if { [string length $ln] == 0 } continue

        # skip comment
        if { [string index $ln 0] == "#" } continue

        # success
        return 1
    }

    return 0
}
阅读(1970) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~