Compaq AA-RH99A-TE Remote Starter User Manual


 
For example:
resp = read_response_status();
next_number(resp, NULL, &size);
ret->size = size;
3.2.19 Getting the Next Token as a String
The next_token function returns a pointer to the next token in the specified
pointer to a string. A token is a sequence of nonspace characters. This
function has the following syntax:
char*
next_token(
char* ptr,
int* len_ret,
char** next_ret);
Argument
Input/Output
Description
ptr
Input Specifies the name of the pointer
len_ret
Output Returns the length of the next token,
if non-NULL
next_ret
Output Returns a pointer to the first character after, but
not included in the current token, if non-NULL
You use this function to extract words or other tokens from a character
string. A common use, as shown in the example that follows, is to extract
tokens from a string of numbers. You can then cast the tokens to a numerical
data type, such as the long data type, and use them as numbers.
For example:
static long *parse_memory(char *buf, int offset, int size)
{
long *buffer, *ret;
int index, len;
char *ptr, *token, *next;
NEW_TYPE(buffer, offset + size, long, long *, "parse_memory");
ret = buffer;
index = offset;
ptr = buf;
while(index < offset + size){
if((token = next_token(ptr, &len, &next)) == NULL){
ret = NULL;
break;
}
ptr = next;
if(token[len - 1] == :) continue;
buffer[index] = strtoul(token, &ptr, 16);
if(ptr != &token[len]){
ret = NULL;
break;
}
index++;
}
if(ret == NULL) free(buffer);
return(ret);
Writing Extensions to the kdbx Debugger 3–15