upscli_str_add_unique_token - Man Page

Add a unique token into a string buffer, with optional callbacks as needed by implementation

Synopsis

        #include <upsclient​.h>

        int     upscli_str_add_unique_token(char *tgt, size_t tgtsize, const char *token,
                                int (*callback_always)(char *, size_t, const char *),
                                int (*callback_unique)(char *, size_t, const char *) );

Description

The upscli_str_add_unique_token() function takes the pointer tgt to a caller-provided char * buffer of size tgtsize, and the pointer token to a contiguous token that should be added to the end of tgt buffer, if it is not there yet​.

The token contents are stripped of surrounding space characters, and the method recurses to independently process each space-separated token inside (if there are any spaces left)​.

The resulting tgt buffer would eventually collect a string comprised of unique token values in order of first mention, separated by single space characters (ASCII 0x20)​.

Optionally calls callback_always (if not NULL) after checking the input for spaces (and maybe recursing) and before checking if the token is already there, and/or callback_unique (if not NULL) after checking for uniqueness and just before going to add a newly seen token​.

It is up to the caller to dynamically or statically allocate the tgt buffer and free() it if needed​. As far as this method is concerned, the buffer may be recycled (in data processing loops) by setting the initial character to '\0', making it an empty string again​.

Return Value

The upscli_str_add_unique_token() function returns a numeric code:

See Also

upscli_str_contains_token(3)

Info

10/07/2026 Network UPS Tools 2.8.5 NUT Manual