recutils
rec-utils.h
Go to the documentation of this file.
1 /* -*- mode: C -*-
2  *
3  * File: rec-utils.h
4  * Date: Fri Apr 9 19:42:52 2010
5  *
6  * GNU recutils - Miscellanea utilities
7  *
8  */
9 
10 /* Copyright (C) 2010-2019 Jose E. Marchesi */
11 
12 /* This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef REC_UTILS_H
27 #define REC_UTILS_H
28 
29 #include <config.h>
30 
31 #include <rec.h>
32 #include <stdint.h>
33 #include <stdbool.h>
34 
36  {
42  };
43 
44 /* Non public constants used by several modules. */
45 
46 #define REC_INT_RE "-?((0x[0-9a-fA-F]+)|[0-9]+)"
47 #define REC_INT_SIZE_RE \
48  "^[ \t\n]*(>|<|>=|<=)?[ \t\n]*" \
49  REC_INT_RE \
50  "[ \t\n]*$"
51 
52 /* Parse an integer/real in the NULL-terminated string STR and store
53  it at NUMBER. Return true if the conversion was successful. false
54  otherwise. */
55 bool rec_atoi (const char *str, int *number);
56 bool rec_atod (const char *str, double *number);
57 
58 /* Extract type and url from a %rec: field value. */
59 char *rec_extract_url (const char *str);
60 char *rec_extract_file (const char *str);
61 char *rec_extract_type (const char *str);
62 
63 /* Extract size and condition from a %size: field value. */
64 size_t rec_extract_size (const char *str);
66 
67 /* Matching a string against a regexp. */
68 bool rec_match (const char *str, const char *regexp);
69 bool rec_match_insensitive (const char *str, const char *regexp);
70 
71 /* Generic parsing routines. */
72 bool rec_blank_p (char c);
73 bool rec_digit_p (char c);
74 bool rec_letter_p (char c);
75 bool rec_parse_int (const char **str, int *num);
76 void rec_skip_blanks (const char **str);
77 bool rec_parse_regexp (const char **str, const char *re, char **result);
78 
79 /* String utilities. */
80 char *rec_concat_strings (const char *str1, const char *str2, const char *str3);
81 
82 /* Miscellanea. */
83 int rec_timespec_subtract (struct timespec *result,
84  struct timespec *x,
85  struct timespec *y);
86 
87 uint32_t rec_endian_swap (uint32_t number);
88 
89 #endif /* rec-utils.h */
90 
91 /* End of rec-utils.h. */
bool rec_blank_p(char c)
Definition: rec-utils.c:274
char * rec_extract_file(const char *str)
Definition: rec-utils.c:84
void rec_skip_blanks(const char **str)
Definition: rec-utils.c:260
bool rec_match(const char *str, const char *regexp)
Definition: rec-utils.c:315
bool rec_atod(const char *str, double *number)
Definition: rec-utils.c:60
bool rec_letter_p(char c)
Definition: rec-utils.c:288
bool rec_parse_regexp(const char **str, const char *re, char **result)
Definition: rec-utils.c:205
size_t rec_extract_size(const char *str)
Definition: rec-utils.c:329
bool rec_atoi(const char *str, int *number)
Definition: rec-utils.c:38
rec_size_condition_e
Definition: rec-utils.h:36
@ SIZE_COND_GE
Definition: rec-utils.h:41
@ SIZE_COND_LE
Definition: rec-utils.h:39
@ SIZE_COND_L
Definition: rec-utils.h:38
@ SIZE_COND_G
Definition: rec-utils.h:40
@ SIZE_COND_E
Definition: rec-utils.h:37
bool rec_digit_p(char c)
Definition: rec-utils.c:282
char * rec_extract_url(const char *str)
Definition: rec-utils.c:112
enum rec_size_condition_e rec_extract_size_condition(const char *str)
Definition: rec-utils.c:350
bool rec_parse_int(const char **str, int *num)
Definition: rec-utils.c:169
uint32_t rec_endian_swap(uint32_t number)
Definition: rec-utils.c:418
int rec_timespec_subtract(struct timespec *result, struct timespec *x, struct timespec *y)
Definition: rec-utils.c:400
char * rec_concat_strings(const char *str1, const char *str2, const char *str3)
Definition: rec-utils.c:431
char * rec_extract_type(const char *str)
Definition: rec-utils.c:140
bool rec_match_insensitive(const char *str, const char *regexp)
Definition: rec-utils.c:322