Permalink
Browse files

Add new string functions

  • Loading branch information...
derickr committed Jan 13, 2018
1 parent 370f87a commit 8a28a93692c7f9fee0dbae0f21cb9b23ce3f889e
Showing with 90 additions and 11 deletions.
  1. +1 −2 usefulstuff.c
  2. +3 −5 xdebug_handler_dbgp.c
  3. +1 −1 xdebug_stack.c
  4. +77 −1 xdebug_str.c
  5. +8 −2 xdebug_str.h
View
@@ -109,9 +109,8 @@ char* xdebug_fd_read_line_delim(int socketfd, fd_buf *context, int type, unsigne
char *xdebug_join(const char *delim, xdebug_arg *args, int begin, int end)
{
int i;
xdebug_str *ret;
xdebug_str *ret = xdebug_str_new();
xdebug_str_ptr_init(ret);
if (begin < 0) {
begin = 0;
}
View
@@ -240,9 +240,7 @@ static xdebug_dbgp_cmd* lookup_cmd(char *cmd)
static xdebug_str *make_message(xdebug_con *context, xdebug_xml_node *message TSRMLS_DC)
{
xdebug_str xml_message = XDEBUG_STR_INITIALIZER;
xdebug_str *ret;
xdebug_str_ptr_init(ret);
xdebug_str *ret = xdebug_str_new();
xdebug_xml_return_node(message, &xml_message);
if (XG(remote_log_file)) {
@@ -255,7 +253,7 @@ static xdebug_str *make_message(xdebug_con *context, xdebug_xml_node *message TS
xdebug_str_add(ret, "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n", 0);
xdebug_str_add(ret, xml_message.d, 0);
xdebug_str_addl(ret, "\0", 1, 0);
xdebug_str_dtor(xml_message);
xdebug_str_destroy(&xml_message);
return ret;
}
@@ -270,7 +268,7 @@ static void send_message(xdebug_con *context, xdebug_xml_node *message TSRMLS_DC
fprintf(stderr, "There was a problem sending %ld bytes on socket %d: %s", tmp->l, context->socket, sock_error);
efree(sock_error);
}
xdebug_str_ptr_dtor(tmp);
xdebug_str_free(tmp);
}
static xdebug_xml_node* get_symbol(char* name, xdebug_var_export_options *options TSRMLS_DC)
View
@@ -225,7 +225,7 @@ void xdebug_log_stack(const char *error_type_str, char *buffer, const char *erro
xdebug_str_add(&log_buffer, xdebug_sprintf(") %s:%d", i->filename, i->lineno), 1);
php_log_err(log_buffer.d TSRMLS_CC);
xdebug_str_free(&log_buffer);
xdebug_str_destroy(&log_buffer);
}
}
}
View
@@ -65,6 +65,34 @@ void xdebug_str_addl(xdebug_str *xs, const char *str, int le, int f)
}
}
void xdebug_str_add_str(xdebug_str *xs, const xdebug_str *str)
{
if (xs->l + str->l > xs->a - 1) {
xs->d = xdrealloc(xs->d, xs->a + str->l + XDEBUG_STR_PREALLOC);
xs->a = xs->a + str->l + XDEBUG_STR_PREALLOC;
}
if (!xs->l) {
xs->d[0] = '\0';
}
memcpy(xs->d + xs->l, str->d, str->l);
xs->d[xs->l + str->l] = '\0';
xs->l = xs->l + str->l;
}
void xdebug_str_addc(xdebug_str *xs, char letter)
{
if (xs->l + 1 > xs->a - 1) {
xs->d = xdrealloc(xs->d, xs->a + 1 + XDEBUG_STR_PREALLOC);
xs->a = xs->a + 1 + XDEBUG_STR_PREALLOC;
}
if (!xs->l) {
xs->d[0] = '\0';
}
xs->d[xs->l] = letter;
xs->d[xs->l + 1] = '\0';
xs->l = xs->l + 1;
}
void xdebug_str_chop(xdebug_str *xs, int c)
{
if (c > xs->l) {
@@ -75,13 +103,61 @@ void xdebug_str_chop(xdebug_str *xs, int c)
}
}
void xdebug_str_free(xdebug_str *s)
xdebug_str *xdebug_str_new(void)
{
xdebug_str *tmp = xdmalloc(sizeof(xdebug_str));
tmp->l = 0;
tmp->a = 0;
tmp->d = NULL;
return tmp;
}
xdebug_str *xdebug_str_create(char *c, size_t len)
{
xdebug_str *tmp = xdebug_str_new();
tmp->l = tmp->a = len;
tmp->a++;
tmp->d = xdmalloc(tmp->a);
memcpy(tmp->d, c, tmp->l);
tmp->d[tmp->l] = '\0';
return tmp;
}
xdebug_str *xdebug_str_create_from_char(char *c)
{
return xdebug_str_create(c, strlen(c));
}
xdebug_str *xdebug_str_copy(xdebug_str *orig)
{
xdebug_str *tmp = xdebug_str_new();
tmp->l = tmp->a = orig->l;
tmp->a++;
tmp->d = xdmalloc(tmp->a);
memcpy(tmp->d, orig->d, tmp->l);
tmp->d[orig->l] = '\0';
return tmp;
}
void xdebug_str_destroy(xdebug_str *s)
{
if (s->d) {
xdfree(s->d);
}
}
void xdebug_str_free(xdebug_str *s)
{
xdebug_str_destroy(s);
xdfree(s);
}
char *xdebug_sprintf(const char* fmt, ...)
{
char *new_str;
View
@@ -23,8 +23,6 @@
#define XDEBUG_STR_INITIALIZER { 0, 0, NULL }
#define XDEBUG_STR_PREALLOC 1024
#define xdebug_str_ptr_init(str) str = xdmalloc(sizeof(xdebug_str)); str->l = 0; str->a = 0; str->d = NULL;
#define xdebug_str_ptr_dtor(str) xdfree(str->d); xdfree(str)
#define xdebug_str_dtor(str) xdfree(str.d)
typedef struct xdebug_str {
@@ -35,7 +33,15 @@ typedef struct xdebug_str {
void xdebug_str_add(xdebug_str *xs, const char *str, int f);
void xdebug_str_addl(xdebug_str *xs, const char *str, int le, int f);
void xdebug_str_add_str(xdebug_str *xs, const xdebug_str *str);
void xdebug_str_addc(xdebug_str *xs, char letter);
void xdebug_str_chop(xdebug_str *xs, int c);
xdebug_str *xdebug_str_new(void);
xdebug_str *xdebug_str_create_from_char(char *c);
xdebug_str *xdebug_str_create(char *c, size_t len);
xdebug_str *xdebug_str_copy(xdebug_str *orig);
void xdebug_str_destroy(xdebug_str *s);
void xdebug_str_free(xdebug_str *s);
char* xdebug_sprintf (const char* fmt, ...);

0 comments on commit 8a28a93

Please sign in to comment.