Commit | Line | Data |
---|---|---|
09a0104b BJ |
1 | #include "ex.h" |
2 | /* | |
3 | * Ex - a text editor | |
4 | * Bill Joy UCB June/August 1977 | |
5 | */ | |
6 | ||
7 | int getcopy(); | |
8 | ||
9 | move() | |
10 | { | |
11 | register int *adt; | |
12 | ||
13 | if (Command[0] == 'M') { | |
14 | setdot1(); | |
15 | markpr(addr2 == dot ? addr1 - 1 : addr2 + 1); | |
16 | } else | |
17 | setdot(); | |
18 | nonzero(); | |
19 | adt = address(); | |
20 | if (adt == 0) | |
21 | error("%s where?|%s requires a trailing address", Command); | |
22 | newline(); | |
23 | move1(Command[0] != 'M', adt); | |
24 | killed(); | |
25 | } | |
26 | ||
27 | int *tad1; | |
28 | ||
29 | move1(cflag, addrt) | |
30 | char cflag; | |
31 | int *addrt; | |
32 | { | |
33 | register int *adt, *ad1, *ad2; | |
34 | int lines; | |
35 | ||
36 | adt = addrt; | |
37 | lines = (addr2 - addr1) + 1; | |
38 | if (cflag) { | |
39 | tad1 = addr1; | |
40 | ad1 = dol; | |
41 | append(getcopy, ad1++); | |
42 | ad2 = dol; | |
43 | } else { | |
44 | ad2 = addr2; | |
45 | for (ad1 = addr1; ad1 <= ad2;) | |
46 | *ad1++ =& ~01; | |
47 | ad1 = addr1; | |
48 | } | |
49 | ad2++; | |
50 | if (adt < ad1) { | |
51 | if (adt + 1 == ad1 && !cflag) | |
52 | error("That move would do nothing!"); | |
53 | dot = adt + (ad2 - ad1); | |
54 | if (++adt != ad1) { | |
55 | reverse(adt, ad1); | |
56 | reverse(ad1, ad2); | |
57 | reverse(adt, ad2); | |
58 | } | |
59 | } else if (adt >= ad2) { | |
60 | dot = adt++; | |
61 | reverse(ad1, ad2); | |
62 | reverse(ad2, adt); | |
63 | reverse(ad1, adt); | |
64 | } else | |
65 | error("Move to a moved line"); | |
66 | change(); | |
67 | if (!inglobal) | |
68 | if (cflag) { | |
69 | undap1 = addrt + 1; | |
70 | undap2 = undap1 + lines; | |
71 | deletenone(); | |
72 | } else { | |
73 | undkind = UNDMOVE; | |
74 | undap1 = addr1; | |
75 | undap2 = addr2; | |
76 | unddel = addrt; | |
77 | unddol = dol; | |
78 | } | |
79 | } | |
80 | ||
81 | reverse(a1, a2) | |
82 | register int *a1, *a2; | |
83 | { | |
84 | register int t; | |
85 | ||
86 | for (;;) { | |
87 | t = *--a2; | |
88 | if (a2 <= a1) | |
89 | return; | |
90 | *a2 = *a1; | |
91 | *a1++ = t; | |
92 | } | |
93 | } | |
94 | ||
95 | getcopy() | |
96 | { | |
97 | if (tad1 > addr2) | |
98 | return (EOF); | |
99 | getline(*tad1++); | |
100 | return (0); | |
101 | } | |
102 | ||
103 | getPUT() | |
104 | { | |
105 | if (tad1 > unddol) | |
106 | return (EOF); | |
107 | getline(*tad1++); | |
108 | tad1++; | |
109 | return (0); | |
110 | } | |
111 | ||
112 | yank() | |
113 | { | |
114 | ||
115 | save12(); | |
116 | undkind = UNDNONE; | |
117 | killed(); | |
118 | } | |
119 | ||
120 | PUT() | |
121 | { | |
122 | register int cnt; | |
123 | ||
124 | cnt = unddol - dol; | |
125 | tad1 = dol + 1; | |
126 | append(getPUT, addr2); | |
127 | netchange(cnt); | |
128 | } |