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

Diff for /src/usr.bin/mg/line.c between version 1.59 and 1.60

version 1.59, 2017/09/09 13:10:28 version 1.60, 2018/07/12 12:38:56
Line 18 
Line 18 
  */   */
   
 #include <sys/queue.h>  #include <sys/queue.h>
   #include <ctype.h>
 #include <limits.h>  #include <limits.h>
 #include <signal.h>  #include <signal.h>
 #include <stdio.h>  #include <stdio.h>
Line 511 
Line 512 
 lreplace(RSIZE plen, char *st)  lreplace(RSIZE plen, char *st)
 {  {
         RSIZE   rlen;   /* replacement length            */          RSIZE   rlen;   /* replacement length            */
         int s;          struct line *lp;
           RSIZE n;
           int s, doto, is_query_capitalised = 0, is_query_allcaps = 0;
           int is_replace_alllower = 0;
           char *repl;
   
         if ((s = checkdirty(curbp)) != TRUE)          if ((s = checkdirty(curbp)) != TRUE)
                 return (s);                  return (s);
Line 520 
Line 525 
                 ewprintf("Buffer is read only");                  ewprintf("Buffer is read only");
                 return (FALSE);                  return (FALSE);
         }          }
   
           if ((repl = strdup(st)) == NULL) {
                   dobeep();
                   ewprintf("out of memory");
                   return (FALSE);
           }
   
         undo_boundary_enable(FFRAND, 0);          undo_boundary_enable(FFRAND, 0);
   
         (void)backchar(FFARG | FFRAND, (int)plen);          (void)backchar(FFARG | FFRAND, (int)plen);
   
           lp = curwp->w_dotp;
           doto = curwp->w_doto;
           n = plen;
   
           is_query_capitalised = isupper((unsigned char)lgetc(lp, doto));
   
           if (is_query_capitalised) {
                   for (n = 0, is_query_allcaps = 1; n < plen && is_query_allcaps;
                       n++) {
                           is_query_allcaps = !isalpha((unsigned char)lgetc(lp,
                               doto)) || isupper((unsigned char)lgetc(lp, doto));
                           doto++;
                           if (doto == llength(lp)) {
                                   doto = 0;
                                   lp = lforw(lp);
                                   n++; /* \n is implicit in the buffer */
                           }
                   }
           }
   
         (void)ldelete(plen, KNONE);          (void)ldelete(plen, KNONE);
   
         rlen = strlen(st);          rlen = strlen(repl);
         region_put_data(st, rlen);          for (n = 0, is_replace_alllower = 1; n < rlen && is_replace_alllower;
               n++)
                   is_replace_alllower = !isupper((unsigned char)repl[n]);
   
           if (is_replace_alllower) {
                   if (is_query_allcaps) {
                           for (n = 0; n < rlen; n++)
                                   repl[n] = toupper((unsigned char)repl[n]);
                   } else if (is_query_capitalised) {
                           repl[0] = toupper((unsigned char)repl[0]);
                   }
           }
   
           region_put_data(repl, rlen);
         lchange(WFFULL);          lchange(WFFULL);
   
         undo_boundary_enable(FFRAND, 1);          undo_boundary_enable(FFRAND, 1);
   
           free(repl);
         return (TRUE);          return (TRUE);
 }  }
   

Legend:
Removed from v.1.59  
changed lines
  Added in v.1.60