-/* Gets a line from the terminal */
-/* string == Pointer to string buffer */
-/* lim == Maximum length - if negative, no-show */
-void ctdl_getline(char *string, int lim)
+/*
+ * Function to read a line of text from the terminal.
+ *
+ * string Pointer to string buffer
+ * lim Maximum length
+ * noshow If nonzero, echo asterisks instead of keystrokes
+ */
+void ctdl_getline(char *string, int lim, int noshow)
{
int a, b;
- char flag = 0;
- if (lim < 0) {
- lim = (0 - lim);
- flag = 1;
- }
strcpy(string, "");
gl_string = string;
async_ka_start();
GLA: a = inkey();
- /* a = (a & 127); ** commented out because it isn't just an ASCII world anymore */
if ((a == 8 || a == 23) && (IsEmptyStr(string)))
goto GLA;
if ((a != 10) && (a != 8) && (strlen(string) == lim))
async_ka_end();
return;
}
- if (a < 32)
+ if (a < 32) {
a = '.';
+ }
b = strlen(string);
string[b] = a;
string[b + 1] = 0;
- if (flag == 0)
- scr_putc(a);
- if (flag == 1)
+ if (noshow) {
scr_putc('*');
+ }
+ else {
+ scr_putc(a);
+ }
goto GLA;
}
color(DIM_WHITE);
scr_printf(": ");
color(BRIGHT_CYAN);
- ctdl_getline(buf, len);
- if (buf[0] != 0)
+ ctdl_getline(buf, abs(len), (len<0));
+ if (buf[0] != 0) {
strcpy(str, buf);
+ }
color(DIM_WHITE);
}
*/
void newprompt(char *prompt, char *str, int len)
{
+ str[0] = 0;
color(BRIGHT_MAGENTA);
scr_printf("%s", prompt);
color(DIM_MAGENTA);
- ctdl_getline(str, len);
+ ctdl_getline(str, abs(len), (len<0));
color(DIM_WHITE);
}
if (cmdmatch(cmdbuf, cptr, 5)) {
/* We've found our command. */
if (requires_string(cptr, cmdpos)) {
- ctdl_getline(argbuf, 64);
+ argbuf[0] = 0;
+ ctdl_getline(argbuf, 64, 0);
} else {
scr_printf("\n");
}