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