| 214 |
if (rlen > 1000) |
if (rlen > 1000) |
| 215 |
{ |
{ |
| 216 |
int dlen; |
int dlen; |
| 217 |
|
|
| 218 |
/* If libreadline support is required, use readline() to read a line if the |
/* If libreadline support is required, use readline() to read a line if the |
| 219 |
input is a terminal. Note that readline() removes the trailing newline, so |
input is a terminal. Note that readline() removes the trailing newline, so |
| 220 |
we must put it back again, to be compatible with fgets(). */ |
we must put it back again, to be compatible with fgets(). */ |
| 221 |
|
|
| 222 |
#ifdef SUPPORT_LIBREADLINE |
#ifdef SUPPORT_LIBREADLINE |
| 223 |
if (isatty(fileno(f))) |
if (isatty(fileno(f))) |
| 224 |
{ |
{ |
| 225 |
size_t len; |
size_t len; |
| 226 |
char *s = readline(prompt); |
char *s = readline(prompt); |
| 227 |
if (s == NULL) return (here == start)? NULL : start; |
if (s == NULL) return (here == start)? NULL : start; |
| 228 |
len = strlen(s); |
len = strlen(s); |
| 229 |
if (len > 0) add_history(s); |
if (len > 0) add_history(s); |
| 230 |
if (len > rlen - 1) len = rlen - 1; |
if (len > rlen - 1) len = rlen - 1; |
| 231 |
memcpy(here, s, len); |
memcpy(here, s, len); |
| 232 |
here[len] = '\n'; |
here[len] = '\n'; |
| 233 |
here[len+1] = 0; |
here[len+1] = 0; |
| 234 |
free(s); |
free(s); |
| 235 |
} |
} |
| 236 |
else |
else |
| 237 |
#endif |
#endif |
| 238 |
|
|
| 239 |
/* Read the next line by normal means, prompting if the file is stdin. */ |
/* Read the next line by normal means, prompting if the file is stdin. */ |
| 240 |
|
|
| 241 |
{ |
{ |
| 242 |
if (f == stdin) printf(prompt); |
if (f == stdin) printf(prompt); |
| 243 |
if (fgets((char *)here, rlen, f) == NULL) |
if (fgets((char *)here, rlen, f) == NULL) |
| 244 |
return (here == start)? NULL : start; |
return (here == start)? NULL : start; |
| 245 |
} |
} |
| 246 |
|
|
| 247 |
dlen = (int)strlen((char *)here); |
dlen = (int)strlen((char *)here); |
| 248 |
if (dlen > 0 && here[dlen - 1] == '\n') return start; |
if (dlen > 0 && here[dlen - 1] == '\n') return start; |
| 249 |
here += dlen; |
here += dlen; |