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

Diff for /src/usr.bin/mg/undo.c between version 1.21 and 1.22

version 1.21, 2003/11/09 01:20:32 version 1.22, 2003/11/09 01:44:39
Line 169 
Line 169 
 }  }
   
 static __inline__ int  static __inline__ int
 last_was_boundary(void)  lastrectype(void)
 {  {
         struct undo_rec *rec;          struct undo_rec *rec;
   
         if ((rec = LIST_FIRST(&curwp->w_undo)) != NULL &&          if ((rec = LIST_FIRST(&curwp->w_undo)) != NULL)
             (rec->type == BOUNDARY))                  return (rec->type);
                 return (1);  
         return (0);          return (0);
 }  }
   
Line 183 
Line 182 
 undo_enable(int on)  undo_enable(int on)
 {  {
         int pon = undo_disable_flag;          int pon = undo_disable_flag;
   
         undo_disable_flag = (on == TRUE) ? 0 : 1;          undo_disable_flag = (on == TRUE) ? 0 : 1;
         return (pon ? FALSE : TRUE);          return (pon ? FALSE : TRUE);
 }  }
Line 223 
Line 223 
          */           */
         rec = LIST_FIRST(&curwp->w_undo);          rec = LIST_FIRST(&curwp->w_undo);
         if (rec != NULL) {          if (rec != NULL) {
                 /* this will be hit like, 80% of the time... */  
                 if (rec->type == BOUNDARY)  
                         rec = LIST_NEXT(rec, next);  
                 if (rec->type == INSERT) {                  if (rec->type == INSERT) {
                         if (rec->pos + rec->region.r_size == pos) {                          if (rec->pos + rec->region.r_size == pos) {
                                 rec->region.r_size += reg.r_size;                                  rec->region.r_size += reg.r_size;
Line 243 
Line 240 
         memmove(&rec->region, &reg, sizeof(REGION));          memmove(&rec->region, &reg, sizeof(REGION));
         rec->content = NULL;          rec->content = NULL;
   
         if (!last_was_boundary())          if (lastrectype() != INSERT)
                 undo_add_boundary();                  undo_add_boundary();
   
         LIST_INSERT_HEAD(&curwp->w_undo, rec, next);          LIST_INSERT_HEAD(&curwp->w_undo, rec, next);
         undo_add_boundary();  
   
         return (TRUE);          return (TRUE);
 }  }
Line 298 
Line 294 
   
         region_get_data(&reg, rec->content, reg.r_size);          region_get_data(&reg, rec->content, reg.r_size);
   
           if (lastrectype() != DELETE)
                   undo_add_boundary();
   
         LIST_INSERT_HEAD(&curwp->w_undo, rec, next);          LIST_INSERT_HEAD(&curwp->w_undo, rec, next);
         undo_add_boundary();  
   
         return (TRUE);          return (TRUE);
 }  }
Line 416 
Line 414 
         struct undo_rec *ptr, *nptr;          struct undo_rec *ptr, *nptr;
         int done, rval;          int done, rval;
         LINE *lp;          LINE *lp;
         int offset;          int offset, save;
   
         ptr = curwp->w_undoptr;          ptr = curwp->w_undoptr;
   
Line 450 
Line 448 
                  * Loop while we don't get a boundary specifying we've                   * Loop while we don't get a boundary specifying we've
                  * finished the current action...                   * finished the current action...
                  */                   */
   
                   if (lastrectype() != BOUNDARY)
                           undo_add_boundary();
   
                   save = nobound;
                   nobound = 1;
   
                 done = 0;                  done = 0;
                 do {                  do {
                         /* Unlink the current node from the list */  
                         nptr = LIST_NEXT(ptr, next);  
                         LIST_REMOVE(ptr, next);  
   
                         /*                          /*
                          * Move to where this has to apply                           * Move to where this has to apply
                          *                           *
Line 491 
Line 492 
                         default:                          default:
                                 break;                                  break;
                         }                          }
                         free_undo_record(ptr);  
   
                         /* And move to next record */                          /* And move to next record */
                         ptr = nptr;                          ptr = LIST_NEXT(ptr, next);
                 } while (ptr != NULL && !done);                  } while (ptr != NULL && !done);
   
                   nobound = save;
                   undo_add_boundary();
   
                 ewprintf("Undo!");                  ewprintf("Undo!");
         }          }

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22