summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/debug/textbuf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/debug/textbuf.cpp')
-rw-r--r--src/emu/debug/textbuf.cpp154
1 files changed, 68 insertions, 86 deletions
diff --git a/src/emu/debug/textbuf.cpp b/src/emu/debug/textbuf.cpp
index 395a58482a7..ab7bf6505b3 100644
--- a/src/emu/debug/textbuf.cpp
+++ b/src/emu/debug/textbuf.cpp
@@ -35,24 +35,17 @@ struct text_buffer
, linesize(lineoffs ? lines : 0)
{
}
- ~text_buffer()
- {
- if (buffer)
- delete [] buffer;
- if (lineoffs)
- delete [] lineoffs;
- }
- char *const buffer;
- s32 *const lineoffs;
- s32 const bufsize;
- s32 bufstart = 0;
- s32 bufend = 0;
- s32 const linesize;
- s32 linestart = 0;
- s32 lineend = 0;
- u32 linestartseq = 0;
- s32 maxwidth = 0;
+ std::unique_ptr<char []> const buffer;
+ std::unique_ptr<s32 []> const lineoffs;
+ s32 const bufsize;
+ s32 bufstart = 0;
+ s32 bufend = 0;
+ s32 const linesize;
+ s32 linestart = 0;
+ s32 lineend = 0;
+ u32 linestartseq = 0;
+ s32 maxwidth = 0;
/*-------------------------------------------------
buffer_used - return the number of bytes
@@ -88,22 +81,19 @@ struct text_buffer
text_buffer_alloc - allocate a new text buffer
-------------------------------------------------*/
-text_buffer *text_buffer_alloc(u32 bytes, u32 lines)
+text_buffer_ptr text_buffer_alloc(u32 bytes, u32 lines)
{
// allocate memory for the text buffer object
- text_buffer *const text(new (std::nothrow) text_buffer(bytes, lines));
+ text_buffer_ptr text(new (std::nothrow) text_buffer(bytes, lines));
if (!text)
return nullptr;
if (!text->buffer || !text->lineoffs)
- {
- delete text;
return nullptr;
- }
// initialize the buffer description
- text_buffer_clear(text);
+ text_buffer_clear(*text);
return text;
}
@@ -114,7 +104,7 @@ text_buffer *text_buffer_alloc(u32 bytes, u32 lines)
text buffer
-------------------------------------------------*/
-void text_buffer_free(text_buffer *text)
+void text_buffer_deleter::operator()(text_buffer *text) const
{
delete text;
}
@@ -124,21 +114,21 @@ void text_buffer_free(text_buffer *text)
text_buffer_clear - clear a text buffer
-------------------------------------------------*/
-void text_buffer_clear(text_buffer *text)
+void text_buffer_clear(text_buffer &text)
{
- /* reset all the buffer pointers and other bits */
- text->bufstart = 0;
- text->bufend = 0;
+ // reset all the buffer pointers and other bits
+ text.bufstart = 0;
+ text.bufend = 0;
- text->linestart = 0;
- text->lineend = 0;
- text->linestartseq = 0;
+ text.linestart = 0;
+ text.lineend = 0;
+ text.linestartseq = 0;
- text->maxwidth = 0;
+ text.maxwidth = 0;
- /* create the initial line */
- text->lineoffs[0] = 0;
- text->buffer[text->lineoffs[0]] = 0;
+ // create the initial line
+ text.lineoffs[0] = 0;
+ text.buffer[text.lineoffs[0]] = 0;
}
@@ -154,9 +144,9 @@ void text_buffer_clear(text_buffer *text)
buffer
-------------------------------------------------*/
-void text_buffer_print(text_buffer *text, const char *data)
+void text_buffer_print(text_buffer &text, const char *data)
{
- text_buffer_print_wrap(text, data, 10000);
+ text_buffer_print_wrap(text, data, MAX_LINE_LENGTH);
}
@@ -166,21 +156,21 @@ void text_buffer_print(text_buffer *text, const char *data)
column
-------------------------------------------------*/
-void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol)
+void text_buffer_print_wrap(text_buffer &text, const char *data, int wrapcol)
{
- s32 stopcol = (wrapcol < MAX_LINE_LENGTH) ? wrapcol : MAX_LINE_LENGTH;
+ s32 const stopcol = (wrapcol < MAX_LINE_LENGTH) ? wrapcol : MAX_LINE_LENGTH;
s32 needed_space;
/* we need to ensure there is enough space for this string plus enough for the max line length */
needed_space = s32(strlen(data)) + MAX_LINE_LENGTH;
/* make space in the buffer if we need to */
- while (text->buffer_space() < needed_space && text->linestart != text->lineend)
+ while (text.buffer_space() < needed_space && text.linestart != text.lineend)
{
- text->linestartseq++;
- if (++text->linestart >= text->linesize)
- text->linestart = 0;
- text->bufstart = text->lineoffs[text->linestart];
+ text.linestartseq++;
+ if (++text.linestart >= text.linesize)
+ text.linestart = 0;
+ text.bufstart = text.lineoffs[text.linestart];
}
/* now add the data */
@@ -191,14 +181,14 @@ void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol)
/* a CR resets our position */
if (ch == '\r')
- text->bufend = text->lineoffs[text->lineend];
+ text.bufend = text.lineoffs[text.lineend];
/* non-CR data is just characters */
else if (ch != '\n')
- text->buffer[text->bufend++] = ch;
+ text.buffer[text.bufend++] = ch;
/* an explicit newline or line-too-long condition inserts a newline */
- linelen = text->bufend - text->lineoffs[text->lineend];
+ linelen = text.bufend - text.lineoffs[text.lineend];
if (ch == '\n' || linelen >= stopcol)
{
int overflow = 0;
@@ -208,7 +198,7 @@ void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol)
{
/* scan backwards, removing characters along the way */
overflow = 1;
- while (overflow < linelen && text->buffer[text->bufend - overflow] != ' ')
+ while (overflow < linelen && text.buffer[text.bufend - overflow] != ' ')
overflow++;
/* if we found a space, take it; otherwise, reset and pretend we didn't try */
@@ -219,39 +209,39 @@ void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol)
}
/* did we beat the max width */
- if (linelen > text->maxwidth)
- text->maxwidth = linelen;
+ if (linelen > text.maxwidth)
+ text.maxwidth = linelen;
/* append a terminator */
if (overflow == 0)
- text->buffer[text->bufend++] = 0;
+ text.buffer[text.bufend++] = 0;
else
- text->buffer[text->bufend - overflow] = 0;
+ text.buffer[text.bufend - overflow] = 0;
/* determine what the next line will be */
- if (++text->lineend >= text->linesize)
- text->lineend = 0;
+ if (++text.lineend >= text.linesize)
+ text.lineend = 0;
/* if we're out of lines, consume the next one */
- if (text->lineend == text->linestart)
+ if (text.lineend == text.linestart)
{
- text->linestartseq++;
- if (++text->linestart >= text->linesize)
- text->linestart = 0;
- text->bufstart = text->lineoffs[text->linestart];
+ text.linestartseq++;
+ if (++text.linestart >= text.linesize)
+ text.linestart = 0;
+ text.bufstart = text.lineoffs[text.linestart];
}
/* if we don't have enough room in the buffer for a max line, wrap to the start */
- if (text->bufend + MAX_LINE_LENGTH + 1 >= text->bufsize)
- text->bufend = 0;
+ if (text.bufend + MAX_LINE_LENGTH + 1 >= text.bufsize)
+ text.bufend = 0;
/* create a new empty line */
- text->lineoffs[text->lineend] = text->bufend - (overflow ? (overflow - 1) : 0);
+ text.lineoffs[text.lineend] = text.bufend - (overflow ? (overflow - 1) : 0);
}
}
/* nullptr terminate what we have on this line */
- text->buffer[text->bufend] = 0;
+ text.buffer[text.bufend] = 0;
}
@@ -267,9 +257,9 @@ void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol)
width of all lines seen so far
-------------------------------------------------*/
-u32 text_buffer_max_width(text_buffer *text)
+u32 text_buffer_max_width(text_buffer const &text)
{
- return text->maxwidth;
+ return text.maxwidth;
}
@@ -278,12 +268,10 @@ u32 text_buffer_max_width(text_buffer *text)
lines in the text buffer
-------------------------------------------------*/
-u32 text_buffer_num_lines(text_buffer *text)
+u32 text_buffer_num_lines(text_buffer const &text)
{
- s32 lines = text->lineend + 1 - text->linestart;
- if (lines <= 0)
- lines += text->linesize;
- return lines;
+ s32 const lines = text.lineend + 1 - text.linestart;
+ return (lines <= 0) ? (lines + text.linesize) : lines;
}
@@ -292,9 +280,9 @@ u32 text_buffer_num_lines(text_buffer *text)
line index into a sequence number
-------------------------------------------------*/
-u32 text_buffer_line_index_to_seqnum(text_buffer *text, u32 index)
+u32 text_buffer_line_index_to_seqnum(text_buffer const &text, u32 index)
{
- return text->linestartseq + index;
+ return text.linestartseq + index;
}
@@ -303,18 +291,13 @@ u32 text_buffer_line_index_to_seqnum(text_buffer *text, u32 index)
an indexed line in the buffer
-------------------------------------------------*/
-const char *text_buffer_get_seqnum_line(text_buffer *text, u32 seqnum)
+const char *text_buffer_get_seqnum_line(text_buffer const &text, u32 seqnum)
{
- u32 numlines = text_buffer_num_lines(text);
- u32 index = seqnum - text->linestartseq;
+ u32 const numlines = text_buffer_num_lines(text);
+ u32 const index = seqnum - text.linestartseq;
if (index >= numlines)
return nullptr;
- return &text->buffer[text->lineoffs[(text->linestart + index) % text->linesize]];
-}
-
-text_buffer_lines text_buffer_get_lines(text_buffer *text)
-{
- return text_buffer_lines(*text);
+ return &text.buffer[text.lineoffs[(text.linestart + index) % text.linesize]];
}
/*---------------------------------------------------------------------
@@ -324,22 +307,21 @@ text_buffer_lines text_buffer_get_lines(text_buffer *text)
text_buffer_line text_buffer_lines::text_buffer_line_iterator::operator*() const
{
- const char *line = &m_buffer.buffer[m_buffer.lineoffs[m_lineptr]];
+ char const *const line = &m_buffer.buffer[m_buffer.lineoffs[m_lineptr]];
auto next_lineptr = m_lineptr + 1;
if (next_lineptr == m_buffer.linesize)
next_lineptr = 0;
- const char *nextline = &m_buffer.buffer[m_buffer.lineoffs[next_lineptr]];
-
- /* -1 for the '\0' at the end of line */
+ char const *const nextline = &m_buffer.buffer[m_buffer.lineoffs[next_lineptr]];
+ // -1 for the '\0' at the end of line
ptrdiff_t difference = (nextline - line) - 1;
if (difference < 0)
difference += m_buffer.bufsize;
- return text_buffer_line{ line, (size_t)difference };
+ return text_buffer_line{ line, size_t(difference) };
}
/*---------------------------------------------------------------------