[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.9 and 1.10

version 1.9, 2002/03/18 01:45:55 version 1.10, 2002/06/20 03:59:15
Line 1 
Line 1 
 /* $OpenBSD$ */  /* $OpenBSD$ */
 /*  /*
  * Copyright (c) 2002 Vincent Labrecque <vincent@openbsd.org>   * Copyright (c) 2002 Vincent Labrecque
  *                                                       All rights reserved.   * All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions   * modification, are permitted provided that the following conditions
Line 251 
Line 251 
          * We try to reuse the last undo record to `compress' things.           * We try to reuse the last undo record to `compress' things.
          */           */
         rec = LIST_FIRST(&curbp->b_undo);          rec = LIST_FIRST(&curbp->b_undo);
         /* this will be hit like, 80% of the time... */          if (rec != NULL) {
         if (rec != NULL && rec->type == BOUNDARY)                  /* this will be hit like, 80% of the time... */
                 rec = LIST_NEXT(rec, next);                  if (rec->type == BOUNDARY)
                           rec = LIST_NEXT(rec, next);
         if ((rec != NULL) &&                  else if (rec->type == INSERT) {
             (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;                                  return TRUE;
                         return TRUE;                          }
                 }                  }
         }          }
   
Line 300 
Line 300 
   
         pos = find_absolute_dot(lp, offset);          pos = find_absolute_dot(lp, offset);
   
         if (offset == llength(lp)) /* if it's a newline... */          if (offset == llength(lp))      /* if it's a newline... */
                 undo_add_boundary();                  undo_add_boundary();
         else if ((rec = LIST_FIRST(&curbp->b_undo)) != NULL) {          else if ((rec = LIST_FIRST(&curbp->b_undo)) != NULL) {
                 /*                  /*
                  * Separate this command from the previous one if we're not                   * Separate this command from the previous one if we're not
                  * just before the previous record...                   * just before the previous record...
                  */                   */
                 if (rec->type == DELETE){                  if (rec->type == DELETE) {
                         if (rec->pos - rec->region.r_size != pos)                          if (rec->pos - rec->region.r_size != pos)
                                 undo_add_boundary();                                  undo_add_boundary();
                 } else if (rec->type != BOUNDARY)                  } else if (rec->type != BOUNDARY)
Line 395 
Line 395 
         bclear(bp);          bclear(bp);
         popbuf(bp);          popbuf(bp);
   
         for (wp = wheadp; wp != NULL; wp = wp->w_wndp)          for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
                 if (wp->w_bufp == bp) {                  if (wp->w_bufp == bp) {
                         wp->w_dotp = bp->b_linep;                          wp->w_dotp = bp->b_linep;
                         wp->w_doto = 0;                          wp->w_doto = 0;
                 }                  }
           }
   
         num = 0;          num = 0;
         for (rec = LIST_FIRST(&curbp->b_undo); rec != NULL;          for (rec = LIST_FIRST(&curbp->b_undo); rec != NULL;
Line 412 
Line 413 
                     (rec->type == CHANGE) ? "CHANGE":                      (rec->type == CHANGE) ? "CHANGE":
                     (rec->type == BOUNDARY) ? "----" : "UNKNOWN",                      (rec->type == BOUNDARY) ? "----" : "UNKNOWN",
                     rec->pos);                      rec->pos);
                 if (rec->type == DELETE || rec->type == CHANGE) {  
   
                   if (rec->type == DELETE || rec->type == CHANGE) {
                         strlcat(buf, "\"", sizeof buf);                          strlcat(buf, "\"", sizeof buf);
                         snprintf(tmp, sizeof tmp, "%.*s", rec->region.r_size,                          snprintf(tmp, sizeof tmp, "%.*s", rec->region.r_size,
                             rec->content);                              rec->content);
Line 422 
Line 423 
                 }                  }
                 snprintf(tmp, sizeof buf, " [%d]", rec->region.r_size);                  snprintf(tmp, sizeof buf, " [%d]", rec->region.r_size);
                 strlcat(buf, tmp, sizeof buf);                  strlcat(buf, tmp, sizeof buf);
   
                 addlinef(bp, buf);                  addlinef(bp, buf);
         }          }
         return TRUE;          return TRUE;
Line 456 
Line 456 
  *   *
  * Note that the "undo of actionX" have no special meaning. Only when,   * Note that the "undo of actionX" have no special meaning. Only when,
  * say, we undo a deletion, the insertion will be recorded just as if it   * say, we undo a deletion, the insertion will be recorded just as if it
  * was typed on the keyboard. Hence resulting in the inverse operation to be   * was typed on the keyboard. Resulting in the inverse operation being
  * saved in the list.   * saved in the list.
  *   *
  * If undoptr reaches the bottom of the list, or if we moved between   * If undoptr reaches the bottom of the list, or if we moved between
Line 480 
Line 480 
                 ptr = LIST_FIRST(&curbp->b_undo);                  ptr = LIST_FIRST(&curbp->b_undo);
   
         rval = TRUE;          rval = TRUE;
         while (n > 0) {          while (n--) {
                 /* if we have a spurious boundary, free it and move on.... */                  /* if we have a spurious boundary, free it and move on.... */
                 while (ptr && ptr->type == BOUNDARY) {                  while (ptr && ptr->type == BOUNDARY) {
                         nptr = LIST_NEXT(ptr, next);                          nptr = LIST_NEXT(ptr, next);
Line 517 
Line 517 
                          * not move there...                           * not move there...
                          */                           */
                         if (ptr->type != BOUNDARY) {                          if (ptr->type != BOUNDARY) {
                                 if (find_line_offset(ptr->pos,&lp,&offset)                                  if (find_line_offset(ptr->pos, &lp,
                                     == FALSE) {                                      &offset) == FALSE) {
                                         ewprintf("Internal error in Undo!");                                          ewprintf("Internal error in Undo!");
                                         rval = FALSE;                                          rval = FALSE;
                                         break;                                          break;
Line 556 
Line 556 
                 } while (ptr != NULL && !done);                  } while (ptr != NULL && !done);
   
                 ewprintf("Undo!");                  ewprintf("Undo!");
                 n--;  
         }          }
         /*          /*
          * Record where we are. (we have to save our new position at the end           * Record where we are. (we have to save our new position at the end

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10