teco

Check-in [8e111f84f0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Bringup, phase 1: undo. Make some undo stuff private to undo.c
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:8e111f84f09656db408b093982143254ffc4615e82794ff9067a07711f36383b
User & Date: ajv-899-334-8894@vsta.org 2013-12-17 21:36:22
Context
2013-12-17
21:47
Add undo hook for search/replace check-in: 48baaa179d user: ajv-899-334-8894@vsta.org tags: master, trunk
21:36
Bringup, phase 1: undo. Make some undo stuff private to undo.c check-in: 8e111f84f0 user: ajv-899-334-8894@vsta.org tags: master, trunk
2013-12-16
20:06
Bring up some undo infrastructure, make undo generation counting its own API, not based directly on text prompt counting. check-in: 985847f302 user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to defs.h.

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
...
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
...
428
429
430
431
432
433
434

435
436
extern char lastc;	/* last char read */
extern int ttyerr;	/* error return from ioctl */
extern int inp_noterm;	/* nonzero if standard in is not a terminal */
extern int out_noterm;	/* nonzero if standard out is not a term. */
extern jmp_buf xxx;	/* preserved environment for error restart */
extern int terr;	/* local error code */
extern struct qp t_qp;	/* temporary buffer pointer */
extern struct undo
	*undo_head,	/* Start of undo chain of transactions */
	*undo;		/* Current position in undo/redo chain */

/* more temporaries */
extern struct qp aa, bb, cc;

/* temporary bcell */
extern struct buffcell t_bcell;

................................................................................
/* delayed free-list pointer */
extern struct buffcell *dly_freebuff;

/* cell free-list pointer */
extern struct qp *freedcell;

/* get buffcell routine */
extern struct buffcell *get_bcell();

/* get/return data cell routine */
extern struct qp *get_dcell();
extern void free_dcell(struct qp *);

/* the text buffer header */
extern struct qh buff;

/* the q-register headers point to the start of the buffer and registers */
extern struct qh qreg[];	/* for q regs, command, search, file */
................................................................................
extern void vt(int);
extern int do_fb(void);
extern int read_cmdstr(void);
extern void set_term_par(int lines, int cols);
extern void recalc_tsize(int);
extern int backc(struct qp *arg);
extern void rev_undo(void);


#endif /* TE_DEFS_H */







<
<
<







 







|


|







 







>


281
282
283
284
285
286
287



288
289
290
291
292
293
294
...
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
...
425
426
427
428
429
430
431
432
433
434
extern char lastc;	/* last char read */
extern int ttyerr;	/* error return from ioctl */
extern int inp_noterm;	/* nonzero if standard in is not a terminal */
extern int out_noterm;	/* nonzero if standard out is not a term. */
extern jmp_buf xxx;	/* preserved environment for error restart */
extern int terr;	/* local error code */
extern struct qp t_qp;	/* temporary buffer pointer */




/* more temporaries */
extern struct qp aa, bb, cc;

/* temporary bcell */
extern struct buffcell t_bcell;

................................................................................
/* delayed free-list pointer */
extern struct buffcell *dly_freebuff;

/* cell free-list pointer */
extern struct qp *freedcell;

/* get buffcell routine */
extern struct buffcell *get_bcell(void);

/* get/return data cell routine */
extern struct qp *get_dcell(void);
extern void free_dcell(struct qp *);

/* the text buffer header */
extern struct qh buff;

/* the q-register headers point to the start of the buffer and registers */
extern struct qh qreg[];	/* for q regs, command, search, file */
................................................................................
extern void vt(int);
extern int do_fb(void);
extern int read_cmdstr(void);
extern void set_term_par(int lines, int cols);
extern void recalc_tsize(int);
extern int backc(struct qp *arg);
extern void rev_undo(void);
extern void undo_insert(int, int), undo_del(int, int);

#endif /* TE_DEFS_H */

Changes to exec1.c.

720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
...
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
            make_buffer(&qreg[mm]);

            /* find end of reg */
            for (bb.p = qreg[mm].f; bb.p->f != NULL;
                    bb.p = bb.p->f) {
                ;
            }
            bb.c = (colonflag) ? qreg[mm].z % CELLSIZE : 0;

            movenchars(&aa, &bb, ll);

            /* update q-reg char count */
            qreg[mm].z += ll;
        }
        colonflag = 0;
................................................................................
            }
            insert1();			/* start insert */
            cc.p = &t_bcell;	/* point cc to the temp cell */
            cc.c = 0;

            /* copy the char string */
            moveuntil(&cc, &bb, '\0', &ins_count, CELLSIZE-1, 0);
            insert2(ins_count);	/* finish the insert */
            esp->flag1 = 0;		/* consume argument */
            esp->op = OP_START;
        }
        break;

    case CTL('T'):			/* type or input character */
        /* type */







|







 







|







720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
...
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
            make_buffer(&qreg[mm]);

            /* find end of reg */
            for (bb.p = qreg[mm].f; bb.p->f != NULL;
                    bb.p = bb.p->f) {
                ;
            }
            bb.c = (colonflag) ? (qreg[mm].z % CELLSIZE) : 0;

            movenchars(&aa, &bb, ll);

            /* update q-reg char count */
            qreg[mm].z += ll;
        }
        colonflag = 0;
................................................................................
            }
            insert1();			/* start insert */
            cc.p = &t_bcell;	/* point cc to the temp cell */
            cc.c = 0;

            /* copy the char string */
            moveuntil(&cc, &bb, '\0', &ins_count, CELLSIZE-1, 0);
            insert2(ins_count);		/* finish the insert */
            esp->flag1 = 0;		/* consume argument */
            esp->op = OP_START;
        }
        break;

    case CTL('T'):			/* type or input character */
        /* type */

Changes to subs.c.

373
374
375
376
377
378
379



380
381
382
383
384
385
386
...
429
430
431
432
433
434
435



436
437
438
439
440
441
442
    movenchars(&aa, &bb, nchars);	/* copy cell up to dot */
}

/* count is the number of chars added */
void
insert2(int count)
{



    /* put the new cell where the old one was */
    aa.p->b->f = insert_p;
    insert_p->b = aa.p->b;
    insert_p = NULL;

    /* splice rest of buffer to end */
    bb.p->f = aa.p;
................................................................................
        dot -= nchars;

    } else if (dot + nchars > z) {
        /* don't delete beyond end of buffer */
        ERROR(E_POP);
    }




    /* pointer to beginning of area to delete */
    set_pointer(dot, &aa);

    /* and to end */
    set_pointer(dot+nchars, &bb);

    /* update earliest char loc touched */







>
>
>







 







>
>
>







373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
...
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
    movenchars(&aa, &bb, nchars);	/* copy cell up to dot */
}

/* count is the number of chars added */
void
insert2(int count)
{
    /* Record the change */
    undo_insert(dot, count);

    /* put the new cell where the old one was */
    aa.p->b->f = insert_p;
    insert_p->b = aa.p->b;
    insert_p = NULL;

    /* splice rest of buffer to end */
    bb.p->f = aa.p;
................................................................................
        dot -= nchars;

    } else if (dot + nchars > z) {
        /* don't delete beyond end of buffer */
        ERROR(E_POP);
    }

    /* record for undo */
    undo_del(dot, nchars);

    /* pointer to beginning of area to delete */
    set_pointer(dot, &aa);

    /* and to end */
    set_pointer(dot+nchars, &bb);

    /* update earliest char loc touched */

Changes to undo.c.

16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
104
105
106
107
108
109
110










































 *  present in the edit buffer.  When undo->f is not NULL, the
 *  changes described beyond this point are not present in the edit
 *  buffer, because they have been undone.
 */
#include <strings.h>
#include "defs.h"


struct undo *undo, *undo_head;

/* Transaction grouping of undo sets */
static unsigned int grpid;

/*
 * alloc_undo()
 *	Allocate a new "struct undo" entry
 */
struct undo *
get_undo(int op)
{
    struct undo *u = (struct undo *)get_dcell();

    bzero(u, sizeof(struct undo));
    u->op = op;
    u->dot = dot;
    u->grpid = grpid;
    return(u);
}

/*
 * add_undo()
 *	Put a "struct undo" entry onto the undo/redo chain
 */
void
add_undo(struct undo *u)
{
    struct undo *t;

    ASSERT(u->f == NULL);
    ASSERT(u->b == NULL);

................................................................................
    if (undo->grpid != grpid) {
	return;
    }

    /* Ok, advance by one */
    grpid += 1;
}

















































>
|








|






<








|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
 *  present in the edit buffer.  When undo->f is not NULL, the
 *  changes described beyond this point are not present in the edit
 *  buffer, because they have been undone.
 */
#include <strings.h>
#include "defs.h"

/* Current undo position, and head of list of all recorded undo records */
static struct undo *undo, *undo_head;

/* Transaction grouping of undo sets */
static unsigned int grpid;

/*
 * alloc_undo()
 *	Allocate a new "struct undo" entry
 */
static struct undo *
get_undo(int op)
{
    struct undo *u = (struct undo *)get_dcell();

    bzero(u, sizeof(struct undo));
    u->op = op;

    u->grpid = grpid;
    return(u);
}

/*
 * add_undo()
 *	Put a "struct undo" entry onto the undo/redo chain
 */
static void
add_undo(struct undo *u)
{
    struct undo *t;

    ASSERT(u->f == NULL);
    ASSERT(u->b == NULL);

................................................................................
    if (undo->grpid != grpid) {
	return;
    }

    /* Ok, advance by one */
    grpid += 1;
}

/*
 * undo_insert()
 *	Add undo record for insertion of this much text
 */
void
undo_insert(int pos, int nchars)
{
    struct undo *u;

    u = get_undo(UNDO_INS);
    u->dot = pos;
    u->count = nchars;
    add_undo(u);
}

/*
 * undo_del()
 *	Add undo record for deletion of this text
 */
void
undo_del(int pos, int nchars)
{
    struct undo *u;
    struct buffcell *bc;
    struct qp src, dest;

    /* Our undo record */
    u = get_undo(UNDO_INS);
    u->dot = pos;
    u->count = nchars;

    /* Make a snapshot of the deleted chars */
    set_pointer(pos, &src);
    bc = dest.p = get_bcell();
    dest.c = 0;
    movenchars(&src, &dest, nchars);

    /* Record the change */
    u->p = bc;
    add_undo(u);
}

Changes to utils.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
49
50
51
52
53
54
55
56



57
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
..
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "defs.h"

/*
 * routines to handle storage
 * get a buffcell
 * if there are no buffcells available, call malloc for more storage
 */
struct buffcell*
get_bcell()
{
    struct buffcell *p;
    int i;

    if (freebuff == NULL) {
        p = (struct buffcell *) malloc(BLOCKSIZE);
        if (!p) {
................................................................................

/* free a list of buffcells */
void
free_blist(struct buffcell *p)
{
    struct buffcell *t;

    if (p != NULL) {



         /* find end of ret'd list */
        for (t = p; t -> f != NULL; t = t -> f) {

            ;
        }

        /* put ret'd list at head of "free" list */
        t->f = freebuff;
        freebuff = p;
    }
}

/* free a list of buffcells to the "delayed free" list */
void
dly_free_blist(struct buffcell *p)
{
    struct buffcell *t;
................................................................................
    t->f = dly_freebuff;
    dly_freebuff = p;
}

/* get a cell */
/* if there are no cells available, get a buffcell and make more */
struct qp *
get_dcell()
{
    struct qp *t;
    int i;

    if (freedcell == NULL) {
        /* get a buffcell */
        t = freedcell = (struct qp *) get_bcell();







|
|







 







|
>
>
>
|
<
>
|
|

|
|
|
<







 







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67

68
69
70
71
72
73
74
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "defs.h"

/*
 * routines to handle storage
 * get a buffcell
 * if there are no buffcells available, call malloc for more storage
 */
struct buffcell *
get_bcell(void)
{
    struct buffcell *p;
    int i;

    if (freebuff == NULL) {
        p = (struct buffcell *) malloc(BLOCKSIZE);
        if (!p) {
................................................................................

/* free a list of buffcells */
void
free_blist(struct buffcell *p)
{
    struct buffcell *t;

    if (p == NULL) {
	return;
    }

    /* find end of ret'd list */

    for (t = p; t->f != NULL; t = t->f) {
	;
    }

    /* put ret'd list at head of "free" list */
    t->f = freebuff;
    freebuff = p;

}

/* free a list of buffcells to the "delayed free" list */
void
dly_free_blist(struct buffcell *p)
{
    struct buffcell *t;
................................................................................
    t->f = dly_freebuff;
    dly_freebuff = p;
}

/* get a cell */
/* if there are no cells available, get a buffcell and make more */
struct qp *
get_dcell(void)
{
    struct qp *t;
    int i;

    if (freedcell == NULL) {
        /* get a buffcell */
        t = freedcell = (struct qp *) get_bcell();