File: hanno.tcl

package info (click to toggle)
tix 8.4.3-4
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 8,448 kB
  • ctags: 6,844
  • sloc: ansic: 28,077; tcl: 22,774; python: 7,577; makefile: 332; cs: 253; sh: 185; perl: 128
file content (69 lines) | stat: -rw-r--r-- 1,385 bytes parent folder | download | duplicates (6)
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
#
#	$Id: hanno.tcl,v 1.1.1.1 2000/05/17 11:08:53 idiscovery Exp $
#
#!/bin/sh
# the next line restarts using tixwish \
exec tclsh7.6 "$0" "$@"

# Options
#
#	-v : Verbose mode. Print out what hanno is doing.
#
set verbose 0

if {[info exists env(TIX_VERBOSE)] && $env(TIX_VERBOSE) == 1} {
    set verbose 1
}

if {[lsearch -glob $argv -v*] != -1} {
    set verbose 1
}

set files [exec find . -name *.html -print]

foreach file $files {
    if {$verbose} {
	puts "\[html anno]: checking $file"
    }
    set output {}
    set src [open $file RDONLY]

    set changed 1

    while {![eof $src]} {
	set line [gets $src]

	if {[regexp -nocase {[ \t]*\<hr>\<i>Last modified.*} $line]} {
	    # Do nothing
	} elseif {[regexp -nocase {[ \t]*\<i>Serial.*\</i>} $line]} {
	    if {[scan $line "<i>Serial %d</i>" lastmtime] == 1} {
		if {[expr [file mtime $file] - $lastmtime] >= 10} {
		    set changed 1
		} else {
		    set changed 0
		}
	    }
	} else {
	    append output $line\n
	}
    }
    close $src

    if {$changed == 1} {
	if {$verbose} {
	    puts "\[html anno]: modifying tag of $file"
	}

	set date [clock format [file mtime $file]]

	set des [open $file {WRONLY TRUNC}]
	puts -nonewline $des $output

	# Somehow the "seek" is necessary
	#
	seek $des -1 current
	puts $des "<hr><i>Last modified $date </i> --- "
	puts $des "<i>Serial [file mtime $file]</i>"
	close $des
    }
}