forget difference between big and small commands - obsolete with vm.
[minix.git] / commands / yap / help.c
blob2c550253c2c4242569cf2d2d8fb29bbe51d5028c
1 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
3 #ifndef lint
4 static char rcsid[] = "$Header$";
5 #endif
7 #define _HELP_
8 #include "in_all.h"
9 #include "help.h"
10 #include "machine.h"
11 #include "commands.h"
12 #include "keys.h"
13 #include "output.h"
14 #include "prompt.h"
15 #include "main.h"
16 #include "display.h"
17 #include "term.h"
18 #include "options.h"
20 static int h_cnt; /* Count # of lines */
21 static struct state *origin; /* Keep track of startstate */
24 * Print a key sequence.
25 * We arrived at an endstate. The s_next link in the state structure now
26 * leads us from "origin" to the current state, so that we can print the key
27 * sequence easily.
30 STATIC VOID
31 pr_comm() {
32 register struct state *p = origin;
33 register char *pb;
34 register int c;
35 char buf[30];
36 register int i = 0; /* How many characters printed? */
38 pb = buf;
39 for (;;) {
40 c = p->s_char & 0177;
41 if (c < ' ' || c == 0177) {
43 * Will take an extra position
45 i++;
47 *pb++ = c;
48 i++;
49 if (!p->s_match) break;
50 p = p->s_next;
52 do {
53 *pb++ = ' ';
54 } while (++i < 12);
55 *pb = 0;
56 cputline(buf);
60 * Print out a description of the keymap. This is done, by temporarily using
61 * the s_next field in the state structure indicate the state matching the
62 * next character, so that we can walk from "origin" to an endstate.
65 STATIC VOID
66 pr_mach(currstate, back) register struct state *currstate, *back; {
67 struct state *save;
69 while (currstate) {
70 if (interrupt) break;
71 if (back) {
72 save = back->s_next; /* Save original link */
73 back->s_next = currstate;
75 if (!currstate->s_match) {
77 * End state, print command
79 pr_comm();
80 putline(commands[currstate->s_cnt].c_descr);
81 putline("\r\n");
82 if (++h_cnt >= maxpagesize) {
83 ret_to_continue();
84 h_cnt = 0;
87 else pr_mach(currstate->s_match, currstate);
88 currstate = currstate->s_next;
89 if (back) back->s_next = save; /* restore */
90 else origin = currstate;
94 /*ARGSUSED*/
95 int
96 do_help(i) long i; { /* The help command */
98 startcomm = 0;
99 h_cnt = 2;
100 putline("\r\nSummary of yap commands:\r\n");
101 origin = currmap->k_mach;
102 pr_mach(currmap->k_mach, (struct state *) 0);
103 if (h_cnt) {
104 ret_to_continue();
106 if (!hardcopy && scr_info.currentpos) redraw(1);