]> granicus.if.org Git - php/commitdiff
make api function and format structure for color management
authorkrakjoe <joe.watkins@live.co.uk>
Sun, 24 Nov 2013 17:50:22 +0000 (17:50 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Sun, 24 Nov 2013 17:50:22 +0000 (17:50 +0000)
phpdbg_cmd.h
phpdbg_utils.c
phpdbg_utils.h

index dc3899302d8267481136af6cba33dc4be18b1136..57ec73fff5e1186e4c80aa529c348f5a801ba571 100644 (file)
@@ -89,7 +89,8 @@ struct _phpdbg_command_t {
 typedef struct {
        long num;
        zend_execute_data *execute_data;
-} phpdbg_frame_t; /* }}} */
+} phpdbg_frame_t;
+/* }}} */
 
 /*
 * Workflow:
index 1d015ecf8f7bebd5daad6187b2680347082777e3..12e39a99faaa2eb194b6629b1f837ba23a97a712 100644 (file)
 
 ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
 
-int phpdbg_is_numeric(const char *str) /* {{{ */
+/* {{{ color structures */
+const static phpdbg_color_t colors[] = {
+       PHPDBG_COLOR_D("white",  "0:0"),
+       PHPDBG_COLOR_D("red",    "0:31"),
+       PHPDBG_COLOR_D("green",  "0:32"),
+       PHPDBG_COLOR_D("blue",   "0;34"),
+       PHPDBG_COLOR_D("purple", "0;35"),
+       PHPDBG_COLOR_D("cyan",   "0;36"),
+       PHPDBG_COLOR_END
+}; /* }}} */
+
+PHPDBG_API int phpdbg_is_numeric(const char *str) /* {{{ */
 {
     if (!str)
         return 0;
@@ -46,7 +57,7 @@ int phpdbg_is_numeric(const char *str) /* {{{ */
        return 0;
 } /* }}} */
 
-int phpdbg_is_empty(const char *str) /* {{{ */
+PHPDBG_API int phpdbg_is_empty(const char *str) /* {{{ */
 {
     if (!str)
         return 1;
@@ -60,12 +71,12 @@ int phpdbg_is_empty(const char *str) /* {{{ */
        return 1;
 } /* }}} */
 
-int phpdbg_is_addr(const char *str) /* {{{ */
+PHPDBG_API int phpdbg_is_addr(const char *str) /* {{{ */
 {
        return str[0] && str[1] && memcmp(str, "0x", 2) == 0;
 } /* }}} */
 
-int phpdbg_is_class_method(const char *str, size_t len, char **class, char **method) /* {{{ */
+PHPDBG_API int phpdbg_is_class_method(const char *str, size_t len, char **class, char **method) /* {{{ */
 {
        char *sep = NULL;
 
@@ -91,7 +102,7 @@ int phpdbg_is_class_method(const char *str, size_t len, char **class, char **met
        return 1;
 } /* }}} */
 
-char *phpdbg_resolve_path(const char *path TSRMLS_DC) /* {{{ */
+PHPDBG_API char *phpdbg_resolve_path(const char *path TSRMLS_DC) /* {{{ */
 {
        char resolved_name[MAXPATHLEN];
 
@@ -102,7 +113,7 @@ char *phpdbg_resolve_path(const char *path TSRMLS_DC) /* {{{ */
        return estrdup(resolved_name);
 } /* }}} */
 
-const char *phpdbg_current_file(TSRMLS_D) /* {{{ */
+PHPDBG_API const char *phpdbg_current_file(TSRMLS_D) /* {{{ */
 {
        const char *file = zend_get_executed_filename(TSRMLS_C);
 
@@ -113,7 +124,7 @@ const char *phpdbg_current_file(TSRMLS_D) /* {{{ */
        return file;
 } /* }}} */
 
-char *phpdbg_trim(const char *str, size_t len, size_t *new_len) /* {{{ */
+PHPDBG_API char *phpdbg_trim(const char *str, size_t len, size_t *new_len) /* {{{ */
 {
        const char *p = str;
        char *new = NULL;
@@ -143,7 +154,7 @@ char *phpdbg_trim(const char *str, size_t len, size_t *new_len) /* {{{ */
 
 } /* }}} */
 
-int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ...) /* {{{ */
+PHPDBG_API int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ...) /* {{{ */
 {
     int rc = 0;
        char *buffer = NULL;
@@ -206,3 +217,18 @@ int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ...) /* {{{ *
 
        return rc;
 } /* }}} */
+
+PHPDBG_API const phpdbg_color_t* phpdbg_get_color(const char *name, size_t name_length) /* {{{ */
+{
+       const phpdbg_color_t *color = colors;
+       
+       while (color && color->name) {
+               if (name_length == color->name_length &&
+                       memcmp(name, color->name, name_length) == SUCCESS) {
+                       return color;
+               }
+               ++color;
+       }
+       
+       return NULL;
+} /* }}} */
index b0143190414cf40232ce67737ee4ba28701ef9a2..07ff8712a4527be445a13748b980c6b1c8d3b7e5 100644 (file)
 #ifndef PHPDBG_UTILS_H
 #define PHPDBG_UTILS_H
 
+/* {{{ color management */
+#define PHPDBG_COLOR_LEN 12
+#define PHPDBG_COLOR_D(color, code) \
+       {color, sizeof(color), code}
+#define PHPDBG_COLOR_END \
+       {NULL, 0L, {0}}
+
+typedef struct _phpdbg_color_t {
+       char                    *name;
+       size_t                  name_length;
+       const char              code[PHPDBG_COLOR_LEN];
+} phpdbg_color_t; 
+
+PHPDBG_API const phpdbg_color_t* phpdbg_get_color(const char *name, size_t name_length); /* }}} */
+
 /**
  * Input scan functions
  */
-int phpdbg_is_numeric(const char*);
-int phpdbg_is_empty(const char*);
-int phpdbg_is_addr(const char*);
-int phpdbg_is_class_method(const char*, size_t, char**, char**);
-const char *phpdbg_current_file(TSRMLS_D);
-char *phpdbg_resolve_path(const char* TSRMLS_DC);
-char *phpdbg_trim(const char*, size_t, size_t*);
+PHPDBG_API int phpdbg_is_numeric(const char*);
+PHPDBG_API int phpdbg_is_empty(const char*);
+PHPDBG_API int phpdbg_is_addr(const char*);
+PHPDBG_API int phpdbg_is_class_method(const char*, size_t, char**, char**);
+PHPDBG_API const char *phpdbg_current_file(TSRMLS_D);
+PHPDBG_API char *phpdbg_resolve_path(const char* TSRMLS_DC);
+PHPDBG_API char *phpdbg_trim(const char*, size_t, size_t*);
 
 /**
  * Error/notice/formatting helper
@@ -43,9 +58,9 @@ enum {
 };
 
 #ifdef ZTS
-int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 4, 5);
+PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 4, 5);
 #else
-int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
+PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
 #endif
 
 #define phpdbg_error(fmt, ...)              phpdbg_print(P_ERROR   TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)