kmp_str.h

Go to the documentation of this file.
00001 /*
00002  * kmp_str.h -- String manipulation routines.
00003  * $Revision: 42150 $
00004  * $Date: 2013-03-15 15:40:38 -0500 (Fri, 15 Mar 2013) $
00005  */
00006 
00007 /* <copyright>
00008     Copyright (c) 1997-2013 Intel Corporation.  All Rights Reserved.
00009 
00010     Redistribution and use in source and binary forms, with or without
00011     modification, are permitted provided that the following conditions
00012     are met:
00013 
00014       * Redistributions of source code must retain the above copyright
00015         notice, this list of conditions and the following disclaimer.
00016       * Redistributions in binary form must reproduce the above copyright
00017         notice, this list of conditions and the following disclaimer in the
00018         documentation and/or other materials provided with the distribution.
00019       * Neither the name of Intel Corporation nor the names of its
00020         contributors may be used to endorse or promote products derived
00021         from this software without specific prior written permission.
00022 
00023     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027     HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 
00035 
00036 ------------------------------------------------------------------------
00037 
00038     Portions of this software are protected under the following patents:
00039         U.S. Patent 5,812,852
00040         U.S. Patent 6,792,599
00041         U.S. Patent 7,069,556
00042         U.S. Patent 7,328,433
00043         U.S. Patent 7,500,242
00044 
00045 </copyright> */
00046 
00047 #ifndef KMP_STR_H
00048 #define KMP_STR_H
00049 
00050 #include <string.h>
00051 #include <stdarg.h>
00052 
00053 #include "kmp_os.h"
00054 
00055 #ifdef __cplusplus
00056     extern "C" {
00057 #endif // __cplusplus
00058 
00059 #if KMP_OS_WINDOWS
00060     #define strdup    _strdup
00061     #define snprintf  _snprintf
00062     #define vsnprintf _vsnprintf
00063 #endif
00064 
00065 /*  some macros to replace ctype.h functions  */
00066 #define TOLOWER(c)  ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) + 'a' - 'A') : (c))
00067 
00068 struct kmp_str_buf {
00069     char * str;             // Pointer to buffer content, read only.
00070     int    size;            // Do not change this field!
00071     int    used;            // Number of characters printed to buffer, read only.
00072     char   bulk[ 512 ];     // Do not use this field!
00073 }; // struct kmp_str_buf
00074 typedef struct kmp_str_buf  kmp_str_buf_t;
00075 
00076 #define __kmp_str_buf_init( b )   { (b)->str = (b)->bulk; (b)->size = sizeof( (b)->bulk ); (b)->used = 0; (b)->bulk[ 0 ] = 0; }
00077 
00078 void   __kmp_str_buf_clear( kmp_str_buf_t * buffer );
00079 void   __kmp_str_buf_reserve( kmp_str_buf_t * buffer, int size );
00080 void   __kmp_str_buf_detach( kmp_str_buf_t * buffer );
00081 void   __kmp_str_buf_free( kmp_str_buf_t * buffer );
00082 void   __kmp_str_buf_cat( kmp_str_buf_t * buffer, char const * str, int len );
00083 void   __kmp_str_buf_vprint( kmp_str_buf_t * buffer, char const * format, va_list args );
00084 void   __kmp_str_buf_print( kmp_str_buf_t * buffer, char const * format, ... );
00085 void   __kmp_str_buf_print_size( kmp_str_buf_t * buffer, size_t size );
00086 
00087 /*
00088     File name parser. Usage:
00089 
00090         kmp_str_fname_t fname = __kmp_str_fname_init( path );
00091         // Use fname.path (copy of original path ), fname.dir, fname.base.
00092         // Note fname.dir concatenated with fname.base gives exact copy of path.
00093         __kmp_str_fname_free( & fname );
00094 
00095 */
00096 struct kmp_str_fname {
00097     char * path;
00098     char * dir;
00099     char * base;
00100 }; // struct kmp_str_fname
00101 typedef struct kmp_str_fname kmp_str_fname_t;
00102 void __kmp_str_fname_init( kmp_str_fname_t * fname, char const * path );
00103 void __kmp_str_fname_free( kmp_str_fname_t * fname );
00104 // Compares file name with specified patern. If pattern is NULL, any fname matched.
00105 int __kmp_str_fname_match( kmp_str_fname_t const * fname, char const * pattern );
00106 
00107 /*
00108     The compiler provides source locations in string form ";file;func;line;col;;". It not not
00109     convenient for manupulation. These structure keeps source location in more convenient form.
00110     Usage:
00111 
00112         kmp_str_loc_t loc = __kmp_str_loc_init( ident->psource, 0 );
00113         // use loc.file, loc.func, loc.line, loc.col.
00114         // loc.fname is available if the second argument of __kmp_str_loc_init is true.
00115         __kmp_str_loc_free( & loc );
00116 
00117     If psource is NULL or does not follow format above, file and/or func may be NULL pointers.
00118 */
00119 struct kmp_str_loc {
00120     char *          _bulk;  // Do not use thid field.
00121     kmp_str_fname_t fname;  // Will be initialized if init_fname is true.
00122     char *          file;
00123     char *          func;
00124     int             line;
00125     int             col;
00126 }; // struct kmp_str_loc
00127 typedef struct kmp_str_loc kmp_str_loc_t;
00128 kmp_str_loc_t __kmp_str_loc_init( char const * psource, int init_fname );
00129 void __kmp_str_loc_free( kmp_str_loc_t * loc );
00130 
00131 int    __kmp_str_eqf( char const * lhs, char const * rhs );
00132 char * __kmp_str_format( char const * format, ... );
00133 void   __kmp_str_free( char const * * str );
00134 int    __kmp_str_match( char const * target, int len, char const * data );
00135 int    __kmp_str_match_false( char const * data );
00136 int    __kmp_str_match_true( char const * data );
00137 void   __kmp_str_replace( char * str, char search_for, char replace_with );
00138 void   __kmp_str_split( char * str, char delim, char ** head, char ** tail );
00139 char * __kmp_str_token( char * str, char const * delim, char ** buf );
00140 int    __kmp_str_to_int( char const * str, char sentinel );
00141 
00142 void __kmp_str_to_size( char const * str, size_t * out, size_t dfactor, char const * * error );
00143 void __kmp_str_to_uint( char const * str, kmp_uint64 * out, char const * * error );
00144 
00145 #ifdef __cplusplus
00146     } // extern "C"
00147 #endif // __cplusplus
00148 
00149 #endif // KMP_STR_H
00150 
00151 // end of file //
00152 

Generated on 25 Aug 2013 for libomp_oss by  doxygen 1.6.1