[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.7 and 1.8

version 1.7, 2001/05/23 21:01:16 version 1.8, 2001/05/23 21:47:33
Line 13 
Line 13 
 #include "macro.h"  #include "macro.h"
 #endif /* !NO_MACRO */  #endif /* !NO_MACRO */
   
 static int      showall         __P((char *ind, KEYMAP *map));  static int      showall(BUFFER *, KEYMAP *, char *);
 static VOID     findbind        __P((PF, char *, KEYMAP *));  static int      findbind(KEYMAP *, PF, char *);
 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 107 
Line 101 
         int f, n;          int f, n;
 {  {
         int              m;          int              m;
         static char      locbind[80] = "Local keybindings for mode ";          BUFFER          *bp;
   
         bp = bfind("*help*", TRUE);          bp = bfind("*help*", TRUE);
         if (bclear(bp) != TRUE)          if (bclear(bp) != TRUE)
                 /* clear it out */                  /* clear it out */
                 return FALSE;                  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);                  if ((addlinef(bp, "Local keybindings for mode %s:",
                 (VOID)strcat(&locbind[27], ":");                                  curbp->b_modes[m]->p_name) == FALSE) ||
                 if ((addline(bp, locbind) == FALSE) ||                      (showall(bp, curbp->b_modes[m]->p_map, "") == FALSE) ||
                     (showall(buf, curbp->b_modes[m]->p_map) == FALSE) ||  
                     (addline(bp, "") == FALSE))                      (addline(bp, "") == FALSE))
                         return FALSE;                          return FALSE;
         }          }
         if ((addline(bp, "Global bindings:") == FALSE) ||          if ((addline(bp, "Global bindings:") == FALSE) ||
             (showall(buf, map_table[0].p_map) == FALSE))              (showall(bp, map_table[0].p_map, "") == FALSE))
                 return FALSE;                  return FALSE;
         return popbuftop(bp);          return popbuftop(bp);
 }  }
   
 static int  static int
 showall(ind, map)  showall(BUFFER *bp, KEYMAP *map, char *prefix)
         char   *ind;  
         KEYMAP *map;  
 {  {
         MAP_ELEMENT     *ele;          KEYMAP *newmap;
         PF               functp;          char buf[80], key[16];
         int              i, last;          PF fun;
         char            *cp, *cp2;          int c;
   
         if (addline(bp, "") == FALSE)          if (addline(bp, "") == FALSE)
                 return FALSE;                  return FALSE;
         last = -1;  
         for (ele = &map->map_element[0];          /* XXX - 256 ? */
             ele < &map->map_element[map->map_num]; ele++) {          for (c = 0; c < 256; c++) {
                 if (map->map_default != rescan && ++last < ele->k_base) {                  fun = doscan(map, c, &newmap);
                         cp = keyname(ind, last);                  if (fun == rescan || fun == selfinsert)
                         if (last < ele->k_base - 1) {                          continue;
                                 (VOID)strcpy(cp, " .. ");                  keyname(buf, c);
                                 cp = keyname(cp + 4, ele->k_base - 1);                  sprintf(key, "%s%s ", prefix, buf);
                         }                  if (fun == NULL) {
                         do {                          if (showall(bp, newmap, key) == FALSE)
                                 *cp++ = ' ';  
                         } while (cp < &buf[16]);  
                         (VOID)strcpy(cp, function_name(map->map_default));  
                         if (addline(bp, buf) == FALSE)  
                                 return FALSE;                                  return FALSE;
                 }                  } else {
                 last = ele->k_num;                          if (addlinef(bp, "%-16s%s", key,
                 for (i = ele->k_base; i <= last; i++) {                                      function_name(fun)) == FALSE)
                         functp = ele->k_funcp[i - ele->k_base];  
                         if (functp != rescan) {  
                                 if (functp != NULL)  
                                         cp2 = function_name(functp);  
                                 else  
                                         cp2 = map_name(ele->k_prefmap);  
                                 if (cp2 != NULL) {  
                                         cp = keyname(ind, i);  
                                         do {  
                                                 *cp++ = ' ';  
                                         } while (cp < &buf[16]);  
                                         (VOID)strcpy(cp, cp2);  
                                         if (addline(bp, buf) == FALSE)  
                                                 return FALSE;  
                                 }  
                         }  
                 }  
         }  
         for (ele = &map->map_element[0];  
             ele < &map->map_element[map->map_num]; ele++) {  
                 if (ele->k_prefmap != NULL) {  
                         for (i = ele->k_base;  
                             ele->k_funcp[i - ele->k_base] != NULL; i++) {  
                                 if (i >= ele->k_num)  
                                         /* damaged map */  
                                         return FALSE;  
                         }  
                         cp = keyname(ind, i);  
                         *cp++ = ' ';  
                         if (showall(cp, ele->k_prefmap) == FALSE)  
                                 return FALSE;                                  return FALSE;
                 }                  }
         }          }
   
         return TRUE;          return TRUE;
 }  }
   
Line 219 
Line 177 
         int f, n;          int f, n;
 {  {
         BUFFER          *bp;          BUFFER          *bp;
         FUNCTNAMES      *fnp;          LIST            *fnames, *el;
         char            *cp1, *cp2;  
         char             string[32];          char             string[32];
   
         if (eread("apropos: ", string, sizeof(string), EFNEW) == ABORT)          if (eread("apropos: ", string, sizeof(string), EFNEW) == ABORT)
Line 229 
Line 186 
         bp = bfind("*help*", TRUE);          bp = bfind("*help*", TRUE);
         if (bclear(bp) == FALSE)          if (bclear(bp) == FALSE)
                 return FALSE;                  return FALSE;
         for (fnp = &functnames[0]; fnp < &functnames[nfunct]; fnp++) {  
                 for (cp1 = fnp->n_name; *cp1; cp1++) {          fnames = complete_function_list("", NULL);
                         cp2 = string;          for (el = fnames; el != NULL; el = el->l_next) {
                         while (*cp2 && *cp1 == *cp2)                  char buf[32];
                                 cp1++, cp2++;                  if (strstr(el->l_name, string) == NULL)
                         if (!*cp2) {                          continue;
                                 (VOID)strcpy(buf2, fnp->n_name);                  buf[0] = '\0';
                                 buf2p = &buf2[strlen(buf2)];                  findbind(name_map("fundamental"),
                                 findbind(fnp->n_funct, buf, map_table[0].p_map);                          name_function(el->l_name), buf);
                                 if (addline(bp, buf2) == FALSE)  
                                         return FALSE;                  if (addlinef(bp, "%-32s%s", el->l_name,  buf) == FALSE) {
                                 break;                          free_file_list(fnames);
                         } else                          return FALSE;
                                 cp1 -= cp2 - string;  
                 }                  }
         }          }
           free_file_list(fnames);
         return popbuftop(bp);          return popbuftop(bp);
 }  }
   
 static VOID  static int
 findbind(funct, ind, map)  findbind(KEYMAP *map, PF fun, char *buf)
         KEYMAP *map;  
         PF      funct;  
         char   *ind;  
 {  {
         MAP_ELEMENT     *ele;          KEYMAP *newmap;
         int              i, last;          PF nfun;
         char            *cp;          char buf2[16], key[16];
           int c;
   
         last = -1;          /* XXX - 256 ? */
         for (ele = &map->map_element[0];          for (c = 0; c < 256; c++) {
             ele < &map->map_element[map->map_num]; ele++) {                  nfun = doscan(map, c, &newmap);
                 if (map->map_default == funct && ++last < ele->k_base) {                  if (nfun == fun) {
                         cp = keyname(ind, last);                          keyname(buf, c);
                         if (last < ele->k_base - 1) {                          return TRUE;
                                 (VOID)strcpy(cp, " .. ");  
                                 (VOID)keyname(cp + 4, ele->k_base - 1);  
                         }  
                         bindfound();  
                 }                  }
                 last = ele->k_num;                  if (nfun == NULL) {
                 for (i = ele->k_base; i <= last; i++) {                          if (findbind(newmap, fun, buf2) == TRUE) {
                         if (funct == ele->k_funcp[i - ele->k_base]) {                                  keyname(key, c);
                                 if (funct == NULL) {                                  sprintf(buf, "%s %s", key, buf2);
                                         cp = map_name(ele->k_prefmap);                                  return TRUE;
                                         if (!cp ||  
                                             strncmp(cp, buf2, strlen(cp)) != 0)  
                                                 continue;  
                                 }  
                                 (VOID)keyname(ind, i);  
                                 bindfound();  
                         }                          }
                 }                  }
         }          }
         for (ele = &map->map_element[0];  
             ele < &map->map_element[map->map_num]; ele++) {  
                 if (ele->k_prefmap != NULL) {  
                         for (i = ele->k_base;  
                             ele->k_funcp[i - ele->k_base] != NULL; i++) {  
                                 if (i >= ele->k_num)  
                                         /* damaged */  
                                         return;  
                         }  
                         cp = keyname(ind, i);  
                         *cp++ = ' ';  
                         findbind(funct, cp, ele->k_prefmap);  
                 }  
         }  
 }  
   
 static VOID          return FALSE;
 bindfound()  
 {  
         if (buf2p < &buf2[32]) {  
                 do {  
                         *buf2p++ = ' ';  
                 } while (buf2p < &buf2[32]);  
         } else {  
                 *buf2p++ = ',';  
                 *buf2p++ = ' ';  
         }  
         (VOID)strcpy(buf2p, buf);  
         buf2p += strlen(buf);  
 }  }
 #endif /* !NO_HELP */  #endif /* !NO_HELP */

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8