xref: /titanic_51/usr/src/lib/libast/common/man/tok.3 (revision 4a6ec905b96eb96a398c346f59e034a90ce8ad37)
.fp 5 CW .. .nr ;G \\n(.f .Af "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9" \\*(;G .. .aF 5 \\n(.f "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" .. .aF 5 1 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" .. .aF 1 5 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" ..

0

..

..

TOK 3
NAME
tok - space separated token stream routines
SYNOPSIS
.L "#include <ast.h>" .L "void* tokopen(char* string)" .L "char* tokread(void* tok)" .L "void tokclose(void* tok)" .L "int tokscan(char* string, char** next, const char* format, ...);" .L "Sfio_t* tokline(const char* input, int flags, int* line);"
DESCRIPTION
.L tokopen returns a pointer to a space separated token stream on the 0 terminated string .LR string . .L tokread returns a pointer to the next space separated token in the token stream .L tok as returned by .LR tokopen . 0 is returned when no tokens remain. .L tokread temporarily modifies .L string by inserting 0's to terminate each token. .L tokclose closes the token stream and restores .L string to its original state.

.L tokscan scans the string .L string for tokens specified in .LR format . It is a more forgiving sscanf (3). If .L "next != 0" then it will point to the next unread character in .L string on return. The number of scanned tokens is returned. .L -1 is returned if .L string was not empty and .L format failed to match and tokens.

space in .L format matches 0 or more space or tab characters. newline in format eats the remainder of the current line in .LR string . "...", '...' and \echaracter quotes are interpreted. A quoted carriage-return is converted to newline . newline in .L string is equivalent to end of string except when quoted. \enewline is a line splice.

.L % in .L format prefixes format conversion characters; each conversion character corresponds to a .L tokscan argument following the .L format argument. The format conversions are:

.L %c A single .LR char .

.L "%hd %d %ld" [short, int, long] base 10 integer.

.L "%hn %n %ln" [short, int, long] C-style base integer.

.L "%ho %o %lo" [short, int, long] base 8 integer.

.L %s String.

.L "%hu %u %lu" [short, int, long] C-style base unsigned integer.

.L %v The next two arguments are a pointer to a .L char** argument vector and the maximum number of elements in the vector.

.L "%hx %x %lx" [short, int, long] base 16 integer.

.L %s and .L %v data may also be counted length strings of the form \f5(count:data) where count is the number of characters in data and the terminating .L ) may also be a tab , or the data may be .L (null) which represents the .L NULL string.

.L tokline returns an sfio (3) stream to a file or string that splices \enewline into single lines, allows "..." and '...' to quotes to span newlines (done by translating quoted newline to carriage-return ; .L tokscan above converts quoted carriage-return back to newline ), and deletes "# ... newline" comments. This is done by pushing an sfio discipline onto a string or file stream. Seeks are disabled on the resulting stream. If .L "flags == SF_READ" then .L input is a file name; If .L "flags == SF_STRING" then .L input is a 0 terminated string; otherwise .L input is an open .L Sfio_t* stream. If .L "line != 0" then it points to a line count that is initialized to 0 and is incremented for each input line.

"SEE ALSO"
sfio(3)