phpdbg_utils.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Felipe Pena <felipe@php.net> |
  16. | Authors: Joe Watkins <joe.watkins@live.co.uk> |
  17. | Authors: Bob Weinand <bwoebi@php.net> |
  18. +----------------------------------------------------------------------+
  19. */
  20. #ifndef PHPDBG_UTILS_H
  21. #define PHPDBG_UTILS_H
  22. /**
  23. * Input scan functions
  24. */
  25. PHPDBG_API int phpdbg_is_numeric(const char*);
  26. PHPDBG_API int phpdbg_is_empty(const char*);
  27. PHPDBG_API int phpdbg_is_addr(const char*);
  28. PHPDBG_API int phpdbg_is_class_method(const char*, size_t, char**, char**);
  29. PHPDBG_API const char *phpdbg_current_file(TSRMLS_D);
  30. PHPDBG_API char *phpdbg_resolve_path(const char* TSRMLS_DC);
  31. PHPDBG_API char *phpdbg_trim(const char*, size_t, size_t*);
  32. PHPDBG_API const zend_function *phpdbg_get_function(const char*, const char* TSRMLS_DC);
  33. /**
  34. * Error/notice/formatting helpers
  35. */
  36. enum {
  37. P_ERROR = 1,
  38. P_NOTICE,
  39. P_WRITELN,
  40. P_WRITE,
  41. P_LOG
  42. };
  43. #ifdef ZTS
  44. PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 4, 5);
  45. #else
  46. PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
  47. #endif
  48. PHPDBG_API int phpdbg_rlog(FILE *stream, const char *fmt, ...);
  49. #define phpdbg_error(fmt, ...) phpdbg_print(P_ERROR TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
  50. #define phpdbg_notice(fmt, ...) phpdbg_print(P_NOTICE TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
  51. #define phpdbg_writeln(fmt, ...) phpdbg_print(P_WRITELN TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
  52. #define phpdbg_write(fmt, ...) phpdbg_print(P_WRITE TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
  53. #define phpdbg_log(fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
  54. #define phpdbg_error_ex(out, fmt, ...) phpdbg_print(P_ERROR TSRMLS_CC, out, fmt, ##__VA_ARGS__)
  55. #define phpdbg_notice_ex(out, fmt, ...) phpdbg_print(P_NOTICE TSRMLS_CC, out, fmt, ##__VA_ARGS__)
  56. #define phpdbg_writeln_ex(out, fmt, ...) phpdbg_print(P_WRITELN TSRMLS_CC, out, fmt, ##__VA_ARGS__)
  57. #define phpdbg_write_ex(out, fmt, ...) phpdbg_print(P_WRITE TSRMLS_CC, out, fmt, ##__VA_ARGS__)
  58. #define phpdbg_log_ex(out, fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, out, fmt, ##__VA_ARGS__)
  59. #if PHPDBG_DEBUG
  60. # define phpdbg_debug(fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDERR], fmt, ##__VA_ARGS__)
  61. #else
  62. # define phpdbg_debug(fmt, ...)
  63. #endif
  64. /* {{{ For writing blank lines */
  65. #define EMPTY NULL /* }}} */
  66. /* {{{ For prompt lines */
  67. #define PROMPT "phpdbg>" /* }}} */
  68. /* {{{ For separation */
  69. #define SEPARATE "------------------------------------------------" /* }}} */
  70. /* {{{ Color Management */
  71. #define PHPDBG_COLOR_LEN 12
  72. #define PHPDBG_COLOR_D(color, code) \
  73. {color, sizeof(color)-1, code}
  74. #define PHPDBG_COLOR_END \
  75. {NULL, 0L, {0}}
  76. #define PHPDBG_ELEMENT_LEN 3
  77. #define PHPDBG_ELEMENT_D(name, id) \
  78. {name, sizeof(name)-1, id}
  79. #define PHPDBG_ELEMENT_END \
  80. {NULL, 0L, 0}
  81. #define PHPDBG_COLOR_INVALID -1
  82. #define PHPDBG_COLOR_PROMPT 0
  83. #define PHPDBG_COLOR_ERROR 1
  84. #define PHPDBG_COLOR_NOTICE 2
  85. #define PHPDBG_COLORS 3
  86. typedef struct _phpdbg_color_t {
  87. char *name;
  88. size_t name_length;
  89. const char code[PHPDBG_COLOR_LEN];
  90. } phpdbg_color_t;
  91. typedef struct _phpdbg_element_t {
  92. char *name;
  93. size_t name_length;
  94. int id;
  95. } phpdbg_element_t;
  96. PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC);
  97. PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color TSRMLS_DC);
  98. PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length TSRMLS_DC);
  99. PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(TSRMLS_D);
  100. PHPDBG_API int phpdbg_get_element(const char *name, size_t len TSRMLS_DC); /* }}} */
  101. /* {{{ Prompt Management */
  102. PHPDBG_API void phpdbg_set_prompt(const char* TSRMLS_DC);
  103. PHPDBG_API const char *phpdbg_get_prompt(TSRMLS_D); /* }}} */
  104. /* {{{ Console Width */
  105. PHPDBG_API int phpdbg_get_terminal_width(TSRMLS_D); /* }}} */
  106. int phpdbg_rebuild_symtable(TSRMLS_D);
  107. #if PHP_VERSION_ID < 50500
  108. /* copy from zend_hash.c PHP 5.5 for 5.4 compatibility */
  109. static void zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, HashPosition *pos) {
  110. Bucket *p;
  111. p = pos ? (*pos) : ht->pInternalPointer;
  112. if (!p) {
  113. Z_TYPE_P(key) = IS_NULL;
  114. } else if (p->nKeyLength) {
  115. Z_TYPE_P(key) = IS_STRING;
  116. Z_STRVAL_P(key) = IS_INTERNED(p->arKey) ? (char*)p->arKey : estrndup(p->arKey, p->nKeyLength - 1);
  117. Z_STRLEN_P(key) = p->nKeyLength - 1;
  118. } else {
  119. Z_TYPE_P(key) = IS_LONG;
  120. Z_LVAL_P(key) = p->h;
  121. }
  122. }
  123. #endif
  124. #endif /* PHPDBG_UTILS_H */