Debian Codegraph @

tapset/tokenize.stp

raw
1 // Tokenize tapset
2 // Copyright (C) 2010-2018 Red Hat, Inc.
3 //
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
7 // later version.
8
9 %{
10 #define STAP_NEED_CONTEXT_TOKENIZE 1
11 %}
12
13 /**
14 * sfunction tokenize - Return the next non-empty token in a string
15 *
16 * @delim: set of characters that delimit the tokens
17 *
18 * Description: This function returns the next token in the string
19 * passed in the previous call to tokenize. If no delimiter is found,
20 * the entire remaining input string is * returned. It returns empty
21 * when no more tokens are available.
22 */
23 function tokenize:string(delim:string) {
24 return tokenize("", delim)
25 }
26
27 /**
28 * sfunction tokenize - Return the next non-empty token in a string
29 *
30 * @input: string to tokenize. If empty, returns the next non-empty token
31 * in the string passed in the previous call to tokenize().
32 * @delim: set of characters that delimit the tokens
33 *
34 * Description: This function returns the next non-empty token in the
35 * given input string, where the tokens are delimited by characters in
36 * the delim string. If the input string is non-empty, it returns the
37 * first token. If the input string is empty, it returns the next
38 * token in the string passed in the previous call to tokenize.
39 * If no delimiter is found, the entire remaining input string is
40 * returned. It returns empty when no more tokens are available.
41 */
42 function tokenize:string(input:string, delim:string)
43 %{ /* unprivileged */ /* unmodified-fnargs */
44 char *token = NULL;
45 char *token_end = NULL;
46
47 if (STAP_ARG_input[0]) {
48 strlcpy(CONTEXT->tok_str, STAP_ARG_input, MAXSTRINGLEN);
49 CONTEXT->tok_start = &CONTEXT->tok_str[0];
50 CONTEXT->tok_end = &CONTEXT->tok_str[0] + strlen(CONTEXT->tok_str);
51 }
52 do {
53 token = strsep(& CONTEXT->tok_start, STAP_ARG_delim);
54 } while (token && !token[0]);
55 if (token) {
56 token_end = (CONTEXT->tok_start ? CONTEXT->tok_start - 1 : CONTEXT->tok_end);
57 memcpy(STAP_RETVALUE, token, token_end - token + 1);
58 }
59 %}