To: vim-dev@vim.org Subject: Patch 5.6.067 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.6.067 Problem: When a file name contains a NL, the viminfo file is corrupted. Solution: Use viminfo_writestring() to convert the NL to CTRL-V n. Also fix the Buffers menu and listing a menu name with a newline. Files: runtime/menu.vim, src/buffer.c, src/mark.c, src/menu.c *** ../vim-5.6.66/runtime/menu.vim Wed Jan 12 20:53:26 2000 --- runtime/menu.vim Sat Apr 15 17:56:11 2000 *************** *** 3,9 **** " Note that ":amenu" is often used to make a menu work in all modes. " " Maintainer: Bram Moolenaar ! " Last change: 2000 Jan 02 " Make sure the '<' and 'C' flags are not included in 'cpoptions', otherwise " would not be recognized. See ":help 'cpoptions'". --- 3,9 ---- " Note that ":amenu" is often used to make a menu work in all modes. " " Maintainer: Bram Moolenaar ! " Last change: 2000 Apr 15 " Make sure the '<' and 'C' flags are not included in 'cpoptions', otherwise " would not be recognized. See ":help 'cpoptions'". *************** *** 69,75 **** if has("win32") vmenu 20.390 &Edit.&Deletex x endif ! amenu 20.400 &Edit.&Select\ allggvG :if &slm != ""exe ":norm gggHG"elseexe ":norm ggVG"endif amenu 20.405 &Edit.-SEP2- : if has("win32") || has("gui_gtk") amenu 20.410 &Edit.&Find\.\.\. :promptfind --- 69,75 ---- if has("win32") vmenu 20.390 &Edit.&Deletex x endif ! amenu 20.400 &Edit.&Select\ allggVG :if &slm != ""exe ":norm gggHG"elseexe ":norm ggVG"endif amenu 20.405 &Edit.-SEP2- : if has("win32") || has("gui_gtk") amenu 20.410 &Edit.&Find\.\.\. :promptfind *************** *** 246,252 **** endif let name = name2 . "\t" . fnamemodify(name,':h') endif ! let name = escape(name, '\\. |') return name endfunc --- 246,253 ---- endif let name = name2 . "\t" . fnamemodify(name,':h') endif ! let name = escape(name, "\\. \t|") ! let name = substitute(name, "\n", "^@", "g") return name endfunc *** ../vim-5.6.66/src/buffer.c Tue Apr 4 20:49:34 2000 --- src/buffer.c Sat Apr 15 17:39:00 2000 *************** *** 2607,2626 **** colnr_t col; BUF *buf; char_u *sfname; /* don't read in if there are files on the command-line or if writing: */ ! if (!writing && arg_file_count == 0 && find_viminfo_parameter('%') != NULL) { /* Format is: Tab Tab . * Watch out for a Tab in the file name, work from the end. */ lnum = 0; col = 0; ! tab = vim_strrchr(line + 1, '\t'); if (tab != NULL) { *tab++ = '\0'; col = atoi((char *)tab); ! tab = vim_strrchr(line + 1, '\t'); if (tab != NULL) { *tab++ = '\0'; --- 2607,2631 ---- colnr_t col; BUF *buf; char_u *sfname; + char_u *xline; + + /* Handle long line and escaped characters. */ + xline = viminfo_readstring(line + 1, fp); /* don't read in if there are files on the command-line or if writing: */ ! if (xline != NULL && !writing && arg_file_count == 0 ! && find_viminfo_parameter('%') != NULL) { /* Format is: Tab Tab . * Watch out for a Tab in the file name, work from the end. */ lnum = 0; col = 0; ! tab = vim_strrchr(xline, '\t'); if (tab != NULL) { *tab++ = '\0'; col = atoi((char *)tab); ! tab = vim_strrchr(xline, '\t'); if (tab != NULL) { *tab++ = '\0'; *************** *** 2630,2636 **** /* Expand "~/" in the file name at "line + 1" to a full path. * Then try shortening it by comparing with the current directory */ ! expand_env(line + 1, NameBuff, MAXPATHL); mch_dirname(IObuff, IOSIZE); sfname = shorten_fname(NameBuff, IObuff); if (sfname == NULL) --- 2635,2641 ---- /* Expand "~/" in the file name at "line + 1" to a full path. * Then try shortening it by comparing with the current directory */ ! expand_env(xline, NameBuff, MAXPATHL); mch_dirname(IObuff, IOSIZE); sfname = shorten_fname(NameBuff, IObuff); if (sfname == NULL) *************** *** 2644,2649 **** --- 2649,2655 ---- buflist_setfpos(buf, lnum, col); } } + vim_free(xline); return vim_fgets(line, LSIZE, fp); } *************** *** 2654,2663 **** --- 2660,2675 ---- { BUF *buf; WIN *win; + char_u *line; if (find_viminfo_parameter('%') == NULL) return; + /* Allocate room for the file name, lnum and col. */ + line = alloc(MAXPATHL + 30); + if (line == NULL) + return; + for (win = firstwin; win != NULL; win = win->w_next) set_last_cursor(win); *************** *** 2667,2677 **** if (buf->b_fname == NULL || buf->b_help || removable(buf->b_ffname)) continue; ! home_replace(NULL, buf->b_ffname, NameBuff, MAXPATHL, TRUE); ! ! fprintf(fp, "%%%s\t%ld\t%d\n", NameBuff, (long)buf->b_last_cursor.lnum, buf->b_last_cursor.col); } } #endif --- 2679,2690 ---- if (buf->b_fname == NULL || buf->b_help || removable(buf->b_ffname)) continue; ! putc('%', fp); ! home_replace(NULL, buf->b_ffname, line, MAXPATHL, TRUE); ! sprintf(line + STRLEN(line), "\t%ld\t%d", (long)buf->b_last_cursor.lnum, buf->b_last_cursor.col); + viminfo_writestring(fp, line); } } #endif *** ../vim-5.6.66/src/mark.c Thu Aug 19 22:18:52 1999 --- src/mark.c Sat Apr 15 17:38:44 2000 *************** *** 817,827 **** if (name == NULL) continue; ! fprintf(fp, "'%c %ld %ld %s\n", i < NMARKS ? i + 'A' : i - NMARKS + '0', (long)namedfm[i].mark.lnum, ! (long)namedfm[i].mark.col, ! name); if (namedfm[i].fnum) vim_free(name); } --- 817,827 ---- if (name == NULL) continue; ! fprintf(fp, "'%c %ld %ld ", i < NMARKS ? i + 'A' : i - NMARKS + '0', (long)namedfm[i].mark.lnum, ! (long)namedfm[i].mark.col); ! viminfo_writestring(fp, name); if (namedfm[i].fnum) vim_free(name); } *************** *** 902,908 **** buf->b_ffname[0] != NUL && !removable(buf->b_ffname)) { home_replace(NULL, buf->b_ffname, IObuff, IOSIZE, TRUE); ! fprintf(fp_out, "\n> %s\n", (char *)IObuff); if (buf->b_last_cursor.lnum != 0) fprintf(fp_out, "\t\"\t%ld\t%d\n", buf->b_last_cursor.lnum, buf->b_last_cursor.col); --- 902,909 ---- buf->b_ffname[0] != NUL && !removable(buf->b_ffname)) { home_replace(NULL, buf->b_ffname, IObuff, IOSIZE, TRUE); ! fprintf(fp_out, "\n> "); ! viminfo_writestring(fp_out, IObuff); if (buf->b_last_cursor.lnum != 0) fprintf(fp_out, "\t\"\t%ld\t%d\n", buf->b_last_cursor.lnum, buf->b_last_cursor.col); *************** *** 933,939 **** { BUF *buf; int num_marked_files; - char_u save_char; int load_marks; int copy_marks_out; char_u *str; --- 934,939 ---- *************** *** 960,975 **** } /* * Find file name, set str to start. * Ignore leading and trailing white space. */ str = skipwhite(line + 1); p = str + STRLEN(str); while (p != str && (*p == NUL || vim_isspace(*p))) p--; if (*p) p++; - save_char = *p; *p = NUL; /* --- 960,978 ---- } /* + * Handle long line and translate escaped characters. * Find file name, set str to start. * Ignore leading and trailing white space. */ str = skipwhite(line + 1); + str = viminfo_readstring(str, fp_in); + if (str == NULL) + continue; p = str + STRLEN(str); while (p != str && (*p == NUL || vim_isspace(*p))) p--; if (*p) p++; *p = NUL; /* *************** *** 1003,1014 **** if (buf == NULL || !buf->b_marks_read) { copy_marks_out = TRUE; ! *p = save_char; ! fputs("\n", fp_out); ! fputs((char *)line, fp_out); count++; } } while (!(eof = vim_fgets(line, LSIZE, fp_in)) && line[0] == TAB) { if (load_marks) --- 1006,1018 ---- if (buf == NULL || !buf->b_marks_read) { copy_marks_out = TRUE; ! fputs("\n> ", fp_out); ! viminfo_writestring(fp_out, str); count++; } } + vim_free(str); + while (!(eof = vim_fgets(line, LSIZE, fp_in)) && line[0] == TAB) { if (load_marks) *** ../vim-5.6.66/src/menu.c Sun Jan 16 16:32:33 2000 --- src/menu.c Sat Apr 15 17:51:40 2000 *************** *** 761,767 **** MSG_PUTS(" "); } /* Same highlighting as for directories!? */ ! msg_puts_attr(menu->name, hl_attr(HLF_D)); } if (menu != NULL && menu->children == NULL) --- 764,770 ---- MSG_PUTS(" "); } /* Same highlighting as for directories!? */ ! msg_outtrans_attr(menu->name, hl_attr(HLF_D)); } if (menu != NULL && menu->children == NULL) *** ../vim-5.6.66/src/version.c Thu Apr 13 12:02:05 2000 --- src/version.c Sat Apr 15 17:58:59 2000 *************** *** 420,421 **** --- 420,423 ---- { /* Add new patch number below this line */ + /**/ + 67, /**/ -- hundred-and-one symptoms of being an internet addict: 54. You start tilting your head sideways to smile. /-/-- Bram Moolenaar --- Bram@moolenaar.net --- http://www.moolenaar.net --\-\ \-\-- Vim: http://www.vim.org ---- ICCF Holland: http://www.vim.org/iccf --/-/