megabyte@chinet.UUCP (Mark E. Sunderlin) (06/10/86)
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