]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/openmp/runtime/src/kmp_str.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / openmp / runtime / src / kmp_str.h
1 /*
2  * kmp_str.h -- String manipulation routines.
3  */
4
5 //===----------------------------------------------------------------------===//
6 //
7 //                     The LLVM Compiler Infrastructure
8 //
9 // This file is dual licensed under the MIT and the University of Illinois Open
10 // Source Licenses. See LICENSE.txt for details.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef KMP_STR_H
15 #define KMP_STR_H
16
17 #include <stdarg.h>
18 #include <string.h>
19
20 #include "kmp_os.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif // __cplusplus
25
26 #if KMP_OS_WINDOWS
27 #define strdup _strdup
28 #endif
29
30 /*  some macros to replace ctype.h functions  */
31 #define TOLOWER(c) ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) + 'a' - 'A') : (c))
32
33 struct kmp_str_buf {
34   char *str; // Pointer to buffer content, read only.
35   unsigned int size; // Do not change this field!
36   int used; // Number of characters printed to buffer, read only.
37   char bulk[512]; // Do not use this field!
38 }; // struct kmp_str_buf
39 typedef struct kmp_str_buf kmp_str_buf_t;
40
41 #define __kmp_str_buf_init(b)                                                  \
42   {                                                                            \
43     (b)->str = (b)->bulk;                                                      \
44     (b)->size = sizeof((b)->bulk);                                             \
45     (b)->used = 0;                                                             \
46     (b)->bulk[0] = 0;                                                          \
47   }
48
49 void __kmp_str_buf_clear(kmp_str_buf_t *buffer);
50 void __kmp_str_buf_reserve(kmp_str_buf_t *buffer, int size);
51 void __kmp_str_buf_detach(kmp_str_buf_t *buffer);
52 void __kmp_str_buf_free(kmp_str_buf_t *buffer);
53 void __kmp_str_buf_cat(kmp_str_buf_t *buffer, char const *str, int len);
54 void __kmp_str_buf_catbuf(kmp_str_buf_t *dest, const kmp_str_buf_t *src);
55 int __kmp_str_buf_vprint(kmp_str_buf_t *buffer, char const *format,
56                          va_list args);
57 int __kmp_str_buf_print(kmp_str_buf_t *buffer, char const *format, ...);
58 void __kmp_str_buf_print_size(kmp_str_buf_t *buffer, size_t size);
59
60 /* File name parser.
61    Usage:
62
63    kmp_str_fname_t fname = __kmp_str_fname_init( path );
64    // Use fname.path (copy of original path ), fname.dir, fname.base.
65    // Note fname.dir concatenated with fname.base gives exact copy of path.
66    __kmp_str_fname_free( & fname );
67 */
68 struct kmp_str_fname {
69   char *path;
70   char *dir;
71   char *base;
72 }; // struct kmp_str_fname
73 typedef struct kmp_str_fname kmp_str_fname_t;
74 void __kmp_str_fname_init(kmp_str_fname_t *fname, char const *path);
75 void __kmp_str_fname_free(kmp_str_fname_t *fname);
76 // Compares file name with specified patern. If pattern is NULL, any fname
77 // matched.
78 int __kmp_str_fname_match(kmp_str_fname_t const *fname, char const *pattern);
79
80 /* The compiler provides source locations in string form
81    ";file;func;line;col;;". It is not convenient for manupulation. This
82    structure keeps source location in more convenient form.
83    Usage:
84
85    kmp_str_loc_t loc = __kmp_str_loc_init( ident->psource, 0 );
86    // use loc.file, loc.func, loc.line, loc.col.
87    // loc.fname is available if second argument of __kmp_str_loc_init is true.
88    __kmp_str_loc_free( & loc );
89
90    If psource is NULL or does not follow format above, file and/or func may be
91    NULL pointers.
92 */
93 struct kmp_str_loc {
94   char *_bulk; // Do not use thid field.
95   kmp_str_fname_t fname; // Will be initialized if init_fname is true.
96   char *file;
97   char *func;
98   int line;
99   int col;
100 }; // struct kmp_str_loc
101 typedef struct kmp_str_loc kmp_str_loc_t;
102 kmp_str_loc_t __kmp_str_loc_init(char const *psource, int init_fname);
103 void __kmp_str_loc_free(kmp_str_loc_t *loc);
104
105 int __kmp_str_eqf(char const *lhs, char const *rhs);
106 char *__kmp_str_format(char const *format, ...);
107 void __kmp_str_free(char **str);
108 int __kmp_str_match(char const *target, int len, char const *data);
109 int __kmp_str_match_false(char const *data);
110 int __kmp_str_match_true(char const *data);
111 void __kmp_str_replace(char *str, char search_for, char replace_with);
112 void __kmp_str_split(char *str, char delim, char **head, char **tail);
113 char *__kmp_str_token(char *str, char const *delim, char **buf);
114 int __kmp_str_to_int(char const *str, char sentinel);
115
116 void __kmp_str_to_size(char const *str, size_t *out, size_t dfactor,
117                        char const **error);
118 void __kmp_str_to_uint(char const *str, kmp_uint64 *out, char const **error);
119
120 #ifdef __cplusplus
121 } // extern "C"
122 #endif // __cplusplus
123
124 #endif // KMP_STR_H
125
126 // end of file //