From: <si...@us...> - 2006-05-29 13:56:25
|
Revision: 879 Author: sickpig Date: 2006-05-29 06:56:13 -0700 (Mon, 29 May 2006) ViewCVS: http://svn.sourceforge.net/yaacs/?rev=879&view=rev Log Message: ----------- * Fix a bug on getList * indent plus remove trailing space Modified Paths: -------------- trunk/yaacs/yamisc.tcl Modified: trunk/yaacs/yamisc.tcl =================================================================== --- trunk/yaacs/yamisc.tcl 2006-05-29 13:54:56 UTC (rev 878) +++ trunk/yaacs/yamisc.tcl 2006-05-29 13:56:13 UTC (rev 879) @@ -19,45 +19,50 @@ # Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA namespace eval ::yamisc { - namespace export calc_cod_fisc check_user_connection conf_priorita getIp ifconfig verifyDate onValidatePhone onValidateLength disjoin + namespace export * # calc_cod_fisc error-codes - + variable ERRMSG variable ERR - variable ERR_NOCOM 1 - variable ERR_SURALG 2 - variable ERR_NAMALG 3 + variable ERR_NOCOM 1 + variable ERR_SURALG 2 + variable ERR_NAMALG 3 variable ERR_BADDATE 4 } proc ::yamisc::logFax {db fax proj uid rid} { - set sql "insert into log.fax (fax,proj,uid,status,rid,touch) values ('$fax', $proj, $uid, true, $rid, now())"; + set sql "insert into log.fax (fax,proj,uid,status,rid,touch) values ('$fax', $proj, $uid, true, $rid, now())" return [list [::yadb::execl $db $sql] "Ok"] -} +} proc ::yamisc::logEmail {db email proj uid rid com} { set sql "insert into log.email (addr,proj,uid,status,rid,send_time,cod_com) \ - values ('$email', $proj, $uid, True, $rid, now(), $com)"; - ::yadb::execl $db $sql -} + values ('$email', $proj, $uid, True, $rid, now(), $com)" + ::yadb::execl $db $sql +} # give back len list contains all the # field value for each tuple of table # -#@param db - db conn handler -#@param table - a db table +#@param db - db conn handler +#@param table - a db table #@param field - a table's field +#@param ofi - order by field #@return a list -proc ::yamisc::getList {db table field} { - pg_select $db "Select $field from $table " rec { +proc ::yamisc::getList {db table field {ofi ""}} { + set sql "Select $field from $table " + set orderby "" + if {$ofi ne ""} { set orderby " order by $ofi"} + set sql "$sql$orderby" + pg_select $db $sql rec { lappend alist $rec([set field]) } return $alist -} +} # Try to find every IP addres configured # for each eth device (execept for lo) @@ -67,12 +72,12 @@ if {$::tcl_platform(platform) eq "windows"} { return [regexp -inline {\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}} [exec ipconfig] ] - } else { + } else { variable iplist {} - + set buffer [exec /sbin/ifconfig] set scan "inet addr:" - + set addrlist {} foreach line [split $buffer \n] { if [regexp HWaddr $line] { @@ -81,14 +86,14 @@ if ![regexp $scan $line] continue set s [expr [string first $scan $line 0] + [string length $scan]] set f [expr [string first " " $line $s] - 1] - set addr [string range $line $s $f] + set addr [string range $line $s $f] - if { $addr != "127.0.0.1" } { - lappend addrlist $addr + if { $addr != "127.0.0.1" } { + lappend addrlist $addr } - } - return [lindex $addrlist 2] - } + } + return [lindex $addrlist 2] + } } @@ -98,9 +103,9 @@ # @param state state's id (on db's table) which you want to know priority # @return The state's priority (it's an integer). On error -1 is returned. proc ::yamisc::conf_priorita {db state} { - set prio_sql "select prio from projects.outcomes where ouid=$state" - set priority [yadb::getTuple $db $prio_sql 0]; - return [lindex $priority 0]; + set prio_sql "select prio from projects.outcomes where ouid=$state" + set priority [yadb::getTuple $db $prio_sql 0]; + return [lindex $priority 0]; } @@ -205,10 +210,10 @@ #try to calc name regsub -all B|C|D|F|G|H|L|M|N|P|Q|R|S|T|V|Z|J|K|W|X|Y [string toupper $name] "" oe; - regsub -all A|E|I|O|U [string toupper $name] "" nm; + regsub -all A|E|I|O|U [string toupper $name] "" nm; - set numvocali [string length $oe]; - set numconsonanti [string length $nm] + set numvocali [string length $oe]; + set numconsonanti [string length $nm] if { ($numconsonanti==0 && $numvocali!=2) || ($numconsonanti==1 && $numvocali==0) || \ ($numconsonanti==2 && $numvocali<1)} { @@ -345,47 +350,47 @@ proc ::yamisc::verifyDate {date} { set lst [split $date '/'] set dd [lindex $lst 0] - set mm [lindex $lst 1] - set yy [lindex $lst 2] + set mm [lindex $lst 1] + set yy [lindex $lst 2] - if {[regexp {^[0-9]+$} $mm]==0 || $mm <1 || $mm >12} { - return 0 - } + if {[regexp {^[0-9]+$} $mm]==0 || $mm <1 || $mm >12} { + return 0 + } - if {[regexp {^[0-9]+$} $yy]==0 ||$yy <1970} { - return 0 - } + if {[regexp {^[0-9]+$} $yy]==0 ||$yy <1970} { + return 0 + } if { [expr $yy % 400]==0 } { set feb 29 } elseif { [expr $yy % 100]==0} { set feb 28 } elseif { [expr $yy % 4]==0 } { - set feb 29 - } else { - set feb 28 - } + set feb 29 + } else { + set feb 28 + } - set dm "31 $feb 31 30 31 30 31 31 30 31 30 31" + set dm "31 $feb 31 30 31 30 31 31 30 31 30 31" if { [regexp {^[0-9]+$} $dd]==0 } { return 0 } - if { $dd == 1 } { - set max_d 0 - } else { - set max_d [expr 3*($mm -1)] - } + if { $dd == 1 } { + set max_d 0 + } else { + set max_d [expr 3*($mm -1)] + } - set max_dd [expr $max_d+1] - set max [string range $dm $max_d $max_dd] + set max_dd [expr $max_d+1] + set max [string range $dm $max_d $max_dd] - if { $dd <1 || $dd > $max } { - return 0 - } + if { $dd <1 || $dd > $max } { + return 0 + } - return 1 + return 1 } # Ensure that the inputed chars are @@ -396,7 +401,7 @@ # @param max string len # @return True if is a valid char, False otherwise proc ::yamisc::onValidateLength {char len} { - if { [llength $char] != 0 } { + if { [llength $char] != 0 } { if { [string length "$char"] <= $len } { return 1; @@ -404,9 +409,9 @@ return 0; } - } else { + } else { return 1 - } + } } # ::yamisc::disjoin remove from the first list elements that are in the second one @@ -506,12 +511,12 @@ proc ::yamisc::hostSettings {db ip} { set res [::yadb::getTuple $db "select hostname, room, voip, mac \ from log.host_location where ip='$ip'" 0] - + if {$res == -1} { ::yalog::error "cannot retrieve settings for host $ip" return -1 - } - + } + set voip [lindex $res 2] if {$voip eq "t"} { set voip 1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |