xref: /original-bsd/contrib/ed/k.c (revision 2f46dd9e)
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.4 (Berkeley) 03/08/93";
13 #endif /* not lint */
14 
15 #include <sys/types.h>
16 
17 #include <regex.h>
18 #include <setjmp.h>
19 #include <stdio.h>
20 #include <string.h>
21 
22 #ifdef DBI
23 #include <db.h>
24 #endif
25 
26 #include "ed.h"
27 #include "extern.h"
28 
29 /*
30  * This the mark command (k); see ed(1).
31  */
32 
33 void
34 set_mark(inputt, errnum)
35 	FILE *inputt;
36 	int *errnum;
37 {
38 	int l_mark;
39 
40 	l_mark = getc(inputt);
41 	if (End_default == 1)
42 		End = current;
43 	if (End == NULL) {
44 		strcpy(help_msg, "bad address");
45 		*errnum = -1;
46 		ungetc('\n', inputt);
47 		return;
48 	}
49 	Start_default = End_default = 0;
50 
51 	/*
52 	 * The marks have to be "a" to "z" (inclusive); that is, ye olde
53 	 * portable character set (ASCII) lower case alphabet.
54 	 */
55 	if ((l_mark < 97) || (l_mark > 122) || (End == NULL)) {
56 		strcpy(help_msg, "illegal mark character");
57 		*errnum = -1;
58 		return;
59 	}
60 	l_mark = l_mark - 97;
61 	(mark_matrix[l_mark].address) = End;
62 
63 	if (rol(inputt, errnum))
64 		return;
65 
66 	*errnum = 1;
67 }
68 
69 
70 /*
71  * This gets the address of a marked line.
72  */
73 LINE *
74 get_mark(inputt, errnum)
75 	FILE *inputt;
76 	int *errnum;
77 {
78 	int l_mark;
79 
80 	l_mark = getc(inputt);
81 	/* Ditto above comment. */
82 	if ((l_mark < 97) || (l_mark > 122)) {
83 		strcpy(help_msg, "illegal mark character");
84 		*errnum = -1;
85 		return (NULL);
86 	}
87 	l_mark = l_mark - 97;
88 	*errnum = 0;
89 	return (mark_matrix[l_mark].address);
90 }
91 
92 
93 /*
94  * This is for the restoration of marks during an undo.
95  */
96 void
97 ku_chk(begi, fini, val)
98 	LINE *begi, *fini, *val;
99 {
100 	register int l_cnt;
101 	LINE *l_midd;
102 
103 	l_midd = begi;
104 	while (l_midd != NULL) {
105 		for (l_cnt = 0; l_cnt < 26; l_cnt++)
106 			if (mark_matrix[l_cnt].address == l_midd) {
107 				u_add_stk(&(mark_matrix[l_cnt].address));
108 				(mark_matrix[l_cnt].address) = val;
109 			}
110 		if (l_midd == fini)
111 			break;
112 		l_midd = l_midd->below;
113 	}
114 }
115