[BACK]Return to help.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Diff for /src/usr.bin/mg/help.c between version 1.2 and 1.3

version 1.2, 2000/04/13 06:12:15 version 1.3, 2000/09/01 14:59:08
Line 1 
Line 1 
 /* Help functions for Mg 2 */  /*
    * Help functions for Mg 2
    */
   
 #include "def.h"  #include "def.h"
   
Line 7 
Line 9 
 #include "key.h"  #include "key.h"
 #ifndef NO_MACRO  #ifndef NO_MACRO
 #include "macro.h"  #include "macro.h"
 #endif  #endif /* !NO_MACRO */
   
 static int showall      __P((char *ind, KEYMAP *map));  static int      showall         __P((char *ind, KEYMAP *map));
 static VOID findbind    __P((PF, char *, KEYMAP *));  static VOID     findbind        __P((PF, char *, KEYMAP *));
 static VOID bindfound   __P((void));  static VOID     bindfound       __P((void));
   
   static BUFFER  *bp;
   static char     buf[80];        /* used by showall and findbind */
   static char     buf2[128];
   static char    *buf2p;
   
 /*  /*
  * Read a key from the keyboard, and look it up in the keymap.   * Read a key from the keyboard, and look it up in the keymap.
  * Display the name of the function currently bound to the key.   * Display the name of the function currently bound to the key.
Line 20 
Line 27 
 /* ARGSUSED */  /* ARGSUSED */
 int  int
 desckey(f, n)  desckey(f, n)
         int     f, n;          int f, n;
 {  {
         KEYMAP *curmap;          KEYMAP  *curmap;
         PF      funct;          PF       funct;
         char   *pep;          int      c, m, i;
         char    prompt[80];          char    *pep;
         int     c;          char     prompt[80];
         int     m;  
         int     i;  
   
 #ifndef NO_MACRO  #ifndef NO_MACRO
         if (inmacro)          if (inmacro)
                 return TRUE;    /* ignore inside keyboard macro */                  return TRUE;    /* ignore inside keyboard macro */
 #endif  #endif /* !NO_MACRO */
         (VOID) strcpy(prompt, "Describe key briefly: ");          (VOID)strcpy(prompt, "Describe key briefly: ");
         pep = prompt + strlen(prompt);          pep = prompt + strlen(prompt);
         key.k_count = 0;          key.k_count = 0;
         m = curbp->b_nmodes;          m = curbp->b_nmodes;
Line 97 
Line 102 
  * keys and their current bindings, and stores the table in the   * keys and their current bindings, and stores the table in the
  * *help* pop-up buffer.  This lets Mg produce it's own wall chart.   * *help* pop-up buffer.  This lets Mg produce it's own wall chart.
  */   */
 static BUFFER  *bp;  
 static char     buf[80];        /* used by showall and findbind */  
   
 /* ARGSUSED */  /* ARGSUSED */
 int  int
 wallchart(f, n)  wallchart(f, n)
           int f, n;
 {  {
         int             m;          int              m;
         static char     locbind[80] = "Local keybindings for mode ";          static char      locbind[80] = "Local keybindings for mode ";
   
         bp = bfind("*help*", TRUE);          bp = bfind("*help*", TRUE);
         if (bclear(bp) != TRUE)          if (bclear(bp) != TRUE)
                 return FALSE;   /* Clear it out.         */                  /* clear it out */
                   return FALSE;
         for (m = curbp->b_nmodes; m > 0; m--) {          for (m = curbp->b_nmodes; m > 0; m--) {
                 (VOID) strcpy(&locbind[27], curbp->b_modes[m]->p_name);                  (VOID)strcpy(&locbind[27], curbp->b_modes[m]->p_name);
                 (VOID) strcat(&locbind[27], ":");                  (VOID)strcat(&locbind[27], ":");
                 if ((addline(bp, locbind) == FALSE) ||                  if ((addline(bp, locbind) == FALSE) ||
                     (showall(buf, curbp->b_modes[m]->p_map) == FALSE) ||                      (showall(buf, curbp->b_modes[m]->p_map) == FALSE) ||
                     (addline(bp, "") == FALSE))                      (addline(bp, "") == FALSE))
Line 126 
Line 130 
   
 static int  static int
 showall(ind, map)  showall(ind, map)
         char           *ind;          char   *ind;
         KEYMAP         *map;          KEYMAP *map;
 {  {
         MAP_ELEMENT    *ele;          MAP_ELEMENT     *ele;
         int             i;          PF               functp;
         PF              functp;          int              i, last;
         char           *cp;          char            *cp, *cp2;
         char           *cp2;  
         int             last;  
   
         if (addline(bp, "") == FALSE)          if (addline(bp, "") == FALSE)
                 return FALSE;                  return FALSE;
         last = -1;          last = -1;
         for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num];          for (ele = &map->map_element[0];
             ele++) {              ele < &map->map_element[map->map_num]; ele++) {
                 if (map->map_default != rescan && ++last < ele->k_base) {                  if (map->map_default != rescan && ++last < ele->k_base) {
                         cp = keyname(ind, last);                          cp = keyname(ind, last);
                         if (last < ele->k_base - 1) {                          if (last < ele->k_base - 1) {
                                 (VOID) strcpy(cp, " .. ");                                  (VOID)strcpy(cp, " .. ");
                                 cp = keyname(cp + 4, ele->k_base - 1);                                  cp = keyname(cp + 4, ele->k_base - 1);
                         }                          }
                         do {                          do {
                                 *cp++ = ' ';                                  *cp++ = ' ';
                         } while (cp < &buf[16]);                          } while (cp < &buf[16]);
                         (VOID) strcpy(cp, function_name(map->map_default));                          (VOID)strcpy(cp, function_name(map->map_default));
                         if (addline(bp, buf) == FALSE)                          if (addline(bp, buf) == FALSE)
                                 return FALSE;                                  return FALSE;
                 }                  }
Line 167 
Line 169 
                                         do {                                          do {
                                                 *cp++ = ' ';                                                  *cp++ = ' ';
                                         } while (cp < &buf[16]);                                          } while (cp < &buf[16]);
                                         (VOID) strcpy(cp, cp2);                                          (VOID)strcpy(cp, cp2);
                                         if (addline(bp, buf) == FALSE)                                          if (addline(bp, buf) == FALSE)
                                                 return FALSE;                                                  return FALSE;
                                 }                                  }
                         }                          }
                 }                  }
         }          }
         for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num];          for (ele = &map->map_element[0];
             ele++) {              ele < &map->map_element[map->map_num]; ele++) {
                 if (ele->k_prefmap != NULL) {                  if (ele->k_prefmap != NULL) {
                         for (i = ele->k_base;                          for (i = ele->k_base;
                             ele->k_funcp[i - ele->k_base] != prefix; i++) {                              ele->k_funcp[i - ele->k_base] != prefix; i++) {
                                 if (i >= ele->k_num)    /* damaged map */                                  if (i >= ele->k_num)
                                           /* damaged map */
                                         return FALSE;                                          return FALSE;
                         }                          }
                         cp = keyname(ind, i);                          cp = keyname(ind, i);
Line 193 
Line 196 
   
 int  int
 help_help(f, n)  help_help(f, n)
         int             f, n;          int f, n;
 {  {
         KEYMAP         *kp;          KEYMAP  *kp;
         PF              funct;          PF       funct;
   
         if ((kp = name_map("help")) == NULL)          if ((kp = name_map("help")) == NULL)
                 return FALSE;                  return FALSE;
Line 207 
Line 210 
 #ifndef NO_MACRO  #ifndef NO_MACRO
         if (macrodef && macrocount < MAXMACRO)          if (macrodef && macrocount < MAXMACRO)
                 macro[macrocount - 1].m_funct = funct;                  macro[macrocount - 1].m_funct = funct;
 #endif  #endif /* !NO_MACRO */
         return (*funct) (f, n);          return (*funct)(f, n);
 }  }
   
 static char     buf2[128];  
 static char    *buf2p;  
   
 /* ARGSUSED */  /* ARGSUSED */
 int  int
 apropos_command(f, n)  apropos_command(f, n)
         int             f, n;          int f, n;
 {  {
         char           *cp1, *cp2;          BUFFER          *bp;
         char            string[32];          FUNCTNAMES      *fnp;
         FUNCTNAMES     *fnp;          char            *cp1, *cp2;
         BUFFER         *bp;          char             string[32];
   
         if (eread("apropos: ", string, sizeof(string), EFNEW) == ABORT)          if (eread("apropos: ", string, sizeof(string), EFNEW) == ABORT)
                 return ABORT;                  return ABORT;
Line 236 
Line 236 
                         while (*cp2 && *cp1 == *cp2)                          while (*cp2 && *cp1 == *cp2)
                                 cp1++, cp2++;                                  cp1++, cp2++;
                         if (!*cp2) {                          if (!*cp2) {
                                 (VOID) strcpy(buf2, fnp->n_name);                                  (VOID)strcpy(buf2, fnp->n_name);
                                 buf2p = &buf2[strlen(buf2)];                                  buf2p = &buf2[strlen(buf2)];
                                 findbind(fnp->n_funct, buf, map_table[0].p_map);                                  findbind(fnp->n_funct, buf, map_table[0].p_map);
                                 if (addline(bp, buf2) == FALSE)                                  if (addline(bp, buf2) == FALSE)
Line 251 
Line 251 
   
 static VOID  static VOID
 findbind(funct, ind, map)  findbind(funct, ind, map)
         PF              funct;          KEYMAP *map;
         char           *ind;          PF      funct;
         KEYMAP         *map;          char   *ind;
 {  {
         MAP_ELEMENT    *ele;          MAP_ELEMENT     *ele;
         int             i;          int              i, last;
         char           *cp;          char            *cp;
         int             last;  
   
         last = -1;          last = -1;
         for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num];          for (ele = &map->map_element[0];
             ele++) {              ele < &map->map_element[map->map_num]; ele++) {
                 if (map->map_default == funct && ++last < ele->k_base) {                  if (map->map_default == funct && ++last < ele->k_base) {
                         cp = keyname(ind, last);                          cp = keyname(ind, last);
                         if (last < ele->k_base - 1) {                          if (last < ele->k_base - 1) {
                                 (VOID) strcpy(cp, " .. ");                                  (VOID)strcpy(cp, " .. ");
                                 (VOID) keyname(cp + 4, ele->k_base - 1);                                  (VOID)keyname(cp + 4, ele->k_base - 1);
                         }                          }
                         bindfound();                          bindfound();
                 }                  }
Line 280 
Line 279 
                                             strncmp(cp, buf2, strlen(cp)) != 0)                                              strncmp(cp, buf2, strlen(cp)) != 0)
                                                 continue;                                                  continue;
                                 }                                  }
                                 (VOID) keyname(ind, i);                                  (VOID)keyname(ind, i);
                                 bindfound();                                  bindfound();
                         }                          }
                 }                  }
         }          }
         for (ele = &map->map_element[0]; ele < &map->map_element[map->map_num];          for (ele = &map->map_element[0];
             ele++) {              ele < &map->map_element[map->map_num]; ele++) {
                 if (ele->k_prefmap != NULL) {                  if (ele->k_prefmap != NULL) {
                         for (i = ele->k_base;                          for (i = ele->k_base;
                             ele->k_funcp[i - ele->k_base] != prefix; i++) {                              ele->k_funcp[i - ele->k_base] != prefix; i++) {
                                 if (i >= ele->k_num)                                  if (i >= ele->k_num)
                                         return; /* damaged */                                          /* damaged */
                                           return;
                         }                          }
                         cp = keyname(ind, i);                          cp = keyname(ind, i);
                         *cp++ = ' ';                          *cp++ = ' ';
Line 303 
Line 303 
 static VOID  static VOID
 bindfound()  bindfound()
 {  {
   
         if (buf2p < &buf2[32]) {          if (buf2p < &buf2[32]) {
                 do {                  do {
                         *buf2p++ = ' ';                          *buf2p++ = ' ';
Line 312 
Line 311 
                 *buf2p++ = ',';                  *buf2p++ = ',';
                 *buf2p++ = ' ';                  *buf2p++ = ' ';
         }          }
         (VOID) strcpy(buf2p, buf);          (VOID)strcpy(buf2p, buf);
         buf2p += strlen(buf);          buf2p += strlen(buf);
 }  }
 #endif  #endif /* !NO_HELP */

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3