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

Diff for /src/usr.bin/mg/extend.c between version 1.67 and 1.68

version 1.67, 2019/07/11 18:20:18 version 1.68, 2019/07/17 18:18:37
Line 110 
Line 110 
                 if (n1 <= MAPELEDEF && n1 <= n2) {                  if (n1 <= MAPELEDEF && n1 <= n2) {
                         ele--;                          ele--;
                         if ((pfp = calloc(c - ele->k_base + 1,                          if ((pfp = calloc(c - ele->k_base + 1,
                             sizeof(PF))) == NULL) {                              sizeof(PF))) == NULL)
                                 dobeep();                                  return (dobeep_msg("Out of memory"));
                                 ewprintf("Out of memory");  
                                 return (FALSE);  
                         }  
                         nold = ele->k_num - ele->k_base + 1;                          nold = ele->k_num - ele->k_base + 1;
                         for (i = 0; i < nold; i++)                          for (i = 0; i < nold; i++)
                                 pfp[i] = ele->k_funcp[i];                                  pfp[i] = ele->k_funcp[i];
Line 125 
Line 123 
                         ele->k_funcp = pfp;                          ele->k_funcp = pfp;
                 } else if (n2 <= MAPELEDEF) {                  } else if (n2 <= MAPELEDEF) {
                         if ((pfp = calloc(ele->k_num - c + 1,                          if ((pfp = calloc(ele->k_num - c + 1,
                             sizeof(PF))) == NULL) {                              sizeof(PF))) == NULL)
                                 dobeep();                                  return (dobeep_msg("Out of memory"));
                                 ewprintf("Out of memory");  
                                 return (FALSE);  
                         }  
                         nold = ele->k_num - ele->k_base + 1;                          nold = ele->k_num - ele->k_base + 1;
                         for (i = 0; i < nold; i++)                          for (i = 0; i < nold; i++)
                                 pfp[i + n2] = ele->k_funcp[i];                                  pfp[i + n2] = ele->k_funcp[i];
Line 144 
Line 140 
                                         return (FALSE);                                          return (FALSE);
                                 curmap = newmap;                                  curmap = newmap;
                         }                          }
                         if ((pfp = malloc(sizeof(PF))) == NULL) {                          if ((pfp = malloc(sizeof(PF))) == NULL)
                                 dobeep();                                  return (dobeep_msg("Out of memory"));
                                 ewprintf("Out of memory");  
                                 return (FALSE);  
                         }  
                         pfp[0] = funct;                          pfp[0] = funct;
                         for (mep = &curmap->map_element[curmap->map_num];                          for (mep = &curmap->map_element[curmap->map_num];
                             mep > ele; mep--) {                              mep > ele; mep--) {
Line 169 
Line 163 
                         else {                          else {
                                 if ((mp = malloc(sizeof(KEYMAP) +                                  if ((mp = malloc(sizeof(KEYMAP) +
                                     (MAPINIT - 1) * sizeof(struct map_element))) == NULL) {                                      (MAPINIT - 1) * sizeof(struct map_element))) == NULL) {
                                         dobeep();                                          (void)dobeep_msg("Out of memory");
                                         ewprintf("Out of memory");  
                                         ele->k_funcp[c - ele->k_base] =                                          ele->k_funcp[c - ele->k_base] =
                                             curmap->map_default;                                              curmap->map_default;
                                         return (FALSE);                                          return (FALSE);
Line 199 
Line 192 
                                         if ((mp = malloc(sizeof(KEYMAP) +                                          if ((mp = malloc(sizeof(KEYMAP) +
                                             (MAPINIT - 1) *                                              (MAPINIT - 1) *
                                             sizeof(struct map_element))) == NULL) {                                              sizeof(struct map_element))) == NULL) {
                                                 dobeep();                                                  (void)dobeep_msg("Out of memory");
                                                 ewprintf("Out of memory");  
                                                 ele->k_funcp[c - ele->k_base] =                                                  ele->k_funcp[c - ele->k_base] =
                                                     curmap->map_default;                                                      curmap->map_default;
                                                 return (FALSE);                                                  return (FALSE);
Line 226 
Line 218 
                                 curmap = newmap;                                  curmap = newmap;
                         }                          }
                         if ((pfp = calloc(ele->k_num - c + !n2,                          if ((pfp = calloc(ele->k_num - c + !n2,
                             sizeof(PF))) == NULL) {                              sizeof(PF))) == NULL)
                                 dobeep();                                  return (dobeep_msg("Out of memory"));
                                 ewprintf("Out of memory");  
                                 return (FALSE);  
                         }  
                         ele->k_funcp[n1] = NULL;                          ele->k_funcp[n1] = NULL;
                         for (i = n1 + n2; i <= ele->k_num - ele->k_base; i++)                          for (i = n1 + n2; i <= ele->k_num - ele->k_base; i++)
                                 pfp[i - n1 - n2] = ele->k_funcp[i];                                  pfp[i - n1 - n2] = ele->k_funcp[i];
Line 250 
Line 240 
                         if (pref_map == NULL) {                          if (pref_map == NULL) {
                                 if ((mp = malloc(sizeof(KEYMAP) + (MAPINIT - 1)                                  if ((mp = malloc(sizeof(KEYMAP) + (MAPINIT - 1)
                                     * sizeof(struct map_element))) == NULL) {                                      * sizeof(struct map_element))) == NULL) {
                                         dobeep();                                          (void)dobeep_msg("Out of memory");
                                         ewprintf("Out of memory");  
                                         ele->k_funcp[c - ele->k_base] =                                          ele->k_funcp[c - ele->k_base] =
                                             curmap->map_default;                                              curmap->map_default;
                                         return (FALSE);                                          return (FALSE);
Line 279 
Line 268 
         int      i;          int      i;
   
         if (curmap->map_max > SHRT_MAX - MAPGROW) {          if (curmap->map_max > SHRT_MAX - MAPGROW) {
                 dobeep();                  (void)dobeep_msg("keymap too large");
                 ewprintf("keymap too large");  
                 return (NULL);                  return (NULL);
         }          }
         if ((mp = malloc(sizeof(KEYMAP) + (curmap->map_max + (MAPGROW - 1)) *          if ((mp = malloc(sizeof(KEYMAP) + (curmap->map_max + (MAPGROW - 1)) *
             sizeof(struct map_element))) == NULL) {              sizeof(struct map_element))) == NULL) {
                 dobeep();                  (void)dobeep_msg("Out of memory");
                 ewprintf("Out of memory");  
                 return (NULL);                  return (NULL);
         }          }
         mp->map_num = curmap->map_num;          mp->map_num = curmap->map_num;
Line 343 
Line 330 
                  * Keystrokes aren't collected. Not hard, but pretty useless.                   * Keystrokes aren't collected. Not hard, but pretty useless.
                  * Would not work for function keys in any case.                   * Would not work for function keys in any case.
                  */                   */
                 dobeep();                  return (dobeep_msg("Can't rebind key in macro"));
                 ewprintf("Can't rebind key in macro");  
                 return (FALSE);  
         }          }
         if (inmacro) {          if (inmacro) {
                 for (s = 0; s < maclcur->l_used - 1; s++) {                  for (s = 0; s < maclcur->l_used - 1; s++) {
Line 383 
Line 368 
                 else if (bufp[0] == '\0')                  else if (bufp[0] == '\0')
                         return (FALSE);                          return (FALSE);
                 if (((funct = name_function(bprompt)) == NULL) ?                  if (((funct = name_function(bprompt)) == NULL) ?
                     (pref_map = name_map(bprompt)) == NULL : funct == NULL) {                      (pref_map = name_map(bprompt)) == NULL : funct == NULL)
                         dobeep();                          return (dobeep_msg("[No match]"));
                         ewprintf("[No match]");  
                         return (FALSE);  
                 }  
         }          }
         return (remap(curmap, c, funct, pref_map));          return (remap(curmap, c, funct, pref_map));
 }  }
Line 512 
Line 495 
         else if (bufp[0] == '\0')          else if (bufp[0] == '\0')
                 return (FALSE);                  return (FALSE);
         (void)strlcat(buf, tmp, sizeof(buf));          (void)strlcat(buf, tmp, sizeof(buf));
         if ((mp = name_map(tmp)) == NULL) {          if ((mp = name_map(tmp)) == NULL)
                 dobeep();                  return (dobeep_msgs("Unknown map ", tmp));
                 ewprintf("Unknown map %s", tmp);  
                 return (FALSE);  
         }  
         if (strlcat(buf, "key: ", sizeof(buf)) >= sizeof(buf))          if (strlcat(buf, "key: ", sizeof(buf)) >= sizeof(buf))
                 return (FALSE);                  return (FALSE);
   
Line 568 
Line 549 
                 }                  }
                 return ((*funct)(f, n));                  return ((*funct)(f, n));
         }          }
         dobeep();          return (dobeep_msg("[No match]"));
         ewprintf("[No match]");  
         return (FALSE);  
 }  }
   
 /*  /*
Line 714 
Line 693 
                 *p = '\0';                  *p = '\0';
         /* we now know that string starts with '(' and ends with ')' */          /* we now know that string starts with '(' and ends with ')' */
         if (regcomp(&regex_buff, "^[(][\t ]*[)]$", REG_EXTENDED)) {          if (regcomp(&regex_buff, "^[(][\t ]*[)]$", REG_EXTENDED)) {
                 dobeep();  
                 ewprintf("Could not compile regex");  
                 regfree(&regex_buff);                  regfree(&regex_buff);
                 return(FALSE);                  return (dobeep_msg("Could not compile regex"));
         }          }
         if (!regexec(&regex_buff, funstr, 0, NULL, 0)) {          if (!regexec(&regex_buff, funstr, 0, NULL, 0)) {
                 dobeep();  
                 ewprintf("No command found");  
                 regfree(&regex_buff);                  regfree(&regex_buff);
                 return(FALSE);                  return (dobeep_msg("No command found"));
         }          }
         /* currently there are no mg commands that don't have a letter */          /* currently there are no mg commands that don't have a letter */
         if (regcomp(&regex_buff, "^[(][\t ]*[A-Za-z-]+[\t ]*[)]$",          if (regcomp(&regex_buff, "^[(][\t ]*[A-Za-z-]+[\t ]*[)]$",
             REG_EXTENDED)) {              REG_EXTENDED)) {
                 dobeep();  
                 ewprintf("Could not compile regex");  
                 regfree(&regex_buff);                  regfree(&regex_buff);
                 return(FALSE);                  return (dobeep_msg("Could not compile regex"));
         }          }
         if (!regexec(&regex_buff, funstr, 0, NULL, 0))          if (!regexec(&regex_buff, funstr, 0, NULL, 0))
                 singlecmd = 1;                  singlecmd = 1;
Line 757 
Line 730 
          * If no extant mg command found, line could be a (define of some kind.           * If no extant mg command found, line could be a (define of some kind.
          * Since no defines exist at the moment, just return.           * Since no defines exist at the moment, just return.
          */           */
         if ((funcp = name_function(cmdp)) == NULL) {          if ((funcp = name_function(cmdp)) == NULL)
                 dobeep();                  return (dobeep_msgs("Unknown command: %s", cmdp));
                 ewprintf("Unknown command: %s", cmdp);  
                 return (FALSE);  
         }  
         numparams = numparams_function(funcp);          numparams = numparams_function(funcp);
         if (numparams == 0) {          if (numparams == 0)
                 dobeep();                  return (dobeep_msgs("Command takes no arguments: %s", cmdp));
                 ewprintf("Command takes no arguments: %s", cmdp);  
                 return (FALSE);  
         }  
   
         /* now find the first argument */          /* now find the first argument */
         p = fendp + 1;          p = fendp + 1;
Line 782 
Line 750 
                                 *p = '\0';      /* terminate arg string */                                  *p = '\0';      /* terminate arg string */
                                 excbuf[0] = '\0';                                  excbuf[0] = '\0';
                                 if (strlcpy(excbuf, cmdp, sizeof(excbuf))                                  if (strlcpy(excbuf, cmdp, sizeof(excbuf))
                                      >= sizeof(excbuf)) {                                       >= sizeof(excbuf))
                                         dobeep();                                          return (dobeep_msg("strlcpy error"));
                                         ewprintf("strlcpy error");  
                                         return (FALSE);  
                                 }  
                                 if (strlcat(excbuf, s, sizeof(excbuf))                                  if (strlcat(excbuf, s, sizeof(excbuf))
                                     >= sizeof(excbuf)) {                                      >= sizeof(excbuf))
                                         dobeep();                                          return (dobeep_msg("strlcpy error"));
                                         ewprintf("strlcpy error");  
                                         return (FALSE);  
                                 }  
                                 if (strlcat(excbuf, argp, sizeof(excbuf))                                  if (strlcat(excbuf, argp, sizeof(excbuf))
                                     >= sizeof(excbuf)) {                                      >= sizeof(excbuf))
                                         dobeep();                                          return (dobeep_msg("strlcpy error"));
                                         ewprintf("strlcpy error");  
                                         return (FALSE);  
                                 }  
                                 excline(excbuf);                                  excline(excbuf);
                                 *p = ' ';       /* so 'for' loop can continue */                                  *p = ' ';       /* so 'for' loop can continue */
                         }                          }
Line 837 
Line 799 
   
         lp = NULL;          lp = NULL;
   
         if (macrodef || inmacro) {          if (macrodef || inmacro)
                 dobeep();                  return (dobeep_msg("Not now!"));
                 ewprintf("Not now!");  
                 return (FALSE);  
         }  
         f = 0;          f = 0;
         n = 1;          n = 1;
         funcp = skipwhite(line);          funcp = skipwhite(line);
Line 867 
Line 827 
                         return (FALSE);                          return (FALSE);
                 n = (int)nl;                  n = (int)nl;
         }          }
         if ((fp = name_function(funcp)) == NULL) {          if ((fp = name_function(funcp)) == NULL)
                 dobeep();                  return (dobeep_msgs("Unknown function: ", funcp));
                 ewprintf("Unknown function: %s", funcp);  
                 return (FALSE);  
         }  
         if (fp == bindtokey || fp == unbindtokey) {          if (fp == bindtokey || fp == unbindtokey) {
                 bind = BINDARG;                  bind = BINDARG;
                 curmap = fundamental_map;                  curmap = fundamental_map;
Line 997 
Line 955 
                 case BINDNEXT:                  case BINDNEXT:
                         lp->l_text[lp->l_used] = '\0';                          lp->l_text[lp->l_used] = '\0';
                         if ((curmap = name_map(lp->l_text)) == NULL) {                          if ((curmap = name_map(lp->l_text)) == NULL) {
                                 dobeep();                                  (void)dobeep_msgs("No such mode: ", lp->l_text);
                                 ewprintf("No such mode: %s", lp->l_text);  
                                 status = FALSE;                                  status = FALSE;
                                 free(lp);                                  free(lp);
                                 goto cleanup;                                  goto cleanup;
Line 1015 
Line 972 
         }          }
         switch (bind) {          switch (bind) {
         default:          default:
                 dobeep();                  (void)dobeep_msg("Bad args to set key");
                 ewprintf("Bad args to set key");  
                 status = FALSE;                  status = FALSE;
                 break;                  break;
         case BINDDO:          case BINDDO:

Legend:
Removed from v.1.67  
changed lines
  Added in v.1.68