}
asprintf(why,
- "%s expected no arguments",
+ "The command \"%s\" expected no arguments",
phpdbg_command_name(command, buffer));
return FAILURE;
}
#define verify_arg(e, a, t) if (!(a)) { \
if (!optional) { \
asprintf(why, \
- "%s expected %s and got nothing at parameter %lu", \
+ "The command \"%s\" expected %s and got nothing at parameter %lu", \
phpdbg_command_name(command, buffer), \
(e), \
current); \
} \
} else if ((a)->type != (t)) { \
asprintf(why, \
- "%s expected %s and got %s at parameter %lu", \
+ "The command \"%s\" expected %s and got %s at parameter %lu", \
phpdbg_command_name(command, buffer), \
(e),\
phpdbg_get_param_type((a) TSRMLS_CC), \
if ((received < least)) {
asprintf(why,
- "%s expected at least %lu arguments (%s) and received %lu",
+ "The command \"%s\" expected at least %lu arguments (%s) and received %lu",
phpdbg_command_name(command, buffer),
least,
command->args,
}
switch (matches) {
- case 0: if (!parent) {
- asprintf(
+ case 0: {
+ if (parent) {
+ asprintf(
+ why,
+ "The command \"%s %s\" could not be found",
+ parent->name, name->str);
+ } else asprintf(
why,
- "The command %s could not be found",
+ "The command \"%s\" could not be found",
name->str);
- return NULL;
- } else return parent;
+ } return parent;
case 1: {
(*top) = (*top)->next;
asprintf(
why,
- "The command %s is ambigious, matching %lu commands (%s)",
+ "The command \"%s\" is ambigious, matching %lu commands (%s)",
name->str, matches, list);
free(list);
} return NULL;
if (stack->type != STACK_PARAM) {
asprintf(
- why, "the passed argument was not a stack !!");
+ why, "The passed argument was not a stack !!");
return FAILURE;
}
if (!stack->len) {
asprintf(
- why, "the stack contains nothing !!");
+ why, "The stack contains nothing !!");
return FAILURE;
}
default:
asprintf(
- why, "the first parameter makes no sense !!");
+ why, "The first parameter makes no sense !!");
return FAILURE;
}
}
}
}
-
- phpdbg_error("No help can be found for the subject \"%s\"", param->str);
+
return FAILURE;
} /* }}} */
};
static yyconst flex_int16_t yy_accept[67] =
{ 0,
- 12, 12, 0, 0, 16, 12, 14, 1, 9, 9,
+ 0, 0, 0, 0, 16, 12, 14, 1, 9, 9,
3, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 13, 13, 12, 14, 9, 12, 2, 12, 12,
4, 12, 6, 8, 12, 7, 5, 12, 12, 12,
PHPDBG_COMMAND(set) /* {{{ */
{
phpdbg_error(
- "No information command selected!");
+ "No set command selected!");
return SUCCESS;
} /* }}} */
case FAILURE:
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) {
- phpdbg_error("%s", why);
+ if (why) {
+ phpdbg_error("%s", why);
+ }
}
}
}
}
}
-
+
if (why) {
free(why);
why = NULL;
}
-
+
yy_delete_buffer(state, scanner);
yylex_destroy(scanner);
-
+
phpdbg_stack_free(&stack);
phpdbg_destroy_input(&input TSRMLS_CC);
-
+
} while ((input = phpdbg_read_input(NULL TSRMLS_CC)));
if (!input)
if (input) {
phpdbg_destroy_input(&input TSRMLS_CC);
}
+
+ if (why) {
+ free(why);
+ }
phpdbg_stack_free(&stack);
#ifndef _WIN32
PHPDBG_SET(color) /* {{{ */
{
- /*if ((param->type == STR_PARAM) && (input->argc == 3)) {
- const phpdbg_color_t *color = phpdbg_get_color(
- input->argv[2]->string, input->argv[2]->length TSRMLS_CC);
- int element = PHPDBG_COLOR_INVALID;
-
- if (color) {
- if (phpdbg_argv_is(1, "prompt")) {
- phpdbg_notice(
- "setting prompt color to %s (%s)", color->name, color->code);
- element = PHPDBG_COLOR_PROMPT;
- if (PHPDBG_G(prompt)[1]) {
- free(PHPDBG_G(prompt)[1]);
- PHPDBG_G(prompt)[1]=NULL;
- }
- } else if (phpdbg_argv_is(1, "error")) {
- phpdbg_notice(
- "setting error color to %s (%s)", color->name, color->code);
- element = PHPDBG_COLOR_ERROR;
-
- } else if (phpdbg_argv_is(1, "notice")) {
- phpdbg_notice(
- "setting notice color to %s (%s)", color->name, color->code);
- element = PHPDBG_COLOR_NOTICE;
-
- } else goto usage;
-
- phpdbg_set_color(element, color TSRMLS_CC);
- } else {
- phpdbg_error(
- "Failed to find the requested color (%s)", input->argv[2]->string);
- }
- } else {
-usage:
+ const phpdbg_color_t *color = phpdbg_get_color(
+ param->next->str, param->next->len TSRMLS_CC);
+
+ if (!color) {
phpdbg_error(
- "set color used incorrectly: set color <prompt|error|notice> <color>");
- } */
+ "Failed to find the requested color (%s)", param->next->str);
+ return SUCCESS;
+ }
+ switch (phpdbg_get_element(param->str, param->len TSRMLS_CC)) {
+ case PHPDBG_COLOR_PROMPT:
+ phpdbg_notice(
+ "setting prompt color to %s (%s)", color->name, color->code);
+ if (PHPDBG_G(prompt)[1]) {
+ free(PHPDBG_G(prompt)[1]);
+ PHPDBG_G(prompt)[1]=NULL;
+ }
+ phpdbg_set_color(PHPDBG_COLOR_PROMPT, color TSRMLS_CC);
+ break;
+
+ case PHPDBG_COLOR_ERROR:
+ phpdbg_notice(
+ "setting error color to %s (%s)", color->name, color->code);
+ phpdbg_set_color(PHPDBG_COLOR_ERROR, color TSRMLS_CC);
+ break;
+
+ case PHPDBG_COLOR_NOTICE:
+ phpdbg_notice(
+ "setting notice color to %s (%s)", color->name, color->code);
+ phpdbg_set_color(PHPDBG_COLOR_NOTICE, color TSRMLS_CC);
+ break;
+
+ default:
+ phpdbg_error(
+ "Failed to find the requested element (%s)", param->str);
+ }
+
return SUCCESS;
} /* }}} */
PHPDBG_COLOR_END
}; /* }}} */
+/* {{{ */
+const static phpdbg_element_t elements[] = {
+ PHPDBG_ELEMENT_D("prompt", PHPDBG_COLOR_PROMPT),
+ PHPDBG_ELEMENT_D("error", PHPDBG_COLOR_ERROR),
+ PHPDBG_ELEMENT_D("notice", PHPDBG_COLOR_NOTICE),
+ PHPDBG_ELEMENT_END
+}; /* }}} */
+
PHPDBG_API int phpdbg_is_numeric(const char *str) /* {{{ */
{
if (!str)
return colors;
} /* }}} */
+PHPDBG_API int phpdbg_get_element(const char *name, size_t len) {
+ const phpdbg_element_t *element = elements;
+
+ while (element && element->name) {
+ if (len == element->name_length) {
+ if (strncasecmp(name, element->name, len) == SUCCESS) {
+ return element->id;
+ }
+ }
+ element++;
+ }
+
+ return PHPDBG_COLOR_INVALID;
+}
+
PHPDBG_API void phpdbg_set_prompt(const char *prompt TSRMLS_DC) /* {{{ */
{
/* free formatted prompt */
{color, sizeof(color)-1, code}
#define PHPDBG_COLOR_END \
{NULL, 0L, {0}}
+#define PHPDBG_ELEMENT_LEN 3
+#define PHPDBG_ELEMENT_D(name, id) \
+ {name, sizeof(name)-1, id}
+#define PHPDBG_ELEMENT_END \
+ {NULL, 0L, 0}
#define PHPDBG_COLOR_INVALID -1
-#define PHPDBG_COLOR_PROMPT 0
-#define PHPDBG_COLOR_ERROR 1
-#define PHPDBG_COLOR_NOTICE 2
-#define PHPDBG_COLORS 3
+#define PHPDBG_COLOR_PROMPT 0
+#define PHPDBG_COLOR_ERROR 1
+#define PHPDBG_COLOR_NOTICE 2
+#define PHPDBG_COLORS 3
typedef struct _phpdbg_color_t {
char *name;
const char code[PHPDBG_COLOR_LEN];
} phpdbg_color_t;
+typedef struct _phpdbg_element_t {
+ char *name;
+ size_t name_length;
+ int id;
+} phpdbg_element_t;
+
PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC);
PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color TSRMLS_DC);
PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length TSRMLS_DC);
-PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(TSRMLS_D); /* }}} */
+PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(TSRMLS_D);
+PHPDBG_API int phpdbg_get_element(const char *name, size_t len TSRMLS_DC); /* }}} */
/* {{{ Prompt Management */
PHPDBG_API void phpdbg_set_prompt(const char* TSRMLS_DC);