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

source code of openmp/runtime/src/kmp_str.h