TABLE OF CONTENTS


::pwtk::readFile

SYNOPSIS

proc ::pwtk::readFile {args} {

USAGE

    ::pwtk::readFile ?-nonewline? filename

DESCRIPTION

Read a file and return its content. If the -nonewline switch is specified then the last character of the file is discarded if it is a newline.

RETURN VALUE

The content of the file.

SOURCE

    set filename [lindex $args end]
    ::pwtk::fileMustExist $filename
    set fID [open $filename r]

    if { [llength $args] == 1 } {
        set opt {}
    } elseif { [llength $args] == 2 && [lindex $args 0] == "-nonewline" } {
        set opt -nonewline
    } else {
        ::pwtk::error "wrong usage: must be \"readFile ?-nonewline? filename\", but got: $args" 1
    }
    set output [eval read $opt $fID]
    close $fID

    return $output
}