/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
  3. static const char SCCSID[]="@(#)emess.c 4.6 94/05/24 GIE REL";
  4. #endif
  5. #ifdef _MSC_VER
  6. # ifndef _CRT_SECURE_NO_DEPRECATE
  7. # define _CRT_SECURE_NO_DEPRECATE
  8. # endif
  9. # ifndef _CRT_NONSTDC_NO_DEPRECATE
  10. # define _CRT_NONSTDC_NO_DEPRECATE
  11. # endif
  12. #endif
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <stdarg.h>
  16. #include <errno.h>
  17. #include <string.h>
  18. #include "proj_api.h"
  19. #define EMESS_ROUTINE
  20. #include "emess.h"
  21. void
  22. emess(int code, char *fmt, ...) {
  23. va_list args;
  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. }