mirror of
https://git.zap.org.au/git/trader.git
synced 2025-02-02 15:08:13 -05:00
Add the modified status variable to gettxline()
Also correct a bug in gettxline() that always returned OK!
This commit is contained in:
parent
42e05ee20b
commit
60ab28c711
46
src/intf.c
46
src/intf.c
@ -468,6 +468,7 @@ bool getanswer (WINDOW *win)
|
|||||||
y, x - Start of field (line, col)
|
y, x - Start of field (line, col)
|
||||||
fieldsize - Size of field in characters
|
fieldsize - Size of field in characters
|
||||||
attr - Curses attribute to use for the field
|
attr - Curses attribute to use for the field
|
||||||
|
modified - Pointer to modified status
|
||||||
Returns: int - Status code: OK, ERR or key code
|
Returns: int - Status code: OK, ERR or key code
|
||||||
|
|
||||||
This low-level function draws an input field fieldsize characters long
|
This low-level function draws an input field fieldsize characters long
|
||||||
@ -493,6 +494,9 @@ bool getanswer (WINDOW *win)
|
|||||||
appropriate. As with CANCEL etc., emptyval is NOT used, nor are
|
appropriate. As with CANCEL etc., emptyval is NOT used, nor are
|
||||||
leading and trailing spaces stripped.
|
leading and trailing spaces stripped.
|
||||||
|
|
||||||
|
In all of these cases, the boolean variable pointed to by modified (if
|
||||||
|
not NULL) is set to true if the user actually modified the input line.
|
||||||
|
|
||||||
If KEY_DEFAULTVAL is pressed when the input line is empty, the string
|
If KEY_DEFAULTVAL is pressed when the input line is empty, the string
|
||||||
pointed to by defaultval (if not NULL) is placed in the buffer as if
|
pointed to by defaultval (if not NULL) is placed in the buffer as if
|
||||||
typed by the user. Editing is NOT terminated in this case.
|
typed by the user. Editing is NOT terminated in this case.
|
||||||
@ -507,11 +511,11 @@ bool getanswer (WINDOW *win)
|
|||||||
int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
||||||
int maxlen, const char *emptyval, const char *defaultval,
|
int maxlen, const char *emptyval, const char *defaultval,
|
||||||
const char *allowed, bool stripspc, int y, int x,
|
const char *allowed, bool stripspc, int y, int x,
|
||||||
int fieldsize, int attr)
|
int fieldsize, int attr, bool *modified)
|
||||||
{
|
{
|
||||||
int i, len, pos, cpos, nb;
|
int i, len, pos, cpos, nb;
|
||||||
int oldattr;
|
int oldattr;
|
||||||
bool done, redraw, first;
|
bool done, redraw, first, mod;
|
||||||
char c;
|
char c;
|
||||||
int key, key2, ret;
|
int key, key2, ret;
|
||||||
|
|
||||||
@ -536,6 +540,8 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
cpos = MIN(len, fieldsize - 1);
|
cpos = MIN(len, fieldsize - 1);
|
||||||
redraw = true;
|
redraw = true;
|
||||||
done = false;
|
done = false;
|
||||||
|
mod = false;
|
||||||
|
ret = OK;
|
||||||
|
|
||||||
while (! done) {
|
while (! done) {
|
||||||
if (redraw) {
|
if (redraw) {
|
||||||
@ -572,6 +578,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
len = strlen(buf);
|
len = strlen(buf);
|
||||||
pos = len;
|
pos = len;
|
||||||
cpos = MIN(len, fieldsize - 1);
|
cpos = MIN(len, fieldsize - 1);
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
} else if ((key < 0400) && (! iscntrl(key))) {
|
} else if ((key < 0400) && (! iscntrl(key))) {
|
||||||
if ((len >= maxlen) ||
|
if ((len >= maxlen) ||
|
||||||
@ -587,6 +594,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
if (cpos < fieldsize - 1) {
|
if (cpos < fieldsize - 1) {
|
||||||
cpos++;
|
cpos++;
|
||||||
}
|
}
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -605,21 +613,28 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
while ((i < len) && isspace(buf[i])) {
|
while ((i < len) && isspace(buf[i])) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
memmove(buf, buf + i, len - i + 1);
|
if (i > 0) {
|
||||||
len -= i;
|
memmove(buf, buf + i, len - i + 1);
|
||||||
|
len -= i;
|
||||||
|
mod = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Strip trailing spaces
|
// Strip trailing spaces
|
||||||
i = len;
|
i = len;
|
||||||
while ((i > 0) && isspace(buf[i - 1])) {
|
while ((i > 0) && isspace(buf[i - 1])) {
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
buf[i] = '\0';
|
if (i < len) {
|
||||||
len = i;
|
buf[i] = '\0';
|
||||||
|
len = i;
|
||||||
|
mod = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((emptyval != NULL) && (len == 0)) {
|
if ((emptyval != NULL) && (len == 0)) {
|
||||||
strncpy(buf, emptyval, bufsize - 1);
|
strncpy(buf, emptyval, bufsize - 1);
|
||||||
buf[bufsize - 1] = '\0';
|
buf[bufsize - 1] = '\0';
|
||||||
|
mod = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = OK;
|
ret = OK;
|
||||||
@ -754,6 +769,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
if (cpos > 0) {
|
if (cpos > 0) {
|
||||||
cpos--;
|
cpos--;
|
||||||
}
|
}
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -767,6 +783,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
memmove(buf + pos, buf + pos + 1, len - pos);
|
memmove(buf + pos, buf + pos + 1, len - pos);
|
||||||
len--;
|
len--;
|
||||||
// pos and cpos stay the same
|
// pos and cpos stay the same
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -777,6 +794,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
len = 0;
|
len = 0;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
cpos = 0;
|
cpos = 0;
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -789,6 +807,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
len -= pos;
|
len -= pos;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
cpos = 0;
|
cpos = 0;
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -801,6 +820,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
buf[pos] = '\0';
|
buf[pos] = '\0';
|
||||||
len = pos;
|
len = pos;
|
||||||
// pos and cpos stay the same
|
// pos and cpos stay the same
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -833,6 +853,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
memmove(buf + i, buf + pos, len - pos + 1);
|
memmove(buf + i, buf + pos, len - pos + 1);
|
||||||
len -= (pos - i);
|
len -= (pos - i);
|
||||||
pos = i;
|
pos = i;
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -847,6 +868,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
c = buf[pos - 1];
|
c = buf[pos - 1];
|
||||||
buf[pos - 1] = buf[pos - 2];
|
buf[pos - 1] = buf[pos - 2];
|
||||||
buf[pos - 2] = c;
|
buf[pos - 2] = c;
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
} else {
|
} else {
|
||||||
c = buf[pos];
|
c = buf[pos];
|
||||||
@ -857,6 +879,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
if (cpos < fieldsize - 1) {
|
if (cpos < fieldsize - 1) {
|
||||||
cpos++;
|
cpos++;
|
||||||
}
|
}
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -945,6 +968,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
memmove(buf + i, buf + pos, len - pos + 1);
|
memmove(buf + i, buf + pos, len - pos + 1);
|
||||||
len -= (pos - i);
|
len -= (pos - i);
|
||||||
pos = i;
|
pos = i;
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -962,6 +986,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
memmove(buf + pos, buf + i, len - i + 1);
|
memmove(buf + pos, buf + i, len - i + 1);
|
||||||
len -= (i - pos);
|
len -= (i - pos);
|
||||||
// pos and cpos stay the same
|
// pos and cpos stay the same
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -998,6 +1023,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -1020,6 +1046,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
cpos++;
|
cpos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1039,6 +1066,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
cpos++;
|
cpos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1065,6 +1093,7 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
cpos++;
|
cpos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mod = true;
|
||||||
redraw = true;
|
redraw = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1106,5 +1135,8 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|||||||
wattrset(win, oldattr);
|
wattrset(win, oldattr);
|
||||||
wrefresh(win);
|
wrefresh(win);
|
||||||
|
|
||||||
return OK;
|
if (modified != NULL) {
|
||||||
|
*modified = mod;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,6 @@ extern bool getanswer (WINDOW *win);
|
|||||||
extern int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
extern int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
||||||
int maxlen, const char *emptyval, const char *defaultval,
|
int maxlen, const char *emptyval, const char *defaultval,
|
||||||
const char *allowed, bool stripspc, int y, int x,
|
const char *allowed, bool stripspc, int y, int x,
|
||||||
int fieldsize, int attr);
|
int fieldsize, int attr, bool *modified);
|
||||||
|
|
||||||
|
|
||||||
#endif /* included_INTF_H */
|
#endif /* included_INTF_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user