fread (buffer + size - BUFFERSIZE - 1, 1, BUFFERSIZE, sd);
} while (!feof (sd));
+ /* check size */
+ if (buffer[0] == '\0') {
+ free (buffer);
+ buffer = NULL;
+ }
+
return buffer;
}
status = pclose(fp);
}
- if (status == -1) {
- VERBOSE (ERROR, fprintf (stderr, "can't exec command: %s\n", cmd));
+ if ((status == -1) || (buffer == NULL)) {
free (buffer);
buffer = NULL;
}
}
if (status == -1) {
- VERBOSE (ERROR, fprintf (stderr, "can't load file: %s\n", name));
free (buffer);
buffer = NULL;
}
/* winlnk: cmd.o debug.o tui.o -lpdcurses */
#include <stdlib.h>
+#include <unistd.h>
#include "cmd.h"
#include "debug.h"
char *input = NULL;
char *command = NULL;
+int second = 0;
void display (char **lines, int xmax, int ymax)
{
bodymsg (lines[skip + i]);
eol = (lines[skip + i][xmax - 1 ] == '\0');
}
+ if (second > 0) {
+ DoExit ();
+ break;
+ }
int key = waitforkey ();
switch (key) {
case KEY_ESC:
}
if (buffer == NULL) {
- char msg[80];
- sprintf (msg, "Error executing %s", command ? command : input ? input : "stdin");
- statusmsg (msg);
+ cleanup ();
+ VERBOSE (ERROR, fprintf (stderr, "%s: %s\n", command ? "can't execute:" : input ? "can't load:" : "can't read", command ? command : input ? input : "stdin"));
+ exit (1);
}
if (!lines) {
free (buffer);
}
- display (lines, xmax, ymax);
- if (command || buffer) {
- free_lines (lines);
- lines = NULL;
+ if (lines) {
+ display (lines, xmax, ymax);
+ if (command || buffer) {
+ free_lines (lines);
+ lines = NULL;
+ }
+ }
+
+ if (second > 0) {
+ VERBOSE (DEBUG, fprintf (stdout, "sleeping for %d''\n", second));
+ sleep (second);
+ cleanup ();
+ exit (0);
}
}
int usage (int ret)
{
FILE *fd = ret ? stderr : stdout;
- fprintf (fd, "usage: %s [-c command] [-f file] [-h] [-v]\n", progname);
+ fprintf (fd, "usage: %s [-c command] [-f file] [-h] [-s sec] [-v]\n", progname);
fprintf (fd, " -c: command\n");
fprintf (fd, " -i: input file\n");
fprintf (fd, " -h: help message\n");
+ fprintf (fd, " -s: stoptime\n");
fprintf (fd, " -v: verbose level (%d)\n", verbose);
return ret;
return usage (1);
}
break;
+ case 's':
+ arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
+ if (arg == NULL) {
+ VERBOSE (ERROR, fprintf (stderr, "%s: missing number of second\n", progname));
+ return usage (1);
+ }
+ second = atoi (arg);
+ break;
case 'v':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
if (arg == NULL) {
return 0;
}
-/* test: cmore.exe -h | grep usage */
/* test: cmore.exe -c 2>&1 | grep error */
/* test: cmore.exe -c notAnExistingCommand 2>&1 | grep can\'t */
/* test: cmore.exe -f 2>&1 | grep error */
/* test: cmore.exe -f notAnExistingFile 2>&1 | grep can\'t */
+/* test: cmore.exe -h | grep usage */
+/* test: cmore.exe -Z 2>&1 | grep usage */
+/* test: cmore.exe -v 2>&1 | grep missing */
+/* test: cmore.exe -s 2>&1 | grep missing */
+/* test: cmore.exe _ 2>&1 | grep invalid */
+/* test: cat tui.c | cmore.exe -v 5 -s 2*/
/* test: (sleep 1; echo -n q) | cmore.exe -c 'ip addr' */
/* test: (sleep 1; echo -ne '\e\e') | cmore.exe -f tui.c */
/* test: (sleep 1; echo -n kkkkk; sleep 1; echo -n i; sleep 1; echo -n q) | cmore.exe -c 'ip addr' */