getmaxyx (wbody, ymax, xmax);
char *buffer = (char *)-1;
+ static int is_stdin = 0;
if (command) {
buffer = exec_cmd (command);
} else if (input) {
buffer = load_file (input);
} else if (!lines) {
- buffer = read_stdin ();
+ if (!is_stdin) {
+ buffer = read_stdin ();
+ is_stdin = 1;
+ }
}
if (buffer == NULL) {
if (lines) {
display (lines, xmax, ymax);
- if (command || buffer) {
+ if (buffer) {
free_lines (lines);
lines = NULL;
}
char *desc[] = {"New command", NULL};
char *buf[] = {buffer, NULL};
int c = getstrings (desc, buf, 48);
- VERBOSE (DEBUG, fprintf (stdout, "return: 0x%04x (%c)\n", c, (c >= 32) ? c : '.'));
+
+ if ((c == '\n') && (strlen (buffer) > 0)) {
+ free (command);
+ free (input);
+ command = strdup (buffer);
+ input = NULL;
+ process ();
+ }
}
void chfile (void)
{
+ char buffer[48 + 1] = {0};
+ char *desc[] = {"New file", NULL};
+ char *buf[] = {buffer, NULL};
+ int c = getstrings (desc, buf, 48);
+
+ if ((c == '\n') && (strlen (buffer) > 0)) {
+ free (command);
+ free (input);
+ command = NULL;
+ input = strdup (buffer);
+ process ();
+ }
}
void contdisp (void)
switch (c) {
case 'c':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
- if ((arg) && (command == NULL)) {
- command = arg;
+ if (arg) {
+ free (command);
+ free (input);
+ command = strdup (arg);
+ input = NULL;
} else {
- VERBOSE (ERROR, fprintf (stderr, "%s: error for command '%s'\n", progname, arg));
+ VERBOSE (ERROR, fprintf (stderr, "%s: error for command\n", progname));
return usage (1);
}
break;
case 'f':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
- if ((arg) && (input == NULL)) {
- input = arg;
+ if (arg) {
+ free (command);
+ free (input);
+ command = NULL;
+ input = strdup (arg);
} else {
- VERBOSE (ERROR, fprintf (stderr, "%s: error for file '%s'\n", progname, arg));
+ VERBOSE (ERROR, fprintf (stderr, "%s: error for file\n", progname));
return usage (1);
}
break;