home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
STRLIST
/
STRLIST.DOC
< prev
next >
Wrap
Text File
|
1992-03-11
|
7KB
|
168 lines
STRLIST.DOC -- Turbo Pascal 6.0 String List Resource
by Wilbert van Leijen
*** Released into the Public Domain ***
Description
-----------
STRLIST takes an ASCII file as input and converts it to an object
file, linkable to a TP 6.0 program.
STRLIST interprets the ASCII file to be a list of strings,
each on a separate line.
STRLIST aides you to store lists of strings efficiently in your
application; e.g. error messages or pick-list data. This utility
overcomes the drawbacks of storing static data that, when put in
an array of String[nn] would waste considerable data space, or
when looked up using a Case statement, would unnecessarily increase
code size.
Usage
-----
Call STRLIST from the DOS command line as follows:
STRLIST source[.LST] object[.OBJ] PublicName [/option]
whereby:
"source": file name of the ASCII input file (default extension: .LST)
"object": file name of the output file (default extension: .OBJ)
"PublicName": identifier (symbolic name) of the string list
"option": one of the following:
/A make list of ASCIIZ (null-terminated) strings
/P make list of length-byte (Pascal) strings
/S as with /P, but returned differently
/9 make list of "$" terminated strings and display them
on the screen using DOS call 9
The first three arguments are required. If "option" is omitted,
it takes "/P" as the default value.
The input file
--------------
The input file must be a plain ASCII file.
Each line is treated as an entry in the string list and can therefore
be up to 255 characters long.
Leading and trailing spaces on a line are stripped from a string.
STRLIST has limited parsing capabilities:
- If the first non-blank character is a ";" (semi-colon), STRLIST will
interpret this as a line containing a comment, and will skip this
line.
- If a line is empty or contains only spaces, it will be ignored and
no string is added to the list. Hence, the minimum length of any
string is 1.
- Special characters can be put in a string by prefixing them with
the "\" (backslash) character. STRLIST recognises the following
special characters:
\\ Single backslash
\A ASCII 7 (Bell) character
\B ASCII 8 (Backspace) character
\F ASCII 12 (Form feed) character
\N ASCII 10 (Line feed) character
\R ASCII 13 (Carriage return) character
\T ASCII 9 (Horizontal tab) character
\V ASCII 11 (Vertical tab) character
\Xnn Hexadecimal character, whereby "nn" must be 2 digits
Example: \X20 is a space; \X1A means EOF;
\X00 is the null character
When STRLIST interprets special characters, case is not important.
\x20Example of a string with leading space, \a beep and cr-lf\r\n
; This is a comment. Next line has a string of length 1
\x00
The output file
---------------
The .OBJ file STRLIST generates is linkable to a TP 6.0 program.
STRLIST will always export two FAR callable routines; the name
of these routines depends on what you specify under "PublicName".
Both routines must be declared FAR. Failure to do so might
result in a system crash.
No matter what option you choose, the first exported identifier
will always be of the format "PublicNameCount". This function
returns the number of strings in the list.
Note that since TP 6.0, the declaration in the calling Pascal program
of all public routines in an .OBJ is not mandatory. If you wish,
you can omit the declaration of "PublicNameCount".
Note also that the list is "1-based": if you call "Publicname",
the first entry in the list is 1 (rather than zero). For speed's
sake, "PublicName" does NOT perform any range checking!
/A option (list of ASCIIZ strings):
Function PublicNameCount : Integer; Far; External;
Function PublicName(i : Integer) : Pointer; Far; External;
PublicName returns a pointer to the i-th ASCIIZ string.
/P option (list of Pascal strings):
Function PublicNameCount : Integer; Far; External;
Function PublicName(i : Integer) : String; Far; External;
PublicName returns the i-th string in the list.
As with all Pascal functions returning strings, the result is
left on the stack.
/S option (list of Pascal strings):
Function PublicNameCount : Integer; Far; External;
Function PublicName(i : Integer) : Pointer; Far; External;
PublicName returns the address of the i-string in the list.
One way to call PublicName is: String(PublicName(i)^);
/9 option (display string using DOS call 9):
Function PublicNameCount : Integer; Far; External;
Procedure PublicName(i : Integer); Far; External;
PublicName displays the i-th string on the screen. The output
is redirectable.
When we ignore the information any object file must pass to the linker,
the .OBJ file generated by STRLIST consists of these 3 parts:
- the code of the exported routines
These are between 27 and 34 bytes in size
- the string list
The strings are stored contiguously, without "slack bytes"
- the index to the string list
A lookup table, its Pascal declaration would be:
Array[1..entries] of Word
All data resides in the CODE segment.
Limitations
-----------
- STRLIST can generate an .OBJ file of up to 64kB in size. Object
files larger than 65520 bytes cannot be linked with TP 6.0 anyhow.
- The maximum number of strings in the list is limited to 8192.
- The maximum number of bytes in the whole string list must not
exceed a number something less than 64000 minus the size of the
lookup table (2 times the number of strings), since beside the
loader code, the string list and the index to the string list,
some space must be set aside for internal .OBJ file housekeeping
purposes.
- When put in an unit, the string list can be safely overlaid,
provided that any other code in this unit adheres to the guidelines
regarding overlays, as spelled out in the TP 6.0 Programmer's Guide.
Author
------
Wilbert van Leijen (Wilbert van.Leijen at Fido 2:500/12.10956)
Marathonweg 72-2
1076 TM Amsterdam
The Netherlands