Tcl's [binary scan] and the Go Challenge 1
4 stars based on
Beside the listed commands for manipulating chemical and non-chemical objects, the standard Tcl scripting interface is enhanced with a collection of additional commands which do not belong to one of the two big groups.
This is a list of these commands:. In addition to these commands, the Tcl math expression engine was extended by the following functions:. This command provides basic functionality for the processing of bit vectors on a string level. Bit vectors understood by this command consist of 0 and 1 characters, optionally prefixed by a percent or B character.
Bitvectors with this encoding style can, for example, be obtained from a Tcl data recall command on chemistry object bitvector data item. These are the standard boolean operations.
If not arguments except the first are given, the result is the input vector for and, or, xorand the inverted input vector for the rest. In case the vectors are of different lengths, they are virtually padded with zero bits to the size of the largest vector.
Return a list of the vector positions starting with 0 which have a set or unset bit. Optionally, an offset for the first bit to be tested, and the maximum number of bits to be tested may be specified. By default, testing begins with the first vector position index 0 and continues until the binary format command in tcl of the vector. The subcommand binary format command in tcl may be abbreviated to test. Generated a new vector of the specified length.
By default, it is set to all zeros. The value parameter, which may be 0 or 1, can be used to generate a vector with all set bits. Perform a screening operation on the bitvector. This command returns the first index position where a bit is set in the second vector, but not in the first. If all set bits in the second vector have counterparts in the first vector, minus one is returned. Count binary format command in tcl total number of set bits in all the specified vectors.
This command reads formatted binary data from an output channel. The specified Tcl channel is automatically configured for binary data for the duration of the command and then restored to the original state. The command is complementary to the bwrite command described below and uses the same formatting specifications.
Multiple values sharing the same format can be read in one statement with a set of recipient variables is specified. The return value is the value of the binary format command in tcl item read. If no variables are used, one item is read and returned, but not stored in a variable. This command writes formatted binary data to an output channel.
If more than one data item is specified, the same format is used for all the data items. For most formats, the binary data layout is not changed and it thus platform-dependent. The exception are those formats which are prefixed with an X: These follow the platform-independent XDR encoding standard Binary format command in tcl in their layout network byte order, MSB firstbut not in the stored item size the byte size of smaller objects binary format command in tcl not expanded to multiples of four.
The following formats are supported:. The string format may contain additional length and pad character specifications. If a pad character is used, it must be supplied as binary format command in tcl ISO Latin code.
This makes it simple to use zero bytes as filler. If it is longer, the extra characters are ignored. A zero byte is not written, because this string has an explicit length. The bread command provides the binary format command in tcl functionality to read binary data into variables binary format command in tcl the same format specifications as template. Decode a color name. On Unix systems, color names are looked up in the local X11 color database.
On the PC platform, a representative X11 color database dump is compiled into the application. In addition to English color names, the standard hex color notation, such as rrggbb or rgb, may be used, with or without alpha channel data.
If a hex color notation has 4, 8 or 16 hex digits, the value is interpreted as rgbarrggbbaa and rrrrggggbbbbaaaarespectively. In case of 12 hex digits 12 is both divisible by 3 and 4the interpretation rrrrggggbbbb takes precedence.
Color names are case-insensitive. By default, a color depth of 16 bits is assumed, and the returned color component values are thus in the range Smaller or larger color component value ranges may be specified by an explicit depth value, which must be in the range between 2 and If the - shade option is used, the decoded color value is darkened or brightened by the specified amount by component-wise addition before it is output in the selected format.
The shading value is scaled according to the selected color depth, i. The transformed color values are automatically clamped to the white and black extremes, so the output will always be a valid color representation.
A shading value of zero has no effect in any color depth. The default return format is a list with the binary format command in tcl RGB values of the decoded color. If the - hex option is set, the output is formatted as a single hex-encoded color value.
If the - alpha option is given, binary format command in tcl format of the output includes the opacity value as the fourth component in RGBA order, either as an additional list element or appended to the hex string.
With the - name option the command attempts to find the most closely matching color name in the database for the decoded and transformed color values and return that name instead of a color component list or hex encoding. The command may also be spelled colour instead of color. Transform the current process into a daemon process which is decoupled from all control terminals and runs in the background until finished or terminated.
The current process is forked, and the old foreground process exited. By default, the background process priority is unchanged. Alternatively, a new priority may be specified as the first optional argument. If it not an empty string, binary format command in tcl attempt is made to set the process priority to the new value.
No error message is generated when the attempt fails. Useful priority values depend on the platform. On Linux, the range is Increasing the priority, by using a value lower than the current process value, requires non-standard permissions, usually an effective application user ID of root. By default, all open file handles are closed.
If the optional closefiles parameter is set to 0, most file handles are kept open. An exception are the standard input, output and error channels. Note that the closing of the file descriptors does not automatically invalidate any Tcl scripting language references to these, such as standard Tcl file or socket handles, or toolkit molfile handles.
These should be explicitly closed by the application script before this function is called. Otherwise, any use of these stale handles results in errors. This command is only available on Unix-based platforms. Binary format command in tcl command decodes a number of commonly encountered encoding formats for string and binary data. The decoded data is returned as command result. The mode parameter decides which decoding scheme is used:.
The return value is a wide integer value with all bits set according to the decoded symbolic value string. If the value cannot be decoded, an error results. An empty value argument always yields zero as result.
The return value is 5, which is combined from set bit index 0 for a and set bit index 2 for c. For bitsets, the first colon-separated word in the enumeration specification contains one or more aliases for zero set bits, which corresponds to the numerical result zero. Instead of a vertical bar, whitespace may also be used as bit position name separators.
The return value is the integer value linked to the symbolic value argument. The returned value is 1, which is the default value of symbolic name bor its alias betataken from its colon-separated word index.
The word index is used in the absence of an explicit value, as it is specified in the example for value c. The decoded data may contain zero-bytes and other special characters and may thus need special care in further processing. The counterpart of the decode command is the encode command, which can be used to encode data in all recognized decoder formats.
This command is the counterpart to the decode command. It is not completely identical, tough - the decoder automatically recognizes certain variants of encoding schemes, which need to be specified in detail on the encoder side. The encoded datam which may be binary, is returned as command result. The possible encoding modes are:.
The result of this command is likely to contain zero bytes and other special characters. Further processing of this data may require caution. Only selected interpreters provide this command, for example the standard tclcactvs and the stand-alone csweb variant. In addition to providing the fcgi command, these interpreters also register additional pre-opened Tcl channels f cgi-stdinfcgi-stdout and fcgi-stderr.
If the redirect flag is set it is set by defaultthe stdoutstderr and stdin Tcl channels are redirected to the corresponding FCGI multiplex socket. The current redirection status is mirrored in the read-only control variable:: If the autoexit flag is set it is also set by defaultthe application automatically exits if the socket communication results in an error or EOF.
The return value is a status code and zero in case a normal communication was initiated. In case automatic exiting is disabled, a negative binary format command in tcl code is returned if there is an error.