1 /* @(#)markcmds.c 1.19 09/07/09 Copyright 1984-2009 J. Schilling */
2 #include <schily/mconfig.h>
3 #ifndef lint
4 static UConst char sccsid[] =
5 "@(#)markcmds.c 1.19 09/07/09 Copyright 1984-2009 J. Schilling";
6 #endif
7 /*
8 * Commands that deal with the mark defining the selection
9 * which is bewteen cursor and mark.
10 *
11 * Copyright (c) 1984-2009 J. Schilling
12 */
13 /*
14 * The contents of this file are subject to the terms of the
15 * Common Development and Distribution License, Version 1.0 only
16 * (the "License"). You may not use this file except in compliance
17 * with the License.
18 *
19 * See the file CDDL.Schily.txt in this distribution for details.
20 * A copy of the CDDL is also available via the Internet at
21 * http://www.opensource.org/licenses/cddl1.txt
22 *
23 * When distributing Covered Code, include this CDDL HEADER in each
24 * file and include the License file CDDL.Schily.txt from this distribution.
25 */
26
27 #include "ved.h"
28
29 EXPORT void setmark __PR((ewin_t *wp, epos_t newmark));
30 EXPORT void resetmark __PR((ewin_t *wp));
31 LOCAL void displaymark __PR((ewin_t *wp));
32 EXPORT void vjumpmark __PR((ewin_t *wp));
33 EXPORT void vexchmarkdot __PR((ewin_t *wp));
34 EXPORT void vclearmark __PR((ewin_t *wp));
35 EXPORT void vsetmark __PR((ewin_t *wp));
36
37 /*
38 * Set the mark to a position and display it
39 */
40 EXPORT void
setmark(wp,newmark)41 setmark(wp, newmark)
42 ewin_t *wp;
43 epos_t newmark;
44 {
45 if (wp->markvalid)
46 resetmark(wp);
47 if (newmark > wp->eof)
48 newmark = wp->eof;
49 wp->mark = newmark;
50 wp->markvalid = 1;
51 displaymark(wp);
52 }
53
54 /*
55 * Clear (unvalidate) the mark and display the change
56 */
57 EXPORT void
resetmark(wp)58 resetmark(wp)
59 ewin_t *wp;
60 {
61 wp->markvalid = 0;
62 displaymark(wp);
63 }
64
65 /*
66 * Go to the mark and make it visible or not - depending on the current
67 * status of the mark.
68 */
69 LOCAL void
displaymark(wp)70 displaymark(wp)
71 ewin_t *wp;
72 {
73 epos_t savedot = wp->dot;
74
75 if (wp->mark > wp->eof)
76 wp->mark = wp->eof;
77 if (wp->mark < wp->window)
78 return;
79 update(wp); /* Needed if the command moved 'dot' */
80 wp->dot = wp->mark;
81
82 setpos(wp);
83 if (setcursor(wp))
84 typescreen(wp, wp->dot, cursor.hp, wp->dot + 1);
85 wp->dot = savedot;
86 setpos(wp);
87 setcursor(wp);
88 }
89
90 /*
91 * Set the cursor to the position of the mark
92 */
93 EXPORT void
vjumpmark(wp)94 vjumpmark(wp)
95 ewin_t *wp;
96 {
97 if (! wp->markvalid) {
98 nomarkmsg(wp);
99 } else {
100 wp->dot = wp->mark;
101 }
102 }
103
104 /*
105 * Exchange the positions of the cursor and the mark
106 */
107 EXPORT void
vexchmarkdot(wp)108 vexchmarkdot(wp)
109 ewin_t *wp;
110 {
111 epos_t savedot = wp->dot;
112
113 if (! wp->markvalid) {
114 nomarkmsg(wp);
115 } else {
116 wp->dot = wp->mark;
117 }
118 setmark(wp, savedot);
119 }
120
121 /*
122 * Clear (unvalidate) the mark
123 */
124 EXPORT void
vclearmark(wp)125 vclearmark(wp)
126 ewin_t *wp;
127 {
128 if (wp->markvalid)
129 resetmark(wp);
130 writemsg(wp, "Mark cleared.");
131 }
132
133 /*
134 * Set the mark to the position of the cursor
135 */
136 EXPORT void
vsetmark(wp)137 vsetmark(wp)
138 ewin_t *wp;
139 {
140 setmark(wp, wp->dot);
141 }
142