home *** CD-ROM | disk | FTP | other *** search
- From: mool@oce.nl (Bram Moolenaar)
- Newsgroups: comp.sources.misc
- Subject: v44i027: vim - Vi IMproved editor, v3.0, Part08/26
- Date: 16 Aug 1994 21:18:01 -0500
- Organization: Sterling Software
- Sender: kent@sparky.sterling.com
- Approved: kent@sparky.sterling.com
- Message-ID: <32rs0p$kd4@sparky.sterling.com>
- X-Md4-Signature: 7cecb61518ccc01a0cc898127514fdd4
-
- Submitted-by: mool@oce.nl (Bram Moolenaar)
- Posting-number: Volume 44, Issue 27
- Archive-name: vim/part08
- Environment: UNIX, AMIGA, MS-DOS, Windows NT
- Supersedes: vim: Volume 41, Issue 50-75
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # Contents: vim/doc/difference.doc vim/src/cmdline.c.B
- # vim/src/proto/buffer.pro
- # Wrapped by kent@sparky on Mon Aug 15 21:44:02 1994
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 8 (of 26)."'
- if test -f 'vim/doc/difference.doc' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'vim/doc/difference.doc'\"
- else
- echo shar: Extracting \"'vim/doc/difference.doc'\" \(20566 characters\)
- sed "s/^X//" >'vim/doc/difference.doc' <<'END_OF_FILE'
- X
- X
- XThis is a summary of the differences between VIM and vi. It is not complete.
- Xsee also reference.doc and look for comments in {}.
- X
- X
- XThe most interesting additions:
- X
- XVi compatibility.
- XWhen the 'compatible' option is set, all options are given a vi-compatible
- Xvalue. Vim will behave like the "real" vi as much as possible.
- X
- X
- XMulti level undo.
- X'u' goes backward in time, 'ctrl-R' goes forward again. Set option
- X'undolines' to the number of changes to be remembered (default 100). Set
- X'undolines' to 0 for vi-compatible one level undo.
- X
- XWhen all changes in a buffer have been undone, the buffer is not considered
- Xchanged anymore. You can exit it with :q, without <!>.
- X
- X
- XMultiple windows and buffers.
- XVim can split the screen into several windows, each editing a different
- Xbuffer or the same buffer at a different location. Buffers can still be
- Xloaded (and changed) but not displayed in a window. This is called a hidden
- Xbuffer. Many commands and options have been added for this facility, see
- Xwindows.doc.
- X
- X
- XRepeat a series of commands.
- X'q'<c> starts recording typed characters into named register <c> (append to
- Xthe register if register name is upper case). A subsequent 'q' stops
- Xrecording. The register can then be executed with the '@'<c> command. This is
- Xvery useful to repeat a complex action.
- X
- X
- XFlexible insert mode.
- XThe arrow keys can be used in insert mode to move around in the file. This
- Xbreaks the insert in two parts as far as undo and redo is concerned.
- X
- XCTRL-O can be used to execute a single command-mode command. This is almost
- Xthe same as hitting ESC, typing the command and hitting 'a'. For undo/redo
- Xonly those inserts are remembered where something was actually inserted.
- X
- X
- XVisual mode.
- XVisual can be used to first choose a piece of text and then give a command
- Xto do something with it. This is an (easy to use) alternative to first giving
- Xthe operator and then moving to the end of the text to be operated upon. 'v'
- Xand 'V' are used to start Visual mode. 'v' works on characters and 'V' on
- Xlines. Move the cursor to extend the Visual part. It is shown highlighted on
- Xthe screen. By typing 'o' the other end of the Visual text can be moved. The
- XVisual text can be affected by an operator:
- X d delete
- X c change
- X y yank
- X > or < insert or delete indent
- X ! filter through external program
- X = filter through indent
- X : start ":" command for the Visual lines.
- X Q format text to 'textwidth' columns
- X J join lines
- X ~ swap case
- X u make lowercase
- X U make uppercase
- X
- X
- XBlock operators.
- XWith Visual a rectangular block of text can be selected. Start Visual with
- XCTRL-V. The block can be deleted ('d'), yanked ('y') or its case can be
- Xchanged ('~', 'u' and 'U'). A deleted or yanked block can be put into the
- Xtext with the 'p' and 'P' commands.
- X
- X
- XOnline help.
- X':help' command and help key (F1 for MSDOS) display several pages of concise
- Xhelp. The name of the help file can be set with the "helpfile" option.
- X
- X
- XCommand line editing.
- XYou can insert or delete at any place in the command line using the cursor
- Xkeys. The right/left cursor keys can be used to move forward/backward one
- Xcharacter. The shifted right/left cursor keys can be used to move
- Xforward/backward one word. CTRL-B/CTRL-E can be used to go to the begin/end
- Xof the command line.
- X
- XThe command lines are remembered. The up/down cursor keys can be used to
- Xrecall previous command lines. The 'history' option can be set to the number
- Xof lines that will be remembered.
- X
- X
- XCommand line completion.
- XWhile entering a command line (on the bottom line of the screen) <TAB> can be
- Xtyped to complete
- X what example where
- X- a command :e<TAB> at start of command line
- X- a tag :ta no<TAB> after :ta
- X- an option :set sc<TAB> after :set
- X- a filename :e v<TAB> after any command that accepts a filename
- X
- XIf there are multiple matches, CTRL-N (next) and CTRL-P (previous) will walk
- Xthrough the matches. <TAB> works line CTRL-N, but wraps around to the first
- Xmatch.
- X
- XThe 'wildchar' option can be set to the character for command line
- Xcompletion, <TAB> is the default. CTRL-D can be typed after an (incomplete)
- Xwildcard; all matches will be listed. CTRL-A will insert all matches.
- XCTRL-L will insert the longest common part of the matches.
- X
- X
- XHorizontal scrolling.
- XIf the 'wrap' option is off, long lines will not wrap and only part of them
- Xwill be shown. When the cursor is moved to a part that is not shown, the
- Xscreen will scroll horizontally. The minimal number of columns to scroll can
- Xbe set with the 'sidescroll' option.
- X
- X
- XText formatting.
- XThe 'textwidth' (tw) option can be used to automatically limit the line
- Xlength. This supplements the 'wrapmargin' option of Vi, which was not very
- Xuseful. The 'Q' operator can be used to format a piece of text ("Q}" formats
- Xa paragraph). Commands for text alignment: ":center", ":left" and ":right".
- X
- X
- XEdit-compile-edit speedup.
- XThe ":make" command can be used to run the compilation and jump to the first
- Xerror. Alternatively Vim can be started with the "-e" option from the
- Xcompiler. A file with compiler error messages is interpreted. Each line in
- Xthe error file is scanned for the name of a file, line number and error
- Xmessage. Vim starts editing at the first error. Optionally the name of the
- Xerror file can be given with "-e errorfile". The ":cn" command can be used to
- Xjump to the next error. ":cl" lists all the error messages. Other commands
- Xare available (almost the same as with Manx's Z editor). The 'errorfile'
- Xoption has the name of the file with error messages. The 'errorformat' option
- Xcan be set to a scanf-like string to handle output from many compilers. The
- X'makeprg' option contains the name of the program to be executed with the
- X":make" command. The 'shellpipe' option contains the string to be used to put
- Xthe output of the compiler into the errorfile.
- X
- X
- XCommand line options:
- X
- XWhen Vim is started with "-v" (View) then readonly mode is used (includes
- X"-n").
- X
- XWhen Vim is started with "-b" (Binary) then some options are set to be able
- Xto edit binary or executable files.
- X
- XWhen Vim is started with "-s scriptfile", the characters read from
- X"scriptfile" are treated as if you typed them. If end of file is reached
- Xbefore the editor exits, further characters are read from the console.
- X
- XThe "-w" option can be used to record all typed characters in a script file.
- XThis file can then be used to redo the editing, possibly on another file or
- Xafter changing some commands in the script file.
- X
- XThe "-n" option disables the writing of a ".swp" file (see below).
- X
- XThe "-c command" option does the same as the the "+command" option.
- X
- XThe "-T terminal" option sets the terminal type.
- X
- XThe "-e" option starts Vim in quickfix mode.
- X
- XThe "-o" option opens a window for each argument. "-o4" opens four windows.
- X
- X
- XIn command mode:
- X
- XMissing command: 'Q' (go to Ex mode).
- XMissing Ex commands: append, change, insert, open, recover and z.
- X
- XThe command characters are shown in the last line of the screen. They are
- Xremoved when the command is finished. If you do not want this (on a slow
- Xterminal) reset the 'showcmd' option.
- X
- XIf the 'ruler' option is set, the current cursor position is shown in the
- Xlast line of the screen.
- X
- X'u' and CTRL-R accept a count for the number of undos/redos.
- X
- X'U' still works after having moved off of the last changed line and after
- X'u'.
- X
- XNulls in the file are replaced by <LF> internally. This allows editing of
- Xbinary files (more or less).
- X
- XCharacters with the 8th bit set are displayed. The characters between '~' and
- X0xa0 are displayed as "~?", "~@", "~A", etc., unless the "graphic' option is
- Xset.
- X
- X'=' is an operator to filter lines through an external command (vi: lisp
- Xstuff). The name of the command can be set with the 'equalprg' option. The
- Xdefault is "indent".
- X
- X'][' goes to the next ending of a C function ('}' in column 1).
- X'[]' goes to the previous ending of a C function ('}' in column 1).
- X
- X']f', '[f' and 'gf' start editing the file whose name is under the cursor.
- XCTRL-W f splits the window and starts editint the file whose name is under
- Xthe cursor.
- X
- X'*' searches forward for the identifier under the cursor, '#' backward.
- X'K' runs the program defined by the "keywordprg" option, with the identifier
- Xunder the cursor as argument.
- X
- X'%' can be preceded with a count. The cursor jumps to the line that
- Xpercentage down in the file. The normal '%' function to jump to the matching
- Xbrace skips braces inside quotes.
- X
- XWith the CTRL-] command, the cursor may be in the middle of the identifier.
- X
- XThe used tags are remembered. Commands that can be used with the tag stack
- Xare CTRL-T, ':pop' and ':tag'. ':tags' lists the tag stack.
- X
- XThe 'tags' option can be set to a list of tag file names. Thus multiple
- Xtag files can be used.
- X
- XPreviously used file names are remembered in the alternate file name list.
- XCTRL-^ accepts a count, which is an index in this list.
- X
- XSearch patterns have more features. The <NL> character is seen as part of the
- Xsearch pattern and the substitute string of ":s". Vi sees it as the end of
- Xthe command.
- X
- XSearches can put the cursor on the end of a match and may include a character
- Xoffset.
- X
- XCount added to '~', ':next', ':Next', 'n' and 'N'.
- X
- XThe command ":next!" with 'autowrite' set does not write the file. In vi the
- Xfile was written, but this is considered to be a bug, because one does not
- Xexpect it and the file is not written with ':rewind!'.
- X
- X"5r<CR>" replaces five characters by five line breaks. Vi replaces five
- Xcharacters with a single line break.
- X
- XAdded :wnext command. Same as ":write" followed by ":next".
- X
- XThe ":w!" command always writes, also when the file is write protected.
- X
- XIf option "tildeop" has been set, '~' is an operator (must be followed by a
- Xmovement command).
- X
- XWith the 'J' (join) command you can reset the 'joinspaces' (js) option to
- Xhave only one space after a period (Vi inserts two spaces).
- X
- X'cw' can be used to change white space formed by several characters (Vi is
- Xconfusing: 'cw' only changes one space, while 'dw' deletes all white space).
- X
- X'o' and 'O' accept a count for repeating the insert (Vi clears a part of
- Xdisplay).
- X
- X':dis' command shows the contents of the yank register.
- X
- XPreviously used file names are remembered in the alternate file name list.
- X":files" command shows the list of alternate filenames.
- X'#'<N> is replaced by the <N>th alternate filename in the list.
- X"#<" is replaced by the current filename without extension.
- X
- XFlags after command not supported (no plans to include it).
- X
- XOn non-UNIX systems ":cd" command shows current directory instead of going to
- Xthe home directory. ":pwd" prints the current directory on all systems.
- X
- X':source!' command reads Vi commands from a file.
- X
- X':mkexrc' command writes current modified options and mappings to a ".exrc"
- Xfile. ':mkvimrc' writes to a ".vimrc" file.
- X
- XNo check for "tail recursion" with mappings. This allows things like
- X":map! foo ^]foo".
- X
- XThe :put! command inserts the contents of a register above the current line.
- X
- XThe 'p' and 'P' commands of vi cannot be repeated with '.' when the putted
- Xtext is less than a line. In Vim they can always be repeated.
- X
- XThe named register '.' can be used with commands p, P and :put. The contents
- Xof the register is the last inserted text.
- X
- X":noremap" command can be used to enter a mapping that will not be remapped.
- XThis is useful to exchange the meaning of two keys. ":cmap", ":cunmap" and
- X":cnoremap" can be used for mapping in command line editing only. ":imap",
- X":iunmap" and ":inoremap" can be used for mapping in insert mode only.
- XSimilar commands exist for abbreviations: ":noreabbrev", ":iabbrev"
- X":cabbrev", ":iunabbrev", ":cunabbrev", ":inoreabbrev", ":cnoreabbrev".
- X
- XIn vi the command ":map foo bar" would remove a previous mapping
- X":map bug foo". This is considered a bug, so it is not included in Vim.
- X":unmap! foo" does remove ":map! bug foo", because unmapping would be very
- Xdifficult otherwise (this is vi compatible).
- X
- X":@r" command executes register r (is in some versions of vi).
- X
- XThe ':' register contains the last command line.
- XThe '%' register contians the current file name.
- X
- XCTRL-O/CTRL-I can be used to jump to older/newer positions. These are the
- Xsame positions as used with the '' command, but may be in another file. The
- X':jumps' command lists the older positions.
- X
- XIf the 'shiftround' option is set, an indent is rounded to a multiple of
- X'shiftwidth' with '>' and '<' commands.
- X
- XThe 'scrolljump' option can be set to the minimal number of lines to scroll
- Xwhen the cursor gets off the screen. Use this when scrolling is slow.
- X
- XUppercase marks can be used to jump between files. The ':marks' command lists
- Xall currently set marks. The commands "']" and "`]" jump to the end of the
- Xprevious operator or end of the text inserted with the put command. "'[" and
- X"`[" do jump to the start.
- X
- XThe 'shelltype' option can be set to reflect the type of shell used.
- X
- XThe 'highlight' option can be set for the higlight mode to be used for
- Xseveral commands.
- X
- XThe CTRL-A (add) and CTRL-X (subtract) commands are new. The count to the
- Xcommand (default 1) is added to/subtracted from the number at or after the
- Xcursor. That number may be decimal, octal (starts with a '0') or hexadecimal
- X(starts with '0x'). Very useful in macros.
- X
- XWith the :set command the prefix "inv" can be used to invert toggle options.
- X
- XIn both Vi and Vim you can create a line break with the ":substitute" command
- Xby using a CTRL-M. For Vi this means you cannot insert a real CTRL-M in the
- Xtext. With Vim you can put a real CTRL-M in the text by preceding it with a
- XCTRL-V.
- X
- X
- XIn insert mode:
- X
- XIf the 'revins' option is set, insert happens backwards. This is for typing
- XHebrew. When inserting normal characters the cursor will not be shifted and
- Xthe text moves rightwards. In replace mode the cursor will move leftwards.
- XBackspace, CTRL-W and CTRL-U will also work in the opposite direction. CTRL-B
- Xtoggles the 'revins' option.
- X
- XThe backspace key can be used just like CTRL-D to remove auto-indents.
- X
- XYou can backspace, ctrl-U and CTRL-W over line breaks if the 'backspace' (bs)
- Xoption is set to non-zero. You can backspace over the start of insert if the
- X'backspace' option is set to 2.
- X
- XWhen the 'paste' option is set, a few option are reset and mapping in insert
- Xmode and abbreviation are disabled. This allows for pasting text in windowing
- Xsystems without unexpected results. When the 'paste' option is reset, the old
- Xoption values are restored.
- X
- XCTRL-T/CTRL-D always insert/delete an indent in the current line, no matter
- Xwhat column the cursor is in.
- X
- XCTRL-@ (insert previously inserted text) works always (Vi: only when typed as
- Xfirst character).
- X
- XCTRL-A works like CTRL-@ but does not leave insert mode.
- X
- XCTRL-R <0-9a-z> can be used to insert the contents of a register.
- X
- XWhen the 'smartindent' (si) option is set, C programs will be better
- Xauto-indented.
- X
- XCTRL-Y and CTRL-E can be used to copy a character from above/below the
- Xcurrent cursor position.
- X
- XAfter CTRL-V you can enter a three digit decimal number. This byte value is
- Xinserted in the text as a single character. Useful for international
- Xcharacters that are not on your keyboard.
- X
- XWhen the 'expandtab' (et) option is set, a <TAB> is expanded to the
- Xappropriate number of spaces.
- X
- XThe window always reflects the contents of the buffer (Vi does not do this
- Xwhen changing text and in some other cases).
- X
- XIf Vim is compiled with DIGRAPHS defined, digraphs are supported. A set of
- Xnormal Amiga digraphs is included. They are shown with the :digraph" command.
- XMore can be added with ":digraph {char1}{char2} {number}". A digraph is
- Xentered with "CTRL-K {char1} {char2}" or "{char1} BS {char2}" (only when
- X'digraph' option is set).
- X
- XWhen repeating an insert, e.g. "10atest <ESC>" vi would only handle wrapmargin
- Xfor the first insert. Vim does it for all.
- X
- X
- XIn command line mode:
- X
- XESC terminates the command line without executing it. In vi the command line
- Xwould be executed, which is not what most people expect (hitting ESC should
- Xalways get you back to command mode). To avoid problems with some
- Xobscure macros, an ESC in a macro will execute the command. If you want a
- Xtyped ESC to execute the command like vi does you can fix this with
- X ":cmap ^V<ESC> ^V<CR>"
- X
- Xgeneral:
- X
- XMissing options: autoprint (ap), beautify (bf), edcompatible, hardtabs (ht),
- Xlisp, mesg, open, optimize (op), prompt, redraw, slowopen (slow), terse,
- Xwindow, w300, w1200 and w9600. These options can be set but are otherwise
- Xignored.
- X
- XWhen the 'compatible' option is set, all options are set for maximum
- Xvi-compatibility
- X
- XThe 'ttimeout' option is like 'timeout', but only works for cursor and
- Xfunction keys, not for ordinary mapped characters. The 'timoutlen' option
- Xgives the number of milliseconds that is waited for. If the 'esckeys' option
- Xis not set, cursor and function keys that start with <ESC> are not recognized
- Xin insert mode.
- X
- XThere is an option for each terminal string. Can be used when termcap is not
- Xsupported or to change individual strings.
- X
- XWhen the 'textmode' option is set (default for MSDOS) <CR><LF> is used as
- Xline separator. When reset (default for Unix and Amiga) <LF> is used. When
- Xthe 'textauto' option is set, Vim tries to detect the type of line separator
- Xused by reading up to the first <LF>. The 'textmode' option is set
- Xaccordingly.
- X
- XOn systems that have no job control (most systems but BSD-UNIX) the CTRL-Z,
- X":stop" or ":suspend" command starts a new shell.
- X
- XIf Vim is started on the Amiga without an interactive window for output, a
- Xwindow is opened (and :sh still works). You can give a device to use for
- Xediting with the '-d' argument, e.g. "-d con:20/20/600/150".
- X
- XOn startup the VIMINIT or EXINIT environment variables, the file s:.vimrc or
- Xs:.exrc and .vimrc or .exrc are read for initialization commands. When
- Xreading .vimrc and .exrc some commands are not allowed because of security
- Xreasons (shell commands and writing to a file, :map commands are echoed).
- XThis can be overrided with the 'secure' option.
- X
- XLine lenght can be at least upto the maximum value of an int (for the Amiga
- X32767 characters, for most 32-bit systems much larger). Editing such lines is
- Xnot always possible. File length upto 2147483646 lines. If a line is larger
- Xthan the screen, the last line is filled with <@>s and only the part of the
- Xline before that is shown (unless 'wrap' option is reset).
- X
- XThe 'columns' option is used to set or get the width of the display.
- X
- XThe name of the current file name is shown in the title bar of the window.
- X
- XWildcards in file names are expanded.
- X
- XOption settings are read from the first and last few lines of the file.
- XOption 'modelines' determines how many lines are tried (default is 5). Note
- Xthat this is different from the Vi versions that can execute any Ex command
- Xin a modeline (a major security problem).
- X
- XIf the 'insertmode' option is set (e.g. in .exrc), Vim starts in insert mode.
- X
- XAll text is kept in memory. Available memory limits the file size (and other
- Xthings such as undo). This may be a problem with MSDOS, is hardly a problem
- Xont the Amiga and almost never with Unix.
- X
- XIf the 'backup' or 'writebackup' option is set: Before a file is overwritten,
- Xa backup file (.bak) is made. If the "backup" option is set it is left
- Xbehind.
- X
- XIf the 'binary' option is set and the file does not have an end-of-line for
- Xthe last line, the end-of-line is not appended when writing.
- X
- XVim creates a file ending in ".swp" to store parts of the file that have been
- Xchanged or that do not fit in memory. This file can be used to recover from
- Xan aborted editing session with "vim -r file". Using the swap file can be
- Xswitched off by setting the 'updatecount' option to 0 or starting Vim with
- Xthe "-n" option. Use the 'directory' option for placing the .swp file
- Xsomewhere else.
- X
- XThe 'shortname' (sn) option, when set, tells Vim that ".bak" and ".swp"
- Xfilenames are to be MSDOS-like: 8 characters plus 3 for extention. This
- Xshould be used on messydos or crossdos filesystems on the Amiga. If this
- Xoption is off, Vim tries to guess if MSDOS filename restrictions are
- Xeffective.
- X
- XRecovery after a crash has a smaller chance for success, because there is no
- Xtemporary file.
- X
- XError messages are shown at least one second (Vi overwrites error messages).
- X
- XIf Vim asks to "Hit RETURN to continue", you can hit any key. Characters
- Xother than <CR>, <LF> and <SPACE> are interpreted as the (start of) a
- Xcommand. (Vi only accepts a command starting with ':').
- X
- XThe contents of the numbered and unnamed registers is remembered when
- Xchanging files.
- X
- XThe AUX: device of the Amiga is supported.
- X
- Xvi:tw=77:
- END_OF_FILE
- if test 20566 -ne `wc -c <'vim/doc/difference.doc'`; then
- echo shar: \"'vim/doc/difference.doc'\" unpacked with wrong size!
- fi
- # end of 'vim/doc/difference.doc'
- fi
- if test -f 'vim/src/cmdline.c.B' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'vim/src/cmdline.c.B'\"
- else
- echo shar: Extracting \"'vim/src/cmdline.c.B'\" \(44081 characters\)
- sed "s/^X//" >'vim/src/cmdline.c.B' <<'END_OF_FILE'
- X break;
- X
- X case CMD_set:
- X (void)doset(arg);
- X break;
- X
- X case CMD_abbreviate:
- X case CMD_cabbrev:
- X case CMD_iabbrev:
- X case CMD_cnoreabbrev:
- X case CMD_inoreabbrev:
- X case CMD_noreabbrev:
- X case CMD_unabbreviate:
- X case CMD_cunabbrev:
- X case CMD_iunabbrev:
- X i = ABBREV;
- X goto doabbr; /* almost the same as mapping */
- X
- X case CMD_cmap:
- X case CMD_imap:
- X case CMD_map:
- X case CMD_cnoremap:
- X case CMD_inoremap:
- X case CMD_noremap:
- X /*
- X * If we are sourcing .exrc or .vimrc in current directory we
- X * print the mappings for security reasons.
- X */
- X if (secure)
- X {
- X secure = 2;
- X msg_outtrans(cmd, -1);
- X msg_outchar('\n');
- X }
- X case CMD_cunmap:
- X case CMD_iunmap:
- X case CMD_unmap:
- X i = 0;
- Xdoabbr:
- X if (*cmd == 'c') /* cmap, cunmap, cnoremap, etc. */
- X {
- X i += CMDLINE;
- X ++cmd;
- X }
- X else if (*cmd == 'i') /* imap, iunmap, inoremap, etc. */
- X {
- X i += INSERT;
- X ++cmd;
- X }
- X else if (forceit || i) /* map!, unmap!, noremap!, abbrev */
- X i += INSERT + CMDLINE;
- X else
- X i += NORMAL; /* map, unmap, noremap */
- X switch (domap((*cmd == 'n') ? 2 : (*cmd == 'u'), arg, i))
- X {
- X case 1: emsg(e_invarg);
- X break;
- X case 2: emsg(e_nomap);
- X break;
- X case 3: emsg(e_ambmap);
- X break;
- X }
- X break;
- X
- X case CMD_display:
- X dodis(); /* display buffer contents */
- X break;
- X
- X case CMD_help:
- X help();
- X break;
- X
- X case CMD_version:
- X msg(longVersion);
- X break;
- X
- X case CMD_winsize: /* obsolete command */
- X line1 = getdigits(&arg);
- X skipspace(&arg);
- X line2 = getdigits(&arg);
- X set_winsize((int)line1, (int)line2, TRUE);
- X break;
- X
- X case CMD_delete:
- X case CMD_yank:
- X case CMD_rshift:
- X case CMD_lshift:
- X yankbuffer = regname;
- X curbuf->b_startop.lnum = line1;
- X curbuf->b_endop.lnum = line2;
- X nlines = line2 - line1 + 1;
- X mtype = MLINE;
- X curwin->w_cursor.lnum = line1;
- X switch (cmdidx)
- X {
- X case CMD_delete:
- X dodelete();
- X break;
- X case CMD_yank:
- X (void)doyank(FALSE);
- X curwin->w_cursor.lnum = line2; /* put cursor on last line */
- X break;
- X case CMD_rshift:
- X doshift(RSHIFT, FALSE, amount);
- X break;
- X case CMD_lshift:
- X doshift(LSHIFT, FALSE, amount);
- X break;
- X }
- X break;
- X
- X case CMD_put:
- X yankbuffer = regname;
- X curwin->w_cursor.lnum = line2;
- X doput(forceit ? BACKWARD : FORWARD, -1L, FALSE);
- X break;
- X
- X case CMD_t:
- X case CMD_copy:
- X case CMD_move:
- X n = get_address(&arg);
- X /*
- X * move or copy lines from 'line1'-'line2' to below line 'n'
- X */
- X if (n == MAXLNUM || n < 0 || n > curbuf->b_ml.ml_line_count)
- X {
- X emsg(e_invaddr);
- X break;
- X }
- X
- X if (cmdidx == CMD_move)
- X {
- X if (do_move(line1, line2, n) == FAIL)
- X break;
- X }
- X else
- X do_copy(line1, line2, n);
- X u_clearline();
- X curwin->w_cursor.col = 0;
- X updateScreen(NOT_VALID);
- X break;
- X
- X case CMD_and: /* :& */
- X case CMD_tilde: /* :~ */
- X case CMD_substitute: /* :s */
- X dosub(line1, line2, arg, &nextcomm,
- X cmdidx == CMD_substitute ? 0 :
- X cmdidx == CMD_and ? 1 : 2);
- X break;
- X
- X case CMD_join:
- X curwin->w_cursor.lnum = line1;
- X if (line1 == line2)
- X {
- X if (addr_count >= 2) /* :2,2join does nothing */
- X break;
- X if (line2 == curbuf->b_ml.ml_line_count)
- X {
- X beep();
- X break;
- X }
- X ++line2;
- X }
- X dodojoin(line2 - line1 + 1, !forceit, TRUE);
- X break;
- X
- X case CMD_global:
- X if (forceit)
- X *cmd = 'v';
- X case CMD_vglobal:
- X doglob(*cmd, line1, line2, arg);
- X break;
- X
- X case CMD_at: /* :[addr]@r */
- X curwin->w_cursor.lnum = line2;
- X if (doexecbuf(*arg) == FAIL) /* put the register in mapbuf */
- X beep();
- X else
- X (void)docmdline((char_u *)NULL); /* execute from the mapbuf */
- X break;
- X
- X case CMD_bang:
- X dobang(addr_count, line1, line2, forceit, arg);
- X break;
- X
- X case CMD_undo:
- X u_undo(1);
- X break;
- X
- X case CMD_redo:
- X u_redo(1);
- X break;
- X
- X case CMD_source:
- X if (forceit) /* :so! read vi commands */
- X (void)openscript(arg);
- X else
- X {
- X ++no_wait_return;
- X if (dosource(arg) == FAIL) /* :so read ex commands */
- X emsg2(e_notopen, arg);
- X --no_wait_return;
- X if (need_wait_return)
- X wait_return(FALSE);
- X }
- X break;
- X
- X case CMD_mkvimrc:
- X if (*arg == NUL)
- X arg = (char_u *)VIMRC_FILE;
- X /*FALLTHROUGH*/
- X
- X case CMD_mkexrc:
- X {
- X FILE *fd;
- X
- X if (*arg == NUL)
- X arg = (char_u *)EXRC_FILE;
- X#ifdef UNIX
- X /* with Unix it is possible to open a directory */
- X if (isdir(arg) == TRUE)
- X {
- X EMSG2("\"%s\" is a directory", arg);
- X break;
- X }
- X#endif
- X if (!forceit && (fd = fopen((char *)arg, "r")) != NULL)
- X {
- X fclose(fd);
- X EMSG2("\"%s\" exists (use ! to override)", arg);
- X break;
- X }
- X
- X if ((fd = fopen((char *)arg, "w")) == NULL)
- X {
- X EMSG2("Cannot open \"%s\" for writing", arg);
- X break;
- X }
- X if (makemap(fd) == FAIL || makeset(fd) == FAIL || fclose(fd))
- X emsg(e_write);
- X break;
- X }
- X
- X case CMD_cc:
- X qf_jump(0, atoi((char *)arg));
- X break;
- X
- X case CMD_cf:
- X if (*arg != NUL)
- X {
- X /*
- X * Great trick: Insert 'ef=' before arg.
- X * Always ok, because "cf " must be there.
- X */
- X arg -= 3;
- X arg[0] = 'e';
- X arg[1] = 'f';
- X arg[2] = '=';
- X (void)doset(arg);
- X }
- X (void)qf_init();
- X break;
- X
- X case CMD_cl:
- X qf_list();
- X break;
- X
- X case CMD_cn:
- X qf_jump(FORWARD, *arg == NUL ? 1 : atoi((char *)arg));
- X break;
- X
- X case CMD_cp:
- X qf_jump(BACKWARD, *arg == NUL ? 1 : atoi((char *)arg));
- X break;
- X
- X case CMD_cq:
- X getout(1); /* this does not always work. why? */
- X
- X case CMD_mark:
- X case CMD_k:
- X pos = curwin->w_cursor; /* save curwin->w_cursor */
- X curwin->w_cursor.lnum = line2;
- X curwin->w_cursor.col = 0;
- X (void)setmark(*arg); /* set mark */
- X curwin->w_cursor = pos; /* restore curwin->w_cursor */
- X break;
- X
- X#ifdef SETKEYMAP
- X case CMD_setkeymap:
- X set_keymap(arg);
- X break;
- X#endif
- X
- X case CMD_center:
- X case CMD_right:
- X case CMD_left:
- X do_align(line1, line2, atoi((char *)arg),
- X cmdidx == CMD_center ? 0 : cmdidx == CMD_right ? 1 : -1);
- X break;
- X
- X case CMD_make:
- X domake(arg);
- X break;
- X
- X default:
- X emsg(e_invcmd);
- X }
- X
- X
- Xdoend:
- X forceit = FALSE; /* reset now so it can be used in getfile() */
- X if (nextcomm && *nextcomm == NUL) /* not really a next command */
- X nextcomm = NULL;
- X return nextcomm;
- X}
- X
- X/*
- X * if 'autowrite' option set, try to write the file
- X *
- X * return FAIL for failure, OK otherwise
- X */
- X int
- Xautowrite(buf)
- X BUF *buf;
- X{
- X if (!p_aw || (!forceit && buf->b_p_ro) || buf->b_filename == NULL)
- X return FAIL;
- X return buf_write_all(buf);
- X}
- X
- X/*
- X * flush all buffers, except the ones that are readonly
- X */
- X void
- Xautowrite_all()
- X{
- X BUF *buf;
- X
- X if (!p_aw)
- X return;
- X for (buf = firstbuf; buf; buf = buf->b_next)
- X if (buf->b_changed && !buf->b_p_ro)
- X (void)buf_write_all(buf);
- X}
- X
- X/*
- X * flush the contents of a buffer, unless it has no file name
- X *
- X * return FAIL for failure, OK otherwise
- X */
- X static int
- Xbuf_write_all(buf)
- X BUF *buf;
- X{
- X return (buf_write(buf, buf->b_filename, buf->b_sfilename, (linenr_t)1, buf->b_ml.ml_line_count, 0, 0, TRUE));
- X}
- X
- X/*
- X * write current buffer to file 'fname'
- X * if 'append' is TRUE, append to the file
- X *
- X * if *fname == NUL write to current file
- X * if b_notedited is TRUE, check for overwriting current file
- X *
- X * return FAIL for failure, OK otherwise
- X */
- X static int
- Xdowrite(fname, append)
- X char_u *fname;
- X int append;
- X{
- X FILE *fd;
- X int other;
- X char_u *sfname = NULL; /* init to shut up gcc */
- X
- X if (*fname == NUL)
- X other = FALSE;
- X else
- X {
- X sfname = fname;
- X fname = fix_fname(fname);
- X other = otherfile(fname);
- X }
- X
- X /*
- X * if we have a new file name put it in the list of alternate file names
- X */
- X if (other)
- X setaltfname(fname, sfname, (linenr_t)1);
- X
- X /*
- X * writing to the current file is not allowed in readonly mode
- X * and need a file name
- X */
- X if (!other && (check_readonly() || check_fname() == FAIL))
- X return FAIL;
- X
- X if (!other)
- X {
- X fname = curbuf->b_filename;
- X sfname = curbuf->b_sfilename;
- X }
- X
- X /*
- X * write to other file or b_notedited set: overwriting only allowed with '!'
- X */
- X if ((other || curbuf->b_notedited) && !forceit && !append && !p_wa && (fd = fopen((char *)fname, "r")) != NULL)
- X { /* don't overwrite existing file */
- X fclose(fd);
- X#ifdef UNIX
- X /* with UNIX it is possible to open a directory */
- X if (isdir(fname) == TRUE)
- X EMSG2("\"%s\" is a directory", fname);
- X else
- X#endif
- X emsg(e_exists);
- X return FAIL;
- X }
- X return (buf_write(curbuf, fname, sfname, line1, line2, append, forceit, TRUE));
- X}
- X
- X/*
- X * start editing a new file
- X *
- X * fname: the file name
- X * - full path if sfname used,
- X * - any file name if sfname is NULL
- X * - empty string to re-edit with the same file name (but may be
- X * in a different directory)
- X * - NULL to start an empty buffer
- X * sfname: the short file name (or NULL)
- X * command: the command to be executed after loading the file
- X * hide: if TRUE don't free the current buffer
- X * newlnum: put cursor on this line number (if possible)
- X *
- X * return FAIL for failure, OK otherwise
- X */
- X int
- Xdoecmd(fname, sfname, command, hide, newlnum)
- X char_u *fname;
- X char_u *sfname;
- X char_u *command;
- X int hide;
- X linenr_t newlnum;
- X{
- X int other_file; /* TRUE if editing another file */
- X int oldbuf = FALSE; /* TRUE if using existing buffer */
- X BUF *buf;
- X
- X /* if no short name given, use fname for short name */
- X if (sfname == NULL)
- X sfname = fname;
- X
- X if (fname == NULL)
- X other_file = TRUE;
- X else if (*fname == NUL && curbuf->b_filename == NULL) /* there is no file name */
- X other_file = FALSE;
- X else
- X {
- X if (*fname == NUL) /* re-edit with same file name */
- X {
- X fname = curbuf->b_filename;
- X sfname = curbuf->b_sfilename;
- X }
- X fname = fix_fname(fname); /* may expand to full path name */
- X other_file = otherfile(fname);
- X }
- X/*
- X * if the file was changed we may not be allowed to abandon it
- X * - if we are going to re-edit the same file
- X * - or if we are the only window on this file and if hide is FALSE
- X */
- X if ((!other_file || (curbuf->b_nwindows == 1 && !hide)) &&
- X check_changed(curbuf, FALSE, !other_file))
- X {
- X if (other_file && fname != NULL)
- X setaltfname(fname, sfname, (linenr_t)1);
- X return FAIL;
- X }
- X/*
- X * If we are starting to edit another file, open a (new) buffer.
- X * Otherwise we re-use the current buffer.
- X */
- X if (other_file)
- X {
- X curwin->w_alt_fnum = curbuf->b_fnum;
- X buflist_altlnum();
- X
- X buf = buflist_new(fname, sfname, 1L, TRUE);
- X if (buf == NULL)
- X return FAIL;
- X if (buf->b_ml.ml_mfp == NULL) /* no memfile yet */
- X {
- X oldbuf = FALSE;
- X buf->b_nwindows = 1;
- X }
- X else /* existing memfile */
- X {
- X oldbuf = TRUE;
- X ++buf->b_nwindows;
- X }
- X /*
- X * make the (new) buffer the one used by the current window
- X * if the old buffer becomes unused, free it if hide is FALSE
- X * If the current buffer was empty and has no file name, curbuf
- X * is returned by buflist_new().
- X */
- X if (buf != curbuf)
- X {
- X close_buffer(curbuf, !hide, FALSE);
- X curwin->w_buffer = buf;
- X curbuf = buf;
- X }
- X
- X curwin->w_pcmark.lnum = 1;
- X curwin->w_pcmark.col = 0;
- X }
- X else if (check_fname() == FAIL)
- X return FAIL;
- X
- X/*
- X * If we get here we are sure to start editing
- X */
- X /* don't redraw until the cursor is in the right line */
- X ++RedrawingDisabled;
- X
- X/*
- X * other_file oldbuf
- X * FALSE FALSE re-edit same file, buffer is re-used
- X * FALSE TRUE not posible
- X * TRUE FALSE start editing new file, new buffer
- X * TRUE TRUE start editing in existing buffer (nothing to do)
- X */
- X if (!other_file) /* re-use the buffer */
- X {
- X if (newlnum == 0)
- X newlnum = curwin->w_cursor.lnum;
- X buf_freeall(curbuf); /* free all things for buffer */
- X buf_clear(curbuf);
- X curbuf->b_startop.lnum = 0; /* clear '[ and '] marks */
- X curbuf->b_endop.lnum = 0;
- X }
- X
- X if (!oldbuf) /* need to read the file */
- X (void)open_buffer();
- X win_init(curwin);
- X maketitle();
- X
- X if (newlnum && command == NULL)
- X {
- X curwin->w_cursor.lnum = newlnum;
- X curwin->w_cursor.col = 0;
- X }
- X check_cursor();
- X
- X /*
- X * Did not read the file, need to show some info about the file.
- X * Do this after setting the cursor.
- X */
- X if (oldbuf)
- X fileinfo(did_cd);
- X
- X if (command != NULL)
- X docmdline(command);
- X --RedrawingDisabled;
- X if (!skip_redraw)
- X updateScreen(CURSUPD); /* redraw now */
- X
- X if (p_im)
- X stuffReadbuff((char_u *)"i"); /* start editing in insert mode */
- X return OK;
- X}
- X
- X/*
- X * get + command from ex argument
- X */
- X static char_u *
- Xgetargcmd(argp)
- X char_u **argp;
- X{
- X char_u *arg = *argp;
- X char_u *command = NULL;
- X
- X if (*arg == '+') /* +[command] */
- X {
- X ++arg;
- X if (isspace(*arg))
- X command = (char_u *)"$";
- X else
- X {
- X command = arg;
- X /*
- X * should check for "\ " (but vi has a bug that prevents it to work)
- X */
- X skiptospace(&arg);
- X }
- X if (*arg)
- X *arg++ = NUL; /* terminate command with NUL */
- X
- X skipspace(&arg); /* skip over spaces */
- X *argp = arg;
- X }
- X return command;
- X}
- X
- X/*
- X * look for command separator '|' or '\n'
- X */
- X static char_u *
- Xchecknextcomm(arg)
- X char_u *arg;
- X{
- X char_u *p;
- X char_u *nextcomm = NULL;
- X
- X for (p = arg; *p; ++p)
- X {
- X if (*p == '\\' && p[1])
- X ++p;
- X else if (*p == '|' || *p == '\n')
- X {
- X nextcomm = p + 1; /* remember start of next command */
- X *p = NUL; /* delete '|' or '\n' */
- X del_spaces(arg); /* delete spaces in front of '|' or '\n' */
- X break;
- X }
- X }
- X return nextcomm;
- X}
- X
- X static void
- Xdomake(arg)
- X char_u *arg;
- X{
- X if (*p_ef == NUL)
- X {
- X EMSG("errorfile option not set");
- X return;
- X }
- X if (curbuf->b_changed)
- X (void)autowrite(curbuf);
- X remove((char *)p_ef);
- X outchar(':');
- X outstr(arg); /* show what we are doing */
- X sprintf((char *)IObuff, "%s %s %s", arg, p_sp, p_ef);
- X doshell(IObuff);
- X#ifdef AMIGA
- X flushbuf();
- X vpeekc(); /* read window status report and redraw before message */
- X#endif
- X (void)qf_init();
- X remove((char *)p_ef);
- X}
- X
- X/*
- X * Redefine the argument list to 'str'.
- X *
- X * Return FAIL for failure, OK otherwise.
- X */
- X static int
- Xdoarglist(str)
- X char_u *str;
- X{
- X int new_count = 0;
- X char_u **new_files = NULL;
- X int exp_count;
- X char_u **exp_files;
- X char_u **t;
- X char_u *p;
- X int inquote;
- X int i;
- X
- X while (*str)
- X {
- X /*
- X * create a new entry in new_files[]
- X */
- X t = (char_u **)lalloc((long_u)(sizeof(char_u *) * (new_count + 1)), TRUE);
- X if (t != NULL)
- X for (i = new_count; --i >= 0; )
- X t[i] = new_files[i];
- X free(new_files);
- X if (t == NULL)
- X return FAIL;
- X new_files = t;
- X new_files[new_count++] = str;
- X
- X /*
- X * isolate one argument, taking quotes
- X */
- X inquote = FALSE;
- X for (p = str; *str; ++str)
- X {
- X /*
- X * for MSDOS a backslash is part of a file name.
- X * Only skip ", space and tab.
- X */
- X#ifdef MSDOS
- X if (*str == '\\' && (str[1] == '"' || str[1] == ' ' || str[1] == '\t'))
- X#else
- X if (*str == '\\' && str[1] != NUL)
- X#endif
- X *p++ = *++str;
- X else
- X {
- X if (!inquote && isspace(*str))
- X break;
- X if (*str == '"')
- X inquote ^= TRUE;
- X else
- X *p++ = *str;
- X }
- X }
- X skipspace(&str);
- X *p = NUL;
- X }
- X
- X i = ExpandWildCards(new_count, new_files, &exp_count, &exp_files, FALSE, TRUE);
- X free(new_files);
- X if (i == FAIL)
- X return FAIL;
- X if (exp_count == 0)
- X {
- X emsg(e_nomatch);
- X return FAIL;
- X }
- X if (arg_exp) /* arg_files[] has been allocated, free it */
- X FreeWild(arg_count, arg_files);
- X else
- X arg_exp = TRUE;
- X arg_files = exp_files;
- X arg_count = exp_count;
- X
- X /*
- X * put all file names in the buffer list
- X */
- X for (i = 0; i < arg_count; ++i)
- X (void)buflist_add(arg_files[i]);
- X
- X return OK;
- X}
- X
- X void
- Xgotocmdline(clr, firstc)
- X int clr;
- X int firstc;
- X{
- X msg_start();
- X if (clr) /* clear the bottom line(s) */
- X msg_ceol(); /* will reset clear_cmdline */
- X windgoto(cmdline_row, 0);
- X if (firstc)
- X msg_outchar(firstc);
- X}
- X
- X void
- Xgotocmdend()
- X{
- X windgoto((int)Rows - 1, 0);
- X outchar('\n');
- X}
- X
- X static int
- Xcheck_readonly()
- X{
- X if (!forceit && curbuf->b_p_ro)
- X {
- X emsg(e_readonly);
- X return TRUE;
- X }
- X return FALSE;
- X}
- X
- X/*
- X * return TRUE if buffer was changed and cannot be abandoned.
- X */
- X static int
- Xcheck_changed(buf, checkaw, mult_win)
- X BUF *buf;
- X int checkaw; /* do autowrite if buffer was changed */
- X int mult_win; /* check also when several windows for this buffer */
- X{
- X if ( !forceit &&
- X buf->b_changed && (mult_win || buf->b_nwindows <= 1) &&
- X (!checkaw || autowrite(buf) == FAIL))
- X {
- X emsg(e_nowrtmsg);
- X return TRUE;
- X }
- X return FALSE;
- X}
- X
- X/*
- X * return TRUE if any buffer was changed and cannot be abandoned.
- X */
- X static int
- Xcheck_changed_any(checkaw)
- X int checkaw; /* do autowrite if buffer was changed */
- X{
- X BUF *buf;
- X
- X if (!forceit)
- X {
- X for (buf = firstbuf; buf != NULL; buf = buf->b_next)
- X {
- X if (buf->b_changed && (!checkaw || autowrite(buf) == FAIL))
- X {
- X EMSG2("No write since last change for buffer \"%s\"",
- X buf->b_xfilename == NULL ? (char_u *)"No File" : buf->b_xfilename);
- X return TRUE;
- X }
- X }
- X }
- X return FALSE;
- X}
- X
- X/*
- X * return FAIL if there is no filename, OK if there is one
- X * give error message for FAIL
- X */
- X int
- Xcheck_fname()
- X{
- X if (curbuf->b_filename == NULL)
- X {
- X emsg(e_noname);
- X return FAIL;
- X }
- X return OK;
- X}
- X
- X/*
- X * - if there are more files to edit
- X * - and this is the last window
- X * - and forceit not used
- X * - and not repeated twice on a row
- X * return FAIL and give error message if 'message' TRUE
- X * return OK otherwise
- X */
- X static int
- Xcheck_more(message)
- X int message; /* when FALSE check only, no messages */
- X{
- X if (!forceit && firstwin == lastwin && curwin->w_arg_idx + 1 < arg_count &&
- X quitmore == 0)
- X {
- X if (message)
- X {
- X emsg2((char_u *)"%ld more files to edit", (char_u *)(long)(arg_count - curwin->w_arg_idx - 1));
- X quitmore = 2; /* next try to quit is allowed */
- X }
- X return FAIL;
- X }
- X return OK;
- X}
- X
- X/*
- X * try to abandon current file and edit "fname"
- X * return 1 for "normal" error, 2 for "not written" error, 0 for success
- X * -1 for succesfully opening another file
- X * 'lnum' is the line number for the cursor in the new file (if non-zero).
- X */
- X int
- Xgetfile(fname, sfname, setpm, lnum)
- X char_u *fname;
- X char_u *sfname;
- X int setpm;
- X linenr_t lnum;
- X{
- X int other;
- X
- X fname_expand(&fname, &sfname); /* make fname full path and set sfname */
- X other = otherfile(fname);
- X
- X if (other && !forceit && curbuf->b_nwindows == 1 &&
- X !p_hid && curbuf->b_changed && autowrite(curbuf) == FAIL)
- X {
- X emsg(e_nowrtmsg);
- X return 2; /* file has been changed */
- X }
- X if (setpm)
- X setpcmark();
- X if (!other)
- X {
- X if (lnum != 0)
- X curwin->w_cursor.lnum = lnum;
- X check_cursor();
- X curwin->w_cursor.col = 0;
- X
- X return 0; /* it's in the same file */
- X }
- X if (doecmd(fname, sfname, NULL, p_hid, lnum) == OK)
- X return -1; /* opened another file */
- X return 1; /* error encountered */
- X}
- X
- X#ifdef WEBB_COMPLETE
- X/*
- X * vim_strncpy()
- X *
- X * This is here because strncpy() does not guarantee successful results when
- X * the to and from strings overlap. It is only currently called from nextwild()
- X * which copies part of the command line to another part of the command line.
- X * This produced garbage when expanding files etc in the middle of the command
- X * line (on my terminal, anyway) -- webb.
- X */
- X static void
- Xvim_strncpy(to, from, len)
- X char_u *to;
- X char_u *from;
- X int len;
- X{
- X int i;
- X
- X if (to <= from)
- X {
- X while (len-- && *from)
- X *to++ = *from++;
- X if (len >= 0)
- X *to = *from; /* Copy NUL */
- X }
- X else
- X {
- X for (i = 0; i < len; i++)
- X {
- X to++;
- X if (*from++ == NUL)
- X {
- X i++;
- X break;
- X }
- X }
- X for (; i > 0; i--)
- X *--to = *--from;
- X }
- X}
- X
- X/* Return FALSE if this is not an appropriate context in which to do
- X * completion of anything, & TRUE if it is (even if there are no matches). For
- X * the caller, this means that the character is just passed through like a
- X * normal character (instead of being expanded). This allows :s/^I^D etc.
- X */
- X static int
- X#else
- X static void
- X#endif /* WEBB_COMPLETE */
- Xnextwild(buff, type)
- X char_u *buff;
- X int type;
- X{
- X int i;
- X char_u *p1;
- X char_u *p2 = NULL;
- X int oldlen;
- X int difflen;
- X
- X#ifdef WEBB_COMPLETE
- X if (cmd_numfiles == -1)
- X set_expand_context(cmdfirstc, cmdbuff);
- X if (expand_context == EXPAND_UNSUCCESSFUL)
- X {
- X beep();
- X return OK; /* Something illegal on command line */
- X }
- X if (expand_context == EXPAND_NOTHING)
- X {
- X /* Caller can use the character as a normal char instead */
- X return FAIL;
- X }
- X expand_interactively = TRUE;
- X
- X#endif /* WEBB_COMPLETE */
- X msg_outstr((char_u *)"..."); /* show that we are busy */
- X flushbuf();
- X
- X#ifdef WEBB_COMPLETE
- X i = expand_pattern - buff;
- X#else
- X for (i = cmdpos; i > 0 && buff[i - 1] != ' '; --i)
- X ;
- X#endif /* WEBB_COMPLETE */
- X oldlen = cmdpos - i;
- X
- X /* add a "*" to the file name and expand it */
- X if ((p1 = addstar(&buff[i], oldlen)) != NULL)
- X {
- X if ((p2 = ExpandOne(p1, FALSE, type)) != NULL)
- X {
- X if (cmdlen + (difflen = STRLEN(p2) - oldlen) > CMDBUFFSIZE - 4)
- X emsg(e_toolong);
- X else
- X {
- X#ifdef WEBB_COMPLETE
- X vim_strncpy(&buff[cmdpos + difflen], &buff[cmdpos], cmdlen - cmdpos);
- X#else
- X STRNCPY(&buff[cmdpos + difflen], &buff[cmdpos], (size_t)(cmdlen - cmdpos));
- X#endif /* WEBB_COMPLETE */
- X STRNCPY(&buff[i], p2, STRLEN(p2));
- X cmdlen += difflen;
- X cmdpos += difflen;
- X }
- X free(p2);
- X }
- X free(p1);
- X }
- X redrawcmd();
- X#ifdef WEBB_COMPLETE
- X if (cmd_numfiles <= 0 && p2 == NULL)
- X beep();
- X else if (cmd_numfiles == 1)
- X {
- X (void)ExpandOne(NULL, FALSE, -2); /* free expanded "file" names */
- X cmd_numfiles = -1;
- X }
- X expand_interactively = FALSE;
- X return OK;
- X#endif /* WEBB_COMPLETE */
- X}
- X
- X/*
- X * Do wildcard expansion on the string 'str'.
- X * Return a pointer to alloced memory containing the new string.
- X * Return NULL for failure.
- X *
- X * mode = -2: only release file names
- X * mode = -1: normal expansion, do not keep file names
- X * mode = 0: normal expansion, keep file names
- X * mode = 1: use next match in multiple match
- X * mode = 2: use previous match in multiple match
- X * mode = 3: use next match in multiple match and wrap to first
- X * mode = 4: return all matches concatenated
- X * mode = 5: return longest matched part
- X */
- X char_u *
- XExpandOne(str, list_notfound, mode)
- X char_u *str;
- X int list_notfound;
- X int mode;
- X{
- X char_u *ss = NULL;
- X static char_u **cmd_files = NULL; /* list of input files */
- X static int findex;
- X int i, found = 0;
- X int multmatch = FALSE;
- X long_u len;
- X char_u *filesuf, *setsuf, *nextsetsuf;
- X int filesuflen, setsuflen;
- X
- X/*
- X * first handle the case of using an old match
- X */
- X if (mode >= 1 && mode < 4)
- X {
- X if (cmd_numfiles > 0)
- X {
- X if (mode == 2)
- X --findex;
- X else /* mode == 1 || mode == 3 */
- X ++findex;
- X if (findex < 0)
- X findex = 0;
- X if (findex > cmd_numfiles - 1)
- X {
- X if (mode == 3)
- X findex = 0;
- X else
- X findex = cmd_numfiles - 1;
- X }
- X return strsave(cmd_files[findex]);
- X }
- X else
- X return NULL;
- X }
- X
- X/* free old names */
- X if (cmd_numfiles != -1 && mode < 4)
- X {
- X FreeWild(cmd_numfiles, cmd_files);
- X cmd_numfiles = -1;
- X }
- X findex = 0;
- X
- X if (mode == -2) /* only release file name */
- X return NULL;
- X
- X if (cmd_numfiles == -1)
- X {
- X#ifdef WEBB_COMPLETE
- X if (ExpandFromContext((char_u *)str, &cmd_numfiles, &cmd_files, FALSE,
- X list_notfound) == FAIL)
- X /* error: do nothing */;
- X else if (cmd_numfiles == 0)
- X {
- X if (!expand_interactively)
- X emsg(e_nomatch);
- X }
- X#else
- X if (ExpandWildCards(1, (char_u **)&str, &cmd_numfiles, &cmd_files, FALSE, list_notfound) == FAIL)
- X /* error: do nothing */;
- X else if (cmd_numfiles == 0)
- X emsg(e_nomatch);
- X#endif /* WEBB_COMPLETE */
- X else if (mode < 4)
- X {
- X if (cmd_numfiles > 1) /* more than one match; check suffixes */
- X {
- X found = -2;
- X for (i = 0; i < cmd_numfiles; ++i)
- X {
- X if ((filesuf = STRRCHR(cmd_files[i], '.')) != NULL)
- X {
- X filesuflen = STRLEN(filesuf);
- X for (setsuf = p_su; *setsuf; setsuf = nextsetsuf)
- X {
- X if ((nextsetsuf = STRCHR(setsuf + 1, '.')) == NULL)
- X nextsetsuf = setsuf + STRLEN(setsuf);
- X setsuflen = (int)(nextsetsuf - setsuf);
- X if (filesuflen == setsuflen &&
- X STRNCMP(setsuf, filesuf, (size_t)setsuflen) == 0)
- X break;
- X }
- X if (*setsuf) /* suffix matched: ignore file */
- X continue;
- X }
- X if (found >= 0)
- X {
- X multmatch = TRUE;
- X break;
- X }
- X found = i;
- X }
- X }
- X if (multmatch || found < 0)
- X {
- X#ifdef WEBB_COMPLETE
- X /* Can we ever get here unless it's while expanding
- X * interactively? If not, we can get rid of this all together.
- X * Don't really want to wait for this message (and possibly
- X * have to hit return to continue!).
- X */
- X if (!expand_interactively)
- X#endif /* WEBB_COMPLETE */
- X emsg(e_toomany);
- X#ifdef WEBB_COMPLETE
- X else
- X beep();
- X#endif /* WEBB_COMPLETE */
- X found = 0; /* return first one */
- X multmatch = TRUE; /* for found < 0 */
- X }
- X if (found >= 0 && !(multmatch && mode == -1))
- X ss = strsave(cmd_files[found]);
- X }
- X }
- X
- X if (mode == 5 && cmd_numfiles > 0) /* find longest common part */
- X {
- X for (len = 0; cmd_files[0][len]; ++len)
- X {
- X for (i = 0; i < cmd_numfiles; ++i)
- X {
- X#ifdef AMIGA
- X if (toupper(cmd_files[i][len]) != toupper(cmd_files[0][len]))
- X#else
- X if (cmd_files[i][len] != cmd_files[0][len])
- X#endif
- X break;
- X }
- X if (i < cmd_numfiles)
- X break;
- X }
- X ss = alloc((unsigned)len + 1);
- X if (ss)
- X {
- X STRNCPY(ss, cmd_files[0], (size_t)len);
- X ss[len] = NUL;
- X }
- X multmatch = TRUE; /* don't free the names */
- X findex = -1; /* next p_wc gets first one */
- X }
- X
- X if (mode == 4 && cmd_numfiles > 0) /* concatenate all file names */
- X {
- X len = 0;
- X for (i = 0; i < cmd_numfiles; ++i)
- X len += STRLEN(cmd_files[i]) + 1;
- X ss = lalloc(len, TRUE);
- X if (ss)
- X {
- X *ss = NUL;
- X for (i = 0; i < cmd_numfiles; ++i)
- X {
- X STRCAT(ss, cmd_files[i]);
- X if (i != cmd_numfiles - 1)
- X STRCAT(ss, " ");
- X }
- X }
- X }
- X
- X#ifdef WEBB_COMPLETE
- X if (mode == -1 || mode == 4)
- X#else
- X if (!multmatch || mode == -1 || mode == 4)
- X#endif /* WEBB_COMPLETE */
- X {
- X FreeWild(cmd_numfiles, cmd_files);
- X cmd_numfiles = -1;
- X }
- X return ss;
- X}
- X
- X/*
- X * show all filenames that match the string "file" with length "len"
- X */
- X#ifdef WEBB_COMPLETE
- X static int
- Xshowmatches(buff)
- X char_u *buff;
- X#else
- X static void
- Xshowmatches(file, len)
- X char_u *file;
- X int len;
- X#endif /* WEBB_COMPLETE */
- X{
- X char_u *file_str;
- X int num_files;
- X char_u **files_found;
- X int i, j, k;
- X int maxlen;
- X int lines;
- X int columns;
- X
- X#ifdef WEBB_COMPLETE
- X set_expand_context(cmdfirstc, cmdbuff);
- X if (expand_context == EXPAND_UNSUCCESSFUL)
- X {
- X beep();
- X return OK; /* Something illegal on command line */
- X }
- X if (expand_context == EXPAND_NOTHING)
- X {
- X /* Caller can use the character as a normal char instead */
- X return FAIL;
- X }
- X expand_interactively = TRUE;
- X
- X /* add star to file name, or convert to regexp if not expanding files! */
- X file_str = addstar(expand_pattern, (int)(buff + cmdpos - expand_pattern));
- X if (file_str == NULL)
- X {
- X expand_interactively = FALSE;
- X return OK;
- X }
- X#else
- X file_str = addstar(file, len); /* add star to file name */
- X if (file_str == NULL)
- X return;
- X#endif /* WEBB_COMPLETE */
- X
- X msg_outchar('\n');
- X flushbuf();
- X
- X /* find all files that match the description */
- X#ifdef WEBB_COMPLETE
- X if (ExpandFromContext(file_str, &num_files, &files_found, FALSE, FALSE) == FAIL)
- X {
- X num_files = 0;
- X files_found = (char_u **)"";
- X }
- X#else
- X if (ExpandWildCards(1, &file_str, &num_files, &files_found, FALSE, FALSE) == FAIL)
- X return;
- X#endif /* WEBB_COMPLETE */
- X
- X /* find the maximum length of the file names */
- X maxlen = 0;
- X for (i = 0; i < num_files; ++i)
- X {
- X j = STRLEN(files_found[i]);
- X if (j > maxlen)
- X maxlen = j;
- X }
- X
- X /* compute the number of columns and lines for the listing */
- X maxlen += 2; /* two spaces between file names */
- X columns = ((int)Columns + 2) / maxlen;
- X if (columns < 1)
- X columns = 1;
- X lines = (num_files + columns - 1) / columns;
- X
- X (void)set_highlight('d'); /* find out highlight mode for directories */
- X
- X /* list the files line by line */
- X for (i = 0; i < lines; ++i)
- X {
- X for (k = i; k < num_files; k += lines)
- X {
- X if (k > i)
- X for (j = maxlen - STRLEN(files_found[k - lines]); --j >= 0; )
- X msg_outchar(' ');
- X#ifdef WEBB_COMPLETE
- X if (expand_context == EXPAND_FILES)
- X j = isdir(files_found[k]); /* highlight directories */
- X else
- X j = FALSE;
- X#else
- X j = isdir(files_found[k]); /* highlight directories */
- X#endif /* WEBB_COMPLETE */
- X if (j)
- X {
- X start_highlight();
- X screen_start(); /* don't output spaces to position cursor */
- X }
- X msg_outstr(files_found[k]);
- X if (j)
- X stop_highlight();
- X }
- X msg_outchar('\n');
- X flushbuf(); /* show one line at a time */
- X }
- X free(file_str);
- X FreeWild(num_files, files_found);
- X
- X/*
- X * we redraw the command below the lines that we have just listed
- X * This is a bit tricky, but it saves a lot of screen updating.
- X */
- X cmdline_row = msg_row; /* will put it back later */
- X#ifdef WEBB_COMPLETE
- X
- X expand_interactively = FALSE;
- X return OK;
- X#endif /* WEBB_COMPLETE */
- X}
- X
- X/*
- X * copy the file name into allocated memory and add a '*' at the end
- X */
- X static char_u *
- Xaddstar(fname, len)
- X char_u *fname;
- X int len;
- X{
- X char_u *retval;
- X#ifdef WEBB_COMPLETE
- X int i, j;
- X int new_len;
- X char_u save_char;
- X
- X if (expand_interactively && expand_context != EXPAND_FILES &&
- X expand_context != EXPAND_DIRECTORIES)
- X {
- X /* Matching will be done internally (on something other than files).
- X * So we convert the file-matching-type wildcards into our kind for
- X * use with regcomp(). First work out how long it will be:
- X */
- X new_len = len + 2; /* +2 for '^' at start, NUL at end */
- X for (i = 0; i < len; i++)
- X if (fname[i] == '*')
- X new_len++; /* '*' needs to be replaced by '.*' */
- X retval = alloc(new_len);
- X if (retval != NULL)
- X {
- X retval[0] = '^';
- X for (i = 0, j = 1; i < len; i++, j++)
- X if (fname[i] == '*')
- X {
- X retval[j++] = '.';
- X retval[j] = '*';
- X }
- X else if (fname[i] == '?')
- X retval[j] = '.';
- X else
- X retval[j] = fname[i];
- X retval[j] = NUL;
- X }
- X }
- X else
- X {
- X retval = alloc(len + 4);
- X if (retval != NULL)
- X {
- X STRNCPY(retval, fname, (size_t)len);
- X /*
- X * Don't add a star to ~ or ~user
- X */
- X save_char = fname[j = len];
- X fname[j] = NUL;
- X if (gettail(fname)[0] != '~')
- X {
- X#ifdef MSDOS
- X /*
- X * if there is no dot in the file name, add "*.*" instead of "*".
- X */
- X for (i = len - 1; i >= 0; --i)
- X if (strchr(".\\/:", retval[i]))
- X break;
- X if (i < 0 || retval[i] != '.')
- X {
- X retval[len++] = '*';
- X retval[len++] = '.';
- X }
- X#endif
- X retval[len++] = '*';
- X }
- X retval[len] = NUL;
- X fname[j] = save_char;
- X }
- X }
- X#else /* WEBB_COMPLETE */
- X#ifdef MSDOS
- X int i;
- X#endif
- X
- X retval = alloc(len + 4);
- X if (retval != NULL)
- X {
- X STRNCPY(retval, fname, (size_t)len);
- X#ifdef MSDOS
- X /*
- X * if there is no dot in the file name, add "*.*" instead of "*".
- X */
- X for (i = len - 1; i >= 0; --i)
- X if (strchr(".\\/:", retval[i]))
- X break;
- X if (i < 0 || retval[i] != '.')
- X {
- X retval[len++] = '*';
- X retval[len++] = '.';
- X }
- X#endif
- X retval[len] = '*';
- X retval[len + 1] = 0;
- X }
- X#endif /* WEBB_COMPLETE */
- X return retval;
- X}
- X
- X/*
- X * dosource: read the file "fname" and execute its lines as EX commands
- X *
- X * This function may be called recursively!
- X *
- X * return FAIL if file could not be opened, OK otherwise
- X */
- X int
- Xdosource(fname)
- X register char_u *fname;
- X{
- X register FILE *fp;
- X register int len;
- X#ifdef MSDOS
- X int error = FALSE;
- X#endif
- X
- X expand_env(fname, NameBuff, MAXPATHL); /* use NameBuff for expanded name */
- X if ((fp = fopen((char *)NameBuff, READBIN)) == NULL)
- X return FAIL;
- X
- X ++dont_sleep; /* don't call sleep() in emsg() */
- X len = 0;
- X while (fgets((char *)IObuff + len, IOSIZE - len, fp) != NULL && !got_int)
- X {
- X len = STRLEN(IObuff) - 1;
- X if (len >= 0 && IObuff[len] == '\n') /* remove trailing newline */
- X {
- X#ifdef MSDOS
- X if (len > 0 && IObuff[len - 1] == '\r') /* trailing CR-LF */
- X --len;
- X else
- X {
- X if (!error)
- X EMSG("Warning: Wrong line separator, ^M may be missing");
- X error = TRUE; /* lines like ":map xx yy^M" will fail */
- X }
- X#endif
- X /* escaped newline, read more */
- X if (len > 0 && len < IOSIZE && IObuff[len - 1] == Ctrl('V'))
- X {
- X IObuff[len - 1] = '\n'; /* remove CTRL-V */
- X continue;
- X }
- X IObuff[len] = NUL;
- X }
- X breakcheck(); /* check for ^C here, so recursive :so will be broken */
- X docmdline(IObuff);
- X len = 0;
- X }
- X fclose(fp);
- X if (got_int)
- X emsg(e_interr);
- X --dont_sleep;
- X return OK;
- X}
- X
- X/*
- X * get single EX address
- X */
- X static linenr_t
- Xget_address(ptr)
- X char_u **ptr;
- X{
- X linenr_t cursor_lnum = curwin->w_cursor.lnum;
- X int c;
- X int i;
- X long n;
- X char_u *cmd;
- X FPOS pos;
- X FPOS *fp;
- X linenr_t lnum;
- X
- X cmd = *ptr;
- X skipspace(&cmd);
- X lnum = MAXLNUM;
- X do
- X {
- X switch (*cmd)
- X {
- X case '.': /* '.' - Cursor position */
- X ++cmd;
- X lnum = cursor_lnum;
- X break;
- X
- X case '$': /* '$' - last line */
- X ++cmd;
- X lnum = curbuf->b_ml.ml_line_count;
- X break;
- X
- X case '\'': /* ''' - mark */
- X if (*++cmd == NUL || (fp = getmark(*cmd++, FALSE)) == NULL)
- X {
- X emsg(e_umark);
- X goto error;
- X }
- X lnum = fp->lnum;
- X break;
- X
- X case '/':
- X case '?': /* '/' or '?' - search */
- X c = *cmd++;
- X pos = curwin->w_cursor; /* save curwin->w_cursor */
- X curwin->w_cursor.col = -1; /* searchit() will increment the col */
- X if (c == '/')
- X {
- X if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) /* :/pat on last line */
- X curwin->w_cursor.lnum = 1;
- X else
- X ++curwin->w_cursor.lnum;
- X }
- X searchcmdlen = 0;
- X if (dosearch(c, cmd, FALSE, (long)1, FALSE, TRUE))
- X lnum = curwin->w_cursor.lnum;
- X curwin->w_cursor = pos;
- X
- X cmd += searchcmdlen; /* adjust command string pointer */
- X break;
- X
- X default:
- X if (isdigit(*cmd)) /* absolute line number */
- X lnum = getdigits(&cmd);
- X }
- X
- X while (*cmd == '-' || *cmd == '+')
- X {
- X if (lnum == MAXLNUM)
- X lnum = cursor_lnum;
- X i = *cmd++;
- X if (!isdigit(*cmd)) /* '+' is '+1', but '+0' is not '+1' */
- X n = 1;
- X else
- X n = getdigits(&cmd);
- X if (i == '-')
- X lnum -= n;
- X else
- X lnum += n;
- X }
- X
- X cursor_lnum = lnum;
- X } while (*cmd == '/' || *cmd == '?');
- X
- Xerror:
- X *ptr = cmd;
- X return lnum;
- X}
- X
- X
- X#ifdef WEBB_COMPLETE
- X/*
- X * Must parse the command line so far to work out what context we are in.
- X * Completion can then be done based on that context.
- X * This routine sets two global variables:
- X * char_u *expand_pattern --- The start of the pattern to be expanded within
- X * the command line (ends at the cursor).
- X * int expand_context --- The type of thing to expand. Will be one of:
- X * EXPAND_UNSUCCESSFUL --- Used somtimes when there is something illegal on
- X * the command line, like an unknown command. Caller should beep.
- X * EXPAND_NOTHING --- Unrecognised context for completion, use char like a
- X * normal char, rather than for completion. eg :s/^I/
- X * EXPAND_COMMANDS --- Cursor is still touching the command, so complete it.
- X * EXPAND_FILES --- After command with XFILE set, or after setting with
- X * P_EXPAND set. eg :e ^I, :w>>^I
- X * EXPAND_DIRECTORIES --- In some cases this is used instead of the latter
- X * when we know only directories are of interest. eg :set dir=^I
- X * EXPAND_SETTINGS --- Complete variable names. eg :set d^I
- X * EXPAND_BOOL_SETTINGS --- Complete bollean variables only, eg :set no^I
- X * EXPAND_TAGS --- Complete tags from the files in p_tags. eg :ta a^I
- X *
- X * -- webb.
- X */
- X static void
- Xset_expand_context(firstc, buff)
- X int firstc; /* either ':', '/', or '?' */
- X char_u *buff; /* buffer for command string */
- X{
- X char_u *nextcomm;
- X char_u old_char;
- X
- X old_char = cmdbuff[cmdpos];
- X cmdbuff[cmdpos] = NUL;
- X nextcomm = buff;
- X while (nextcomm != NULL)
- X nextcomm = set_one_cmd_context(firstc, nextcomm);
- X cmdbuff[cmdpos] = old_char;
- X}
- X
- X/*
- X * This is all pretty much copied from DoOneCmd(), with all the extra stuff we
- X * don't need/want deleted. Maybe this could be done better if we didn't
- X * repeat all this stuff. The only problem is that they may not stay perfectly
- X * compatible with each other, but then the command line syntax probably won't
- X * change that much -- webb.
- X */
- X static char_u *
- Xset_one_cmd_context(firstc, buff)
- X int firstc; /* either ':', '/', or '?' */
- X char_u *buff; /* buffer for command string */
- X{
- X register char_u *p;
- X char_u *cmd, *arg;
- X int i;
- X int cmdidx;
- X int argt;
- X char_u delim;
- X int forced = FALSE;
- X int usefilter = FALSE; /* filter instead of file name */
- X
- X expand_pattern = buff;
- X if (firstc != ':')
- X {
- X expand_context = EXPAND_NOTHING;
- X return NULL;
- X }
- X expand_context = EXPAND_COMMANDS; /* Default until we get past command */
- X
- X/*
- X * 2. skip comment lines and leading space, colons or bars
- X */
- X for (cmd = buff; *cmd && strchr(" \t:|", *cmd) != NULL; cmd++)
- X ;
- X expand_pattern = cmd;
- X
- X if (*cmd == NUL)
- X return NULL;
- X if (*cmd == '"') /* ignore comment lines */
- X {
- X expand_context = EXPAND_NOTHING;
- X return NULL;
- X }
- X
- X/*
- X * 3. parse a range specifier of the form: addr [,addr] [;addr] ..
- X */
- X
- X --cmd;
- X do
- X {
- X ++cmd; /* skip ',' or ';' */
- X skipspace(&cmd);
- X do
- X {
- X switch (*cmd)
- X {
- X case '.': /* '.' - Cursor position */
- X case '$': /* '$' - last line */
- X case '%': /* '%' - all lines */
- X ++cmd;
- X break;
- X
- X case '\'': /* ''' - mark */
- X if (*++cmd != NUL)
- X ++cmd;
- X break;
- X
- X case '/':
- X case '?': /* '/' or '?' - search */
- X delim = *cmd++;
- X while (*cmd != NUL && *cmd != delim)
- X cmd++;
- X if (*cmd == delim)
- X cmd++;
- X break;
- X
- X default:
- X while (isdigit((char)*cmd))
- X ++cmd;
- X break;
- X }
- X
- X while (*cmd == '-' || *cmd == '+')
- X {
- X cmd++;
- X while (isdigit(*cmd))
- X cmd++;
- X }
- X } while (*cmd == '/' || *cmd == '?');
- X } while (*cmd == ',' || *cmd == ';');
- X
- X/*
- X * 4. parse command
- X */
- X
- X skipspace(&cmd);
- X expand_pattern = cmd;
- X if (*cmd == NUL)
- X return NULL;
- X if (*cmd == '"')
- X {
- X expand_context = EXPAND_NOTHING;
- X return NULL;
- X }
- X
- X if (*cmd == '|' || *cmd == '\n')
- X return cmd + 1; /* There's another command */
- X
- X /*
- X * Isolate the command and search for it in the command table.
- X * Exeptions:
- X * - the 'k' command can directly be followed by any character.
- X * - the 's' command can be followed directly by 'c', 'g' or 'r'
- X */
- X if (*cmd == 'k')
- X {
- X cmdidx = CMD_k;
- X p = cmd + 1;
- X }
- X else
- X {
- X p = cmd;
- X while (isalpha(*p) || *p == '*') /* Allow * wild card */
- X ++p;
- X if (p == cmd && strchr("@!=><&~#", *p) != NULL) /* non-alpha command */
- X ++p;
- X i = (int)(p - cmd);
- X
- X if (i == 0)
- X {
- X expand_context = EXPAND_UNSUCCESSFUL;
- X return NULL;
- X }
- X for (cmdidx = 0; cmdidx < CMD_SIZE; ++cmdidx)
- X if (STRNCMP(cmdnames[cmdidx].cmd_name, cmd, (size_t)i) == 0)
- X break;
- X }
- X if (p == cmdbuff + cmdpos) /* We are still touching the command */
- X return NULL; /* So complete it */
- X
- X if (cmdidx == CMD_SIZE)
- X {
- X if (*cmd == 's' && strchr("cgr", cmd[1]) != NULL)
- X {
- X cmdidx = CMD_substitute;
- X p = cmd + 1;
- X }
- X else
- X {
- X /* Not still touching the command and it was an illegal command */
- X expand_context = EXPAND_UNSUCCESSFUL;
- X return NULL;
- X }
- X }
- X
- X expand_context = EXPAND_NOTHING; /* Default now that we're past command */
- X
- X if (*p == '!') /* forced commands */
- X {
- X forced = TRUE;
- X ++p;
- X }
- X
- X/*
- X * 5. parse arguments
- X */
- X argt = cmdnames[cmdidx].cmd_argt;
- X
- X arg = p; /* remember start of argument */
- X skipspace(&arg);
- X
- X if (cmdidx == CMD_write)
- X {
- X if (*arg == '>') /* append */
- X {
- X if (*++arg == '>') /* It should be */
- X ++arg;
- X skipspace(&arg);
- X }
- X else if (*arg == '!') /* :w !filter */
- X {
- X ++arg;
- X usefilter = TRUE;
- X }
- X }
- X
- X if (cmdidx == CMD_read)
- X {
- X usefilter = forced; /* :r! filter if forced */
- X if (*arg == '!') /* :r !filter */
- X {
- X ++arg;
- X usefilter = TRUE;
- X }
- X }
- X
- X if (cmdidx == CMD_lshift || cmdidx == CMD_rshift)
- X {
- X while (*arg == *cmd) /* allow any number of '>' or '<' */
- X ++arg;
- X skipspace(&arg);
- X }
- X
- X /*
- X * Check for '|' to separate commands and '"' to start comments.
- X * Don't do this for ":read !cmd" and ":write !cmd".
- X */
- X if ((argt & TRLBAR) && !usefilter)
- X {
- X p = arg;
- X while (*p)
- X {
- X if (*p == Ctrl('V'))
- X {
- X if (p[1] != NUL)
- X ++p;
- X }
- X else if ((*p == '"' && !(argt & NOTRLCOM)) || *p == '|' || *p == '\n')
- X {
- X if (*(p - 1) != '\\')
- X {
- X if (*p == '|' || *p == '\n')
- X return p + 1;
- X return NULL; /* It's a comment */
- X }
- X }
- X ++p;
- X }
- X }
- X
- X if (!(argt & EXTRA) && strchr("|\"", *arg) == NULL) /* no arguments allowed */
- X return NULL;
- X
- X /* Find start of last argument (argument just before cursor): */
- X p = cmdbuff + cmdpos;
- X while (p != arg && *p != ' ' && *p != TAB)
- X p--;
- X if (*p == ' ' || *p == TAB)
- X p++;
- X expand_pattern = p;
- X
- X if (argt & XFILE)
- X expand_context = EXPAND_FILES;
- X
- X/*
- X * 6. switch on command name
- X */
- X switch (cmdidx)
- X {
- X case CMD_cd:
- X case CMD_chdir:
- X expand_context = EXPAND_DIRECTORIES;
- X break;
- X case CMD_buffer:
- X case CMD_wnext:
- X case CMD_args: /* args now takes arguments like :next */
- X case CMD_next:
- X case CMD_snext:
- X case CMD_split:
- X case CMD_new:
- X case CMD_edit:
- X case CMD_ex:
- X case CMD_visual:
- X for (p = arg; *p; ++p)
- X {
- X if (*p == '\\' && p[1])
- X ++p;
- X else if (*p == '|' || *p == '\n')
- X return p + 1;
- X }
- X break;
- X case CMD_global:
- X case CMD_vglobal:
- X delim = *arg; /* get the delimiter */
- X if (delim)
- X ++arg; /* skip delimiter if there is one */
- X
- X while (arg[0] != NUL && arg[0] != delim)
- X {
- X if (arg[0] == '\\' && arg[1] != NUL)
- X ++arg;
- X ++arg;
- X }
- X if (arg[0] != NUL)
- X return arg + 1;
- X break;
- X case CMD_and:
- X case CMD_substitute:
- X delim = *arg;
- X if (delim)
- X ++arg;
- X for (i = 0; i < 2; i++, arg++)
- X while (arg[0] != NUL && arg[0] != delim)
- X {
- X if (arg[0] == '\\' && arg[1] != NUL)
- X ++arg;
- X ++arg;
- X }
- X while (arg[0] != NUL && strchr("|\"#", arg[0]) == NULL)
- X ++arg;
- X if (arg[0] != NUL)
- X return arg;
- X break;
- X case CMD_set:
- X set_context_in_set_cmd(arg);
- X break;
- X case CMD_tag:
- X expand_context = EXPAND_TAGS;
- X expand_pattern = arg;
- X break;
- X default:
- X break;
- X }
- X return NULL;
- X}
- X
- X/*
- X * Do the expansion based on the global variables expand_context and
- X * expand_pattern -- webb.
- X */
- X static int
- XExpandFromContext(pat, num_file, file, files_only, list_notfound)
- X char_u *pat;
- X int *num_file;
- X char_u ***file;
- X int files_only;
- X int list_notfound;
- X{
- X regexp *prog;
- X int cmdidx;
- X int count;
- X int ret;
- X int i;
- X
- X if (!expand_interactively || expand_context == EXPAND_FILES)
- X return ExpandWildCards(1, &pat, num_file, file, files_only, list_notfound);
- X else if (expand_context == EXPAND_DIRECTORIES)
- X {
- X if (ExpandWildCards(1, &pat, num_file, file, files_only, list_notfound)
- X == FAIL)
- X return FAIL;
- X count = 0;
- X for (i = 0; i < *num_file; i++)
- X if (isdir((*file)[i]))
- X (*file)[count++] = (*file)[i];
- X else
- X free((*file)[i]);
- X if (count == 0)
- X {
- X free(*file);
- X *file = (char_u **)"";
- X *num_file = -1;
- X return FAIL;
- X }
- X *num_file = count;
- X return OK;
- X }
- X *file = (char_u **)"";
- X *num_file = 0;
- X ret = OK;
- X reg_ic = FALSE;
- X reg_magic = p_magic;
- X prog = regcomp(pat);
- X if (prog == NULL)
- X return FAIL;
- X if (expand_context == EXPAND_COMMANDS)
- X {
- X /* Count the matches: */
- X count = 0;
- X for (cmdidx = 0; cmdidx < CMD_SIZE; cmdidx++)
- X if (regexec(prog, cmdnames[cmdidx].cmd_name, TRUE))
- X count++;
- X if (count == 0
- X || (*file = (char_u **) alloc((int)(count * sizeof(char_u *)))) == NULL)
- X ret = FAIL;
- X else
- X {
- X *num_file = count;
- X count = 0;
- X for (cmdidx = 0; cmdidx < CMD_SIZE; cmdidx++)
- X if (regexec(prog, cmdnames[cmdidx].cmd_name, TRUE))
- X (*file)[count++] = strsave(cmdnames[cmdidx].cmd_name);
- X }
- X }
- X else if (expand_context == EXPAND_SETTINGS
- X || expand_context == EXPAND_BOOL_SETTINGS)
- X ret = ExpandSettings(prog, num_file, file);
- X else if (expand_context == EXPAND_TAGS)
- X ret = ExpandTags(prog, num_file, file);
- X else
- X ret = FAIL;
- X
- X free(prog);
- X return ret;
- X}
- X#endif /* WEBB_COMPLETE */
- END_OF_FILE
- if test 44081 -ne `wc -c <'vim/src/cmdline.c.B'`; then
- echo shar: \"'vim/src/cmdline.c.B'\" unpacked with wrong size!
- elif test -f 'vin/src/cmdline.c.A'; then
- echo shar: Combining \"'vim/src/cmdline.c'\" \(82989 characters\)
- cat 'vim/src/cmdline.c.A' 'vim/src/cmdline.c.B' > 'vim/src/cmdline.c'
- if test 82989 -ne `wc -c <'vim/src/cmdline.c'`; then
- echo shar: \"'vim/src/cmdline.c'\" combined with wrong size!
- else
- rm vim/src/cmdline.c.A vim/src/cmdline.c.B
- fi
- fi
- # end of 'vim/src/cmdline.c.B'
- fi
- if test -f 'vim/src/proto/buffer.pro' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'vim/src/proto/buffer.pro'\"
- else
- echo shar: Extracting \"'vim/src/proto/buffer.pro'\" \(1276 characters\)
- sed "s/^X//" >'vim/src/proto/buffer.pro' <<'END_OF_FILE'
- X/* buffer.c */
- Xint open_buffer __PARMS((void));
- Xvoid close_buffer __PARMS((struct buffer *buf, int free_buf, int remove));
- Xvoid buf_clear __PARMS((struct buffer *buf));
- Xvoid buf_freeall __PARMS((struct buffer *buf));
- Xint do_buffer __PARMS((int action, int start, int dir, int count, int forceit));
- Xstruct buffer *buflist_new __PARMS((unsigned char *fname, unsigned char *sfname, long lnum, int use_curbuf));
- Xint buflist_getfile __PARMS((int n, long lnum, int setpm));
- Xvoid buflist_getlnum __PARMS((void));
- Xunsigned char *buflist_nr2name __PARMS((int n));
- Xvoid buflist_list __PARMS((void));
- Xint buflist_name_nr __PARMS((int fnum, unsigned char **fname, long *lnum));
- Xint setfname __PARMS((unsigned char *fname, unsigned char *sfname, int message));
- Xvoid setaltfname __PARMS((unsigned char *fname, unsigned char *sfname, long lnum));
- Xint buflist_add __PARMS((unsigned char *fname));
- Xvoid buflist_altlnum __PARMS((void));
- Xint otherfile __PARMS((unsigned char *fname));
- Xvoid fileinfo __PARMS((int fullname));
- Xvoid maketitle __PARMS((void));
- Xvoid resettitle __PARMS((void));
- Xunsigned char *fix_fname __PARMS((unsigned char *fname));
- Xvoid fname_expand __PARMS((unsigned char **fname, unsigned char **sfname));
- Xvoid do_arg_all __PARMS((void));
- Xvoid do_buffer_all __PARMS((int all));
- END_OF_FILE
- if test 1276 -ne `wc -c <'vim/src/proto/buffer.pro'`; then
- echo shar: \"'vim/src/proto/buffer.pro'\" unpacked with wrong size!
- fi
- # end of 'vim/src/proto/buffer.pro'
- fi
- echo shar: End of archive 8 \(of 26\).
- cp /dev/null ark8isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 26 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-