#--------------------------------------------------------------------- # listvars.tcl # Tcl script for IRC bot eggdrop # # Reads in a file with variable names and writes back these varables # names and their values. # # Example of a datafile: # my-ip # admin # network # username # # v0: 05-Feb-2003 #--------------------------------------------------------------------- package require eggdrop 1.6.13 package require Tcl 8.0 # bindings bind dcc m listvars dcc:listvars bind time - * time:listvars proc dcc:listvars { hand idx test } { time:listvars putlog "LISTVARS: Done!" } proc time:listvars { args } { set datafile "listvars.dat" # Part I: reading from file if { ![file exists $datafile] } { putlog "LISTVARS: Error. File $datafile does not exist." return } if { ![file readable $datafile] } { putlog "LISTVARS: Error. File \"$datafile\" is not readable." return } # make a backup # file copy -force $datafile $datafile.bk # open the file for reading set fileid [open $datafile r] # read in the file line by line and scan for variable names while { [gets $fileid line] != -1 } { if { [scan $line %s varname] != 1 } { continue } lappend varlist $varname } close $fileid # found any variable names? if { ![info exists varlist] } { putlog "LISTVARS: Error. List with variables does not exist." return } # Part II: writing to file # file is writeable? if { ![file writable $datafile] } { putlog "LISTVARS: Error. File \"$datafile\" is not writeable." return } # open the file for writing set fileid [open $datafile w] # write variables to file foreach globvarname $varlist { upvar #0 $globvarname globvarval if { ![info exists globvarval] } { putlog "LISTVARS: Warning: $globvarname does not exist or no value set." puts $fileid "$globvarname" } else { puts $fileid "$globvarname $globvarval" } } close $fileid putlog "LISTVARS: written variables to file." } putlog "List variables version 0 loaded."