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