# HG changeset patch # User Matti Hamalainen # Date 1315510012 -10800 # Node ID 7b03971c6d286738b7d9ec6c10091a8ed7df75b9 # Parent 6428b1bcb34ba9a59bc94ae560d4df01ff3bf2ab Remove tabs and reindent. diff -r 6428b1bcb34b -r 7b03971c6d28 convert_spede_mn_tuksu.tcl --- a/convert_spede_mn_tuksu.tcl Thu Sep 08 22:23:33 2011 +0300 +++ b/convert_spede_mn_tuksu.tcl Thu Sep 08 22:26:52 2011 +0300 @@ -10,8 +10,8 @@ ### Check commandline arguments if {$argc != 3} { - puts "Usage: $argv0 " - exit 0 + puts "Usage: $argv0 " + exit 0 } set db_input [lindex $argv 0] @@ -23,13 +23,13 @@ puts "NOTICE! This WILL destroy the current data in table '$db_table'!" if {![confirm_yesno "Proceed"]} { - exit 0 + exit 0 } ### Open flatfile for reading if {[catch {set fd [open $db_input r]} uerrmsg]} { - puts "Could not open file '$db_input' for reading: $uerrmsg" - exit 1 + puts "Could not open file '$db_input' for reading: $uerrmsg" + exit 1 } ### Open SQLite database, drop old tables, create new @@ -42,22 +42,22 @@ set nline 0 seek $fd 0 start while {![eof $fd]} { - incr nline - set line [gets $fd] - if {$line != ""} { - set items [split $line "|"] - set host [lindex $items 3] - set uid [lindex $items 4] - set sql "INSERT INTO $db_table (id,utime,utext,user,host,chan) VALUES ([lindex $items 0], [lindex $items 2], '[lescape $items 1]', '[lescape $items 3]', '[lescape $items 4]', '[lescape $items 5]')" - if {[catch {dbh eval $sql} uerrmsg]} { - puts "\nError ($nline): $uerrmsg on:\n$sql" - exit 15 - } - } - if {[expr $nline % 10] == 1} { - puts -nonewline "." - flush stdout - } + incr nline + set line [gets $fd] + if {$line != ""} { + set items [split $line "|"] + set host [lindex $items 3] + set uid [lindex $items 4] + set sql "INSERT INTO $db_table (id,utime,utext,user,host,chan) VALUES ([lindex $items 0], [lindex $items 2], '[lescape $items 1]', '[lescape $items 3]', '[lescape $items 4]', '[lescape $items 5]')" + if {[catch {dbh eval $sql} uerrmsg]} { + puts "\nError ($nline): $uerrmsg on:\n$sql" + exit 15 + } + } + if {[expr $nline % 10] == 1} { + puts -nonewline "." + flush stdout + } } dbh close diff -r 6428b1bcb34b -r 7b03971c6d28 convert_urllog_db.tcl --- a/convert_urllog_db.tcl Thu Sep 08 22:23:33 2011 +0300 +++ b/convert_urllog_db.tcl Thu Sep 08 22:26:52 2011 +0300 @@ -10,8 +10,8 @@ ### Check commandline arguments if {$argc != 2} { - puts "Usage: $argv0 " - exit 0 + puts "Usage: $argv0 " + exit 0 } set db_input [lindex $argv 0] @@ -23,13 +23,13 @@ puts "NOTICE! This WILL destroy the current data in table '$db_table'!" if {![confirm_yesno "Proceed"]} { - exit 0 + exit 0 } ### Open flatfile for reading if {[catch {set fd [open $db_input r]} uerrmsg]} { - puts "Could not open '$db_input' for reading: $uerrmsg" - exit 1 + puts "Could not open '$db_input' for reading: $uerrmsg" + exit 1 } ### Open SQLite database, drop old table, create new @@ -43,20 +43,20 @@ set minentries 9999 set maxentries 0 while {![eof $fd]} { - incr nline - set line [gets $fd] - if {$line != ""} { - set items [split $line " "] - set tmp [llength $items] - if {$tmp > $maxentries} { set maxentries $tmp } - if {$tmp < $minentries} { set minentries $tmp } - } + incr nline + set line [gets $fd] + if {$line != ""} { + set items [split $line " "] + set tmp [llength $items] + if {$tmp > $maxentries} { set maxentries $tmp } + if {$tmp < $minentries} { set minentries $tmp } + } } if {$maxentries != 5 || $maxentries != $minentries} { - puts "old / variable" + puts "old / variable" } else { - puts "new" + puts "new" } ### Show some information @@ -67,27 +67,27 @@ set nline 0 seek $fd 0 start while {![eof $fd]} { - incr nline - set line [gets $fd] - set items [split $line " "] - if {$line != ""} { - set host [lindex $items 3] - if {[regexp {^\((.+)\)$} $host ures uhost]} { - set host $uhost - } - set uid [lindex $items 4] - if {$uid != ""} { - set sql "INSERT INTO $db_table (id,utime,url,user,host) VALUES ($uid, [lindex $items 1], '[lescape $items 0]', '[lescape $items 2]', '[escape $host]')" - if {[catch {dbh eval $sql} uerrmsg]} { - puts "\nError ($nline): $uerrmsg on:\n$sql" - exit 15 - } - } - } - if {[expr $nline % 10] == 1} { - puts -nonewline "." - flush stdout - } + incr nline + set line [gets $fd] + set items [split $line " "] + if {$line != ""} { + set host [lindex $items 3] + if {[regexp {^\((.+)\)$} $host ures uhost]} { + set host $uhost + } + set uid [lindex $items 4] + if {$uid != ""} { + set sql "INSERT INTO $db_table (id,utime,url,user,host) VALUES ($uid, [lindex $items 1], '[lescape $items 0]', '[lescape $items 2]', '[escape $host]')" + if {[catch {dbh eval $sql} uerrmsg]} { + puts "\nError ($nline): $uerrmsg on:\n$sql" + exit 15 + } + } + } + if {[expr $nline % 10] == 1} { + puts -nonewline "." + flush stdout + } } puts "OK" @@ -95,27 +95,27 @@ set nline 0 seek $fd 0 start while {![eof $fd]} { - incr nline - set line [gets $fd] - set items [split $line " "] - if {$line != ""} { - set host [lindex $items 3] - if {[regexp {^\((.+)\)$} $host ures uhost]} { - set host $uhost - } - set uid [lindex $items 4] - if {$uid == ""} { - set sql "INSERT INTO $db_table (utime,url,user,host) VALUES ([lindex $items 1], '[lescape $items 0]', '[lescape $items 2]', '[escape $host]')" - if {[catch {dbh eval $sql} uerrmsg]} { - puts "\nError ($nline): $uerrmsg on:\n$sql" - exit 15 - } - } - } - if {[expr $nline % 10] == 1} { - puts -nonewline "." - flush stdout - } + incr nline + set line [gets $fd] + set items [split $line " "] + if {$line != ""} { + set host [lindex $items 3] + if {[regexp {^\((.+)\)$} $host ures uhost]} { + set host $uhost + } + set uid [lindex $items 4] + if {$uid == ""} { + set sql "INSERT INTO $db_table (utime,url,user,host) VALUES ([lindex $items 1], '[lescape $items 0]', '[lescape $items 2]', '[escape $host]')" + if {[catch {dbh eval $sql} uerrmsg]} { + puts "\nError ($nline): $uerrmsg on:\n$sql" + exit 15 + } + } + } + if {[expr $nline % 10] == 1} { + puts -nonewline "." + flush stdout + } } dbh close diff -r 6428b1bcb34b -r 7b03971c6d28 create_spede_mn_tuksu.tcl --- a/create_spede_mn_tuksu.tcl Thu Sep 08 22:23:33 2011 +0300 +++ b/create_spede_mn_tuksu.tcl Thu Sep 08 22:26:52 2011 +0300 @@ -13,40 +13,40 @@ ### Check commandline arguments set db_str [join $db_list ", "] if {$argc < 1} { - puts "Creates tables for $db_str target SQLite3 file" - puts "Usage: $argv0 \[-drop\]" - puts "" - puts "-drop option will drop any existing tables of same name." - exit 0 + puts "Creates tables for $db_str target SQLite3 file" + puts "Usage: $argv0 \[-drop\]" + puts "" + puts "-drop option will drop any existing tables of same name." + exit 0 } set db_drop 0 set db_output [lindex $argv 0] if {$argc >= 2 && [lindex $argv 1] == "-drop"} { - set db_drop 1 + set db_drop 1 } ### Open database open_db $db_output if {$db_drop} { - puts "WARNING! Dropping of old tables $db_str requested!" - puts "All data in those tables will be permanently lost!" + puts "WARNING! Dropping of old tables $db_str requested!" + puts "All data in those tables will be permanently lost!" - if {![confirm_yesno "Proceed"]} { - puts "Aborting procedure." - dbh close - exit 0 - } + if {![confirm_yesno "Proceed"]} { + puts "Aborting procedure." + dbh close + exit 0 + } - foreach i $db_list { - drop_table $i - } + foreach i $db_list { + drop_table $i + } } puts "Creating tables $db_str ..." foreach i $db_list { - create_table_quotes_votes $i 0 + create_table_quotes_votes $i 0 } dbh close diff -r 6428b1bcb34b -r 7b03971c6d28 create_urllog_db.tcl --- a/create_urllog_db.tcl Thu Sep 08 22:23:33 2011 +0300 +++ b/create_urllog_db.tcl Thu Sep 08 22:26:52 2011 +0300 @@ -9,33 +9,33 @@ ### Check commandline arguments if {$argc < 1} { - puts "Creates tables for URLLog target SQLite3 file" - puts "Usage: $argv0 \[-drop\]" - puts "" - puts "-drop option will drop any existing URLLog tables." - exit 0 + puts "Creates tables for URLLog target SQLite3 file" + puts "Usage: $argv0 \[-drop\]" + puts "" + puts "-drop option will drop any existing URLLog tables." + exit 0 } set db_drop 0 set db_output [lindex $argv 0] if {$argc >= 2 && [lindex $argv 1] == "-drop"} { - set db_drop 1 + set db_drop 1 } ### Open database open_db $db_output if {$db_drop} { - puts "WARNING! Dropping old tables URLLog requested!" - puts "All data in those tables will be permanently lost!" + puts "WARNING! Dropping old tables URLLog requested!" + puts "All data in those tables will be permanently lost!" - if {![confirm_yesno "Proceed"]} { - puts "Aborting procedure." - dbh close - exit 0 - } + if {![confirm_yesno "Proceed"]} { + puts "Aborting procedure." + dbh close + exit 0 + } - drop_table "urls" + drop_table "urls" } create_table_urls diff -r 6428b1bcb34b -r 7b03971c6d28 hae_feedit.tcl --- a/hae_feedit.tcl Thu Sep 08 22:23:33 2011 +0300 +++ b/hae_feedit.tcl Thu Sep 08 22:26:52 2011 +0300 @@ -28,57 +28,57 @@ package require http ::http::config -urlencoding iso8859-1 -useragent "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.0) Opera 9.5" if {$http_proxy != 0} { - ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port + ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port } proc convert_ent {udata} { - global html_ent - return [string map $html_ent $udata] + global html_ent + return [string map $html_ent $udata] } proc add_entry {uname uprefix uurl udesc} { - global entries isentries newurls currclock - set utest "$uprefix[convert_ent $uurl]" - set isentries($utest) 1 - if {[catch {set utmp $entries($utest)}]} { - set entries($utest) [list $currclock $uname $utest [convert_ent $udesc]] - incr newurls - } + global entries isentries newurls currclock + set utest "$uprefix[convert_ent $uurl]" + set isentries($utest) 1 + if {[catch {set utmp $entries($utest)}]} { + set entries($utest) [list $currclock $uname $utest [convert_ent $udesc]] + incr newurls + } } proc add_rss_feed {datauri dataname dataprefix} { - if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { - puts "Error getting $datauri: $uerrmsg" - return 1 - } - set upage [::http::data $utoken] - ::http::cleanup $utoken - - set umatches [regexp -all -nocase -inline -- ".\*\?<..CDATA.(.\*\?)\\\]\\\]>.\*\?(http.\*\?).\*\?" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] - } - - if {$nmatches == 0} { - set umatches [regexp -all -nocase -inline -- ".\*\?(.\*\?).\*\?(http.\*\?).\*\?" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] - } - } + if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { + puts "Error getting $datauri: $uerrmsg" + return 1 + } + set upage [::http::data $utoken] + ::http::cleanup $utoken + + set umatches [regexp -all -nocase -inline -- ".\*\?<..CDATA.(.\*\?)\\\]\\\]>.\*\?(http.\*\?).\*\?" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] + } + + if {$nmatches == 0} { + set umatches [regexp -all -nocase -inline -- ".\*\?(.\*\?).\*\?(http.\*\?).\*\?" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] + } + } - if {$nmatches == 0} { - set umatches [regexp -all -nocase -inline -- "\]*>.\*\?(.\*\?).\*\?(http.\*\?).\*\?" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] - } - } - return 0 + if {$nmatches == 0} { + set umatches [regexp -all -nocase -inline -- "\]*>.\*\?(.\*\?).\*\?(http.\*\?).\*\?" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname $dataprefix [lindex $umatches [expr $n+2]] [lindex $umatches [expr $n+1]] + } + } + return 0 } @@ -87,16 +87,16 @@ set oldurls 0 set newurls 0 if {![catch {set ufile [open $datafile r 0600]} uerrmsg]} { - while {![eof $ufile]} { - gets $ufile uline - set urec [split $uline "½"] - if {[llength $urec] == 4} { - set entries([lindex $urec 2]) $urec - set isentries([lindex $urec 2]) 0 - incr oldurls - } - } - close $ufile + while {![eof $ufile]} { + gets $ufile uline + set urec [split $uline "½"] + if {[llength $urec] == 4} { + set entries([lindex $urec 2]) $urec + set isentries([lindex $urec 2]) 0 + incr oldurls + } + } + close $ufile } set currclock [clock seconds] @@ -106,22 +106,22 @@ set datauri "http://www.halla-aho.com/scripta/"; set dataname "Mestari" if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { - puts "Error getting $datauri: $uerrmsg" + puts "Error getting $datauri: $uerrmsg" } else { - set upage [::http::data $utoken] - ::http::cleanup $utoken - - set umatches [regexp -all -nocase -inline -- "(\[^<\]+)" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] - } + set upage [::http::data $utoken] + ::http::cleanup $utoken + + set umatches [regexp -all -nocase -inline -- "(\[^<\]+)" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] + } - set umatches [regexp -all -nocase -inline -- "(\[^<\]\[^b\]\[^<\]+)" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] - } + set umatches [regexp -all -nocase -inline -- "(\[^<\]\[^b\]\[^<\]+)" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname $datauri [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] + } } @@ -129,16 +129,16 @@ set datauri "http://www.peldor.com/chapters/index_sidebar.html"; set dataname "The Adventurers" if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { - puts "Error getting $datauri: $uerrmsg" + puts "Error getting $datauri: $uerrmsg" } else { - set upage [::http::data $utoken] - ::http::cleanup $utoken - - set umatches [regexp -all -nocase -inline -- "(\[^<\]+)" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname "http://www.peldor.com/" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] - } + set upage [::http::data $utoken] + ::http::cleanup $utoken + + set umatches [regexp -all -nocase -inline -- "(\[^<\]+)" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname "http://www.peldor.com/" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] + } } @@ -146,16 +146,16 @@ set datauri "http://www.giantitp.com/comics/oots.html"; set dataname "OOTS" if {[catch {set utoken [::http::geturl $datauri -binary true -timeout 5000]} uerrmsg]} { - puts "Error getting $datauri: $uerrmsg" + puts "Error getting $datauri: $uerrmsg" } else { - set upage [::http::data $utoken] - ::http::cleanup $utoken - - set umatches [regexp -all -nocase -inline -- "(\[^<\]+)" $upage] - set nmatches [llength $umatches] - for {set n 0} {$n < $nmatches} {incr n 3} { - add_entry $dataname "http://www.giantitp.com" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] - } + set upage [::http::data $utoken] + ::http::cleanup $utoken + + set umatches [regexp -all -nocase -inline -- "(\[^<\]+)" $upage] + set nmatches [llength $umatches] + for {set n 0} {$n < $nmatches} {incr n 3} { + add_entry $dataname "http://www.giantitp.com" [lindex $umatches [expr $n+1]] [lindex $umatches [expr $n+2]] + } } @@ -176,19 +176,19 @@ ### Avataan tulostiedosto set tmpfname "$datafile.tmp" if {[catch {set outfile [open $tmpfname w 0600]} uerrmsg]} { - puts "Error opening $tmpfname for writing: $uerrmsg" - return 1 + puts "Error opening $tmpfname for writing: $uerrmsg" + return 1 } set uexpire [expr [clock seconds] - (7*24*60*60)] foreach {ukey udata} [array get entries] { -# if {$isentries($ukey) != 0 || [lindex $udata 0] >= $uexpire} { - puts $outfile [join $udata "½"] -# } +# if {$isentries($ukey) != 0 || [lindex $udata 0] >= $uexpire} { + puts $outfile [join $udata "½"] +# } } close $outfile if {[catch {file rename -force -- $tmpfname $datafile} uerrmsg]} { - puts "Error renaming $tmpfname to $datafile: $uerrmsg" + puts "Error renaming $tmpfname to $datafile: $uerrmsg" } #puts "$newurls new entries." diff -r 6428b1bcb34b -r 7b03971c6d28 hae_ruoka.tcl --- a/hae_ruoka.tcl Thu Sep 08 22:23:33 2011 +0300 +++ b/hae_ruoka.tcl Thu Sep 08 22:26:52 2011 +0300 @@ -67,8 +67,8 @@ foreach {ukey udata} $umat { set item [string trim [convert_ent $udata]] if {[string length $item] > 0} { - lappend tmp $item - } + lappend tmp $item + } } add_entry $dataname [lindex $umatches 1] [lindex $umatches 2] [join $tmp "; "] } @@ -100,8 +100,8 @@ foreach {ukey udata} $umat { set item [string trim [convert_ent $udata]] if {[string length $item] > 0} { - lappend tmp $item - } + lappend tmp $item + } } add_entry $dataname [lindex $umatches 1] [lindex $umatches 2] [join $tmp "; "] } diff -r 6428b1bcb34b -r 7b03971c6d28 hae_saatiedot.tcl --- a/hae_saatiedot.tcl Thu Sep 08 22:23:33 2011 +0300 +++ b/hae_saatiedot.tcl Thu Sep 08 22:26:52 2011 +0300 @@ -17,29 +17,29 @@ package require http ::http::config -urlencoding iso8859-1 -useragent "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.0) Opera 9.5" if {$use_proxy != 0} { - ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port + ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port } ############################################################################## proc fetch_uri {uurl} { - global ngot - if {[catch {set utoken [::http::geturl $uurl -binary true -timeout 5000]} uerrmsg]} { - puts "Error getting #$uurl: $uerrmsg" - return "" - } else { - incr ngot - set udata [::http::data $utoken] - ::http::cleanup $utoken - return $udata - } + global ngot + if {[catch {set utoken [::http::geturl $uurl -binary true -timeout 5000]} uerrmsg]} { + puts "Error getting #$uurl: $uerrmsg" + return "" + } else { + incr ngot + set udata [::http::data $utoken] + ::http::cleanup $utoken + return $udata + } } ############################################################################## set tmpfname "$datafile.tmp" if {[catch {set savefile [open $tmpfname w 0600]} uerrmsg]} { - puts "Error opening $tmpfname: $uerrmsg" - return 1 + puts "Error opening $tmpfname: $uerrmsg" + return 1 } # Haetaan 22 framea osoitteista @@ -48,15 +48,15 @@ # ja talletetaan kaikki samaan tiedostoon set ngot 0 for { set i 1 } { $i < 23 } { incr i } { - puts $savefile [fetch_uri "http://alk.tiehallinto.fi/alk/tiesaa/tiesaa_maak_$i.html"] + puts $savefile [fetch_uri "http://alk.tiehallinto.fi/alk/tiesaa/tiesaa_maak_$i.html"] } #set paske [fetch_uri "http://www.wunderground.com/global/stations/56294.html"] close $savefile if {$ngot > 5} { - if {[catch {file rename -force -- $tmpfname $datafile} uerrmsg]} { - puts "Error renaming $tmpfname to $datafile: $uerrmsg" - } + if {[catch {file rename -force -- $tmpfname $datafile} uerrmsg]} { + puts "Error renaming $tmpfname to $datafile: $uerrmsg" + } } diff -r 6428b1bcb34b -r 7b03971c6d28 laske.tcl --- a/laske.tcl Thu Sep 08 22:23:33 2011 +0300 +++ b/laske.tcl Thu Sep 08 22:26:52 2011 +0300 @@ -45,8 +45,8 @@ # ------------------------------------------------------------------------- proc laske_pubmsg {nick uhost hand chan args} { if {$args == {} || $args == ""} { - laske_smsg $chan "Laa laalis paski." - return 1 + laske_smsg $chan "Laa laalis paski." + return 1 } set result [laske_do $args] @@ -57,8 +57,8 @@ # ------------------------------------------------------------------------- proc laske_msg {nick uhost hand args} { if {$args == {} || $args == ""} { - laske_smsg $nick "Laa laalis paski." - return 1 + laske_smsg $nick "Laa laalis paski." + return 1 } set result [laske_do $args] diff -r 6428b1bcb34b -r 7b03971c6d28 util_convert.tcl --- a/util_convert.tcl Thu Sep 08 22:23:33 2011 +0300 +++ b/util_convert.tcl Thu Sep 08 22:26:52 2011 +0300 @@ -1,70 +1,70 @@ ### Helper functions proc escape { str } { - return [string map {' ''} $str] + return [string map {' ''} $str] } proc lescape { lst pos } { - return [escape [lindex $lst $pos]] + return [escape [lindex $lst $pos]] } proc confirm_yesno { uprompt } { - puts -nonewline "$uprompt \[y/N\]? " - flush stdout - set response [gets stdin] - if {[string tolower $response] == "y"} { - return 1 - } else { - return 0 - } + puts -nonewline "$uprompt \[y/N\]? " + flush stdout + set response [gets stdin] + if {[string tolower $response] == "y"} { + return 1 + } else { + return 0 + } } proc open_db { dbfile } { - global dbh - if {[catch {sqlite3 dbh $dbfile} uerrmsg]} { - puts "Could not open SQLite3 database '$dbfile': $uerrmsg." - exit 2 - } + global dbh + if {[catch {sqlite3 dbh $dbfile} uerrmsg]} { + puts "Could not open SQLite3 database '$dbfile': $uerrmsg." + exit 2 + } } proc drop_table { utable } { - global dbh - puts "Dropping current table '$utable'." - if {[catch {dbh eval "DROP TABLE $utable"} uerrmsg]} { - puts "Dropping table resulted in error (ignored): $uerrmsg." - } + global dbh + puts "Dropping current table '$utable'." + if {[catch {dbh eval "DROP TABLE $utable"} uerrmsg]} { + puts "Dropping table resulted in error (ignored): $uerrmsg." + } } proc create_table { utable usql } { - global dbh - puts "Creating new table '$utable'." - if {[catch {dbh eval "CREATE TABLE $utable ($usql)"} uerrmsg]} { - puts "Error creating table: $uerrmsg." - return 0 - } - return 1 + global dbh + puts "Creating new table '$utable'." + if {[catch {dbh eval "CREATE TABLE $utable ($usql)"} uerrmsg]} { + puts "Error creating table: $uerrmsg." + return 0 + } + return 1 } proc create_table_or_fail { utable usql } { - if {![create_table $utable $usql]} { - exit 3 - } + if {![create_table $utable $usql]} { + exit 3 + } } proc create_table_urls { } { - create_table_or_fail "urls" "id INTEGER PRIMARY KEY AUTOINCREMENT, utime INT, url VARCHAR(2048), user VARCHAR(32), host VARCHAR(256), chan VARCHAR(32), title VARCHAR(256)" + create_table_or_fail "urls" "id INTEGER PRIMARY KEY AUTOINCREMENT, utime INT, url VARCHAR(2048), user VARCHAR(32), host VARCHAR(256), chan VARCHAR(32), title VARCHAR(256)" } proc create_table_quotes_votes { utable ufail } { - - set sql1 "id INTEGER PRIMARY KEY AUTOINCREMENT, utime INT, utext VARCHAR(2048), user VARCHAR(32), host VARCHAR(256), chan VARCHAR(32)" - set sql2 "id INTEGER PRIMARY KEY AUTOINCREMENT, user VARCHAR(32), urlid INTEGER, vote INTEGER" + + set sql1 "id INTEGER PRIMARY KEY AUTOINCREMENT, utime INT, utext VARCHAR(2048), user VARCHAR(32), host VARCHAR(256), chan VARCHAR(32)" + set sql2 "id INTEGER PRIMARY KEY AUTOINCREMENT, user VARCHAR(32), urlid INTEGER, vote INTEGER" - if {$ufail} { - create_table_or_fail "$utable" "$sql1" - create_table_or_fail "${utable}_votes" "$sql2" - } else { - create_table "$utable" "$sql1" - create_table "${utable}_votes" "$sql2" - } + if {$ufail} { + create_table_or_fail "$utable" "$sql1" + create_table_or_fail "${utable}_votes" "$sql2" + } else { + create_table "$utable" "$sql1" + create_table "${utable}_votes" "$sql2" + } }