=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/vim/Attic/cmdcmds.c,v retrieving revision 1.1 retrieving revision 1.2 diff -c -r1.1 -r1.2 *** src/usr.bin/vim/Attic/cmdcmds.c 1996/09/07 21:40:26 1.1 --- src/usr.bin/vim/Attic/cmdcmds.c 1996/09/21 06:22:52 1.2 *************** *** 1,4 **** ! /* $OpenBSD: cmdcmds.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar --- 1,4 ---- ! /* $OpenBSD: cmdcmds.c,v 1.2 1996/09/21 06:22:52 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar *************** *** 16,35 **** #include "proto.h" #include "option.h" ! #ifdef USE_TMPNAM ! # define mktemp(a) tmpnam(a) ! #endif ! ! extern char *mktemp __ARGS((char *)); ! ! #ifdef OS2 ! static void check_tmpenv __ARGS((void)); ! #endif ! #ifdef VIMINFO static char_u *viminfo_filename __ARGS((char_u *)); ! static void do_viminfo __ARGS((FILE *fp_in, FILE *fp_out, int want_info, int want_marks, int force_read)); ! static int read_viminfo_up_to_marks __ARGS((char_u *line, FILE *fp, int force)); #endif /* VIMINFO */ void --- 16,29 ---- #include "proto.h" #include "option.h" ! static void do_filter __ARGS((linenr_t line1, linenr_t line2, ! char_u *buff, int do_in, int do_out)); #ifdef VIMINFO static char_u *viminfo_filename __ARGS((char_u *)); ! static void do_viminfo __ARGS((FILE *fp_in, FILE *fp_out, int want_info, ! int want_marks, int force_read)); ! static int read_viminfo_up_to_marks __ARGS((char_u *line, FILE *fp, ! int forceit)); #endif /* VIMINFO */ void *************** *** 41,46 **** --- 35,45 ---- char_u buf3[3]; c = gchar_cursor(); + if (c == NUL) + { + MSG("empty line"); + return; + } if (c == NL) /* NUL is stored as NL */ c = NUL; if (isprintchar(c) && (c < ' ' || c > '~')) *************** *** 142,152 **** } void ! do_retab(start, end, new_ts, force) linenr_t start; linenr_t end; int new_ts; ! int force; { linenr_t lnum; int got_tab = FALSE; --- 141,151 ---- } void ! do_retab(start, end, new_ts, forceit) linenr_t start; linenr_t end; int new_ts; ! int forceit; { linenr_t lnum; int got_tab = FALSE; *************** *** 189,195 **** } else { ! if (got_tab || (force && num_spaces > 1)) { /* Retabulate this string of white-space */ --- 188,194 ---- } else { ! if (got_tab || (forceit && num_spaces > 1)) { /* Retabulate this string of white-space */ *************** *** 506,525 **** AppendToRedobuff((char_u *)"\n"); bangredo = FALSE; } if (addr_count == 0) /* :! */ { /* echo the command */ msg_start(); msg_outchar(':'); msg_outchar('!'); ! msg_outtrans(prevcmd); msg_clr_eos(); windgoto(msg_row, msg_col); ! do_shell(prevcmd); } else /* :range! */ ! do_filter(line1, line2, prevcmd, do_in, do_out); } /* --- 505,538 ---- AppendToRedobuff((char_u *)"\n"); bangredo = FALSE; } + /* + * Add quotes around the command, for shells that need them. + */ + if (*p_shq != NUL) + { + newcmd = alloc((unsigned)(STRLEN(prevcmd) + 2 * STRLEN(p_shq) + 1)); + if (newcmd == NULL) + return; + STRCPY(newcmd, p_shq); + STRCAT(newcmd, prevcmd); + STRCAT(newcmd, p_shq); + } if (addr_count == 0) /* :! */ { /* echo the command */ msg_start(); msg_outchar(':'); msg_outchar('!'); ! msg_outtrans(newcmd); msg_clr_eos(); windgoto(msg_row, msg_col); ! do_shell(newcmd); } else /* :range! */ ! do_filter(line1, line2, newcmd, do_in, do_out); ! if (newcmd != prevcmd) ! vim_free(newcmd); } /* *************** *** 591,597 **** msg_pos((int)Rows - 1, 0); #ifdef AUTOCMD ! if (!autocmd_busy) #endif { /* --- 604,612 ---- msg_pos((int)Rows - 1, 0); #ifdef AUTOCMD ! if (autocmd_busy) ! must_redraw = CLEAR; ! else #endif { /* *************** *** 630,639 **** } #endif /* AMIGA */ } - #ifdef AUTOCMD - else - must_redraw = CLEAR; - #endif } /* --- 645,650 ---- *************** *** 649,669 **** * We use input redirection if do_in is TRUE. * We use output redirection if do_out is TRUE. */ ! void do_filter(line1, line2, buff, do_in, do_out) linenr_t line1, line2; char_u *buff; int do_in, do_out; { ! #ifdef USE_TMPNAM ! char_u itmp[L_tmpnam]; /* use tmpnam() */ ! char_u otmp[L_tmpnam]; ! #else ! char_u itmp[TMPNAMELEN]; ! char_u otmp[TMPNAMELEN]; ! #endif linenr_t linecount; FPOS cursor_save; /* * Disallow shell commands from .exrc and .vimrc in current directory for --- 660,678 ---- * We use input redirection if do_in is TRUE. * We use output redirection if do_out is TRUE. */ ! static void do_filter(line1, line2, buff, do_in, do_out) linenr_t line1, line2; char_u *buff; int do_in, do_out; { ! char_u *itmp = NULL; ! char_u *otmp = NULL; linenr_t linecount; FPOS cursor_save; + #ifdef AUTOCMD + BUF *old_curbuf = curbuf; + #endif /* * Disallow shell commands from .exrc and .vimrc in current directory for *************** *** 700,721 **** * 6. Remove the temp files */ ! #ifndef USE_TMPNAM /* tmpnam() will make its own name */ ! # ifdef OS2 ! check_tmpenv(); ! expand_env(TMPNAME1, itmp, TMPNAMELEN); ! expand_env(TMPNAME2, otmp, TMPNAMELEN); ! # else ! STRCPY(itmp, TMPNAME1); ! STRCPY(otmp, TMPNAME2); ! # endif ! #endif ! ! if ((do_in && *mktemp((char *)itmp) == NUL) || ! (do_out && *mktemp((char *)otmp) == NUL)) { emsg(e_notmp); ! return; } /* --- 709,719 ---- * 6. Remove the temp files */ ! if ((do_in && (itmp = vim_tempname('i')) == NULL) || ! (do_out && (otmp = vim_tempname('o')) == NULL)) { emsg(e_notmp); ! goto filterend; } /* *************** *** 724,736 **** */ ++no_wait_return; /* don't call wait_return() while busy */ if (do_in && buf_write(curbuf, itmp, NULL, line1, line2, ! FALSE, 0, FALSE, TRUE) == FAIL) { msg_outchar('\n'); /* keep message from buf_write() */ --no_wait_return; (void)emsg2(e_notcreate, itmp); /* will call wait_return */ goto filterend; } if (!do_out) msg_outchar('\n'); --- 722,739 ---- */ ++no_wait_return; /* don't call wait_return() while busy */ if (do_in && buf_write(curbuf, itmp, NULL, line1, line2, ! FALSE, FALSE, FALSE, TRUE) == FAIL) { msg_outchar('\n'); /* keep message from buf_write() */ --no_wait_return; (void)emsg2(e_notcreate, itmp); /* will call wait_return */ goto filterend; } + #ifdef AUTOCMD + if (curbuf != old_curbuf) + goto filterend; + #endif + if (!do_out) msg_outchar('\n'); *************** *** 754,768 **** { char_u *p; /* ! * If there is a pipe, we have to put the '<' in front of it */ p = vim_strchr(IObuff, '|'); ! if (p) *p = NUL; STRCAT(IObuff, " < "); STRCAT(IObuff, itmp); p = vim_strchr(buff, '|'); ! if (p) STRCAT(IObuff, p); } #endif --- 757,773 ---- { char_u *p; /* ! * If there is a pipe, we have to put the '<' in front of it. ! * Don't do this when 'shellquote' is not empty, otherwise the redirection ! * would be inside the quotes. */ p = vim_strchr(IObuff, '|'); ! if (p && *p_shq == NUL) *p = NUL; STRCAT(IObuff, " < "); STRCAT(IObuff, itmp); p = vim_strchr(buff, '|'); ! if (p && *p_shq == NUL) STRCAT(IObuff, p); } #endif *************** *** 824,829 **** --- 829,838 ---- emsg2(e_notread, otmp); goto error; } + #ifdef AUTOCMD + if (curbuf != old_curbuf) + goto filterend; + #endif if (do_in) { *************** *** 832,837 **** --- 841,848 ---- dellines(linecount, TRUE, TRUE); curbuf->b_op_start.lnum -= linecount; /* adjust '[ */ curbuf->b_op_end.lnum -= linecount; /* adjust '] */ + write_lnum_adjust(-linecount); /* adjust last line + for next write */ } else { *************** *** 864,898 **** } filterend: - vim_remove(itmp); - vim_remove(otmp); - } ! #ifdef OS2 ! /* ! * If $TMP is not defined, construct a sensible default. ! * This is required for TMPNAME1 and TMPNAME2 to work. ! */ ! static void ! check_tmpenv() ! { ! char_u *envent; ! ! if (getenv("TMP") == NULL) { ! envent = alloc(8); ! if (envent != NULL) ! { ! strcpy(envent, "TMP=C:/"); ! putenv(envent); ! } } } - #endif /* OS2 */ #ifdef VIMINFO static int no_viminfo __ARGS((void)); static int no_viminfo() --- 875,900 ---- } filterend: ! #ifdef AUTOCMD ! if (curbuf != old_curbuf) { ! --no_wait_return; ! EMSG("*Filter* Autocommands must not change current buffer"); } + #endif + if (itmp != NULL) + vim_remove(itmp); + if (otmp != NULL) + vim_remove(otmp); + vim_free(itmp); + vim_free(otmp); } #ifdef VIMINFO static int no_viminfo __ARGS((void)); + static int viminfo_errcnt; static int no_viminfo() *************** *** 902,916 **** } /* * read_viminfo() -- Read the viminfo file. Registers etc. which are already * set are not over-written unless force is TRUE. -- webb */ int ! read_viminfo(file, want_info, want_marks, force) char_u *file; int want_info; int want_marks; ! int force; { FILE *fp; --- 904,938 ---- } /* + * Report an error for reading a viminfo file. + * Count the number of errors. When there are more than 10, return TRUE. + */ + int + viminfo_error(message, line) + char *message; + char_u *line; + { + sprintf((char *)IObuff, "viminfo: %s in line: ", message); + STRNCAT(IObuff, line, IOSIZE - STRLEN(IObuff)); + emsg(IObuff); + if (++viminfo_errcnt >= 10) + { + EMSG("viminfo: Too many errors, skipping rest of file"); + return TRUE; + } + return FALSE; + } + + /* * read_viminfo() -- Read the viminfo file. Registers etc. which are already * set are not over-written unless force is TRUE. -- webb */ int ! read_viminfo(file, want_info, want_marks, forceit) char_u *file; int want_info; int want_marks; ! int forceit; { FILE *fp; *************** *** 921,927 **** if ((fp = fopen((char *)file, READBIN)) == NULL) return FAIL; ! do_viminfo(fp, NULL, want_info, want_marks, force); fclose(fp); --- 943,950 ---- if ((fp = fopen((char *)file, READBIN)) == NULL) return FAIL; ! viminfo_errcnt = 0; ! do_viminfo(fp, NULL, want_info, want_marks, forceit); fclose(fp); *************** *** 932,965 **** * write_viminfo() -- Write the viminfo file. The old one is read in first so * that effectively a merge of current info and old info is done. This allows * multiple vims to run simultaneously, without losing any marks etc. If ! * force is TRUE, then the old file is not read in, and only internal info is * written to the file. -- webb */ void ! write_viminfo(file, force) char_u *file; ! int force; { FILE *fp_in = NULL; FILE *fp_out = NULL; ! #ifdef USE_TMPNAM ! char_u tmpname[L_tmpnam]; /* use tmpnam() */ ! #else ! char_u tmpname[TMPNAMELEN]; ! #endif if (no_viminfo()) return; - #ifndef USE_TMPNAM /* tmpnam() will make its own name */ - # ifdef OS2 - check_tmpenv(); - expand_env(TMPNAME2, tmpname, TMPNAMELEN); - # else - STRCPY(tmpname, TMPNAME2); - # endif - #endif - file = viminfo_filename(file); /* may set to default if NULL */ file = strsave(file); /* make a copy, don't want NameBuff */ if (file != NULL) --- 955,975 ---- * write_viminfo() -- Write the viminfo file. The old one is read in first so * that effectively a merge of current info and old info is done. This allows * multiple vims to run simultaneously, without losing any marks etc. If ! * forceit is TRUE, then the old file is not read in, and only internal info is * written to the file. -- webb */ void ! write_viminfo(file, forceit) char_u *file; ! int forceit; { FILE *fp_in = NULL; FILE *fp_out = NULL; ! char_u *tempname = NULL; if (no_viminfo()) return; file = viminfo_filename(file); /* may set to default if NULL */ file = strsave(file); /* make a copy, don't want NameBuff */ if (file != NULL) *************** *** 967,995 **** fp_in = fopen((char *)file, READBIN); if (fp_in == NULL) fp_out = fopen((char *)file, WRITEBIN); ! else if (*mktemp((char *)tmpname) != NUL) ! fp_out = fopen((char *)tmpname, WRITEBIN); } if (file == NULL || fp_out == NULL) { EMSG2("Can't write viminfo file %s!", file == NULL ? (char_u *)"" : ! fp_in == NULL ? file : tmpname); if (fp_in != NULL) fclose(fp_in); ! vim_free(file); ! return; } ! do_viminfo(fp_in, fp_out, !force, !force, FALSE); fclose(fp_out); /* errors are ignored !? */ if (fp_in != NULL) { fclose(fp_in); ! if (vim_rename(tmpname, file) == -1) ! vim_remove(tmpname); } vim_free(file); } static char_u * --- 977,1010 ---- fp_in = fopen((char *)file, READBIN); if (fp_in == NULL) fp_out = fopen((char *)file, WRITEBIN); ! else if ((tempname = vim_tempname('o')) != NULL) ! fp_out = fopen((char *)tempname, WRITEBIN); } if (file == NULL || fp_out == NULL) { EMSG2("Can't write viminfo file %s!", file == NULL ? (char_u *)"" : ! fp_in == NULL ? file : tempname); if (fp_in != NULL) fclose(fp_in); ! goto end; } ! viminfo_errcnt = 0; ! do_viminfo(fp_in, fp_out, !forceit, !forceit, FALSE); fclose(fp_out); /* errors are ignored !? */ if (fp_in != NULL) { fclose(fp_in); ! /* ! * In case of an error, don't overwrite the original viminfo file. ! */ ! if (viminfo_errcnt || vim_rename(tempname, file) == -1) ! vim_remove(tempname); } + end: vim_free(file); + vim_free(tempname); } static char_u * *************** *** 1055,1068 **** * are local to a file. Returns TRUE when end-of-file is reached. -- webb */ static int ! read_viminfo_up_to_marks(line, fp, force) char_u *line; FILE *fp; ! int force; { int eof; ! prepare_viminfo_history(force ? 9999 : 0); eof = vim_fgets(line, LSIZE, fp); while (!eof && line[0] != '>') { --- 1070,1083 ---- * are local to a file. Returns TRUE when end-of-file is reached. -- webb */ static int ! read_viminfo_up_to_marks(line, fp, forceit) char_u *line; FILE *fp; ! int forceit; { int eof; ! prepare_viminfo_history(forceit ? 9999 : 0); eof = vim_fgets(line, LSIZE, fp); while (!eof && line[0] != '>') { *************** *** 1075,1089 **** eof = vim_fgets(line, LSIZE, fp); break; case '"': ! eof = read_viminfo_register(line, fp, force); break; case '/': /* Search string */ case '&': /* Substitute search string */ case '~': /* Last search string, followed by '/' or '&' */ ! eof = read_viminfo_search_pattern(line, fp, force); break; case '$': ! eof = read_viminfo_sub_string(line, fp, force); break; case ':': case '?': --- 1090,1104 ---- eof = vim_fgets(line, LSIZE, fp); break; case '"': ! eof = read_viminfo_register(line, fp, forceit); break; case '/': /* Search string */ case '&': /* Substitute search string */ case '~': /* Last search string, followed by '/' or '&' */ ! eof = read_viminfo_search_pattern(line, fp, forceit); break; case '$': ! eof = read_viminfo_sub_string(line, fp, forceit); break; case ':': case '?': *************** *** 1093,1099 **** /* How do we have a file mark when the file is not in the * buffer list? */ ! eof = read_viminfo_filemark(line, fp, force); break; #if 0 case '+': --- 1108,1114 ---- /* How do we have a file mark when the file is not in the * buffer list? */ ! eof = read_viminfo_filemark(line, fp, forceit); break; #if 0 case '+': *************** *** 1102,1109 **** break; #endif default: ! EMSG2("viminfo: Illegal starting char in line %s", line); ! eof = vim_fgets(line, LSIZE, fp); break; } } --- 1117,1126 ---- break; #endif default: ! if (viminfo_error("Illegal starting char", line)) ! eof = TRUE; ! else ! eof = vim_fgets(line, LSIZE, fp); break; } } *************** *** 1197,1203 **** } /* ! * Implementation of ":file [fname]". */ void do_file(arg, forceit) --- 1214,1220 ---- } /* ! * Implementation of ":file[!] [fname]". */ void do_file(arg, forceit)