.. | .. |
---|
4 | 4 | #include <linux/string.h> |
---|
5 | 5 | #include <stdlib.h> |
---|
6 | 6 | |
---|
7 | | -#include "sane_ctype.h" |
---|
| 7 | +#include <linux/ctype.h> |
---|
| 8 | + |
---|
| 9 | +const char *graph_dotted_line = |
---|
| 10 | + "---------------------------------------------------------------------" |
---|
| 11 | + "---------------------------------------------------------------------" |
---|
| 12 | + "---------------------------------------------------------------------"; |
---|
| 13 | +const char *dots = |
---|
| 14 | + "....................................................................." |
---|
| 15 | + "....................................................................." |
---|
| 16 | + "....................................................................."; |
---|
8 | 17 | |
---|
9 | 18 | #define K 1024LL |
---|
10 | 19 | /* |
---|
.. | .. |
---|
58 | 67 | |
---|
59 | 68 | out_err: |
---|
60 | 69 | return -1; |
---|
61 | | -} |
---|
62 | | - |
---|
63 | | -/* |
---|
64 | | - * Helper function for splitting a string into an argv-like array. |
---|
65 | | - * originally copied from lib/argv_split.c |
---|
66 | | - */ |
---|
67 | | -static const char *skip_sep(const char *cp) |
---|
68 | | -{ |
---|
69 | | - while (*cp && isspace(*cp)) |
---|
70 | | - cp++; |
---|
71 | | - |
---|
72 | | - return cp; |
---|
73 | | -} |
---|
74 | | - |
---|
75 | | -static const char *skip_arg(const char *cp) |
---|
76 | | -{ |
---|
77 | | - while (*cp && !isspace(*cp)) |
---|
78 | | - cp++; |
---|
79 | | - |
---|
80 | | - return cp; |
---|
81 | | -} |
---|
82 | | - |
---|
83 | | -static int count_argc(const char *str) |
---|
84 | | -{ |
---|
85 | | - int count = 0; |
---|
86 | | - |
---|
87 | | - while (*str) { |
---|
88 | | - str = skip_sep(str); |
---|
89 | | - if (*str) { |
---|
90 | | - count++; |
---|
91 | | - str = skip_arg(str); |
---|
92 | | - } |
---|
93 | | - } |
---|
94 | | - |
---|
95 | | - return count; |
---|
96 | | -} |
---|
97 | | - |
---|
98 | | -/** |
---|
99 | | - * argv_free - free an argv |
---|
100 | | - * @argv - the argument vector to be freed |
---|
101 | | - * |
---|
102 | | - * Frees an argv and the strings it points to. |
---|
103 | | - */ |
---|
104 | | -void argv_free(char **argv) |
---|
105 | | -{ |
---|
106 | | - char **p; |
---|
107 | | - for (p = argv; *p; p++) { |
---|
108 | | - free(*p); |
---|
109 | | - *p = NULL; |
---|
110 | | - } |
---|
111 | | - |
---|
112 | | - free(argv); |
---|
113 | | -} |
---|
114 | | - |
---|
115 | | -/** |
---|
116 | | - * argv_split - split a string at whitespace, returning an argv |
---|
117 | | - * @str: the string to be split |
---|
118 | | - * @argcp: returned argument count |
---|
119 | | - * |
---|
120 | | - * Returns an array of pointers to strings which are split out from |
---|
121 | | - * @str. This is performed by strictly splitting on white-space; no |
---|
122 | | - * quote processing is performed. Multiple whitespace characters are |
---|
123 | | - * considered to be a single argument separator. The returned array |
---|
124 | | - * is always NULL-terminated. Returns NULL on memory allocation |
---|
125 | | - * failure. |
---|
126 | | - */ |
---|
127 | | -char **argv_split(const char *str, int *argcp) |
---|
128 | | -{ |
---|
129 | | - int argc = count_argc(str); |
---|
130 | | - char **argv = calloc(argc + 1, sizeof(*argv)); |
---|
131 | | - char **argvp; |
---|
132 | | - |
---|
133 | | - if (argv == NULL) |
---|
134 | | - goto out; |
---|
135 | | - |
---|
136 | | - if (argcp) |
---|
137 | | - *argcp = argc; |
---|
138 | | - |
---|
139 | | - argvp = argv; |
---|
140 | | - |
---|
141 | | - while (*str) { |
---|
142 | | - str = skip_sep(str); |
---|
143 | | - |
---|
144 | | - if (*str) { |
---|
145 | | - const char *p = str; |
---|
146 | | - char *t; |
---|
147 | | - |
---|
148 | | - str = skip_arg(str); |
---|
149 | | - |
---|
150 | | - t = strndup(p, str-p); |
---|
151 | | - if (t == NULL) |
---|
152 | | - goto fail; |
---|
153 | | - *argvp++ = t; |
---|
154 | | - } |
---|
155 | | - } |
---|
156 | | - *argvp = NULL; |
---|
157 | | - |
---|
158 | | -out: |
---|
159 | | - return argv; |
---|
160 | | - |
---|
161 | | -fail: |
---|
162 | | - argv_free(argv); |
---|
163 | | - return NULL; |
---|
164 | 70 | } |
---|
165 | 71 | |
---|
166 | 72 | /* Character class matching */ |
---|
.. | .. |
---|
301 | 207 | return s1[i1] - s2[i2]; |
---|
302 | 208 | } |
---|
303 | 209 | return 0; |
---|
304 | | -} |
---|
305 | | - |
---|
306 | | -/** |
---|
307 | | - * strxfrchar - Locate and replace character in @s |
---|
308 | | - * @s: The string to be searched/changed. |
---|
309 | | - * @from: Source character to be replaced. |
---|
310 | | - * @to: Destination character. |
---|
311 | | - * |
---|
312 | | - * Return pointer to the changed string. |
---|
313 | | - */ |
---|
314 | | -char *strxfrchar(char *s, char from, char to) |
---|
315 | | -{ |
---|
316 | | - char *p = s; |
---|
317 | | - |
---|
318 | | - while ((p = strchr(p, from)) != NULL) |
---|
319 | | - *p++ = to; |
---|
320 | | - |
---|
321 | | - return s; |
---|
322 | | -} |
---|
323 | | - |
---|
324 | | -/** |
---|
325 | | - * ltrim - Removes leading whitespace from @s. |
---|
326 | | - * @s: The string to be stripped. |
---|
327 | | - * |
---|
328 | | - * Return pointer to the first non-whitespace character in @s. |
---|
329 | | - */ |
---|
330 | | -char *ltrim(char *s) |
---|
331 | | -{ |
---|
332 | | - while (isspace(*s)) |
---|
333 | | - s++; |
---|
334 | | - |
---|
335 | | - return s; |
---|
336 | | -} |
---|
337 | | - |
---|
338 | | -/** |
---|
339 | | - * rtrim - Removes trailing whitespace from @s. |
---|
340 | | - * @s: The string to be stripped. |
---|
341 | | - * |
---|
342 | | - * Note that the first trailing whitespace is replaced with a %NUL-terminator |
---|
343 | | - * in the given string @s. Returns @s. |
---|
344 | | - */ |
---|
345 | | -char *rtrim(char *s) |
---|
346 | | -{ |
---|
347 | | - size_t size = strlen(s); |
---|
348 | | - char *end; |
---|
349 | | - |
---|
350 | | - if (!size) |
---|
351 | | - return s; |
---|
352 | | - |
---|
353 | | - end = s + size - 1; |
---|
354 | | - while (end >= s && isspace(*end)) |
---|
355 | | - end--; |
---|
356 | | - *(end + 1) = '\0'; |
---|
357 | | - |
---|
358 | | - return s; |
---|
359 | 210 | } |
---|
360 | 211 | |
---|
361 | 212 | char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints) |
---|