1345153Sdim/* 2345153Sdim * kmp_str.h -- String manipulation routines. 3345153Sdim */ 4345153Sdim 5345153Sdim//===----------------------------------------------------------------------===// 6345153Sdim// 7353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 8353358Sdim// See https://llvm.org/LICENSE.txt for license information. 9353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 10345153Sdim// 11345153Sdim//===----------------------------------------------------------------------===// 12345153Sdim 13345153Sdim#ifndef KMP_STR_H 14345153Sdim#define KMP_STR_H 15345153Sdim 16345153Sdim#include <stdarg.h> 17345153Sdim#include <string.h> 18345153Sdim 19345153Sdim#include "kmp_os.h" 20345153Sdim 21345153Sdim#ifdef __cplusplus 22345153Sdimextern "C" { 23345153Sdim#endif // __cplusplus 24345153Sdim 25345153Sdim#if KMP_OS_WINDOWS 26345153Sdim#define strdup _strdup 27345153Sdim#endif 28345153Sdim 29345153Sdim/* some macros to replace ctype.h functions */ 30345153Sdim#define TOLOWER(c) ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) + 'a' - 'A') : (c)) 31345153Sdim 32345153Sdimstruct kmp_str_buf { 33345153Sdim char *str; // Pointer to buffer content, read only. 34345153Sdim unsigned int size; // Do not change this field! 35345153Sdim int used; // Number of characters printed to buffer, read only. 36345153Sdim char bulk[512]; // Do not use this field! 37345153Sdim}; // struct kmp_str_buf 38345153Sdimtypedef struct kmp_str_buf kmp_str_buf_t; 39345153Sdim 40345153Sdim#define __kmp_str_buf_init(b) \ 41345153Sdim { \ 42345153Sdim (b)->str = (b)->bulk; \ 43345153Sdim (b)->size = sizeof((b)->bulk); \ 44345153Sdim (b)->used = 0; \ 45345153Sdim (b)->bulk[0] = 0; \ 46345153Sdim } 47345153Sdim 48345153Sdimvoid __kmp_str_buf_clear(kmp_str_buf_t *buffer); 49345153Sdimvoid __kmp_str_buf_reserve(kmp_str_buf_t *buffer, int size); 50345153Sdimvoid __kmp_str_buf_detach(kmp_str_buf_t *buffer); 51345153Sdimvoid __kmp_str_buf_free(kmp_str_buf_t *buffer); 52345153Sdimvoid __kmp_str_buf_cat(kmp_str_buf_t *buffer, char const *str, int len); 53345153Sdimvoid __kmp_str_buf_catbuf(kmp_str_buf_t *dest, const kmp_str_buf_t *src); 54345153Sdimint __kmp_str_buf_vprint(kmp_str_buf_t *buffer, char const *format, 55345153Sdim va_list args); 56345153Sdimint __kmp_str_buf_print(kmp_str_buf_t *buffer, char const *format, ...); 57345153Sdimvoid __kmp_str_buf_print_size(kmp_str_buf_t *buffer, size_t size); 58345153Sdim 59345153Sdim/* File name parser. 60345153Sdim Usage: 61345153Sdim 62345153Sdim kmp_str_fname_t fname = __kmp_str_fname_init( path ); 63345153Sdim // Use fname.path (copy of original path ), fname.dir, fname.base. 64345153Sdim // Note fname.dir concatenated with fname.base gives exact copy of path. 65345153Sdim __kmp_str_fname_free( & fname ); 66345153Sdim*/ 67345153Sdimstruct kmp_str_fname { 68345153Sdim char *path; 69345153Sdim char *dir; 70345153Sdim char *base; 71345153Sdim}; // struct kmp_str_fname 72345153Sdimtypedef struct kmp_str_fname kmp_str_fname_t; 73345153Sdimvoid __kmp_str_fname_init(kmp_str_fname_t *fname, char const *path); 74345153Sdimvoid __kmp_str_fname_free(kmp_str_fname_t *fname); 75345153Sdim// Compares file name with specified patern. If pattern is NULL, any fname 76345153Sdim// matched. 77345153Sdimint __kmp_str_fname_match(kmp_str_fname_t const *fname, char const *pattern); 78345153Sdim 79345153Sdim/* The compiler provides source locations in string form 80345153Sdim ";file;func;line;col;;". It is not convenient for manupulation. This 81345153Sdim structure keeps source location in more convenient form. 82345153Sdim Usage: 83345153Sdim 84345153Sdim kmp_str_loc_t loc = __kmp_str_loc_init( ident->psource, 0 ); 85345153Sdim // use loc.file, loc.func, loc.line, loc.col. 86345153Sdim // loc.fname is available if second argument of __kmp_str_loc_init is true. 87345153Sdim __kmp_str_loc_free( & loc ); 88345153Sdim 89345153Sdim If psource is NULL or does not follow format above, file and/or func may be 90345153Sdim NULL pointers. 91345153Sdim*/ 92345153Sdimstruct kmp_str_loc { 93345153Sdim char *_bulk; // Do not use thid field. 94345153Sdim kmp_str_fname_t fname; // Will be initialized if init_fname is true. 95345153Sdim char *file; 96345153Sdim char *func; 97345153Sdim int line; 98345153Sdim int col; 99345153Sdim}; // struct kmp_str_loc 100345153Sdimtypedef struct kmp_str_loc kmp_str_loc_t; 101345153Sdimkmp_str_loc_t __kmp_str_loc_init(char const *psource, int init_fname); 102345153Sdimvoid __kmp_str_loc_free(kmp_str_loc_t *loc); 103345153Sdim 104345153Sdimint __kmp_str_eqf(char const *lhs, char const *rhs); 105345153Sdimchar *__kmp_str_format(char const *format, ...); 106345153Sdimvoid __kmp_str_free(char **str); 107345153Sdimint __kmp_str_match(char const *target, int len, char const *data); 108345153Sdimint __kmp_str_match_false(char const *data); 109345153Sdimint __kmp_str_match_true(char const *data); 110345153Sdimvoid __kmp_str_replace(char *str, char search_for, char replace_with); 111345153Sdimvoid __kmp_str_split(char *str, char delim, char **head, char **tail); 112345153Sdimchar *__kmp_str_token(char *str, char const *delim, char **buf); 113345153Sdimint __kmp_str_to_int(char const *str, char sentinel); 114345153Sdim 115345153Sdimvoid __kmp_str_to_size(char const *str, size_t *out, size_t dfactor, 116345153Sdim char const **error); 117345153Sdimvoid __kmp_str_to_uint(char const *str, kmp_uint64 *out, char const **error); 118345153Sdim 119345153Sdim#ifdef __cplusplus 120345153Sdim} // extern "C" 121345153Sdim#endif // __cplusplus 122345153Sdim 123345153Sdim#endif // KMP_STR_H 124345153Sdim 125345153Sdim// end of file // 126