nullpo.c 2.3 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, const char *fmt, va_list ap);
  9. static void nullpo_info_core_(const char *file, int line, const char *func);
  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. if (target != NULL)
  27. return 0;
  28. nullpo_info_core_(file, line, func);
  29. return 1;
  30. }
  31. /*======================================
  32. * nullpo Information output (external call)
  33. *--------------------------------------*/
  34. void nullpo_info_f(const char *file, int line, const char *func,
  35. const char *fmt, ...)
  36. {
  37. va_list ap;
  38. va_start(ap, fmt);
  39. nullpo_info_core(file, line, func, fmt, ap);
  40. va_end(ap);
  41. }
  42. void nullpo_info(const char *file, int line, const char *func)
  43. {
  44. nullpo_info_core_(file, line, func);
  45. }
  46. static void nullpo_info_core_(const char *file, int line, const char *func){
  47. if (file == NULL)
  48. file = "??";
  49. func =
  50. func == NULL ? "unknown":
  51. func[0] == '\0' ? "unknown":
  52. func;
  53. ShowMessage("--- nullpo info --------------------------------------------\n");
  54. ShowMessage("%s:%d: in func `%s'\n", file, line, func);
  55. }
  56. /*======================================
  57. * nullpo intelligence Output (Main)
  58. *--------------------------------------*/
  59. static void nullpo_info_core(const char *file, int line, const char *func,
  60. const char *fmt, va_list ap)
  61. {
  62. nullpo_info_core_(file,line,func);
  63. if (fmt != NULL)
  64. {
  65. if (fmt[0] != '\0')
  66. {
  67. vprintf(fmt, ap);
  68. // Check whether the new line at the end
  69. if (fmt[strlen(fmt)-1] != '\n')
  70. ShowMessage("\n");
  71. }
  72. }
  73. ShowMessage("--- end nullpo info ----------------------------------------\n");
  74. }