Codebase list mg / upstream/20061222
Imported Upstream version 20061222 Andreas Beckmann 9 years ago
19 changed file(s) with 100 addition(s) and 127 deletion(s). Raw diff Collapse all Expand all
1414
1515
1616 CC= gcc
17 CFLAGS= -O2 -pipe
17 CFLAGS?= -O2 -pipe
1818 CFLAGS+= -g -Wall -Werror
1919 LDFLAGS= -lncurses
2020
0 /* $OpenBSD: autoexec.c,v 1.10 2005/10/14 19:46:46 kjell Exp $ */
0 /* $OpenBSD: autoexec.c,v 1.13 2006/12/20 21:31:45 deraadt Exp $ */
11 /* this file is in the public domain */
22 /* Author: Vincent Labrecque <vincent@openbsd.org> April 2002 */
33
1515 static SLIST_HEAD(, autoexec) autos;
1616 static int ready;
1717
18
19 #define AUTO_GROW 8
1820 /*
1921 * Return a NULL terminated array of function pointers to be called
2022 * when we open a file that matches <fname>. The list must be free(ed)
3638 SLIST_FOREACH(ae, &autos, next) {
3739 if (fnmatch(ae->pattern, fname, 0) == 0) {
3840 if (used >= have) {
39 npfl = realloc(pfl, (have + 8 + 1) * sizeof(PF));
41 npfl = realloc(pfl, (have + AUTO_GROW + 1) *
42 sizeof(PF));
4043 if (npfl == NULL)
4144 panic("out of memory");
4245 pfl = npfl;
43 have += 8;
46 have += AUTO_GROW;
4447 }
4548 pfl[used++] = ae->fp;
4649 }
4750 }
48 if (used) {
51 if (used)
4952 pfl[used] = NULL;
50 pfl = realloc(pfl, (used + 1) * sizeof(PF));
51 }
53
5254 return (pfl);
5355 }
5456
9294 else if (patp[0] == '\0')
9395 return (FALSE);
9496 if ((funcp = eread("Execute: ", funcbuf, sizeof(funcbuf),
95 EFNEW | EFCR)) == NULL)
97 EFNEW | EFCR | EFFUNC)) == NULL)
9698 return (ABORT);
9799 else if (funcp[0] == '\0')
98100 return (FALSE);
0 /* $OpenBSD: basic.c,v 1.27 2006/11/18 20:36:50 kjell Exp $ */
0 /* $OpenBSD: basic.c,v 1.28 2006/12/20 21:21:09 kjell Exp $ */
11
22 /* This file is in the public domain */
33
265265 n = 1; /* if tiny window. */
266266 } else if (n < 0)
267267 return (backpage(f | FFRAND, -n));
268 #ifdef CVMVAS
269 else /* Convert from pages */
270 n *= curwp->w_ntrows; /* to lines. */
271 #endif
272268 lp = curwp->w_linep;
273269 while (n-- && lforw(lp) != curbp->b_headp) {
274270 lp = lforw(lp);
308304 n = 1; /* window is tiny. */
309305 } else if (n < 0)
310306 return (forwpage(f | FFRAND, -n));
311 #ifdef CVMVAS
312 else /* Convert from pages */
313 n *= curwp->w_ntrows; /* to lines. */
314 #endif
315307 lp = curwp->w_linep;
316308 while (n-- && lback(lp) != curbp->b_headp) {
317309 lp = lback(lp);
0 /* $OpenBSD: buffer.c,v 1.65 2006/11/18 23:05:24 kjell Exp $ */
0 /* $OpenBSD: buffer.c,v 1.66 2006/11/19 16:51:19 deraadt Exp $ */
11
22 /* This file is in the public domain. */
33
496496 static struct buffer *
497497 bnew(const char *bname)
498498 {
499 struct buffer *bp;
499 struct buffer *bp;
500500 struct line *lp;
501501 int i;
502502
638638 int
639639 augbname(char *bn, char *fn, size_t bs)
640640 {
641 int count;
641 int count;
642642 size_t remain, len;
643643
644644 len = strlcpy(bn, basename(fn), bs);
0 #define FKEYS
1 #define REGEX
2 #define XKEYS
3 #define HAVE_ARC4RANDOM
2929 # FKEYS -- add support for function key sequences.
3030 # XKEYS -- use termcap function key definitions.
3131 # Warning: XKEYS and bsmap mode do _not_ get along.
32 # PREFIXREGION -- enable function "prefix-region"
3332 # REGEX -- create regular expression functions
3433
3534 cat << EOF > config.h
3635 #define FKEYS
37 #define PREFIXREGION
3836 #define REGEX
3937 #define XKEYS
4038 EOF
7573 int main(void)
7674 {strtonum(NULL, 1, 1, NULL);return 0;}
7775 EOF
78 if gcc testfile.c -o testfile 2>&3; then
76 if gcc -Wall testfile.c -o testfile 2>&3; then
7977 echo 'Found.'
8078 else
8179 echo 'Not Found, adding.'
9088 int main(void)
9189 {strlcpy(NULL, NULL, 1);return 0;}
9290 EOF
93 if gcc testfile.c -o testfile 2>&3; then
91 if gcc -Wall testfile.c -o testfile 2>&3; then
9492 echo 'Found.'
9593 else
9694 echo 'Not Found, adding.'
151149 extraflags="$extraflags -I/usr/$i/include"
152150 break
153151 fi
154 echo 'Not found!'
155 echo 'If you know where term.h is, please email the author!'
152 echo 'Not found!' >&2
153 echo 'Do you have the ncurses devel package installed?' >&2
154 echo 'If you know where term.h is, please email the author!' >&2
156155 exit 1
157156 done
158157 fi
0 /* $OpenBSD: def.h,v 1.97 2006/11/17 08:45:31 kjell Exp $ */
0 /* $OpenBSD: def.h,v 1.98 2006/11/19 16:51:19 deraadt Exp $ */
11
22 /* This file is in the public domain. */
33
4646 #define TRUE 1 /* True, yes, good, etc. */
4747 #define ABORT 2 /* Death, ^G, abort, etc. */
4848
49 #define KCLEAR 2 /* clear echo area */
49 #define KCLEAR 2 /* clear echo area */
5050
5151 /*
5252 * These flag bits keep track of
0 /* $OpenBSD: dired.c,v 1.41 2006/07/25 08:27:09 kjell Exp $ */
0 /* $OpenBSD: dired.c,v 1.42 2006/11/01 06:02:29 ray Exp $ */
11
22 /* This file is in the public domain. */
33
635635 }
636636 line[0] = line[1] = ' ';
637637 while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) {
638 line[strlen(line) - 1] = '\0'; /* remove ^J */
638 char *p;
639
640 if ((p = strchr(line, '\n')) != NULL)
641 *p = '\0'; /* remove ^J */
639642 (void) addline(bp, line);
640643 }
641644 if (pclose(dirpipe) == -1) {
0 /* $OpenBSD: display.c,v 1.30 2006/07/25 08:22:32 kjell Exp $ */
0 /* $OpenBSD: display.c,v 1.32 2006/12/20 21:31:45 deraadt Exp $ */
11
22 /* This file is in the public domain. */
33
102102
103103 #ifndef LINENOMODE
104104 #define LINENOMODE TRUE
105 #endif /* !LINENOMODE */
106 static int linenos = LINENOMODE;
105 #endif /* !LINENOMODE */
106 static int linenos = LINENOMODE;
107107
108108 /*
109109 * Since we don't have variables (we probably should) this is a command
118118 else
119119 linenos = !linenos;
120120
121 sgarbf = TRUE;
121 sgarbf = TRUE;
122122
123123 return (TRUE);
124124 }
0 /* $OpenBSD: extend.c,v 1.48 2006/07/25 08:27:09 kjell Exp $ */
0 /* $OpenBSD: extend.c,v 1.49 2006/12/21 18:18:13 kjell Exp $ */
11
22 /* This file is in the public domain. */
33
9090 * Structure assignments would come in real handy, but K&R based compilers
9191 * don't have them. Care is taken so running out of memory will leave
9292 * the keymap in a usable state.
93 * Parameters are:
94 * curmap: pointer to the map being changed
95 * c: character being changed
96 * funct: function being changed to
97 * pref_map: if funct==NULL, map to bind to or NULL for new
9398 */
9499 static int
95 remap(KEYMAP *curmap, /* pointer to the map being changed */
96 int c, /* character being changed */
97 PF funct, /* function being changed to */
98 KEYMAP *pref_map) /* if funct==NULL, map to bind to or NULL for new */
100 remap(KEYMAP *curmap, int c, PF funct, KEYMAP *pref_map)
99101 {
100102 int i, n1, n2, nold;
101103 KEYMAP *mp, *newmap;
221223 n2 = 1;
222224 for (i = 0; n2 && i < n1; i++)
223225 n2 &= ele->k_funcp[i] != NULL;
224 if (curmap->map_num >= curmap->map_max &&
225 (curmap = reallocmap(curmap)) == NULL)
226 return (FALSE);
226 if (curmap->map_num >= curmap->map_max) {
227 if ((newmap = reallocmap(curmap)) == NULL)
228 return (FALSE);
229 curmap = newmap;
230 }
227231 if ((pfp = calloc(ele->k_num - c + !n2,
228232 sizeof(PF))) == NULL) {
229233 ewprintf("Out of memory");
265269 }
266270
267271 /*
268 * Reallocate a keymap, used above.
272 * Reallocate a keymap. Returns NULL (without trashing the current map)
273 * on failure.
269274 */
270275 static KEYMAP *
271276 reallocmap(KEYMAP *curmap)
0 /* $OpenBSD: fileio.c,v 1.78 2006/09/19 05:52:23 otto Exp $ */
0 /* $OpenBSD: fileio.c,v 1.79 2006/11/19 16:51:19 deraadt Exp $ */
11
22 /* This file is in the public domain. */
33
112112 {
113113 struct line *lp, *lp2, *lpend;
114114 int emptylines = 0;
115 int ret;
116115
117116 lpend = bp->b_headp;
118117
119 /* This stuff is to make sure there is exactly one trailing \n at the
120 * end of the buffer. */
121
122 /* XXX make this stuff work with flags once we have them. */
118 /*
119 * This stuff is to make sure there is exactly one trailing \n at the
120 * end of the buffer.
121
122 * Since I assume 99.99% of all files are best of with exactly one
123 * trailing \n I'll make that the default behaviour, no questions asked.
124 */
123125
124126 /* Scroll backwards to the last nonempty line. Stop if the buffer
125127 * contains only empty lines. */
132134 return(FIOERR);
133135 else {
134136 if (emptylines == 0) {
135 ret = eyorn("No newline at end of file, add one");
136 switch(ret) {
137 case(ABORT): /* c-g is pressed */
138 return(FIOERR);
139 case(TRUE):
140 lnewline_at(lback(lpend), llength(lback(lpend)));
141 break;
142 default:
143 break;
144 }
137 lnewline_at(lback(lpend), llength(lback(lpend)));
145138 } else if (emptylines > 1) {
146 ret = eyorn("Trailing newlines at end of file,"
147 " remove them");
148 switch(ret) {
149 case(ABORT): /* c-g is pressed */
150 return(FIOERR);
151 case(TRUE):
152 /* Step to the desired end of the buffer. */
153 lp = lforw(lp);
154 lp = lforw(lp);
155 /* And remove the remaining newlines, use extra
156 * pointer to make sure we don't step on a freed
157 * line. */
158 while(lp != lpend) {
159 lp2 = lforw(lp);
160 lfree(lp);
161 lp = lp2;
162 }
163 break;
164 default:
165 break;
139 /* Step to the desired end of the buffer. */
140 lp = lforw(lp);
141 lp = lforw(lp);
142 /* And remove the remaining newlines, use extra pointer
143 * to make sure we don't step on a freed line. */
144 while(lp != lpend) {
145 lp2 = lforw(lp);
146 lfree(lp);
147 lp = lp2;
166148 }
167149 }
168150 }
475457 char prefixx[NFILEN + 1];
476458
477459 /*
478 * We need three different strings: dir - the name of the directory
479 * containing what the user typed. Must be a real unix file name,
480 * e.g. no ~user, etc.. Must not end in /. prefix - the portion of
481 * what the user typed that is before the names we are going to find
482 * in the directory. Must have a trailing / if the user typed it.
483 * names from the directory. We open dir, and return prefix
460 * We need three different strings:
461
462 * dir - the name of the directory containing what the user typed.
463 * Must be a real unix file name, e.g. no ~user, etc..
464 * Must not end in /.
465 * prefix - the portion of what the user typed that is before the
466 * names we are going to find in the directory. Must have a
467 * trailing / if the user typed it.
468 * names from the directory - We open dir, and return prefix
484469 * concatenated with names.
485470 */
486471
487472 /* first we get a directory name we can look up */
488473 /*
489474 * Names ending in . are potentially odd, because adjustname will
490 * treat foo/.. as a reference to another directory, whereas we are
475 * treat foo/bar/.. as a foo/, whereas we are
491476 * interested in names starting with ..
492477 */
493478 len = strlen(buf);
494 if (buf[len - 1] == '.') {
479 if (len && buf[len - 1] == '.') {
495480 buf[len - 1] = 'x';
496481 dir = adjustname(buf, TRUE);
497482 buf[len - 1] = '.';
503488 * If the user typed a trailing / or the empty string
504489 * he wants us to use his file spec as a directory name.
505490 */
506 if (buf[0] && buf[strlen(buf) - 1] != '/') {
491 if (len && buf[len - 1] != '/') {
507492 file = strrchr(dir, '/');
508493 if (file) {
509494 *file = '\0';
531516 * SV files are fairly short. For BSD, something more general would
532517 * be required.
533518 */
534 if ((preflen + MAXNAMLEN) > NFILEN)
519 if (preflen > NFILEN - MAXNAMLEN)
535520 return (NULL);
536521
537522 /* loop over the specified directory, making up the list of files */
0 /* $OpenBSD: funmap.c,v 1.24 2006/06/01 09:00:50 kjell Exp $ */
0 /* $OpenBSD: funmap.c,v 1.26 2006/12/21 18:06:02 kjell Exp $ */
11 /*
22 * Copyright (c) 2001 Artur Grabowski <art@openbsd.org>. All rights reserved.
33 *
5353 {gotobol, "beginning-of-line",},
5454 {blinkparen, "blink-matching-paren",},
5555 {showmatch, "blink-matching-paren-hack",},
56 #ifdef BSMAP
5756 {bsmap, "bsmap-mode",},
58 #endif /* BSMAP */
5957 {NULL, "c-x 4 prefix",},
6058 {NULL, "c-x prefix",},
6159 #ifndef NO_MACRO
147145 {openline, "open-line",},
148146 {nextwind, "other-window",},
149147 {overwrite_mode, "overwrite-mode",},
150 #ifdef PREFIXREGION
151148 {prefixregion, "prefix-region",},
152 #endif /* PREFIXREGION */
153149 {backline, "previous-line",},
154150 {prevwind, "previous-window",},
155151 {spawncli, "push-shell",},
185181 {set_default_mode, "set-default-mode",},
186182 {setfillcol, "set-fill-column",},
187183 {setmark, "set-mark-command",},
188 #ifdef PREFIXREGION
189184 {setprefix, "set-prefix-string",},
190 #endif /* PREFIXREGION */
191185 {shrinkwind, "shrink-window",},
192186 #ifdef NOTAB
193187 {space_to_tabstop, "space-to-tabstop",},
0 /* $OpenBSD: grep.c,v 1.32 2006/07/25 08:27:09 kjell Exp $ */
0 /* $OpenBSD: grep.c,v 1.33 2006/11/19 16:51:19 deraadt Exp $ */
11 /*
22 * Copyright (c) 2001 Artur Grabowski <art@openbsd.org>.
33 * Copyright (c) 2005 Kjell Wooding <kjell@openbsd.org>.
310310 /* last line is compilation result */
311311 if (curwp->w_dotp == last)
312312 return (FALSE);
313
313
314314 if ((line = linetostr(curwp->w_dotp)) == NULL)
315315 return (FALSE);
316316 lp = line;
0 /* $OpenBSD: kbd.c,v 1.22 2006/04/03 02:43:22 kjell Exp $ */
0 /* $OpenBSD: kbd.c,v 1.23 2006/12/21 18:06:02 kjell Exp $ */
11
22 /* This file is in the public domain. */
33
4444 return (TRUE);
4545 }
4646
47 #ifdef BSMAP
48 static int bs_map = BSMAP;
47 static int bs_map = 0;
48
4949 /*
5050 * Toggle backspace mapping
5151 */
5959 ewprintf("Backspace mapping %sabled", bs_map ? "en" : "dis");
6060 return (TRUE);
6161 }
62 #endif /* BSMAP */
6362
6463 void
6564 ungetkey(int c)
9493 pushed = FALSE;
9594 } else
9695 c = ttgetc();
97 #ifdef BSMAP
98 if (bs_map)
96
97 if (bs_map) {
9998 if (c == CCHR('H'))
10099 c = CCHR('?');
101100 else if (c == CCHR('?'))
102101 c = CCHR('H');
103 #endif /* BSMAP */
102 }
104103 if (use_metakey && (c & METABIT)) {
105104 pushedc = c & ~METABIT;
106105 pushed = TRUE;
0 /* $OpenBSD: kbd.h,v 1.17 2005/11/18 20:56:53 deraadt Exp $ */
0 /* $OpenBSD: kbd.h,v 1.18 2006/07/27 19:59:29 deraadt Exp $ */
11
22 /* This file is in the public domain. */
33
0 /* $OpenBSD: main.c,v 1.54 2006/07/25 08:22:32 kjell Exp $ */
0 /* $OpenBSD: main.c,v 1.55 2006/11/19 16:51:19 deraadt Exp $ */
11
22 /* This file is in the public domain. */
33
1919 int lastflag; /* flags, last command */
2020 int curgoal; /* goal column */
2121 int startrow; /* row to start */
22 struct buffer *curbp; /* current buffer */
23 struct buffer *bheadp; /* BUFFER list head */
24 struct mgwin *curwp; /* current window */
25 struct mgwin *wheadp; /* MGWIN listhead */
22 struct buffer *curbp; /* current buffer */
23 struct buffer *bheadp; /* BUFFER list head */
24 struct mgwin *curwp; /* current window */
25 struct mgwin *wheadp; /* MGWIN listhead */
2626 char pat[NPAT]; /* pattern */
2727
2828 static void edinit(PF);
0 /* $OpenBSD: region.c,v 1.24 2006/07/25 08:22:32 kjell Exp $ */
0 /* $OpenBSD: region.c,v 1.25 2006/12/16 17:00:03 kjell Exp $ */
11
22 /* This file is in the public domain. */
33
239239 return (TRUE);
240240 }
241241
242 #ifdef PREFIXREGION
243 /*
244 * Implements one of my favorite keyboard macros; put a string at the
245 * beginning of a number of lines in a buffer. The quote string is
246 * settable by using set-prefix-string. Great for quoting mail, which
247 * is the real reason I wrote it, but also has uses for creating bar
248 * comments (like the one you're reading) in C code.
249 */
250
251242 #define PREFIXLENGTH 40
252243 static char prefix_string[PREFIXLENGTH] = {'>', '\0'};
253244
297288 }
298289
299290 /*
300 * Set line prefix string.
291 * Set line prefix string. Used by prefixregion.
301292 */
302293 /* ARGSUSED */
303294 int
324315 retval = FALSE;
325316 return (retval);
326317 }
327 #endif /* PREFIXREGION */
328318
329319 int
330320 region_get_data(struct region *reg, char *buf, int len)
0 /* $OpenBSD: undo.c,v 1.42 2006/11/17 08:45:31 kjell Exp $ */
0 /* $OpenBSD: undo.c,v 1.43 2006/11/19 16:51:19 deraadt Exp $ */
11 /*
22 * Copyright (c) 2002 Vincent Labrecque <vincent@openbsd.org>
33 * Copyright (c) 2005, 2006 Kjell Wooding <kjell@openbsd.org>
3535 static LIST_HEAD(, undo_rec) undo_free;
3636 static int undo_free_num;
3737 static int boundary_flag = TRUE;
38 static int undo_enable_flag = TRUE;
38 static int undo_enable_flag = TRUE;
3939
4040 /*
4141 * Local functions
0 /* $OpenBSD: yank.c,v 1.5 2006/11/17 08:45:31 kjell Exp $ */
0 /* $OpenBSD: yank.c,v 1.6 2006/11/19 16:51:19 deraadt Exp $ */
11
22 /* This file is in the public domain. */
33
4141 * that if you put something in the kill buffer you are going to put more
4242 * stuff there too later. Return TRUE if all is well, and FALSE on errors.
4343 * Print a message on errors. Dir says whether to put it at back or front.
44 * This call is ignored if KNONE is set.
44 * This call is ignored if KNONE is set.
4545 */
4646 int
4747 kinsert(int c, int dir)