beetlebug▾
/

option readfile

Adds the entries of a file to the option database.

option readfile FILENAME ?PRIORITY?

Description

Each line of the file is an entry: a pattern, a colon, and a value. The spaces after the colon are not part of the value. A line that starts with ! is a comment, and an empty line is skipped. Each entry gets PRIORITY, interactive by default.

The file opens through the file commands of the script, so it needs the file capability, and in the jail of a root folder the path is from the root.

Arguments

ArgumentTypeDefaultDescription
FILENAMEpathrequiredThe path of the file of entries.
PRIORITYpriorityinteractiveThe priority of each entry, as for option add.

Returns

An empty string.

Examples

% set f [file tempfile path]
> puts $f "! The colors of the app\n*Button.foreground: green"
> close $f
> option readfile $path
> file delete $path
> button .r
> .r cget -foreground
green

Errors

% set f [file tempfile path]
> puts $f "no colon here"
> close $f
> option readfile $path
missing colon on line
-errorcode NONE

% option readfile /nonexistent/app.txt
couldn't open "/nonexistent/app.txt": no such file or directory
-errorcode POSIX ENOENT {no such file or directory}

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also