Posted to tcl by patthoyts at Thu Jul 27 09:37:22 GMT 2006view pretty
# From tkabber - plugins/iq/version.tcl proc try_linux_version {distr file flag} { global linux_distribution if {![file exists $file]} { return } if {![file readable $file]} { set linux_distribution $distr return } set fd [open $file r] set content [read $fd] close $fd set last [string first "\n" $content] if {$last < 0} { set last end } else { set last [expr {$last - 1}] } set line [string range $content 0 $last] switch -- $flag { file { set linux_distribution $line } append { set linux_distribution "$distr $line" } } } proc guess_linux_distribution {} { global linux_distribution if {[info exists linux_distribution]} { return $linux_distribution } foreach {distr file flag} { \ "SuSE Linux" /etc/SuSE-release file \ "Debian GNU/Linux" /etc/debian_version append \ "ASPLinux" /etc/asplinux-release file \ "Alt Linux" /etc/altlinux-release file \ "PLD Linux" /etc/pld-release file \ "Gentoo Linux" /etc/gentoo-release file \ "Mandrake Linux" /etc/mandrake-release file \ "RedHat Linux" /etc/redhat-release file \ "Conectiva Linux" /etc/conectiva-release file \ "Slackware Linux" /etc/slackware-version append } { try_linux_version $distr $file $flag if {[info exists linux_distribution]} { return $linux_distribution } } set linux_distribution Linux return $linux_distribution }