void _lmessage(int errn, char *severity, va_list args) { register int flmn; /* library message number */ char mbuf[MAXMLN+1]; /* Message buffer */ char tbuf[MAXMLN+1]; /* Temporary message buffer */ char *mcnm; /* Pointer to msg. catalog name */ char *bmsg; /* Pointer to back-up message */ char *smsg; /* Pointer to severity text */ char *dmsg; /* Pointer to default message text */ #ifdef _UNICOS if (_numargs() == 0) (void) abort(); #endif mbuf[0] = '\n'; mbuf[1] = '\0'; bmsg = NULL; /* Assume no back-up message */ smsg = ""; /* Assume unset severity */ flmn = errn; /* * Map -1 errors to FERDPEOF (temporarily, we hope) * Map all negative errors to positive errors. */ if (flmn < 0) if (flmn == -1) flmn = FERDPEOF; else flmn = -flmn; if (flmn < BASE) { mcnm = "sys"; #ifdef KEY /* Bug 4452 */ smsg = "UNRECOVERABLE error on system request\nlib-%d: %s"; #else /* KEY Bug 4452 */ smsg = "UNRECOVERABLE error on system request"; #endif /* KEY Bug 4452 */ #ifdef _UNICOS /* * Provide a back-up error message for those errors * where we expect that the message system will fail * to retrieve a message. */ if (flmn == ENOMEM) bmsg = "Unable to allocate memory."; if (flmn == EMFILE) bmsg = "Too many open files."; #else /* * Use strerror() to provide a back-up error message * for 'sys' errors on non-UNICOS systems. We don't * want to load strerror() on UNICOS systems, however. */ bmsg = strerror(flmn); #ifdef KEY /* Bug 4452 */ /* Write these messages and return, because we won't be able * to find flmn in the message catalog. */ fprintf(stderr, smsg, flmn, bmsg); return; #endif /* KEY Bug 4452 */ #endif } else if (flmn < (BASE+999) || (flmn >= FDC_ERRB && flmn < (FDC_ERRB+999))) { mcnm = FEMCN; /* Library catalog name */ smsg = "UNRECOVERABLE library error"; /* * Provide a minimal back-up message for * out-of-memory errors. */ if (flmn == FENOMEMY || flmn == FEFMTMEM || flmn == FDC_ERR_NOMEM) bmsg = "Unable to allocate memory."; } #ifdef _UNICOS else if (flmn >= ETFIRST && flmn <= ETLAST) { mcnm = "tape"; smsg = "UNRECOVERABLE tape error"; bmsg = "Consult Appendix C, Tape Subsystem User's Guide, SG-2051"; } #endif else { mcnm = "unknown"; smsg = "UNRECOVERABLE"; bmsg = "Unrecognized error number"; } if (bmsg != NULL) /* Set back-up message, if extant */ (void) strcpy(&mbuf[1], bmsg); if (severity != NULL) smsg = severity; /* Retrieve the raw message text */ dmsg = libu_defgets(flmn); if (dmsg != NULL) { size_t len; len = strlen(dmsg); if (len >= MAXMLN) len = MAXMLN - 1; (void) strncpy(&mbuf[1], dmsg, len); mbuf[len + 1] = '\0'; } /* Edit the message */ (void) vsprintf(tbuf, &mbuf[1], args); /* Format the message */ (void) catmsgfmt(CMDNAME, mcnm, flmn, smsg, tbuf, &mbuf[1], MAXMLN, NULL, NULL); /* Print the formatted message */ #if !defined(_ABSOFT) (void) write(fileno(stderr), mbuf, strlen(mbuf)); #else fwrite(mbuf, strlen(mbuf), 1, stderr); #endif return; }
void _lmessage(int errn, char *severity, va_list args) { register int flmn; /* library message number */ char mbuf[MAXMLN+1]; /* Message buffer */ char tbuf[MAXMLN+1]; /* Temporary message buffer */ char *mcnm; /* Pointer to msg. catalog name */ char *bmsg; /* Pointer to back-up message */ char *smsg; /* Pointer to severity text */ nl_catd mcfd; /* Message catalog descriptor */ #ifdef __mips static nl_catd lib_mcfd; /* lib msg cat file descriptor */ static int lib_mcfd_opnd = 0; /* lib msg cat already open flag */ int lib_mcat = 0; /* lib msg catalog indicator */ #endif /* __mips */ #ifdef _UNICOS if (_numargs() == 0) (void) abort(); #endif mbuf[0] = '\n'; mbuf[1] = '\0'; bmsg = NULL; /* Assume no back-up message */ smsg = ""; /* Assume unset severity */ flmn = errn; /* * Map -1 errors to FERDPEOF (temporarily, we hope) * Map all negative errors to positive errors. */ if (flmn < 0) if (flmn == -1) flmn = FERDPEOF; else flmn = -flmn; if (flmn < BASE) { mcnm = "sys"; smsg = "UNRECOVERABLE error on system request"; #ifdef _UNICOS /* * Provide a back-up error message for those errors * where we expect that the message system will fail * to retrieve a message. */ if (flmn == ENOMEM) bmsg = "Unable to allocate memory."; if (flmn == EMFILE) bmsg = "Too many open files."; #else /* * Use strerror() to provide a back-up error message * for 'sys' errors on non-UNICOS systems. We don't * want to load strerror() on UNICOS systems, however. */ bmsg = strerror(flmn); #endif } else if (flmn < (BASE+999) || (flmn >= FDC_ERRB && flmn < (FDC_ERRB+999))) { mcnm = FEMCN; /* Library catalog name */ #ifdef __mips lib_mcat = 1; #endif /* __mips */ smsg = "UNRECOVERABLE library error"; /* * Provide a minimal back-up message for * out-of-memory errors. */ if (flmn == FENOMEMY || flmn == FEFMTMEM || flmn == FDC_ERR_NOMEM) bmsg = "Unable to allocate memory."; } #ifdef _UNICOS else if (flmn >= ETFIRST && flmn <= ETLAST) { mcnm = "tape"; smsg = "UNRECOVERABLE tape error"; bmsg = "Consult Appendix C, Tape Subsystem User's Guide, SG-2051"; } #endif else { mcnm = "unknown"; smsg = "UNRECOVERABLE"; bmsg = "Unrecognized error number"; } if (bmsg != NULL) /* Set back-up message, if extant */ (void) strcpy(&mbuf[1], bmsg); if (severity != NULL) smsg = severity; /* Open the message catalog */ #ifdef __mips /* if this is the library message catalog, then... */ if (lib_mcat) { if (lib_mcfd_opnd) { /* set lib msg cat fd to opened lib msg cat fd */ mcfd = lib_mcfd; } else { /* message catalog not opened yet, do the following: * 1. open it * 2. save the lib msg cat fd * 3. set flag indicating it was opened */ mcfd = catopen(mcnm, 0); lib_mcfd = mcfd; lib_mcfd_opnd = 1; } } else { /* not the lib message catalog, open catalog */ mcfd = catopen(mcnm, 0); } #else /* __mips */ mcfd = catopen(mcnm, 0); #endif /* __mips */ /* Retrieve the raw message text */ (void) catgetmsg(mcfd, NL_MSGSET, flmn, &mbuf[1], MAXMLN); /* Edit the message */ (void) vsprintf(tbuf, &mbuf[1], args); /* Format the message */ (void) catmsgfmt(CMDNAME, mcnm, flmn, smsg, tbuf, &mbuf[1], MAXMLN, NULL, NULL); /* Print the formatted message */ #if !defined(_ABSOFT) (void) write(fileno(stderr), mbuf, strlen(mbuf)); #else fwrite(mbuf, strlen(mbuf), 1, stderr); #endif return; }
void _lmessage(int errn, char *severity, va_list args) { register int flmn; /* library message number */ char mbuf[MAXMLN+1]; /* Message buffer */ char tbuf[MAXMLN+1]; /* Temporary message buffer */ char *mcnm; /* Pointer to msg. catalog name */ char *bmsg; /* Pointer to back-up message */ char *smsg; /* Pointer to severity text */ nl_catd mcfd; /* Message catalog descriptor */ #ifdef __mips static nl_catd lib_mcfd; /* lib msg cat file descriptor */ static int lib_mcfd_opnd = 0; /* lib msg cat already open flag */ int lib_mcat = 0; /* lib msg catalog indicator */ #endif /* __mips */ #ifdef _UNICOS if (_numargs() == 0) (void) abort(); #endif mbuf[0] = '\n'; mbuf[1] = '\0'; bmsg = NULL; /* Assume no back-up message */ smsg = ""; /* Assume unset severity */ flmn = errn; /* * Map -1 errors to FERDPEOF (temporarily, we hope) * Map all negative errors to positive errors. */ if (flmn < 0) if (flmn == -1) flmn = FERDPEOF; else flmn = -flmn; if (flmn < BASE) { mcnm = "sys"; #ifdef KEY /* Bug 4452 */ smsg = "UNRECOVERABLE error on system request\nlib-%d: %s"; #else /* KEY Bug 4452 */ smsg = "UNRECOVERABLE error on system request"; #endif /* KEY Bug 4452 */ #ifdef _UNICOS /* * Provide a back-up error message for those errors * where we expect that the message system will fail * to retrieve a message. */ if (flmn == ENOMEM) bmsg = "Unable to allocate memory."; if (flmn == EMFILE) bmsg = "Too many open files."; #else /* * Use strerror() to provide a back-up error message * for 'sys' errors on non-UNICOS systems. We don't * want to load strerror() on UNICOS systems, however. */ bmsg = strerror(flmn); #ifdef KEY /* Bug 4452 */ /* Write these messages and return, because we won't be able * to find flmn in the message catalog. */ fprintf(stderr, smsg, flmn, bmsg); return; #endif /* KEY Bug 4452 */ #endif } else if (flmn < (BASE+999) || (flmn >= FDC_ERRB && flmn < (FDC_ERRB+999))) { mcnm = FEMCN; /* Library catalog name */ #ifdef __mips lib_mcat = 1; #endif /* __mips */ smsg = "UNRECOVERABLE library error"; /* * Provide a minimal back-up message for * out-of-memory errors. */ if (flmn == FENOMEMY || flmn == FEFMTMEM || flmn == FDC_ERR_NOMEM) bmsg = "Unable to allocate memory."; } #ifdef _UNICOS else if (flmn >= ETFIRST && flmn <= ETLAST) { mcnm = "tape"; smsg = "UNRECOVERABLE tape error"; bmsg = "Consult Appendix C, Tape Subsystem User's Guide, SG-2051"; } #endif else { mcnm = "unknown"; smsg = "UNRECOVERABLE"; bmsg = "Unrecognized error number"; } if (bmsg != NULL) /* Set back-up message, if extant */ (void) strcpy(&mbuf[1], bmsg); if (severity != NULL) smsg = severity; /* Open the message catalog */ #ifdef __mips /* if this is the library message catalog, then... */ if (lib_mcat) { if (lib_mcfd_opnd) { /* set lib msg cat fd to opened lib msg cat fd */ mcfd = lib_mcfd; } else { /* message catalog not opened yet, do the following: * 1. open it * 2. save the lib msg cat fd * 3. set flag indicating it was opened */ mcfd = catopen(mcnm, 0); lib_mcfd = mcfd; lib_mcfd_opnd = 1; } } else { /* not the lib message catalog, open catalog */ mcfd = catopen(mcnm, 0); } #else /* __mips */ mcfd = catopen(mcnm, 0); #endif /* __mips */ /* Retrieve the raw message text */ #ifdef KEY /* bug 6682 */ /* If we can't get the NLS message, print something lest the user * think that the boilerplate surrounding the missing message (e.g. * "Unit n not connected") is the real problem. Usual cause is a * C-coded "main" which hides the Fortran runtime "main". */ char *cgm_result; if (((nl_catd) -1) == mcfd || 0 == (cgm_result = catgetmsg(mcfd, NL_MSGSET, flmn, &mbuf[1], MAXMLN)) || 0 == *cgm_result) { strcpy(mbuf, "\nUnable to find error message (check NLSPATH, file lib.cat)"); } #else /* KEY bug 6682 */ (void) catgetmsg(mcfd, NL_MSGSET, flmn, &mbuf[1], MAXMLN); #endif /* KEY bug 6682 */ /* Edit the message */ (void) vsprintf(tbuf, &mbuf[1], args); /* Format the message */ (void) catmsgfmt(CMDNAME, mcnm, flmn, smsg, tbuf, &mbuf[1], MAXMLN, NULL, NULL); /* Print the formatted message */ #if !defined(_ABSOFT) (void) write(fileno(stderr), mbuf, strlen(mbuf)); #else fwrite(mbuf, strlen(mbuf), 1, stderr); #endif #ifdef KEY /* Bug 6673 */ /* If user wants verbose message, print it now. We always print the * terse message first because it might have substitutable arguments * which add meaning. We skip the first line of the verbose message * because it's the same as the terse message, with constant lexemes * in place of the substitutable arguments. */ if (cgm_result && *cgm_result) { verbose_message(mcnm, errn); } #endif /* KEY Bug 6673 */ return; }