Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!uwvax!umnd-cs!umn-cs!meccts!nis!stag!root
From: root@stag.UUCP (Computer Abuser)
Newsgroups: comp.sys.atari.st
Subject: Public Domain Standard C Libraries: Part 2 of 2
Message-ID: <187@stag.UUCP>
Date: Sun, 26-Jul-87 16:26:05 EDT
Article-I.D.: stag.187
Posted: Sun Jul 26 16:26:05 1987
Date-Received: Mon, 27-Jul-87 00:40:02 EDT
Distribution: world
Organization: Mindtools ST Access Group, Plymouth, MN
Lines: 816
Keywords: PD C libraries
----------------------Cut Here...Start of Part 2 of 2------------------------
FORMATTING/TYPE CONVERSION:
_printf(op, put, fmt, args)
char *op;
int (*put)();
char *fmt;
int *args;
points to a format control string. pointers to a
list of arguments. The format string is used to create and output
stream with the arguments. The function is used to output
each character. The parameter is given to the function
to specify the output stream. Calls to are of the form:
"(*put)(c, op);" where is the character to output. The format
string is composed of characters and format specifications. The
'%' character introduces a format specifier. The general form of
a format specifier is:
%[-][ |+][0][|*][l]{d|i|u|o|x|b|c|s}
The '-' specifies left justification. The ' ' or '+' specifies
the character which preceeds positive numeric values. The '0'
specifies that numeric fields will be padded with '0' rather than
' '. The field is a numeric value specifying a fixed
field width. If '*' is specified for the field width, an "int"
value from the argument list is taken to contain the field width.
If output exceeds the field width, the field will be '*' filled.
The "." type of width specification is not supported.
The field simply acts like ".", specifying
both minimum and maximum field size with one value. In order
to be somewhat compatible with the dotted width spec, the width
value will be zeroed if a '.' is seen, allowing the digits of
the second field spec to set the width value. If no width is
specified, the field width varies according to the data printed.
The 'l' specifies that the associated value is a "long" type.
The trailing character specifies the format type, as follows:
d Signed decimal integer
i same as 'd'
u Unsigned decimal integer
o Unsigned octal integer
x Unsigned hexadecimal integer
b Unsigned binary integer
c Character
s String
If the character following the '%' is not recognized, it is
simply passed along to the output stream, thus "%%" is used to
print a single '%' character.
char *ltoa(n, buffer, radix)
long n;
char *buffer;
int radix;
Convert the long value to a string in using
as the number base. If is negative, '-' will be the first
character in . A pointer to is returned.
char *ultoa(n, buffer, radix)
unsigned long n;
char *buffer;
int radix;
Convert the unsigned long value to a string in using
as the number base. A pointer to is returned.
char *itoa(n, buffer, radix)
int n;
char *buffer;
int radix;
Convert the integer value to a string in using
as the number base. If is negative, '-' will be the first
character in . A pointer to is returned.
long ltoa(number)
char *number;
Convert the string to a long value. Leading whitespace
is ignored, a leading +/- is optional. Characters are processed
until a non-digit is reached. Return value is undefined in an
overflow situation.
int itoa(number)
char *number;
Convert the string to an int value. Leading whitespace
is ignored, a leading +/- is optional. Characters are processed
until a non-digit is reached. Return value is undefined in an
overflow situation.
_scanf(ip, get, unget, fmt, args)
char *ip;
int (*get)();
int (*unget)();
char *fmt;
char **args;
points to a format control string. pointers to a
list of arguments, each of which is the address of a variable in
which input data may be stored. The format string is used to
control reading of characters from the function. As each
character is needed is called in the form: "c = (*get)(ip);"
where is the character read (negative for errors) and
is the auxiliary pointer specified by the parameter. If
a character needs to be un-gotten, a call to of the form:
"(*unget)(c, ip);" is made. The format string is composed of
characters and format specifications. Any characters in ,
except whitespace characters, which are not part of a format
specifier are expected to be matched one-to-one by characters in
the input stream. Scanning terminates if a mismatch occurs or
if any call to results in an error. Whitespace characters
match 0 or more whitespace characters in the input stream. The
'%' character introduces a format specifier. The general form
of a format specifier is:
%[*][][l]{d|i|u|o|x|b|c|s}
The '*' specifies that a field is to be scanned by not stored. No
variable pointer should be provided for non-stored format specs.
The field specifies that maximum number of characters to
be process to fill the given format type. Less than
characters will be processed if the field ends before
characters have been processed. A field ends when either a
whitespace character, or a character which does not fit the
specified format, is read. The 'l' specifies that the associated
variable is a "long" type. The trailing character specifies the
format type, as follows:
d Signed decimal integer
u Unsigned decimal integer
o Unsigned octal integer
x Unsigned hexadecimal integer
b Unsigned binary integer
i Unsigned decimal/octal/hexadecimal/binary integer
c Character
s String
If a is specified with the 'c' format, exactly
characters (including whitespace) are read from the input
stream, and written to a string. No '\0' character is added.
If the character following the '%' is not recognized, it is
expected to match the input stream as a non-format character,
thus "%%" is used to match a single '%' character.
char *ctlcnv(string)
char *string;
Convert \ notation in to actual characters. This
is useful for reading strings from a stream when you want to allow
insertion of control character or other characters that may have
special meaning otherwise, or may not otherwise be allowed. The
following formats are supported:
\n newline or linefeed
\r carriage return
\0 null character (value 0)
\b backspace
\t horizontal tab
\v vertical tab
\f form feed
\a alarm (bell)
\\ backslash
\' single quote
\" double quote
\NNN octal constant
\xNN hexadecimal constant
\ "folded" line (both characters removed)
A pointer to the modified is returned.
STRING MANIPULATION:
You may want to include "STRING.H" in your program if you use
functions in this section, otherwise you'll have to declare the
return types for any functions you use.
char *blkcpy(dest, source, len)
char *dest;
char *source;
int len;
Copies the block to the . bytes are
always copied. No terminator is added to . A pointer
to is returned. Overlap checking IS done.
char *blkfill(dest, data, len)
char *dest;
char data;
int len;
Fill will bytes of . A pointer to
is returned.
int blkcmp(blk1, blk2, len)
char *blk1;
char *blk2;
int len;
Lexicographically compare the two blocks. Return a value
indicating the relationship between the blocks. Possible
return values are:
negative blk1 < blk2
0 blk1 == blk2
positive blk1 > blk2
bytes are always compared.
int blkicmp(blk1, blk2, len)
char *blk1;
char *blk2;
int len;
Compare blocks as with blkcmp(), but ignore the case of any
alphabetic characters.
char *memcpy(dst, src, cnt)
char *dst;
char *src;
int cnt;
Same as blkcpy().
char *memccpy(dst, src, c, cnt)
char *dst;
char *src;
char c;
int cnt;
Copy bytes from to until either bytes have been
copied, or the character has been copied. Returns .
char *memset(dst, c, cnt)
char *dst;
char c;
int cnt;
Same as blkfill().
char *memchr(buf, c, cnt)
char *buf;
char c;
int cnt;
Search the first bytes of for . Returns a pointer to
the matching character, or NULL if not found.
int memcmp(buf1, buf2, cnt)
char *buf1;
char *buf2;
int cnt;
Same as blkcmp().
int memicmp(buf1, buf2, cnt)
char *buf1;
char *buf2;
int cnt;
Same as blkicmp().
int strlen(string)
char *string;
Returns the number of characters in a string, not including the
terminating '\0'.
char *strcpy(dest, source)
char *dest;
char *source;
Copies the string to the including the '\0'. A
pointer to the start of is returned.
char *strncpy(dest, source, limit)
char *dest;
char *source;
int limit;
Copies the string to the . At most,
characters are copied. If ends before characters
have been copied, the '\0' is copied, otherwise is not
terminated by the copy.
char *strdup(string)
char *string;
Create a copy of and return a pointer to the copy.
char *strset(string, c)
char *string;
char c;
Fill with up the the terminating '\0' of .
char *strnset(string, c, n)
char *string;
char c;
int n;
Fill at most characters of with , up the the
terminating '\0' of .
char *substr(dest, source, start, end)
char *dest;
char *source;
int start;
int end;
Copy characters from to starting with character
and ending with . A pointer to , which will
be '\0' terminated, is returned.
char *subnstr(dest, source, start, length)
char *dest;
char *source;
int start;
int length;
Copy characters from to starting with
character . A pointer to , which will be '\0'
terminated, is returned.
char *strcat(dest, source)
char *dest;
char *source;
Concatenate on the end of . The terminator of
will be overwritten by the first character of .
The termintor from will be copied. A pointer to
the modified is returned.
char *strncat(dest, source, limit)
char *dest;
char *source;
int limit;
Concatenate characters from onto . If
contains less than characters, the length of
source is used for . The terminating '\0' is always
added. A pointer to is returned.
char *strupr(string)
char *string;
Convert all alphabetic characters in to upper case.
char *strlwr(string)
char *string;
Convert all alphabetic characters in to lower case.
char *strrev(string)
char *string;
Reverse the order of the characters in in place.
int strcmp(str1, str2)
char *str1;
char *str2;
Lexicographically compare the two strings. Return a value
indicating the relationship between the strings. Possible
return values are:
negative str1 < str2
0 str1 == str2
positive str1 > str2
int strncmp(str1, str2, limit)
char *str1;
char *str2;
int limit;
Compare strings as with strcmp(), but limit comparison to the
characters.
int stricmp(str1, str2)
char *str1;
char *str2;
Compare strings as with strcmp(), but ignore the case of any
alphabetic characters.
int strnicmp(str1, str2, limit)
char *str1;
char *str2;
int limit;
Compare strings as with strncmp(), but ignore the case of any
alphabetic characters.
char *strstr(string, pattern)
char *string;
char *pattern;
Return a pointer to the first occurance of in .
NULL is returned if is not found.
char *stristr(string, pattern)
char *string;
char *pattern;
Same as strstr(), but ignore the case of any alphabetic characters.
char *strchr(string, symbol)
char *string;
char symbol;
Return a pointer to the first occurance of in .
NULL is returned if is not found.
char *strrchr(string, symbol)
char *string;
char symbol;
Return a pointer to the last occurance of in .
NULL is returned if is not found.
int strpos(string, symbol)
char *string;
char symbol;
Return the index of the first occurance of in .
-1 is returned if is not found.
int strrpos(string, symbol)
char *string;
char symbol;
Return the index of the last occurance of in .
-1 is returned if is not found.
int strspn(string, set)
char *string;
char *set;
Return the length of the sub-string of that consists
entirely of characters found in . The terminating '\0'
in is not considered part of the match set. If the first
character if is not in , 0 is returned.
int strcspn(string, symbol)
char *string;
char *set;
Return the length of the sub-string of that consists
entirely of characters not found in . The terminating '\0'
in is not considered part of the match set. If the first
character if is in , 0 is returned.
char *strpbrk(string, set)
char *string;
char *set;
Return a pointer to the first occurace in of any
character in .
char *strrpbrk(string, set)
char *string;
char *set;
Return a pointer to the last occurace in of any
character in .
char *strtok(string, delim)
char *string;
char *delim;
Return a token from . If is not NULL, it is
the beginning of a string from which tokens are to be extracted.
Characters found in are skipped over to find the start
of a token, characters are then accumulated until a character in
is found, or the terminator of is reached.
A pointer to the '\0' terminated token is then returned. Note
that this function modifies (by inserting '\0's) in
the process. Subsequent calls to strtok() may specify NULL as
the argument, in which case subsequent tokens are
returned, or NULL if there are no more tokens.
char *strtrim(string, junk)
char *string;
char *junk;
Remove leading and trailing characters found in
from . Return a pointer to the modified .
char *stradj(string, dir)
char *string;
int dir;
Adjust by adding space if is positive, or removing
space if is negative. The magnitude of is the number
of character positions to add or remove. Characters are added or
removed at the beginning of . A pointer to the modified
is returned.
int strrpl(string, ptrn, rpl, n)
char *string;
char *ptrn;
char *rpl;
int n;
Replace at most occurances of in with .
If is -1, replace all. Return the number of replacments.
int strirpl(string, ptrn, rpl, n)
char *string;
char *ptrn;
char *rpl;
int n;
Same as strrpl() except ignore the case of alphabetic characters.
CHARACTER FUNCTIONS:
To use the functions in this section, you must include "CTYPE.H"
in your source file. Please note that the isXXXX() functions,
except isascii(), only have defined results if isascii() is true.
(ie. they only work properly on values 0x00 through 0x7F)
int toupper(c)
int c;
Convert to upper case, if alphabetic. This is implemeted
as a macro and also as a function. You may force use of the
function version rather than the macro (which evaluates its
argument twice) by using the "#undef toupper" directive.
int tolower(c)
int c;
Convert to lower case, if alphabetic. This is implemeted
as a macro and also as a function. You may force use of the
function version rather than the macro (which evaluates its
argument twice) by using the "#undef tolower" directive.
int _toupper(c)
int c;
This macro should be used only if is known to be lower case.
It converts to upper case. Results are undefined if converting
a character which is not lower case.
int _tolower(c)
int c;
This macro should be used only if is known to be upper case.
It converts to lower case. Results are undefined if converting
a character which is not upper case.
int toascii(c)
int c;
Convert to 7-bit ascii, putting it into the range 0x00..0x7F.
int isalnum(c)
int c;
Return non-zero if is '0'..'9','A'..'Z','a'..'z'.
int isalpha(c)
int c;
Return non-zero if is 'A'..'Z','a'..'z'.
int isascii(c)
int c;
Return non-zero if is 0x00..0x7F.
int iscntrl(c)
int c;
Return non-zero if is 0x00..0x1F,0x7F.
int isdigit(c)
int c;
Return non-zero if is '0'..'9'.
int islower(c)
int c;
Return non-zero if is 'a'..'z'.
int isprint(c)
int c;
Return non-zero if is 0x20..0x7E.
int ispunct(c)
int c;
Return non-zero if is not iscntrl(), isalnum() or isspace().
int isspace(c)
int c;
Return non-zero if is 0x09..0x0D,0x20.
int isupper(c)
int c;
Return non-zero if is 'A'..'Z'.
int isxdigit(c)
int c;
Return non-zero if is '0'..'9','A'..'F','a'..'f'.
DATE/TIME FUNCTIONS:
To use the functions in this section, you must include "TIME.H"
in your source file.
long time(rawtime)
long *rawtime;
Get the current system clock date/time value. Under many systems,
this function returns the number of seconds since 00:00:00 GMT on
Jan 1, 1970. This implementation returns an encoded date/time
value instead. Therefore any programs which depend on this value
being a number of seconds will not work properly. However, other
functions in this section which make use of the raw time value
returned by time() are implemented to be compatible with this
encoding, and will work properly. In addition to returning the
raw time value, if the pointer in not NULL, the value
is stored in the long points to.
char *ctime(rawtime)
long *rawtime;
Convert to a string. A 26 character fixed field string
is created from the raw time value. The following is an example
of what this string might look like:
"Wed Jul 08 18:43:07 1987\n\0"
A 24-hour clock is used, and due to a limitation in the ST system
clock value, only a resolution of 2 seconds is possible. A pointer
to the formatted string, which is held in an internal buffer, is
returned.
struct tm *gmtime(rawtime)
long *rawtime;
Convert to fill time structure fields. A pointer to an
internal structure is returned. Refer to "TIME.H" for the values
of the various structure fields.
struct tm *localtime(rawtime)
long *rawtime;
Since there is not concept of "time zone" on the ST, this function
is identical to gmtime().
char *asctime(time)
struct tm *time;
Convert