d = serial_dump_char_size(b->data, d, off, b->dsize + 1, convert);
d = serial_dump_int(b->dptr - b->data, d, off);
d = serial_dump_int(b->dsize, d, off);
- d = serial_dump_int(b->destroy, d, off);
return d;
}
(*b)->dptr = (*b)->data + offset;
serial_restore_int(&used, d, off);
(*b)->dsize = used;
- serial_restore_int(&used, d, off);
- (*b)->destroy = used;
}
/**
enum CommandResult rc = MUTT_CMD_ERROR;
- struct Buffer expn, token;
-
- mutt_buffer_init(&expn);
- mutt_buffer_init(&token);
-
- expn.data = expn.dptr = line;
- expn.dsize = mutt_str_strlen(line);
+ struct Buffer *token = mutt_buffer_pool_get();
+ struct Buffer *expn = mutt_buffer_from(line);
+ expn->dptr = expn->data;
mutt_buffer_reset(err);
- SKIPWS(expn.dptr);
- while (*expn.dptr)
+ SKIPWS(expn->dptr);
+ while (*expn->dptr != '\0')
{
- mutt_extract_token(&token, &expn, MUTT_TOKEN_NO_FLAGS);
+ mutt_extract_token(token, expn, MUTT_TOKEN_NO_FLAGS);
for (size_t i = 0; ICommandList[i].name; i++)
{
- if (mutt_str_strcmp(token.data, ICommandList[i].name) != 0)
+ if (mutt_str_strcmp(token->data, ICommandList[i].name) != 0)
continue;
- rc = ICommandList[i].func(&token, &expn, ICommandList[i].data, err);
+ rc = ICommandList[i].func(token, expn, ICommandList[i].data, err);
if (rc != 0)
goto finish;
}
finish:
- if (expn.destroy)
- FREE(&expn.data);
+ mutt_buffer_pool_release(&token);
+ mutt_buffer_free(&expn);
return rc;
}
ptr = mutt_mem_malloc(tok->dsize);
memcpy(ptr, expn.data, expnlen);
strcpy(ptr + expnlen, tok->dptr);
- if (tok->destroy)
- FREE(&tok->data);
- tok->data = ptr;
- tok->dptr = ptr;
- tok->destroy = 1; /* mark that the caller should destroy this data */
+ tok->data = mutt_str_strdup(ptr);
+ tok->dptr = tok->data;
ptr = NULL;
FREE(&expn.data);
}
enum CommandResult mutt_parse_rc_line(/* const */ char *line,
struct Buffer *token, struct Buffer *err)
{
- int i;
- enum CommandResult rc = MUTT_CMD_SUCCESS;
- struct Buffer expn;
-
if (!line || !*line)
return 0;
- mutt_buffer_init(&expn);
- expn.data = line;
- expn.dptr = line;
- expn.dsize = mutt_str_strlen(line);
+ int i;
+ enum CommandResult rc = MUTT_CMD_SUCCESS;
+
+ struct Buffer *expn = mutt_buffer_from(line);
+ expn->dptr = expn->data;
*err->data = 0;
- SKIPWS(expn.dptr);
- while (*expn.dptr)
+ SKIPWS(expn->dptr);
+ while (*expn->dptr != '\0')
{
- if (*expn.dptr == '#')
+ if (*expn->dptr == '#')
break; /* rest of line is a comment */
- if (*expn.dptr == ';')
+ if (*expn->dptr == ';')
{
- expn.dptr++;
+ expn->dptr++;
continue;
}
- mutt_extract_token(token, &expn, MUTT_TOKEN_NO_FLAGS);
+ mutt_extract_token(token, expn, MUTT_TOKEN_NO_FLAGS);
for (i = 0; Commands[i].name; i++)
{
if (mutt_str_strcmp(token->data, Commands[i].name) == 0)
{
- rc = Commands[i].func(token, &expn, Commands[i].data, err);
+ rc = Commands[i].func(token, expn, Commands[i].data, err);
if (rc != MUTT_CMD_SUCCESS)
{ /* -1 Error, +1 Finish */
goto finish; /* Propagate return code */
}
}
finish:
- if (expn.destroy)
- FREE(&expn.data);
+ mutt_buffer_free(&expn);
return rc;
}
char *data; ///< Pointer to data
char *dptr; ///< Current read/write position
size_t dsize; ///< Length of data
- int destroy; ///< Destroy 'data' when done?
};
/* Convert a buffer to a const char * "string" */
ptr = mutt_mem_malloc(tok->dsize);
memcpy(ptr, expn.data, expnlen);
strcpy(ptr + expnlen, tok->dptr);
- if (tok->destroy)
- FREE(&tok->data);
- tok->data = ptr;
- tok->dptr = ptr;
- tok->destroy = 1; /* mark that the caller should destroy this data */
+ tok->data = mutt_str_strdup(ptr);
+ tok->dptr = tok->data;
ptr = NULL;
FREE(&expn.data);
}