aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

help.c (2349B)


      1 /* copyright (c) 1985 ceriel J.H. jacobs */
      2 
      3 #include "help.h"
      4 #include "commands.h"
      5 #include "display.h"
      6 #include "in_all.h"
      7 #include "keys.h"
      8 #include "machine.h"
      9 #include "main.h"
     10 #include "options.h"
     11 #include "output.h"
     12 #include "prompt.h"
     13 #include "term.h"
     14 
     15 static int           h_cnt;  /* count # of lines */
     16 static struct state *origin; /* keep track of startstate */
     17 
     18 /*
     19  * print a key sequence
     20  * we arrived at an endstate. the s_next link in the state structure now
     21  * leads us from "origin" to the current state, so that we can print the key
     22  * sequence easily
     23  */
     24 
     25 static void
     26 pr_comm(void)
     27 {
     28   struct state *p = origin;
     29   char         *pb;
     30   int           c;
     31   char          buf[30];
     32   int           i = 0; /* how many characters printed? */
     33 
     34   pb = buf;
     35   for (;;) {
     36     c = p->s_char & 0177;
     37     if (c < ' ' || c == 0177) {
     38       /*
     39        * will take an extra position
     40        */
     41       i++;
     42     }
     43     *pb++ = c;
     44     i++;
     45     if (!p->s_match)
     46       break;
     47     p = p->s_next;
     48   }
     49   do {
     50     *pb++ = ' ';
     51   } while (++i < 12);
     52   *pb = 0;
     53   cputline(buf);
     54 }
     55 
     56 /*
     57  * print out a description of the keymap. this is done, by temporarily using
     58  * the s_next field in the state structure indicate the state matching the
     59  * next character, so that we can walk from "origin" to an endstate
     60  */
     61 
     62 static void
     63 pr_mach(struct state *currstate, struct state *back)
     64 {
     65   struct state *save;
     66 
     67   while (currstate) {
     68     if (interrupt)
     69       break;
     70     if (back) {
     71       save         = back->s_next; /* save original link */
     72       back->s_next = currstate;
     73     }
     74     if (!currstate->s_match) {
     75       /*
     76        * end state, print command
     77        */
     78       pr_comm();
     79       putline(commands[currstate->s_cnt].c_descr);
     80       putline("\r\n");
     81       if (++h_cnt >= maxpagesize) {
     82         ret_to_continue();
     83         h_cnt = 0;
     84       }
     85     } else
     86       pr_mach(currstate->s_match, currstate);
     87     currstate = currstate->s_next;
     88     if (back)
     89       back->s_next = save; /* restore */
     90     else
     91       origin = currstate;
     92   }
     93 }
     94 
     95 /* ARGSUSED */
     96 int
     97 do_help(long i)
     98 { /* the help command */
     99   (void)i;
    100 
    101   startcomm = 0;
    102   h_cnt     = 2;
    103   putline("\r\nSummary of yap commands:\r\n");
    104   origin = currmap->k_mach;
    105   pr_mach(currmap->k_mach, (struct state *)0);
    106   if (h_cnt) {
    107     ret_to_continue();
    108   }
    109   if (!hardcopy && scr_info.currentpos)
    110     redraw(1);
    111   return 0;
    112 }