3 /* linker: cmd.o debug.o tui.o -lcurses */
4 /* winlnk: cmd.o debug.o tui.o -lpdcurses */
14 /* static variables */
15 char *progname
= NULL
;
16 char *version
= "0.1";
22 void display (char **lines
, int xmax
, int ymax
)
27 statusmsg ("Press 'q' or escape to quit");
29 statusmsg ("Press 'q' or double-escape to quit");
37 for (i
= 0; i
< ymax
- 1; i
++) {
38 if (lines
[skip
+ i
] == NULL
) {
44 bodymsg (lines
[skip
+ i
]);
45 eol
= (lines
[skip
+ i
][xmax
- 1 ] == '\0');
47 if (lines
[skip
+ i
] != NULL
) {
51 char *str
= (char *) calloc (1, xmax
+ 1);
52 strcpy (str
, lines
[skip
+ i
]);
53 if (str
[xmax
- 1] != '\0') {
54 VERBOSE (DEBUG
, fprintf (stdout
, "last line too long\n"));
55 strcpy (str
+ xmax
- 3, ">>");
65 int key
= waitforkey ();
66 VERBOSE (DEBUG
, fprintf (stdout
, "key pressed: 0x%04x (%c)\n", key
, (key
>= ' ') && (key
< 256) ? key
: '.'));
88 skip
= (skip
> 0) ? skip
- 1 : skip
;
92 skip
= (lines
[skip
+ 1] != NULL
) ? skip
+ 1 : skip
;
108 static char **lines
= NULL
;
111 WINDOW
*wbody
= bodywin ();
112 getmaxyx (wbody
, ymax
, xmax
);
114 char *buffer
= (char *)-1;
116 buffer
= exec_cmd (command
);
118 buffer
= load_file (input
);
120 buffer
= read_stdin ();
123 if (buffer
== NULL
) {
125 VERBOSE (ERROR
, fprintf (stderr
, "%s: %s\n", command
? "can't execute:" : input
? "can't load:" : "can't read", command
? command
: input
? input
: "stdin"));
130 lines
= split_lines (buffer
, xmax
);
135 display (lines
, xmax
, ymax
);
136 if (command
|| buffer
) {
143 VERBOSE (DEBUG
, fprintf (stdout
, "sleeping for %d''\n", second
));
152 { "Refresh", process
, "Refresh action"},
153 { "Exit", DoExit
, "Terminate program" },
164 { "About", DoExit
, "About..." },
175 { "File", sub0
, "File menu" },
176 { "Help", sub1
, "Help menu" },
177 { "", (FUNC
)0, "" } /* always add this as the last item! */
183 FILE *fd
= ret
? stderr
: stdout
;
184 fprintf (fd
, "usage: %s [-c command] [-f file] [-h] [-s sec] [-v]\n", progname
);
185 fprintf (fd
, " -c: command\n");
186 fprintf (fd
, " -i: input file\n");
187 fprintf (fd
, " -h: help message\n");
188 fprintf (fd
, " -s: stoptime\n");
189 fprintf (fd
, " -v: verbose level (%d)\n", verbose
);
195 int main (int argc
, char *argv
[])
199 char *pt
= progname
= argv
[0];
201 if ((*pt
== '/') || (*pt
== '\\')) {
207 /* process argument */
209 char *arg
= *(++argv
);
211 VERBOSE (ERROR
, fprintf (stderr
, "%s: invalid option -- %s\n", progname
, arg
));
217 arg
= (arg
[2]) ? arg
+ 2 : (--argc
> 0) ? *(++argv
) : NULL
;
218 if ((arg
) && (command
== NULL
)) {
221 VERBOSE (ERROR
, fprintf (stderr
, "%s: error for command '%s'\n", progname
, arg
));
226 arg
= (arg
[2]) ? arg
+ 2 : (--argc
> 0) ? *(++argv
) : NULL
;
227 if ((arg
) && (input
== NULL
)) {
230 VERBOSE (ERROR
, fprintf (stderr
, "%s: error for file '%s'\n", progname
, arg
));
235 arg
= (arg
[2]) ? arg
+ 2 : (--argc
> 0) ? *(++argv
) : NULL
;
237 VERBOSE (ERROR
, fprintf (stderr
, "%s: missing number of second\n", progname
));
243 arg
= (arg
[2]) ? arg
+ 2 : (--argc
> 0) ? *(++argv
) : NULL
;
245 VERBOSE (ERROR
, fprintf (stderr
, "%s: missing verbose level\n", progname
));
248 verbose
= atoi (arg
);
252 return usage (c
!= 'h');
256 char titre
[256] = {0};
257 sprintf (titre
, "Application: %s", command
? command
: input
? input
: "stdin");
259 startmenu (MainMenu
, titre
, process
);
264 /* test: cmore.exe -c 2>&1 | grep error */
265 /* test: cmore.exe -c notAnExistingCommand 2>&1 | grep can\'t */
266 /* test: cmore.exe -f 2>&1 | grep error */
267 /* test: cmore.exe -f notAnExistingFile 2>&1 | grep can\'t */
268 /* test: cmore.exe -h | grep usage */
269 /* test: cmore.exe -Z 2>&1 | grep usage */
270 /* test: cmore.exe -v 2>&1 | grep missing */
271 /* test: cmore.exe -s 2>&1 | grep missing */
272 /* test: cmore.exe _ 2>&1 | grep invalid */
273 /* test: cat tui.c | cmore.exe -v 5 -s 2*/
274 /* test: (sleep 1; echo -n q) | cmore.exe -c 'ip addr' */
275 /* test: (sleep 1; echo -ne '\e\e') | cmore.exe -f tui.c */
276 /* test: (sleep 1; echo -n kkkkk; sleep 1; echo -n i; sleep 1; echo -n q) | cmore.exe -c 'ip addr' */
277 /* test: (sleep 1; echo -n q) | cmore.exe -c 'echo -n a; for i in $(seq 1 '$(( $COLUMNS*($LINES-4)-2 ))'); do echo -n .; done; echo -n z' -v 5 | grep -q 'last line too long' */
278 /* test: (sleep 1; echo -n q) | cmore.exe -c 'echo -n a; for i in $(seq 1 '$(( $COLUMNS*($LINES-4)-3 ))'); do echo -n .; done; echo -n z' -v 5 | grep -q 'last line too long'; test $? -eq 1 */
280 /* vim: set ts=4 sw=4 et: */