Codebase list mg / 8124ecd
Imported Debian patch 20060818-1 Trent Buck 17 years ago
34 changed file(s) with 243 addition(s) and 183 deletion(s). Raw diff Collapse all Expand all
1313 mandir= $(prefix)/share/man
1414
1515
16 CC= gcc
17 CFLAGS= -O2 -pipe
18 CFLAGS+= -g -Wall -Werror
19 LDFLAGS= -lncurses
16 LDFLAGS+= -lncurses
2017
2118 INSTALL= /usr/bin/install
2219 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 $ */
11
22 /* This file is in the public domain */
33
4141 return (forwchar(f, -n));
4242 while (n--) {
4343 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) {
4545 if (!(f & FFRAND))
4646 ewprintf("Beginning of buffer");
4747 return (FALSE);
8282 while (n--) {
8383 if (curwp->w_doto == llength(curwp->w_dotp)) {
8484 curwp->w_dotp = lforw(curwp->w_dotp);
85 if (curwp->w_dotp == curbp->b_linep) {
85 if (curwp->w_dotp == curbp->b_headp) {
8686 curwp->w_dotp = lback(curwp->w_dotp);
8787 if (!(f & FFRAND))
8888 ewprintf("End of buffer");
106106 gotobob(int f, int n)
107107 {
108108 (void) setmark(f, n);
109 curwp->w_dotp = lforw(curbp->b_linep);
109 curwp->w_dotp = bfirstlp(curbp);
110110 curwp->w_doto = 0;
111111 curwp->w_flag |= WFFULL;
112112 curwp->w_dotline = 1;
122122 gotoeob(int f, int n)
123123 {
124124 (void) setmark(f, n);
125 curwp->w_dotp = lback(curbp->b_linep);
125 curwp->w_dotp = blastlp(curbp);
126126 curwp->w_doto = llength(curwp->w_dotp);
127127 curwp->w_dotline = curwp->w_bufp->b_lines;
128128 curwp->w_flag |= WFFULL;
144144
145145 if (n < 0)
146146 return (backline(f | FFRAND, -n));
147 if ((dlp = curwp->w_dotp) == curbp->b_linep)
147 if ((dlp = curwp->w_dotp) == curbp->b_headp)
148148 return(TRUE);
149149 if ((lastflag & CFCPCN) == 0) /* Fix goal. */
150150 setgoal();
153153 return (TRUE);
154154 while (n--) {
155155 dlp = lforw(dlp);
156 if (dlp == curbp->b_linep) {
156 if (dlp == curbp->b_headp) {
157157 curwp->w_dotp = lback(dlp);
158158 curwp->w_doto = llength(curwp->w_dotp);
159159 curwp->w_flag |= WFMOVE;
187187 setgoal();
188188 thisflag |= CFCPCN;
189189 dlp = curwp->w_dotp;
190 while (n-- && lback(dlp) != curbp->b_linep) {
190 while (n-- && lback(dlp) != curbp->b_headp) {
191191 dlp = lback(dlp);
192192 curwp->w_dotline--;
193193 }
270270 n *= curwp->w_ntrows; /* to lines. */
271271 #endif
272272 lp = curwp->w_linep;
273 while (n-- && lforw(lp) != curbp->b_linep) {
273 while (n-- && lforw(lp) != curbp->b_headp) {
274274 lp = lforw(lp);
275275 curwp->w_dotline++;
276276 }
277277 curwp->w_linep = lp;
278278 curwp->w_flag |= WFFULL;
279279 /* 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))
281281 if (lp == curwp->w_dotp)
282282 return (TRUE);
283283 curwp->w_dotp = curwp->w_linep;
310310 n *= curwp->w_ntrows; /* to lines. */
311311 #endif
312312 lp = curwp->w_linep;
313 while (n-- && lback(lp) != curbp->b_linep) {
313 while (n-- && lback(lp) != curbp->b_headp) {
314314 lp = lback(lp);
315315 curwp->w_dotline--;
316316 }
317317 curwp->w_linep = lp;
318318 curwp->w_flag |= WFFULL;
319319 /* 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))
321321 if (lp == curwp->w_dotp)
322322 return (TRUE);
323323 curwp->w_dotp = curwp->w_linep;
459459 if (n == 0)
460460 n++;
461461 curwp->w_dotline = n;
462 clp = lforw(curbp->b_linep); /* "clp" is first line */
462 clp = lforw(curbp->b_headp); /* "clp" is first line */
463463 while (--n > 0) {
464 if (lforw(clp) == curbp->b_linep) {
464 if (lforw(clp) == curbp->b_headp) {
465465 curwp->w_dotline = curwp->w_bufp->b_lines;
466466 break;
467467 }
469469 }
470470 } else {
471471 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 */
473473 while (n < 0) {
474 if (lback(clp) == curbp->b_linep) {
474 if (lback(clp) == curbp->b_headp) {
475475 curwp->w_dotline = 1;
476476 break;
477477 }
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 $ */
11
22 /* This file is in the public domain. */
33
169169 }
170170 if (bp == curbp)
171171 curbp = bp1;
172 free(bp->b_linep); /* Release header line. */
172 free(bp->b_headp); /* Release header line. */
173173 bp2 = NULL; /* Find the header. */
174174 bp1 = bheadp;
175175 while (bp1 != bp) {
306306
307307 nbytes = 0; /* Count bytes in buf. */
308308 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) {
311311 nbytes += llength(lp) + 1;
312312 lp = lforw(lp);
313313 }
328328 bp->b_fname) == FALSE)
329329 return (NULL);
330330 }
331 blp->b_dotp = lforw(blp->b_linep); /* put dot at beginning of
331 blp->b_dotp = bfirstlp(blp); /* put dot at beginning of
332332 * buffer */
333333 blp->b_doto = 0;
334334 return (blp); /* All done */
417417 lp->l_used = strlen(lp->l_text);
418418 va_end(ap);
419419
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;
424424 bp->b_lines++;
425425
426426 return (TRUE);
522522 bp->b_marko = 0;
523523 bp->b_flag = defb_flag;
524524 bp->b_nwnd = 0;
525 bp->b_linep = lp;
525 bp->b_headp = lp;
526526 bp->b_nmodes = defb_nmodes;
527527 LIST_INIT(&bp->b_undo);
528528 bp->b_undoptr = NULL;
539539 bp->b_bufp = bheadp;
540540 bheadp = bp;
541541 bp->b_dotline = bp->b_markline = 1;
542 bp->b_lines = 0;
542 bp->b_lines = 1;
543543
544544 return (bp);
545545 }
564564 (s = eyesno("Buffer modified; kill anyway")) != TRUE)
565565 return (s);
566566 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)
568568 lfree(lp);
569 bp->b_dotp = bp->b_linep; /* Fix dot */
569 bp->b_dotp = bp->b_headp; /* Fix dot */
570570 bp->b_doto = 0;
571571 bp->b_markp = NULL; /* Invalidate "mark" */
572572 bp->b_marko = 0;
573573 bp->b_dotline = bp->b_markline = 1;
574 bp->b_lines = 0;
574 bp->b_lines = 1;
575575
576576 return (TRUE);
577577 }
707707 }
708708 /* insert the buffer */
709709 nline = 0;
710 clp = lforw(bp->b_linep);
710 clp = bfirstlp(bp);
711711 for (;;) {
712712 for (clo = 0; clo < llength(clp); clo++)
713713 if (linsert(1, lgetc(clp, clo)) == FALSE)
714714 return (FALSE);
715 if ((clp = lforw(clp)) == bp->b_linep)
715 if ((clp = lforw(clp)) == bp->b_headp)
716716 break;
717717 if (newline(FFRAND, 1) == FALSE) /* fake newline */
718718 return (FALSE);
725725
726726 clp = curwp->w_linep; /* cosmetic adjustment */
727727 if (curwp->w_dotp == clp) { /* for offscreen insert */
728 while (nline-- && lback(clp) != curbp->b_linep)
728 while (nline-- && lback(clp) != curbp->b_headp)
729729 clp = lback(clp);
730730 curwp->w_linep = clp; /* adjust framing. */
731731 curwp->w_flag |= WFFULL;
763763 {
764764 struct mgwin *wp;
765765
766 bp->b_dotp = lforw(bp->b_linep);
766 bp->b_dotp = bfirstlp(bp);
767767 bp->b_doto = 0;
768768 if (bp->b_nwnd != 0) {
769769 for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
0 #define FKEYS
1 #define PREFIXREGION
2 #define REGEX
3 #define XKEYS
4 #define HAVE_ARC4RANDOM
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
015 mg (20060707-1) unstable; urgency=low
116
217 * Initial release (Closes: #375408)
00 Source: mg
11 Section: editors
2 Priority: important
2 Priority: optional
33 Maintainer: Trent Buck <trentbuck@gmail.com>
44 Build-Depends: debhelper (>= 4.0.0), autotools-dev, libc6-dev, libncurses-dev
55 Standards-Version: 3.6.2
0 ?package(mg):needs="text" section="Apps/Editors"\
1 title="Mg" command="/usr/bin/mg"
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#
2222 else
2323 CFLAGS += -O2
2424 endif
25 export CFLAGS
26
27 CC = gcc
28 export CC
2529
2630 config.status: configure
2731 dh_testdir
6569 dh_installdocs
6670 dh_installexamples
6771 # dh_install
68 # dh_installmenu
72 dh_installmenu
6973 # dh_installdebconf
7074 # dh_installlogrotate
7175 # 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 $ */
11
22 /* This file is in the public domain. */
33
237237 * dot and mark in the header, but this is only valid if the buffer
238238 * is not being displayed (that is, if "b_nwnd" is 0). The text for
239239 * 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".
241241 */
242242 struct buffer {
243243 struct list b_list; /* buffer list pointer */
244244 struct buffer *b_altb; /* Link to alternate buffer */
245245 struct line *b_dotp; /* Link to "." line structure */
246246 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 */
248248 struct maps_s *b_modes[PBMODES]; /* buffer modes */
249249 int b_doto; /* Offset of "." in above line */
250250 int b_marko; /* ditto for the "mark" */
264264 #define b_bufp b_list.l_p.x_bp
265265 #define b_bname b_list.l_name
266266
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
267271 #define BFCHG 0x01 /* Changed. */
268272 #define BFBAK 0x02 /* Need to make a backup. */
269273 #ifdef NOTAB
280284 enum {
281285 INSERT = 1,
282286 DELETE,
283 BOUNDARY
287 BOUNDARY,
288 MODIFIED
284289 } type;
285290 struct region region;
286291 int pos;
306311 void ttcolor(int);
307312 void ttresize(void);
308313
309 #ifdef __GLIBC__
310 volatile int winch_flag; /* sig_atomic_t is just an int */
311 #else
312314 volatile sig_atomic_t winch_flag;
313 #endif
314315
315316 /* ttyio.c */
316317 void ttopen(void);
603604 int undo_dump(int, int);
604605 int undo_enable(int);
605606 void undo_add_boundary(void);
607 void undo_add_modified(void);
606608 int undo_add_insert(struct line *, int, int);
607609 int undo_add_delete(struct line *, int, int);
608610 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 $ */
11
22 /* This file is in the public domain. */
33
247247 while (n--) {
248248 if (llength(curwp->w_dotp) > 0)
249249 lputc(curwp->w_dotp, 0, 'D');
250 if (lforw(curwp->w_dotp) != curbp->b_linep)
250 if (lforw(curwp->w_dotp) != curbp->b_headp)
251251 curwp->w_dotp = lforw(curwp->w_dotp);
252252 }
253253 curwp->w_flag |= WFEDIT | WFMOVE;
264264 while (n--) {
265265 if (llength(curwp->w_dotp) > 0)
266266 lputc(curwp->w_dotp, 0, ' ');
267 if (lforw(curwp->w_dotp) != curbp->b_linep)
267 if (lforw(curwp->w_dotp) != curbp->b_headp)
268268 curwp->w_dotp = lforw(curwp->w_dotp);
269269 }
270270 curwp->w_flag |= WFEDIT | WFMOVE;
281281 while (n--) {
282282 if (llength(curwp->w_dotp) > 0)
283283 lputc(curwp->w_dotp, 0, ' ');
284 if (lback(curwp->w_dotp) != curbp->b_linep)
284 if (lback(curwp->w_dotp) != curbp->b_headp)
285285 curwp->w_dotp = lback(curwp->w_dotp);
286286 }
287287 curwp->w_doto = 0;
342342 struct line *lp, *nlp;
343343 char fname[NFILEN];
344344
345 for (lp = lforw(curbp->b_linep); lp != curbp->b_linep; lp = nlp) {
345 for (lp = bfirstlp(curbp); lp != curbp->b_headp; lp = nlp) {
346346 nlp = lforw(lp);
347347 if (llength(lp) && lgetc(lp, 0) == 'D') {
348348 switch (d_makename(lp, fname, sizeof(fname))) {
643643 strerror(errno));
644644 return (NULL);
645645 }
646 bp->b_dotp = lforw(bp->b_linep); /* go to first line */
646 bp->b_dotp = bfirstlp(bp);
647647 (void)strlcpy(bp->b_fname, dname, sizeof(bp->b_fname));
648648 (void)strlcpy(bp->b_cwd, dname, sizeof(bp->b_cwd));
649649 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 $ */
11
22 /* This file is in the public domain. */
33
424424 for (i = 0; i < wp->w_ntrows; ++i) {
425425 if (lp == wp->w_dotp)
426426 goto out;
427 if (lp == wp->w_bufp->b_linep)
427 if (lp == wp->w_bufp->b_headp)
428428 break;
429429 lp = lforw(lp);
430430 }
448448 * Find the line.
449449 */
450450 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) {
452452 --i;
453453 lp = lback(lp);
454454 }
474474 vscreen[i]->v_color = CTEXT;
475475 vscreen[i]->v_flag |= (VFCHG | VFHBAD);
476476 vtmove(i, 0);
477 if (lp != wp->w_bufp->b_linep) {
477 if (lp != wp->w_bufp->b_headp) {
478478 for (j = 0; j < llength(lp); ++j)
479479 vtputc(lgetc(lp, j));
480480 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 $ */
11
22 /* This file is in the public domain. */
33
620620 int s;
621621 static char excbuf[128];
622622
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)) {
624624 if (llength(lp) >= 128)
625625 return (FALSE);
626626 (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 $ */
11
22 /* This file is in the public domain. */
33
223223
224224 for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
225225 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);
227227 wp->w_doto = 0;
228228 wp->w_markp = NULL;
229229 wp->w_marko = 0;
256256 if (startrow)
257257 gotoline(FFARG, startrow);
258258
259 undo_add_modified();
259260 return (status);
260261 }
261262
345346 oline = curwp->w_dotline;
346347 (void)lnewline();
347348 olp = lback(curwp->w_dotp);
348 if (olp == curbp->b_linep) {
349 if (olp == curbp->b_headp) {
349350 /* if at end of buffer, create a line to insert before */
350351 (void)lnewline();
351352 curwp->w_dotp = lback(curwp->w_dotp);
427428 curwp->w_dotp = olp;
428429 curwp->w_doto = opos;
429430 curwp->w_dotline = oline;
430 if (olp == curbp->b_linep)
431 if (olp == curbp->b_headp)
431432 curwp->w_dotp = lforw(olp);
432433 if (newname != NULL)
433434 bp->b_flag |= BFCHG | BFBAK; /* Need a backup. */
440441 * pointers in other windows correctly if they are also at the end of
441442 * buffer.
442443 */
443 lp1 = bp->b_linep;
444 lp1 = bp->b_headp;
444445 if (curwp->w_markp == lp1) {
445446 lp2 = curwp->w_dotp;
446447 } 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 $ */
11
22 /* This file is in the public domain. */
33
114114 int emptylines = 0;
115115 int ret;
116116
117 lpend = bp->b_linep;
117 lpend = bp->b_headp;
118118
119119 /* This stuff is to make sure there is exactly one trailing \n at the
120120 * 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 $ */
11 /*
22 * Copyright (c) 2001 Artur Grabowski <art@openbsd.org>.
33 * Copyright (c) 2005 Kjell Wooding <kjell@openbsd.org>.
276276 else
277277 addlinef(bp, "Command finished at %s", timestr);
278278
279 bp->b_dotp = lforw(bp->b_linep); /* go to first line */
279 bp->b_dotp = bfirstlp(bp);
280280 bp->b_modes[0] = name_mode("fundamental");
281281 bp->b_modes[1] = name_mode("compile");
282282 bp->b_nmodes = 1;
304304
305305 compile_win = curwp;
306306 compile_buffer = curbp;
307 last = lback(compile_buffer->b_linep);
307 last = blastlp(compile_buffer);
308308
309309 retry:
310310 /* last line is compilation result */
347347 return (TRUE);
348348 fail:
349349 free(line);
350 if (curwp->w_dotp != lback(curbp->b_linep)) {
350 if (curwp->w_dotp != blastlp(curbp)) {
351351 curwp->w_dotp = lforw(curwp->w_dotp);
352352 curwp->w_flag |= WFMOVE;
353353 goto retry;
366366 }
367367 curwp = compile_win;
368368 curbp = compile_buffer;
369 if (curwp->w_dotp == lback(curbp->b_linep)) {
369 if (curwp->w_dotp == blastlp(curbp)) {
370370 ewprintf("No more hits");
371371 return (FALSE);
372372 }
5050 KEYMAP *name_map(const char *);
5151 struct maps_s *name_mode(const char *);
5252 PF doscan(KEYMAP *, int, KEYMAP **);
53 const char *map_name(KEYMAP *);
5453 void maps_init(void);
5554 int maps_add(KEYMAP *, const char *);
5655
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 $ */
11
22 /* This file is in the public domain. */
33
211211 gotoeob /* > */
212212 };
213213
214 static PF metalb[] = {
215 gotobop, /* [ */
214 static PF metabsl[] = {
216215 delwhite, /* \ */
217 gotoeop, /* ] */
216 rescan, /* ] */
218217 rescan, /* ^ */
219218 rescan, /* _ */
220219 rescan, /* ` */
239238 upperword, /* u */
240239 backpage, /* v */
241240 copyregion, /* w */
242 extend /* x */
241 extend, /* x */
242 rescan, /* y */
243 rescan, /* z */
244 gotobop, /* { */
245 rescan, /* | */
246 gotoeop /* } */
243247 };
244248
245249 static PF metatilde[] = {
268272 '-', '>', metami, NULL
269273 },
270274 {
271 '[', 'f', metalb, NULL
272 },
273 {
274 'l', 'x', metal, NULL
275 '\\', 'f', metabsl, NULL
276 },
277 {
278 'l', '}', metal, NULL
275279 },
276280 {
277281 '~', CCHR('?'), metatilde, NULL
505509 return (TRUE);
506510 }
507511
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
519512 struct maps_s *
520513 name_mode(const char *name)
521514 {
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 $ */
11
22 /* This file is in the public domain. */
33
157157 lp1 = curwp->w_dotp;
158158
159159 /* special case for the end */
160 if (lp1 == curbp->b_linep) {
160 if (lp1 == curbp->b_headp) {
161161 struct line *lp2, *lp3;
162162
163163 /* now should only happen in empty buffer */
247247 lp1 = curwp->w_dotp;
248248
249249 /* special case for the end */
250 if (lp1 == curbp->b_linep) {
250 if (lp1 == curbp->b_headp) {
251251 struct line *lp2, *lp3;
252252
253253 /* now should only happen in empty buffer */
416416 dotp = curwp->w_dotp;
417417 doto = curwp->w_doto;
418418 /* Hit the end of the buffer */
419 if (dotp == curbp->b_linep)
419 if (dotp == curbp->b_headp)
420420 return (FALSE);
421421 /* Size of the chunk */
422422 chunk = dotp->l_used - doto;
425425 chunk = n;
426426 /* End of line, merge */
427427 if (chunk == 0) {
428 if (dotp == lback(curbp->b_linep))
429 /* End of buffer */
428 if (dotp == blastlp(curbp))
430429 return (FALSE);
431430 lchange(WFFULL);
432431 if (ldelnewline() == FALSE)
491490 lp1 = curwp->w_dotp;
492491 lp2 = lp1->l_fp;
493492 /* at the end of the buffer */
494 if (lp2 == curbp->b_linep)
493 if (lp2 == curbp->b_headp)
495494 return (TRUE);
496495 curwp->w_bufp->b_lines--;
497496 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 $ */
11
22 /* This file is in the public domain. */
33
2626 char pat[NPAT]; /* pattern */
2727
2828 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 }
2940
3041 int
3142 main(int argc, char **argv)
3546 int o, i, nfiles;
3647 int nobackups = 0;
3748
38 while ((o = getopt(argc, argv, "nf:")) != -1)
49 while ((o = getopt(argc, argv, "hnf:")) != -1)
3950 switch (o) {
4051 case 'n':
4152 nobackups = 1;
4657 "initial function");
4758 init_fcn_name = optarg;
4859 break;
60 case 'h':
61 /* FALLTHRU */
4962 default:
50 errx(1, "usage: mg [options] [file ...]");
63 usage();
5164 }
5265 argc -= optind;
5366 argv += optind;
182195 wheadp = wp;
183196 curwp = wp;
184197 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;
186199 wp->w_ntrows = nrow - 2; /* 2 = mode, echo. */
187200 wp->w_flag = WFMODE | WFFULL; /* Full. */
188201
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 $ */
11
22 /* This file is in the public domain. */
33
104104 for (;;) {
105105 if (cbo == 0) {
106106 clp = lback(clp); /* beginning of line */
107 if (clp == curbp->b_linep)
107 if (clp == curbp->b_headp)
108108 return (FALSE);
109109 cbo = llength(clp) + 1;
110110 }
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 $
11 .\"
22 .Dd February 25, 2000
33 .Dt MG 1
175175 .El
176176 .Sh SEE ALSO
177177 .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 $ */
11
22 /* This file is in the public domain. */
33
3636 * and scan back until we hit a <NL><SP> <NL><TAB> or
3737 * <NL><NL>
3838 */
39 while (lback(curwp->w_dotp) != curbp->b_linep)
39 while (lback(curwp->w_dotp) != curbp->b_headp)
4040 if (llength(lback(curwp->w_dotp)) &&
4141 lgetc(curwp->w_dotp, 0) != ' ' &&
4242 lgetc(curwp->w_dotp, 0) != '.' &&
4646 if (llength(lback(curwp->w_dotp)) &&
4747 lgetc(curwp->w_dotp, 0) == '.') {
4848 curwp->w_dotp = lforw(curwp->w_dotp);
49 if (curwp->w_dotp == curbp->b_linep) {
49 if (curwp->w_dotp == curbp->b_headp) {
5050 /*
5151 * beyond end of buffer,
5252 * cleanup time
8888 curwp->w_dotp = lforw(curwp->w_dotp);
8989
9090 /* 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) {
9292 if (llength(curwp->w_dotp) &&
9393 lgetc(curwp->w_dotp, 0) != ' ' &&
9494 lgetc(curwp->w_dotp, 0) != '.' &&
9797 else
9898 break;
9999 }
100 if (curwp->w_dotp == curbp->b_linep) {
100 if (curwp->w_dotp == curbp->b_headp) {
101101 /* beyond end of buffer, cleanup time */
102102 curwp->w_dotp = lback(curwp->w_dotp);
103103 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 $ */
11
22 /* This file is in the public domain. */
33
3030 int ratio;
3131
3232 /* collect the data */
33 clp = lforw(curbp->b_linep);
33 clp = bfirstlp(curbp);
3434 cchar = 0;
3535 cline = 0;
3636 cbyte = 0;
5151 /* now count the chars */
5252 nchar += llength(clp);
5353 clp = lforw(clp);
54 if (clp == curbp->b_linep)
54 if (clp == curbp->b_headp)
5555 break;
5656 /* count the newline */
5757 nchar++;
5959 /* determine row */
6060 row = curwp->w_toprow + 1;
6161 clp = curwp->w_linep;
62 while (clp != curbp->b_linep && clp != curwp->w_dotp) {
62 while (clp != curbp->b_headp && clp != curwp->w_dotp) {
6363 ++row;
6464 clp = lforw(clp);
6565 }
205205 RSIZE nld;
206206
207207 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)
209209 lp1 = lp2;
210210 lp2 = lp1;
211211 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)
213213 ++nld;
214214 if (nld == 0)
215215 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 $ */
11
22 /* This file is in the public domain. */
33
346346 * Don't start matching past end of line -- must move to
347347 * beginning of next line, unless at end of file.
348348 */
349 if (clp != curbp->b_linep) {
349 if (clp != curbp->b_headp) {
350350 clp = lforw(clp);
351351 tbo = 0;
352352 }
354354 * Note this loop does not process the last line, but this editor
355355 * always makes the last line empty so this is good.
356356 */
357 while (clp != (curbp->b_linep)) {
357 while (clp != (curbp->b_headp)) {
358358 regex_match[0].rm_so = tbo;
359359 regex_match[0].rm_eo = llength(clp);
360360 error = regexec_new(&re_buff, ltext(clp), RE_NMATCH, regex_match,
400400 * Note this loop does not process the last line, but this editor
401401 * always makes the last line empty so this is good.
402402 */
403 while (clp != (curbp->b_linep)) {
403 while (clp != (curbp->b_headp)) {
404404 regex_match[0].rm_so = 0;
405405 regex_match[0].rm_eo = llength(clp);
406406 lastmatch.rm_so = -1;
552552 /* Consider dot on next line */
553553 clp = lforw(clp);
554554
555 while (clp != (curbp->b_linep)) {
555 while (clp != (curbp->b_headp)) {
556556 /* see if line matches */
557557 regex_match[0].rm_so = 0;
558558 regex_match[0].rm_eo = llength(clp);
627627 /* Consider dot on next line */
628628 clp = lforw(clp);
629629
630 while (clp != (curbp->b_linep)) {
630 while (clp != (curbp->b_headp)) {
631631 /* see if line matches */
632632 regex_match[0].rm_so = 0;
633633 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 $ */
11
22 /* This file is in the public domain. */
33
3232 thisflag |= CFKILL;
3333 curwp->w_dotp = region.r_linep;
3434 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);
3639 }
3740
3841 /*
196199 flp = blp = curwp->w_dotp;
197200 bsize = curwp->w_doto;
198201 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) {
201204 flp = lforw(flp);
202205 if (flp == curwp->w_markp) {
203206 rp->r_linep = curwp->w_dotp;
207210 }
208211 fsize += llength(flp) + 1;
209212 }
210 if (lback(blp) != curbp->b_linep) {
213 if (lback(blp) != curbp->b_headp) {
211214 blp = lback(blp);
212215 bsize += llength(blp) + 1;
213216 if (blp == curwp->w_markp) {
334337 for (i = 0; i < len; i++) {
335338 if (off == llength(lp)) {
336339 lp = lforw(lp);
337 if (lp == curbp->b_linep)
340 if (lp == curbp->b_headp)
338341 break;
339342 off = 0;
340343 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 $ */
11
22 /* This file is in the public domain. */
33
229229 }
230230 if (success == FALSE && dir == SRCH_FORW) {
231231 /* wrap the search to beginning */
232 clp = lforw(curbp->b_linep);
232 clp = bfirstlp(curbp);
233233 curwp->w_dotp = clp;
234234 curwp->w_doto = 0;
235235 curwp->w_dotline = 1;
261261 }
262262 if (success == FALSE && dir == SRCH_BACK) {
263263 /* wrap the search to end */
264 clp = lback(curbp->b_linep);
264 clp = blastlp(curbp);
265265 curwp->w_dotp = clp;
266266 curwp->w_doto =
267267 llength(curwp->w_dotp);
665665 xcase = 1;
666666 for (;;) {
667667 if (cbo == llength(clp)) {
668 if ((clp = lforw(clp)) == curbp->b_linep)
668 if ((clp = lforw(clp)) == curbp->b_headp)
669669 break;
670670 nline++;
671671 cbo = 0;
679679 while (*pp != 0) {
680680 if (tbo == llength(tlp)) {
681681 tlp = lforw(tlp);
682 if (tlp == curbp->b_linep)
682 if (tlp == curbp->b_headp)
683683 goto fail;
684684 tbo = 0;
685685 c = CCHR('J');
727727 for (;;) {
728728 if (cbo == 0) {
729729 clp = lback(clp);
730 if (clp == curbp->b_linep)
730 if (clp == curbp->b_headp)
731731 return (FALSE);
732732 nline--;
733733 cbo = llength(clp) + 1;
743743 while (pp != &pat[0]) {
744744 if (tbo == 0) {
745745 tlp = lback(tlp);
746 if (tlp == curbp->b_linep)
746 if (tlp == curbp->b_headp)
747747 goto fail;
748748 nline--;
749749 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 $ */
11
22 /* This file is in the public domain. */
33
88
99 #include "def.h"
1010
11 #include <signal.h>
1211 #include <termios.h>
1312 #include <term.h>
1413
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 $ */
11
22 /* This file is in the public domain. */
33
2828 #include <stdlib.h>
2929 #include <string.h>
3030 #include <errno.h>
31
31 #include <signal.h>
3232
3333
3434 #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 $ */
11
22 /* This file is in the public domain. */
33
3333 #include <sys/ioctl.h>
3434
3535 #include <term.h>
36 #include <signal.h>
3736
3837 static int charcost(char *);
3938
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 $ */
11 /*
22 * Copyright (c) 2002 Vincent Labrecque <vincent@openbsd.org>
3 * Copyright (c) 2005, 2006 Kjell Wooding <kjell@openbsd.org>
34 * All rights reserved.
45 *
56 * Redistribution and use in source and binary forms, with or without
4950 * Local functions
5051 */
5152 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 *);
5354 static struct undo_rec *new_undo_record(void);
5455 static int drop_oldest_undo_record(void);
5556
6768 int count = 0;
6869 struct line *p;
6970
70 for (p = curbp->b_linep; p != lp; p = lforw(p)) {
71 for (p = curbp->b_headp; p != lp; p = lforw(p)) {
7172 if (count != 0) {
72 if (p == curbp->b_linep) {
73 if (p == curbp->b_headp) {
7374 ewprintf("Error: Undo stuff called with a"
7475 "nonexistent line");
7576 return (FALSE);
8384 }
8485
8586 static int
86 find_lo(int pos, struct line **olp, int *offset)
87 find_lo(int pos, struct line **olp, int *offset, int *lnum)
8788 {
8889 struct line *p;
89
90 p = curbp->b_linep;
90 int lineno;
91
92 p = curbp->b_headp;
93 lineno = 0;
9194 while (pos > llength(p)) {
9295 pos -= llength(p) + 1;
93 if ((p = lforw(p)) == curbp->b_linep) {
96 if ((p = lforw(p)) == curbp->b_headp) {
9497 *olp = NULL;
9598 *offset = 0;
9699 return (FALSE);
97100 }
101 lineno++;
98102 }
99103 *olp = p;
100104 *offset = pos;
105 *lnum = lineno;
101106
102107 return (TRUE);
103108 }
202207
203208 /*
204209 * 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.
206211 */
207212 void
208213 undo_add_boundary(void)
209214 {
210215 struct undo_rec *rec;
216 int last;
211217
212218 if (nobound)
213219 return;
214220
215 if (lastrectype() == BOUNDARY)
221 last = lastrectype();
222 if (last == BOUNDARY || last == MODIFIED)
216223 return;
217224
218225 rec = new_undo_record();
219226 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;
220243
221244 LIST_INSERT_HEAD(&curbp->b_undo, rec, next);
222245
360383
361384 for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
362385 if (wp->w_bufp == bp) {
363 wp->w_dotp = bp->b_linep;
386 wp->w_dotp = bp->b_headp;
364387 wp->w_doto = 0;
365388 }
366389 }
373396 "%d:\t %s at %d ", num,
374397 (rec->type == DELETE) ? "DELETE":
375398 (rec->type == INSERT) ? "INSERT":
376 (rec->type == BOUNDARY) ? "----" : "UNKNOWN",
399 (rec->type == BOUNDARY) ? "----" :
400 (rec->type == MODIFIED) ? "MODIFIED": "UNKNOWN",
377401 rec->pos);
378402
379403 if (rec->content) {
437461 struct line *lp;
438462 int offset, save, dot;
439463 static int nulled = FALSE;
464 int lineno;
440465
441466 dot = find_dot(curwp->w_dotp, curwp->w_doto);
442467
485510 /*
486511 * Move to where this has to apply
487512 *
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...
491516 */
492 if (ptr->type != BOUNDARY) {
517 if (ptr->type != BOUNDARY && ptr->type != MODIFIED) {
493518 if (find_lo(ptr->pos, &lp,
494 &offset) == FALSE) {
519 &offset, &lineno) == FALSE) {
495520 ewprintf("Internal error in Undo!");
496521 rval = FALSE;
497522 break;
498523 }
499524 curwp->w_dotp = lp;
500525 curwp->w_doto = offset;
526 curwp->w_markline = curwp->w_dotline;
527 curwp->w_dotline = lineno;
501528 }
502529
503530 /*
514541 case BOUNDARY:
515542 done = 1;
516543 break;
544 case MODIFIED:
545 curbp->b_flag &= ~BFCHG;
546 break;
517547 default:
518548 break;
519549 }
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 $ */
11
22 /* This file is in the public domain. */
33
182182 }
183183 lp = curwp->w_linep;
184184 i = curwp->w_toprow;
185 while (i != 0 && lback(lp) != curbp->b_linep) {
185 while (i != 0 && lback(lp) != curbp->b_headp) {
186186 --i;
187187 lp = lback(lp);
188188 }
312312 /* shrink below */
313313 if (curwp->w_wndp == adjwp) {
314314 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)
316316 lp = lforw(lp);
317317 adjwp->w_linep = lp;
318318 adjwp->w_toprow += n;
319319 /* shrink above */
320320 } else {
321321 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)
323323 lp = lback(lp);
324324 curwp->w_linep = lp;
325325 curwp->w_toprow -= n;
365365 /* grow below */
366366 if (curwp->w_wndp == adjwp) {
367367 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)
369369 lp = lback(lp);
370370 adjwp->w_linep = lp;
371371 adjwp->w_toprow -= n;
372372 /* grow above */
373373 } else {
374374 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)
376376 lp = lforw(lp);
377377 curwp->w_linep = lp;
378378 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 $ */
11
22 /* This file is in the public domain. */
33
173173 nextp = lforw(curwp->w_dotp);
174174 i = n;
175175 while (--i) {
176 if (nextp == curbp->b_linep)
176 if (nextp == curbp->b_headp)
177177 break;
178178 chunk += llength(nextp) + 1;
179179 nextp = lforw(nextp);
184184 curwp->w_doto = 0;
185185 i = n;
186186 while (i++) {
187 if (lback(curwp->w_dotp) == curbp->b_linep)
187 if (lback(curwp->w_dotp) == curbp->b_headp)
188188 break;
189189 curwp->w_dotp = lback(curwp->w_dotp);
190190 curwp->w_flag |= WFMOVE;
244244
245245 /* if offscreen insert */
246246 if (curwp->w_dotp == lp) {
247 while (nline-- && lback(lp) != curbp->b_linep)
247 while (nline-- && lback(lp) != curbp->b_headp)
248248 lp = lback(lp);
249249 /* adjust framing */
250250 curwp->w_linep = lp;