2021-09-21 00:54:24 +00:00
|
|
|
Common String Handling Functions for C02
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
Strings are zero-terminated arrays of type char with a maximum length
|
|
|
|
of 128 characters.
|
|
|
|
|
|
|
|
The first character in a string is at position 0, and the last character
|
|
|
|
is at position length minus 1.
|
|
|
|
|
|
|
|
Since all of the routines stop processing at the 128th character, a 128
|
2021-09-04 22:58:29 +00:00
|
|
|
character string does not require a zero terminator, and any character
|
|
|
|
array with length[128] will not overflow.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
Due to the limitations of parameter passing in C02, the argument lists of
|
2021-09-04 22:58:29 +00:00
|
|
|
most of these functions do not match those in standard C and C++.
|
|
|
|
|
|
|
|
For functions that operate on two string, one of the strings is specified
|
2021-09-21 00:54:24 +00:00
|
|
|
using the setdst() function from module stddef. Unless otherwise noted,
|
|
|
|
none of the functions change dstptr.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
Usage: at the beginning of the program use the directives
|
|
|
|
|
2018-08-02 09:10:14 +00:00
|
|
|
#include <stddef.h02>
|
2018-01-28 19:00:23 +00:00
|
|
|
#include <string.h02>
|
|
|
|
|
|
|
|
The following functions are defined:
|
|
|
|
|
2021-09-04 22:58:29 +00:00
|
|
|
n = strlen(s); Returns length of string.
|
|
|
|
|
2021-09-21 00:54:24 +00:00
|
|
|
Note: Sets srcptr to &s.
|
2021-09-04 22:58:29 +00:00
|
|
|
|
2021-09-21 00:54:24 +00:00
|
|
|
n = strchr(c, s); Searches string s for character c.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
Returns position of first occurance of character
|
|
|
|
in string, or 255 if character was not found.
|
|
|
|
|
2021-09-21 00:54:24 +00:00
|
|
|
Note: Sets srcptr to &s.
|
2021-09-04 22:58:29 +00:00
|
|
|
|
2021-09-21 00:54:24 +00:00
|
|
|
n = strrch(c, s); Returns position of last occurance of character
|
2018-01-28 19:00:23 +00:00
|
|
|
in string, or 255 if character was not found.
|
|
|
|
|
2021-09-21 00:54:24 +00:00
|
|
|
Note: Sets srcptr to &s.
|
2021-09-04 22:58:29 +00:00
|
|
|
|
|
|
|
n = strcat(s); Concatenates source string s onto the end of
|
|
|
|
destination string set by prior setdst() call.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
Returns total length of concatenated string.
|
|
|
|
|
2021-09-21 00:54:24 +00:00
|
|
|
Note: Sets srcptr to &s.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
2021-09-04 22:58:29 +00:00
|
|
|
c = strcmp(s); Compares source string s against destination
|
|
|
|
string set by prior setdst() call.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
Returns 255 if destination < source, 0 if
|
|
|
|
destination = source, and 1 if destination > source.
|
|
|
|
|
|
|
|
These results can be evaluated using the C02
|
|
|
|
unary comparator ! or the test-operators :+ or :-.
|
|
|
|
|
2021-09-21 00:54:24 +00:00
|
|
|
Note: Sets srcptr to &s.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
2021-09-04 22:58:29 +00:00
|
|
|
n = strcpy(s); Copies wource string s into destination string set
|
|
|
|
by prior setdst() call, replacing previous contents.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
Returns number of characters copied.
|
|
|
|
|
|
|
|
To copy the first n characters from string s to
|
|
|
|
string d, the following code can be used:
|
|
|
|
|
2021-09-04 22:58:29 +00:00
|
|
|
setdst(&d); strcpy(s); s[n]=0;
|
2021-09-21 00:54:24 +00:00
|
|
|
|
|
|
|
Note: Sets srcptr to &s.
|
|
|
|
|
|
|
|
n = strstr(s); Searches for string s in destination string set.
|
2021-09-04 22:58:29 +00:00
|
|
|
|
|
|
|
Returns position of source string in destination
|
|
|
|
string, or 255 if character was not found.
|
|
|
|
|
2021-09-21 00:54:24 +00:00
|
|
|
Note: calls strcmp(), leaving srcptr pointing to
|
|
|
|
the matched string in the destination string
|
|
|
|
(or the end if not found).
|
2021-09-04 22:58:29 +00:00
|
|
|
|
|
|
|
These functions are not part of the standard C and C++ string libraries.
|
|
|
|
They are included because they are more efficient than equivalent C02 code.
|
|
|
|
|
|
|
|
strcpb(s) Copies string s to the system buffer (sysbfr).
|
|
|
|
|
2021-09-21 00:54:24 +00:00
|
|
|
Note: sets srcptr to &s and dstptr to &sysbfr,
|
|
|
|
then calls strcpy().
|
2021-09-04 22:58:29 +00:00
|
|
|
|
|
|
|
n = strcut(n, s); Copies from source string s, starting at position n,
|
|
|
|
into destination string set by prior setdst() call,
|
2018-01-28 19:00:23 +00:00
|
|
|
replacing previous contents.
|
|
|
|
|
|
|
|
Returns number of characters copied.
|
|
|
|
|
|
|
|
To copy a substring starting at position n with
|
2021-09-04 22:58:29 +00:00
|
|
|
length i from string s to string d, the following
|
2018-01-28 19:00:23 +00:00
|
|
|
code can be used:
|
|
|
|
|
2021-09-04 22:58:29 +00:00
|
|
|
setdst(&d); strcut(s, n); s[i] = 0;
|
2018-01-28 19:00:23 +00:00
|
|
|
|
2021-09-21 00:54:24 +00:00
|
|
|
Note: Sets srcptr to the address of position n
|
|
|
|
in s and calls strcpy().
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
Note: This library expects the following functions to be defined
|
|
|
|
|
2021-09-04 22:58:29 +00:00
|
|
|
setdst(s); Set destination pointer
|
|
|
|
setsrc(s); Set source pointer and initialize index
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
along with the zero page variable pairs
|
|
|
|
|
2021-09-04 22:58:29 +00:00
|
|
|
srcptr Source String Pointer
|
|
|
|
dstptr Destination String Pointer
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
as well as the transient variables
|
|
|
|
|
|
|
|
temp0 Temporary storage
|
|
|
|
temp1
|
|
|
|
|