print_string.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*************************************************************************/
  2. /* print_string.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "print_string.h"
  30. #include "os/os.h"
  31. #include <stdio.h>
  32. static PrintHandlerList *print_handler_list=NULL;
  33. void add_print_handler(PrintHandlerList *p_handler) {
  34. _global_lock();
  35. p_handler->next=print_handler_list;
  36. print_handler_list=p_handler;
  37. _global_unlock();
  38. }
  39. void remove_print_handler(PrintHandlerList *p_handler) {
  40. OS::get_singleton()->print("pre-removing print handler...\n");
  41. _global_lock();
  42. PrintHandlerList *prev = NULL;
  43. PrintHandlerList *l = print_handler_list;
  44. OS::get_singleton()->print("removing print handler...\n");
  45. while(l) {
  46. if (l==p_handler) {
  47. OS::get_singleton()->print("found\n");
  48. if (prev)
  49. prev->next=l->next;
  50. else
  51. print_handler_list=l->next;
  52. break;
  53. }
  54. prev=l;
  55. l=l->next;
  56. }
  57. OS::get_singleton()->print("print hanlder list is %p\n",print_handler_list);
  58. ERR_FAIL_COND(l==NULL);
  59. _global_unlock();
  60. }
  61. void print_line(String p_string) {
  62. OS::get_singleton()->print("%s\n",p_string.utf8().get_data());
  63. _global_lock();
  64. PrintHandlerList *l = print_handler_list;
  65. while(l) {
  66. l->printfunc(l->userdata,p_string);
  67. l=l->next;
  68. }
  69. _global_unlock();
  70. }