1 /* @(#)undodb.c 1.2 04/18/83 2 * 3 * Copyright -C- 1982 Barry S. Roitblat 4 * 5 * 6 * This file contains routines for recording (remembering) database 7 * activity to provide an undo capability for the gremlin picture editor. 8 */ 9 10 #include "gremlin.h" 11 #include "grem2.h" 12 13 /* The following are used to point to the undo database lists */ 14 15 UNELT *unlist, *unback; 16 17 /* imports from point.c */ 18 19 POINT *PTInit(), *PTMakePoint(); 20 21 /* imports from c */ 22 23 extern char *malloc(); 24 extern char *strcpy(); 25 26 /* imports from db1.c */ 27 28 extern DBClearElt(); 29 30 31 UNRembAdd(element, db) 32 ELT *element, *(*db); 33 /* 34 * This routine records an addition to the database by saving 35 * a pointer to the new element 36 */ 37 38 { 39 UNELT *temp; 40 41 temp = (UNELT *) malloc(sizeof(UNELT)); 42 temp->action = ADD; 43 temp->dbase = db; 44 temp->oldelt = NULL; 45 temp->newelt = element; 46 temp->nextun = unlist; 47 unlist = temp; 48 } /* end RembAdd */ 49 50 UNRembDelete(element, db) 51 ELT *element, *(*db); 52 /* 53 * This routine records a deletion from the database by saving 54 * a pointer to the deleted element 55 */ 56 57 { 58 UNELT *temp; 59 60 temp = (UNELT *) malloc(sizeof(UNELT)); 61 temp->action = DELETE; 62 temp->dbase = db; 63 temp->oldelt = element; 64 temp->newelt = NULL; 65 temp->nextun = unlist; 66 unlist = temp; 67 } /* end RembDelete */ 68 69 70 UNRembMod(element, db) 71 ELT *element, *(*db); 72 /* 73 * This routine records a modification to the database. The 74 * element passed to it is the element which will be modified and it 75 * is therefore copied (copying the text and pointlist also) 76 * and save as oldelt. A pointer of the element (which will be 77 * modified) is saved in newelt. 78 */ 79 80 { 81 POINT *pt; 82 UNELT *temp; 83 ELT *hold; 84 85 temp = (UNELT *) malloc(sizeof(UNELT)); 86 temp->action = MOD; 87 temp->dbase = db; 88 temp->newelt = element; 89 temp->oldelt = hold = (ELT *) malloc(sizeof(ELT)); 90 hold->type = element->type; 91 hold->brushf = element->brushf; 92 hold->size = element->size; 93 hold->textpt = malloc((unsigned) strlen(element->textpt) + 1); 94 (void) strcpy(hold->textpt, element->textpt); 95 pt = element->ptlist; 96 hold->ptlist = PTInit(); 97 while ( !Nullpoint(pt) ) 98 { 99 (void) PTMakePoint(pt->x, pt->y, &(hold->ptlist)); 100 pt = PTNextPoint(pt); 101 } /* end while */ 102 temp->nextun = unlist; 103 unlist = temp; 104 } /* end RembMod */ 105 106 UNForget() 107 /* 108 * This routine clears the undo database. The database is copied 109 * into the backup database and elements from the backup database 110 * are deleted and returned to free storage. If nothing is in the undo 111 * database, the backup database is preserved. 112 */ 113 114 { 115 UNELT *temp; 116 117 if (unlist == nullun) return; 118 while (unback != nullun) 119 { 120 temp = unback->nextun; 121 switch (unback->action) 122 { 123 case ADD: free((char *) unback); 124 break; 125 126 case MOD: 127 case DELETE: DBClearElt(unback->oldelt); 128 free((char *) unback); 129 break; 130 } /* end switch */; 131 unback = temp; 132 } /* end while */; 133 unback = unlist; 134 unlist = nullun; 135 } /* end Forget */ 136