1 /*- 2 * Copyright (c) 1992 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rodney Ruddock of the University of Guelph. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char sccsid[] = "@(#)k.c 5.2 (Berkeley) 01/23/93"; 13 #endif /* not lint */ 14 15 #include <sys/types.h> 16 17 #include <db.h> 18 #include <regex.h> 19 #include <setjmp.h> 20 #include <stdio.h> 21 #include <string.h> 22 23 #include "ed.h" 24 #include "extern.h" 25 26 /* 27 * This the mark command (k); see ed(1). 28 */ 29 30 void 31 set_mark(inputt, errnum) 32 FILE *inputt; 33 int *errnum; 34 { 35 int l_mark; 36 37 l_mark = getc(inputt); 38 if (End_default == 1) 39 End = current; 40 if (End == NULL) { 41 strcpy(help_msg, "bad address"); 42 *errnum = -1; 43 ungetc('\n', inputt); 44 return; 45 } 46 start_default = End_default = 0; 47 48 /* 49 * The marks have to be "a" to "z" (inclusive); that is, ye olde 50 * portable character set (ASCII) lower case alphabet. 51 */ 52 if ((l_mark < 97) || (l_mark > 122) || (End == NULL)) { 53 strcpy(help_msg, "illegal mark character"); 54 *errnum = -1; 55 return; 56 } 57 l_mark = l_mark - 97; 58 (mark_matrix[l_mark].address) = End; 59 60 if (rol(inputt, errnum)) 61 return; 62 63 *errnum = 1; 64 } 65 66 67 /* 68 * This gets the address of a marked line. 69 */ 70 LINE * 71 get_mark(errnum) 72 int *errnum; 73 { 74 int l_mark; 75 76 l_mark = getchar(); 77 /* Ditto above comment. */ 78 if ((l_mark < 97) || (l_mark > 122)) { 79 strcpy(help_msg, "illegal mark character"); 80 *errnum = -1; 81 return (NULL); 82 } 83 l_mark = l_mark - 97; 84 *errnum = 0; 85 return (mark_matrix[l_mark].address); 86 } 87 88 89 /* 90 * This is for the restoration of marks during an undo. 91 */ 92 void 93 ku_chk(begi, fini, val) 94 LINE *begi, *fini, *val; 95 { 96 register int l_cnt; 97 LINE *l_midd; 98 99 l_midd = begi; 100 while (l_midd != NULL) { 101 for (l_cnt = 0; l_cnt < 26; l_cnt++) 102 if (mark_matrix[l_cnt].address == l_midd) { 103 u_add_stk(&(mark_matrix[l_cnt].address)); 104 (mark_matrix[l_cnt].address) = val; 105 } 106 if (l_midd == fini) 107 break; 108 l_midd = l_midd->below; 109 } 110 } 111