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