date and time created 83/07/22 17:07:04 by edward
[unix-history] / usr / src / usr.bin / window / cmd2.c
CommitLineData
708ccf0a 1#ifndef lint
8c4fb896 2static char *sccsid = "@(#)cmd2.c 1.3 83/07/20";
708ccf0a
EW
3#endif
4
5#include "defs.h"
6
7struct ww *getwin();
8struct ww *openwin();
9char *strtime();
10
11dohelp()
12{
13 register struct ww *w;
14
8c4fb896
EW
15 if ((w = openwin(22, "Help")) == 0) {
16 wwputs("Can't open help window. ", cmdwin);
708ccf0a 17 return;
8c4fb896 18 }
708ccf0a
EW
19 wwprintf(w, "The escape character is ^P, which gets you into command mode.\r\n");
20 wwprintf(w, "The commands are:\r\n");
8c4fb896
EW
21 wwprintf(w, "[1-9] Select window [1-9] and exit command mode\r\n");
22 wwprintf(w, "%%[1-9] Select window [1-9]\r\n");
23 wwprintf(w, "c[1-9] Close window [1-9]\r\n");
24 wwprintf(w, "C Close all empty windows\r\n");
25 wwprintf(w, "Z Close all windows\r\n");
26 wwprintf(w, "Q Show all windows in sequence\r\n");
27 wwprintf(w, "R Force refresh after every newline in current window\r\n");
28 wwprintf(w, "r Don't refresh every line\r\n");
29 wwprintf(w, "w Open a new window\r\n");
30 wwprintf(w, "s Print IO statistics\r\n");
31 wwprintf(w, "t Print resource usage of this program\r\n");
32 wwprintf(w, "T Print resource usage of children\r\n");
33 wwprintf(w, "escape Exit command mode\r\n");
34 wwprintf(w, "^L Redraw screen\r\n");
35 wwprintf(w, "^Z Suspend\r\n");
36 wwprintf(w, ". Quit\r\n");
b4be6cd6 37 waitnl(w);
708ccf0a
EW
38 closewin(w);
39}
40
41dotime(flag)
42{
43 register struct ww *w;
44 struct rusage rusage;
45 struct timeval timeval;
46
8c4fb896
EW
47 if ((w = openwin(8, "Time")) == 0) {
48 wwputs("Can't open time window. ", cmdwin);
708ccf0a 49 return;
8c4fb896 50 }
708ccf0a
EW
51
52 gettimeofday(&timeval, &timezone);
53 timeval.tv_sec -= starttime.tv_sec;
54 if ((timeval.tv_usec -= starttime.tv_usec) < 0) {
55 timeval.tv_sec--;
56 timeval.tv_usec += 1000000;
57 }
58 getrusage(flag, &rusage);
59
60 wwprintf(w, "time\t\tutime\t\tstime\t\tmaxrss\tixrss\tidrss\tisrss\r\n");
61 wwprintf(w, "%-16s", strtime(&timeval));
62 wwprintf(w, "%-16s", strtime(&rusage.ru_utime));
63 wwprintf(w, "%-16s", strtime(&rusage.ru_stime));
64 wwprintf(w, "%D\t%D\t%D\t%D\r\n",
65 rusage.ru_maxrss, rusage.ru_ixrss,
66 rusage.ru_idrss, rusage.ru_isrss);
67 wwprintf(w, "minflt\tmajflt\tnswap\tinblk\toublk\tmsgsnd\tmsgrcv\tnsigs\tnvcsw\tnivcsw\r\n");
68 wwprintf(w, "%D\%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\r\n",
69 rusage.ru_minflt, rusage.ru_majflt, rusage.ru_nswap,
70 rusage.ru_inblock, rusage.ru_oublock,
71 rusage.ru_msgsnd, rusage.ru_msgrcv, rusage.ru_nsignals,
72 rusage.ru_nvcsw, rusage.ru_nivcsw);
73
b4be6cd6 74 waitnl(w);
708ccf0a
EW
75 closewin(w);
76}
77
78char *
79strtime(t)
80register struct timeval *t;
81{
82 char fill = 0;
83 static char buf[20];
84 register char *p = buf;
85
86 if (t->tv_sec > 60*60) {
87 sprintf(p, "%D:", t->tv_sec / (60*60));
88 while (*p++)
89 ;
90 p--;
91 t->tv_sec %= 60*60;
92 fill++;
93 }
94 if (t->tv_sec > 60) {
95 sprintf(p, fill ? "%02D:" : "%D:", t->tv_sec / 60);
96 while (*p++)
97 ;
98 p--;
99 t->tv_sec %= 60;
100 fill++;
101 }
102 sprintf(p, fill ? "%02D.%02d" : "%D.%02D",
103 t->tv_sec, t->tv_usec / 10000);
104 return buf;
105}
106
8c4fb896
EW
107doquit()
108{
109 wwputs("Really quit? ", cmdwin);
110 wwsetcursor(WCurRow(cmdwin->ww_win), WCurCol(cmdwin->ww_win));
111 while (bpeekc() < 0)
112 bread();
113 if (bgetc() == 'y') {
114 wwputs("Yes", cmdwin);
115 quit++;
116 } else
117 wwputs("\r\n", cmdwin);
118}
119
708ccf0a
EW
120struct ww *
121openwin(nrow, label)
122char *label;
123{
124 register struct ww *w;
125
8c4fb896 126 if ((w = wwopen(WW_NONE, 0, nrow, WCols, 1, 0)) == 0)
708ccf0a 127 return 0;
708ccf0a
EW
128 wwframe(w);
129 wwlabel(w, label, WINVERSE);
8c4fb896 130 wwsetcurwin(w);
708ccf0a
EW
131 return w;
132}
133
b4be6cd6 134waitnl(w)
708ccf0a
EW
135register struct ww *w;
136{
8c4fb896 137 wwsetcurwin(w);
708ccf0a
EW
138 wwprintf(w, "\r\nType return to continue: ");
139 wwsetcursor(WCurRow(w->ww_win), WCurCol(w->ww_win));
b4be6cd6 140 while (bgetc() < 0)
708ccf0a 141 bread();
b4be6cd6
EW
142}
143
144closewin(w)
145register struct ww *w;
146{
708ccf0a 147 wwclose(w);
8c4fb896 148 wwsetcurwin(cmdwin);
708ccf0a 149}