home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume44 / vim / part08 < prev    next >
Encoding:
Internet Message Format  |  1994-08-16  |  70.1 KB

  1. From: mool@oce.nl (Bram Moolenaar)
  2. Newsgroups: comp.sources.misc
  3. Subject: v44i027:  vim - Vi IMproved editor, v3.0, Part08/26
  4. Date: 16 Aug 1994 21:18:01 -0500
  5. Organization: Sterling Software
  6. Sender: kent@sparky.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <32rs0p$kd4@sparky.sterling.com>
  9. X-Md4-Signature: 7cecb61518ccc01a0cc898127514fdd4
  10.  
  11. Submitted-by: mool@oce.nl (Bram Moolenaar)
  12. Posting-number: Volume 44, Issue 27
  13. Archive-name: vim/part08
  14. Environment: UNIX, AMIGA, MS-DOS, Windows NT
  15. Supersedes: vim: Volume 41, Issue 50-75
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  vim/doc/difference.doc vim/src/cmdline.c.B
  22. #   vim/src/proto/buffer.pro
  23. # Wrapped by kent@sparky on Mon Aug 15 21:44:02 1994
  24. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  25. echo If this archive is complete, you will see the following message:
  26. echo '          "shar: End of archive 8 (of 26)."'
  27. if test -f 'vim/doc/difference.doc' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'vim/doc/difference.doc'\"
  29. else
  30.   echo shar: Extracting \"'vim/doc/difference.doc'\" \(20566 characters\)
  31.   sed "s/^X//" >'vim/doc/difference.doc' <<'END_OF_FILE'
  32. X
  33. X
  34. XThis is a summary of the differences between VIM and vi. It is not complete.
  35. Xsee also reference.doc and look for comments in {}.
  36. X
  37. X
  38. XThe most interesting additions:
  39. X
  40. XVi compatibility.
  41. XWhen the 'compatible' option is set, all options are given a vi-compatible
  42. Xvalue. Vim will behave like the "real" vi as much as possible.
  43. X
  44. X
  45. XMulti level undo.
  46. X'u' goes backward in time, 'ctrl-R' goes forward again. Set option 
  47. X'undolines' to the number of changes to be remembered (default 100). Set 
  48. X'undolines' to 0 for vi-compatible one level undo.
  49. X
  50. XWhen all changes in a buffer have been undone, the buffer is not considered
  51. Xchanged anymore. You can exit it with :q, without <!>.
  52. X
  53. X
  54. XMultiple windows and buffers.
  55. XVim can split the screen into several windows, each editing a different
  56. Xbuffer or the same buffer at a different location. Buffers can still be
  57. Xloaded (and changed) but not displayed in a window. This is called a hidden
  58. Xbuffer. Many commands and options have been added for this facility, see
  59. Xwindows.doc.
  60. X
  61. X
  62. XRepeat a series of commands.
  63. X'q'<c> starts recording typed characters into named register <c> (append to
  64. Xthe register if register name is upper case). A subsequent 'q' stops
  65. Xrecording. The register can then be executed with the '@'<c> command. This is
  66. Xvery useful to repeat a complex action.
  67. X
  68. X
  69. XFlexible insert mode.
  70. XThe arrow keys can be used in insert mode to move around in the file. This 
  71. Xbreaks the insert in two parts as far as undo and redo is concerned.
  72. X
  73. XCTRL-O can be used to execute a single command-mode command. This is almost 
  74. Xthe same as hitting ESC, typing the command and hitting 'a'. For undo/redo 
  75. Xonly those inserts are remembered where something was actually inserted.
  76. X
  77. X
  78. XVisual mode.
  79. XVisual can be used to first choose a piece of text and then give a command 
  80. Xto do something with it. This is an (easy to use) alternative to first giving 
  81. Xthe operator and then moving to the end of the text to be operated upon. 'v' 
  82. Xand 'V' are used to start Visual mode. 'v' works on characters and 'V' on
  83. Xlines. Move the cursor to extend the Visual part. It is shown highlighted on
  84. Xthe screen. By typing 'o' the other end of the Visual text can be moved. The
  85. XVisual text can be affected by an operator:
  86. X    d    delete
  87. X    c    change
  88. X    y    yank
  89. X    > or <    insert or delete indent
  90. X    !    filter through external program
  91. X    =    filter through indent
  92. X    :    start ":" command for the Visual lines.
  93. X    Q    format text to 'textwidth' columns
  94. X    J    join lines
  95. X    ~    swap case
  96. X    u    make lowercase
  97. X    U    make uppercase
  98. X
  99. X
  100. XBlock operators.
  101. XWith Visual a rectangular block of text can be selected. Start Visual with 
  102. XCTRL-V. The block can be deleted ('d'), yanked ('y') or its case can be 
  103. Xchanged ('~', 'u' and 'U'). A deleted or yanked block can be put into the
  104. Xtext with the 'p' and 'P' commands.
  105. X
  106. X
  107. XOnline help.
  108. X':help' command and help key (F1 for MSDOS) display several pages of concise 
  109. Xhelp. The name of the help file can be set with the "helpfile" option.
  110. X
  111. X
  112. XCommand line editing.
  113. XYou can insert or delete at any place in the command line using the cursor 
  114. Xkeys. The right/left cursor keys can be used to move forward/backward one 
  115. Xcharacter. The shifted right/left cursor keys can be used to move 
  116. Xforward/backward one word. CTRL-B/CTRL-E can be used to go to the begin/end
  117. Xof the command line.
  118. X
  119. XThe command lines are remembered. The up/down cursor keys can be used to 
  120. Xrecall previous command lines. The 'history' option can be set to the number 
  121. Xof lines that will be remembered.
  122. X
  123. X
  124. XCommand line completion.
  125. XWhile entering a command line (on the bottom line of the screen) <TAB> can be 
  126. Xtyped to complete
  127. X   what        example        where
  128. X- a command    :e<TAB>        at start of command line
  129. X- a tag        :ta no<TAB>    after :ta
  130. X- an option    :set sc<TAB>    after :set
  131. X- a filename    :e v<TAB>    after any command that accepts a filename
  132. X
  133. XIf there are multiple matches, CTRL-N (next) and CTRL-P (previous) will walk
  134. Xthrough the matches. <TAB> works line CTRL-N, but wraps around to the first
  135. Xmatch.
  136. X
  137. XThe 'wildchar' option can be set to the character for command line
  138. Xcompletion, <TAB> is the default. CTRL-D can be typed after an (incomplete)
  139. Xwildcard; all matches will be listed. CTRL-A will insert all matches.
  140. XCTRL-L will insert the longest common part of the matches.
  141. X
  142. X
  143. XHorizontal scrolling.
  144. XIf the 'wrap' option is off, long lines will not wrap and only part of them
  145. Xwill be shown. When the cursor is moved to a part that is not shown, the
  146. Xscreen will scroll horizontally. The minimal number of columns to scroll can
  147. Xbe set with the 'sidescroll' option.
  148. X
  149. X
  150. XText formatting.
  151. XThe 'textwidth' (tw) option can be used to automatically limit the line 
  152. Xlength. This supplements the 'wrapmargin' option of Vi, which was not very 
  153. Xuseful. The 'Q' operator can be used to format a piece of text ("Q}" formats 
  154. Xa paragraph). Commands for text alignment: ":center", ":left" and ":right".
  155. X
  156. X
  157. XEdit-compile-edit speedup.
  158. XThe ":make" command can be used to run the compilation and jump to the first
  159. Xerror. Alternatively Vim can be started with the "-e" option from the
  160. Xcompiler. A file with compiler error messages is interpreted. Each line in
  161. Xthe error file is scanned for the name of a file, line number and error
  162. Xmessage. Vim starts editing at the first error. Optionally the name of the
  163. Xerror file can be given with "-e errorfile". The ":cn" command can be used to
  164. Xjump to the next error. ":cl" lists all the error messages. Other commands
  165. Xare available (almost the same as with Manx's Z editor). The 'errorfile'
  166. Xoption has the name of the file with error messages. The 'errorformat' option
  167. Xcan be set to a scanf-like string to handle output from many compilers. The
  168. X'makeprg' option contains the name of the program to be executed with the
  169. X":make" command. The 'shellpipe' option contains the string to be used to put
  170. Xthe output of the compiler into the errorfile.
  171. X
  172. X
  173. XCommand line options:
  174. X
  175. XWhen Vim is started with "-v" (View) then readonly mode is used (includes 
  176. X"-n").
  177. X
  178. XWhen Vim is started with "-b" (Binary) then some options are set to be able
  179. Xto edit binary or executable files.
  180. X
  181. XWhen Vim is started with "-s scriptfile", the characters read from 
  182. X"scriptfile" are treated as if you typed them. If end of file is reached 
  183. Xbefore the editor exits, further characters are read from the console.
  184. X
  185. XThe "-w" option can be used to record all typed characters in a script file. 
  186. XThis file can then be used to redo the editing, possibly on another file or 
  187. Xafter changing some commands in the script file.
  188. X
  189. XThe "-n" option disables the writing of a ".swp" file (see below).
  190. X
  191. XThe "-c command" option does the same as the the "+command" option.
  192. X
  193. XThe "-T terminal" option sets the terminal type.
  194. X
  195. XThe "-e" option starts Vim in quickfix mode.
  196. X
  197. XThe "-o" option opens a window for each argument. "-o4" opens four windows.
  198. X
  199. X
  200. XIn command mode:
  201. X
  202. XMissing command: 'Q' (go to Ex mode).
  203. XMissing Ex commands: append, change, insert, open, recover and z.
  204. X
  205. XThe command characters are shown in the last line of the screen. They are 
  206. Xremoved when the command is finished. If you do not want this (on a slow 
  207. Xterminal) reset the 'showcmd' option.
  208. X
  209. XIf the 'ruler' option is set, the current cursor position is shown in the 
  210. Xlast line of the screen.
  211. X
  212. X'u' and CTRL-R accept a count for the number of undos/redos.
  213. X
  214. X'U' still works after having moved off of the last changed line and after 
  215. X'u'.
  216. X
  217. XNulls in the file are replaced by <LF> internally. This allows editing of 
  218. Xbinary files (more or less).
  219. X
  220. XCharacters with the 8th bit set are displayed. The characters between '~' and 
  221. X0xa0 are displayed as "~?", "~@", "~A", etc., unless the "graphic' option is 
  222. Xset.
  223. X
  224. X'=' is an operator to filter lines through an external command (vi: lisp 
  225. Xstuff). The name of the command can be set with the 'equalprg' option. The 
  226. Xdefault is "indent".
  227. X
  228. X'][' goes to the next ending of a C function ('}' in column 1).
  229. X'[]' goes to the previous ending of a C function ('}' in column 1).
  230. X
  231. X']f', '[f' and 'gf' start editing the file whose name is under the cursor.
  232. XCTRL-W f splits the window and starts editint the file whose name is under
  233. Xthe cursor.
  234. X
  235. X'*' searches forward for the identifier under the cursor, '#' backward.
  236. X'K' runs the program defined by the "keywordprg" option, with the identifier 
  237. Xunder the cursor as argument.
  238. X
  239. X'%' can be preceded with a count. The cursor jumps to the line that 
  240. Xpercentage down in the file. The normal '%' function to jump to the matching
  241. Xbrace skips braces inside quotes.
  242. X
  243. XWith the CTRL-] command, the cursor may be in the middle of the identifier.
  244. X
  245. XThe used tags are remembered. Commands that can be used with the tag stack 
  246. Xare CTRL-T, ':pop' and ':tag'. ':tags' lists the tag stack.
  247. X
  248. XThe 'tags' option can be set to a list of tag file names. Thus multiple 
  249. Xtag files can be used.
  250. X
  251. XPreviously used file names are remembered in the alternate file name list.
  252. XCTRL-^ accepts a count, which is an index in this list.
  253. X
  254. XSearch patterns have more features. The <NL> character is seen as part of the
  255. Xsearch pattern and the substitute string of ":s". Vi sees it as the end of
  256. Xthe command.
  257. X
  258. XSearches can put the cursor on the end of a match and may include a character
  259. Xoffset.
  260. X
  261. XCount added to '~', ':next', ':Next', 'n' and 'N'.
  262. X
  263. XThe command ":next!" with 'autowrite' set does not write the file. In vi the
  264. Xfile was written, but this is considered to be a bug, because one does not
  265. Xexpect it and the file is not written with ':rewind!'.
  266. X
  267. X"5r<CR>" replaces five characters by five line breaks. Vi replaces five
  268. Xcharacters with a single line break.
  269. X
  270. XAdded :wnext command. Same as ":write" followed by ":next".
  271. X
  272. XThe ":w!" command always writes, also when the file is write protected.
  273. X
  274. XIf option "tildeop" has been set, '~' is an operator (must be followed by a 
  275. Xmovement command).
  276. X
  277. XWith the 'J' (join) command you can reset the 'joinspaces' (js) option to 
  278. Xhave only one space after a period (Vi inserts two spaces).
  279. X
  280. X'cw' can be used to change white space formed by several characters (Vi is 
  281. Xconfusing: 'cw' only changes one space, while 'dw' deletes all white space).
  282. X
  283. X'o' and 'O' accept a count for repeating the insert (Vi clears a part of 
  284. Xdisplay).
  285. X
  286. X':dis' command shows the contents of the yank register.
  287. X
  288. XPreviously used file names are remembered in the alternate file name list.
  289. X":files" command shows the list of alternate filenames.
  290. X'#'<N> is replaced by the <N>th alternate filename in the list.
  291. X"#<" is replaced by the current filename without extension.
  292. X
  293. XFlags after command not supported (no plans to include it).
  294. X
  295. XOn non-UNIX systems ":cd" command shows current directory instead of going to
  296. Xthe home directory. ":pwd" prints the current directory on all systems.
  297. X
  298. X':source!' command reads Vi commands from a file.
  299. X
  300. X':mkexrc' command writes current modified options and mappings to a ".exrc" 
  301. Xfile. ':mkvimrc' writes to a ".vimrc" file.
  302. X
  303. XNo check for "tail recursion" with mappings. This allows things like
  304. X":map! foo ^]foo".
  305. X
  306. XThe :put! command inserts the contents of a register above the current line.
  307. X
  308. XThe 'p' and 'P' commands of vi cannot be repeated with '.' when the putted
  309. Xtext is less than a line. In Vim they can always be repeated.
  310. X
  311. XThe named register '.' can be used with commands p, P and :put. The contents 
  312. Xof the register is the last inserted text.
  313. X
  314. X":noremap" command can be used to enter a mapping that will not be remapped.
  315. XThis is useful to exchange the meaning of two keys. ":cmap", ":cunmap" and
  316. X":cnoremap" can be used for mapping in command line editing only. ":imap",
  317. X":iunmap" and ":inoremap" can be used for mapping in insert mode only.
  318. XSimilar commands exist for abbreviations: ":noreabbrev", ":iabbrev"
  319. X":cabbrev", ":iunabbrev", ":cunabbrev", ":inoreabbrev", ":cnoreabbrev".
  320. X
  321. XIn vi the command ":map foo bar" would remove a previous mapping
  322. X":map bug foo". This is considered a bug, so it is not included in Vim.
  323. X":unmap! foo" does remove ":map! bug foo", because unmapping would be very
  324. Xdifficult otherwise (this is vi compatible).
  325. X
  326. X":@r" command executes register r (is in some versions of vi).
  327. X
  328. XThe ':' register contains the last command line.
  329. XThe '%' register contians the current file name.
  330. X
  331. XCTRL-O/CTRL-I can be used to jump to older/newer positions. These are the 
  332. Xsame positions as used with the '' command, but may be in another file. The 
  333. X':jumps' command lists the older positions.
  334. X
  335. XIf the 'shiftround' option is set, an indent is rounded to a multiple of 
  336. X'shiftwidth' with '>' and '<' commands.
  337. X
  338. XThe 'scrolljump' option can be set to the minimal number of lines to scroll 
  339. Xwhen the cursor gets off the screen. Use this when scrolling is slow.
  340. X
  341. XUppercase marks can be used to jump between files. The ':marks' command lists 
  342. Xall currently set marks. The commands "']" and "`]" jump to the end of the 
  343. Xprevious operator or end of the text inserted with the put command. "'[" and 
  344. X"`[" do jump to the start.
  345. X
  346. XThe 'shelltype' option can be set to reflect the type of shell used.
  347. X
  348. XThe 'highlight' option can be set for the higlight mode to be used for
  349. Xseveral commands.
  350. X
  351. XThe CTRL-A (add) and CTRL-X (subtract) commands are new. The count to the 
  352. Xcommand (default 1) is added to/subtracted from the number at or after the 
  353. Xcursor. That number may be decimal, octal (starts with a '0') or hexadecimal 
  354. X(starts with '0x'). Very useful in macros.
  355. X
  356. XWith the :set command the prefix "inv" can be used to invert toggle options.
  357. X
  358. XIn both Vi and Vim you can create a line break with the ":substitute" command
  359. Xby using a CTRL-M. For Vi this means you cannot insert a real CTRL-M in the
  360. Xtext. With Vim you can put a real CTRL-M in the text by preceding it with a
  361. XCTRL-V.
  362. X
  363. X
  364. XIn insert mode:
  365. X
  366. XIf the 'revins' option is set, insert happens backwards. This is for typing
  367. XHebrew. When inserting normal characters the cursor will not be shifted and
  368. Xthe text moves rightwards. In replace mode the cursor will move leftwards.
  369. XBackspace, CTRL-W and CTRL-U will also work in the opposite direction. CTRL-B
  370. Xtoggles the 'revins' option.
  371. X
  372. XThe backspace key can be used just like CTRL-D to remove auto-indents.
  373. X
  374. XYou can backspace, ctrl-U and CTRL-W over line breaks if the 'backspace' (bs) 
  375. Xoption is set to non-zero. You can backspace over the start of insert if the 
  376. X'backspace' option is set to 2.
  377. X
  378. XWhen the 'paste' option is set, a few option are reset and mapping in insert
  379. Xmode and abbreviation are disabled. This allows for pasting text in windowing
  380. Xsystems without unexpected results. When the 'paste' option is reset, the old
  381. Xoption values are restored.
  382. X
  383. XCTRL-T/CTRL-D always insert/delete an indent in the current line, no matter 
  384. Xwhat column the cursor is in.
  385. X
  386. XCTRL-@ (insert previously inserted text) works always (Vi: only when typed as 
  387. Xfirst character).
  388. X
  389. XCTRL-A works like CTRL-@ but does not leave insert mode.
  390. X
  391. XCTRL-R <0-9a-z> can be used to insert the contents of a register.
  392. X
  393. XWhen the 'smartindent' (si) option is set, C programs will be better 
  394. Xauto-indented.
  395. X
  396. XCTRL-Y and CTRL-E can be used to copy a character from above/below the 
  397. Xcurrent cursor position.
  398. X
  399. XAfter CTRL-V you can enter a three digit decimal number. This byte value is 
  400. Xinserted in the text as a single character. Useful for international 
  401. Xcharacters that are not on your keyboard.
  402. X
  403. XWhen the 'expandtab' (et) option is set, a <TAB> is expanded to the 
  404. Xappropriate number of spaces.
  405. X
  406. XThe window always reflects the contents of the buffer (Vi does not do this 
  407. Xwhen changing text and in some other cases).
  408. X
  409. XIf Vim is compiled with DIGRAPHS defined, digraphs are supported. A set of 
  410. Xnormal Amiga digraphs is included. They are shown with the :digraph" command. 
  411. XMore can be added with ":digraph {char1}{char2} {number}". A digraph is 
  412. Xentered with "CTRL-K {char1} {char2}" or "{char1} BS {char2}" (only when 
  413. X'digraph' option is set).
  414. X
  415. XWhen repeating an insert, e.g. "10atest <ESC>" vi would only handle wrapmargin
  416. Xfor the first insert. Vim does it for all.
  417. X
  418. X
  419. XIn command line mode:
  420. X
  421. XESC terminates the command line without executing it. In vi the command line
  422. Xwould be executed, which is not what most people expect (hitting ESC should
  423. Xalways get you back to command mode). To avoid problems with some
  424. Xobscure macros, an ESC in a macro will execute the command. If you want a
  425. Xtyped ESC to execute the command like vi does you can fix this with
  426. X    ":cmap ^V<ESC> ^V<CR>"
  427. X
  428. Xgeneral:
  429. X
  430. XMissing options: autoprint (ap), beautify (bf), edcompatible, hardtabs (ht), 
  431. Xlisp, mesg, open, optimize (op), prompt, redraw, slowopen (slow), terse,
  432. Xwindow, w300, w1200 and w9600. These options can be set but are otherwise
  433. Xignored.
  434. X
  435. XWhen the 'compatible' option is set, all options are set for maximum 
  436. Xvi-compatibility
  437. X
  438. XThe 'ttimeout' option is like 'timeout', but only works for cursor and 
  439. Xfunction keys, not for ordinary mapped characters. The 'timoutlen' option
  440. Xgives the number of milliseconds that is waited for. If the 'esckeys' option
  441. Xis not set, cursor and function keys that start with <ESC> are not recognized
  442. Xin insert mode.
  443. X
  444. XThere is an option for each terminal string. Can be used when termcap is not 
  445. Xsupported or to change individual strings.
  446. X
  447. XWhen the 'textmode' option is set (default for MSDOS) <CR><LF> is used as
  448. Xline separator. When reset (default for Unix and Amiga) <LF> is used. When
  449. Xthe 'textauto' option is set, Vim tries to detect the type of line separator
  450. Xused by reading up to the first <LF>. The 'textmode' option is set
  451. Xaccordingly.
  452. X
  453. XOn systems that have no job control (most systems but BSD-UNIX) the CTRL-Z, 
  454. X":stop" or ":suspend" command starts a new shell.
  455. X
  456. XIf Vim is started on the Amiga without an interactive window for output, a 
  457. Xwindow is opened (and :sh still works). You can give a device to use for 
  458. Xediting with the '-d' argument, e.g. "-d con:20/20/600/150".
  459. X
  460. XOn startup the VIMINIT or EXINIT environment variables, the file s:.vimrc or 
  461. Xs:.exrc and .vimrc or .exrc are read for initialization commands. When 
  462. Xreading .vimrc and .exrc some commands are not allowed because of security 
  463. Xreasons (shell commands and writing to a file, :map commands are echoed). 
  464. XThis can be overrided with the 'secure' option.
  465. X
  466. XLine lenght can be at least upto the maximum value of an int (for the Amiga
  467. X32767 characters, for most 32-bit systems much larger). Editing such lines is
  468. Xnot always possible. File length upto 2147483646 lines. If a line is larger
  469. Xthan the screen, the last line is filled with <@>s and only the part of the
  470. Xline before that is shown (unless 'wrap' option is reset).
  471. X
  472. XThe 'columns' option is used to set or get the width of the display.
  473. X
  474. XThe name of the current file name is shown in the title bar of the window.
  475. X
  476. XWildcards in file names are expanded.
  477. X
  478. XOption settings are read from the first and last few lines of the file. 
  479. XOption 'modelines' determines how many lines are tried (default is 5). Note 
  480. Xthat this is different from the Vi versions that can execute any Ex command 
  481. Xin a modeline (a major security problem).
  482. X
  483. XIf the 'insertmode' option is set (e.g. in .exrc), Vim starts in insert mode.
  484. X
  485. XAll text is kept in memory. Available memory limits the file size (and other 
  486. Xthings such as undo). This may be a problem with MSDOS, is hardly a problem 
  487. Xont the Amiga and almost never with Unix.
  488. X
  489. XIf the 'backup' or 'writebackup' option is set: Before a file is overwritten, 
  490. Xa backup file (.bak) is made. If the "backup" option is set it is left 
  491. Xbehind.
  492. X
  493. XIf the 'binary' option is set and the file does not have an end-of-line for
  494. Xthe last line, the end-of-line is not appended when writing.
  495. X
  496. XVim creates a file ending in ".swp" to store parts of the file that have been
  497. Xchanged or that do not fit in memory. This file can be used to recover from
  498. Xan aborted editing session with "vim -r file". Using the swap file can be
  499. Xswitched off by setting the 'updatecount' option to 0 or starting Vim with
  500. Xthe "-n" option. Use the 'directory' option for placing the .swp file
  501. Xsomewhere else.
  502. X
  503. XThe 'shortname' (sn) option, when set, tells Vim that ".bak" and ".swp" 
  504. Xfilenames are to be MSDOS-like: 8 characters plus 3 for extention. This 
  505. Xshould be used on messydos or crossdos filesystems on the Amiga. If this 
  506. Xoption is off, Vim tries to guess if MSDOS filename restrictions are 
  507. Xeffective.
  508. X
  509. XRecovery after a crash has a smaller chance for success, because there is no 
  510. Xtemporary file.
  511. X
  512. XError messages are shown at least one second (Vi overwrites error messages).
  513. X
  514. XIf Vim asks to "Hit RETURN to continue", you can hit any key. Characters 
  515. Xother than <CR>, <LF> and <SPACE> are interpreted as the (start of) a 
  516. Xcommand. (Vi only accepts a command starting with ':').
  517. X
  518. XThe contents of the numbered and unnamed registers is remembered when
  519. Xchanging files.
  520. X
  521. XThe AUX: device of the Amiga is supported.
  522. X
  523. Xvi:tw=77:
  524. END_OF_FILE
  525.   if test 20566 -ne `wc -c <'vim/doc/difference.doc'`; then
  526.     echo shar: \"'vim/doc/difference.doc'\" unpacked with wrong size!
  527.   fi
  528.   # end of 'vim/doc/difference.doc'
  529. fi
  530. if test -f 'vim/src/cmdline.c.B' -a "${1}" != "-c" ; then 
  531.   echo shar: Will not clobber existing file \"'vim/src/cmdline.c.B'\"
  532. else
  533.   echo shar: Extracting \"'vim/src/cmdline.c.B'\" \(44081 characters\)
  534.   sed "s/^X//" >'vim/src/cmdline.c.B' <<'END_OF_FILE'
  535. X                break;
  536. X
  537. X        case CMD_set:
  538. X                (void)doset(arg);
  539. X                break;
  540. X
  541. X        case CMD_abbreviate:
  542. X        case CMD_cabbrev:
  543. X        case CMD_iabbrev:
  544. X        case CMD_cnoreabbrev:
  545. X        case CMD_inoreabbrev:
  546. X        case CMD_noreabbrev:
  547. X        case CMD_unabbreviate:
  548. X        case CMD_cunabbrev:
  549. X        case CMD_iunabbrev:
  550. X                i = ABBREV;
  551. X                goto doabbr;        /* almost the same as mapping */
  552. X
  553. X        case CMD_cmap:
  554. X        case CMD_imap:
  555. X        case CMD_map:
  556. X        case CMD_cnoremap:
  557. X        case CMD_inoremap:
  558. X        case CMD_noremap:
  559. X                /*
  560. X                 * If we are sourcing .exrc or .vimrc in current directory we
  561. X                 * print the mappings for security reasons.
  562. X                 */
  563. X                if (secure)
  564. X                {
  565. X                    secure = 2;
  566. X                    msg_outtrans(cmd, -1);
  567. X                    msg_outchar('\n');
  568. X                }
  569. X        case CMD_cunmap:
  570. X        case CMD_iunmap:
  571. X        case CMD_unmap:
  572. X                i = 0;
  573. Xdoabbr:
  574. X                if (*cmd == 'c')        /* cmap, cunmap, cnoremap, etc. */
  575. X                {
  576. X                    i += CMDLINE;
  577. X                    ++cmd;
  578. X                }
  579. X                else if (*cmd == 'i')    /* imap, iunmap, inoremap, etc. */
  580. X                {
  581. X                    i += INSERT;
  582. X                    ++cmd;
  583. X                }
  584. X                else if (forceit || i)    /* map!, unmap!, noremap!, abbrev */
  585. X                    i += INSERT + CMDLINE;
  586. X                else
  587. X                    i += NORMAL;            /* map, unmap, noremap */
  588. X                switch (domap((*cmd == 'n') ? 2 : (*cmd == 'u'), arg, i))
  589. X                {
  590. X                    case 1: emsg(e_invarg);
  591. X                            break;
  592. X                    case 2: emsg(e_nomap);
  593. X                            break;
  594. X                    case 3: emsg(e_ambmap);
  595. X                            break;
  596. X                }
  597. X                break;
  598. X
  599. X        case CMD_display:
  600. X                dodis();        /* display buffer contents */
  601. X                break;
  602. X
  603. X        case CMD_help:
  604. X                help();
  605. X                break;
  606. X
  607. X        case CMD_version:
  608. X                msg(longVersion);
  609. X                break;
  610. X
  611. X        case CMD_winsize:                    /* obsolete command */
  612. X                line1 = getdigits(&arg);
  613. X                skipspace(&arg);
  614. X                line2 = getdigits(&arg);
  615. X                set_winsize((int)line1, (int)line2, TRUE);
  616. X                break;
  617. X
  618. X        case CMD_delete:
  619. X        case CMD_yank:
  620. X        case CMD_rshift:
  621. X        case CMD_lshift:
  622. X                yankbuffer = regname;
  623. X                curbuf->b_startop.lnum = line1;
  624. X                curbuf->b_endop.lnum = line2;
  625. X                nlines = line2 - line1 + 1;
  626. X                mtype = MLINE;
  627. X                curwin->w_cursor.lnum = line1;
  628. X                switch (cmdidx)
  629. X                {
  630. X                case CMD_delete:
  631. X                    dodelete();
  632. X                    break;
  633. X                case CMD_yank:
  634. X                    (void)doyank(FALSE);
  635. X                    curwin->w_cursor.lnum = line2;        /* put cursor on last line */
  636. X                    break;
  637. X                case CMD_rshift:
  638. X                    doshift(RSHIFT, FALSE, amount);
  639. X                    break;
  640. X                case CMD_lshift:
  641. X                    doshift(LSHIFT, FALSE, amount);
  642. X                    break;
  643. X                }
  644. X                break;
  645. X
  646. X        case CMD_put:
  647. X                yankbuffer = regname;
  648. X                curwin->w_cursor.lnum = line2;
  649. X                doput(forceit ? BACKWARD : FORWARD, -1L, FALSE);
  650. X                break;
  651. X
  652. X        case CMD_t:
  653. X        case CMD_copy:
  654. X        case CMD_move:
  655. X                n = get_address(&arg);
  656. X                /*
  657. X                 * move or copy lines from 'line1'-'line2' to below line 'n'
  658. X                 */
  659. X                if (n == MAXLNUM || n < 0 || n > curbuf->b_ml.ml_line_count)
  660. X                {
  661. X                    emsg(e_invaddr);
  662. X                    break;
  663. X                }
  664. X
  665. X                if (cmdidx == CMD_move)
  666. X                {
  667. X                    if (do_move(line1, line2, n) == FAIL)
  668. X                        break;
  669. X                }
  670. X                else
  671. X                    do_copy(line1, line2, n);
  672. X                u_clearline();
  673. X                curwin->w_cursor.col = 0;
  674. X                updateScreen(NOT_VALID);
  675. X                break;
  676. X
  677. X        case CMD_and:            /* :& */
  678. X        case CMD_tilde:            /* :~ */
  679. X        case CMD_substitute:    /* :s */
  680. X                dosub(line1, line2, arg, &nextcomm,
  681. X                            cmdidx == CMD_substitute ? 0 :
  682. X                            cmdidx == CMD_and ? 1 : 2);
  683. X                break;
  684. X
  685. X        case CMD_join:
  686. X                curwin->w_cursor.lnum = line1;
  687. X                if (line1 == line2)
  688. X                {
  689. X                    if (addr_count >= 2)    /* :2,2join does nothing */
  690. X                        break;
  691. X                    if (line2 == curbuf->b_ml.ml_line_count)
  692. X                    {
  693. X                        beep();
  694. X                        break;
  695. X                    }
  696. X                    ++line2;
  697. X                }
  698. X                dodojoin(line2 - line1 + 1, !forceit, TRUE);
  699. X                break;
  700. X
  701. X        case CMD_global:
  702. X                if (forceit)
  703. X                    *cmd = 'v';
  704. X        case CMD_vglobal:
  705. X                doglob(*cmd, line1, line2, arg);
  706. X                break;
  707. X
  708. X        case CMD_at:                /* :[addr]@r */
  709. X                curwin->w_cursor.lnum = line2;
  710. X                if (doexecbuf(*arg) == FAIL)            /* put the register in mapbuf */
  711. X                    beep();
  712. X                else
  713. X                    (void)docmdline((char_u *)NULL);    /* execute from the mapbuf */
  714. X                break;
  715. X
  716. X        case CMD_bang:
  717. X                dobang(addr_count, line1, line2, forceit, arg);
  718. X                break;
  719. X
  720. X        case CMD_undo:
  721. X                u_undo(1);
  722. X                break;
  723. X
  724. X        case CMD_redo:
  725. X                u_redo(1);
  726. X                break;
  727. X
  728. X        case CMD_source:
  729. X                if (forceit)    /* :so! read vi commands */
  730. X                    (void)openscript(arg);
  731. X                else
  732. X                {
  733. X                    ++no_wait_return;
  734. X                    if (dosource(arg) == FAIL)        /* :so read ex commands */
  735. X                        emsg2(e_notopen, arg);
  736. X                    --no_wait_return;
  737. X                    if (need_wait_return)
  738. X                        wait_return(FALSE);
  739. X                }
  740. X                break;
  741. X
  742. X        case CMD_mkvimrc:
  743. X                if (*arg == NUL)
  744. X                    arg = (char_u *)VIMRC_FILE;
  745. X                /*FALLTHROUGH*/
  746. X
  747. X        case CMD_mkexrc:
  748. X                {
  749. X                    FILE    *fd;
  750. X
  751. X                    if (*arg == NUL)
  752. X                        arg = (char_u *)EXRC_FILE;
  753. X#ifdef UNIX
  754. X                        /* with Unix it is possible to open a directory */
  755. X                    if (isdir(arg) == TRUE)
  756. X                    {
  757. X                        EMSG2("\"%s\" is a directory", arg);
  758. X                        break;
  759. X                    }
  760. X#endif
  761. X                    if (!forceit && (fd = fopen((char *)arg, "r")) != NULL)
  762. X                    {
  763. X                        fclose(fd);
  764. X                        EMSG2("\"%s\" exists (use ! to override)", arg);
  765. X                        break;
  766. X                    }
  767. X
  768. X                    if ((fd = fopen((char *)arg, "w")) == NULL)
  769. X                    {
  770. X                        EMSG2("Cannot open \"%s\" for writing", arg);
  771. X                        break;
  772. X                    }
  773. X                    if (makemap(fd) == FAIL || makeset(fd) == FAIL || fclose(fd))
  774. X                        emsg(e_write);
  775. X                    break;
  776. X                }
  777. X
  778. X        case CMD_cc:
  779. X                    qf_jump(0, atoi((char *)arg));
  780. X                    break;
  781. X
  782. X        case CMD_cf:
  783. X                    if (*arg != NUL)
  784. X                    {
  785. X                        /*
  786. X                         * Great trick: Insert 'ef=' before arg.
  787. X                         * Always ok, because "cf " must be there.
  788. X                         */
  789. X                        arg -= 3;
  790. X                        arg[0] = 'e';
  791. X                        arg[1] = 'f';
  792. X                        arg[2] = '=';
  793. X                        (void)doset(arg);
  794. X                    }
  795. X                    (void)qf_init();
  796. X                    break;
  797. X
  798. X        case CMD_cl:
  799. X                    qf_list();
  800. X                    break;
  801. X
  802. X        case CMD_cn:
  803. X                    qf_jump(FORWARD, *arg == NUL ? 1 : atoi((char *)arg));
  804. X                    break;
  805. X
  806. X        case CMD_cp:
  807. X                    qf_jump(BACKWARD, *arg == NUL ? 1 : atoi((char *)arg));
  808. X                    break;
  809. X
  810. X        case CMD_cq:
  811. X                    getout(1);        /* this does not always work. why? */
  812. X
  813. X        case CMD_mark:
  814. X        case CMD_k:
  815. X                    pos = curwin->w_cursor;            /* save curwin->w_cursor */
  816. X                    curwin->w_cursor.lnum = line2;
  817. X                    curwin->w_cursor.col = 0;
  818. X                    (void)setmark(*arg);            /* set mark */
  819. X                    curwin->w_cursor = pos;            /* restore curwin->w_cursor */
  820. X                    break;
  821. X
  822. X#ifdef SETKEYMAP
  823. X        case CMD_setkeymap:
  824. X                    set_keymap(arg);
  825. X                    break;
  826. X#endif
  827. X
  828. X        case CMD_center:
  829. X        case CMD_right:
  830. X        case CMD_left:
  831. X                    do_align(line1, line2, atoi((char *)arg),
  832. X                            cmdidx == CMD_center ? 0 : cmdidx == CMD_right ? 1 : -1);
  833. X                    break;
  834. X
  835. X        case CMD_make:
  836. X                    domake(arg);
  837. X                    break;
  838. X
  839. X        default:
  840. X                    emsg(e_invcmd);
  841. X    }
  842. X
  843. X
  844. Xdoend:
  845. X    forceit = FALSE;        /* reset now so it can be used in getfile() */
  846. X    if (nextcomm && *nextcomm == NUL)        /* not really a next command */
  847. X        nextcomm = NULL;
  848. X    return nextcomm;
  849. X}
  850. X
  851. X/*
  852. X * if 'autowrite' option set, try to write the file
  853. X *
  854. X * return FAIL for failure, OK otherwise
  855. X */
  856. X    int
  857. Xautowrite(buf)
  858. X    BUF        *buf;
  859. X{
  860. X    if (!p_aw || (!forceit && buf->b_p_ro) || buf->b_filename == NULL)
  861. X        return FAIL;
  862. X    return buf_write_all(buf);
  863. X}
  864. X
  865. X/*
  866. X * flush all buffers, except the ones that are readonly
  867. X */
  868. X    void
  869. Xautowrite_all()
  870. X{
  871. X    BUF        *buf;
  872. X
  873. X    if (!p_aw)
  874. X        return;
  875. X    for (buf = firstbuf; buf; buf = buf->b_next)
  876. X        if (buf->b_changed && !buf->b_p_ro)
  877. X            (void)buf_write_all(buf);
  878. X}
  879. X
  880. X/*
  881. X * flush the contents of a buffer, unless it has no file name
  882. X *
  883. X * return FAIL for failure, OK otherwise
  884. X */
  885. X    static int
  886. Xbuf_write_all(buf)
  887. X    BUF        *buf;
  888. X{
  889. X    return (buf_write(buf, buf->b_filename, buf->b_sfilename, (linenr_t)1, buf->b_ml.ml_line_count, 0, 0, TRUE));
  890. X}
  891. X
  892. X/*
  893. X * write current buffer to file 'fname'
  894. X * if 'append' is TRUE, append to the file
  895. X *
  896. X * if *fname == NUL write to current file
  897. X * if b_notedited is TRUE, check for overwriting current file
  898. X *
  899. X * return FAIL for failure, OK otherwise
  900. X */
  901. X    static int
  902. Xdowrite(fname, append)
  903. X    char_u    *fname;
  904. X    int        append;
  905. X{
  906. X    FILE    *fd;
  907. X    int        other;
  908. X    char_u    *sfname = NULL;                /* init to shut up gcc */
  909. X
  910. X    if (*fname == NUL)
  911. X        other = FALSE;
  912. X    else
  913. X    {
  914. X        sfname = fname;
  915. X        fname = fix_fname(fname);
  916. X        other = otherfile(fname);
  917. X    }
  918. X
  919. X    /*
  920. X     * if we have a new file name put it in the list of alternate file names
  921. X     */
  922. X    if (other)
  923. X        setaltfname(fname, sfname, (linenr_t)1);
  924. X
  925. X    /*
  926. X     * writing to the current file is not allowed in readonly mode
  927. X     * and need a file name
  928. X     */
  929. X    if (!other && (check_readonly() || check_fname() == FAIL))
  930. X        return FAIL;
  931. X
  932. X    if (!other)
  933. X    {
  934. X        fname = curbuf->b_filename;
  935. X        sfname = curbuf->b_sfilename;
  936. X    }
  937. X
  938. X    /*
  939. X     * write to other file or b_notedited set: overwriting only allowed with '!'
  940. X     */
  941. X    if ((other || curbuf->b_notedited) && !forceit && !append && !p_wa && (fd = fopen((char *)fname, "r")) != NULL)
  942. X    {                                /* don't overwrite existing file */
  943. X        fclose(fd);
  944. X#ifdef UNIX
  945. X            /* with UNIX it is possible to open a directory */
  946. X        if (isdir(fname) == TRUE)
  947. X            EMSG2("\"%s\" is a directory", fname);
  948. X        else
  949. X#endif
  950. X            emsg(e_exists);
  951. X        return FAIL;
  952. X    }
  953. X    return (buf_write(curbuf, fname, sfname, line1, line2, append, forceit, TRUE));
  954. X}
  955. X
  956. X/*
  957. X * start editing a new file
  958. X *
  959. X *    fname: the file name
  960. X *                - full path if sfname used,
  961. X *                - any file name if sfname is NULL
  962. X *                - empty string to re-edit with the same file name (but may be
  963. X *                    in a different directory)
  964. X *                - NULL to start an empty buffer
  965. X *   sfname: the short file name (or NULL)
  966. X *  command: the command to be executed after loading the file
  967. X *     hide: if TRUE don't free the current buffer
  968. X *  newlnum: put cursor on this line number (if possible)
  969. X *
  970. X * return FAIL for failure, OK otherwise
  971. X */
  972. X    int
  973. Xdoecmd(fname, sfname, command, hide, newlnum)
  974. X    char_u        *fname;
  975. X    char_u        *sfname;
  976. X    char_u        *command;
  977. X    int            hide;
  978. X    linenr_t    newlnum;
  979. X{
  980. X    int            other_file;                /* TRUE if editing another file */
  981. X    int            oldbuf = FALSE;            /* TRUE if using existing buffer */
  982. X    BUF            *buf;
  983. X
  984. X        /* if no short name given, use fname for short name */
  985. X    if (sfname == NULL)
  986. X        sfname = fname;
  987. X
  988. X    if (fname == NULL)
  989. X        other_file = TRUE;
  990. X    else if (*fname == NUL && curbuf->b_filename == NULL)    /* there is no file name */
  991. X        other_file = FALSE;
  992. X    else
  993. X    {
  994. X        if (*fname == NUL)                /* re-edit with same file name */
  995. X        {
  996. X            fname = curbuf->b_filename;
  997. X            sfname = curbuf->b_sfilename;
  998. X        }
  999. X        fname = fix_fname(fname);        /* may expand to full path name */
  1000. X        other_file = otherfile(fname);
  1001. X    }
  1002. X/*
  1003. X * if the file was changed we may not be allowed to abandon it
  1004. X * - if we are going to re-edit the same file
  1005. X * - or if we are the only window on this file and if hide is FALSE
  1006. X */
  1007. X    if ((!other_file || (curbuf->b_nwindows == 1 && !hide)) &&
  1008. X                        check_changed(curbuf, FALSE, !other_file))
  1009. X    {
  1010. X        if (other_file && fname != NULL)
  1011. X            setaltfname(fname, sfname, (linenr_t)1);
  1012. X        return FAIL;
  1013. X    }
  1014. X/*
  1015. X * If we are starting to edit another file, open a (new) buffer.
  1016. X * Otherwise we re-use the current buffer.
  1017. X */
  1018. X    if (other_file)
  1019. X    {
  1020. X        curwin->w_alt_fnum = curbuf->b_fnum;
  1021. X        buflist_altlnum();
  1022. X
  1023. X        buf = buflist_new(fname, sfname, 1L, TRUE);
  1024. X        if (buf == NULL)
  1025. X            return FAIL;
  1026. X        if (buf->b_ml.ml_mfp == NULL)        /* no memfile yet */
  1027. X        {
  1028. X            oldbuf = FALSE;
  1029. X            buf->b_nwindows = 1;
  1030. X        }
  1031. X        else                                /* existing memfile */
  1032. X        {
  1033. X            oldbuf = TRUE;
  1034. X            ++buf->b_nwindows;
  1035. X        }
  1036. X        /*
  1037. X         * make the (new) buffer the one used by the current window
  1038. X         * if the old buffer becomes unused, free it if hide is FALSE
  1039. X         * If the current buffer was empty and has no file name, curbuf
  1040. X         * is returned by buflist_new().
  1041. X         */
  1042. X        if (buf != curbuf)
  1043. X        {
  1044. X            close_buffer(curbuf, !hide, FALSE);
  1045. X            curwin->w_buffer = buf;
  1046. X            curbuf = buf;
  1047. X        }
  1048. X
  1049. X        curwin->w_pcmark.lnum = 1;
  1050. X        curwin->w_pcmark.col = 0;
  1051. X    }
  1052. X    else if (check_fname() == FAIL)
  1053. X        return FAIL;
  1054. X
  1055. X/*
  1056. X * If we get here we are sure to start editing
  1057. X */
  1058. X        /* don't redraw until the cursor is in the right line */
  1059. X    ++RedrawingDisabled;
  1060. X
  1061. X/*
  1062. X * other_file    oldbuf
  1063. X *    FALSE        FALSE        re-edit same file, buffer is re-used
  1064. X *    FALSE        TRUE        not posible
  1065. X *  TRUE        FALSE        start editing new file, new buffer
  1066. X *  TRUE        TRUE        start editing in existing buffer (nothing to do)
  1067. X */
  1068. X    if (!other_file)                    /* re-use the buffer */
  1069. X    {
  1070. X        if (newlnum == 0)
  1071. X            newlnum = curwin->w_cursor.lnum;
  1072. X        buf_freeall(curbuf);            /* free all things for buffer */
  1073. X        buf_clear(curbuf);
  1074. X        curbuf->b_startop.lnum = 0;        /* clear '[ and '] marks */
  1075. X        curbuf->b_endop.lnum = 0;
  1076. X    }
  1077. X
  1078. X    if (!oldbuf)                        /* need to read the file */
  1079. X        (void)open_buffer();
  1080. X    win_init(curwin);
  1081. X    maketitle();
  1082. X
  1083. X    if (newlnum && command == NULL)
  1084. X    {
  1085. X        curwin->w_cursor.lnum = newlnum;
  1086. X        curwin->w_cursor.col = 0;
  1087. X    }
  1088. X    check_cursor();
  1089. X
  1090. X    /*
  1091. X     * Did not read the file, need to show some info about the file.
  1092. X     * Do this after setting the cursor.
  1093. X     */
  1094. X    if (oldbuf)
  1095. X        fileinfo(did_cd);
  1096. X
  1097. X    if (command != NULL)
  1098. X        docmdline(command);
  1099. X    --RedrawingDisabled;
  1100. X    if (!skip_redraw)
  1101. X        updateScreen(CURSUPD);            /* redraw now */
  1102. X
  1103. X    if (p_im)
  1104. X        stuffReadbuff((char_u *)"i");    /* start editing in insert mode */
  1105. X    return OK;
  1106. X}
  1107. X
  1108. X/*
  1109. X * get + command from ex argument
  1110. X */
  1111. X    static char_u *
  1112. Xgetargcmd(argp)
  1113. X    char_u **argp;
  1114. X{
  1115. X    char_u *arg = *argp;
  1116. X    char_u *command = NULL;
  1117. X
  1118. X    if (*arg == '+')        /* +[command] */
  1119. X    {
  1120. X        ++arg;
  1121. X        if (isspace(*arg))
  1122. X            command = (char_u *)"$";
  1123. X        else
  1124. X        {
  1125. X            command = arg;
  1126. X            /*
  1127. X             * should check for "\ " (but vi has a bug that prevents it to work)
  1128. X             */
  1129. X            skiptospace(&arg);
  1130. X        }
  1131. X        if (*arg)
  1132. X            *arg++ = NUL;    /* terminate command with NUL */
  1133. X        
  1134. X        skipspace(&arg);    /* skip over spaces */
  1135. X        *argp = arg;
  1136. X    }
  1137. X    return command;
  1138. X}
  1139. X
  1140. X/*
  1141. X * look for command separator '|' or '\n'
  1142. X */
  1143. X    static char_u *
  1144. Xchecknextcomm(arg)
  1145. X    char_u *arg;
  1146. X{
  1147. X    char_u *p;
  1148. X    char_u *nextcomm = NULL;
  1149. X
  1150. X    for (p = arg; *p; ++p)
  1151. X    {
  1152. X        if (*p == '\\' && p[1])
  1153. X            ++p;
  1154. X        else if (*p == '|' || *p == '\n')
  1155. X        {
  1156. X            nextcomm = p + 1;    /* remember start of next command */
  1157. X            *p = NUL;            /* delete '|' or '\n' */
  1158. X            del_spaces(arg);    /* delete spaces in front of '|' or '\n' */
  1159. X            break;
  1160. X        }
  1161. X    }
  1162. X    return nextcomm;
  1163. X}
  1164. X
  1165. X    static void
  1166. Xdomake(arg)
  1167. X    char_u *arg;
  1168. X{
  1169. X    if (*p_ef == NUL)
  1170. X    {
  1171. X        EMSG("errorfile option not set");
  1172. X        return;
  1173. X    }
  1174. X    if (curbuf->b_changed)
  1175. X        (void)autowrite(curbuf);
  1176. X    remove((char *)p_ef);
  1177. X    outchar(':');
  1178. X    outstr(arg);        /* show what we are doing */
  1179. X    sprintf((char *)IObuff, "%s %s %s", arg, p_sp, p_ef);
  1180. X    doshell(IObuff);
  1181. X#ifdef AMIGA
  1182. X    flushbuf();
  1183. X    vpeekc();        /* read window status report and redraw before message */
  1184. X#endif
  1185. X    (void)qf_init();
  1186. X    remove((char *)p_ef);
  1187. X}
  1188. X
  1189. X/* 
  1190. X * Redefine the argument list to 'str'.
  1191. X *
  1192. X * Return FAIL for failure, OK otherwise.
  1193. X */
  1194. X    static int
  1195. Xdoarglist(str)
  1196. X    char_u *str;
  1197. X{
  1198. X    int        new_count = 0;
  1199. X    char_u    **new_files = NULL;
  1200. X    int        exp_count;
  1201. X    char_u    **exp_files;
  1202. X    char_u    **t;
  1203. X    char_u    *p;
  1204. X    int        inquote;
  1205. X    int        i;
  1206. X
  1207. X    while (*str)
  1208. X    {
  1209. X        /*
  1210. X         * create a new entry in new_files[]
  1211. X         */
  1212. X        t = (char_u **)lalloc((long_u)(sizeof(char_u *) * (new_count + 1)), TRUE);
  1213. X        if (t != NULL)
  1214. X            for (i = new_count; --i >= 0; )
  1215. X                t[i] = new_files[i];
  1216. X        free(new_files);
  1217. X        if (t == NULL)
  1218. X            return FAIL;
  1219. X        new_files = t;
  1220. X        new_files[new_count++] = str;
  1221. X
  1222. X        /*
  1223. X         * isolate one argument, taking quotes
  1224. X         */
  1225. X        inquote = FALSE;
  1226. X        for (p = str; *str; ++str)
  1227. X        {
  1228. X            /*
  1229. X             * for MSDOS a backslash is part of a file name.
  1230. X             * Only skip ", space and tab.
  1231. X             */
  1232. X#ifdef MSDOS
  1233. X            if (*str == '\\' && (str[1] == '"' || str[1] == ' ' || str[1] == '\t'))
  1234. X#else
  1235. X            if (*str == '\\' && str[1] != NUL)
  1236. X#endif
  1237. X                *p++ = *++str;
  1238. X            else
  1239. X            {
  1240. X                if (!inquote && isspace(*str))
  1241. X                    break;
  1242. X                if (*str == '"')
  1243. X                    inquote ^= TRUE;
  1244. X                else
  1245. X                    *p++ = *str;
  1246. X            }
  1247. X        }
  1248. X        skipspace(&str);
  1249. X        *p = NUL;
  1250. X    }
  1251. X    
  1252. X    i = ExpandWildCards(new_count, new_files, &exp_count, &exp_files, FALSE, TRUE);
  1253. X    free(new_files);
  1254. X    if (i == FAIL)
  1255. X        return FAIL;
  1256. X    if (exp_count == 0)
  1257. X    {
  1258. X        emsg(e_nomatch);
  1259. X        return FAIL;
  1260. X    }
  1261. X    if (arg_exp)                /* arg_files[] has been allocated, free it */
  1262. X        FreeWild(arg_count, arg_files);
  1263. X    else
  1264. X        arg_exp = TRUE;
  1265. X    arg_files = exp_files;
  1266. X    arg_count = exp_count;
  1267. X
  1268. X    /*
  1269. X     * put all file names in the buffer list
  1270. X     */
  1271. X    for (i = 0; i < arg_count; ++i)
  1272. X        (void)buflist_add(arg_files[i]);
  1273. X
  1274. X    return OK;
  1275. X}
  1276. X
  1277. X    void
  1278. Xgotocmdline(clr, firstc)
  1279. X    int                clr;
  1280. X    int                firstc;
  1281. X{
  1282. X    msg_start();
  1283. X    if (clr)            /* clear the bottom line(s) */
  1284. X        msg_ceol();        /* will reset clear_cmdline */
  1285. X    windgoto(cmdline_row, 0);
  1286. X    if (firstc)
  1287. X        msg_outchar(firstc);
  1288. X}
  1289. X
  1290. X    void
  1291. Xgotocmdend()
  1292. X{
  1293. X    windgoto((int)Rows - 1, 0);
  1294. X    outchar('\n');
  1295. X}
  1296. X
  1297. X    static int
  1298. Xcheck_readonly()
  1299. X{
  1300. X    if (!forceit && curbuf->b_p_ro)
  1301. X    {
  1302. X        emsg(e_readonly);
  1303. X        return TRUE;
  1304. X    }
  1305. X    return FALSE;
  1306. X}
  1307. X
  1308. X/*
  1309. X * return TRUE if buffer was changed and cannot be abandoned.
  1310. X */
  1311. X    static int
  1312. Xcheck_changed(buf, checkaw, mult_win)
  1313. X    BUF        *buf;
  1314. X    int        checkaw;        /* do autowrite if buffer was changed */
  1315. X    int        mult_win;        /* check also when several windows for this buffer */
  1316. X{
  1317. X    if (    !forceit &&
  1318. X            buf->b_changed && (mult_win || buf->b_nwindows <= 1) &&
  1319. X            (!checkaw || autowrite(buf) == FAIL))
  1320. X    {
  1321. X        emsg(e_nowrtmsg);
  1322. X        return TRUE;
  1323. X    }
  1324. X    return FALSE;
  1325. X}
  1326. X
  1327. X/*
  1328. X * return TRUE if any buffer was changed and cannot be abandoned.
  1329. X */
  1330. X    static int
  1331. Xcheck_changed_any(checkaw)
  1332. X    int        checkaw;        /* do autowrite if buffer was changed */
  1333. X{
  1334. X    BUF        *buf;
  1335. X
  1336. X    if (!forceit)
  1337. X    {
  1338. X        for (buf = firstbuf; buf != NULL; buf = buf->b_next)
  1339. X        {
  1340. X            if (buf->b_changed && (!checkaw || autowrite(buf) == FAIL))
  1341. X            {
  1342. X                EMSG2("No write since last change for buffer \"%s\"",
  1343. X                        buf->b_xfilename == NULL ? (char_u *)"No File" : buf->b_xfilename);
  1344. X                return TRUE;
  1345. X            }
  1346. X        }
  1347. X    }
  1348. X    return FALSE;
  1349. X}
  1350. X
  1351. X/*
  1352. X * return FAIL if there is no filename, OK if there is one
  1353. X * give error message for FAIL
  1354. X */
  1355. X    int
  1356. Xcheck_fname()
  1357. X{
  1358. X    if (curbuf->b_filename == NULL)
  1359. X    {
  1360. X        emsg(e_noname);
  1361. X        return FAIL;
  1362. X    }
  1363. X    return OK;
  1364. X}
  1365. X
  1366. X/*
  1367. X * - if there are more files to edit
  1368. X * - and this is the last window
  1369. X * - and forceit not used
  1370. X * - and not repeated twice on a row
  1371. X *      return FAIL and give error message if 'message' TRUE
  1372. X * return OK otherwise
  1373. X */
  1374. X    static int
  1375. Xcheck_more(message)
  1376. X    int message;            /* when FALSE check only, no messages */
  1377. X{
  1378. X    if (!forceit && firstwin == lastwin && curwin->w_arg_idx + 1 < arg_count &&
  1379. X                                    quitmore == 0)
  1380. X    {
  1381. X        if (message)
  1382. X        {
  1383. X            emsg2((char_u *)"%ld more files to edit", (char_u *)(long)(arg_count - curwin->w_arg_idx - 1));
  1384. X            quitmore = 2;            /* next try to quit is allowed */
  1385. X        }
  1386. X        return FAIL;
  1387. X    }
  1388. X    return OK;
  1389. X}
  1390. X
  1391. X/*
  1392. X * try to abandon current file and edit "fname"
  1393. X * return 1 for "normal" error, 2 for "not written" error, 0 for success
  1394. X * -1 for succesfully opening another file
  1395. X * 'lnum' is the line number for the cursor in the new file (if non-zero).
  1396. X */
  1397. X    int
  1398. Xgetfile(fname, sfname, setpm, lnum)
  1399. X    char_u        *fname;
  1400. X    char_u        *sfname;
  1401. X    int            setpm;
  1402. X    linenr_t    lnum;
  1403. X{
  1404. X    int other;
  1405. X
  1406. X    fname_expand(&fname, &sfname);    /* make fname full path and set sfname */
  1407. X    other = otherfile(fname);
  1408. X
  1409. X    if (other && !forceit && curbuf->b_nwindows == 1 &&
  1410. X            !p_hid && curbuf->b_changed && autowrite(curbuf) == FAIL)
  1411. X    {
  1412. X        emsg(e_nowrtmsg);
  1413. X        return 2;        /* file has been changed */
  1414. X    }
  1415. X    if (setpm)
  1416. X        setpcmark();
  1417. X    if (!other)
  1418. X    {
  1419. X        if (lnum != 0)
  1420. X            curwin->w_cursor.lnum = lnum;
  1421. X        check_cursor();
  1422. X        curwin->w_cursor.col = 0;
  1423. X
  1424. X        return 0;        /* it's in the same file */
  1425. X    }
  1426. X    if (doecmd(fname, sfname, NULL, p_hid, lnum) == OK)
  1427. X        return -1;        /* opened another file */
  1428. X    return 1;            /* error encountered */
  1429. X}
  1430. X
  1431. X#ifdef WEBB_COMPLETE
  1432. X/*
  1433. X * vim_strncpy()
  1434. X *
  1435. X * This is here because strncpy() does not guarantee successful results when
  1436. X * the to and from strings overlap.  It is only currently called from nextwild()
  1437. X * which copies part of the command line to another part of the command line.
  1438. X * This produced garbage when expanding files etc in the middle of the command
  1439. X * line (on my terminal, anyway) -- webb.
  1440. X */
  1441. X    static void
  1442. Xvim_strncpy(to, from, len)
  1443. X    char_u *to;
  1444. X    char_u *from;
  1445. X    int len;
  1446. X{
  1447. X    int i;
  1448. X
  1449. X    if (to <= from)
  1450. X    {
  1451. X        while (len-- && *from)
  1452. X            *to++ = *from++;
  1453. X        if (len >= 0)
  1454. X            *to = *from;    /* Copy NUL */
  1455. X    }
  1456. X    else
  1457. X    {
  1458. X        for (i = 0; i < len; i++)
  1459. X        {
  1460. X            to++;
  1461. X            if (*from++ == NUL)
  1462. X            {
  1463. X                i++;
  1464. X                break;
  1465. X            }
  1466. X        }
  1467. X        for (; i > 0; i--)
  1468. X            *--to = *--from;
  1469. X    }
  1470. X}
  1471. X
  1472. X/* Return FALSE if this is not an appropriate context in which to do
  1473. X * completion of anything, & TRUE if it is (even if there are no matches).  For
  1474. X * the caller, this means that the character is just passed through like a
  1475. X * normal character (instead of being expanded).  This allows :s/^I^D etc.
  1476. X */
  1477. X    static int
  1478. X#else
  1479. X    static void
  1480. X#endif /* WEBB_COMPLETE */
  1481. Xnextwild(buff, type)
  1482. X    char_u *buff;
  1483. X    int        type;
  1484. X{
  1485. X    int        i;
  1486. X    char_u    *p1;
  1487. X    char_u    *p2 = NULL;
  1488. X    int        oldlen;
  1489. X    int        difflen;
  1490. X
  1491. X#ifdef WEBB_COMPLETE
  1492. X    if (cmd_numfiles == -1)
  1493. X        set_expand_context(cmdfirstc, cmdbuff);
  1494. X    if (expand_context == EXPAND_UNSUCCESSFUL)
  1495. X    {
  1496. X        beep();
  1497. X        return OK;    /* Something illegal on command line */
  1498. X    }
  1499. X    if (expand_context == EXPAND_NOTHING)
  1500. X    {
  1501. X        /* Caller can use the character as a normal char instead */
  1502. X        return FAIL;
  1503. X    }
  1504. X    expand_interactively = TRUE;
  1505. X
  1506. X#endif /* WEBB_COMPLETE */
  1507. X    msg_outstr((char_u *)"...");        /* show that we are busy */
  1508. X    flushbuf();
  1509. X
  1510. X#ifdef WEBB_COMPLETE
  1511. X    i = expand_pattern - buff;
  1512. X#else
  1513. X    for (i = cmdpos; i > 0 && buff[i - 1] != ' '; --i)
  1514. X        ;
  1515. X#endif /* WEBB_COMPLETE */
  1516. X    oldlen = cmdpos - i;
  1517. X
  1518. X        /* add a "*" to the file name and expand it */
  1519. X    if ((p1 = addstar(&buff[i], oldlen)) != NULL)
  1520. X    {
  1521. X        if ((p2 = ExpandOne(p1, FALSE, type)) != NULL)
  1522. X        {
  1523. X            if (cmdlen + (difflen = STRLEN(p2) - oldlen) > CMDBUFFSIZE - 4)
  1524. X                emsg(e_toolong);
  1525. X            else
  1526. X            {
  1527. X#ifdef WEBB_COMPLETE
  1528. X                vim_strncpy(&buff[cmdpos + difflen], &buff[cmdpos], cmdlen - cmdpos);
  1529. X#else
  1530. X                STRNCPY(&buff[cmdpos + difflen], &buff[cmdpos], (size_t)(cmdlen - cmdpos));
  1531. X#endif /* WEBB_COMPLETE */
  1532. X                STRNCPY(&buff[i], p2, STRLEN(p2));
  1533. X                cmdlen += difflen;
  1534. X                cmdpos += difflen;
  1535. X            }
  1536. X            free(p2);
  1537. X        }
  1538. X        free(p1);
  1539. X    }
  1540. X    redrawcmd();
  1541. X#ifdef WEBB_COMPLETE
  1542. X    if (cmd_numfiles <= 0 && p2 == NULL)
  1543. X        beep();
  1544. X    else if (cmd_numfiles == 1)
  1545. X    {
  1546. X        (void)ExpandOne(NULL, FALSE, -2);    /* free expanded "file" names */
  1547. X        cmd_numfiles = -1;
  1548. X    }
  1549. X    expand_interactively = FALSE;
  1550. X    return OK;
  1551. X#endif /* WEBB_COMPLETE */
  1552. X}
  1553. X
  1554. X/*
  1555. X * Do wildcard expansion on the string 'str'.
  1556. X * Return a pointer to alloced memory containing the new string.
  1557. X * Return NULL for failure.
  1558. X *
  1559. X * mode = -2: only release file names
  1560. X * mode = -1: normal expansion, do not keep file names
  1561. X * mode =  0: normal expansion, keep file names
  1562. X * mode =  1: use next match in multiple match
  1563. X * mode =  2: use previous match in multiple match
  1564. X * mode =  3: use next match in multiple match and wrap to first
  1565. X * mode =  4: return all matches concatenated
  1566. X * mode =  5: return longest matched part
  1567. X */
  1568. X    char_u *
  1569. XExpandOne(str, list_notfound, mode)
  1570. X    char_u    *str;
  1571. X    int        list_notfound;
  1572. X    int        mode;
  1573. X{
  1574. X    char_u        *ss = NULL;
  1575. X    static char_u **cmd_files = NULL;      /* list of input files */
  1576. X    static int    findex;
  1577. X    int            i, found = 0;
  1578. X    int            multmatch = FALSE;
  1579. X    long_u        len;
  1580. X    char_u        *filesuf, *setsuf, *nextsetsuf;
  1581. X    int            filesuflen, setsuflen;
  1582. X
  1583. X/*
  1584. X * first handle the case of using an old match
  1585. X */
  1586. X    if (mode >= 1 && mode < 4)
  1587. X    {
  1588. X        if (cmd_numfiles > 0)
  1589. X        {
  1590. X            if (mode == 2)
  1591. X                --findex;
  1592. X            else    /* mode == 1 || mode == 3 */
  1593. X                ++findex;
  1594. X            if (findex < 0)
  1595. X                findex = 0;
  1596. X            if (findex > cmd_numfiles - 1)
  1597. X            {
  1598. X                if (mode == 3)
  1599. X                    findex = 0;
  1600. X                else
  1601. X                    findex = cmd_numfiles - 1;
  1602. X            }
  1603. X            return strsave(cmd_files[findex]);
  1604. X        }
  1605. X        else
  1606. X            return NULL;
  1607. X    }
  1608. X
  1609. X/* free old names */
  1610. X    if (cmd_numfiles != -1 && mode < 4)
  1611. X    {
  1612. X        FreeWild(cmd_numfiles, cmd_files);
  1613. X        cmd_numfiles = -1;
  1614. X    }
  1615. X    findex = 0;
  1616. X
  1617. X    if (mode == -2)        /* only release file name */
  1618. X        return NULL;
  1619. X
  1620. X    if (cmd_numfiles == -1)
  1621. X    {
  1622. X#ifdef WEBB_COMPLETE
  1623. X        if (ExpandFromContext((char_u *)str, &cmd_numfiles, &cmd_files, FALSE,
  1624. X                                                        list_notfound) == FAIL)
  1625. X            /* error: do nothing */;
  1626. X        else if (cmd_numfiles == 0)
  1627. X        {
  1628. X            if (!expand_interactively)
  1629. X                emsg(e_nomatch);
  1630. X        }
  1631. X#else
  1632. X        if (ExpandWildCards(1, (char_u **)&str, &cmd_numfiles, &cmd_files, FALSE, list_notfound) == FAIL)
  1633. X            /* error: do nothing */;
  1634. X        else if (cmd_numfiles == 0)
  1635. X            emsg(e_nomatch);
  1636. X#endif /* WEBB_COMPLETE */
  1637. X        else if (mode < 4)
  1638. X        {
  1639. X            if (cmd_numfiles > 1)        /* more than one match; check suffixes */
  1640. X            {
  1641. X                found = -2;
  1642. X                for (i = 0; i < cmd_numfiles; ++i)
  1643. X                {
  1644. X                    if ((filesuf = STRRCHR(cmd_files[i], '.')) != NULL)
  1645. X                    {
  1646. X                        filesuflen = STRLEN(filesuf);
  1647. X                        for (setsuf = p_su; *setsuf; setsuf = nextsetsuf)
  1648. X                        {
  1649. X                            if ((nextsetsuf = STRCHR(setsuf + 1, '.')) == NULL)
  1650. X                                nextsetsuf = setsuf + STRLEN(setsuf);
  1651. X                            setsuflen = (int)(nextsetsuf - setsuf);
  1652. X                            if (filesuflen == setsuflen &&
  1653. X                                        STRNCMP(setsuf, filesuf, (size_t)setsuflen) == 0)
  1654. X                                break;
  1655. X                        }
  1656. X                        if (*setsuf)                /* suffix matched: ignore file */
  1657. X                            continue;
  1658. X                    }
  1659. X                    if (found >= 0)
  1660. X                    {
  1661. X                        multmatch = TRUE;
  1662. X                        break;
  1663. X                    }
  1664. X                    found = i;
  1665. X                }
  1666. X            }
  1667. X            if (multmatch || found < 0)
  1668. X            {
  1669. X#ifdef WEBB_COMPLETE
  1670. X                /* Can we ever get here unless it's while expanding
  1671. X                 * interactively?  If not, we can get rid of this all together.
  1672. X                 * Don't really want to wait for this message (and possibly
  1673. X                 * have to hit return to continue!).
  1674. X                 */
  1675. X                if (!expand_interactively)
  1676. X#endif /* WEBB_COMPLETE */
  1677. X                    emsg(e_toomany);
  1678. X#ifdef WEBB_COMPLETE
  1679. X                else
  1680. X                    beep();
  1681. X#endif /* WEBB_COMPLETE */
  1682. X                found = 0;                /* return first one */
  1683. X                multmatch = TRUE;        /* for found < 0 */
  1684. X            }
  1685. X            if (found >= 0 && !(multmatch && mode == -1))
  1686. X                ss = strsave(cmd_files[found]);
  1687. X        }
  1688. X    }
  1689. X
  1690. X    if (mode == 5 && cmd_numfiles > 0)        /* find longest common part */
  1691. X    {
  1692. X        for (len = 0; cmd_files[0][len]; ++len)
  1693. X        {
  1694. X            for (i = 0; i < cmd_numfiles; ++i)
  1695. X            {
  1696. X#ifdef AMIGA
  1697. X                if (toupper(cmd_files[i][len]) != toupper(cmd_files[0][len]))
  1698. X#else
  1699. X                if (cmd_files[i][len] != cmd_files[0][len])
  1700. X#endif
  1701. X                    break;
  1702. X            }
  1703. X            if (i < cmd_numfiles)
  1704. X                break;
  1705. X        }
  1706. X        ss = alloc((unsigned)len + 1);
  1707. X        if (ss)
  1708. X        {
  1709. X            STRNCPY(ss, cmd_files[0], (size_t)len);
  1710. X            ss[len] = NUL;
  1711. X        }
  1712. X        multmatch = TRUE;                    /* don't free the names */
  1713. X        findex = -1;                        /* next p_wc gets first one */
  1714. X    }
  1715. X
  1716. X    if (mode == 4 && cmd_numfiles > 0)        /* concatenate all file names */
  1717. X    {
  1718. X        len = 0;
  1719. X        for (i = 0; i < cmd_numfiles; ++i)
  1720. X            len += STRLEN(cmd_files[i]) + 1;
  1721. X        ss = lalloc(len, TRUE);
  1722. X        if (ss)
  1723. X        {
  1724. X            *ss = NUL;
  1725. X            for (i = 0; i < cmd_numfiles; ++i)
  1726. X            {
  1727. X                STRCAT(ss, cmd_files[i]);
  1728. X                if (i != cmd_numfiles - 1)
  1729. X                    STRCAT(ss, " ");
  1730. X            }
  1731. X        }
  1732. X    }
  1733. X
  1734. X#ifdef WEBB_COMPLETE
  1735. X    if (mode == -1 || mode == 4)
  1736. X#else
  1737. X    if (!multmatch || mode == -1 || mode == 4)
  1738. X#endif /* WEBB_COMPLETE */
  1739. X    {
  1740. X        FreeWild(cmd_numfiles, cmd_files);
  1741. X        cmd_numfiles = -1;
  1742. X    }
  1743. X    return ss;
  1744. X}
  1745. X
  1746. X/*
  1747. X * show all filenames that match the string "file" with length "len"
  1748. X */
  1749. X#ifdef WEBB_COMPLETE
  1750. X    static int
  1751. Xshowmatches(buff)
  1752. X    char_u *buff;
  1753. X#else
  1754. X    static void
  1755. Xshowmatches(file, len)
  1756. X    char_u *file;
  1757. X    int    len;
  1758. X#endif /* WEBB_COMPLETE */
  1759. X{
  1760. X    char_u *file_str;
  1761. X    int num_files;
  1762. X    char_u **files_found;
  1763. X    int i, j, k;
  1764. X    int maxlen;
  1765. X    int lines;
  1766. X    int columns;
  1767. X
  1768. X#ifdef WEBB_COMPLETE
  1769. X    set_expand_context(cmdfirstc, cmdbuff);
  1770. X    if (expand_context == EXPAND_UNSUCCESSFUL)
  1771. X    {
  1772. X        beep();
  1773. X        return OK;    /* Something illegal on command line */
  1774. X    }
  1775. X    if (expand_context == EXPAND_NOTHING)
  1776. X    {
  1777. X        /* Caller can use the character as a normal char instead */
  1778. X        return FAIL;
  1779. X    }
  1780. X    expand_interactively = TRUE;
  1781. X
  1782. X    /* add star to file name, or convert to regexp if not expanding files! */
  1783. X    file_str = addstar(expand_pattern, (int)(buff + cmdpos - expand_pattern));
  1784. X    if (file_str == NULL)
  1785. X    {
  1786. X        expand_interactively = FALSE;
  1787. X        return OK;
  1788. X    }
  1789. X#else
  1790. X    file_str = addstar(file, len);        /* add star to file name */
  1791. X    if (file_str == NULL)
  1792. X        return;
  1793. X#endif /* WEBB_COMPLETE */
  1794. X
  1795. X    msg_outchar('\n');
  1796. X    flushbuf();
  1797. X
  1798. X    /* find all files that match the description */
  1799. X#ifdef WEBB_COMPLETE
  1800. X    if (ExpandFromContext(file_str, &num_files, &files_found, FALSE, FALSE) == FAIL)
  1801. X    {
  1802. X        num_files = 0;
  1803. X        files_found = (char_u **)"";
  1804. X    }
  1805. X#else
  1806. X    if (ExpandWildCards(1, &file_str, &num_files, &files_found, FALSE, FALSE) == FAIL)
  1807. X        return;
  1808. X#endif /* WEBB_COMPLETE */
  1809. X
  1810. X    /* find the maximum length of the file names */
  1811. X    maxlen = 0;
  1812. X    for (i = 0; i < num_files; ++i)
  1813. X    {
  1814. X        j = STRLEN(files_found[i]);
  1815. X        if (j > maxlen)
  1816. X            maxlen = j;
  1817. X    }
  1818. X
  1819. X    /* compute the number of columns and lines for the listing */
  1820. X    maxlen += 2;    /* two spaces between file names */
  1821. X    columns = ((int)Columns + 2) / maxlen;
  1822. X    if (columns < 1)
  1823. X        columns = 1;
  1824. X    lines = (num_files + columns - 1) / columns;
  1825. X
  1826. X    (void)set_highlight('d');    /* find out highlight mode for directories */
  1827. X
  1828. X    /* list the files line by line */
  1829. X    for (i = 0; i < lines; ++i)
  1830. X    {
  1831. X        for (k = i; k < num_files; k += lines)
  1832. X        {
  1833. X            if (k > i)
  1834. X                for (j = maxlen - STRLEN(files_found[k - lines]); --j >= 0; )
  1835. X                    msg_outchar(' ');
  1836. X#ifdef WEBB_COMPLETE
  1837. X            if (expand_context == EXPAND_FILES)
  1838. X                j = isdir(files_found[k]);    /* highlight directories */
  1839. X            else
  1840. X                j = FALSE;
  1841. X#else
  1842. X            j = isdir(files_found[k]);    /* highlight directories */
  1843. X#endif /* WEBB_COMPLETE */
  1844. X            if (j)
  1845. X            {
  1846. X                start_highlight();
  1847. X                screen_start();        /* don't output spaces to position cursor */
  1848. X            }
  1849. X            msg_outstr(files_found[k]);
  1850. X            if (j)
  1851. X                stop_highlight();
  1852. X        }
  1853. X        msg_outchar('\n');
  1854. X        flushbuf();                    /* show one line at a time */
  1855. X    }
  1856. X    free(file_str);
  1857. X    FreeWild(num_files, files_found);
  1858. X
  1859. X/*
  1860. X * we redraw the command below the lines that we have just listed
  1861. X * This is a bit tricky, but it saves a lot of screen updating.
  1862. X */
  1863. X    cmdline_row = msg_row;        /* will put it back later */
  1864. X#ifdef WEBB_COMPLETE
  1865. X
  1866. X    expand_interactively = FALSE;
  1867. X    return OK;
  1868. X#endif /* WEBB_COMPLETE */
  1869. X}
  1870. X
  1871. X/*
  1872. X * copy the file name into allocated memory and add a '*' at the end
  1873. X */
  1874. X    static char_u *
  1875. Xaddstar(fname, len)
  1876. X    char_u    *fname;
  1877. X    int        len;
  1878. X{
  1879. X    char_u    *retval;
  1880. X#ifdef WEBB_COMPLETE
  1881. X    int        i, j;
  1882. X    int        new_len;
  1883. X    char_u    save_char;
  1884. X
  1885. X    if (expand_interactively && expand_context != EXPAND_FILES &&
  1886. X        expand_context != EXPAND_DIRECTORIES)
  1887. X    {
  1888. X        /* Matching will be done internally (on something other than files).
  1889. X         * So we convert the file-matching-type wildcards into our kind for
  1890. X         * use with regcomp().  First work out how long it will be:
  1891. X         */
  1892. X        new_len = len + 2;                /* +2 for '^' at start, NUL at end */
  1893. X        for (i = 0; i < len; i++)
  1894. X            if (fname[i] == '*')
  1895. X                new_len++;                /* '*' needs to be replaced by '.*' */
  1896. X        retval = alloc(new_len);
  1897. X        if (retval != NULL)
  1898. X        {
  1899. X            retval[0] = '^';
  1900. X            for (i = 0, j = 1; i < len; i++, j++)
  1901. X                if (fname[i] == '*')
  1902. X                {
  1903. X                    retval[j++] = '.';
  1904. X                    retval[j] = '*';
  1905. X                }
  1906. X                else if (fname[i] == '?')
  1907. X                    retval[j] = '.';
  1908. X                else
  1909. X                    retval[j] = fname[i];
  1910. X            retval[j] = NUL;
  1911. X        }
  1912. X    }
  1913. X    else
  1914. X    {
  1915. X        retval = alloc(len + 4);
  1916. X        if (retval != NULL)
  1917. X        {
  1918. X            STRNCPY(retval, fname, (size_t)len);
  1919. X            /*
  1920. X             * Don't add a star to ~ or ~user
  1921. X             */
  1922. X            save_char = fname[j = len];
  1923. X            fname[j] = NUL;
  1924. X            if (gettail(fname)[0] != '~')
  1925. X            {
  1926. X#ifdef MSDOS
  1927. X            /*
  1928. X             * if there is no dot in the file name, add "*.*" instead of "*".
  1929. X             */
  1930. X                for (i = len - 1; i >= 0; --i)
  1931. X                    if (strchr(".\\/:", retval[i]))
  1932. X                        break;
  1933. X                if (i < 0 || retval[i] != '.')
  1934. X                {
  1935. X                    retval[len++] = '*';
  1936. X                    retval[len++] = '.';
  1937. X                }
  1938. X#endif
  1939. X                retval[len++] = '*';
  1940. X            }
  1941. X            retval[len] = NUL;
  1942. X            fname[j] = save_char;
  1943. X        }
  1944. X    }
  1945. X#else /* WEBB_COMPLETE */
  1946. X#ifdef MSDOS
  1947. X    int        i;
  1948. X#endif
  1949. X
  1950. X    retval = alloc(len + 4);
  1951. X    if (retval != NULL)
  1952. X    {
  1953. X        STRNCPY(retval, fname, (size_t)len);
  1954. X#ifdef MSDOS
  1955. X    /*
  1956. X     * if there is no dot in the file name, add "*.*" instead of "*".
  1957. X     */
  1958. X        for (i = len - 1; i >= 0; --i)
  1959. X            if (strchr(".\\/:", retval[i]))
  1960. X                break;
  1961. X        if (i < 0 || retval[i] != '.')
  1962. X        {
  1963. X            retval[len++] = '*';
  1964. X            retval[len++] = '.';
  1965. X        }
  1966. X#endif
  1967. X        retval[len] = '*';
  1968. X        retval[len + 1] = 0;
  1969. X    }
  1970. X#endif /* WEBB_COMPLETE */
  1971. X    return retval;
  1972. X}
  1973. X
  1974. X/*
  1975. X * dosource: read the file "fname" and execute its lines as EX commands
  1976. X *
  1977. X * This function may be called recursively!
  1978. X *
  1979. X * return FAIL if file could not be opened, OK otherwise
  1980. X */
  1981. X    int
  1982. Xdosource(fname)
  1983. X    register char_u *fname;
  1984. X{
  1985. X    register FILE    *fp;
  1986. X    register int    len;
  1987. X#ifdef MSDOS
  1988. X    int                error = FALSE;
  1989. X#endif
  1990. X
  1991. X    expand_env(fname, NameBuff, MAXPATHL);        /* use NameBuff for expanded name */
  1992. X    if ((fp = fopen((char *)NameBuff, READBIN)) == NULL)
  1993. X        return FAIL;
  1994. X
  1995. X    ++dont_sleep;            /* don't call sleep() in emsg() */
  1996. X    len = 0;
  1997. X    while (fgets((char *)IObuff + len, IOSIZE - len, fp) != NULL && !got_int)
  1998. X    {
  1999. X        len = STRLEN(IObuff) - 1;
  2000. X        if (len >= 0 && IObuff[len] == '\n')    /* remove trailing newline */
  2001. X        {
  2002. X#ifdef MSDOS
  2003. X            if (len > 0 && IObuff[len - 1] == '\r') /* trailing CR-LF */
  2004. X                --len;
  2005. X            else
  2006. X            {
  2007. X                if (!error)
  2008. X                    EMSG("Warning: Wrong line separator, ^M may be missing");
  2009. X                error = TRUE;        /* lines like ":map xx yy^M" will fail */
  2010. X            }
  2011. X#endif
  2012. X                /* escaped newline, read more */
  2013. X            if (len > 0 && len < IOSIZE && IObuff[len - 1] == Ctrl('V'))
  2014. X            {
  2015. X                IObuff[len - 1] = '\n';        /* remove CTRL-V */
  2016. X                continue;
  2017. X            }
  2018. X            IObuff[len] = NUL;
  2019. X        }
  2020. X        breakcheck();        /* check for ^C here, so recursive :so will be broken */
  2021. X        docmdline(IObuff);
  2022. X        len = 0;
  2023. X    }
  2024. X    fclose(fp);
  2025. X    if (got_int)
  2026. X        emsg(e_interr);
  2027. X    --dont_sleep;
  2028. X    return OK;
  2029. X}
  2030. X
  2031. X/*
  2032. X * get single EX address
  2033. X */
  2034. X    static linenr_t
  2035. Xget_address(ptr)
  2036. X    char_u        **ptr;
  2037. X{
  2038. X    linenr_t    cursor_lnum = curwin->w_cursor.lnum;
  2039. X    int            c;
  2040. X    int            i;
  2041. X    long        n;
  2042. X    char_u      *cmd;
  2043. X    FPOS        pos;
  2044. X    FPOS        *fp;
  2045. X    linenr_t    lnum;
  2046. X
  2047. X    cmd = *ptr;
  2048. X    skipspace(&cmd);
  2049. X    lnum = MAXLNUM;
  2050. X    do
  2051. X    {
  2052. X        switch (*cmd)
  2053. X        {
  2054. X            case '.':                         /* '.' - Cursor position */
  2055. X                        ++cmd;
  2056. X                        lnum = cursor_lnum;
  2057. X                        break;
  2058. X
  2059. X            case '$':                         /* '$' - last line */
  2060. X                        ++cmd;
  2061. X                        lnum = curbuf->b_ml.ml_line_count;
  2062. X                        break;
  2063. X
  2064. X            case '\'':                         /* ''' - mark */
  2065. X                        if (*++cmd == NUL || (fp = getmark(*cmd++, FALSE)) == NULL)
  2066. X                        {
  2067. X                            emsg(e_umark);
  2068. X                            goto error;
  2069. X                        }
  2070. X                        lnum = fp->lnum;
  2071. X                        break;
  2072. X
  2073. X            case '/':
  2074. X            case '?':                        /* '/' or '?' - search */
  2075. X                        c = *cmd++;
  2076. X                        pos = curwin->w_cursor;        /* save curwin->w_cursor */
  2077. X                        curwin->w_cursor.col = -1;    /* searchit() will increment the col */
  2078. X                        if (c == '/')
  2079. X                        {
  2080. X                             if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)    /* :/pat on last line */
  2081. X                                curwin->w_cursor.lnum = 1;
  2082. X                            else
  2083. X                                ++curwin->w_cursor.lnum;
  2084. X                        }
  2085. X                        searchcmdlen = 0;
  2086. X                        if (dosearch(c, cmd, FALSE, (long)1, FALSE, TRUE))
  2087. X                            lnum = curwin->w_cursor.lnum;
  2088. X                        curwin->w_cursor = pos;
  2089. X                
  2090. X                        cmd += searchcmdlen;    /* adjust command string pointer */
  2091. X                        break;
  2092. X
  2093. X            default:
  2094. X                        if (isdigit(*cmd))                /* absolute line number */
  2095. X                            lnum = getdigits(&cmd);
  2096. X        }
  2097. X        
  2098. X        while (*cmd == '-' || *cmd == '+')
  2099. X        {
  2100. X            if (lnum == MAXLNUM)
  2101. X                lnum = cursor_lnum;
  2102. X            i = *cmd++;
  2103. X            if (!isdigit(*cmd))    /* '+' is '+1', but '+0' is not '+1' */
  2104. X                n = 1;
  2105. X            else 
  2106. X                n = getdigits(&cmd);
  2107. X            if (i == '-')
  2108. X                lnum -= n;
  2109. X            else
  2110. X                lnum += n;
  2111. X        }
  2112. X
  2113. X        cursor_lnum = lnum;
  2114. X    } while (*cmd == '/' || *cmd == '?');
  2115. X
  2116. Xerror:
  2117. X    *ptr = cmd;
  2118. X    return lnum;
  2119. X}
  2120. X
  2121. X
  2122. X#ifdef WEBB_COMPLETE
  2123. X/*
  2124. X * Must parse the command line so far to work out what context we are in.
  2125. X * Completion can then be done based on that context.
  2126. X * This routine sets two global variables:
  2127. X *    char_u *expand_pattern --- The start of the pattern to be expanded within
  2128. X *                                the command line (ends at the cursor).
  2129. X *    int expand_context --- The type of thing to expand.  Will be one of:
  2130. X *      EXPAND_UNSUCCESSFUL --- Used somtimes when there is something illegal on
  2131. X *            the command line, like an unknown command.  Caller should beep.
  2132. X *      EXPAND_NOTHING --- Unrecognised context for completion, use char like a
  2133. X *            normal char, rather than for completion.  eg :s/^I/
  2134. X *      EXPAND_COMMANDS --- Cursor is still touching the command, so complete it.
  2135. X *      EXPAND_FILES --- After command with XFILE set, or after setting with
  2136. X *            P_EXPAND set.  eg :e ^I, :w>>^I
  2137. X *      EXPAND_DIRECTORIES --- In some cases this is used instead of the latter
  2138. X *            when we know only directories are of interest.  eg :set dir=^I
  2139. X *      EXPAND_SETTINGS --- Complete variable names.  eg :set d^I
  2140. X *      EXPAND_BOOL_SETTINGS --- Complete bollean variables only,  eg :set no^I
  2141. X *      EXPAND_TAGS --- Complete tags from the files in p_tags.  eg :ta a^I
  2142. X *
  2143. X * -- webb.
  2144. X */
  2145. X    static void
  2146. Xset_expand_context(firstc, buff)
  2147. X    int            firstc;     /* either ':', '/', or '?' */
  2148. X    char_u        *buff;         /* buffer for command string */
  2149. X{
  2150. X    char_u        *nextcomm;
  2151. X    char_u        old_char;
  2152. X
  2153. X    old_char = cmdbuff[cmdpos];
  2154. X    cmdbuff[cmdpos] = NUL;
  2155. X    nextcomm = buff;
  2156. X    while (nextcomm != NULL)
  2157. X        nextcomm = set_one_cmd_context(firstc, nextcomm);
  2158. X    cmdbuff[cmdpos] = old_char;
  2159. X}
  2160. X
  2161. X/*
  2162. X * This is all pretty much copied from DoOneCmd(), with all the extra stuff we
  2163. X * don't need/want deleted.  Maybe this could be done better if we didn't
  2164. X * repeat all this stuff.  The only problem is that they may not stay perfectly
  2165. X * compatible with each other, but then the command line syntax probably won't
  2166. X * change that much -- webb.
  2167. X */
  2168. X    static char_u *
  2169. Xset_one_cmd_context(firstc, buff)
  2170. X    int            firstc;     /* either ':', '/', or '?' */
  2171. X    char_u        *buff;         /* buffer for command string */
  2172. X{
  2173. X    register char_u        *p;
  2174. X    char_u                *cmd, *arg;
  2175. X    int                 i;
  2176. X    int                    cmdidx;
  2177. X    int                    argt;
  2178. X    char_u                delim;
  2179. X    int                    forced = FALSE;
  2180. X    int                    usefilter = FALSE;    /* filter instead of file name */
  2181. X
  2182. X    expand_pattern = buff;
  2183. X    if (firstc != ':')
  2184. X    {
  2185. X        expand_context = EXPAND_NOTHING;
  2186. X        return NULL;
  2187. X    }
  2188. X    expand_context = EXPAND_COMMANDS;    /* Default until we get past command */
  2189. X
  2190. X/*
  2191. X * 2. skip comment lines and leading space, colons or bars
  2192. X */
  2193. X    for (cmd = buff; *cmd && strchr(" \t:|", *cmd) != NULL; cmd++)
  2194. X        ;
  2195. X    expand_pattern = cmd;
  2196. X
  2197. X    if (*cmd == NUL)
  2198. X        return NULL;
  2199. X    if (*cmd == '"')        /* ignore comment lines */
  2200. X    {
  2201. X        expand_context = EXPAND_NOTHING;
  2202. X        return NULL;
  2203. X    }
  2204. X
  2205. X/*
  2206. X * 3. parse a range specifier of the form: addr [,addr] [;addr] ..
  2207. X */
  2208. X
  2209. X    --cmd;
  2210. X    do
  2211. X    {
  2212. X        ++cmd;                            /* skip ',' or ';' */
  2213. X        skipspace(&cmd);
  2214. X        do
  2215. X        {
  2216. X            switch (*cmd)
  2217. X            {
  2218. X                case '.':                         /* '.' - Cursor position */
  2219. X                case '$':                         /* '$' - last line */
  2220. X                case '%':                         /* '%' - all lines */
  2221. X                    ++cmd;
  2222. X                    break;
  2223. X
  2224. X                case '\'':                         /* ''' - mark */
  2225. X                    if (*++cmd != NUL)
  2226. X                        ++cmd;
  2227. X                    break;
  2228. X
  2229. X                case '/':
  2230. X                case '?':                        /* '/' or '?' - search */
  2231. X                    delim = *cmd++;
  2232. X                    while (*cmd != NUL && *cmd != delim)
  2233. X                        cmd++;
  2234. X                    if (*cmd == delim)
  2235. X                        cmd++;
  2236. X                    break;
  2237. X
  2238. X                default:
  2239. X                    while (isdigit((char)*cmd))
  2240. X                        ++cmd;
  2241. X                    break;
  2242. X            }
  2243. X            
  2244. X            while (*cmd == '-' || *cmd == '+')
  2245. X            {
  2246. X                cmd++;
  2247. X                while (isdigit(*cmd))
  2248. X                    cmd++;
  2249. X            }
  2250. X        } while (*cmd == '/' || *cmd == '?');
  2251. X    } while (*cmd == ',' || *cmd == ';');
  2252. X
  2253. X/*
  2254. X * 4. parse command
  2255. X */
  2256. X
  2257. X    skipspace(&cmd);
  2258. X    expand_pattern = cmd;
  2259. X    if (*cmd == NUL)
  2260. X        return NULL;
  2261. X    if (*cmd == '"')
  2262. X    {
  2263. X        expand_context = EXPAND_NOTHING;
  2264. X        return NULL;
  2265. X    }
  2266. X
  2267. X    if (*cmd == '|' || *cmd == '\n')
  2268. X        return cmd + 1;                    /* There's another command */
  2269. X
  2270. X    /*
  2271. X     * Isolate the command and search for it in the command table.
  2272. X     * Exeptions:
  2273. X     * - the 'k' command can directly be followed by any character.
  2274. X     * - the 's' command can be followed directly by 'c', 'g' or 'r'
  2275. X     */
  2276. X    if (*cmd == 'k')
  2277. X    {
  2278. X        cmdidx = CMD_k;
  2279. X        p = cmd + 1;
  2280. X    }
  2281. X    else
  2282. X    {
  2283. X        p = cmd;
  2284. X        while (isalpha(*p) || *p == '*')    /* Allow * wild card */
  2285. X            ++p;
  2286. X        if (p == cmd && strchr("@!=><&~#", *p) != NULL)    /* non-alpha command */
  2287. X            ++p;
  2288. X        i = (int)(p - cmd);
  2289. X
  2290. X        if (i == 0)
  2291. X        {
  2292. X            expand_context = EXPAND_UNSUCCESSFUL;
  2293. X            return NULL;
  2294. X        }
  2295. X        for (cmdidx = 0; cmdidx < CMD_SIZE; ++cmdidx)
  2296. X            if (STRNCMP(cmdnames[cmdidx].cmd_name, cmd, (size_t)i) == 0)
  2297. X                break;
  2298. X    }
  2299. X    if (p == cmdbuff + cmdpos)        /* We are still touching the command */
  2300. X        return NULL;                /* So complete it */
  2301. X
  2302. X    if (cmdidx == CMD_SIZE)
  2303. X    {
  2304. X        if (*cmd == 's' && strchr("cgr", cmd[1]) != NULL)
  2305. X        {
  2306. X            cmdidx = CMD_substitute;
  2307. X            p = cmd + 1;
  2308. X        }
  2309. X        else
  2310. X        {
  2311. X            /* Not still touching the command and it was an illegal command */
  2312. X            expand_context = EXPAND_UNSUCCESSFUL;
  2313. X            return NULL;
  2314. X        }
  2315. X    }
  2316. X
  2317. X    expand_context = EXPAND_NOTHING; /* Default now that we're past command */
  2318. X
  2319. X    if (*p == '!')                    /* forced commands */
  2320. X    {
  2321. X        forced = TRUE;
  2322. X        ++p;
  2323. X    }
  2324. X
  2325. X/*
  2326. X * 5. parse arguments
  2327. X */
  2328. X    argt = cmdnames[cmdidx].cmd_argt;
  2329. X
  2330. X    arg = p;                        /* remember start of argument */
  2331. X    skipspace(&arg);
  2332. X
  2333. X    if (cmdidx == CMD_write)
  2334. X    {
  2335. X        if (*arg == '>')                        /* append */
  2336. X        {
  2337. X            if (*++arg == '>')                /* It should be */
  2338. X                ++arg;
  2339. X            skipspace(&arg);
  2340. X        }
  2341. X        else if (*arg == '!')                    /* :w !filter */
  2342. X        {
  2343. X            ++arg;
  2344. X            usefilter = TRUE;
  2345. X        }
  2346. X    }
  2347. X
  2348. X    if (cmdidx == CMD_read)
  2349. X    {
  2350. X        usefilter = forced;                    /* :r! filter if forced */
  2351. X        if (*arg == '!')                        /* :r !filter */
  2352. X        {
  2353. X            ++arg;
  2354. X            usefilter = TRUE;
  2355. X        }
  2356. X    }
  2357. X
  2358. X    if (cmdidx == CMD_lshift || cmdidx == CMD_rshift)
  2359. X    {
  2360. X        while (*arg == *cmd)        /* allow any number of '>' or '<' */
  2361. X            ++arg;
  2362. X        skipspace(&arg);
  2363. X    }
  2364. X
  2365. X    /*
  2366. X     * Check for '|' to separate commands and '"' to start comments.
  2367. X     * Don't do this for ":read !cmd" and ":write !cmd".
  2368. X     */
  2369. X    if ((argt & TRLBAR) && !usefilter)
  2370. X    {
  2371. X        p = arg;
  2372. X        while (*p)
  2373. X        {
  2374. X            if (*p == Ctrl('V'))
  2375. X            {
  2376. X                if (p[1] != NUL)
  2377. X                    ++p;
  2378. X            }
  2379. X            else if ((*p == '"' && !(argt & NOTRLCOM)) || *p == '|' || *p == '\n')
  2380. X            {
  2381. X                if (*(p - 1) != '\\')
  2382. X                {
  2383. X                    if (*p == '|' || *p == '\n')
  2384. X                        return p + 1;
  2385. X                    return NULL;    /* It's a comment */
  2386. X                }
  2387. X            }
  2388. X            ++p;
  2389. X        }
  2390. X    }
  2391. X
  2392. X    if (!(argt & EXTRA) && strchr("|\"", *arg) == NULL)    /* no arguments allowed */
  2393. X        return NULL;
  2394. X
  2395. X    /* Find start of last argument (argument just before cursor): */
  2396. X    p = cmdbuff + cmdpos;
  2397. X    while (p != arg && *p != ' ' && *p != TAB)
  2398. X        p--;
  2399. X    if (*p == ' ' || *p == TAB)
  2400. X        p++;
  2401. X    expand_pattern = p;
  2402. X
  2403. X    if (argt & XFILE)
  2404. X        expand_context = EXPAND_FILES;
  2405. X
  2406. X/*
  2407. X * 6. switch on command name
  2408. X */
  2409. X    switch (cmdidx)
  2410. X    {
  2411. X        case CMD_cd:
  2412. X        case CMD_chdir:
  2413. X            expand_context = EXPAND_DIRECTORIES;
  2414. X            break;
  2415. X        case CMD_buffer:
  2416. X        case CMD_wnext:
  2417. X        case CMD_args:            /* args now takes arguments like :next */
  2418. X        case CMD_next:
  2419. X        case CMD_snext:
  2420. X        case CMD_split:
  2421. X        case CMD_new:
  2422. X        case CMD_edit:
  2423. X        case CMD_ex:
  2424. X        case CMD_visual:
  2425. X            for (p = arg; *p; ++p)
  2426. X            {
  2427. X                if (*p == '\\' && p[1])
  2428. X                    ++p;
  2429. X                else if (*p == '|' || *p == '\n')
  2430. X                    return p + 1;
  2431. X            }
  2432. X            break;
  2433. X        case CMD_global:
  2434. X        case CMD_vglobal:
  2435. X            delim = *arg;             /* get the delimiter */
  2436. X            if (delim)
  2437. X                ++arg;                /* skip delimiter if there is one */
  2438. X
  2439. X            while (arg[0] != NUL && arg[0] != delim)
  2440. X            {
  2441. X                if (arg[0] == '\\' && arg[1] != NUL)
  2442. X                    ++arg;
  2443. X                ++arg;
  2444. X            }
  2445. X            if (arg[0] != NUL)
  2446. X                return arg + 1;
  2447. X            break;
  2448. X        case CMD_and:
  2449. X        case CMD_substitute:
  2450. X            delim = *arg;
  2451. X            if (delim)
  2452. X                ++arg;
  2453. X            for (i = 0; i < 2; i++, arg++)
  2454. X                while (arg[0] != NUL && arg[0] != delim)
  2455. X                {
  2456. X                    if (arg[0] == '\\' && arg[1] != NUL)
  2457. X                        ++arg;
  2458. X                    ++arg;
  2459. X                }
  2460. X            while (arg[0] != NUL && strchr("|\"#", arg[0]) == NULL)
  2461. X                ++arg;
  2462. X            if (arg[0] != NUL)
  2463. X                return arg;
  2464. X            break;
  2465. X        case CMD_set:
  2466. X            set_context_in_set_cmd(arg);
  2467. X            break;
  2468. X        case CMD_tag:
  2469. X            expand_context = EXPAND_TAGS;
  2470. X            expand_pattern = arg;
  2471. X            break;
  2472. X        default:
  2473. X            break;
  2474. X    }
  2475. X    return NULL;
  2476. X}
  2477. X
  2478. X/*
  2479. X * Do the expansion based on the global variables expand_context and
  2480. X * expand_pattern -- webb.
  2481. X */
  2482. X    static int
  2483. XExpandFromContext(pat, num_file, file, files_only, list_notfound)
  2484. X    char_u *pat;
  2485. X    int *num_file;
  2486. X    char_u ***file;
  2487. X    int files_only;
  2488. X    int list_notfound;
  2489. X{
  2490. X    regexp    *prog;
  2491. X    int        cmdidx;
  2492. X    int        count;
  2493. X    int        ret;
  2494. X    int        i;
  2495. X
  2496. X    if (!expand_interactively || expand_context == EXPAND_FILES)
  2497. X        return ExpandWildCards(1, &pat, num_file, file, files_only, list_notfound);
  2498. X    else if (expand_context == EXPAND_DIRECTORIES)
  2499. X    {
  2500. X        if (ExpandWildCards(1, &pat, num_file, file, files_only, list_notfound)
  2501. X                                                                    == FAIL)
  2502. X            return FAIL;
  2503. X        count = 0;
  2504. X        for (i = 0; i < *num_file; i++)
  2505. X            if (isdir((*file)[i]))
  2506. X                (*file)[count++] = (*file)[i];
  2507. X            else
  2508. X                free((*file)[i]);
  2509. X        if (count == 0)
  2510. X        {
  2511. X            free(*file);
  2512. X            *file = (char_u **)"";
  2513. X            *num_file = -1;
  2514. X            return FAIL;
  2515. X        }
  2516. X        *num_file = count;
  2517. X        return OK;
  2518. X    }
  2519. X    *file = (char_u **)"";
  2520. X    *num_file = 0;
  2521. X    ret = OK;
  2522. X    reg_ic = FALSE;
  2523. X    reg_magic = p_magic;
  2524. X    prog = regcomp(pat);
  2525. X    if (prog == NULL)
  2526. X        return FAIL;
  2527. X    if (expand_context == EXPAND_COMMANDS)
  2528. X    {
  2529. X        /* Count the matches: */
  2530. X        count = 0;
  2531. X        for (cmdidx = 0; cmdidx < CMD_SIZE; cmdidx++)
  2532. X            if (regexec(prog, cmdnames[cmdidx].cmd_name, TRUE))
  2533. X                count++;
  2534. X        if (count == 0
  2535. X          || (*file = (char_u **) alloc((int)(count * sizeof(char_u *)))) == NULL)
  2536. X            ret = FAIL;
  2537. X        else
  2538. X        {
  2539. X            *num_file = count;
  2540. X            count = 0;
  2541. X            for (cmdidx = 0; cmdidx < CMD_SIZE; cmdidx++)
  2542. X                if (regexec(prog, cmdnames[cmdidx].cmd_name, TRUE))
  2543. X                    (*file)[count++] = strsave(cmdnames[cmdidx].cmd_name);
  2544. X        }
  2545. X    }
  2546. X    else if (expand_context == EXPAND_SETTINGS
  2547. X      || expand_context == EXPAND_BOOL_SETTINGS)
  2548. X        ret = ExpandSettings(prog, num_file, file);
  2549. X    else if (expand_context == EXPAND_TAGS)
  2550. X        ret = ExpandTags(prog, num_file, file);
  2551. X    else
  2552. X        ret = FAIL;
  2553. X    
  2554. X    free(prog);
  2555. X    return ret;
  2556. X}
  2557. X#endif /* WEBB_COMPLETE */
  2558. END_OF_FILE
  2559.   if test 44081 -ne `wc -c <'vim/src/cmdline.c.B'`; then
  2560.     echo shar: \"'vim/src/cmdline.c.B'\" unpacked with wrong size!
  2561.   elif test -f 'vin/src/cmdline.c.A'; then
  2562.     echo shar: Combining  \"'vim/src/cmdline.c'\" \(82989 characters\)
  2563.     cat 'vim/src/cmdline.c.A' 'vim/src/cmdline.c.B' > 'vim/src/cmdline.c'
  2564.     if test 82989 -ne `wc -c <'vim/src/cmdline.c'`; then
  2565.       echo shar: \"'vim/src/cmdline.c'\" combined with wrong size!
  2566.     else
  2567.       rm vim/src/cmdline.c.A vim/src/cmdline.c.B 
  2568.     fi
  2569.   fi
  2570.   # end of 'vim/src/cmdline.c.B'
  2571. fi
  2572. if test -f 'vim/src/proto/buffer.pro' -a "${1}" != "-c" ; then 
  2573.   echo shar: Will not clobber existing file \"'vim/src/proto/buffer.pro'\"
  2574. else
  2575.   echo shar: Extracting \"'vim/src/proto/buffer.pro'\" \(1276 characters\)
  2576.   sed "s/^X//" >'vim/src/proto/buffer.pro' <<'END_OF_FILE'
  2577. X/* buffer.c */
  2578. Xint open_buffer __PARMS((void));
  2579. Xvoid close_buffer __PARMS((struct buffer *buf, int free_buf, int remove));
  2580. Xvoid buf_clear __PARMS((struct buffer *buf));
  2581. Xvoid buf_freeall __PARMS((struct buffer *buf));
  2582. Xint do_buffer __PARMS((int action, int start, int dir, int count, int forceit));
  2583. Xstruct buffer *buflist_new __PARMS((unsigned char *fname, unsigned char *sfname, long lnum, int use_curbuf));
  2584. Xint buflist_getfile __PARMS((int n, long lnum, int setpm));
  2585. Xvoid buflist_getlnum __PARMS((void));
  2586. Xunsigned char *buflist_nr2name __PARMS((int n));
  2587. Xvoid buflist_list __PARMS((void));
  2588. Xint buflist_name_nr __PARMS((int fnum, unsigned char **fname, long *lnum));
  2589. Xint setfname __PARMS((unsigned char *fname, unsigned char *sfname, int message));
  2590. Xvoid setaltfname __PARMS((unsigned char *fname, unsigned char *sfname, long lnum));
  2591. Xint buflist_add __PARMS((unsigned char *fname));
  2592. Xvoid buflist_altlnum __PARMS((void));
  2593. Xint otherfile __PARMS((unsigned char *fname));
  2594. Xvoid fileinfo __PARMS((int fullname));
  2595. Xvoid maketitle __PARMS((void));
  2596. Xvoid resettitle __PARMS((void));
  2597. Xunsigned char *fix_fname __PARMS((unsigned char *fname));
  2598. Xvoid fname_expand __PARMS((unsigned char **fname, unsigned char **sfname));
  2599. Xvoid do_arg_all __PARMS((void));
  2600. Xvoid do_buffer_all __PARMS((int all));
  2601. END_OF_FILE
  2602.   if test 1276 -ne `wc -c <'vim/src/proto/buffer.pro'`; then
  2603.     echo shar: \"'vim/src/proto/buffer.pro'\" unpacked with wrong size!
  2604.   fi
  2605.   # end of 'vim/src/proto/buffer.pro'
  2606. fi
  2607. echo shar: End of archive 8 \(of 26\).
  2608. cp /dev/null ark8isdone
  2609. MISSING=""
  2610. 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
  2611.     if test ! -f ark${I}isdone ; then
  2612.     MISSING="${MISSING} ${I}"
  2613.     fi
  2614. done
  2615. if test "${MISSING}" = "" ; then
  2616.     echo You have unpacked all 26 archives.
  2617.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2618. else
  2619.     echo You still must unpack the following archives:
  2620.     echo "        " ${MISSING}
  2621. fi
  2622. exit 0
  2623. exit 0 # Just in case...
  2624.