Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
lmessage.c
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2.1 of the GNU Lesser General Public License 
00007   as published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU Lesser General Public 
00021   License along with this program; if not, write the Free Software 
00022   Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 
00023   USA.
00024 
00025   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00026   Mountain View, CA 94043, or:
00027 
00028   http://www.sgi.com
00029 
00030   For further information regarding this notice, see:
00031 
00032   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00033 
00034 */
00035 
00036 
00037 #pragma ident "@(#) libu/errmsg/lmessage.c      92.4    10/14/99 17:05:30"
00038 #include <liberrno.h>
00039 #include <errno.h>
00040 #include <fcntl.h>
00041 
00042 #if !defined(_ABSOFT)
00043 # include <nl_types.h>
00044 #else
00045 # include "ac_msg_type.h"
00046 #endif
00047 
00048 #include <stdio.h>
00049 #include <stdarg.h>
00050 #include <string.h>
00051 
00052 #if defined(_ABSOFT) && defined(TARGET_NT)
00053 # include <siohdr.h>
00054 #endif
00055 
00056 #include <cray/nlcatmsg.h> /* Open64 header */
00057 
00058 #ifdef  _UNICOS
00059 # include <tapereq.h>
00060   extern char   **_argv;
00061 # define CMDNAME (*_argv)
00062 #else
00063 # include <cray/portdefs.h>
00064 # define CMDNAME ""
00065 #endif
00066 
00067 
00068 /*
00069  *      _lmessage - run-time library message processor
00070  *
00071  *              errn            Message number
00072  *              severity        Pointer to message severity; NULL if
00073  *                              unrecoverable error message
00074  */
00075 
00076 void
00077 _lmessage(int errn, char *severity, va_list args)
00078 {
00079         register int    flmn;           /* library message number       */
00080         char            mbuf[MAXMLN+1]; /* Message buffer               */
00081         char            tbuf[MAXMLN+1]; /* Temporary message buffer     */
00082         char            *mcnm;          /* Pointer to msg. catalog name */
00083         char            *bmsg;          /* Pointer to back-up message   */
00084         char            *smsg;          /* Pointer to severity text     */
00085         nl_catd         mcfd;           /* Message catalog descriptor   */
00086 #ifdef  __mips
00087         static nl_catd  lib_mcfd;       /* lib msg cat file descriptor  */
00088         static int      lib_mcfd_opnd = 0; /* lib msg cat already open flag */
00089         int             lib_mcat = 0;   /* lib msg catalog indicator    */
00090 #endif  /* __mips */
00091 
00092 #ifdef  _UNICOS
00093         if (_numargs() == 0)
00094                 (void) abort();
00095 #endif
00096 
00097         mbuf[0] = '\n';
00098         mbuf[1] = '\0';
00099         bmsg    = NULL;         /* Assume no back-up message */
00100         smsg    = "";           /* Assume unset severity */
00101         flmn    = errn;
00102 
00103         /*
00104          * Map -1 errors to FERDPEOF (temporarily, we hope)
00105          * Map all negative errors to positive errors.
00106          */
00107 
00108         if (flmn < 0)
00109                 if (flmn == -1)
00110                         flmn    = FERDPEOF;
00111                 else
00112                         flmn    = -flmn;
00113 
00114         if (flmn < BASE) {
00115                 mcnm    = "sys";
00116                 smsg    = "UNRECOVERABLE error on system request";
00117 #ifdef  _UNICOS
00118                 /*
00119                  * Provide a back-up error message for those errors
00120                  * where we expect that the message system will fail
00121                  * to retrieve a message.
00122                  */
00123 
00124                 if (flmn == ENOMEM)
00125                         bmsg    = "Unable to allocate memory.";
00126 
00127                 if (flmn == EMFILE)
00128                         bmsg    = "Too many open files.";
00129 #else
00130                 /*
00131                  * Use strerror() to provide a back-up error message
00132                  * for 'sys' errors on non-UNICOS systems.  We don't
00133                  * want to load strerror() on UNICOS systems, however.
00134                  */
00135 
00136                 bmsg    = strerror(flmn);
00137 #endif
00138         }
00139         else
00140                 if (flmn < (BASE+999) ||
00141                     (flmn >= FDC_ERRB && flmn < (FDC_ERRB+999))) {
00142                         mcnm    = FEMCN;        /* Library catalog name */
00143 #ifdef  __mips
00144                         lib_mcat        = 1;
00145 #endif  /* __mips */
00146                         smsg    = "UNRECOVERABLE library error";
00147 
00148                         /*
00149                          * Provide a minimal back-up message for
00150                          * out-of-memory errors.
00151                          */
00152 
00153                         if (flmn == FENOMEMY || flmn == FEFMTMEM ||
00154                             flmn == FDC_ERR_NOMEM)
00155                                 bmsg    = "Unable to allocate memory.";
00156                 }
00157 #ifdef  _UNICOS
00158                 else
00159                         if (flmn >= ETFIRST && flmn <= ETLAST) {
00160                                 mcnm    = "tape";
00161                                 smsg    = "UNRECOVERABLE tape error";
00162                                 bmsg    = "Consult Appendix C, Tape Subsystem User's Guide, SG-2051";
00163                         }
00164 #endif
00165                         else {
00166                                 mcnm    = "unknown";
00167                                 smsg    = "UNRECOVERABLE";
00168                                 bmsg    = "Unrecognized error number";
00169                         }
00170 
00171         if (bmsg != NULL)       /* Set back-up message, if extant */
00172                 (void) strcpy(&mbuf[1], bmsg);
00173 
00174         if (severity != NULL)
00175                 smsg    = severity;
00176 
00177         /* Open the message catalog */
00178 
00179 #if defined(__sgi)
00180         /* if this is the library message catalog, then... */ 
00181         if (lib_mcat) {
00182                 if (lib_mcfd_opnd) {
00183                         /* set lib msg cat fd to opened lib msg cat fd */
00184                         mcfd    = lib_mcfd;
00185                 } else {
00186                         /* message catalog not opened yet, do the following:
00187                          * 1. open it
00188                          * 2. save the lib msg cat fd
00189                          * 3. set flag indicating it was opened
00190                          */
00191                         mcfd    = catopen(mcnm, 0);
00192                         lib_mcfd        = mcfd;
00193                         lib_mcfd_opnd   = 1;
00194                 }
00195         } else {
00196                 /* not the lib message catalog, open catalog */
00197                 mcfd    = catopen(mcnm, 0);
00198         }
00199 #else
00200         mcfd    = catopen(mcnm, 0);
00201 #endif
00202 
00203         /* Retrieve the raw message text */
00204 
00205         (void) catgetmsg(mcfd, NL_MSGSET, flmn, &mbuf[1], MAXMLN);
00206 
00207         /* Edit the message */
00208 
00209         (void) vsprintf(tbuf, &mbuf[1], args);
00210 
00211         /* Format the message */
00212 
00213         (void) catmsgfmt(CMDNAME, mcnm, flmn, smsg, tbuf, &mbuf[1],
00214                          MAXMLN, NULL, NULL);
00215 
00216         /* Print the formatted message */
00217         fwrite(mbuf, strlen(mbuf), 1, stderr);
00218 
00219         return;
00220 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines