PageRenderTime 45ms CodeModel.GetById 30ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/Proj4/emess.c

http://github.com/route-me/route-me
C | 60 lines | 51 code | 3 blank | 6 comment | 11 complexity | 50f880e7425b3e52d34ac8edd7be904a MD5 | raw file
 1/* Error message processing */
 2#ifndef lint
 3static const char SCCSID[]="@(#)emess.c	4.6	94/05/24	GIE	REL";
 4#endif
 5
 6#ifdef _MSC_VER
 7#  ifndef _CRT_SECURE_NO_DEPRECATE
 8#    define _CRT_SECURE_NO_DEPRECATE
 9#  endif
10#  ifndef _CRT_NONSTDC_NO_DEPRECATE
11#    define _CRT_NONSTDC_NO_DEPRECATE
12#  endif
13#endif
14
15#include <stdio.h>
16#include <stdlib.h>
17#include <stdarg.h>
18#include <errno.h>
19#include <string.h>
20#include "proj_api.h"
21#define EMESS_ROUTINE
22#include "emess.h"
23	void
24emess(int code, char *fmt, ...) {
25	va_list args;
26
27	va_start(args, fmt);
28	/* prefix program name, if given */
29	if (fmt != NULL)
30		(void)fprintf(stderr,"%s\n<%s>: ",pj_get_release(),
31                              emess_dat.Prog_name);
32	/* print file name and line, if given */
33	if (emess_dat.File_name != NULL && *emess_dat.File_name) {
34		(void)fprintf(stderr,"while processing file: %s", emess_dat.File_name);
35		if (emess_dat.File_line > 0)
36			(void)fprintf(stderr,", line %d\n", emess_dat.File_line);
37		else
38			(void)fputc('\n', stderr);
39	} else
40		putc('\n', stderr);
41	/* if |code|==2, print errno code data */
42	if (code == 2 || code == -2)
43		(void)fprintf(stderr, "Sys errno: %d: %s\n",
44			errno,
45#ifdef HAVE_STRERROR
46			strerror(errno));
47#else
48			"<system mess. texts unavail.>");
49#endif
50	/* post remainder of call data */
51	(void)vfprintf(stderr,fmt,args);
52	va_end(args);
53	/* die if code positive */
54	if (code > 0) {
55		(void)fputs("\nprogram abnormally terminated\n", stderr);
56		exit(code);
57	}
58	else
59		putc('\n', stderr);
60}