Intel® OpenMP* Runtime Library
 All Classes Functions Variables Typedefs Enumerations Enumerator Modules Pages
kmp_str.h
1 /*
2  * kmp_str.h -- String manipulation routines.
3  */
4 
5 /* <copyright>
6  Copyright (c) 1997-2015 Intel Corporation. All Rights Reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions
10  are met:
11 
12  * Redistributions of source code must retain the above copyright
13  notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  notice, this list of conditions and the following disclaimer in the
16  documentation and/or other materials provided with the distribution.
17  * Neither the name of Intel Corporation nor the names of its
18  contributors may be used to endorse or promote products derived
19  from this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 </copyright> */
34 
35 #ifndef KMP_STR_H
36 #define KMP_STR_H
37 
38 #include <string.h>
39 #include <stdarg.h>
40 
41 #include "kmp_os.h"
42 
43 #ifdef __cplusplus
44  extern "C" {
45 #endif // __cplusplus
46 
47 #if KMP_OS_WINDOWS
48 # define strdup _strdup
49 #endif
50 
51 /* some macros to replace ctype.h functions */
52 #define TOLOWER(c) ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) + 'a' - 'A') : (c))
53 
54 struct kmp_str_buf {
55  char * str; // Pointer to buffer content, read only.
56  unsigned int size; // Do not change this field!
57  int used; // Number of characters printed to buffer, read only.
58  char bulk[ 512 ]; // Do not use this field!
59 }; // struct kmp_str_buf
60 typedef struct kmp_str_buf kmp_str_buf_t;
61 
62 #define __kmp_str_buf_init( b ) { (b)->str = (b)->bulk; (b)->size = sizeof( (b)->bulk ); (b)->used = 0; (b)->bulk[ 0 ] = 0; }
63 
64 void __kmp_str_buf_clear( kmp_str_buf_t * buffer );
65 void __kmp_str_buf_reserve( kmp_str_buf_t * buffer, int size );
66 void __kmp_str_buf_detach( kmp_str_buf_t * buffer );
67 void __kmp_str_buf_free( kmp_str_buf_t * buffer );
68 void __kmp_str_buf_cat( kmp_str_buf_t * buffer, char const * str, int len );
69 void __kmp_str_buf_vprint( kmp_str_buf_t * buffer, char const * format, va_list args );
70 void __kmp_str_buf_print( kmp_str_buf_t * buffer, char const * format, ... );
71 void __kmp_str_buf_print_size( kmp_str_buf_t * buffer, size_t size );
72 
73 /*
74  File name parser. Usage:
75 
76  kmp_str_fname_t fname = __kmp_str_fname_init( path );
77  // Use fname.path (copy of original path ), fname.dir, fname.base.
78  // Note fname.dir concatenated with fname.base gives exact copy of path.
79  __kmp_str_fname_free( & fname );
80 
81 */
82 struct kmp_str_fname {
83  char * path;
84  char * dir;
85  char * base;
86 }; // struct kmp_str_fname
87 typedef struct kmp_str_fname kmp_str_fname_t;
88 void __kmp_str_fname_init( kmp_str_fname_t * fname, char const * path );
89 void __kmp_str_fname_free( kmp_str_fname_t * fname );
90 // Compares file name with specified patern. If pattern is NULL, any fname matched.
91 int __kmp_str_fname_match( kmp_str_fname_t const * fname, char const * pattern );
92 
93 /*
94  The compiler provides source locations in string form ";file;func;line;col;;". It not not
95  convenient for manupulation. These structure keeps source location in more convenient form.
96  Usage:
97 
98  kmp_str_loc_t loc = __kmp_str_loc_init( ident->psource, 0 );
99  // use loc.file, loc.func, loc.line, loc.col.
100  // loc.fname is available if the second argument of __kmp_str_loc_init is true.
101  __kmp_str_loc_free( & loc );
102 
103  If psource is NULL or does not follow format above, file and/or func may be NULL pointers.
104 */
105 struct kmp_str_loc {
106  char * _bulk; // Do not use thid field.
107  kmp_str_fname_t fname; // Will be initialized if init_fname is true.
108  char * file;
109  char * func;
110  int line;
111  int col;
112 }; // struct kmp_str_loc
113 typedef struct kmp_str_loc kmp_str_loc_t;
114 kmp_str_loc_t __kmp_str_loc_init( char const * psource, int init_fname );
115 void __kmp_str_loc_free( kmp_str_loc_t * loc );
116 
117 int __kmp_str_eqf( char const * lhs, char const * rhs );
118 char * __kmp_str_format( char const * format, ... );
119 void __kmp_str_free( char const * * str );
120 int __kmp_str_match( char const * target, int len, char const * data );
121 int __kmp_str_match_false( char const * data );
122 int __kmp_str_match_true( char const * data );
123 void __kmp_str_replace( char * str, char search_for, char replace_with );
124 void __kmp_str_split( char * str, char delim, char ** head, char ** tail );
125 char * __kmp_str_token( char * str, char const * delim, char ** buf );
126 int __kmp_str_to_int( char const * str, char sentinel );
127 
128 void __kmp_str_to_size( char const * str, size_t * out, size_t dfactor, char const * * error );
129 void __kmp_str_to_uint( char const * str, kmp_uint64 * out, char const * * error );
130 
131 #ifdef __cplusplus
132  } // extern "C"
133 #endif // __cplusplus
134 
135 #endif // KMP_STR_H
136 
137 // end of file //
138