Showing posts with label tclsh. Show all posts
Showing posts with label tclsh. Show all posts

Saturday, March 08, 2014

[TCL] Love that Tool Command Language

TCL is just so cool and concise …
cd CSV
set target "snap-[clock format [clock add [clock seconds] -1 hours] -format %Y-%m-%d-%H -gmt 1]"
if {![file exists $target.rar]} then {
    set cmd [list c:/program\ files/winrar/rar.exe m -m5 -s ${target}.rar ${target}-utc.csv]
        exec -- {*}$cmd
}
That goes to the log (called CSV) folder and compresses the previous hour’s worth of log. I run that from a scheduler.

I really like the conciseness of Tcl: clock add [clock seconds] -1 hours, which subtracts an hour from the current time and clock format which takes that and renders it as GMT.

© Copyright Bruce M. Axtens, 2014

Sunday, May 14, 2006

[News] Working again ...

... at Lion Nathan's Swan Brewery.

Thanks, by the way, to all the visitors who keep my stats at an average of 10 visits per week.

More code is in the works: a tcl archive exploder, and a Sudoku solver written as an HTA.

Don't hold your breath!

Thursday, August 11, 2005

Cygwin, bash, grep, gawk, tclsh, VBScript

What a combination!! I've found Cygwin enormously helpful. Take the following snippet for example, which extracts the names of all the Subs and Functions from my library file into a file, and then hands that file on to a tcl script.
#!/bin/bash
grep -i '^Function ' StdFunctions.vbs >func.lst
grep -i '^Sub ' StdFunctions.vbs >> func.lst
cat func.lst | gawk -F " " '{ print $2 }' | gawk -F "(" '{ print $1 }' > Routines.lst
rm func.lst
tclsh routines.tcl
The output file, Routines.lst, looks like this (partially)
CreateMDB
OpenDatabase
OpenDatabase2
SelectSheet
GetColumnDownToEnd
GetColumnDownToLimit
RangeToArray
VectorToTwoDimArray
RelativeToAbsolute
MakeKey3
MakeKey4
TimeStamp
Zerofill
IsFile
IsINISection
GetINIString
Routines.tcl takes this, and an internally specified list of files to check (which I could have coded so as to specify on the commandline) and then tells me whether any of these routines are referred to in the list of files.
#!/bin/tclsh
set mm 0

proc searchFile {theFile theString} {
#puts "Searching $theFile for $theString"
set h [open $theFile r]
set d [split [read $h] \n]
close $h
set c 0
set m 0
foreach dline $d {
incr c
if {[string match -nocase "*${theString}*" $dline] == 1} then {
  set m 1
  #puts "$theFile $c: $dline"
}
}
return $m
}

set vlist [list Create.vbs Daily.vbs NewBatchPrepare.vbs convert.vbs]

set h [open Routines.lst r]
set flist [split [read $h] \n]
close $h

foreach fitem $flist {
if { $fitem == "" } { continue }
set mm 0

foreach vfile $vlist {
if { $vfile == "" } { continue }
#puts "To search for $fitem in $vfile"
set r [searchFile $vfile $fitem]
if {$r == 0} {
  #puts "No sign of $fitem in $vfile"
}
set mm [expr {$mm + $r}]
}
if { $mm < 1 } {
   puts "No sign at all of $fitem"
}
}
It's not foolproof. Some routines are used internally by StdFunctions.vbs. But it's helpful.