14-Dec 15:59 UTC [0.07] 13.494k | Script Library: 1241 scripts Documentation for: glb.r
TITLE
Global services module
SUMMARY
This is a file of functions that are so common that practically every
other script will use them.
DOCUMENTATION
Include this module in your program as follows:
do %glb.r
Then use the procedures as necessary. The services available are:
GLB-NOW: This is a word that references the date and time your program
started running.
GLB-YYYYMMDD: This is a string containing the current date in yyyymmdd
format.
GLB-MMDDYY: This is a string containing the current date in mmddyy
format.
GLB-HHMMDD: This is the current time in hhmmss format. This, and
the above two dates, can be useful for date-time stamps.
GLB-SUBSTRING input-string start-position end-position
This is a function that returns a substring of the string provided
as input.
Along with the input string, provide a starting position
and an ending position. If the ending position is -1, the procedure
will return a substring to the end of the input string. It actually
is not much more complicated to use regular commands to do this operation.
I just can't remember how. Note that the parameters are not a starting
position and a length, but a starting position and an ending position.
GLB-BASE-FILENAME input-file-name
This procedure accepts a file name (a string or a file name) as a
parameter and returns everything except the "extension" which is
the stuff after a dot. The procedure assumes it is getting a name
in the common format of a bunch of stuff, a single dot, and the a
short extension like txt, html, and so on. The purpose of this procedure
is to get that base name so that you can add your own extension.
GLB-FILLER number-of-spaces
This procedure returns a string that is all spaces, with a length
equal to the number-of-spaces parameter supplied to the procedure.
The original use of this procedure was for building up fixed-length
lines.
GLB-ZEROFILL input-string final-size
This is a procedure that was created for taking any input number
and creating a fixed-length number with an assumed decimal point.
In other words, it strips out every character except the digits,
and pads it on the left with leading zeros. This makes a "cobol-like"
number out of a "display-like" number.
GLB-SPACEFILL input-string final-size
This procedure accepts a string and trims the leading spaces, and
pads it with trailing spaces out to the indicated length. It was
created for making fixed-format lines.
GLB-TRACE-EMIT block-of-anything
This procedre accepts a block of anything that the caller might want
to put into a trace file. The procedure will reduce the block and
add a sequence number, and then store it in a larger block. This
larger block will eventually contain only the last 100 items added
to it, since after each call the procedure chops off the oldest entry
(if there are more than 100). This procedure is mainly a debugging
tool.
If your script crashes somewhere, start tracing at some appropriate
point, get the script to halt, and then examine what you have traced.
GLB-TRACE-PRINT
This procedure will display the contents of the trace block you built
up with repeated calls of GLB-TRACE-EMIT.
GLB-TRACE-SAVE
This procedure will convert the trace block to a series of text lines
and save it in a file. The file has a default name which you may
change by change the value of GLB-TRACE-FILE-ID.
GLB-LOG-EMIT log-file-name logging-data
This procedure, copied from the rebol cookbook, accepts a file name
and a string or block of anything, and adds that anything to the
end of the indicated file. The purpose of this procedure is to write
to any specified log file.
GLB-PAUSE pause-prompt
This procedure will cause your script to stop, display the pause-prompt,
and wait for you to type something. At this point, you should some
rebol command which the procedure will try to execute. Normally,
that would be some command to view the values of words in your script,
in an attempt to track down a bug.
GLB-COPY-DIR source-dir/ destination-dir/
This procedure recursively copies the source-dir to the destination-dir.
|