Imported Debian patch 20060818-1
Trent Buck
17 years ago
13 | 13 | mandir= $(prefix)/share/man |
14 | 14 | |
15 | 15 | |
16 | CC= gcc | |
17 | CFLAGS= -O2 -pipe | |
18 | CFLAGS+= -g -Wall -Werror | |
19 | LDFLAGS= -lncurses | |
16 | LDFLAGS+= -lncurses | |
20 | 17 | |
21 | 18 | INSTALL= /usr/bin/install |
22 | 19 | STRIP= /usr/bin/strip |
0 | /* $OpenBSD: basic.c,v 1.24 2006/06/01 09:45:05 kjell Exp $ */ | |
0 | /* $OpenBSD: basic.c,v 1.26 2006/07/25 08:27:09 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain */ |
3 | 3 | |
41 | 41 | return (forwchar(f, -n)); |
42 | 42 | while (n--) { |
43 | 43 | if (curwp->w_doto == 0) { |
44 | if ((lp = lback(curwp->w_dotp)) == curbp->b_linep) { | |
44 | if ((lp = lback(curwp->w_dotp)) == curbp->b_headp) { | |
45 | 45 | if (!(f & FFRAND)) |
46 | 46 | ewprintf("Beginning of buffer"); |
47 | 47 | return (FALSE); |
82 | 82 | while (n--) { |
83 | 83 | if (curwp->w_doto == llength(curwp->w_dotp)) { |
84 | 84 | curwp->w_dotp = lforw(curwp->w_dotp); |
85 | if (curwp->w_dotp == curbp->b_linep) { | |
85 | if (curwp->w_dotp == curbp->b_headp) { | |
86 | 86 | curwp->w_dotp = lback(curwp->w_dotp); |
87 | 87 | if (!(f & FFRAND)) |
88 | 88 | ewprintf("End of buffer"); |
106 | 106 | gotobob(int f, int n) |
107 | 107 | { |
108 | 108 | (void) setmark(f, n); |
109 | curwp->w_dotp = lforw(curbp->b_linep); | |
109 | curwp->w_dotp = bfirstlp(curbp); | |
110 | 110 | curwp->w_doto = 0; |
111 | 111 | curwp->w_flag |= WFFULL; |
112 | 112 | curwp->w_dotline = 1; |
122 | 122 | gotoeob(int f, int n) |
123 | 123 | { |
124 | 124 | (void) setmark(f, n); |
125 | curwp->w_dotp = lback(curbp->b_linep); | |
125 | curwp->w_dotp = blastlp(curbp); | |
126 | 126 | curwp->w_doto = llength(curwp->w_dotp); |
127 | 127 | curwp->w_dotline = curwp->w_bufp->b_lines; |
128 | 128 | curwp->w_flag |= WFFULL; |
144 | 144 | |
145 | 145 | if (n < 0) |
146 | 146 | return (backline(f | FFRAND, -n)); |
147 | if ((dlp = curwp->w_dotp) == curbp->b_linep) | |
147 | if ((dlp = curwp->w_dotp) == curbp->b_headp) | |
148 | 148 | return(TRUE); |
149 | 149 | if ((lastflag & CFCPCN) == 0) /* Fix goal. */ |
150 | 150 | setgoal(); |
153 | 153 | return (TRUE); |
154 | 154 | while (n--) { |
155 | 155 | dlp = lforw(dlp); |
156 | if (dlp == curbp->b_linep) { | |
156 | if (dlp == curbp->b_headp) { | |
157 | 157 | curwp->w_dotp = lback(dlp); |
158 | 158 | curwp->w_doto = llength(curwp->w_dotp); |
159 | 159 | curwp->w_flag |= WFMOVE; |
187 | 187 | setgoal(); |
188 | 188 | thisflag |= CFCPCN; |
189 | 189 | dlp = curwp->w_dotp; |
190 | while (n-- && lback(dlp) != curbp->b_linep) { | |
190 | while (n-- && lback(dlp) != curbp->b_headp) { | |
191 | 191 | dlp = lback(dlp); |
192 | 192 | curwp->w_dotline--; |
193 | 193 | } |
270 | 270 | n *= curwp->w_ntrows; /* to lines. */ |
271 | 271 | #endif |
272 | 272 | lp = curwp->w_linep; |
273 | while (n-- && lforw(lp) != curbp->b_linep) { | |
273 | while (n-- && lforw(lp) != curbp->b_headp) { | |
274 | 274 | lp = lforw(lp); |
275 | 275 | curwp->w_dotline++; |
276 | 276 | } |
277 | 277 | curwp->w_linep = lp; |
278 | 278 | curwp->w_flag |= WFFULL; |
279 | 279 | /* if in current window, don't move dot */ |
280 | for (n = curwp->w_ntrows; n-- && lp != curbp->b_linep; lp = lforw(lp)) | |
280 | for (n = curwp->w_ntrows; n-- && lp != curbp->b_headp; lp = lforw(lp)) | |
281 | 281 | if (lp == curwp->w_dotp) |
282 | 282 | return (TRUE); |
283 | 283 | curwp->w_dotp = curwp->w_linep; |
310 | 310 | n *= curwp->w_ntrows; /* to lines. */ |
311 | 311 | #endif |
312 | 312 | lp = curwp->w_linep; |
313 | while (n-- && lback(lp) != curbp->b_linep) { | |
313 | while (n-- && lback(lp) != curbp->b_headp) { | |
314 | 314 | lp = lback(lp); |
315 | 315 | curwp->w_dotline--; |
316 | 316 | } |
317 | 317 | curwp->w_linep = lp; |
318 | 318 | curwp->w_flag |= WFFULL; |
319 | 319 | /* if in current window, don't move dot */ |
320 | for (n = curwp->w_ntrows; n-- && lp != curbp->b_linep; lp = lforw(lp)) | |
320 | for (n = curwp->w_ntrows; n-- && lp != curbp->b_headp; lp = lforw(lp)) | |
321 | 321 | if (lp == curwp->w_dotp) |
322 | 322 | return (TRUE); |
323 | 323 | curwp->w_dotp = curwp->w_linep; |
459 | 459 | if (n == 0) |
460 | 460 | n++; |
461 | 461 | curwp->w_dotline = n; |
462 | clp = lforw(curbp->b_linep); /* "clp" is first line */ | |
462 | clp = lforw(curbp->b_headp); /* "clp" is first line */ | |
463 | 463 | while (--n > 0) { |
464 | if (lforw(clp) == curbp->b_linep) { | |
464 | if (lforw(clp) == curbp->b_headp) { | |
465 | 465 | curwp->w_dotline = curwp->w_bufp->b_lines; |
466 | 466 | break; |
467 | 467 | } |
469 | 469 | } |
470 | 470 | } else { |
471 | 471 | curwp->w_dotline = curwp->w_bufp->b_lines + n; |
472 | clp = lback(curbp->b_linep); /* "clp" is last line */ | |
472 | clp = lback(curbp->b_headp); /* "clp" is last line */ | |
473 | 473 | while (n < 0) { |
474 | if (lback(clp) == curbp->b_linep) { | |
474 | if (lback(clp) == curbp->b_headp) { | |
475 | 475 | curwp->w_dotline = 1; |
476 | 476 | break; |
477 | 477 | } |
0 | /* $OpenBSD: buffer.c,v 1.60 2006/06/01 09:00:50 kjell Exp $ */ | |
0 | /* $OpenBSD: buffer.c,v 1.63 2006/07/25 08:27:09 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
169 | 169 | } |
170 | 170 | if (bp == curbp) |
171 | 171 | curbp = bp1; |
172 | free(bp->b_linep); /* Release header line. */ | |
172 | free(bp->b_headp); /* Release header line. */ | |
173 | 173 | bp2 = NULL; /* Find the header. */ |
174 | 174 | bp1 = bheadp; |
175 | 175 | while (bp1 != bp) { |
306 | 306 | |
307 | 307 | nbytes = 0; /* Count bytes in buf. */ |
308 | 308 | if (bp != blp) { |
309 | lp = lforw(bp->b_linep); | |
310 | while (lp != bp->b_linep) { | |
309 | lp = bfirstlp(bp); | |
310 | while (lp != bp->b_headp) { | |
311 | 311 | nbytes += llength(lp) + 1; |
312 | 312 | lp = lforw(lp); |
313 | 313 | } |
328 | 328 | bp->b_fname) == FALSE) |
329 | 329 | return (NULL); |
330 | 330 | } |
331 | blp->b_dotp = lforw(blp->b_linep); /* put dot at beginning of | |
331 | blp->b_dotp = bfirstlp(blp); /* put dot at beginning of | |
332 | 332 | * buffer */ |
333 | 333 | blp->b_doto = 0; |
334 | 334 | return (blp); /* All done */ |
417 | 417 | lp->l_used = strlen(lp->l_text); |
418 | 418 | va_end(ap); |
419 | 419 | |
420 | bp->b_linep->l_bp->l_fp = lp; /* Hook onto the end */ | |
421 | lp->l_bp = bp->b_linep->l_bp; | |
422 | bp->b_linep->l_bp = lp; | |
423 | lp->l_fp = bp->b_linep; | |
420 | bp->b_headp->l_bp->l_fp = lp; /* Hook onto the end */ | |
421 | lp->l_bp = bp->b_headp->l_bp; | |
422 | bp->b_headp->l_bp = lp; | |
423 | lp->l_fp = bp->b_headp; | |
424 | 424 | bp->b_lines++; |
425 | 425 | |
426 | 426 | return (TRUE); |
522 | 522 | bp->b_marko = 0; |
523 | 523 | bp->b_flag = defb_flag; |
524 | 524 | bp->b_nwnd = 0; |
525 | bp->b_linep = lp; | |
525 | bp->b_headp = lp; | |
526 | 526 | bp->b_nmodes = defb_nmodes; |
527 | 527 | LIST_INIT(&bp->b_undo); |
528 | 528 | bp->b_undoptr = NULL; |
539 | 539 | bp->b_bufp = bheadp; |
540 | 540 | bheadp = bp; |
541 | 541 | bp->b_dotline = bp->b_markline = 1; |
542 | bp->b_lines = 0; | |
542 | bp->b_lines = 1; | |
543 | 543 | |
544 | 544 | return (bp); |
545 | 545 | } |
564 | 564 | (s = eyesno("Buffer modified; kill anyway")) != TRUE) |
565 | 565 | return (s); |
566 | 566 | bp->b_flag &= ~BFCHG; /* Not changed */ |
567 | while ((lp = lforw(bp->b_linep)) != bp->b_linep) | |
567 | while ((lp = lforw(bp->b_headp)) != bp->b_headp) | |
568 | 568 | lfree(lp); |
569 | bp->b_dotp = bp->b_linep; /* Fix dot */ | |
569 | bp->b_dotp = bp->b_headp; /* Fix dot */ | |
570 | 570 | bp->b_doto = 0; |
571 | 571 | bp->b_markp = NULL; /* Invalidate "mark" */ |
572 | 572 | bp->b_marko = 0; |
573 | 573 | bp->b_dotline = bp->b_markline = 1; |
574 | bp->b_lines = 0; | |
574 | bp->b_lines = 1; | |
575 | 575 | |
576 | 576 | return (TRUE); |
577 | 577 | } |
707 | 707 | } |
708 | 708 | /* insert the buffer */ |
709 | 709 | nline = 0; |
710 | clp = lforw(bp->b_linep); | |
710 | clp = bfirstlp(bp); | |
711 | 711 | for (;;) { |
712 | 712 | for (clo = 0; clo < llength(clp); clo++) |
713 | 713 | if (linsert(1, lgetc(clp, clo)) == FALSE) |
714 | 714 | return (FALSE); |
715 | if ((clp = lforw(clp)) == bp->b_linep) | |
715 | if ((clp = lforw(clp)) == bp->b_headp) | |
716 | 716 | break; |
717 | 717 | if (newline(FFRAND, 1) == FALSE) /* fake newline */ |
718 | 718 | return (FALSE); |
725 | 725 | |
726 | 726 | clp = curwp->w_linep; /* cosmetic adjustment */ |
727 | 727 | if (curwp->w_dotp == clp) { /* for offscreen insert */ |
728 | while (nline-- && lback(clp) != curbp->b_linep) | |
728 | while (nline-- && lback(clp) != curbp->b_headp) | |
729 | 729 | clp = lback(clp); |
730 | 730 | curwp->w_linep = clp; /* adjust framing. */ |
731 | 731 | curwp->w_flag |= WFFULL; |
763 | 763 | { |
764 | 764 | struct mgwin *wp; |
765 | 765 | |
766 | bp->b_dotp = lforw(bp->b_linep); | |
766 | bp->b_dotp = bfirstlp(bp); | |
767 | 767 | bp->b_doto = 0; |
768 | 768 | if (bp->b_nwnd != 0) { |
769 | 769 | for (wp = wheadp; wp != NULL; wp = wp->w_wndp) |
0 | mg (20060818-1) unstable; urgency=low | |
1 | ||
2 | * New upstream release | |
3 | * Set the priority to `optional' | |
4 | * Added a menu entry (based on Zile's) | |
5 | * Add mg to list of `editor' alternatives | |
6 | ||
7 | -- Trent Buck <trentbuck@gmail.com> Mon, 28 Aug 2006 16:47:11 +1000 | |
8 | ||
9 | mg (20060709-1) unstable; urgency=low | |
10 | ||
11 | * New upstream release | |
12 | ||
13 | -- Trent Buck <trentbuck@gmail.com> Mon, 10 Jul 2006 04:23:47 +1000 | |
14 | ||
0 | 15 | mg (20060707-1) unstable; urgency=low |
1 | 16 | |
2 | 17 | * Initial release (Closes: #375408) |
0 | 0 | Source: mg |
1 | 1 | Section: editors |
2 | Priority: important | |
2 | Priority: optional | |
3 | 3 | Maintainer: Trent Buck <trentbuck@gmail.com> |
4 | 4 | Build-Depends: debhelper (>= 4.0.0), autotools-dev, libc6-dev, libncurses-dev |
5 | 5 | Standards-Version: 3.6.2 |
0 | #!/bin/sh | |
1 | update-alternatives --install /usr/bin/editor editor /usr/bin/mg 30 \ | |
2 | --slave /usr/share/man/man1/editor.1.gz editor.1.gz /usr/share/man/man1/mg.1.gz | |
3 | ||
4 | #DEBHELPER# |
0 | #!/bin/sh | |
1 | if [ "$1" != "upgrade" ] | |
2 | then | |
3 | update-alternatives --remove editor /usr/bin/mg | |
4 | fi | |
5 | ||
6 | #DEBHELPER# |
22 | 22 | else |
23 | 23 | CFLAGS += -O2 |
24 | 24 | endif |
25 | export CFLAGS | |
26 | ||
27 | CC = gcc | |
28 | export CC | |
25 | 29 | |
26 | 30 | config.status: configure |
27 | 31 | dh_testdir |
65 | 69 | dh_installdocs |
66 | 70 | dh_installexamples |
67 | 71 | # dh_install |
68 | # dh_installmenu | |
72 | dh_installmenu | |
69 | 73 | # dh_installdebconf |
70 | 74 | # dh_installlogrotate |
71 | 75 | # dh_installemacsen |
0 | /* $OpenBSD: def.h,v 1.92 2006/06/01 09:00:50 kjell Exp $ */ | |
0 | /* $OpenBSD: def.h,v 1.95 2006/07/25 08:27:09 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
237 | 237 | * dot and mark in the header, but this is only valid if the buffer |
238 | 238 | * is not being displayed (that is, if "b_nwnd" is 0). The text for |
239 | 239 | * the buffer is kept in a circularly linked list of lines, with |
240 | * a pointer to the header line in "b_linep". | |
240 | * a pointer to the header line in "b_headp". | |
241 | 241 | */ |
242 | 242 | struct buffer { |
243 | 243 | struct list b_list; /* buffer list pointer */ |
244 | 244 | struct buffer *b_altb; /* Link to alternate buffer */ |
245 | 245 | struct line *b_dotp; /* Link to "." line structure */ |
246 | 246 | struct line *b_markp; /* ditto for mark */ |
247 | struct line *b_linep; /* Link to the header line */ | |
247 | struct line *b_headp; /* Link to the header line */ | |
248 | 248 | struct maps_s *b_modes[PBMODES]; /* buffer modes */ |
249 | 249 | int b_doto; /* Offset of "." in above line */ |
250 | 250 | int b_marko; /* ditto for the "mark" */ |
264 | 264 | #define b_bufp b_list.l_p.x_bp |
265 | 265 | #define b_bname b_list.l_name |
266 | 266 | |
267 | /* Some helper macros, in case they ever change to functions */ | |
268 | #define bfirstlp(buf) (lforw((buf)->b_headp)) | |
269 | #define blastlp(buf) (lback((buf)->b_headp)) | |
270 | ||
267 | 271 | #define BFCHG 0x01 /* Changed. */ |
268 | 272 | #define BFBAK 0x02 /* Need to make a backup. */ |
269 | 273 | #ifdef NOTAB |
280 | 284 | enum { |
281 | 285 | INSERT = 1, |
282 | 286 | DELETE, |
283 | BOUNDARY | |
287 | BOUNDARY, | |
288 | MODIFIED | |
284 | 289 | } type; |
285 | 290 | struct region region; |
286 | 291 | int pos; |
306 | 311 | void ttcolor(int); |
307 | 312 | void ttresize(void); |
308 | 313 | |
309 | #ifdef __GLIBC__ | |
310 | volatile int winch_flag; /* sig_atomic_t is just an int */ | |
311 | #else | |
312 | 314 | volatile sig_atomic_t winch_flag; |
313 | #endif | |
314 | 315 | |
315 | 316 | /* ttyio.c */ |
316 | 317 | void ttopen(void); |
603 | 604 | int undo_dump(int, int); |
604 | 605 | int undo_enable(int); |
605 | 606 | void undo_add_boundary(void); |
607 | void undo_add_modified(void); | |
606 | 608 | int undo_add_insert(struct line *, int, int); |
607 | 609 | int undo_add_delete(struct line *, int, int); |
608 | 610 | void undo_no_boundary(int); |
0 | /* $OpenBSD: dired.c,v 1.39 2006/06/01 09:00:50 kjell Exp $ */ | |
0 | /* $OpenBSD: dired.c,v 1.41 2006/07/25 08:27:09 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
247 | 247 | while (n--) { |
248 | 248 | if (llength(curwp->w_dotp) > 0) |
249 | 249 | lputc(curwp->w_dotp, 0, 'D'); |
250 | if (lforw(curwp->w_dotp) != curbp->b_linep) | |
250 | if (lforw(curwp->w_dotp) != curbp->b_headp) | |
251 | 251 | curwp->w_dotp = lforw(curwp->w_dotp); |
252 | 252 | } |
253 | 253 | curwp->w_flag |= WFEDIT | WFMOVE; |
264 | 264 | while (n--) { |
265 | 265 | if (llength(curwp->w_dotp) > 0) |
266 | 266 | lputc(curwp->w_dotp, 0, ' '); |
267 | if (lforw(curwp->w_dotp) != curbp->b_linep) | |
267 | if (lforw(curwp->w_dotp) != curbp->b_headp) | |
268 | 268 | curwp->w_dotp = lforw(curwp->w_dotp); |
269 | 269 | } |
270 | 270 | curwp->w_flag |= WFEDIT | WFMOVE; |
281 | 281 | while (n--) { |
282 | 282 | if (llength(curwp->w_dotp) > 0) |
283 | 283 | lputc(curwp->w_dotp, 0, ' '); |
284 | if (lback(curwp->w_dotp) != curbp->b_linep) | |
284 | if (lback(curwp->w_dotp) != curbp->b_headp) | |
285 | 285 | curwp->w_dotp = lback(curwp->w_dotp); |
286 | 286 | } |
287 | 287 | curwp->w_doto = 0; |
342 | 342 | struct line *lp, *nlp; |
343 | 343 | char fname[NFILEN]; |
344 | 344 | |
345 | for (lp = lforw(curbp->b_linep); lp != curbp->b_linep; lp = nlp) { | |
345 | for (lp = bfirstlp(curbp); lp != curbp->b_headp; lp = nlp) { | |
346 | 346 | nlp = lforw(lp); |
347 | 347 | if (llength(lp) && lgetc(lp, 0) == 'D') { |
348 | 348 | switch (d_makename(lp, fname, sizeof(fname))) { |
643 | 643 | strerror(errno)); |
644 | 644 | return (NULL); |
645 | 645 | } |
646 | bp->b_dotp = lforw(bp->b_linep); /* go to first line */ | |
646 | bp->b_dotp = bfirstlp(bp); | |
647 | 647 | (void)strlcpy(bp->b_fname, dname, sizeof(bp->b_fname)); |
648 | 648 | (void)strlcpy(bp->b_cwd, dname, sizeof(bp->b_cwd)); |
649 | 649 | if ((bp->b_modes[1] = name_mode("dired")) == NULL) { |
0 | /* $OpenBSD: display.c,v 1.29 2006/06/01 09:00:50 kjell Exp $ */ | |
0 | /* $OpenBSD: display.c,v 1.30 2006/07/25 08:22:32 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
424 | 424 | for (i = 0; i < wp->w_ntrows; ++i) { |
425 | 425 | if (lp == wp->w_dotp) |
426 | 426 | goto out; |
427 | if (lp == wp->w_bufp->b_linep) | |
427 | if (lp == wp->w_bufp->b_headp) | |
428 | 428 | break; |
429 | 429 | lp = lforw(lp); |
430 | 430 | } |
448 | 448 | * Find the line. |
449 | 449 | */ |
450 | 450 | lp = wp->w_dotp; |
451 | while (i != 0 && lback(lp) != wp->w_bufp->b_linep) { | |
451 | while (i != 0 && lback(lp) != wp->w_bufp->b_headp) { | |
452 | 452 | --i; |
453 | 453 | lp = lback(lp); |
454 | 454 | } |
474 | 474 | vscreen[i]->v_color = CTEXT; |
475 | 475 | vscreen[i]->v_flag |= (VFCHG | VFHBAD); |
476 | 476 | vtmove(i, 0); |
477 | if (lp != wp->w_bufp->b_linep) { | |
477 | if (lp != wp->w_bufp->b_headp) { | |
478 | 478 | for (j = 0; j < llength(lp); ++j) |
479 | 479 | vtputc(lgetc(lp, j)); |
480 | 480 | lp = lforw(lp); |
0 | /* $OpenBSD: extend.c,v 1.46 2006/06/01 05:34:52 jason Exp $ */ | |
0 | /* $OpenBSD: extend.c,v 1.48 2006/07/25 08:27:09 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
620 | 620 | int s; |
621 | 621 | static char excbuf[128]; |
622 | 622 | |
623 | for (lp = lforw(bp->b_linep); lp != bp->b_linep; lp = lforw(lp)) { | |
623 | for (lp = bfirstlp(bp); lp != bp->b_headp; lp = lforw(lp)) { | |
624 | 624 | if (llength(lp) >= 128) |
625 | 625 | return (FALSE); |
626 | 626 | (void)strncpy(excbuf, ltext(lp), llength(lp)); |
0 | /* $OpenBSD: file.c,v 1.59 2006/06/01 09:00:50 kjell Exp $ */ | |
0 | /* $OpenBSD: file.c,v 1.62 2006/07/25 08:27:09 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
223 | 223 | |
224 | 224 | for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { |
225 | 225 | if (wp->w_bufp == curbp) { |
226 | wp->w_dotp = wp->w_linep = lforw(curbp->b_linep); | |
226 | wp->w_dotp = wp->w_linep = bfirstlp(curbp); | |
227 | 227 | wp->w_doto = 0; |
228 | 228 | wp->w_markp = NULL; |
229 | 229 | wp->w_marko = 0; |
256 | 256 | if (startrow) |
257 | 257 | gotoline(FFARG, startrow); |
258 | 258 | |
259 | undo_add_modified(); | |
259 | 260 | return (status); |
260 | 261 | } |
261 | 262 | |
345 | 346 | oline = curwp->w_dotline; |
346 | 347 | (void)lnewline(); |
347 | 348 | olp = lback(curwp->w_dotp); |
348 | if (olp == curbp->b_linep) { | |
349 | if (olp == curbp->b_headp) { | |
349 | 350 | /* if at end of buffer, create a line to insert before */ |
350 | 351 | (void)lnewline(); |
351 | 352 | curwp->w_dotp = lback(curwp->w_dotp); |
427 | 428 | curwp->w_dotp = olp; |
428 | 429 | curwp->w_doto = opos; |
429 | 430 | curwp->w_dotline = oline; |
430 | if (olp == curbp->b_linep) | |
431 | if (olp == curbp->b_headp) | |
431 | 432 | curwp->w_dotp = lforw(olp); |
432 | 433 | if (newname != NULL) |
433 | 434 | bp->b_flag |= BFCHG | BFBAK; /* Need a backup. */ |
440 | 441 | * pointers in other windows correctly if they are also at the end of |
441 | 442 | * buffer. |
442 | 443 | */ |
443 | lp1 = bp->b_linep; | |
444 | lp1 = bp->b_headp; | |
444 | 445 | if (curwp->w_markp == lp1) { |
445 | 446 | lp2 = curwp->w_dotp; |
446 | 447 | } else { |
0 | /* $OpenBSD: fileio.c,v 1.76 2006/06/29 21:59:08 jason Exp $ */ | |
0 | /* $OpenBSD: fileio.c,v 1.77 2006/07/25 08:22:32 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
114 | 114 | int emptylines = 0; |
115 | 115 | int ret; |
116 | 116 | |
117 | lpend = bp->b_linep; | |
117 | lpend = bp->b_headp; | |
118 | 118 | |
119 | 119 | /* This stuff is to make sure there is exactly one trailing \n at the |
120 | 120 | * end of the buffer. */ |
0 | /* $OpenBSD: grep.c,v 1.30 2006/06/01 05:34:52 jason Exp $ */ | |
0 | /* $OpenBSD: grep.c,v 1.32 2006/07/25 08:27:09 kjell Exp $ */ | |
1 | 1 | /* |
2 | 2 | * Copyright (c) 2001 Artur Grabowski <art@openbsd.org>. |
3 | 3 | * Copyright (c) 2005 Kjell Wooding <kjell@openbsd.org>. |
276 | 276 | else |
277 | 277 | addlinef(bp, "Command finished at %s", timestr); |
278 | 278 | |
279 | bp->b_dotp = lforw(bp->b_linep); /* go to first line */ | |
279 | bp->b_dotp = bfirstlp(bp); | |
280 | 280 | bp->b_modes[0] = name_mode("fundamental"); |
281 | 281 | bp->b_modes[1] = name_mode("compile"); |
282 | 282 | bp->b_nmodes = 1; |
304 | 304 | |
305 | 305 | compile_win = curwp; |
306 | 306 | compile_buffer = curbp; |
307 | last = lback(compile_buffer->b_linep); | |
307 | last = blastlp(compile_buffer); | |
308 | 308 | |
309 | 309 | retry: |
310 | 310 | /* last line is compilation result */ |
347 | 347 | return (TRUE); |
348 | 348 | fail: |
349 | 349 | free(line); |
350 | if (curwp->w_dotp != lback(curbp->b_linep)) { | |
350 | if (curwp->w_dotp != blastlp(curbp)) { | |
351 | 351 | curwp->w_dotp = lforw(curwp->w_dotp); |
352 | 352 | curwp->w_flag |= WFMOVE; |
353 | 353 | goto retry; |
366 | 366 | } |
367 | 367 | curwp = compile_win; |
368 | 368 | curbp = compile_buffer; |
369 | if (curwp->w_dotp == lback(curbp->b_linep)) { | |
369 | if (curwp->w_dotp == blastlp(curbp)) { | |
370 | 370 | ewprintf("No more hits"); |
371 | 371 | return (FALSE); |
372 | 372 | } |
50 | 50 | KEYMAP *name_map(const char *); |
51 | 51 | struct maps_s *name_mode(const char *); |
52 | 52 | PF doscan(KEYMAP *, int, KEYMAP **); |
53 | const char *map_name(KEYMAP *); | |
54 | 53 | void maps_init(void); |
55 | 54 | int maps_add(KEYMAP *, const char *); |
56 | 55 |
0 | /* $OpenBSD: keymap.c,v 1.37 2005/11/18 20:56:53 deraadt Exp $ */ | |
0 | /* $OpenBSD: keymap.c,v 1.39 2006/08/18 00:22:56 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
211 | 211 | gotoeob /* > */ |
212 | 212 | }; |
213 | 213 | |
214 | static PF metalb[] = { | |
215 | gotobop, /* [ */ | |
214 | static PF metabsl[] = { | |
216 | 215 | delwhite, /* \ */ |
217 | gotoeop, /* ] */ | |
216 | rescan, /* ] */ | |
218 | 217 | rescan, /* ^ */ |
219 | 218 | rescan, /* _ */ |
220 | 219 | rescan, /* ` */ |
239 | 238 | upperword, /* u */ |
240 | 239 | backpage, /* v */ |
241 | 240 | copyregion, /* w */ |
242 | extend /* x */ | |
241 | extend, /* x */ | |
242 | rescan, /* y */ | |
243 | rescan, /* z */ | |
244 | gotobop, /* { */ | |
245 | rescan, /* | */ | |
246 | gotoeop /* } */ | |
243 | 247 | }; |
244 | 248 | |
245 | 249 | static PF metatilde[] = { |
268 | 272 | '-', '>', metami, NULL |
269 | 273 | }, |
270 | 274 | { |
271 | '[', 'f', metalb, NULL | |
272 | }, | |
273 | { | |
274 | 'l', 'x', metal, NULL | |
275 | '\\', 'f', metabsl, NULL | |
276 | }, | |
277 | { | |
278 | 'l', '}', metal, NULL | |
275 | 279 | }, |
276 | 280 | { |
277 | 281 | '~', CCHR('?'), metatilde, NULL |
505 | 509 | return (TRUE); |
506 | 510 | } |
507 | 511 | |
508 | const char * | |
509 | map_name(KEYMAP *map) | |
510 | { | |
511 | struct maps_s *mp; | |
512 | ||
513 | for (mp = maps; mp != NULL; mp = mp->p_next) | |
514 | if (mp->p_map == map) | |
515 | return (mp->p_name); | |
516 | return (NULL); | |
517 | } | |
518 | ||
519 | 512 | struct maps_s * |
520 | 513 | name_mode(const char *name) |
521 | 514 | { |
0 | /* $OpenBSD: line.c,v 1.40 2006/06/01 09:00:50 kjell Exp $ */ | |
0 | /* $OpenBSD: line.c,v 1.42 2006/07/25 08:27:09 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
157 | 157 | lp1 = curwp->w_dotp; |
158 | 158 | |
159 | 159 | /* special case for the end */ |
160 | if (lp1 == curbp->b_linep) { | |
160 | if (lp1 == curbp->b_headp) { | |
161 | 161 | struct line *lp2, *lp3; |
162 | 162 | |
163 | 163 | /* now should only happen in empty buffer */ |
247 | 247 | lp1 = curwp->w_dotp; |
248 | 248 | |
249 | 249 | /* special case for the end */ |
250 | if (lp1 == curbp->b_linep) { | |
250 | if (lp1 == curbp->b_headp) { | |
251 | 251 | struct line *lp2, *lp3; |
252 | 252 | |
253 | 253 | /* now should only happen in empty buffer */ |
416 | 416 | dotp = curwp->w_dotp; |
417 | 417 | doto = curwp->w_doto; |
418 | 418 | /* Hit the end of the buffer */ |
419 | if (dotp == curbp->b_linep) | |
419 | if (dotp == curbp->b_headp) | |
420 | 420 | return (FALSE); |
421 | 421 | /* Size of the chunk */ |
422 | 422 | chunk = dotp->l_used - doto; |
425 | 425 | chunk = n; |
426 | 426 | /* End of line, merge */ |
427 | 427 | if (chunk == 0) { |
428 | if (dotp == lback(curbp->b_linep)) | |
429 | /* End of buffer */ | |
428 | if (dotp == blastlp(curbp)) | |
430 | 429 | return (FALSE); |
431 | 430 | lchange(WFFULL); |
432 | 431 | if (ldelnewline() == FALSE) |
491 | 490 | lp1 = curwp->w_dotp; |
492 | 491 | lp2 = lp1->l_fp; |
493 | 492 | /* at the end of the buffer */ |
494 | if (lp2 == curbp->b_linep) | |
493 | if (lp2 == curbp->b_headp) | |
495 | 494 | return (TRUE); |
496 | 495 | curwp->w_bufp->b_lines--; |
497 | 496 | if (lp2->l_used <= lp1->l_size - lp1->l_used) { |
0 | /* $OpenBSD: main.c,v 1.52 2006/06/01 05:34:52 jason Exp $ */ | |
0 | /* $OpenBSD: main.c,v 1.54 2006/07/25 08:22:32 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
26 | 26 | char pat[NPAT]; /* pattern */ |
27 | 27 | |
28 | 28 | static void edinit(PF); |
29 | static void usage(void); | |
30 | ||
31 | extern char *__progname; | |
32 | ||
33 | static void | |
34 | usage() | |
35 | { | |
36 | fprintf(stderr, "usage: %s [+line] [-hn] [-f mode] [file ...]\n", | |
37 | __progname); | |
38 | exit(1); | |
39 | } | |
29 | 40 | |
30 | 41 | int |
31 | 42 | main(int argc, char **argv) |
35 | 46 | int o, i, nfiles; |
36 | 47 | int nobackups = 0; |
37 | 48 | |
38 | while ((o = getopt(argc, argv, "nf:")) != -1) | |
49 | while ((o = getopt(argc, argv, "hnf:")) != -1) | |
39 | 50 | switch (o) { |
40 | 51 | case 'n': |
41 | 52 | nobackups = 1; |
46 | 57 | "initial function"); |
47 | 58 | init_fcn_name = optarg; |
48 | 59 | break; |
60 | case 'h': | |
61 | /* FALLTHRU */ | |
49 | 62 | default: |
50 | errx(1, "usage: mg [options] [file ...]"); | |
63 | usage(); | |
51 | 64 | } |
52 | 65 | argc -= optind; |
53 | 66 | argv += optind; |
182 | 195 | wheadp = wp; |
183 | 196 | curwp = wp; |
184 | 197 | wp->w_wndp = NULL; /* Initialize window. */ |
185 | wp->w_linep = wp->w_dotp = bp->b_linep; | |
198 | wp->w_linep = wp->w_dotp = bp->b_headp; | |
186 | 199 | wp->w_ntrows = nrow - 2; /* 2 = mode, echo. */ |
187 | 200 | wp->w_flag = WFMODE | WFFULL; /* Full. */ |
188 | 201 |
0 | /* $OpenBSD: match.c,v 1.12 2005/11/18 20:56:53 deraadt Exp $ */ | |
0 | /* $OpenBSD: match.c,v 1.13 2006/07/25 08:22:32 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
104 | 104 | for (;;) { |
105 | 105 | if (cbo == 0) { |
106 | 106 | clp = lback(clp); /* beginning of line */ |
107 | if (clp == curbp->b_linep) | |
107 | if (clp == curbp->b_headp) | |
108 | 108 | return (FALSE); |
109 | 109 | cbo = llength(clp) + 1; |
110 | 110 | } |
0 | .\" $OpenBSD: mg.1,v 1.25 2005/10/11 19:57:17 jmc Exp $ | |
0 | .\" $OpenBSD: mg.1,v 1.27 2006/07/17 15:31:23 kjell Exp $ | |
1 | 1 | .\" |
2 | 2 | .Dd February 25, 2000 |
3 | 3 | .Dt MG 1 |
175 | 175 | .El |
176 | 176 | .Sh SEE ALSO |
177 | 177 | .Xr vi 1 |
178 | .Sh BUGS | |
179 | When you type | |
180 | .Ql \&? | |
181 | to list possible file names, buffer names, etc., | |
182 | a help buffer is created for the possibilities. | |
183 | In Gnu Emacs, | |
184 | this buffer goes away the next time you type a real command. | |
185 | In | |
186 | .Nm mg , | |
187 | you must use "^X-1" to get rid of it. | |
188 | .Pp | |
189 | The undo feature has minor differences compared to the same feature in | |
190 | Gnu Emacs. |
0 | /* $OpenBSD: paragraph.c,v 1.13 2005/11/18 20:56:53 deraadt Exp $ */ | |
0 | /* $OpenBSD: paragraph.c,v 1.14 2006/07/25 08:22:32 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
36 | 36 | * and scan back until we hit a <NL><SP> <NL><TAB> or |
37 | 37 | * <NL><NL> |
38 | 38 | */ |
39 | while (lback(curwp->w_dotp) != curbp->b_linep) | |
39 | while (lback(curwp->w_dotp) != curbp->b_headp) | |
40 | 40 | if (llength(lback(curwp->w_dotp)) && |
41 | 41 | lgetc(curwp->w_dotp, 0) != ' ' && |
42 | 42 | lgetc(curwp->w_dotp, 0) != '.' && |
46 | 46 | if (llength(lback(curwp->w_dotp)) && |
47 | 47 | lgetc(curwp->w_dotp, 0) == '.') { |
48 | 48 | curwp->w_dotp = lforw(curwp->w_dotp); |
49 | if (curwp->w_dotp == curbp->b_linep) { | |
49 | if (curwp->w_dotp == curbp->b_headp) { | |
50 | 50 | /* |
51 | 51 | * beyond end of buffer, |
52 | 52 | * cleanup time |
88 | 88 | curwp->w_dotp = lforw(curwp->w_dotp); |
89 | 89 | |
90 | 90 | /* and scan forword until we hit a <NL><SP> or ... */ |
91 | while (curwp->w_dotp != curbp->b_linep) { | |
91 | while (curwp->w_dotp != curbp->b_headp) { | |
92 | 92 | if (llength(curwp->w_dotp) && |
93 | 93 | lgetc(curwp->w_dotp, 0) != ' ' && |
94 | 94 | lgetc(curwp->w_dotp, 0) != '.' && |
97 | 97 | else |
98 | 98 | break; |
99 | 99 | } |
100 | if (curwp->w_dotp == curbp->b_linep) { | |
100 | if (curwp->w_dotp == curbp->b_headp) { | |
101 | 101 | /* beyond end of buffer, cleanup time */ |
102 | 102 | curwp->w_dotp = lback(curwp->w_dotp); |
103 | 103 | curwp->w_doto = llength(curwp->w_dotp); |
0 | /* $OpenBSD: random.c,v 1.20 2006/06/01 10:10:00 kjell Exp $ */ | |
0 | /* $OpenBSD: random.c,v 1.22 2006/07/25 08:27:09 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
30 | 30 | int ratio; |
31 | 31 | |
32 | 32 | /* collect the data */ |
33 | clp = lforw(curbp->b_linep); | |
33 | clp = bfirstlp(curbp); | |
34 | 34 | cchar = 0; |
35 | 35 | cline = 0; |
36 | 36 | cbyte = 0; |
51 | 51 | /* now count the chars */ |
52 | 52 | nchar += llength(clp); |
53 | 53 | clp = lforw(clp); |
54 | if (clp == curbp->b_linep) | |
54 | if (clp == curbp->b_headp) | |
55 | 55 | break; |
56 | 56 | /* count the newline */ |
57 | 57 | nchar++; |
59 | 59 | /* determine row */ |
60 | 60 | row = curwp->w_toprow + 1; |
61 | 61 | clp = curwp->w_linep; |
62 | while (clp != curbp->b_linep && clp != curwp->w_dotp) { | |
62 | while (clp != curbp->b_headp && clp != curwp->w_dotp) { | |
63 | 63 | ++row; |
64 | 64 | clp = lforw(clp); |
65 | 65 | } |
205 | 205 | RSIZE nld; |
206 | 206 | |
207 | 207 | lp1 = curwp->w_dotp; |
208 | while (llength(lp1) == 0 && (lp2 = lback(lp1)) != curbp->b_linep) | |
208 | while (llength(lp1) == 0 && (lp2 = lback(lp1)) != curbp->b_headp) | |
209 | 209 | lp1 = lp2; |
210 | 210 | lp2 = lp1; |
211 | 211 | nld = (RSIZE)0; |
212 | while ((lp2 = lforw(lp2)) != curbp->b_linep && llength(lp2) == 0) | |
212 | while ((lp2 = lforw(lp2)) != curbp->b_headp && llength(lp2) == 0) | |
213 | 213 | ++nld; |
214 | 214 | if (nld == 0) |
215 | 215 | return (TRUE); |
0 | /* $OpenBSD: re_search.c,v 1.23 2006/05/28 23:30:16 kjell Exp $ */ | |
0 | /* $OpenBSD: re_search.c,v 1.24 2006/07/25 08:22:32 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
346 | 346 | * Don't start matching past end of line -- must move to |
347 | 347 | * beginning of next line, unless at end of file. |
348 | 348 | */ |
349 | if (clp != curbp->b_linep) { | |
349 | if (clp != curbp->b_headp) { | |
350 | 350 | clp = lforw(clp); |
351 | 351 | tbo = 0; |
352 | 352 | } |
354 | 354 | * Note this loop does not process the last line, but this editor |
355 | 355 | * always makes the last line empty so this is good. |
356 | 356 | */ |
357 | while (clp != (curbp->b_linep)) { | |
357 | while (clp != (curbp->b_headp)) { | |
358 | 358 | regex_match[0].rm_so = tbo; |
359 | 359 | regex_match[0].rm_eo = llength(clp); |
360 | 360 | error = regexec_new(&re_buff, ltext(clp), RE_NMATCH, regex_match, |
400 | 400 | * Note this loop does not process the last line, but this editor |
401 | 401 | * always makes the last line empty so this is good. |
402 | 402 | */ |
403 | while (clp != (curbp->b_linep)) { | |
403 | while (clp != (curbp->b_headp)) { | |
404 | 404 | regex_match[0].rm_so = 0; |
405 | 405 | regex_match[0].rm_eo = llength(clp); |
406 | 406 | lastmatch.rm_so = -1; |
552 | 552 | /* Consider dot on next line */ |
553 | 553 | clp = lforw(clp); |
554 | 554 | |
555 | while (clp != (curbp->b_linep)) { | |
555 | while (clp != (curbp->b_headp)) { | |
556 | 556 | /* see if line matches */ |
557 | 557 | regex_match[0].rm_so = 0; |
558 | 558 | regex_match[0].rm_eo = llength(clp); |
627 | 627 | /* Consider dot on next line */ |
628 | 628 | clp = lforw(clp); |
629 | 629 | |
630 | while (clp != (curbp->b_linep)) { | |
630 | while (clp != (curbp->b_headp)) { | |
631 | 631 | /* see if line matches */ |
632 | 632 | regex_match[0].rm_so = 0; |
633 | 633 | regex_match[0].rm_eo = llength(clp); |
0 | /* $OpenBSD: region.c,v 1.22 2006/05/28 23:30:16 kjell Exp $ */ | |
0 | /* $OpenBSD: region.c,v 1.24 2006/07/25 08:22:32 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
32 | 32 | thisflag |= CFKILL; |
33 | 33 | curwp->w_dotp = region.r_linep; |
34 | 34 | curwp->w_doto = region.r_offset; |
35 | return (ldelete(region.r_size, KFORW)); | |
35 | s = ldelete(region.r_size, KFORW); | |
36 | if (s == TRUE && curwp->w_dotline > curwp->w_markline) | |
37 | curwp->w_dotline = curwp->w_markline; | |
38 | return (s); | |
36 | 39 | } |
37 | 40 | |
38 | 41 | /* |
196 | 199 | flp = blp = curwp->w_dotp; |
197 | 200 | bsize = curwp->w_doto; |
198 | 201 | fsize = llength(flp) - curwp->w_doto + 1; |
199 | while (lforw(flp) != curbp->b_linep || lback(blp) != curbp->b_linep) { | |
200 | if (lforw(flp) != curbp->b_linep) { | |
202 | while (lforw(flp) != curbp->b_headp || lback(blp) != curbp->b_headp) { | |
203 | if (lforw(flp) != curbp->b_headp) { | |
201 | 204 | flp = lforw(flp); |
202 | 205 | if (flp == curwp->w_markp) { |
203 | 206 | rp->r_linep = curwp->w_dotp; |
207 | 210 | } |
208 | 211 | fsize += llength(flp) + 1; |
209 | 212 | } |
210 | if (lback(blp) != curbp->b_linep) { | |
213 | if (lback(blp) != curbp->b_headp) { | |
211 | 214 | blp = lback(blp); |
212 | 215 | bsize += llength(blp) + 1; |
213 | 216 | if (blp == curwp->w_markp) { |
334 | 337 | for (i = 0; i < len; i++) { |
335 | 338 | if (off == llength(lp)) { |
336 | 339 | lp = lforw(lp); |
337 | if (lp == curbp->b_linep) | |
340 | if (lp == curbp->b_headp) | |
338 | 341 | break; |
339 | 342 | off = 0; |
340 | 343 | buf[i] = '\n'; |
0 | /* $OpenBSD: search.c,v 1.30 2006/06/01 09:00:50 kjell Exp $ */ | |
0 | /* $OpenBSD: search.c,v 1.32 2006/07/25 08:27:09 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
229 | 229 | } |
230 | 230 | if (success == FALSE && dir == SRCH_FORW) { |
231 | 231 | /* wrap the search to beginning */ |
232 | clp = lforw(curbp->b_linep); | |
232 | clp = bfirstlp(curbp); | |
233 | 233 | curwp->w_dotp = clp; |
234 | 234 | curwp->w_doto = 0; |
235 | 235 | curwp->w_dotline = 1; |
261 | 261 | } |
262 | 262 | if (success == FALSE && dir == SRCH_BACK) { |
263 | 263 | /* wrap the search to end */ |
264 | clp = lback(curbp->b_linep); | |
264 | clp = blastlp(curbp); | |
265 | 265 | curwp->w_dotp = clp; |
266 | 266 | curwp->w_doto = |
267 | 267 | llength(curwp->w_dotp); |
665 | 665 | xcase = 1; |
666 | 666 | for (;;) { |
667 | 667 | if (cbo == llength(clp)) { |
668 | if ((clp = lforw(clp)) == curbp->b_linep) | |
668 | if ((clp = lforw(clp)) == curbp->b_headp) | |
669 | 669 | break; |
670 | 670 | nline++; |
671 | 671 | cbo = 0; |
679 | 679 | while (*pp != 0) { |
680 | 680 | if (tbo == llength(tlp)) { |
681 | 681 | tlp = lforw(tlp); |
682 | if (tlp == curbp->b_linep) | |
682 | if (tlp == curbp->b_headp) | |
683 | 683 | goto fail; |
684 | 684 | tbo = 0; |
685 | 685 | c = CCHR('J'); |
727 | 727 | for (;;) { |
728 | 728 | if (cbo == 0) { |
729 | 729 | clp = lback(clp); |
730 | if (clp == curbp->b_linep) | |
730 | if (clp == curbp->b_headp) | |
731 | 731 | return (FALSE); |
732 | 732 | nline--; |
733 | 733 | cbo = llength(clp) + 1; |
743 | 743 | while (pp != &pat[0]) { |
744 | 744 | if (tbo == 0) { |
745 | 745 | tlp = lback(tlp); |
746 | if (tlp == curbp->b_linep) | |
746 | if (tlp == curbp->b_headp) | |
747 | 747 | goto fail; |
748 | 748 | nline--; |
749 | 749 | tbo = llength(tlp) + 1; |
0 | /* $OpenBSD: spawn.c,v 1.10 2005/06/14 18:14:40 kjell Exp $ */ | |
0 | /* $OpenBSD: spawn.c,v 1.11 2006/08/01 22:16:03 jason Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
8 | 8 | |
9 | 9 | #include "def.h" |
10 | 10 | |
11 | #include <signal.h> | |
12 | 11 | #include <termios.h> |
13 | 12 | #include <term.h> |
14 | 13 |
0 | /* $OpenBSD: sysdef.h,v 1.13 2005/06/14 18:14:40 kjell Exp $ */ | |
0 | /* $OpenBSD: sysdef.h,v 1.15 2006/08/01 22:16:03 jason Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
28 | 28 | #include <stdlib.h> |
29 | 29 | #include <string.h> |
30 | 30 | #include <errno.h> |
31 | ||
31 | #include <signal.h> | |
32 | 32 | |
33 | 33 | |
34 | 34 | #define KBLOCK 8192 /* Kill grow. */ |
0 | /* $OpenBSD: tty.c,v 1.27 2006/04/03 00:40:56 deraadt Exp $ */ | |
0 | /* $OpenBSD: tty.c,v 1.28 2006/08/01 22:16:03 jason Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
33 | 33 | #include <sys/ioctl.h> |
34 | 34 | |
35 | 35 | #include <term.h> |
36 | #include <signal.h> | |
37 | 36 | |
38 | 37 | static int charcost(char *); |
39 | 38 |
0 | /* $OpenBSD: undo.c,v 1.38 2005/12/20 05:04:28 kjell Exp $ */ | |
0 | /* $OpenBSD: undo.c,v 1.41 2006/07/25 08:22:32 kjell Exp $ */ | |
1 | 1 | /* |
2 | 2 | * Copyright (c) 2002 Vincent Labrecque <vincent@openbsd.org> |
3 | * Copyright (c) 2005, 2006 Kjell Wooding <kjell@openbsd.org> | |
3 | 4 | * All rights reserved. |
4 | 5 | * |
5 | 6 | * Redistribution and use in source and binary forms, with or without |
49 | 50 | * Local functions |
50 | 51 | */ |
51 | 52 | static int find_dot(struct line *, int); |
52 | static int find_lo(int, struct line **, int *); | |
53 | static int find_lo(int, struct line **, int *, int *); | |
53 | 54 | static struct undo_rec *new_undo_record(void); |
54 | 55 | static int drop_oldest_undo_record(void); |
55 | 56 | |
67 | 68 | int count = 0; |
68 | 69 | struct line *p; |
69 | 70 | |
70 | for (p = curbp->b_linep; p != lp; p = lforw(p)) { | |
71 | for (p = curbp->b_headp; p != lp; p = lforw(p)) { | |
71 | 72 | if (count != 0) { |
72 | if (p == curbp->b_linep) { | |
73 | if (p == curbp->b_headp) { | |
73 | 74 | ewprintf("Error: Undo stuff called with a" |
74 | 75 | "nonexistent line"); |
75 | 76 | return (FALSE); |
83 | 84 | } |
84 | 85 | |
85 | 86 | static int |
86 | find_lo(int pos, struct line **olp, int *offset) | |
87 | find_lo(int pos, struct line **olp, int *offset, int *lnum) | |
87 | 88 | { |
88 | 89 | struct line *p; |
89 | ||
90 | p = curbp->b_linep; | |
90 | int lineno; | |
91 | ||
92 | p = curbp->b_headp; | |
93 | lineno = 0; | |
91 | 94 | while (pos > llength(p)) { |
92 | 95 | pos -= llength(p) + 1; |
93 | if ((p = lforw(p)) == curbp->b_linep) { | |
96 | if ((p = lforw(p)) == curbp->b_headp) { | |
94 | 97 | *olp = NULL; |
95 | 98 | *offset = 0; |
96 | 99 | return (FALSE); |
97 | 100 | } |
101 | lineno++; | |
98 | 102 | } |
99 | 103 | *olp = p; |
100 | 104 | *offset = pos; |
105 | *lnum = lineno; | |
101 | 106 | |
102 | 107 | return (TRUE); |
103 | 108 | } |
202 | 207 | |
203 | 208 | /* |
204 | 209 | * Record an undo boundary, unless 'nobound' is set via undo_no_boundary. |
205 | * Does nothing if previous undo entry is already a boundary. | |
210 | * Does nothing if previous undo entry is already a boundary or 'modified' flag. | |
206 | 211 | */ |
207 | 212 | void |
208 | 213 | undo_add_boundary(void) |
209 | 214 | { |
210 | 215 | struct undo_rec *rec; |
216 | int last; | |
211 | 217 | |
212 | 218 | if (nobound) |
213 | 219 | return; |
214 | 220 | |
215 | if (lastrectype() == BOUNDARY) | |
221 | last = lastrectype(); | |
222 | if (last == BOUNDARY || last == MODIFIED) | |
216 | 223 | return; |
217 | 224 | |
218 | 225 | rec = new_undo_record(); |
219 | 226 | rec->type = BOUNDARY; |
227 | ||
228 | LIST_INSERT_HEAD(&curbp->b_undo, rec, next); | |
229 | ||
230 | return; | |
231 | } | |
232 | ||
233 | /* | |
234 | * Record an undo "modified" boundary | |
235 | */ | |
236 | void | |
237 | undo_add_modified(void) | |
238 | { | |
239 | struct undo_rec *rec; | |
240 | ||
241 | rec = new_undo_record(); | |
242 | rec->type = MODIFIED; | |
220 | 243 | |
221 | 244 | LIST_INSERT_HEAD(&curbp->b_undo, rec, next); |
222 | 245 | |
360 | 383 | |
361 | 384 | for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { |
362 | 385 | if (wp->w_bufp == bp) { |
363 | wp->w_dotp = bp->b_linep; | |
386 | wp->w_dotp = bp->b_headp; | |
364 | 387 | wp->w_doto = 0; |
365 | 388 | } |
366 | 389 | } |
373 | 396 | "%d:\t %s at %d ", num, |
374 | 397 | (rec->type == DELETE) ? "DELETE": |
375 | 398 | (rec->type == INSERT) ? "INSERT": |
376 | (rec->type == BOUNDARY) ? "----" : "UNKNOWN", | |
399 | (rec->type == BOUNDARY) ? "----" : | |
400 | (rec->type == MODIFIED) ? "MODIFIED": "UNKNOWN", | |
377 | 401 | rec->pos); |
378 | 402 | |
379 | 403 | if (rec->content) { |
437 | 461 | struct line *lp; |
438 | 462 | int offset, save, dot; |
439 | 463 | static int nulled = FALSE; |
464 | int lineno; | |
440 | 465 | |
441 | 466 | dot = find_dot(curwp->w_dotp, curwp->w_doto); |
442 | 467 | |
485 | 510 | /* |
486 | 511 | * Move to where this has to apply |
487 | 512 | * |
488 | * Boundaries are put as position 0 (to save | |
489 | * lookup time in find_dot) so we must | |
490 | * not move there... | |
513 | * Boundaries (and the modified flag) are put as | |
514 | * position 0 (to save lookup time in find_dot) | |
515 | * so we must not move there... | |
491 | 516 | */ |
492 | if (ptr->type != BOUNDARY) { | |
517 | if (ptr->type != BOUNDARY && ptr->type != MODIFIED) { | |
493 | 518 | if (find_lo(ptr->pos, &lp, |
494 | &offset) == FALSE) { | |
519 | &offset, &lineno) == FALSE) { | |
495 | 520 | ewprintf("Internal error in Undo!"); |
496 | 521 | rval = FALSE; |
497 | 522 | break; |
498 | 523 | } |
499 | 524 | curwp->w_dotp = lp; |
500 | 525 | curwp->w_doto = offset; |
526 | curwp->w_markline = curwp->w_dotline; | |
527 | curwp->w_dotline = lineno; | |
501 | 528 | } |
502 | 529 | |
503 | 530 | /* |
514 | 541 | case BOUNDARY: |
515 | 542 | done = 1; |
516 | 543 | break; |
544 | case MODIFIED: | |
545 | curbp->b_flag &= ~BFCHG; | |
546 | break; | |
517 | 547 | default: |
518 | 548 | break; |
519 | 549 | } |
0 | /* $OpenBSD: window.c,v 1.24 2006/06/01 09:00:50 kjell Exp $ */ | |
0 | /* $OpenBSD: window.c,v 1.25 2006/07/25 08:22:32 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
182 | 182 | } |
183 | 183 | lp = curwp->w_linep; |
184 | 184 | i = curwp->w_toprow; |
185 | while (i != 0 && lback(lp) != curbp->b_linep) { | |
185 | while (i != 0 && lback(lp) != curbp->b_headp) { | |
186 | 186 | --i; |
187 | 187 | lp = lback(lp); |
188 | 188 | } |
312 | 312 | /* shrink below */ |
313 | 313 | if (curwp->w_wndp == adjwp) { |
314 | 314 | lp = adjwp->w_linep; |
315 | for (i = 0; i < n && lp != adjwp->w_bufp->b_linep; ++i) | |
315 | for (i = 0; i < n && lp != adjwp->w_bufp->b_headp; ++i) | |
316 | 316 | lp = lforw(lp); |
317 | 317 | adjwp->w_linep = lp; |
318 | 318 | adjwp->w_toprow += n; |
319 | 319 | /* shrink above */ |
320 | 320 | } else { |
321 | 321 | lp = curwp->w_linep; |
322 | for (i = 0; i < n && lback(lp) != curbp->b_linep; ++i) | |
322 | for (i = 0; i < n && lback(lp) != curbp->b_headp; ++i) | |
323 | 323 | lp = lback(lp); |
324 | 324 | curwp->w_linep = lp; |
325 | 325 | curwp->w_toprow -= n; |
365 | 365 | /* grow below */ |
366 | 366 | if (curwp->w_wndp == adjwp) { |
367 | 367 | lp = adjwp->w_linep; |
368 | for (i = 0; i < n && lback(lp) != adjwp->w_bufp->b_linep; ++i) | |
368 | for (i = 0; i < n && lback(lp) != adjwp->w_bufp->b_headp; ++i) | |
369 | 369 | lp = lback(lp); |
370 | 370 | adjwp->w_linep = lp; |
371 | 371 | adjwp->w_toprow -= n; |
372 | 372 | /* grow above */ |
373 | 373 | } else { |
374 | 374 | lp = curwp->w_linep; |
375 | for (i = 0; i < n && lp != curbp->b_linep; ++i) | |
375 | for (i = 0; i < n && lp != curbp->b_headp; ++i) | |
376 | 376 | lp = lforw(lp); |
377 | 377 | curwp->w_linep = lp; |
378 | 378 | curwp->w_toprow += n; |
0 | /* $OpenBSD: yank.c,v 1.3 2006/05/28 23:30:16 kjell Exp $ */ | |
0 | /* $OpenBSD: yank.c,v 1.4 2006/07/25 08:22:32 kjell Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
173 | 173 | nextp = lforw(curwp->w_dotp); |
174 | 174 | i = n; |
175 | 175 | while (--i) { |
176 | if (nextp == curbp->b_linep) | |
176 | if (nextp == curbp->b_headp) | |
177 | 177 | break; |
178 | 178 | chunk += llength(nextp) + 1; |
179 | 179 | nextp = lforw(nextp); |
184 | 184 | curwp->w_doto = 0; |
185 | 185 | i = n; |
186 | 186 | while (i++) { |
187 | if (lback(curwp->w_dotp) == curbp->b_linep) | |
187 | if (lback(curwp->w_dotp) == curbp->b_headp) | |
188 | 188 | break; |
189 | 189 | curwp->w_dotp = lback(curwp->w_dotp); |
190 | 190 | curwp->w_flag |= WFMOVE; |
244 | 244 | |
245 | 245 | /* if offscreen insert */ |
246 | 246 | if (curwp->w_dotp == lp) { |
247 | while (nline-- && lback(lp) != curbp->b_linep) | |
247 | while (nline-- && lback(lp) != curbp->b_headp) | |
248 | 248 | lp = lback(lp); |
249 | 249 | /* adjust framing */ |
250 | 250 | curwp->w_linep = lp; |