FileReadX plugin for Take Command / TCC / TCC/LE

beta version 0.90.5     2024-11-05

Charles Dye

Purpose:

This plugin attempts to reimplement some discontinued former features from Vincent Fatica’s 4UTILS plugin. I am attempting to match his documented syntax fairly closely, but undocumented behaviors, edge conditions, error handling, and so on, are likely to be different.

Installation:

To use this plugin, copy FileReadX.dll to some known location on your hard drive. (If you are still using the 32-bit version of Take Command, take FileReadX-x86.dll instead of FileReadX.dll.) Load the .DLL file with a PLUGIN /L command, for example:

plugin /l c:\bin\tcmd\test\filereadx.dll

If you copy the .DLL file to a subdirectory named PlugIns within your Take Command program directory, the plugin will be loaded automatically when TCC starts.

Plugin Features:

New Commands:
DECINC
New Functions:
@FILEREADI@FILEREADX@FILEWRITEX

Syntax Note:

The syntax definitions in the following text use these conventions for clarity:

BOLD CODEindicates text which must be typed exactly as shown.
CODEindicates optional text, which may be typed as shown or omitted.
Bold italicnames a required argument; a value must be supplied.
Regular italicnames an optional argument.
ellipsis…after an argument means that more than one may be given.

Examples are shown in a gray box:

rem   This is an example:
inc /v count


Some command options take an argument. These are shown with a colon between the option and its argument: /A:arg

If you like, you may substitute an equals sign for the colon: /A=arg This is handy if the arg is a filename, and you want to use tab completion to enter the filename.

Or you can omit the colon: /Aarg

New Commands:

DEC — Decrement an environment variable.

Syntax:
DEC /Q /V /Z varname

/Qquietly — do not display error messages
/Vverbose — display new value
/Ztreat non-numeric variables as zero
varnamethe name of the variable to decrement; required

The variable name varname is required. It may contain letters, digits, dollar signs, hyphens, periods, and underscores; it must not begin with a digit. If the specifed environment variable does not exist, it will be created with a value of -1.

If the environment variable does exist, it should contain:

The updated value will be in the same format as the original value. If the environment variable contains anything other than a number in one of the above formats, INC will give an error unless you also specify /Z.

Decimal values are signed 64-bit integers; hex and octal values are unsigned.

See also: the INC command.



INC — Increment an environment variable.

Syntax:
INC /Q /V /Z varname

/Qquietly — do not display error messages
/Vverbose — display new value
/Ztreat non-numeric variables as zero
varnamethe name of the variable to increment; required

The variable name varname is required. It may contain letters, digits, dollar signs, hyphens, periods, and underscores; it must not begin with a digit. If the specifed environment variable does not exist, it will be created with a value of 1.

If the environment variable does exist, it should contain:

The updated value will be in the same format as the original value. If the environment variable contains anything other than a number in one of the above formats, INC will give an error unless you also specify /Z.

Decimal values are signed 64-bit integers; hex and octal values are unsigned.

See also: the DEC command.



New Functions:

@FILEREADI — Reads and returns variable-sized integers from a file, in a variety of formats.

Syntax:
%@FILEREADI[handle,valsize]

handleas returned by @FILEOPEN
valsizeinteger size in bytes

Handle and valsize are both required. Valsize ranges from 1 to 8. The valsize may optionally be followed by a letter to select the format:

dunsigned decimal integer (the default)
xhexadecimal with leading 0x, lowercase
Xhexadecimal with leading 0x, upperease
hhexadecimal with no prefix, lowercase
Hhexadecimal with no prefix, uppercase
ssigned decimal integer
Ssigned decimal integer, with + for nonnegative values
ooctal with leading 0o

If you do not specify a format, the default is unsigned decimal. If you append an exclamation point to the format, the order of the bytes will be reversed, e.g. 4x! to return a big-endian doubleword in hexadecimal.

If there are fewer than valsize bytes remaining in the file, @FILEREADI returns **EOF**.



@FILEREADX — Reads bytes from a file, and returns them as hexadecimal values.

Syntax:
%@FILEREADX[handle,count,fmt]

handleas returned by @FILEOPEN
countthe maximum number of bytes to return
fmtthe format in which to return values

This function can return up to 4,096 bytes at a time. If you do not specify a count, the default is 1.

If there are fewer than count bytes remaining in the file, @FILEREADX returns only what is there. If there is no more data, @FILEREADX returns **EOF**.

Byte values are separated with spaces. The optional fmt parameter lets you select the format:

0unsigned decimal integers
1hexadecimal with a leading 0x
2hexadecimal with no prefix (the default; suitable for @FILEWRITEX)
3signed decimal integers
4signed decimal integers, with + for nonnegative values
5octal with a leading 0o

See also: the @FILEWRITEX function.



@FILEWRITEX — Writes bytes to a file.

Syntax:
%@FILEWRITEX[handle,val1 val2 val3…]

handleas returned by @FILEOPEN
val1, val2, val3, etc.byte values in hexadecimal

You may provide as many as 4,096 values per call. Each value is one byte; it must be in the range of 0x00 to 0xFF. Values are assumed to be in hexadecimal. A 0x prefix is allowed, but not required.

@FILEWRITEX returns the number of bytes written to the file, or -1 if it fails to write any.

See also: the @FILEREADX function.



Startup Message:

This plugin displays an informational line when it initializes. The message will be suppressed in transient or pipe shells. You can disable it for all shells by defining an environment variable named NOLOADMSG, for example:

set /e /u noloadmsg=1

Changes:


VersionDateChanges
0.90.52024-11-05PLUGIN_BUFFER_MAX is 32K bytes, not 32K characters. @FILEREADX: check for buffer overflow (because it is possible to overflow a 16K buffer).
0.90.42024-10-14Tweaks to the help text; no changes to operation.
0.90.32024-10-11First release.

Status and Licensing:

Consider this beta software. It may well have issues. Try it at your own risk. If you find a problem, you can report it in the JP Software support forum.

FileReadX is currently licensed only for testing purposes. I may make binaries and source code available under some free license once I consider it ready for use.

Download:

You can download the current version of this plugin from https://charlesdye.net/dl/filereadx.zip.