satyr  0.43
utils.h
Go to the documentation of this file.
1 /*
2  utils.h
3 
4  Copyright (C) 2010 Red Hat, Inc.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20 #ifndef SATYR_UTILS_H
21 #define SATYR_UTILS_H
22 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <stdlib.h>
35 #include <stdarg.h>
36 #include <stdbool.h>
37 #include <stdint.h>
38 #include <assert.h>
39 #include <glib.h>
40 
41 #define SR_lower "abcdefghijklmnopqrstuvwxyz"
42 #define SR_upper "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
43 #define SR_alpha SR_lower SR_upper
44 #define SR_space " \t\r\n\v\f"
45 #define SR_digit "0123456789"
46 #define SR_alnum SR_alpha SR_digit
47 
48 #define __sr_printf(x, y) __attribute__((format(printf, (x), (y))))
49 
54 extern bool
56 
57 void
58 sr_struniq(char **strings, size_t *size);
59 
64 int
65 sr_ptrstrcmp(const void *s1, const void *s2);
66 
77 char *
78 sr_strchr_location(const char *s, int c, int *line, int *column);
79 
90 char *
91 sr_strstr_location(const char *haystack,
92  const char *needle,
93  int *line,
94  int *column);
95 
104 size_t
105 sr_strspn_location(const char *s,
106  const char *accept,
107  int *line,
108  int *column);
109 
115 char *
116 sr_file_to_string(const char *filename,
117  char **error_message);
118 
119 bool
120 sr_string_to_file(const char *filename,
121  char *contents,
122  char **error_message);
123 
129 bool
130 sr_skip_char(const char **input, char c);
131 
137 bool
138 sr_skip_char_limited(const char **input, const char *allowed);
139 
146 bool
147 sr_parse_char_limited(const char **input,
148  const char *allowed,
149  char *result);
150 
156 int
157 sr_skip_char_sequence(const char **input, char c);
158 
166 int
167 sr_skip_char_span(const char **input, const char *chars);
168 
180 int
181 sr_skip_char_span_location(const char **input,
182  const char *chars,
183  int *line,
184  int *column);
185 
195 int
196 sr_parse_char_span(const char **input,
197  const char *accept,
198  char **result);
199 
207 int
208 sr_skip_char_cspan(const char **input, const char *reject);
209 
219 bool
220 sr_parse_char_cspan(const char **input,
221  const char *reject,
222  char **result);
223 
231 int
232 sr_skip_string(const char **input, const char *string);
233 
242 bool
243 sr_parse_string(const char **input, const char *string, char **result);
244 
250 char
251 sr_parse_digit(const char **input);
252 
260 int
261 sr_skip_uint(const char **input);
262 
269 int
270 sr_parse_uint32(const char **input, uint32_t *result);
271 
272 int
273 sr_parse_uint64(const char **input, uint64_t *result);
274 
282 int
283 sr_skip_hexadecimal_uint(const char **input);
284 
292 int
293 sr_skip_hexadecimal_0xuint(const char **input);
294 
302 int
303 sr_parse_hexadecimal_uint64(const char **input, uint64_t *result);
304 
312 int
313 sr_parse_hexadecimal_0xuint64(const char **input, uint64_t *result);
314 
315 char *
316 sr_skip_whitespace(const char *s);
317 
318 char *
319 sr_skip_non_whitespace(const char *s);
320 
321 bool
322 sr_skip_to_next_line_location(const char **s, int *line, int *column);
323 
327 char *
328 sr_bin2hex(char *dst, const char *str, int count);
329 
330 char *
331 sr_indent(const char *input, int spaces);
332 
333 char *
334 sr_indent_except_first_line(const char *input, int spaces);
335 
336 char *
337 sr_build_path(const char *first_element, ...);
338 
344 void
345 sr_parse_os_release(const char *input,
346  void (*callback)(char*, char*, void*),
347  void *data);
348 
349 char*
350 anonymize_path(char *file_name);
351 
357 char *
358 sr_demangle_symbol(const char *sym);
359 
360 #ifdef __cplusplus
361 }
362 #endif
363 
364 #endif
char * sr_file_to_string(const char *filename, char **error_message)
int sr_skip_uint(const char **input)
int sr_skip_char_span(const char **input, const char *chars)
bool sr_parse_string(const char **input, const char *string, char **result)
int sr_parse_uint32(const char **input, uint32_t *result)
char * sr_strstr_location(const char *haystack, const char *needle, int *line, int *column)
int sr_skip_hexadecimal_uint(const char **input)
int sr_skip_char_cspan(const char **input, const char *reject)
bool sr_debug_parser
void sr_parse_os_release(const char *input, void(*callback)(char *, char *, void *), void *data)
bool sr_skip_char_limited(const char **input, const char *allowed)
int sr_ptrstrcmp(const void *s1, const void *s2)
int sr_skip_char_sequence(const char **input, char c)
int sr_parse_hexadecimal_uint64(const char **input, uint64_t *result)
int sr_skip_string(const char **input, const char *string)
int sr_skip_hexadecimal_0xuint(const char **input)
int sr_parse_hexadecimal_0xuint64(const char **input, uint64_t *result)
int sr_skip_char_span_location(const char **input, const char *chars, int *line, int *column)
char sr_parse_digit(const char **input)
char * sr_demangle_symbol(const char *sym)
bool sr_parse_char_cspan(const char **input, const char *reject, char **result)
char * sr_bin2hex(char *dst, const char *str, int count)
int sr_parse_char_span(const char **input, const char *accept, char **result)
size_t sr_strspn_location(const char *s, const char *accept, int *line, int *column)
char * sr_strchr_location(const char *s, int c, int *line, int *column)
bool sr_skip_char(const char **input, char c)
bool sr_parse_char_limited(const char **input, const char *allowed, char *result)