volatile unsigned cmdedit_termw; /* = 80; */ /* actual terminal width */
sighandler_t previous_SIGWINCH_handler;
-
- int cmdedit_x; /* real x terminal position */
- int cmdedit_y; /* pseudoreal y terminal position */
- int cmdedit_prmt_len; /* length of prompt (without colors etc) */
+ unsigned cmdedit_x; /* real x terminal position */
+ unsigned cmdedit_y; /* pseudoreal y terminal position */
+ unsigned cmdedit_prmt_len; /* length of prompt (without colors etc) */
unsigned cursor;
unsigned command_len;
return;
cursor -= num;
- if ((unsigned)cmdedit_x >= num) {
+ if (cmdedit_x >= num) {
cmdedit_x -= num;
if (num <= 4) {
/* This is longer by 5 bytes on x86.
- * Also gets mysteriously
- * miscompiled for some ARM users.
+ * Also gets miscompiled for ARM users
+ * (busybox.net/bugs/view.php?id=2274).
* printf(("\b\b\b\b" + 4) - num);
* return;
*/
/* Need to go one or more lines up */
num -= cmdedit_x;
- count_y = 1 + (num / cmdedit_termw);
- cmdedit_y -= count_y;
- cmdedit_x = cmdedit_termw * count_y - num;
+ {
+ unsigned w = cmdedit_termw; /* volatile var */
+ count_y = 1 + (num / w);
+ cmdedit_y -= count_y;
+ cmdedit_x = w * count_y - num;
+ }
/* go to 1st column; go up; go to correct column */
printf("\r" "\033[%dA" "\033[%dC", count_y, cmdedit_x);
}
static void put_prompt(void)
{
out1str(cmdedit_prompt);
- cmdedit_x = cmdedit_prmt_len;
cursor = 0;
-// Huh? what if cmdedit_prmt_len >= width?
- cmdedit_y = 0; /* new quasireal y */
+ {
+ unsigned w = cmdedit_termw; /* volatile var */
+ cmdedit_y = cmdedit_prmt_len / w; /* new quasireal y */
+ cmdedit_x = cmdedit_prmt_len % w;
+ }
}
/* draw prompt, editor line, and clear tail */
exe_n_cwd_tab_completion(matchBuf, find_type);
/* Sort, then remove any duplicates found */
if (matches) {
- int i, n = 0;
+ unsigned i;
+ int n = 0;
qsort_string_vector(matches, num_matches);
for (i = 0; i < num_matches - 1; ++i) {
if (matches[i] && matches[i+1]) { /* paranoia */
static void win_changed(int nsig)
{
- int width;
+ unsigned width;
get_terminal_width_height(0, &width, NULL);
cmdedit_setwidth(width, nsig /* - just a yes/no flag */);
if (nsig == SIGWINCH)
* 0 on ctrl-C (the line entered is still returned in 'command'),
* >0 length of input string, including terminating '\n'
*/
-int read_line_input(const char *prompt, char *command, int maxsize, line_input_t *st)
+int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, line_input_t *st)
{
#if ENABLE_FEATURE_TAB_COMPLETION
smallint lastWasTab = FALSE;
#endif
- unsigned int ic;
+ unsigned ic;
unsigned char c;
smallint break_out = 0;
#if ENABLE_FEATURE_EDITING_VI
return command_len;
}
-line_input_t *new_line_input_t(int flags)
+line_input_t* FAST_FUNC new_line_input_t(int flags)
{
line_input_t *n = xzalloc(sizeof(*n));
n->flags = flags;
#else
#undef read_line_input
-int read_line_input(const char* prompt, char* command, int maxsize)
+int FAST_FUNC read_line_input(const char* prompt, char* command, int maxsize)
{
fputs(prompt, stdout);
fflush(stdout);