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