|
|
1.1 root 1: /***************************************************************************
2: * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne. JOVE *
3: * is provided to you without charge, and with no warranty. You may give *
4: * away copies of JOVE, including sources, provided that this notice is *
5: * included in all the files. *
6: ***************************************************************************/
7:
8: #include "jove.h"
9: #include "ctype.h"
10: #include "disp.h"
11:
12: #include <signal.h>
13:
14: void
15: prCTIME()
16: {
17: s_mess(": %f %s", get_time((time_t *) 0, (char *) 0, 0, -1));
18: }
19:
20: void
21: ChrToOct()
22: {
23: int c,
24: slow = NO;
25:
26: c = waitchar(&slow);
27: ins_str(sprint("\\%03o", c), NO);
28: }
29:
30: void
31: StrLength()
32: {
33: static char inquotes[] = "Where are the quotes?";
34: char *first = StrIndex(-1, linebuf, curchar, '"'),
35: *last = StrIndex(1, linebuf, curchar + 1, '"'),
36: c;
37: int numchars = 0;
38:
39: if (first == 0 || last == 0)
40: complain(inquotes);
41: first += 1;
42: while (first < last) {
43: c = *first++;
44: if (c == '\\') {
45: int num;
46:
47: if (!isdigit(*first))
48: first += 1;
49: else {
50: num = 3;
51: while (num-- && isdigit(*first++) && first < last)
52: ;
53: }
54: }
55: numchars += 1;
56: }
57: s_mess("%d characters", numchars);
58: }
59:
60: /* Transpos cur_char with cur_char - 1 */
61:
62: void
63: TransChar()
64: {
65: char before;
66:
67: if (curchar == 0 || (eolp() && curchar == 1))
68: complain((char *) 0); /* BEEP */
69: if (eolp())
70: b_char(1);
71: before = linebuf[curchar - 1];
72: del_char(BACKWARD, 1, NO);
73: f_char(1);
74: insert_c(before, 1);
75: }
76:
77: /* Switch current line with previous one */
78:
79: void
80: TransLines()
81: {
82: daddr old_prev;
83:
84: if (firstp(curline))
85: return;
86: lsave();
87: old_prev = curline->l_prev->l_dline;
88: curline->l_prev->l_dline = curline->l_dline;
89: curline->l_dline = old_prev;
90: getDOT();
91: if (!lastp(curline))
92: line_move(FORWARD, 1, NO);
93: modify();
94: }
95:
96: void
97: Leave()
98: {
99: longjmp(mainjmp, QUIT);
100: }
101:
102: /* If argument is specified, kill that many lines down. Otherwise,
103: if we "appear" to be at the end of a line, i.e. everything to the
104: right of the cursor is white space, we delete the line separator
105: as if we were at the end of the line. */
106:
107: void
108: KillEOL()
109: {
110: Line *line2;
111: int char2;
112: int num = arg_value();
113:
114: if (is_an_arg()) {
115: if (num == 0) { /* Kill to beginning of line */
116: line2 = curline;
117: char2 = 0;
118: } else {
119: line2 = next_line(curline, num);
120: if ((LineDist(curline, line2) < num) || (line2 == curline))
121: char2 = length(line2);
122: else
123: char2 = 0;
124: }
125: } else if (blnkp(&linebuf[curchar])) {
126: line2 = next_line(curline, 1);
127: if (line2 == curline)
128: char2 = length(curline);
129: else
130: char2 = 0;
131: } else {
132: line2 = curline;
133: char2 = length(curline);
134: }
135: reg_kill(line2, char2, 0);
136: }
137:
138: /* kill to beginning of sentence */
139:
140: void
141: KillBos()
142: {
143: negate_arg_value();
144: KillEos();
145: }
146:
147: /* Kill to end of sentence */
148:
149: void
150: KillEos()
151: {
152: Line *line1;
153: int char1;
154:
155: line1 = curline;
156: char1 = curchar;
157: Eos();
158: reg_kill(line1, char1, 1);
159: }
160:
161: void
162: KillExpr()
163: {
164: Line *line1;
165: int char1;
166:
167: line1 = curline;
168: char1 = curchar;
169: FSexpr();
170: reg_kill(line1, char1, 1);
171: }
172:
173: void
174: Yank()
175: {
176: Line *line,
177: *lp;
178: Bufpos *dot;
179:
180: if (killbuf[killptr] == 0)
181: complain("[Nothing to yank!]");
182: lsave();
183: this_cmd = YANKCMD;
184: line = killbuf[killptr];
185: lp = lastline(line);
186: dot = DoYank(line, 0, lp, length(lp), curline, curchar, curbuf);
187: set_mark();
188: SetDot(dot);
189: }
190:
191: void
192: WtModBuf()
193: {
194: if (!ModBufs(NO))
195: message("[No buffers need saving]");
196: else
197: put_bufs(is_an_arg());
198: }
199:
200: void
201: put_bufs(askp)
202: int askp;
203: {
204: register Buffer *oldb = curbuf,
205: *b;
206:
207: for (b = world; b != 0; b = b->b_next) {
208: if (!IsModified(b) || b->b_type != B_FILE)
209: continue;
210: SetBuf(b); /* Make this current Buffer */
211: if (curbuf->b_fname == 0) {
212: char *newname;
213:
214: newname = ask(NullStr, "Buffer \"%s\" needs a file name; type Return to skip: ", b->b_name);
215: if (*newname == 0)
216: continue;
217: setfname(b, newname);
218: }
219: if (askp && (yes_or_no_p("Write %s? ", curbuf->b_fname) == NO))
220: continue;
221: filemunge(curbuf->b_fname);
222: #if !(defined(MSDOS) || defined(MAC))
223: chk_mtime(curbuf, curbuf->b_fname, "save");
224: #endif
225: file_write(curbuf->b_fname, 0);
226: }
227: SetBuf(oldb);
228: }
229:
230: void
231: ToIndent()
232: {
233: Bol();
234: skip_wht_space();
235: }
236:
237: void
238: skip_wht_space()
239: {
240: register char *cp,
241: c;
242:
243: for (cp = linebuf + curchar; (c = *cp)!='\0'; cp++)
244: if (c != ' ' && c != '\t')
245: break;
246: curchar = cp - linebuf;
247: }
248:
249: /* GoLine -- go to a line, usually wired to goto-line, ESC g or ESC G.
250: If no argument is specified it asks for a line number. */
251: void
252: GoLine()
253: {
254: Line *newline;
255:
256: if (!is_an_arg())
257: set_arg_value(ask_int("Line: ",10));
258: newline = next_line(curbuf->b_first, arg_value() - 1);
259: PushPntp(newline);
260: SetLine(newline);
261: }
262:
263: void
264: NotModified()
265: {
266: unmodify();
267: }
268:
269: void
270: SetLMargin()
271: {
272: int lmarg = calc_pos(linebuf, curchar);
273:
274: if (lmarg >= RMargin)
275: complain("[Left margin must be left of right margin]");
276: LMargin = lmarg;
277: }
278:
279: void
280: SetRMargin()
281: {
282: int rmarg = calc_pos(linebuf, curchar);
283:
284: if (rmarg <= LMargin)
285: complain("[Right margin must be right of left margin]");
286: RMargin = rmarg;
287: }
288:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.