#ifndef lint
-static char *sccsid = "@(#)cmd2.c 2.1 83/07/30";
+static char sccsid[] = "@(#)cmd2.c 3.33 %G%";
#endif
-#include "defs.h"
-
-struct ww *getwin();
-struct ww *openwin();
-char *strtime();
-
-dohelp()
-{
- register struct ww *w;
+/*
+ * Copyright (c) 1983 Regents of the University of California,
+ * All rights reserved. Redistribution permitted subject to
+ * the terms of the Berkeley Software License Agreement.
+ */
- if ((w = openwin(wwnrow - 1, "Help")) == 0) {
- if (terse)
- Ding();
- else
- wwputs("Can't open help window. ", cmdwin);
- return;
- }
- wwprintf(w, "The escape character is %s, which gets you into command mode.\r\n\n",
- unctrl(escapec));
- wwprintf(w, "Short commands:\r\n\n");
- wwprintf(w, "{1-9} Select window {1-9} and return to conversation mode.\r\n");
- wwprintf(w, "%%{1-9} Select window {1-9}.\r\n");
- wwprintf(w, "c{1-9} Close window {1-9}.\r\n");
- wwprintf(w, "C Close all windows.\r\n");
- wwprintf(w, "S Show all windows in sequence.\r\n");
- wwprintf(w, "L List all windows with their labels.\r\n");
- wwprintf(w, "w Open a new window.\r\n");
- wwprintf(w, "[^U^D] Scroll [up, down] half a window.\r\n");
- wwprintf(w, "[^B^F] Scroll [up, down] a full window.\r\n");
- wwprintf(w, "[hjkl] Move cursor [left, down, up, right].\r\n");
- wwprintf(w, "escape Exit command mode.\r\n");
- wwprintf(w, "^L Redraw screen.\r\n");
- wwprintf(w, "^Z Suspend.\r\n");
- wwprintf(w, ". Quit.\r\n");
- waitnl(w);
- wwprintf(w, "Long commands:\r\n\n");
- wwprintf(w, ":terse [off] Turn on (or off) terse mode.\r\n");
- wwprintf(w, ":refresh {1-9} [off] Turn on (or off) refresh after every newline\r\n");
- wwprintf(w, " for window {1-9}.\r\n");
- wwprintf(w, ":label {1-9} string Label window {1-9}.\r\n");
- wwprintf(w, ":escape C Set escape character to C.\r\n");
- wwprintf(w, ":%%{1-9} Select window {1-9}.\r\n");
- wwprintf(w, ":window r c nr nc Open a window at row r column c\r\n");
- wwprintf(w, " with nr rows and nc colomns\r\n");
- wwprintf(w, ":source filename Execute the commands in `filename'.\r\n");
- waitnl(w);
- closewin(w);
-}
+#include "defs.h"
-dotime(flag)
+char *help_shortcmd[] = {
+ "# Select window # and return to conversation mode",
+ "%# Select window # but stay in command mode",
+ "escape Return to conversation mode without changing window",
+ "^^ Return to conversation mode and change to previous window",
+ "c# Close window #",
+ "w Open a new window",
+ "m# Move window #",
+ "M# Move window # to its previous position",
+ "s# Change the size of window #",
+ "S# Change window # to its previous size",
+ "^Y Scroll up one line",
+ "^E Scroll down one line",
+ "^U Scroll up half a window",
+ "^D Scroll down half a window",
+ "^B Scroll up a full window",
+ "^F Scroll down a full window",
+ "h Move cursor left",
+ "j Move cursor down",
+ "k Move cursor up",
+ "l Move cursor right",
+ "^S Stop output in current window",
+ "^Q Restart output in current window",
+ "^L Redraw screen",
+ "^Z Suspend",
+ "q Quit",
+ ": Enter a long command",
+ 0
+};
+char *help_longcmd[] = {
+ ":alias name string ... Make `name' an alias for `string ...'",
+ ":alias Show all aliases",
+ ":close # ... Close windows",
+ ":close all Close all windows",
+ ":cursor modes Set the cursor modes",
+ ":echo # string ... Print `string ...' in window #",
+ ":escape c Set escape character to `c'",
+ ":foreground # flag Make # a foreground window, if `flag' is true",
+ ":label # string Set label of window # to `string'",
+ ":list List all open windows",
+ ":nline lines Set default window buffer size to `lines'",
+ ":select # Select window #",
+ ":shell string ... Set default shell program to `string ...'",
+ ":source filename Execute commands in `filename'",
+ ":terse flag Set terse mode",
+ ":unalias name Undefine `name' as an alias",
+ ":unset variable Deallocate `variable'",
+ ":variable List all variables",
+ ":window row col nrow ncol [nline label pty frame shell]",
+ " Open a window at `row', `col' of size `nrow', `ncol',",
+ " with `nline' lines in the buffer, and `label'",
+ ":write # string ... Write `string ...' to window # as input",
+ 0
+};
+
+c_help()
{
register struct ww *w;
- struct rusage rusage;
- struct timeval timeval;
- if ((w = openwin(8, "Timing and Resource Usage")) == 0) {
- if (terse)
- Ding();
- else
- wwputs("Can't open time window. ", cmdwin);
+ if ((w = openiwin(wwnrow - 3, "Help")) == 0) {
+ error("Can't open help window: %s.", wwerror());
return;
}
-
- gettimeofday(&timeval, &timezone);
- timeval.tv_sec -= starttime.tv_sec;
- if ((timeval.tv_usec -= starttime.tv_usec) < 0) {
- timeval.tv_sec--;
- timeval.tv_usec += 1000000;
- }
- getrusage(flag, &rusage);
-
- wwprintf(w, "time\t\tutime\t\tstime\t\tmaxrss\tixrss\tidrss\tisrss\r\n");
- wwprintf(w, "%-16s", strtime(&timeval));
- wwprintf(w, "%-16s", strtime(&rusage.ru_utime));
- wwprintf(w, "%-16s", strtime(&rusage.ru_stime));
- wwprintf(w, "%D\t%D\t%D\t%D\r\n",
- rusage.ru_maxrss, rusage.ru_ixrss,
- rusage.ru_idrss, rusage.ru_isrss);
- wwprintf(w, "minflt\tmajflt\tnswap\tinblk\toublk\tmsgsnd\tmsgrcv\tnsigs\tnvcsw\tnivcsw\r\n");
- wwprintf(w, "%D\%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\r\n",
- rusage.ru_minflt, rusage.ru_majflt, rusage.ru_nswap,
- rusage.ru_inblock, rusage.ru_oublock,
- rusage.ru_msgsnd, rusage.ru_msgrcv, rusage.ru_nsignals,
- rusage.ru_nvcsw, rusage.ru_nivcsw);
-
- waitnl(w);
- closewin(w);
+ wwprintf(w, "The escape character is %c.\n", escapec);
+ wwprintf(w, "(# represents one of the digits from 1 to 9.)\n\n");
+ if (help_print(w, "Short commands", help_shortcmd) >= 0)
+ (void) help_print(w, "Long commands", help_longcmd);
+ closeiwin(w);
}
-char *
-strtime(t)
-register struct timeval *t;
+help_print(w, name, list)
+register struct ww *w;
+char *name;
+register char **list;
{
- char fill = 0;
- static char buf[20];
- register char *p = buf;
-
- if (t->tv_sec > 60*60) {
- sprintf(p, "%D:", t->tv_sec / (60*60));
- while (*p++)
- ;
- p--;
- t->tv_sec %= 60*60;
- fill++;
- }
- if (t->tv_sec > 60) {
- sprintf(p, fill ? "%02D:" : "%D:", t->tv_sec / 60);
- while (*p++)
- ;
- p--;
- t->tv_sec %= 60;
- fill++;
- }
- sprintf(p, fill ? "%02D.%02d" : "%D.%02D",
- t->tv_sec, t->tv_usec / 10000);
- return buf;
+ wwprintf(w, "%s:\n\n", name);
+ while (*list)
+ switch (more(w, 0)) {
+ case 0:
+ wwputs(*list++, w);
+ wwputc('\n', w);
+ break;
+ case 1:
+ wwprintf(w, "%s: (continued)\n\n", name);
+ break;
+ case 2:
+ return -1;
+ }
+ return more(w, 1) == 2 ? -1 : 0;
}
-dostat()
+c_quit()
{
- register struct ww *w;
-
- if ((w = openwin(6, "IO Statics")) == 0) {
- if (terse)
- Ding();
- else
- wwputs("Can't open statistics window. ", cmdwin);
- return;
- }
- wwprintf(w, "nread\tnreadz\tnreade\tnreadc\tnwrite\tnwritec\r\n");
- wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\r\n",
- nread, nreadz, nreade, nreadc, wwnwrite, wwnwritec);
- waitnl(w);
- closewin(w);
-}
+ char oldterse = terse;
-dolist()
-{
- register struct ww *w, *w1;
- int id;
- char doneit = 0;
-
- if ((w = openwin(14, "Active Windows")) == 0) {
- if (terse)
- Ding();
- else
- wwputs("Can't open listing window. ", cmdwin);
- return;
- }
- for (id = 1; id <= NWINDOW; id++) {
- if ((w1 = wwfind(id)) == 0)
- continue;
- doneit = 1;
- wwprintf(w, "%d %s\r\n", id, w1->ww_label);
- }
- if (!doneit)
- wwprintf(w, "No windows.\r\n");
- waitnl(w);
- closewin(w);
-}
-
-doquit()
-{
- if (terse)
- Wunhide(cmdwin->ww_win);
+ setterse(0);
wwputs("Really quit [yn]? ", cmdwin);
- wwsetcursor(WCurRow(cmdwin->ww_win), WCurCol(cmdwin->ww_win));
- while (bpeekc() < 0)
- bread();
- if (bgetc() == 'y') {
+ wwcurtowin(cmdwin);
+ while (wwpeekc() < 0)
+ wwiomux();
+ if (wwgetc() == 'y') {
wwputs("Yes", cmdwin);
quit++;
} else
- wwputs("\r\n", cmdwin);
- if (terse)
- Whide(cmdwin->ww_win);
-}
-
-struct ww *
-openwin(nrow, label)
-char *label;
-{
- register struct ww *w;
- int startcol;
-
- if ((w = wwopen(WW_NONE, 0, nrow, wwncol, 0, 0)) == 0)
- return 0;
- wwframe(w);
- if ((startcol = (wwncol - strlen(label)) / 2) <= 0)
- startcol = 1;
- wwlabel(w, startcol, label, WINVERSE);
- wwsetcurwin(w);
- return w;
-}
-
-waitnl(w)
-register struct ww *w;
-{
- wwsetcurwin(w);
- wwprintf(w, "\r\nType return to continue: ");
- wwsetcursor(WCurRow(w->ww_win), WCurCol(w->ww_win));
- while (bgetc() < 0)
- bread();
- wwputs("\033E", w); /* clear and home cursor */
-}
-
-closewin(w)
-register struct ww *w;
-{
- wwclose(w);
- wwsetcurwin(cmdwin);
+ wwputc('\n', cmdwin);
+ setterse(!quit && oldterse);
}