vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I have two diffs. The first is a huge cleanup diff of the dired code, and everything I saw while cleaning it up. The second (next message) is a revised version of Han's suggestion (i.e. make mg open directories in dired mode.), and must be applied after the first one to work correctly. Diff 1/2. Dired cleanup diff: The main changes here are: * move dired keybinding code out of keymap.c (as it was overridden by a less-capable version in dired.c) and into dired.c, replacing what used to be there. * change the initialization of the dired keymap (this was the main bug affecting Han's patch) to always happen. * remove some redundant code (pointed out by Han) and fix some style nits * make dired mode work. tagged deletions didn't * (make mail.c initialization consistent, since I am here.) Index: buffer.c ================================================== ================= RCS file: /usr/local/ocvs/src/usr.bin/mg/buffer.c,v retrieving revision 1.46 diff -u -r1.46 buffer.c --- buffer.c 11 Oct 2005 01:08:52 -0000 1.46 +++ buffer.c 11 Oct 2005 09:31:55 -0000 @@ -15,17 +15,16 @@ int togglereadonly(int f, int n) { - if (!(curbp->b_flag & BFREADONLY)) { + if (!(curbp->b_flag & BFREADONLY)) curbp->b_flag |= BFREADONLY; - ewprintf("Now readonly"); - } else { + else { curbp->b_flag &=~ BFREADONLY; if (curbp->b_flag & BFCHG) ewprintf("Warning: Buffer was modified"); } curwp->w_flag |= WFMODE; - return (1); + return (TRUE); } /* @@ -386,7 +385,7 @@ } /* - * The argument "text" points to a format string. Append this line to the + * The argument "fmt" points to a format string. Append this line to the * buffer. Handcraft the EOL on the end. Return TRUE if it worked and * FALSE if you ran out of room. */ Index: dired.c ================================================== ================= RCS file: /usr/local/ocvs/src/usr.bin/mg/dired.c,v retrieving revision 1.22 diff -u -r1.22 dired.c --- dired.c 11 Oct 2005 01:28:29 -0000 1.22 +++ dired.c 11 Oct 2005 09:38:59 -0000 @@ -19,113 +19,127 @@ #ifndef NO_DIRED -int d_findfile(int, int); +void dired_init(void); -static PF dired_cmds_1[] = { - forwline, /* space */ - d_shell_command, /* ! */ - rescan, /* " */ - rescan, /* # */ - rescan, /* $ */ - rescan, /* % */ - rescan, /* & */ - rescan, /* ' */ - rescan, /* ( */ - rescan, /* ) */ - rescan, /* * */ - d_create_directory /* + */ -}; - -static PF dired_cmds_2[] = { - rescan, /* a */ - rescan, /* b */ - rescan, /* c */ - rescan, /* d */ - d_findfile, /* e */ - d_findfile, /* f */ - rescan, /* g */ - rescan, /* h */ - rescan, /* i */ - rescan, /* j */ - rescan, /* k */ - rescan, /* l */ - rescan, /* m */ - forwline, /* n */ - d_ffotherwindow, /* o */ - rescan, /* p */ - rescan, /* q */ - rescan, /* r */ - rescan, /* s */ - rescan, /* t */ - rescan, /* u */ - d_findfile, /* v */ - rescan, /* w */ - d_expunge, /* x */ - rescan, /* y */ - rescan /* z */ -}; - -static PF dired_cmds_3[] = { - rescan, /* A */ - rescan, /* B */ - d_copy, /* C */ - d_del, /* D */ - rescan, /* E */ - rescan, /* F */ - rescan, /* G */ - rescan, /* H */ - rescan, /* I */ - rescan, /* J */ - rescan, /* K */ - rescan, /* L */ - rescan, /* M */ - rescan, /* N */ - rescan, /* O */ - rescan, /* P */ - rescan, /* Q */ - d_rename, /* R */ - rescan, /* S */ - rescan, /* T */ - rescan, /* U */ - d_findfile, /* V */ - rescan, /* W */ - d_expunge, /* X */ - rescan, /* Y */ - rescan /* Z */ +extern struct keymap_s helpmap, cXmap, metamap; + +static PF dirednul[] = { + setmark, /* ^@ */ + gotobol, /* ^A */ + backchar, /* ^B */ + rescan, /* ^C */ + d_del, /* ^D */ + gotoeol, /* ^E */ + forwchar, /* ^F */ + ctrlg, /* ^G */ +#ifndef NO_HELP + NULL, /* ^H */ +#endif /* !NO_HELP */ }; -static PF dired_pf[] = { +static PF diredcl[] = { + reposition, /* ^L */ d_findfile, /* ^M */ - rescan, /* ^N */ - d_findfile /* ^O */ + forwline, /* ^N */ + rescan, /* ^O */ + backline, /* ^P */ + rescan, /* ^Q */ + backisearch, /* ^R */ + forwisearch, /* ^S */ + rescan, /* ^T */ + universal_argument, /* ^U */ + forwpage, /* ^V */ + rescan, /* ^W */ + NULL /* ^X */ +}; + +static PF diredcz[] = { + spawncli, /* ^Z */ + NULL, /* esc */ + rescan, /* ^\ */ + rescan, /* ^] */ + rescan, /* ^^ */ + rescan, /* ^_ */ + forwline /* SP */ +}; + +static PF diredc[] = { + d_copy, /* c */ + d_del, /* d */ + d_findfile, /* e */ + d_findfile /* f */ +}; + +static PF diredn[] = { + forwline, /* n */ + d_ffotherwindow, /* o */ + backline, /* p */ + rescan, /* q */ + d_rename, /* r */ + rescan, /* s */ + rescan, /* t */ + d_undel, /* u */ + rescan, /* v */ + rescan, /* w */ + d_expunge /* x */ +}; + +static PF direddl[] = { + d_undelbak /* del */ }; -static struct KEYMAPE (4 + IMAPEXT) diredmap = { - 4, - 4 + IMAPEXT, +#ifndef DIRED_XMAPS +#define NDIRED_XMAPS 0 /* number of extra map sections */ +#endif /* DIRED_XMAPS */ + +static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = { + 6 + NDIRED_XMAPS, + 6 + NDIRED_XMAPS + IMAPEXT, rescan, { - { CCHR('M'), CCHR('O'), dired_pf, NULL }, - { ' ', '+', dired_cmds_1, NULL }, - { 'A', 'Z', dired_cmds_3, NULL }, - { 'a', 'z', dired_cmds_2, NULL } +#ifndef NO_HELP + { + CCHR('@'), CCHR('H'), dirednul, (KEYMAP *) & helpmap + }, +#else /* !NO_HELP */ + { + CCHR('@'), CCHR('G'), dirednul, NULL + }, +#endif /* !NO_HELP */ + { + CCHR('L'), CCHR('X'), diredcl, (KEYMAP *) & cXmap + }, + { + CCHR('Z'), ' ', diredcz, (KEYMAP *) & metamap + }, + { + 'c', 'f', diredc, NULL + }, + { + 'n', 'x', diredn, NULL + }, + { + CCHR('?'), CCHR('?'), direddl, NULL + }, +#ifdef DIRED_XMAPS + DIRED_XMAPS, /* map sections for dired mode keys */ +#endif /* DIRED_XMAPS */ } }; +void +dired_init(void) +{ + maps_add((KEYMAP *)&diredmap, "dired"); +} /* ARGSUSED */ int dired(int f, int n) { - static int inited = 0; char dirname[NFILEN], *bufp, *slash; BUFFER *bp; - if (inited == 0) { - maps_add((KEYMAP *)&diredmap, "dired"); - inited = 1; - } - if (curbp->b_fname && curbp->b_fname[0] != '\0') { (void)strlcpy(dirname, curbp->b_fname, sizeof(dirname)); if ((slash = strrchr(dirname, '/')) != NULL) { @@ -143,9 +157,7 @@ return (FALSE); if ((bp = dired_(bufp)) == NULL) return (FALSE); - bp->b_modes[0] = name_mode("fundamental"); - bp->b_modes[1] = name_mode("dired"); - bp->b_nmodes = 1; + curbp = bp; return (showbuffer(bp, curwp, WFHARD | WFMODE)); } @@ -154,11 +166,20 @@ int d_otherwindow(int f, int n) { - char dirname[NFILEN], *bufp; + char dirname[NFILEN], *bufp, *slash; BUFFER *bp; MGWIN *wp; - dirname[0] = '\0'; + if (curbp->b_fname && curbp->b_fname[0] != '\0') { + (void)strlcpy(dirname, curbp->b_fname, sizeof(dirname)); + if ((slash = strrchr(dirname, '/')) != NULL) { + *(slash + 1) = '\0'; + } + } else { + if (getcwd(dirname, sizeof(dirname)) == NULL) + dirname[0] = '\0'; + } + if ((bufp = eread("Dired other window: ", dirname, NFILEN, EFDEF | EFNEW | EFCR)) == NULL) return (ABORT); Index: file.c ================================================== ================= RCS file: /usr/local/ocvs/src/usr.bin/mg/file.c,v retrieving revision 1.38 diff -u -r1.38 file.c --- file.c 9 Aug 2005 00:53:48 -0000 1.38 +++ file.c 11 Oct 2005 09:32:52 -0000 @@ -42,6 +42,7 @@ { BUFFER *bp; char fname[NFILEN], *bufp, *adjf, *slash; + int status; if (curbp->b_fname && curbp->b_fname[0] != '\0') { strlcpy(fname, curbp->b_fname, sizeof(fname)); @@ -66,9 +67,7 @@ curbp = bp; if (showbuffer(bp, curwp, WFHARD) != TRUE) return (FALSE); - if (bp->b_fname[0] == 0) { - int status; - + if (bp->b_fname[0] == '\0') { if ((status = readin(adjf)) != TRUE) killbuffer(bp); return (status); @@ -147,6 +146,7 @@ BUFFER *bp; MGWIN *wp; char fname[NFILEN], *adjf, *bufp; + int status; if ((bufp = eread("Find file in other window: ", fname, NFILEN, EFNEW | EFCR | EFFILE)) == NULL) @@ -162,9 +162,7 @@ return (FALSE); curbp = bp; curwp = wp; - if (bp->b_fname[0] == 0) { - int status; - + if (bp->b_fname[0] == '\0') { if ((status = readin(adjf)) != TRUE) killbuffer(bp); return (status); @@ -258,8 +256,10 @@ */ /* - * Insert a file in the current buffer, after dot. Set mark at the end of - * the text inserted; point at the beginning. Return a standard status. + * Insert a file in the current buffer, after dot. If file is a directory, + * and 'replacebuf' is TRUE, invoke dired mode, else die with an error. + * If file is a regular file, set mark at the end of the text inserted; + * point at the beginning. Return a standard status. * Print a summary (lines read, error message) out as well. Unless the * NO_BACKUP conditional is set, this routine also does the read end of * backup processing. The BFBAK flag, if set in a buffer, says that a @@ -270,7 +270,7 @@ static int linesize = 0; int -insertfile(char *fname, char *newname, int needinfo) +insertfile(char *fname, char *newname, int replacebuf) { BUFFER *bp; LINE *lp1, *lp2; @@ -279,7 +279,7 @@ int nbytes, s, nline, siz, x = -1, x2; int opos; /* offset we started at */ - if (needinfo) + if (replacebuf == TRUE) x = undo_enable(FALSE); lp1 = NULL; @@ -296,7 +296,7 @@ (void)strlcpy(bp->b_fname, newname, sizeof bp->b_fname); /* hard file open */ - if ((s = ffropen(fname, needinfo ? bp : NULL)) == FIOERR) + if ((s = ffropen(fname, (replacebuf == TRUE) ? bp : NULL)) == FIOERR) goto out; if (s == FIOFNF) { /* file not found */ @@ -431,10 +431,9 @@ } } } - if (x != -1) - undo_enable(x); + undo_enable(x); - /* return false if error */ + /* return FALSE if error */ return (s != FIOERR); } Index: fileio.c ================================================== ================= RCS file: /usr/local/ocvs/src/usr.bin/mg/fileio.c,v retrieving revision 1.50 diff -u -r1.50 fileio.c --- fileio.c 14 Jun 2005 18:14:40 -0000 1.50 +++ fileio.c 11 Oct 2005 09:31:55 -0000 @@ -456,6 +456,7 @@ strlcpy(fn, curbp->b_fname, len); p = lp->l_text; ep = lp->l_text + llength(lp); + p++; /* skip action letter, if any */ for (i = 0; i < NAME_FIELD; i++) { while (p < ep && isspace(*p)) p++; Index: keymap.c ================================================== ================= RCS file: /usr/local/ocvs/src/usr.bin/mg/keymap.c,v retrieving revision 1.32 diff -u -r1.32 keymap.c --- keymap.c 11 Oct 2005 00:50:00 -0000 1.32 +++ keymap.c 11 Oct 2005 09:31:55 -0000 @@ -26,7 +26,7 @@ desckey /* c */ }; -static struct KEYMAPE (2 + IMAPEXT) helpmap = { +struct KEYMAPE (2 + IMAPEXT) helpmap = { 2, 2 + IMAPEXT, rescan, @@ -146,7 +146,7 @@ }; #ifndef NO_MACRO -static struct KEYMAPE (6 + IMAPEXT) cXmap = { +struct KEYMAPE (6 + IMAPEXT) cXmap = { 6, 6 + IMAPEXT, #else /* !NO_MACRO */ @@ -252,7 +252,7 @@ delbword /* DEL */ }; -static struct KEYMAPE (8 + IMAPEXT) metamap = { +struct KEYMAPE (8 + IMAPEXT) metamap = { 8, 8 + IMAPEXT, rescan, @@ -443,112 +443,10 @@ } }; -#ifndef NO_DIRED -static PF dirednul[] = { - setmark, /* ^@ */ - gotobol, /* ^A */ - backchar, /* ^B */ - rescan, /* ^C */ - d_del, /* ^D */ - gotoeol, /* ^E */ - forwchar, /* ^F */ - ctrlg, /* ^G */ -#ifndef NO_HELP - NULL, /* ^H */ -#endif /* !NO_HELP */ -}; - -static PF diredcl[] = { - reposition, /* ^L */ - forwline, /* ^M */ - forwline, /* ^N */ - rescan, /* ^O */ - backline, /* ^P */ - rescan, /* ^Q */ - backisearch, /* ^R */ - forwisearch, /* ^S */ - rescan, /* ^T */ - universal_argument, /* ^U */ - forwpage, /* ^V */ - rescan, /* ^W */ - NULL /* ^X */ -}; - -static PF diredcz[] = { - spawncli, /* ^Z */ - NULL, /* esc */ - rescan, /* ^\ */ - rescan, /* ^] */ - rescan, /* ^^ */ - rescan, /* ^_ */ - forwline /* SP */ -}; - -static PF diredc[] = { - d_copy, /* c */ - d_del, /* d */ - d_findfile, /* e */ - d_findfile /* f */ -}; - -static PF diredn[] = { - forwline, /* n */ - d_ffotherwindow, /* o */ - backline, /* p */ - rescan, /* q */ - d_rename, /* r */ - rescan, /* s */ - rescan, /* t */ - d_undel, /* u */ - rescan, /* v */ - rescan, /* w */ - d_expunge /* x */ -}; - -static PF direddl[] = { - d_undelbak /* del */ -}; - -#ifndef DIRED_XMAPS -#define NDIRED_XMAPS 0 /* number of extra map sections */ -#endif /* DIRED_XMAPS */ - -static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = { - 6 + NDIRED_XMAPS, - 6 + NDIRED_XMAPS + IMAPEXT, - rescan, - { -#ifndef NO_HELP - { - CCHR('@'), CCHR('H'), dirednul, (KEYMAP *) & helpmap - }, -#else /* !NO_HELP */ - { - CCHR('@'), CCHR('G'), dirednul, NULL - }, -#endif /* !NO_HELP */ - { - CCHR('L'), CCHR('X'), diredcl, (KEYMAP *) & cXmap - }, - { - CCHR('Z'), ' ', diredcz, (KEYMAP *) & metamap - }, - { - 'c', 'f', diredc, NULL - }, - { - 'n', 'x', diredn, NULL - }, - { - CCHR('?'), CCHR('?'), direddl, NULL - }, -#ifdef DIRED_XMAPS - DIRED_XMAPS, /* map sections for dired mode keys */ -#endif /* DIRED_XMAPS */ - } -}; -#endif /* !NO_DIRED */ +/* + * The basic (root) keyboard map + */ MAPS fundamental_mode = { (KEYMAP *)&fundmap, "fundamental" }; /* @@ -574,9 +472,6 @@ #ifndef NO_HELP {(KEYMAP *) &helpmap, "help",}, #endif -#ifndef NO_DIRED - {(KEYMAP *) &diredmap, "dired",}, -#endif {NULL, NULL} }; @@ -596,6 +491,9 @@ } } +/* + * Insert a new (named) keymap at the head of the keymap list. + */ int maps_add(KEYMAP *map, const char *name) { Index: mail.c ================================================== ================= RCS file: /usr/local/ocvs/src/usr.bin/mg/mail.c,v retrieving revision 1.6 diff -u -r1.6 mail.c --- mail.c 9 Aug 2005 00:53:48 -0000 1.6 +++ mail.c 11 Oct 2005 09:31:55 -0000 @@ -10,6 +10,7 @@ #include "kbd.h" #include "funmap.h" +void mail_init(void); static int fake_self_insert(int, int); static int mail(int, int); Index: main.c ================================================== ================= RCS file: /usr/local/ocvs/src/usr.bin/mg/main.c,v retrieving revision 1.41 diff -u -r1.41 main.c --- main.c 9 Aug 2005 00:53:48 -0000 1.41 +++ main.c 11 Oct 2005 09:31:55 -0000 @@ -63,7 +63,12 @@ { extern void grep_init(void); extern void theo_init(void); + extern void mail_init(void); +#ifndef NO_DIRED + extern void dired_init(void); + dired_init(); +#endif /* !NO_DIRED */ grep_init(); theo_init(); mail_init(); |