1ao_string_tokenize(3) Programmer's Manual ao_string_tokenize(3)
2
3
4
6 ao_string_tokenize - tokenize an input string
7
8
10 #include <your-opts.h>
11 cc [...] -o outfile infile.c -lopts [...]
12
13 token_list_t * ao_string_tokenize(char const * string);
14
15
17 This function will convert one input string into a list of strings.
18 The list of strings is derived by separating the input based on white
19 space separation. However, if the input contains either single or dou‐
20 ble quote characters, then the text after that character up to a match‐
21 ing quote will become the string in the list.
22
23 The returned pointer should be deallocated with free(3C) when are done
24 using the data. The data are placed in a single block of allocated
25 memory. Do not deallocate individual token/strings.
26
27 The structure pointed to will contain at least these two fields:
28
29 tkn_ct The number of tokens found in the input string.
30
31 tok_list An array of tkn_ct + 1 pointers to substring tokens, with the
32 last pointer set to NULL.
33
34 There are two types of quoted strings: single quoted (') and double
35 quoted ("). Singly quoted strings are fairly raw in that escape char‐
36 acters (\) are simply another character, except when preceding the fol‐
37 lowing characters:
38 \ double backslashes reduce to one
39 ' incorporates the single quote into the string
40 0fP suppresses both the backslash and newline character
41
42 Double quote strings are formed according to the rules of string con‐
43 stants in ANSI-C programs.
44
45 string string to be tokenized
46
47
49 pointer to a structure that lists each token
50
51
53 NULL is returned and errno will be set to indicate the problem:
54
55
56
57
58
59
60
61 EINVAL - There was an unterminated quoted string.
62
63 ENOENT - The input string was empty.
64
65 ENOMEM - There is not enough memory. @end itemize
66
67
69 #include <stdlib.h>
70 int ix;
71 token_list_t * ptl = ao_string_tokenize(some_string)
72 for (ix = 0; ix < ptl->tkn_ct; ix++)
73 do_something_with_tkn(ptl->tkn_list[ix]);
74 free(ptl);
75 Note that everything is freed with the one call to free(3C).
76
78 The info documentation for the -lopts library.
79 configFileLoad(3), optionFileLoad(3), optionFindNextValue(3), option‐
80 FindValue(3), optionFree(3), optionGetValue(3), optionLoadLine(3),
81 optionMemberList(3), optionNextValue(3), optionOnlyUsage(3), option‐
82 PrintVersion(3), optionPrintVersionAndReturn(3), optionProcess(3),
83 optionRestore(3), optionSaveFile(3), optionSaveState(3), optionUnload‐
84 Nested(3), optionVersion(3), strequate(3), streqvcmp(3), streqvmap(3),
85 strneqvcmp(3), strtransform(3),
86
87
88
89 2020-01-28 ao_string_tokenize(3)