nullpo.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include <stdio.h>
  4. #include <stdarg.h>
  5. #include <string.h>
  6. #include "nullpo.h"
  7. #include "../common/showmsg.h"
  8. static void nullpo_info_core(const char *file, int line, const char *func,
  9. const char *fmt, va_list ap);
  10. /*======================================
  11. * Null Information output and check
  12. *--------------------------------------*/
  13. int nullpo_chk_f(const char *file, int line, const char *func, const void *target,
  14. const char *fmt, ...)
  15. {
  16. va_list ap;
  17. if (target != NULL)
  18. return 0;
  19. va_start(ap, fmt);
  20. nullpo_info_core(file, line, func, fmt, ap);
  21. va_end(ap);
  22. return 1;
  23. }
  24. int nullpo_chk(const char *file, int line, const char *func, const void *target)
  25. {
  26. va_list ap;
  27. if (target != NULL)
  28. return 0;
  29. nullpo_info_core(file, line, func, NULL, ap);
  30. return 1;
  31. }
  32. /*======================================
  33. * nullpo Information output (external call)
  34. *--------------------------------------*/
  35. void nullpo_info_f(const char *file, int line, const char *func,
  36. const char *fmt, ...)
  37. {
  38. va_list ap;
  39. va_start(ap, fmt);
  40. nullpo_info_core(file, line, func, fmt, ap);
  41. va_end(ap);
  42. }
  43. void nullpo_info(const char *file, int line, const char *func)
  44. {
  45. va_list ap;
  46. nullpo_info_core(file, line, func, NULL, ap);
  47. }
  48. /*======================================
  49. * nullpo intelligence Output (Main)
  50. *--------------------------------------*/
  51. static void nullpo_info_core(const char *file, int line, const char *func,
  52. const char *fmt, va_list ap)
  53. {
  54. if (file == NULL)
  55. file = "??";
  56. func =
  57. func == NULL ? "unknown":
  58. func[0] == '\0' ? "unknown":
  59. func;
  60. ShowMessage("--- nullpo info --------------------------------------------\n");
  61. ShowMessage("%s:%d: in func `%s'\n", file, line, func);
  62. if (fmt != NULL)
  63. {
  64. if (fmt[0] != '\0')
  65. {
  66. vprintf(fmt, ap);
  67. // Check whether the new line at the end
  68. if (fmt[strlen(fmt)-1] != '\n')
  69. ShowMessage("\n");
  70. }
  71. }
  72. ShowMessage("--- end nullpo info ----------------------------------------\n");
  73. }