satyr 0.30
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
31extern "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
40#define SR_lower "abcdefghijklmnopqrstuvwxyz"
41#define SR_upper "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
42#define SR_alpha SR_lower SR_upper
43#define SR_space " \t\r\n\v\f"
44#define SR_digit "0123456789"
45#define SR_alnum SR_alpha SR_digit
46
47#define __sr_printf(x, y) __attribute__((format(printf, (x), (y))))
48
53extern bool
55
59void *
60sr_malloc(size_t size);
61
65void *
66sr_mallocz(size_t size);
67
71void *
72sr_malloc_array(size_t elems, size_t elem_size);
73
77void *
78sr_realloc(void *ptr, size_t size);
79
83void *
84sr_realloc_array(void *ptr, size_t elems, size_t elem_size);
85
89char *
90sr_vasprintf(const char *format, va_list p);
91
95char *
96sr_asprintf(const char *format, ...) __sr_printf(1, 2);
97
101char *
102sr_strdup(const char *s);
103
107char *
108sr_strndup(const char *s, size_t n);
109
110void
111sr_struniq(char **strings, size_t *size);
112
117int
118sr_strcmp0(const char *s1, const char *s2);
119
124int
125sr_ptrstrcmp(const void *s1, const void *s2);
126
137char *
138sr_strchr_location(const char *s, int c, int *line, int *column);
139
150char *
151sr_strstr_location(const char *haystack,
152 const char *needle,
153 int *line,
154 int *column);
155
164size_t
165sr_strspn_location(const char *s,
166 const char *accept,
167 int *line,
168 int *column);
169
175char *
176sr_file_to_string(const char *filename,
177 char **error_message);
178
179bool
180sr_string_to_file(const char *filename,
181 char *contents,
182 char **error_message);
183
189bool
190sr_skip_char(const char **input, char c);
191
197bool
198sr_skip_char_limited(const char **input, const char *allowed);
199
206bool
207sr_parse_char_limited(const char **input,
208 const char *allowed,
209 char *result);
210
216int
217sr_skip_char_sequence(const char **input, char c);
218
226int
227sr_skip_char_span(const char **input, const char *chars);
228
240int
241sr_skip_char_span_location(const char **input,
242 const char *chars,
243 int *line,
244 int *column);
245
255int
256sr_parse_char_span(const char **input,
257 const char *accept,
258 char **result);
259
267int
268sr_skip_char_cspan(const char **input, const char *reject);
269
279bool
280sr_parse_char_cspan(const char **input,
281 const char *reject,
282 char **result);
283
291int
292sr_skip_string(const char **input, const char *string);
293
302bool
303sr_parse_string(const char **input, const char *string, char **result);
304
310char
311sr_parse_digit(const char **input);
312
320int
321sr_skip_uint(const char **input);
322
329int
330sr_parse_uint32(const char **input, uint32_t *result);
331
332int
333sr_parse_uint64(const char **input, uint64_t *result);
334
342int
343sr_skip_hexadecimal_uint(const char **input);
344
352int
353sr_skip_hexadecimal_0xuint(const char **input);
354
362int
363sr_parse_hexadecimal_uint64(const char **input, uint64_t *result);
364
372int
373sr_parse_hexadecimal_0xuint64(const char **input, uint64_t *result);
374
375char *
376sr_skip_whitespace(const char *s);
377
378char *
379sr_skip_non_whitespace(const char *s);
380
381bool
382sr_skip_to_next_line_location(const char **s, int *line, int *column);
383
387char *
388sr_bin2hex(char *dst, const char *str, int count);
389
390char *
391sr_indent(const char *input, int spaces);
392
393char *
394sr_indent_except_first_line(const char *input, int spaces);
395
396char *
397sr_build_path(const char *first_element, ...);
398
404void
405sr_parse_os_release(const char *input,
406 void (*callback)(char*, char*, void*),
407 void *data);
408
409char*
410anonymize_path(char *file_name);
411
417char *
418sr_demangle_symbol(const char *sym);
419
420#ifdef __cplusplus
421}
422#endif
423
424#endif
char * sr_strndup(const char *s, size_t n)
int sr_skip_uint(const char **input)
char char * sr_strdup(const char *s)
void * sr_mallocz(size_t size)
int sr_skip_char_span(const char **input, const char *chars)
bool sr_parse_string(const char **input, const char *string, char **result)
char * sr_vasprintf(const char *format, va_list p)
int sr_parse_uint32(const char **input, uint32_t *result)
int sr_skip_hexadecimal_uint(const char **input)
int sr_skip_char_cspan(const char **input, const char *reject)
void * sr_malloc_array(size_t elems, size_t elem_size)
bool sr_debug_parser
void sr_parse_os_release(const char *input, void(*callback)(char *, char *, void *), void *data)
char * sr_strchr_location(const char *s, int c, int *line, int *column)
bool sr_skip_char_limited(const char **input, const char *allowed)
int sr_ptrstrcmp(const void *s1, const void *s2)
char * sr_file_to_string(const char *filename, char **error_message)
int sr_skip_char_sequence(const char **input, char c)
void * sr_realloc(void *ptr, size_t size)
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)
char * sr_demangle_symbol(const char *sym)
void * sr_realloc_array(void *ptr, size_t elems, size_t elem_size)
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_bin2hex(char *dst, const char *str, int count)
char * sr_asprintf(const char *format,...) __sr_printf(1
char sr_parse_digit(const char **input)
int sr_strcmp0(const char *s1, const char *s2)
bool sr_parse_char_cspan(const char **input, const char *reject, char **result)
int sr_parse_char_span(const char **input, const char *accept, char **result)
char * sr_strstr_location(const char *haystack, const char *needle, int *line, int *column)
size_t sr_strspn_location(const char *s, const char *accept, int *line, int *column)
void * sr_malloc(size_t size)
bool sr_skip_char(const char **input, char c)
bool sr_parse_char_limited(const char **input, const char *allowed, char *result)