#!/usr/bin/wish
#
#  Make a little window showing the date; the way I like it.
#

option add "*font" "-adobe-helvetica-bold-r-*-*-10-*-*-*-*-*-*-*"
option add "*background" "white"
option add "*foreground" "black"

proc update {} {
    global the_day the_date gf_ddmmm gf_yyyy

    set date_info [clock format [clock seconds] -format "%A %e %b %y"]
    set the_day [lindex $date_info 0]
    set the_day [string range $the_day 0 2]
    set the_date [lrange $date_info 1 end]

    set gf_nc [string length $the_date]
    set gf_yy [string range $the_date [expr $gf_nc - 2] [expr $gf_nc - 1]]
    if {$gf_yy > 50} {
	set gf_yyyy 19
    } else {
	set gf_yyyy 20
    }
    append gf_yyyy $gf_yy
    set gf_ddmmm [string range $the_date 0 [expr $gf_nc - 4]]

    after 60000 update
}


for {set i 0} {$i < $argc} {incr i} {
    set arg [lindex $argv $i]

    switch -exact -- $arg {
	"-fg" {
	    option add "*foreground" [lindex $argv [expr $i + 1]]
	    incr i
	}
	"-bg" {
	    option add "*background" [lindex $argv [expr $i + 1]]
	    incr i
	}
	"-fn" {
	    option add "*font" [lindex $argv [expr $i + 1]]
	    incr i
	}
	"-geometry" {
	    incr i
	}
	default {
	    puts stderr "Unknown argument: $arg"
	}
    }

}

pack [frame .f] -fill both -expand 1
pack [label .f.l1 -textvariable the_day] -fill both -side top
pack [label .f.l3 -textvariable gf_yyyy] -fill both -side bottom
pack [label .f.l2 -textvariable gf_ddmmm] -fill both -side bottom
update
