mpstrtok()

    #include <mplib1/mpstrtok.h>

    char *mpstrtok( char *str, void **ftok, const char *seps );
This function is a replacment for the standard strtok() function, but which also for multiple strings to be parsed concurrently. The standard strtok has the problem that it uses a single internal static buffer which allows only a single string to be parsed at any one time.

The ability to perform concurrent parsing is performed by means of an extra parameter which holds for a given string, the current token position, the next scan position and the end of string position.

Use is almost identical to strtok apart from the extra parameter.

    char seps[]="\t ";
    char string[]="a selection of strings";
    char *cp;
    void *tokptr;

    cp=mpstrtok( string, &tokptr, seps );
    while(cp)
    {
	printf("Token is <%s>\n",cp);
	cp=mpstrtok( NULL, &tokptr, seps );
	if (cp)
	    printf( "token: <%s>\n", cp );
    };
    (void)(mpstrtok( NULL, &tokptr, NULL );
would produce the output
    token: <a>
    token: <selection>
    token: <of>
    token: <strings>

NOTE: the mpstrok routine allocates memory on the initial call (when str is non-null). This memory is normally only freed when the parse reaches the end of the string. When you wish to finish parsing of the string, either due to reaching the end of the string, or your program has collected enough tokens (No purchase neccessary :-), then mpstrtok should be called with a NULL as the separators string (as illustrated above).

Currently the routine automatically frees the allocated memory when failing to find a token, thus this routine cannot be used to sequentially check for alternate groups of seperators. This restriction may be removed in a future release if the semantics are consistent.