#include <stdio.h>
#include <string.h>
-static inline int phpdbg_needs_params(phpdbg_param_t *param TSRMLS_DC) {
- return 0;
+static inline void phpdbg_append_string(phpdbg_param_t *param, const char *string, size_t length TSRMLS_DC) {
+ if (!param->str) {
+ param->str = malloc(length+1);
+ } else param->str = realloc(param->str, param->len + (length+1));
+
+ memcpy(¶m->str[param->len], string, length);
+ param->len += length;
+ param->str[param->len] = 0;
}
%}
-%s RAW
+%s RAW
%option outfile="sapi/phpdbg/phpdbg_lexer.c" header-file="sapi/phpdbg/phpdbg_lexer.h"
%option warn nodefault
OPCODE ?i:ZEND_([A-Za-z])+
INPUT [^\n]+
%%
-<INITIAL>[a-zA-Z]+ {
- phpdbg_init_param(yylval, STR_PARAM);
- yylval->str = strndup(yytext, yyleng);
- yylval->len = yyleng;
- if (phpdbg_needs_params(yylval TSRMLS_CC)) {
- BEGIN(PARAMS);
- }
- return T_ID;
-}
-
-<PARAMS>[0-9]+ {
- phpdbg_init_param(yylval, NUMERIC_PARAM);
- yylval->num = atoi(yytext);
- return T_ID;
-}
-
-<INITIAL>
-{
+<INITIAL>{
[#]{1} { return T_POUND; }
[:]{2} { return T_DCOLON; }
[:]{1} { return T_COLON; }
return T_ID;
}
}
+
<RAW>{INPUT} {
phpdbg_init_param(yylval, STR_PARAM);
yylval->str = strndup(yytext, yyleng);
BEGIN(INITIAL);
return T_INPUT;
}
+
{WS} { /* ignore whitespace */ }
%%
function TSRMLS_CC);
} /* }}} */
+
static PHP_RINIT_FUNCTION(phpdbg) /* {{{ */
{
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], 8, NULL, php_phpdbg_destroy_bp_file, 0);
#include <stdio.h>
#include <string.h>
+static inline void phpdbg_append_string(phpdbg_param_t *param, const char *string, size_t length TSRMLS_DC) {
+ if (!param->str) {
+ param->str = malloc(length+1);
+ } else param->str = realloc(param->str, param->len + (length+1));
+
+ memcpy(¶m->str[param->len], string, length);
+ param->len += length;
+ param->str[param->len] = 0;
+}
+
#define YY_NO_UNISTD_H 1
-#line 518 "sapi/phpdbg/phpdbg_lexer.c"
+#line 528 "sapi/phpdbg/phpdbg_lexer.c"
#define INITIAL 0
#define RAW 1
register int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-#line 42 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 52 "sapi/phpdbg/dev/phpdbg_lexer.l"
-#line 758 "sapi/phpdbg/phpdbg_lexer.c"
+#line 768 "sapi/phpdbg/phpdbg_lexer.c"
yylval = yylval_param;
case 1:
YY_RULE_SETUP
-#line 45 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 54 "sapi/phpdbg/dev/phpdbg_lexer.l"
{ return T_POUND; }
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 46 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 55 "sapi/phpdbg/dev/phpdbg_lexer.l"
{ return T_DCOLON; }
YY_BREAK
case 3:
YY_RULE_SETUP
-#line 47 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 56 "sapi/phpdbg/dev/phpdbg_lexer.l"
{ return T_COLON; }
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 48 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 57 "sapi/phpdbg/dev/phpdbg_lexer.l"
{
BEGIN(RAW);
phpdbg_init_param(yylval, EMPTY_PARAM);
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 53 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 62 "sapi/phpdbg/dev/phpdbg_lexer.l"
{
BEGIN(RAW);
phpdbg_init_param(yylval, EMPTY_PARAM);
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 58 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 67 "sapi/phpdbg/dev/phpdbg_lexer.l"
{
BEGIN(RAW);
phpdbg_init_param(yylval, EMPTY_PARAM);
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 63 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 72 "sapi/phpdbg/dev/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, NUMERIC_PARAM);
yylval->num = 1;
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 68 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 77 "sapi/phpdbg/dev/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, NUMERIC_PARAM);
yylval->num = 0;
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 73 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 82 "sapi/phpdbg/dev/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, NUMERIC_PARAM);
yylval->num = atoi(yytext);
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 78 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 87 "sapi/phpdbg/dev/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, ADDR_PARAM);
yylval->addr = strtoul(yytext, NULL, 10);
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 83 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 92 "sapi/phpdbg/dev/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, OP_PARAM);
yylval->str = strndup(yytext, yyleng);
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 89 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 98 "sapi/phpdbg/dev/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, STR_PARAM);
yylval->str = strndup(yytext, yyleng);
case 13:
YY_RULE_SETUP
-#line 96 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 106 "sapi/phpdbg/dev/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, STR_PARAM);
yylval->str = strndup(yytext, yyleng);
case 14:
/* rule 14 can match eol */
YY_RULE_SETUP
-#line 103 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 114 "sapi/phpdbg/dev/phpdbg_lexer.l"
{ /* ignore whitespace */ }
YY_BREAK
case 15:
YY_RULE_SETUP
-#line 104 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 115 "sapi/phpdbg/dev/phpdbg_lexer.l"
YY_FATAL_ERROR( "flex scanner jammed" );
YY_BREAK
-#line 960 "sapi/phpdbg/phpdbg_lexer.c"
+#line 970 "sapi/phpdbg/phpdbg_lexer.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(RAW):
yyterminate();
#define YYTABLES_NAME "yytables"
-#line 104 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 115 "sapi/phpdbg/dev/phpdbg_lexer.l"
#undef YY_DECL
#endif
-#line 104 "sapi/phpdbg/dev/phpdbg_lexer.l"
+#line 115 "sapi/phpdbg/dev/phpdbg_lexer.l"
#line 346 "sapi/phpdbg/phpdbg_lexer.h"
#include "phpdbg_list.h"
#include "phpdbg_utils.h"
#include "phpdbg_prompt.h"
+#include "php_streams.h"
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
switch (param->type) {
case NUMERIC_PARAM:
+ printf("list lines: %d\n", param->num);
phpdbg_list_file(phpdbg_current_file(TSRMLS_C),
(param->num < 0 ? 1 - param->num : param->num),
(param->num < 0 ? param->num : 0) + zend_get_executed_lineno(TSRMLS_C),
void phpdbg_list_file(const char *filename, long count, long offset, int highlight TSRMLS_DC) /* {{{ */
{
- unsigned char *mem, *pos, *last_pos, *end_pos;
struct stat st;
-#ifndef _WIN32
- int fd;
-#else
- HANDLE fd, map;
-#endif
- int all_content = (count == 0);
- int line = 0, displayed = 0;
-
+ char *opened = NULL,
+ *mem = NULL;
+ char buffer[8096] = {0,};
+ size_t buflen = 0L;
+ long line = 0;
+
+ php_stream *stream = NULL;
+
if (VCWD_STAT(filename, &st) == FAILURE) {
phpdbg_error("Failed to stat file %s", filename);
return;
}
-
-#ifndef _WIN32
- if ((fd = VCWD_OPEN(filename, O_RDONLY)) == FAILURE) {
+
+ stream = php_stream_open_wrapper(filename, "rb", USE_PATH, &opened);
+
+ if (!stream) {
phpdbg_error("Failed to open file %s to list", filename);
return;
}
-
- pos = last_pos = mem = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
- end_pos = mem + st.st_size;
-#else
-
- fd = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (fd == INVALID_HANDLE_VALUE) {
- phpdbg_error("Failed to open file!");
- return;
- }
-
- map = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, 0, NULL);
- if (map == NULL) {
- phpdbg_error("Failed to map file!");
- CloseHandle(fd);
- return;
- }
-
- pos = last_pos = mem = (char*) MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
- if (mem == NULL) {
- phpdbg_error("Failed to map file in memory");
- CloseHandle(map);
- CloseHandle(fd);
- return;
- }
- end_pos = mem + st.st_size;
-#endif
- while (1) {
- if (pos == end_pos) {
- break;
- }
-
- pos = memchr(last_pos, '\n', end_pos - last_pos);
-
- if (!pos) {
- /* No more line breaks */
- pos = end_pos;
- }
-
+
+ while ((buflen = php_stream_gets(stream, buffer, sizeof(buffer))) > 0L) {
++line;
-
+
if (!offset || offset <= line) {
/* Without offset, or offset reached */
if (!highlight) {
- phpdbg_writeln("%05u: %.*s", line, (int)(pos - last_pos), last_pos);
+ phpdbg_write("%05u: %s", line, buffer);
} else {
if (highlight != line) {
- phpdbg_writeln(" %05u: %.*s", line, (int)(pos - last_pos), last_pos);
+ phpdbg_write(" %05u: %s", line, buffer);
} else {
- phpdbg_writeln(">%05u: %.*s", line, (int)(pos - last_pos), last_pos);
+ phpdbg_write(">%05u: %s", line, buffer);
}
}
- ++displayed;
}
-
- last_pos = pos + 1;
-
- if (!all_content && displayed == count) {
- /* Reached max line to display */
+
+ if ((count + (offset-1)) == line)
break;
- }
}
-
-#ifndef _WIN32
- munmap(mem, st.st_size);
- close(fd);
-#else
- UnmapViewOfFile(mem);
- CloseHandle(map);
- CloseHandle(fd);
-#endif
+
+ php_stream_close(stream);
} /* }}} */
void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */