Article View: net.micro.6809
Article #695err.c: Error numbers to English
From: Mark E. Sunderlin
Date: Tue, 10 Jun 1986 14:50
Date: Tue, 10 Jun 1986 14:50
94 lines
4188 bytes
4188 bytes
A few months ago Brian Lantz Published a small assemble program to
give you the error messages when you gave the program the error number.
Having always thought that "Anything Biran can do in asm, I can do in 'C'" I
write the following 'C' program. Hope it is useful to someone besides my self.
This is NOT a shell archive, so just cut out the program
----------------- CUT ------------- HERE -------------------------------------
/* err.c - a program to humanise error messages
* This program will give you the error
* mesage corrosponding to the error number you
* supply to the program. You may also specify
* your own error file instead of the default.
*
* Syntax: err errnum [errfile]
* Where "errnum" is the error number you want
* the message for and "errfile" is the optional
* error file.
*
* Author: Mark E. Sunderlin - aka Dr. Megabyte
* CIS:74026,3235 DEPHI:MEGABYTE
* USENET: ..ihnp4!chinet!megabyte
*/
#include <stdio.h>
#define ERRFILE "/d0/sys/errmsg" /* default error file */
#define MAXMSG 80 /* largest error msg (I hope!!) */
main(argc,argv)
int argc;
char *argv[];
{
int errnum; /* error number */
char errmesg[MAXMSG]; /* buffer for error message */
char errfile[20]; /* error file name */
FILE *errfp,*fopen();
if (argc < 2) /* No arguments given?? */
usage();
errnum = atoi(argv[1]); /* get error # from command line */
if (!errnum) { /* zero or bad number ?? */
printf("err: unknown error??\n");
exit(0);
}
strcpy(errfile,ERRFILE); /* set file name to default */
if (argc > 2) /* Alternate error file ?? */
strcpy(errfile,argv[2]); /* yes, set filename */
if ((errfp = fopen(errfile,"r")) == NULL) {
printf("err: can't open error file %s\n",errfile);
usage();
}
/* ok, now read the file which must be in the format of:
* errnum - error message
* until we find a match. We take advantge of the fact that
* atoi() only scans a string until it hits the 1st non-digit.
* Thus atoi("23skido") would return 23.
*/
while (fgets(errmesg,MAXMSG,errfp) != NULL) {
if (errnum == atoi(errmesg)) { /* got a match ?? */
printf("Error #%s",errmesg); /* print it */
fclose(errfp); /* close file */
exit(0); /* bye-bye */
}
}
/* We hit end of file with no matching error number */
printf("Error #%d not found in error file\n",errnum);
fclose(errfp);
usage();
} /* end of main() */
usage()
{
printf("usage: err errnum [errfile]\n");
printf(" where errnum is the error number to \n");
printf(" identify and errfile is an optional\n");
printf(" alternate errfile. Default is file \n");
printf(" %s\n",ERRFILE);
exit(0);
}
----------------- CUT ------------- HERE -------------------------------------
--
_________________________________________________________________________
UUCP: (1) seismo!dolqci!irsdcp!scsnet!sunder Mark E. Sunderlin
(2) ihnp4!chinet!megabyte aka Dr. Megabyte
CIS: 74026,3235 (202) 634-2529
Quote: "You have to have FAITH, for that to work on me!"
Mail: IRS 1111 Constitution Ave. NW PM:S:D:NO Washington, DC 20224
Technical Details
Message-ID:
<363@chinet.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbosgd!ihnp4!chinet!megabyteShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbosgd!ihnp4!chinet!megabyte From: megabyte@chinet.UUCP (Mark E. Sunderlin) Newsgroups: net.micro.6809 Subject: err.c: Error numbers to English Message-ID: <363@chinet.UUCP> Date: Tue, 10-Jun-86 10:50:31 EDT Article-I.D.: chinet.363 Posted: Tue Jun 10 10:50:31 1986 Date-Received: Sat, 14-Jun-86 00:52:57 EDT Reply-To: megabyte@chinet.UUCP (Mark E. Sunderlin) Distribution: net Organization: chi-net, Public Access UN*X, Chicago IL Lines: 94 Summary: program gives message whne you give number