| 1 |
/************************************************************************** |
| 2 |
* This program is Copyright (C) 1986-2002 by Jonathan Payne. JOVE is * |
| 3 |
* provided by Jonathan and Jovehacks without charge and without * |
| 4 |
* warranty. You may copy, modify, and/or distribute JOVE, provided that * |
| 5 |
* this notice is included in all the source files and documentation. * |
| 6 |
**************************************************************************/ |
| 7 |
|
| 8 |
#include "jove.h" |
| 9 |
#include "jctype.h" |
| 10 |
#include "disp.h" |
| 11 |
#include "ask.h" |
| 12 |
#include "c.h" |
| 13 |
#include "delete.h" |
| 14 |
#include "insert.h" |
| 15 |
#include "extend.h" |
| 16 |
#include "fmt.h" |
| 17 |
#include "marks.h" |
| 18 |
#include "misc.h" |
| 19 |
#include "move.h" |
| 20 |
#include "para.h" |
| 21 |
|
| 22 |
void |
| 23 |
prCTIME(void) |
| 24 |
{ |
| 25 |
f_mess(": %f %s", get_time((time_t *)NULL, (char *)NULL, 0, -1)); |
| 26 |
stickymsg = YES; |
| 27 |
} |
| 28 |
|
| 29 |
void |
| 30 |
ChrToOct(void) |
| 31 |
{ |
| 32 |
ZXchar c = ask_ks(); |
| 33 |
|
| 34 |
ins_str(sprint("\\%03o", c)); |
| 35 |
#ifdef PCNONASCII |
| 36 |
if (c == PCNONASCII) { |
| 37 |
c = waitchar(); |
| 38 |
ins_str(sprint("\\%03o", c)); |
| 39 |
} |
| 40 |
#endif |
| 41 |
} |
| 42 |
|
| 43 |
void |
| 44 |
StrLength(void) |
| 45 |
{ |
| 46 |
static const char inquotes[] = "Where are the quotes?"; |
| 47 |
char *cp; |
| 48 |
int numchars = 0; |
| 49 |
|
| 50 |
for (cp = linebuf+curchar; ; cp--) { |
| 51 |
if (*cp == '"' && (cp == linebuf || cp[-1] != '\\')) |
| 52 |
break; |
| 53 |
|
| 54 |
if (cp == linebuf) { |
| 55 |
complain(inquotes); |
| 56 |
/* NOTREACHED */ |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
cp += 1; /* skip opening quote */ |
| 61 |
for (;;) { |
| 62 |
switch (*cp++) { |
| 63 |
case '\0': |
| 64 |
complain(inquotes); |
| 65 |
/*NOTREACHED*/ |
| 66 |
case '"': |
| 67 |
f_mess("%d characters", numchars); |
| 68 |
stickymsg = YES; |
| 69 |
return; |
| 70 |
case '\\': |
| 71 |
if (!jisdigit(*cp)) { |
| 72 |
if (*cp == '\0') { |
| 73 |
complain(inquotes); |
| 74 |
/* NOTREACHED */ |
| 75 |
} |
| 76 |
cp += 1; |
| 77 |
} else { |
| 78 |
int num = 3; |
| 79 |
|
| 80 |
do cp += 1; while (--num != 0 && jisdigit(*cp)); |
| 81 |
} |
| 82 |
break; |
| 83 |
} |
| 84 |
numchars += 1; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/* Transpose cur_char with cur_char - 1 */ |
| 89 |
|
| 90 |
void |
| 91 |
TransChar(void) |
| 92 |
{ |
| 93 |
char before; |
| 94 |
|
| 95 |
if (curchar == 0 || (eolp() && curchar == 1)) { |
| 96 |
complain((char *)NULL); /* BEEP */ |
| 97 |
/* NOTREACHED */ |
| 98 |
} |
| 99 |
if (eolp()) |
| 100 |
b_char(1); |
| 101 |
before = linebuf[curchar - 1]; |
| 102 |
del_char(BACKWARD, 1, NO); |
| 103 |
f_char(1); |
| 104 |
insert_c(before, 1); |
| 105 |
} |
| 106 |
|
| 107 |
/* Switch current line with previous one */ |
| 108 |
|
| 109 |
void |
| 110 |
TransLines(void) |
| 111 |
{ |
| 112 |
daddr old_prev; |
| 113 |
|
| 114 |
if (firstp(curline)) |
| 115 |
return; |
| 116 |
|
| 117 |
lsave(); |
| 118 |
/* Exchange l_dline values. |
| 119 |
* CHEAT: this breaks the buffer abstraction. |
| 120 |
* The getDOT unfools a few caching mechanisms. |
| 121 |
*/ |
| 122 |
old_prev = curline->l_prev->l_dline; |
| 123 |
curline->l_prev->l_dline = curline->l_dline; |
| 124 |
curline->l_dline = old_prev; |
| 125 |
getDOT(); |
| 126 |
|
| 127 |
if (!lastp(curline)) |
| 128 |
line_move(FORWARD, 1, NO); |
| 129 |
else |
| 130 |
Eol(); /* can't move to next line, so we do the next best thing */ |
| 131 |
modify(); |
| 132 |
DOLsave = NO; /* CHEAT: contents of linebuf need not override l_dline. */ |
| 133 |
} |
| 134 |
|
| 135 |
/* exit-jove command */ |
| 136 |
|
| 137 |
void |
| 138 |
Leave(void) |
| 139 |
{ |
| 140 |
longjmp(mainjmp, JMP_QUIT); |
| 141 |
/* NOTREACHED */ |
| 142 |
} |
| 143 |
|
| 144 |
/* If argument is specified, kill that many lines down. Otherwise, |
| 145 |
* if we "appear" to be at the end of a line, i.e. everything to the |
| 146 |
* right of the cursor is white space, we delete the line separator |
| 147 |
* as if we were at the end of the line. |
| 148 |
*/ |
| 149 |
void |
| 150 |
KillEOL(void) |
| 151 |
{ |
| 152 |
LinePtr line2; |
| 153 |
int char2; |
| 154 |
long num = arg_value(); |
| 155 |
|
| 156 |
if (is_an_arg()) { |
| 157 |
if (num == 0) { /* Kill to beginning of line */ |
| 158 |
line2 = curline; |
| 159 |
char2 = 0; |
| 160 |
} else { |
| 161 |
line2 = next_line(curline, num); |
| 162 |
if ((LineDist(curline, line2) < num) || (line2 == curline)) |
| 163 |
char2 = length(line2); |
| 164 |
else |
| 165 |
char2 = 0; |
| 166 |
} |
| 167 |
} else if (blnkp(&linebuf[curchar])) { |
| 168 |
line2 = next_line(curline, 1); |
| 169 |
if (line2 == curline) |
| 170 |
char2 = length(curline); |
| 171 |
else |
| 172 |
char2 = 0; |
| 173 |
} else { |
| 174 |
line2 = curline; |
| 175 |
char2 = length(curline); |
| 176 |
} |
| 177 |
reg_kill(line2, char2, NO); |
| 178 |
} |
| 179 |
|
| 180 |
/* kill to beginning of sentence */ |
| 181 |
|
| 182 |
void |
| 183 |
KillBos(void) |
| 184 |
{ |
| 185 |
negate_arg(); |
| 186 |
KillEos(); |
| 187 |
} |
| 188 |
|
| 189 |
/* Kill to end of sentence */ |
| 190 |
|
| 191 |
void |
| 192 |
KillEos(void) |
| 193 |
{ |
| 194 |
LinePtr line1; |
| 195 |
int char1; |
| 196 |
|
| 197 |
line1 = curline; |
| 198 |
char1 = curchar; |
| 199 |
Eos(); |
| 200 |
reg_kill(line1, char1, YES); |
| 201 |
} |
| 202 |
|
| 203 |
void |
| 204 |
KillExpr(void) |
| 205 |
{ |
| 206 |
LinePtr line1; |
| 207 |
int char1; |
| 208 |
|
| 209 |
line1 = curline; |
| 210 |
char1 = curchar; |
| 211 |
FSexpr(); |
| 212 |
reg_kill(line1, char1, YES); |
| 213 |
} |
| 214 |
|
| 215 |
void |
| 216 |
Yank(void) |
| 217 |
{ |
| 218 |
LinePtr line, lp; |
| 219 |
const Bufpos *dot; |
| 220 |
|
| 221 |
if (killbuf[killptr] == NULL) { |
| 222 |
complain("[Nothing to yank!]"); |
| 223 |
/* NOTREACHED */ |
| 224 |
} |
| 225 |
lsave(); |
| 226 |
line = killbuf[killptr]; |
| 227 |
lp = lastline(line); |
| 228 |
dot = DoYank(line, 0, lp, length(lp), curline, curchar, curbuf); |
| 229 |
set_mark(); |
| 230 |
SetDot(dot); |
| 231 |
} |
| 232 |
|
| 233 |
void |
| 234 |
ToIndent(void) |
| 235 |
{ |
| 236 |
Bol(); |
| 237 |
skip_wht_space(); |
| 238 |
} |
| 239 |
|
| 240 |
void |
| 241 |
skip_wht_space(void) |
| 242 |
{ |
| 243 |
char *cp = linebuf + curchar; |
| 244 |
|
| 245 |
while (jiswhite(*cp)) |
| 246 |
cp += 1; |
| 247 |
curchar = cp - linebuf; |
| 248 |
} |
| 249 |
|
| 250 |
/* GoLine -- go to a line, usually wired to goto-line, ESC g or ESC G. |
| 251 |
* If no argument is specified it asks for a line number. |
| 252 |
*/ |
| 253 |
void |
| 254 |
GoLine(void) |
| 255 |
{ |
| 256 |
LinePtr newline; |
| 257 |
|
| 258 |
if (!is_an_arg()) |
| 259 |
set_arg_value(ask_long("1", "Line: ", 10)); |
| 260 |
if (arg_value() < 0) |
| 261 |
newline = prev_line(curbuf->b_last, -1 - arg_value()); |
| 262 |
else |
| 263 |
newline = next_line(curbuf->b_first, arg_value() - 1); |
| 264 |
PushPntp(newline); |
| 265 |
SetLine(newline); |
| 266 |
} |
| 267 |
|
| 268 |
void |
| 269 |
NotModified(void) |
| 270 |
{ |
| 271 |
unmodify(); |
| 272 |
} |
| 273 |
|
| 274 |
void |
| 275 |
SetLMargin(void) |
| 276 |
{ |
| 277 |
int lmarg = calc_pos(linebuf, curchar); |
| 278 |
|
| 279 |
if (lmarg >= RMargin) { |
| 280 |
complain("[Left margin must be left of right margin]"); |
| 281 |
/* NOTREACHED */ |
| 282 |
} |
| 283 |
LMargin = lmarg; |
| 284 |
} |
| 285 |
|
| 286 |
void |
| 287 |
SetRMargin(void) |
| 288 |
{ |
| 289 |
int rmarg = calc_pos(linebuf, curchar); |
| 290 |
|
| 291 |
if (rmarg <= LMargin) { |
| 292 |
complain("[Right margin must be right of left margin]"); |
| 293 |
/* NOTREACHED */ |
| 294 |
} |
| 295 |
RMargin = rmarg; |
| 296 |
} |