aboutsummaryrefslogtreecommitdiff
path: root/src/history.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/history.c')
-rw-r--r--src/history.c79
1 files changed, 42 insertions, 37 deletions
diff --git a/src/history.c b/src/history.c
index 3433c0ed8ddf..bc15da5b8f1d 100644
--- a/src/history.c
+++ b/src/history.c
@@ -195,7 +195,7 @@ bc_history_init(BcHistory* h)
h->hist = history_init();
if (BC_ERR(h->hist == NULL)) bc_vm_fatalError(BC_ERR_FATAL_ALLOC_ERR);
- h->el = el_init(vm.name, stdin, stdout, stderr);
+ h->el = el_init(vm->name, stdin, stdout, stderr);
if (BC_ERR(h->el == NULL)) bc_vm_fatalError(BC_ERR_FATAL_ALLOC_ERR);
// I want history and a prompt.
@@ -269,7 +269,7 @@ bc_history_line(BcHistory* h, BcVec* vec, const char* prompt)
}
else
{
- bc_file_printf(&vm.fout, "\n");
+ bc_file_printf(&vm->fout, "\n");
s = BC_STATUS_EOF;
}
}
@@ -368,7 +368,7 @@ bc_history_line(BcHistory* h, BcVec* vec, const char* prompt)
}
else if (h->line == NULL)
{
- bc_file_printf(&vm.fout, "%s\n", "^D");
+ bc_file_printf(&vm->fout, "%s\n", "^D");
s = BC_STATUS_EOF;
}
else bc_vec_string(vec, 1, "\n");
@@ -566,9 +566,11 @@ bc_history_nextLen(const char* buf, size_t buf_len, size_t pos, size_t* col_len)
{
BC_UNREACHABLE
+#if !BC_CLANG
if (col_len != NULL) *col_len = 0;
return 0;
+#endif // !BC_CLANG
}
// Store the width of the character on screen.
@@ -617,7 +619,9 @@ bc_history_prevLen(const char* buf, size_t pos)
BC_UNREACHABLE
+#if !BC_CLANG
return 0;
+#endif // BC_CLANG
}
/**
@@ -670,6 +674,7 @@ static BcStatus
bc_history_readCode(char* buf, size_t buf_len, uint32_t* cp, size_t* nread)
{
ssize_t n;
+ uchar byte;
assert(buf_len >= 1);
@@ -683,7 +688,7 @@ bc_history_readCode(char* buf, size_t buf_len, uint32_t* cp, size_t* nread)
if (BC_ERR(n <= 0)) goto err;
// Get the byte.
- uchar byte = ((uchar*) buf)[0];
+ byte = ((uchar*) buf)[0];
// Once again, this is the UTF-8 decoding algorithm, but it has reads
// instead of actual decoding.
@@ -898,8 +903,8 @@ bc_history_cursorPos(void)
BC_SIG_ASSERT_LOCKED;
// Report cursor location.
- bc_file_write(&vm.fout, bc_flush_none, "\x1b[6n", 4);
- bc_file_flush(&vm.fout, bc_flush_none);
+ bc_file_write(&vm->fout, bc_flush_none, "\x1b[6n", 4);
+ bc_file_flush(&vm->fout, bc_flush_none);
// Read the response: ESC [ rows ; cols R.
for (i = 0; i < sizeof(buf) - 1; ++i)
@@ -942,7 +947,7 @@ bc_history_columns(void)
struct winsize ws;
int ret;
- ret = ioctl(vm.fout.fd, TIOCGWINSZ, &ws);
+ ret = ioctl(vm->fout.fd, TIOCGWINSZ, &ws);
if (BC_ERR(ret == -1 || !ws.ws_col))
{
@@ -954,16 +959,16 @@ bc_history_columns(void)
if (BC_ERR(start == SIZE_MAX)) return BC_HIST_DEF_COLS;
// Go to right margin and get position.
- bc_file_write(&vm.fout, bc_flush_none, "\x1b[999C", 6);
- bc_file_flush(&vm.fout, bc_flush_none);
+ bc_file_write(&vm->fout, bc_flush_none, "\x1b[999C", 6);
+ bc_file_flush(&vm->fout, bc_flush_none);
cols = bc_history_cursorPos();
if (BC_ERR(cols == SIZE_MAX)) return BC_HIST_DEF_COLS;
// Restore position.
if (cols > start)
{
- bc_file_printf(&vm.fout, "\x1b[%zuD", cols - start);
- bc_file_flush(&vm.fout, bc_flush_none);
+ bc_file_printf(&vm->fout, "\x1b[%zuD", cols - start);
+ bc_file_flush(&vm->fout, bc_flush_none);
}
return cols;
@@ -1021,7 +1026,7 @@ bc_history_refresh(BcHistory* h)
BC_SIG_ASSERT_LOCKED;
- bc_file_flush(&vm.fout, bc_flush_none);
+ bc_file_flush(&vm->fout, bc_flush_none);
// Get to the prompt column position from the left.
while (h->pcol + bc_history_colPos(buf, len, pos) >= h->cols)
@@ -1040,7 +1045,7 @@ bc_history_refresh(BcHistory* h)
}
// Cursor to left edge.
- bc_file_write(&vm.fout, bc_flush_none, "\r", 1);
+ bc_file_write(&vm->fout, bc_flush_none, "\r", 1);
// Take the extra stuff into account. This is where history makes sure to
// preserve stuff that was printed without a newline.
@@ -1053,16 +1058,16 @@ bc_history_refresh(BcHistory* h)
len += extras_len;
pos += extras_len;
- bc_file_write(&vm.fout, bc_flush_none, h->extras.v, extras_len);
+ bc_file_write(&vm->fout, bc_flush_none, h->extras.v, extras_len);
}
// Write the prompt, if desired.
- if (BC_PROMPT) bc_file_write(&vm.fout, bc_flush_none, h->prompt, h->plen);
+ if (BC_PROMPT) bc_file_write(&vm->fout, bc_flush_none, h->prompt, h->plen);
- bc_file_write(&vm.fout, bc_flush_none, h->buf.v, len - extras_len);
+ bc_file_write(&vm->fout, bc_flush_none, h->buf.v, len - extras_len);
// Erase to right.
- bc_file_write(&vm.fout, bc_flush_none, "\x1b[0K", 4);
+ bc_file_write(&vm->fout, bc_flush_none, "\x1b[0K", 4);
// We need to be sure to grow this.
if (pos >= h->buf.len - extras_len) bc_vec_grow(&h->buf, pos + extras_len);
@@ -1070,13 +1075,13 @@ bc_history_refresh(BcHistory* h)
// Move cursor to original position. Do NOT move the putchar of '\r' to the
// printf with colpos. That causes a bug where the cursor will go to the end
// of the line when there is no prompt.
- bc_file_putchar(&vm.fout, bc_flush_none, '\r');
+ bc_file_putchar(&vm->fout, bc_flush_none, '\r');
colpos = bc_history_colPos(h->buf.v, len - extras_len, pos) + h->pcol;
// Set the cursor position again.
- if (colpos) bc_file_printf(&vm.fout, "\x1b[%zuC", colpos);
+ if (colpos) bc_file_printf(&vm->fout, "\x1b[%zuC", colpos);
- bc_file_flush(&vm.fout, bc_flush_none);
+ bc_file_flush(&vm->fout, bc_flush_none);
}
/**
@@ -1114,8 +1119,8 @@ bc_history_edit_insert(BcHistory* h, const char* cbuf, size_t clen)
if (colpos < h->cols)
{
// Avoid a full update of the line in the trivial case.
- bc_file_write(&vm.fout, bc_flush_none, cbuf, clen);
- bc_file_flush(&vm.fout, bc_flush_none);
+ bc_file_write(&vm->fout, bc_flush_none, cbuf, clen);
+ bc_file_flush(&vm->fout, bc_flush_none);
}
else bc_history_refresh(h);
}
@@ -1706,10 +1711,10 @@ bc_history_add(BcHistory* h, char* line)
static void
bc_history_add_empty(BcHistory* h)
{
- BC_SIG_ASSERT_LOCKED;
-
const char* line = "";
+ BC_SIG_ASSERT_LOCKED;
+
// If there is something already there...
if (h->history.len)
{
@@ -1773,7 +1778,7 @@ bc_history_printCtrl(BcHistory* h, unsigned int c)
{
// We sometimes want to print a newline; for the times we don't; it's
// because newlines are taken care of elsewhere.
- bc_file_write(&vm.fout, bc_flush_none, newline, sizeof(newline) - 1);
+ bc_file_write(&vm->fout, bc_flush_none, newline, sizeof(newline) - 1);
bc_history_refresh(h);
}
}
@@ -1796,7 +1801,7 @@ bc_history_edit(BcHistory* h, const char* prompt)
// Don't write the saved output the first time. This is because it has
// already been written to output. In other words, don't uncomment the
// line below or add anything like it.
- // bc_file_write(&vm.fout, bc_flush_none, h->extras.v, h->extras.len - 1);
+ // bc_file_write(&vm->fout, bc_flush_none, h->extras.v, h->extras.len - 1);
// Write the prompt if desired.
if (BC_PROMPT)
@@ -1805,8 +1810,8 @@ bc_history_edit(BcHistory* h, const char* prompt)
h->plen = strlen(prompt);
h->pcol = bc_history_promptColLen(prompt, h->plen);
- bc_file_write(&vm.fout, bc_flush_none, prompt, h->plen);
- bc_file_flush(&vm.fout, bc_flush_none);
+ bc_file_write(&vm->fout, bc_flush_none, prompt, h->plen);
+ bc_file_flush(&vm->fout, bc_flush_none);
}
// This is the input loop.
@@ -1851,14 +1856,14 @@ bc_history_edit(BcHistory* h, const char* prompt)
// Quit if the user wants it.
if (!BC_SIGINT)
{
- vm.status = BC_STATUS_QUIT;
+ vm->status = BC_STATUS_QUIT;
BC_SIG_UNLOCK;
BC_JMP;
}
// Print the ready message.
- bc_file_write(&vm.fout, bc_flush_none, vm.sigmsg, vm.siglen);
- bc_file_write(&vm.fout, bc_flush_none, bc_program_ready_msg,
+ bc_file_write(&vm->fout, bc_flush_none, vm->sigmsg, vm->siglen);
+ bc_file_write(&vm->fout, bc_flush_none, bc_program_ready_msg,
bc_program_ready_msg_len);
bc_history_reset(h);
bc_history_refresh(h);
@@ -1964,7 +1969,7 @@ bc_history_edit(BcHistory* h, const char* prompt)
// Clear screen.
case BC_ACTION_CTRL_L:
{
- bc_file_write(&vm.fout, bc_flush_none, "\x1b[H\x1b[2J", 7);
+ bc_file_write(&vm->fout, bc_flush_none, "\x1b[H\x1b[2J", 7);
bc_history_refresh(h);
break;
}
@@ -1992,7 +1997,7 @@ bc_history_edit(BcHistory* h, const char* prompt)
bc_history_raise(h, SIGQUIT);
}
#else // _WIN32
- vm.status = BC_STATUS_QUIT;
+ vm->status = BC_STATUS_QUIT;
BC_SIG_UNLOCK;
BC_JMP;
#endif // _WIN32
@@ -2032,7 +2037,7 @@ bc_history_line(BcHistory* h, BcVec* vec, const char* prompt)
BcStatus s;
char* line;
- assert(vm.fout.len == 0);
+ assert(vm->fout.len == 0);
bc_history_enableRaw(h);
@@ -2042,8 +2047,8 @@ bc_history_line(BcHistory* h, BcVec* vec, const char* prompt)
s = bc_history_edit(h, prompt);
// Print a newline and flush.
- bc_file_write(&vm.fout, bc_flush_none, "\n", 1);
- bc_file_flush(&vm.fout, bc_flush_none);
+ bc_file_write(&vm->fout, bc_flush_none, "\n", 1);
+ bc_file_flush(&vm->fout, bc_flush_none);
BC_SIG_LOCK;
@@ -2212,7 +2217,7 @@ bc_history_printKeyCodes(BcHistory* h)
// Go left edge manually, we are in raw mode.
bc_vm_putchar('\r', bc_flush_none);
- bc_file_flush(&vm.fout, bc_flush_none);
+ bc_file_flush(&vm->fout, bc_flush_none);
}
bc_history_disableRaw(h);