#! @TCLSH@
set file [lindex $argv 0]
set days [lindex $argv 1]
set user [lrange $argv 2 end]
set module [file dirname $argv0]

set now [exec @DATE@ +%s]
set match 0

if {![file exists $file]} {
  set FILE [open $file w]
} else {
  set FILE [open $file r]
  set line [gets $FILE]
  if {$days != "once"} {
    set cont 1
    while {![eof $FILE] && $cont} {
      set list [split $line :]
      set sec [lindex $list 0]
      if {[expr ($now-$sec)/(3600*24)] >= $days} {
        set line [gets $FILE]
      } else {
        set cont 0
      }
    }
  }

  set newList ""
  while {![eof $FILE]} {
    append newList $line\n
    if {!$match} {
      set list [split $line :]
      if {[lindex $list 1] == $user} {
        set match 1
      }
    }
    set line [gets $FILE]
  }
  close $FILE
  set FILE [open $file w]
  puts -nonewline $FILE $newList
}
if {!$match} {
  puts $FILE "$now:$user"
  close $FILE
}
exit [expr !$match]
