home *** CD-ROM | disk | FTP | other *** search
- #include "jam.h"
- #include"stdlib.h"
- #include "def.h"
-
- #define UNDO_ON
-
- /* element of undo history
- */
- #define INSERT 1
- #define UPPER 2
- #define LOWER 3
- #define TWIDDLE 4
- #define KILL 5
-
- typedef struct _undo
- {
- int type;
- RSIZE line; /* integer line */
- RSIZE offset; /* offset within line */
- RSIZE size; /* size of insert */
- REGION region; /* undo region */
- } Undo;
-
- /* undo state
- */
- static void rn_(Cache,(RSIZE count));
- static Undo rn_(*updateundo,(BUFFER *bp));
-
- static Undo *updateundo(bp)
- BUFFER *bp;
- {
- #ifdef UNDO_ON
- if (!bp->b_undo)
- bp->b_undo = (void *)calloc(1, sizeof(Undo));
- return((Undo *)bp->b_undo);
- #else
- return ((Undo *)0);
- #endif
- }
-
- void clearUndo(bp)
- BUFFER *bp;
- {
- #ifdef UNDO_ON
- if (bp->b_undo)
- {
- free((void *)bp->b_undo);
- bp->b_undo = (void *)0;
- }
- #endif
- }
- static void Cache(count)
- RSIZE count;
- {
- #ifdef UNDO_ON
- register Undo *undo = (Undo *)curbp->b_undo;
-
- undo->offset = curwp->w_doto;
- undo->line = getlinenum(curbp, curwp->w_dotp);
- undo->size = count;
- #endif
- }
- void cacheInsert(count)
- RSIZE count;
- {
- #ifdef UNDO_ON
- register Undo *undo = updateundo(curbp);
-
- undo->type = INSERT;
- Cache(count);
- #endif
- }
- void cacheLower(count)
- RSIZE count;
- {
- #ifdef UNDO_ON
- register Undo *undo = updateundo(curbp);
-
- undo->type = LOWER;
- Cache(count);
- #endif
- }
- void cacheUpper(count)
- RSIZE count;
- {
- #ifdef UNDO_ON
- register Undo *undo = updateundo(curbp);
-
- undo->type = UPPER;
- Cache(count);
- #endif
- }
- void cacheTwiddle()
- {
- #ifdef UNDO_ON
- register Undo *undo = updateundo(curbp);
-
- undo->type = TWIDDLE;
- Cache((RSIZE) 0);
- #endif
- }
- void cacheKill()
- {
- /* broken */
- }
-
- /* undo something
- */
- doUndo(f, n)
- int f, n;
- {
- char *nothing = "Nothing to Undo.";
- register Undo *undo;
-
- #ifdef UNDO_ON
- if (!(undo = (Undo *)(curbp->b_undo)))
- {
- clearUndo(curbp); /* silly now */
- ewprintf(nothing);
- }
- else
- {
- /* set dot to correct line
- */
- gotobigline(undo->line);
- curwp->w_doto = (int)undo->offset;
- curwp->w_flag |= WFMOVE|WFEDIT;
- switch(undo->type)
- {
- case INSERT:
- clearUndo(curbp);
- kdelete(); /* clear kill buffer */
- ldelete(undo->size, KFORW);
- break;
- case UPPER:
- clearUndo(curbp);
- lowerword(FFRAND, (int)undo->size);
- break;
- case LOWER:
- clearUndo(curbp);
- upperword(FFRAND, (int)undo->size);
- break;
- case TWIDDLE:
- twiddle(FFRAND, 0);
- clearUndo(curbp);
- break;
- case KILL:
- clearUndo(curbp);
- yank(FFRAND, 0);
- break;
- default:
- clearUndo(curbp);
- break;
- }
- }
- #else
- ewprintf(nothing);
- #endif
- return(TRUE);
- }
-
-
-
-
-