
# Colour Procedures
proc aqua {} { format %c 3 }
proc blue {} { format %c 5 }
proc black {} { format %c 4 }
proc gray {} { format %c 6 }
proc fuchsia {} { format %c 8 }
proc green {} { format %c 12 }
proc lime {} { format %c 14 }
proc silver {} { format %c 15 }
proc maroon {} { format %c 16 }
proc navy {} { format %c 17 }
proc olive {} { format %c 18 }
proc purple {} { format %c 19 }
proc red {} { format %c 20 }
proc teal {} { format %c 23 }
proc white {} { format %c 24 }
proc yellow {} { format %c 25 }
proc bold {} { format %c 2 }
proc italics {} { format %c 22 }
proc underline {} { format %c 31 }

# Procedure for generating a random number between 0 and x-1
proc rand {x} { expr round(rand() * ($x - 1)) }

# Procedure used by Connect procedure
proc ConfigureSocket { fd } {
  fconfigure $fd -blocking 0 -buffering line
  return $fd
}

# Procedure to connect to a specified host/ip on the specified port via TCP
# Returns the socket id for the connection
proc Connect {host port} {
  if {[catch {socket $host $port} server]} {
    return ""
  }
  return [ConfigureSocket $server]
}

# Procedure to disconnect from a server connected to from the above Connect procedure
# using the specified socket id
proc Disconnect {fd} {
  if {![catch {fileevent $fd readable {}}]} {
    close $fd
  }
}

describe "Miscellaneous Tcl routines required by other scripts."

plinelog "tools.tcl v1.2 now loaded"

