| T X T _ P A R S E L I N E ( )
| | | | | SOURCE: qdev_autodocs.txt 1.163 (12/09/2014) English
INDEP - TXT_#?
----------------------------------------------------------------------------
NAME
txt_parseline() - Assembles an array of arguments from
string.
SYNOPSIS
count = txt_parseline(line, array);
LONG txt_parseline(UBYTE *, LONG **);
FUNCTION
This func. can easily assemble an array of arguments with
no extra memory allocation.
INPUTS
line - A NULL terminated string that is to be altered.
Make sure that you pass a copy that is writable!
array - Pointer to array of addresses. If this is NULL
then only count will be returned. Source string
will not be altered.
RETURNS
Returns number of the arguments found.
BASES
None.
NOTES
Warning! This func. changes contents of the input string!
This function should be used it two passes. In the first
pass you will be given number of actual arguments, so you
know how big array is required. In the second pass you
parse the string. It is wise to allocate the count + 1 so
you can NULL terminate it.
All LF, CR, TAB and SPACE characters are always filtered
outside quotation!
Escaped quotes are not unescaped! This routine handles 3
types of escaped quotes (double quotes specifically). The
Amiga syntax: *" - asterisk+quote, regular syntax: \" -
backslash+quote or: '" - single quote+quote.
SEE ALSO
txt_tokenify(), txt_fixquotes()
EXAMPLE
...
UBYTE text[] = "1 \"2\" \\\"3\\\"";
UBYTE *ptr;
LONG count;
LONG **array;
LONG **aptr;
if ((count = txt_parseline(text, NULL)))
{
if ((array = AllocVec(sizeof(text) +
(count + 1) * sizeof(LONG), MEMF_PUBLIC)))
{
array[count] = NULL;
ptr = (UBYTE *)&array[count + 1];
CopyMem(text, ptr, sizeof(text));
txt_parseline(ptr, array);
aptr = array;
while (*aptr)
{
FPrintf(Output(), "%s\n", (LONG)*aptr++);
}
FreeVec(array);
}
}
BUGS
None known.
----------------------------------------------------------------------------
| |
| |