File: misc.c

package info (click to toggle)
jove 4.16.0.73-5
  • links: PTS
  • area: main
  • in suites: buster
  • size: 2,024 kB
  • sloc: ansic: 27,589; makefile: 454; sh: 49
file content (284 lines) | stat: -rw-r--r-- 5,035 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/**************************************************************************
 * This program is Copyright (C) 1986-2002 by Jonathan Payne.  JOVE is    *
 * provided by Jonathan and Jovehacks without charge and without          *
 * warranty.  You may copy, modify, and/or distribute JOVE, provided that *
 * this notice is included in all the source files and documentation.     *
 **************************************************************************/

#include "jove.h"
#include "jctype.h"
#include "disp.h"
#include "ask.h"
#include "c.h"
#include "delete.h"
#include "insert.h"
#include "extend.h"
#include "fmt.h"
#include "marks.h"
#include "misc.h"
#include "move.h"
#include "paragraph.h"

void
prCTIME()
{
	f_mess(": %f %s", get_time((time_t *)NULL, (char *)NULL, 0, -1));
	stickymsg = YES;
}

void
ChrToOct()
{
	ZXchar	c = ask_ks();

	ins_str(sprint("\\%03o", c));
#ifdef PCNONASCII
	if (c == PCNONASCII) {
		c = waitchar();
		ins_str(sprint("\\%03o", c));
	}
#endif
}

void
StrLength()
{
	static const char	inquotes[] = "Where are the quotes?";
	char	*cp;
	int	numchars = 0;

	for (cp = linebuf+curchar; ; cp--) {
		if (*cp == '"' && (cp == linebuf || cp[-1] != '\\'))
			break;

		if (cp == linebuf)
			complain(inquotes);
	}

	cp += 1;	/* skip opening quote */
	for (;;) {
		switch (*cp++) {
		case '\0':
			complain(inquotes);
			/*NOTREACHED*/
		case '"':
			f_mess("%d characters", numchars);
			stickymsg = YES;
			return;
		case '\\':
			if (!jisdigit(*cp)) {
				if (*cp == '\0')
					complain(inquotes);
				cp += 1;
			} else {
				int	num = 3;

				do cp += 1; while (--num != 0 && jisdigit(*cp));
			}
			break;
		}
		numchars += 1;
	}
}

/* Transpose cur_char with cur_char - 1 */

void
TransChar()
{
	char	before;

	if (curchar == 0 || (eolp() && curchar == 1))
		complain((char *)NULL);	/* BEEP */
	if (eolp())
		b_char(1);
	before = linebuf[curchar - 1];
	del_char(BACKWARD, 1, NO);
	f_char(1);
	insert_c(before, 1);
}

/* Switch current line with previous one */

void
TransLines()
{
	daddr	old_prev;

	if (firstp(curline))
		return;

	lsave();
	/* Exchange l_dline values.
	 * CHEAT: this breaks the buffer abstraction.
	 * The getDOT unfools a few caching mechanisms.
	 */
	old_prev = curline->l_prev->l_dline;
	curline->l_prev->l_dline = curline->l_dline;
	curline->l_dline = old_prev;
	getDOT();

	if (!lastp(curline))
		line_move(FORWARD, 1, NO);
	else
		Eol();	/* can't move to next line, so we do the next best thing */
	modify();
	DOLsave = NO;	/* CHEAT: contents of linebuf need not override l_dline. */
}

/* exit-jove command */

void
Leave()
{
	longjmp(mainjmp, JMP_QUIT);
}

/* If argument is specified, kill that many lines down.  Otherwise,
 * if we "appear" to be at the end of a line, i.e. everything to the
 * right of the cursor is white space, we delete the line separator
 * as if we were at the end of the line.
 */
void
KillEOL()
{
	LinePtr	line2;
	int	char2;
	int	num = arg_value();

	if (is_an_arg()) {
		if (num == 0) {	/* Kill to beginning of line */
			line2 = curline;
			char2 = 0;
		} else {
			line2 = next_line(curline, num);
			if ((LineDist(curline, line2) < num) || (line2 == curline))
				char2 = length(line2);
			else
				char2 = 0;
		}
	} else if (blnkp(&linebuf[curchar])) {
		line2 = next_line(curline, 1);
		if (line2 == curline)
			char2 = length(curline);
		else
			char2 = 0;
	} else {
		line2 = curline;
		char2 = length(curline);
	}
	reg_kill(line2, char2, NO);
}

/* kill to beginning of sentence */

void
KillBos()
{
	negate_arg();
	KillEos();
}

/* Kill to end of sentence */

void
KillEos()
{
	LinePtr	line1;
	int	char1;

	line1 = curline;
	char1 = curchar;
	Eos();
	reg_kill(line1, char1, YES);
}

void
KillExpr()
{
	LinePtr	line1;
	int	char1;

	line1 = curline;
	char1 = curchar;
	FSexpr();
	reg_kill(line1, char1, YES);
}

void
Yank()
{
	LinePtr	line,
		lp;
	Bufpos	*dot;

	if (killbuf[killptr] == NULL)
		complain("[Nothing to yank!]");
	lsave();
	line = killbuf[killptr];
	lp = lastline(line);
	dot = DoYank(line, 0, lp, length(lp), curline, curchar, curbuf);
	set_mark();
	SetDot(dot);
}

void
ToIndent()
{
	Bol();
	skip_wht_space();
}

void
skip_wht_space()
{
	register char	*cp = linebuf + curchar;

	while (jiswhite(*cp))
		cp += 1;
	curchar = cp - linebuf;
}

/* GoLine -- go to a line, usually wired to goto-line, ESC g or ESC G.
 * If no argument is specified it asks for a line number.
 */
void
GoLine()
{
	LinePtr	newline;

	if (!is_an_arg())
		set_arg_value(ask_int("1", "Line: ", 10));
	if (arg_value() < 0)
		newline = prev_line(curbuf->b_last, -1 - arg_value());
	else
		newline = next_line(curbuf->b_first, arg_value() - 1);
	PushPntp(newline);
	SetLine(newline);
}

void
NotModified()
{
	unmodify();
}

void
SetLMargin()
{
	int	lmarg = calc_pos(linebuf, curchar);

	if (lmarg >= RMargin)
		complain("[Left margin must be left of right margin]");
	LMargin = lmarg;
}

void
SetRMargin()
{
	int	rmarg = calc_pos(linebuf, curchar);

	if (rmarg <= LMargin)
		complain("[Right margin must be right of left margin]");
	RMargin = rmarg;
}