kmp_i18n.h

Go to the documentation of this file.
00001 /*
00002  * kmp_i18n.h
00003  * $Revision: 42061 $
00004  * $Date: 2013-02-28 16:36:24 -0600 (Thu, 28 Feb 2013) $
00005  */
00006 
00007 /* <copyright>
00008     Copyright (c) 2007-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_I18N_H
00048 #define KMP_I18N_H
00049 
00050 #include "kmp_str.h"
00051 
00052 #ifdef __cplusplus
00053     extern "C" {
00054 #endif // __cplusplus
00055 
00056 /*
00057     kmp_i18n_id.inc defines kmp_i18n_id_t type. It is an enumeration with identifiers of all the
00058     messages in the catalog. There is one special identifier: kmp_i18n_null, which denotes absence
00059     of message.
00060 */
00061 #include "kmp_i18n_id.inc" // Generated file. Do not edit it manually.
00062 
00063 /*
00064     Low-level functions handling message catalog. __kmp_i18n_open() opens message catalog,
00065     __kmp_i18n_closes() it. Explicit opening is not required: if message catalog is not yet open,
00066     __kmp_i18n_catgets() will open it implicitly. However, catalog should be explicitly closed,
00067     otherwise resources (mamory, handles) may leak.
00068 
00069     __kmp_i18n_catgets() returns read-only string. It should not be freed.
00070 
00071     KMP_I18N_STR macro simplifies acces to strings in message catalog a bit. Following two lines are
00072     equivalent:
00073 
00074         __kmp_i18n_catgets( kmp_i18n_str_Warning )
00075         KMP_I18N_STR( Warning )
00076 */
00077 
00078 void            __kmp_i18n_catopen();
00079 void            __kmp_i18n_catclose();
00080 char const *    __kmp_i18n_catgets( kmp_i18n_id_t id );
00081 
00082 #define KMP_I18N_STR( id )    __kmp_i18n_catgets( kmp_i18n_str_ ## id )
00083 
00084 
00085 /*
00086     ------------------------------------------------------------------------------------------------
00087 
00088     High-level interface for printing strings targeted to the user.
00089 
00090     All the strings are divided into 3 types:
00091 
00092         * messages,
00093         * hints,
00094         * system errors.
00095 
00096     There are 3 kind of message severities:
00097 
00098         * informational messages,
00099         * warnings (non-fatal errors),
00100         * fatal errors.
00101 
00102     For example:
00103 
00104         OMP: Warning #2: Cannot open message catalog "libguide.cat":   (1)
00105         OMP: System error #2: No such file or directory                (2)
00106         OMP: Hint: Please check NLSPATH environment variable.          (3)
00107         OMP: Info #3: Default messages will be used.                   (4)
00108 
00109     where
00110 
00111         (1) is a message of warning severity,
00112         (2) is a system error caused the previos warning,
00113         (3) is a hint for the user how to fix the problem,
00114         (4) is a message of informational severity.
00115 
00116    Usage in complex cases (message is accompanied with hints and system errors):
00117 
00118        int error = errno;   // We need save errno immediately, because it may be changed.
00119        __kmp_msg(
00120            kmp_ms_warning,                            // Severity
00121            KMP_MSG( CantOpenMessageCatalog, name ),   // Primary message
00122            KMP_ERR( error ),                          // System error
00123            KMP_HNT( CheckNLSPATH ),                   // Hint
00124            __kmp_msg_null                             // Variadic argument list finisher
00125        );
00126 
00127     Usage in simple cases (just a message, no system errors or hints):
00128 
00129         KMP_INFORM( WillUseDefaultMessages );
00130         KMP_WARNING( CantOpenMessageCatalog, name );
00131         KMP_FATAL( StackOverlap );
00132         KMP_SYSFAIL( "pthread_create", status );
00133         KMP_CHECK_SYSFAIL( "pthread_create", status );
00134         KMP_CHECK_SYSFAIL_ERRNO( "gettimeofday", status );
00135 
00136     ------------------------------------------------------------------------------------------------
00137 */
00138 
00139 enum kmp_msg_type {
00140     kmp_mt_dummy  =  0, // Special type for internal purposes.
00141     kmp_mt_mesg   =  4, // Primary OpenMP message, could be information, warning, or fatal.
00142     kmp_mt_hint   =  5, // Hint to the user.
00143     kmp_mt_syserr = -1  // System error message.
00144 }; // enum kmp_msg_type
00145 typedef enum kmp_msg_type  kmp_msg_type_t;
00146 
00147 struct kmp_msg {
00148     kmp_msg_type_t  type;
00149     int             num;
00150     char const *    str;
00151     int             len;
00152 }; // struct kmp_message
00153 typedef struct kmp_msg  kmp_msg_t;
00154 
00155 // Two special messages.
00156 extern kmp_msg_t __kmp_msg_empty;  // Can be used in place where message is required syntactically.
00157 extern kmp_msg_t __kmp_msg_null;   // Denotes the end of variadic list of arguments.
00158 
00159 // Helper functions. Creates messages either from message catalog or from system. Note: these
00160 // functions allocate memory. You should pass created messages to __kmp_msg() function, it will
00161 // print messages and destroy them.
00162 kmp_msg_t  __kmp_msg_format( kmp_i18n_id_t id, ... );
00163 kmp_msg_t  __kmp_msg_error_code( int code );
00164 kmp_msg_t  __kmp_msg_error_mesg( char const * mesg );
00165 
00166 // Helper macros to make calls shorter.
00167 #define KMP_MSG( ...  )   __kmp_msg_format( kmp_i18n_msg_ ## __VA_ARGS__ )
00168 #define KMP_HNT( ...  )   __kmp_msg_format( kmp_i18n_hnt_ ## __VA_ARGS__ )
00169 #define KMP_SYSERRCODE( code )  __kmp_msg_error_code( code )
00170 #define KMP_SYSERRMESG( mesg )  __kmp_msg_error_mesg( mesg )
00171 #define KMP_ERR KMP_SYSERRCODE
00172 
00173 // Message severity.
00174 enum kmp_msg_severity {
00175     kmp_ms_inform,      // Just information for the user.
00176     kmp_ms_warning,     // Non-fatal error, execution continues.
00177     kmp_ms_fatal        // Fatal error, program aborts.
00178 }; // enum kmp_msg_severity
00179 typedef enum kmp_msg_severity  kmp_msg_severity_t;
00180 
00181 // Primary function for printing messages for the user. The first message is mandatory. Any number
00182 // of system errors and hints may be specified. Argument list must be finished with __kmp_msg_null.
00183 void    __kmp_msg( kmp_msg_severity_t severity, kmp_msg_t message, ... );
00184 
00185 // Helper macros to make calls shorter in simple cases.
00186 #define KMP_INFORM( ...  ) __kmp_msg( kmp_ms_inform,  KMP_MSG( __VA_ARGS__ ), __kmp_msg_null )
00187 #define KMP_WARNING( ... ) __kmp_msg( kmp_ms_warning, KMP_MSG( __VA_ARGS__ ), __kmp_msg_null )
00188 #define KMP_FATAL(   ... ) __kmp_msg( kmp_ms_fatal,   KMP_MSG( __VA_ARGS__ ), __kmp_msg_null )
00189 #define KMP_SYSFAIL( func, error )                                                                 \
00190     __kmp_msg(                                                                                     \
00191         kmp_ms_fatal,                                                                              \
00192         KMP_MSG( FunctionError, func ),                                                            \
00193         KMP_SYSERRCODE( error ),                                                                   \
00194         __kmp_msg_null                                                                             \
00195     )
00196 
00197 // Check error, if not zero, generate fatal error message.
00198 #define KMP_CHECK_SYSFAIL( func, error )                                                           \
00199     {                                                                                              \
00200         if ( error ) {                                                                             \
00201             KMP_SYSFAIL( func, error );                                                            \
00202         };                                                                                         \
00203     }
00204 
00205 // Check status, if not zero, generate fatal error message using errno.
00206 #define KMP_CHECK_SYSFAIL_ERRNO( func, status )                                                    \
00207     {                                                                                              \
00208         if ( status != 0 ) {                                                                       \
00209             int error = errno;                                                                     \
00210             KMP_SYSFAIL( func, error );                                                            \
00211         };                                                                                         \
00212     }
00213 
00214 #ifdef KMP_DEBUG
00215     void __kmp_i18n_dump_catalog( kmp_str_buf_t & buffer );
00216 #endif // KMP_DEBUG
00217 
00218 #ifdef __cplusplus
00219     }; // extern "C"
00220 #endif // __cplusplus
00221 
00222 #endif // KMP_I18N_H
00223 
00224 // end of file //

Generated on 25 Aug 2013 for libomp_oss by  doxygen 1.6.1