nullpo.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. // #include "logs.h" // 布石してみる
  9. static void nullpo_info_core(const char *file, int line, const char *func,
  10. const char *fmt, va_list ap);
  11. /*======================================
  12. * Nullチェック 及び 情報出力
  13. *--------------------------------------*/
  14. int nullpo_chk_f(const char *file, int line, const char *func, const void *target,
  15. const char *fmt, ...)
  16. {
  17. va_list ap;
  18. if (target != NULL)
  19. return 0;
  20. va_start(ap, fmt);
  21. nullpo_info_core(file, line, func, fmt, ap);
  22. va_end(ap);
  23. return 1;
  24. }
  25. int nullpo_chk(const char *file, int line, const char *func, const void *target)
  26. {
  27. if (target != NULL)
  28. return 0;
  29. nullpo_info_core(file, line, func, NULL, NULL);
  30. return 1;
  31. }
  32. /*======================================
  33. * nullpo情報出力(外部呼出し向けラッパ)
  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. nullpo_info_core(file, line, func, NULL, NULL);
  46. }
  47. /*======================================
  48. * nullpo情報出力(Main)
  49. *--------------------------------------*/
  50. static void nullpo_info_core(const char *file, int line, const char *func,
  51. const char *fmt, va_list ap)
  52. {
  53. if (file == NULL)
  54. file = "??";
  55. func =
  56. func == NULL ? "unknown":
  57. func[0] == '\0' ? "unknown":
  58. func;
  59. ShowMessage("--- nullpo info --------------------------------------------\n");
  60. ShowMessage("%s:%d: in func `%s'\n", file, line, func);
  61. if (fmt != NULL)
  62. {
  63. if (fmt[0] != '\0')
  64. {
  65. vprintf(fmt, ap);
  66. // 最後に改行したか確認
  67. if (fmt[strlen(fmt)-1] != '\n')
  68. ShowMessage("\n");
  69. }
  70. }
  71. ShowMessage("--- end nullpo info ----------------------------------------\n");
  72. // ここらでnullpoログをファイルに書き出せたら
  73. // まとめて提出できるなと思っていたり。
  74. }