/* vi:set sts=4 sw=4:
 * vi:set comments=sbl\:*\ -,mb\:*,el\:*\ -,sr\:/\*,mb\:*,el\:*\/,fb\:- :
 *
 * VIM - Vi IMproved		by Bram Moolenaar
 *
 * Do ":help uganda"  in Vim to read copying and usage conditions.
 * Do ":help credits" in Vim to see a list of people who contributed.
 */

#include "vim.h"
#include "globals.h"
#include "proto.h"

/*
 * Vim originated from Stevie version 3.6 (Fish disk 217) by GRWalter (Fred)
 * It has been changed beyond recognition since then.
 *
 * All the remarks about older versions have been removed, they are not very
 * interesting.  Differences between version 3.0 and 4.x can be found in
 * "../doc/version4.txt".
 *
 * Changes between version 5.0i and 5.0j:
 * - Fixed: In Insert mode "0<C-D><C-D>" deleted an extra character, because
 *   Vim thought that the "0" was still there. (Acevedo)
 * - Fixed: "z<count>l" ignored the count.  Also for "zh" et. al. (Acevedo)
 * - Fixed: Crash when using tags.
 * - Fixed: "S" when 'autoindent' is off didn't delete leading white space.
 * - Fixed: A "highlight" command in the .vimrc file, to list a highlight
 *   setting, produced an unlimited number of spaces.
 * - Fixed: Tag guessing could find a function "some_func" instead of the
 *   "func" we were looking for.
 * - Fixed: "/<Tab>" landed on the wrong character when 'incsearch' is set.
 * - Fixed: ":r" in Ex mode must leave cursor on last read line, instead of
 *   first read line.
 * - Fixed: "g*" and "g#" didn't work.
 * - Fixed: When 'lazyredraw' and 'showcmd' are set, when typing "m<Esc>o"
 *   fast, the "o" command wasn't executed.  Was a recursiveness problem in
 *   vgetorpeek().
 * - Changed the extra field for static tags from "<Tab>;"s" to
 *   ";"<Tab>file:".  This allows for future expansion, and compatibility with
 *   Vi and Elvis.  Additional fields are now ignored.
 * - Fixed: When $DISPLAY is not set and gvim starts vim, title was restored
 *   to "Thanks for flying Vim".
 * - Fixed: The order in which autocommands were executed was sometimes messed
 *   up, because all autocommands for one pattern were put together, and
 *   the same command could only be added once.  Now the order is maintained
 *   and all autocommands are stored.  Disadvantage: when sourcing .vimrc
 *   twice, the autocommands defined there will appear twice!
 * - Made the output of ":autocmd" shorter and look better.
 * - Fixed: ":doautoall" could have the side effects, e.g., moving the cursor.
 * - Fixed: Asking a yes/no question could cause a "hit return" prompt.
 * - Fixed: When the file consists of one long line (>4100 characters), making
 *   changes caused various errors and a crash.
 * - Fixed: DJGPP version could not save long lines (>64000) for undo.
 * - Changed: When an unknown color name is used for GUI highlighting, keep
 *   the old color, don't switch back to black.
 * - Now use black on white if the fg/bg colors from the user are equal.
 * - Win32 GUI:
 *   - Fixed: gui_check_colors() didn't work, because highlight_gui_started()
 *     was called too late.
 *   - Fixed: ":!" commands output disappeared.  Now you have to type "exit"
 *     to close the execution window, but at least it works.
 *   - Fixed: Now accepts modifiers together with ALT key.
 *   - Fixed: Digraphs were wrong.
 * - Improved: Don't update the ruler when repeating insert (slowed it down a
 *   lot).
 * - Changed: 'compatible' is always set by default, also when a .vimrc file
 *   exists.  INCOMPATIBLE with release 4.x.
 * - Fixed: "yw" on the last char in the file didn't work.  Also fixed "6x" at
 *   the end of the line. "6X" at the start of a line fails, but does not
 *   break a mapping.  In general, a movement for an operator doesn't beep or
 *   flush a mapping, but when there is nothing to operate on it beeps (this
 *   is Vi compatible).
 * - Fixed: "m'" and "m`" now set the '' mark at the cursor position.
 * - Changed: All source files are now edited with a tabstop of 8 instead of
 *   4, which is better when debugging and using other tools.  'softtabstop'
 *   is set to 4, to make editing easier.
 *
 * Changes between version 5.0h and 5.0i:
 * - Included ctags version 1.6, with static tags modification (Darren Hiebert).
 * - Made "<Tab>;"s" in tags file recognized as a static tag.
 * - Fixed: Crash when using ":clear group-name" when there are no keywords.
 * - Fixed: Unix: Resetting of signals for external program didn't work,
 *   because SIG_DFL and NULL are the same!  For "!!yes|dd count=1|, the yes
 *   command kept on running.
 * - Partly fixed: Unix GUI: Typehead while executing an external command was
 *   lost.  Now it's not lost while the command is producing output.
 * - Fixed: "dw" at the end of a line didn't delete the last character.
 * - Added: In a help window, a double-click jumps to the tag under the
 *   cursor (like CTRL-]).
 * - Really fixed now: Typing <S-Tab> in Insert mode, when it isn't mapped,
 *   inserted "<S-Tab>".  Now it works like a normal <Tab>, just like <C-Tab>
 *   and <M-Tab>.
 * - Fixed: Redrawing ruler didn't check for old value correctly (caused UMR
 *   warnings in Purify).
 * - Fixed: Memory leaks in ga_grow() and syn_cmd_region().
 * - Fixed: negative array index in finish_viminfo_history().
 * - Fixed: ":g/^/d|mo $" deleted all the lines.  The ":move" command now
 *   removes the :global mark from the moved lines.
 * - Changed the font stuff in the Win32 GUI, to skip fonts that cannot be
 *   used (non-monospaced). (Moore)
 * - GUI Win32: CTRL-Z minimizes the window now (Moore).
 * - Removed beep_count for Win32 (beeping only one out of ten times).
 * - Added setting of blink times to 'guicursor'.  Implemented GUI cursor
 *   blinking for X11 and Win32.
 * - Fixed for MSDOS: Moving the cursor with the mouse didn't work.
 * - Fixed for Win32: Ex mode didn't echo characters.
 * - Changed: For Win32 GUI font name, replace '_' with space (instead of
 *   dot).
 * - Fixed: Test 12 failed.
 * - Fixed: Using "vG" while the last line in the window is a "@" line,
 *   didn't update correctly.  Just the "v" showed "~" lines.
 * - Made ":highlight link" ignored (batch) or produce a warning message
 *   (interactive), when highlighting has already been defined for the group.
 *   Use ":highlight!" to link anyway.
 * - Fixed: Crash when swap file can't be opened, and in a few other
 *   situations, for MSDOS and Win32.
 * - Fixed: "daw" on the last char of the file, when it's a space, moved the
 *   cursor beyond the end of the line.
 * - Fixed: When 'hlsearch' was set or reset, only the current buffer was
 *   redrawn, while this affects all windows.
 * - Fixed: test3 depended on the window width.
 * - Changed: text object commands have been renamed: "a" becomes "aw", "A"
 *   becomes "aW", "s" becomes "as", "p" becomes "ap", "S" becomes "ab" and
 *   "P" becomes "aB".
 * - Fixed: CTRL-^, positioning the cursor somewhere from 1/2 to 1 1/2 screen
 *   down the file, put the cursor at the bottom of the window, instead of
 *   halfway.
 * - Changed: Win32 GUI tries to keep the window inside the screen (Pirotte).
 * - Fixed: Crash for ":let a = expand("`!ls`")", and many other ":let"
 *   commands for which the right hand side results in a NULL string.
 * - Fixed: When scrolling up for ":append" command, not all windows were
 *   updated correctly.
 * - Fixed: When 'hlsearch' is set, and an auto-indent is highlighted,
 *   pressing <Esc> didn't remove the highlighting, although the indent was
 *   deleted.
 * - Fixed: When $DISPLAY not set, starting "gvim" (dropping back to vim) and
 *   then selecting text with the mouse caused a crash.
 * - Fixed: When using an illegal CTRL-X key in Insert mode, the CTRL-X mode
 *   message stuck.
 * - Improved: For Unix, file name expansion is now done internally instead of
 *   starting a shell for it.  Should be a big speed improvement.
 *
 * Changes between version 5.0g and 5.0h:
 * - Included ctags version 1.6b4 (Darren Hiebert).
 * - Changed the Perl interface (Gerassimoff).
 * - Fixed: When 'ru' set and 'nosc', using "$j" showed a wrong ruler.
 * - Changed: <C-Left> and <C-Right> now work like <S-Left> and <S-Right>,
 *   move a word forward/backward (Windows compatible).
 * - Added: 'titlestring' and 'iconstring' options: define window and icon
 *   strings, when not empty.
 * - Changed: when using "%", "#", etc. in an expression, and the value is not
 *   available, just return an empty string, instead of giving an error
 *   message.
 * - Fixed: Under Xfree 3.2, Shift-Tab didn't work (wrong keysym is used).
 * - Fixed: mapping <S-Tab> didn't work.  Changed the key translations to use
 *   the shortest key code possible.  This makes the termcode translations and
 *   mappings more consistant.	Now all modifiers work in all combinations,
 *   not only with <Tab>, but also with <Space>, <CR>, etc.
 * - Fixed: Typing <S-Tab> in Insert mode, when it isn't mapped, inserted
 *   "<S-Tab>".  Now it works like a normal <Tab>, just like <C-Tab> and
 *   <M-Tab>.
 * - Added "maxlines" and "minlines" commands to ":syntax sync".
 * - Reduced memory usage for syntax keywords by about a factor 100.  It's
 *   much faster loading a lot of keywords, but a bit slower displaying.
 * - Fixed: When using more than 256 highlight groups, highlighting confused
 *   the names of different groups.
 * - Implemented 'softtabstop' option.	Makes it more easy to keep 'ts' at 8.
 * - Fixed: When a color was not available, zero was used, which is often
 *   black.  Now use the default color.
 * - Fixed: Listing of "ctermfg" and "ctermbg" highlighting was one off.
 * - Fixed: In GUI, triple click on an empty line caused a crash.
 * - Added changes to produce a DLL version with Borland C++ (Aaron).
 * - Moved prototype for tmpnam() and mktemp() to osdef2.h.in.
 * - Fixed: For Unix, restore three more signals.  And SIGINT is catched now,
 *   so CTRL-C in Ex mode doesnt make Vim exit.
 * - Fixed: ""a5Y" yanked 25 lines instead of 5.
 * - Fixed: Win32 GUI had dotted lines with some fonts. (Gerassimof)
 * - Fixed: a highlight "contains" item with a regexp was using the wrong
 *   groups (one off).
 * - Always allow multi-level undo, also in Vi compatible mode.  But 'u' flag
 *   in 'cpoptions' tells how "u" and CTRL-R work.
 * - 'updatecount' always defaults to non-zero, also for Vi compatible mode.
 *   This means there is a swap file, that can be used for recovery.
 * - For Unix: Put a dot before the swap file name, so it doesn't show in an
 *   ":!ls".
 * - INCOMPATIBLE: Start in 'compatible' mode when there is no ".vimrc" file.
 *   This was requested by many people.
 * - ":set nocompatible" works now.
 * - Fixed: "vrxxx<Esc>" in an empty line could not be undone.
 * - Fixed: A CTRL-C that breaks ":make" caused the errorfile not to be read
 *   (annoying when you want to handle what ":make" produced so far).
 * - Removed the requirement for a ":version" command in a .vimrc file.  It
 *   wasn't used for anything.	You can use ":if" to handle differences
 *   between versions.
 * - Fixed: ":0;/pat" didn't find "pat" in line 1.
 * - Fixed: Search for "/test/s+1" at first char of file gave bottom-top
 *   message, or didn't work at all with 'nowrapscan'. 
 * - Fixed: "E" at end-of-file moved cursor past end-of-line.
 * - Changed the 'highlight' option default, to use highlight groups.  These
 *   highlight groups include color for cterm and gui, to make it look nice by
 *   default.
 * - Made ":highlight NONE" reset all highlighting for one group.
 * - Removed special settings for italic, bold and underline colors.  Can now
 *   be done with highlight groups.
 * - Added 'guicursor' option, to set the cursor shape and color in various
 *   modes.
 * - Fixed: the "Quit" window menu entry now only gives messages when there
 *   are modified buffers.  Still need to find a way to avoid the window being
 *   deleted when there are modified buffers!
 * - Fixed: Bug in viminfo history.  Could cause a crash on exit.
 * - Fixed: A nested match was sometimes skipped if there was a match for the
 *   same item in a previous line (gave bogus paren error).
 * - Added color names "fg", "foreground", "bg" and "background".  They get
 *   the current default fore-/background color.
 * - For MS-DOS, Win32 and OS/2: When comparing file names for autocommands,
 *   don't make a difference between '/' and '\' for path separator.
 * - Fixed: Vim_vc4.mak didn't produce "ex_cmds.h".  Replaced a slash by a
 *   backslash in a few places.
 * - Fixed: DJGPP and Win32 versions created swap files starting with a dot:
 *   ".swp".  Now an underscore is prepended: "_.swp".  This is required for
 *   FAT file sytems.
 * - Win32 GUI: No longer use vim.ini.  Everything can be set in the vimrc or
 *   gvimrc file.
 * - Renamed all color names to be the same on all systems.  For DOS-alikes
 *   this means, for example, that "Cyan" is now "DarkCyan".
 * - A number of additions for the Win32 GUI by Paul Moore:
 *   - Fixed: Beeping didn't work properly.
 *   - Font name now has the real point size, instead of 3/4 points.
 *   - Read the "$VIM/rgb.txt" file for more color names.
 *   - Font name now can contain a '.' in place of a space (no need for a
 *     backslash) and uses ':' to separate fields.  Example:
 *     "set guifont=Courier.New:h13:w7:u", "set
 *     guifont=Lucida.Console:h22:w13".
 *   - additonal fix (not from Paul): reset font attributes first, otherwise
 *     it's impossible to stop underlining et al.
 * - Fixed: MSDOS can now find $VIM value from the name of the executable.
 *
 * Changes between version 5.0f1 and 5.0g:
 * - Included ctags version 1.6b2 (Darren Hiebert).
 * - Fixed: When using both case-match and case-ignore keywords, the
 *   case-ignore keywords were not highlighted.
 * - Fixed: ":print" didn't put cursor on first non-blank in line.
 * - Fixed: ":0r !cat </dev/null" left cursor in line zero, with very strange
 *   effects.
 * - Fixed: Starting without any arguments in a terminal window of less than
 *   ten lines crashed or looped forever, when printing the intro message.
 * - Fixed: With 'showcmd' set and 'timeoutlen' set to a few seconds, trick to
 *   position the cursor leftwards didn't work.
 * - Fixed: AIX stty settings were restored to cs5 instead of cs8 (Winn).
 * - Fixed: Crash for ":set" command, after starting to edit a new buffer.
 * - Fixed: ":if 1\nelseif 0\nelse" did the last else part.
 * - Fixed: file name completion didn't work for "zsh" versions that put spaces
 *   between file names, instead of NULs.
 * - Fixed: When 'nowrap' set, incsearch didn't show a match when it was off
 *   the side of the screen.  Now it also shows the whole match, instead of
 *   just the cursor position (if possible).
 * - Changed "XawChain*" to "XtChain*", should work for more systems.
 * - Added ":syntax clear group-name .." command.
 * - Implemented listing of highlighting.
 * - Updated the default highlight groups in syntax.vim.
 * - Added ":while", ":continue", ":break" and ":endwhile" commands.
 * - Added ":doautoall" command.
 * - Added the (extremely powerful) ":execute" command.
 * - Included support for the Farsi language (Shiran).
 * - Included quite a few fixes for rightleft mode (Lottem).
 * - Changed exists("has_something") to has("something").  Now it's more clear
 *   that the "has_" things aren't really internal variables.
 * - Added ":let" and ":let var" commands: listing of internal variables.
 * - Added strftime() function to expressions.
 * - Fixed: didn't ask to "hit return" when GUI is started and error messages
 *   are printed.
 * - Added for syntax highlighting: It's now possible to match a contained
 *   item in the same position as the where the containing match starts.
 * - Added highlight_exists() function.
 * - Fixed: syntax could take highlighting from two lines back, when making a
 *   change within one line.
 * - Fixed: When trying to edit a file in a non-existent directory, ended up
 *   with editing "No file".
 * - Fixed: Syntax highlighting could not match an empty line.
 * - Fixed: "gqp" to format a paragraph did too much redrawing.
 * - Added: Motif can now position the menu's in the correct order.
 * - Fixed: When 'hlsearch' set, only the current window was updated for a new
 *   search pattern.
 * - Fixed: When 'hlsearch' used, ignorecase could be wrong (when also using
 *   syntax highlighting).
 * - Fixed: Sometimes error messages on startup didn't cause a "hit-return",
 *   because of autocommands containing an empty line.
 * - Fixed: In insert mode, deleting text one char before the end (visual
 *   selection and then "x"), moved the cursor one char to far.
 * - Changed: "vim -u NONE" now also stops loading the .gvimrc and other GUI
 *   inits.
 * - Fixed: "~" on last character of the line moved cursor beyond end of line.
 * - Fixed: Was possible to select part of the window in the border, below the
 *   command line.
 * - Fixed: '< and '> marks were not at the correct position after linewise
 *   Visual selection.
 * - Fixed: dependencies for Perl were not included in Makefile.
 * - When translating a help argument to "CTRL-x", prepend or append a '_',
 *   when applicable.
 * - GUI: Cursor size when it's a line or bar now depends on the font size.
 *
 * Changes between version 5.0f and 5.0f1 (just a patch):
 * - Commented out gcc CFLAGS.
 * - Fixed: Crash in Win32 GUI (Webb).
 * - Added priority to ":menu" command, to fix the problem that the "File"
 *   menu wasn't first when menus are defined in the .vimrc file.  Only works
 *   for Athena now.
 * - Added "AF" and "AB" termcap entries, used instead of "Sf" and "Sb" when
 *   present.  Fixes color-swap problem for some color-xterm termcap entries.
 * - Added "doauto" to syntax/syntax.vim, so the highlighting applies as soon
 *   as syntax.vim is executed.
 *
 * Changes between version 5.0e and 5.0f:
 * - Added quite a few highlighting files, and update a few other ones.
 * - Fixed: When there are only keywords, ":syntax" didn't list them, and
 *   highlighting didn't work.
 * - Added configure check for strncasecmp(), stricmp() and strnicmp().  Added
 *   vim_stricmp() for when there's no library function for stricmp().
 * - Fixed: In an xterm that switches screens, after exiting Vim all shell
 *   commands would be highlighted.
 * - Fixed: Blockwise visual mode wasn't correct when moving vertically over a
 *   special character (displayed as two screen characters).
 * - Added 'nrformat' option.  Default: "hex,octal".
 * - Renamed "struct option" to "struct vimoption" to avoid name clash with
 *   GNU getopt().
 * - Fixed: ":abclear" didn't work (but ":iabclear" and ":cabclear" did work).
 * - In Visual mode, "Q" is ignored (just gives a beep).
 * - In Insert mode, "<C-O>Q" didn't redraw after returning.
 * - Fixed: when 'nowrap' used, screen wasn't always updated correctly.
 * - Fixed: "vim -c split file" displayed extra lines.
 * - Added file_readable() function to expressions.
 * - Included patches for Python (Moore).
 * - Fixed: After starting the GUI, searched the termcap for a "gui" term.
 * - Fixed: When 'hls' used, search for "^$" caused a hang.
 * - Fixed for Unix: Only output an extra newline on exit when outputted
 *   something in the alternate screen, or when there is a message that needs
 *   to be cleared.
 * - Fixed: w_curswant wasn't updated always, caused test20 to fail.
 * - Fixed: "/a\{" did strange things, depending on previous search.
 * - Fixed: When 'hls' was set, an error in the last regexp caused trouble.
 * - Fixed: "c}" only redrawed one line (with -u NONE).
 * - Fixed: Ex mode didn't work for GUI and systems without cooked input.
 * - Fixed: MSDOS an DJGPP versions messed up interrupt handling when going to
 *   Ex mode.  Separated raw/cooked setting and interrupt catching on/off.
 * - Fixed: divide by zero crashed Vim (e.g. in ":echo % % %").
 * - Fixed: Starting GUI in Ex mode could get wrong window height.
 * - Fixed: For mappings, CTRL-META-A was shown as <M-^A> instead of <MC-A>,
 *   while :map only accepts <MC-A>.  Now <M-C-A> is shown.
 * - "/\(.\{2\}\)*" gave bogus error message.
 * - Fixed: syntax regions didn't work correct when no syncing specified
 *   (e.g., a simple string didn't cross lines).
 * - Fixed: Syntax highlighting didn't work for special characters when there
 *   is a 'hls' match in the same line.
 * - Fixed: syntax match which matches an empty string was only recognized
 *   once at the start or just after another match.
 * - Fixed: GUI highlighting: Could not set background or foreground to black
 *   (unless it is the default color)
 * - Fixed: In Insert mode, cursor-right at end of line moved shown cursor left.
 * - Various changes to make the Win32 GUI work better (Webb).
 * - Implemented the "shortest match" regexp "\{-}" (Webb).
 * - Added ":intro" command: Show introductory message.
 * - Fixed: Unix: When using full path name in a tags file, which contains a
 *   link, and 'hidden' set and jumping to a tag in the current file, would
 *   get bogus ATTENTION message.  Solved by always expanding file names, even
 *   when starting with '/'.
 * - Fixed: When inserting a CR with 'cindent' set (and a bunch of other
 *   conditions) the cursor went to a wrong location.
 * - Added: GUI Menu for syntax highlighting in syntax.vim.
 * - Changed '|' register to '=' register (expression evaluation)
 *
 * Changes between version 5.0d and 5.0e:
 * - Use $VIM for global vimrc, gvimrc and menu.vim files.
 * - Removed os_os2_mkpd.c, it only contained the compile flags, which hardly
 *   ever change.
 * - Fixed: After ":global" command, cursor could be past the end of the line.
 * - Fixed: 'hlsearch' highlighting of special characters (e.g., a TAB) didn't
 *   highlight the whole thing.
 * - Fixed: Variable names must not depend on 'iskeyword', because this may
 *   include strange characters, like '(' for help files.
 * - Included xxd version xxd V1.7a (Juergen Weigert).
 * - Fixed: After "Du^R" cursor could be past the end of the line.
 * - Added "%", "#", "<cword>", etc. to expressions (Goldberg).
 * - Added FileChangedShell autocommand event (Goldberg).
 * - Expand <sfile> in an ":autocmd" when it is defined.
 * - Added "nested" flag to ":autocmd", allows nesting.
 * - Handle CTRL-C in GUI for external command, when "setsid()" is supported.
 * - Syncing on C comments is a little bit better for // lines.
 * - Changed syntax of ":region" command to require a '=' for the start, skip
 *   and end items.  More consistent with the ":highlight" command.
 * - Fixed: "r<CR>" didn't work correctly on the last char of a line.
 * - Fixed: sometimes a window resize or other signal caused an endless loop,
 *   involving set_winsize().
 * - Included a few extra syntax files.  Improved a few existing ones.
 * - Fixed: a syntax "end" pattern that matches the start of a line with "^"
 *   didn't work.
 * - Fixed: Syntax keyword matching didn't work when current buffer had other
 *   'iskeyword' setting (e.g., help files).
 * - Added ignoring case for syntax highlighting: ":syntax case [match|ignore]".
 * - Fixed: "vim -r" didn't work, it just hang (using tgetent() while 'term'
 *   is empty).
 * - Fixed: "gk" while 'nowrap' set moved two lines up.
 * - Fixed: when windows are split, a message that causes a scroll-up messed
 *   up one of the windows, which required a CTRL-L to be typed.
 * - Added "mb" termcap option: blink.	Can only be used by assigning it to
 *   one of the other highlight options.
 * - Changed: When an :if or :elseif runs into an error, don't wait for an
 *   :endif, just abort the conditional.
 * - Fixed: possible endless loop when using shell command in the GUI.
 * - Fixed: menu's defined in the .vimrc were removed when GUI started.
 * - Fixed: when syncing in C comments, skip backwards over lines that end in
 *   a backslash.  Helps for multi-line defines.
 * - Allow use of not-yet defined group names after "contains".  Needed for
 *   ALLBUT where the current item is used.
 * - Fixed: A CTRL-C inside an ":if" command stopped the screen updating.
 * - Renamed "various.c" to "misc2.c", "misccmds.c to "misc1.c".
 * - Fixed: was possible to move cursor beyond end of line with "''".
 *
 * Changes between version 5.0c and 5.0d:
 * - Added Win32 GUI version (Robert Webb) !!!
 * - Included Exuberant ctags 1.6b1 (Darren Hiebert).  Made changes to
 *   Makefile to compile it.
 * - Included patches for Python interface from Paul Moore.
 * - Fixed crash when pasting with the mouse in insert mode.
 * - Fixed menu bar not working (or even crashing gvim).
 * - Fixed: RIGHTLEFT didn't work.
 * - Ignore characters after "ex", "view" and "gvim" when checking startup
 *   mode.  Allows the use of "gvim5" et. al.
 * - Added "-Z" argument: start in restricted mode (like "rvim").
 * - Fixed: crash whith ":unmenu *" in .gvimrc for Athena.
 * - Fixed: syntax "ctermfg=" would set "ctermbg=" instead.
 * - Fixed: "5>>" shifted 5 lines 5 times, instead of 1 time.
 * - Fixed: CTRL-C when getting a prompt in ":global" didn't interrupt.
 * - Fixed: CTRL-Y and CTRL-E in Insert mode didn't work.
 * - Fixed: when 'so' is non-zero, and moving the scrollbar completely to the
 *   bottom, there was a lot of flashing.
 * - Fixed: moving cursor with mouse in Insert mode didn't work.
 * - Fixed GUI: scrollbar ident must be long for DEC Alpha.
 * - Made 'guipty' default on, because so many people need it.
 * - "gex" and "gview" start the GUI in ex mode or readonly mode.
 * - Implemented ":set all&", set all options to their default value.
 * - Stop highlighting before clearing the screen, needed for some terminals.
 * - Added "getline()" evaluation function, can be used to check for type of
 *   syntax highlighting in script files.
 * - Added "has_syntax_items" variable, is TRUE when syntax items present.
 * - Fixed: Some functions called vim_regcomp() without setting reg_magic,
 *   which could lead to unpredictable magicness.
 * - Fixed: crash when clicking around the status line, could get a selection
 *   with a backwards range.
 * - Fixed: abbreviations didn't work.
 * - Renamed "sub.c" to "various.c".
 * - Changed ":syntax translate" into ":highlight link".
 * - Handle all syntax stuff like 'magic' is set.
 * - Removed highlight groups local to buffer.	They are all global now, so
 *   they can be shared between buffers.
 * - Added group-name argument to "syntax sync ccomment", so you can specify
 *   the group-name for a comment.
 * - Fixed: when deleting more than one line characterwise, the last character
 *   wasn't deleted.
 * - Fixed: tags file name relative to the current file didn't work.
 *
 * Changes between version 5.0b and 5.0c:
 * - Set time of patch and backup file same as original file (Unix only).
 *   (Hiebert).
 * - INCOMPATIBLE changes to command line arguments:
 *   "-v" now means to start Ex in Vi mode, use "-R" for read-only mode.
 *   "-e" now means to start Vi in Ex mode, use "-q" for quickfix.
 *   "-s" in Ex mode now means to run in silent (batch) mode.
 *   "-x" reserved for crypt, use "-f" to avoid starting a new CLI (Amiga).
 * - Amiga in QuickFix mode no longer opens another window.  Shell commands
 *   can be used now.
 * - Switched to autoconf 2.12.
 * - Added range to ":normal" command.
 * - MSDOS: Added detection of $VIM by finding "vim.exe" in the path.
 * - Win32: Added detection of $VIM by using argv[0].
 * - GUI: fixed: status line could be overwritten when moving the scrollbar
 *   quickly (or when 'wd' is non-zero).
 * - Added decmouse patches from David Binette.
 * - Added "wildcard in path" patches from Karsten Sievert.
 * - Included "shtags" from Stephen Riehm.
 * - Made w_fraction from float to int, so Amiga doesn't need "-lm".
 * - Expand environment variables with expand_env(), instead of calling the
 *   shell.  Makes ":so $VIM/syntax/syntax.vim" a LOT faster.
 * - Fixed: An ESC at the end of a ":normal" command caused a wait for a
 *   terminal code to finish.  Now, a terminal code is not recognized when its
 *   start comes from a mapping or ":normal" command.
 * - Included "<sfile>": file name from a ":source" command.
 * - Renamed strsave() to vim_strsave().  dgux has it as a library function.
 * - Renamed mk_os2pd.c to os_os2_mkpd.c, to put it with the "os_" files.
 * - Renamed perl* to if_perl*.
 * - Added Python interface patches from Paul Moore: if_python*.
 * - Moved a lot of code outside of the big switch() statements in edit.c,
 *   ex_docmd.c and normal.c.  Helps for compiler optimization and makes the
 *   code easier to understand.
 * - Included patches for BeBox from Olaf Seibert.
 * - Included patches from Robert Webb for GUI.  Layout of the windows is now
 *   done inside Vim, instead of letting the layout manager do this.  Makes
 *   Vim work with Lesstif!
 *
 * Changes between version 5.0a and 5.0b:
 * - Renamed b_filename to b_ffname, b_xfilename to b_fname and b_sfilename to
 *   b_sfname.	Renamed mf_xfname to mf_ffname.
 * - Added ":echon" command and changed ":echo" command.
 * - Added register '|': result of expression.
 * - Display '#' register with ":dis" command.
 * - Renamed a lot of files.  All operating system dependent files are now
 *   preceded with "os_".
 * - Read the default menus from $VIM/menu.vim
 *
 * Changes between version < 4.9 and 5.0a:
 * - Added ":echo" command.
 * - Use "datadir" in configure, instead of our own check for HELPDIR.
 * - Reduced output for cursor positioning: Use CR-LF for moving to first few
 *   columns in next few lines;  Don't output CR twice when using termios.
 * - Optimized cursor positioning.  Use CR, BS and NL when it's shorter than
 *   absolute cursor positioning.
 * - Removed ':' from 'isfname' for Unix. Check for "://" in a file name
 *   anyway.  Also check for ":\\", for MS-DOS.
 * - Split cmdline.c into ex_docmd.c and ex_getln.c.
 * - Don't show the mode when redrawing is disabled.
 * - Disable redrawing while repeating insert "1000ii<Esc>".
 * - GUI: Change cursor shape when to vertical bar when inserting and
 *   horizontal bar when replacing text.
 * - Added '@' highlighting flag in 'highlight'.
 * - Added support for "bc" termcap entry.
 * - Count to "K"eyword command, when 'keywordprg' is "man", is inserted in
 *   the man command.  "2K" results in "!man 2 <cword>"
 * - When using "gf" on a relative path name, remove "../" from the file name,
 *   like it's done for file names in the tags file.
 * - When started as "rvim", disallow shell commands.
 * - Added 'u' flag to 'cpoptions': make "u" work like in vi, but allow
 *   multi-level undo/redo with CTRL-R.
 * - Disallow 'h' flag in 'highlight' (wasn't used anymore since 3.0).
 * - Changed variable names and comments for "yank buffer" to "yank register",
 *   to reflect what is used in the docs.
 * - When finishing recording, don't make the record register the default put
 *   register.
 * - Changed attachment layout for Motif (Sonia Heimann).
 * - Made "d$" or "D" for long lines a lot faster (delete all characters at
 *   once, instead of one by one).
 * - When using "!!", don't put ":5,5!" on the command line, but ":.!".  And
 *   some other enhancements to replace the line number with "." or "$" when
 *   possible.
 * - Renamed normal() to normal_cmd(), a Mac compiler doesn't like normal().
 * - Unix: Added "link.sh" script, which removes a few unneccesary libraries
 *   from the link command.
 * - Added all the syntax highlighting stuff, in sytax.c.
 * - When using $VIM and it's not set, get the directory from 'helpfile',
 *   excluding "/doc/help.txt".
 * - Made the default for the 'helpfile' "$VIM/doc/help.txt" (added the
 *   "/doc" part).
 * - Removed use of IObuff in vim_getenv(), makes life easier.
 * - MSDOS et.al.: Renamed $VIM/viminfo to $VIM/_viminfo.  It's more
 *   consistant: .vimrc/_vimrc and .viminfo/_viminfo
 * - Moved contents of regsub.c into regexp.c, cleaned it up a little.
 * - Included patches from Robert Webb for \{a,b\} in regexp patterns.
 * - Included patches from Eric Fischer for first version of Ex mode.
 * - For systems where case doesn't matter in file names (MSDOS, Amiga), sort
 *   file names while ignoring case.  For buffer names too.
 * - Added 'lazyredraw' option: Don't redraw the screen while executing
 *   macros, registers or other not typed commands.
 * - Added '#' register: alternate file name.
 * - Added ":hide" command, exactly the same as ":close".
 * - When starting the GUI, restrict the window size to the screen size.
 * - Deleted "addcr.c" and "addcr.bat".  They were not very useful.
 * - When resizing the window, don't redraw when redrawing is disabled.  Will
 *   happen later.
 * - Added highlighting to show the match with the last used search pattern,
 *   when 'hlsearch' option is set.
 * - Don't use HPUX digraphs by default, but only when HPUX_DIGRAPHS is
 *   defined.
 * - Added 't_xs', highlighting not erased by overwriting, for hpterm.
 *   Combined with 'weirdinvert'.  Visual mode works on hpterm now.
 * - Made setting special highlighting attributes a lot faster by using
 *   highlight_attr[], instead of searching in the 'highlight' string.
 * - Did some performance optimizations, various changes to source code.
 * - Access option table by first letter, instead of searching from start.
 * - Added expression evaluation, ":let" command in eval.c.
 * - Added ":if", ":else", ":elseif" and ":endif" commands.
 * - Fixed UMR warning in set_expand_context().
 * - Fixed memory leak: b_winlnum list was never freed.
 * - Added patches for using Perl.  ":perldo", ":perl", etc.  Patches made by
 *   Sven Verdoolaege and Matt Gerassimoff.
 * - Allow command line file-arguments and option-arguments to be mixed.
 * - Added "-" commandline argument: read text from stdin.
 * - When reading from stdin doesn't work, read from stderr (helps for
 *   "foo | xargs vim".
 * - Removed the use of "did_cd": Only use the full pathname for files that
 *   are currently open, not for files opened after the ":cd". (Webb)
 * - When resizing windows, try to keep the cursor in the same relative
 *   position.	(Webb)
 */

#include "version.h"

char	*Version = VIM_VERSION_SHORT;
char	*mediumVersion = VIM_VERSION_MEDIUM;
#ifdef HAVE_DATE_TIME
char	*longVersion = VIM_VERSION_LONG_DATE __DATE__ " " __TIME__ ")";
#else
char	*longVersion = VIM_VERSION_LONG;
#endif

static void version_msg __ARGS((char *s));

    int
get_version()
{
    return (VIM_VERSION_MAJOR * 100 + VIM_VERSION_MINOR);
}

    void
do_version(arg)
    char_u  *arg;
{
    /*
     * Ignore a ":version 9.99" command.
     */
    if (*arg == NUL)
    {
	/*
	 * When adding features here, don't forget to update the list of
	 * internal variables in eval.c!
	 */
	msg_putchar('\n');
	MSG(longVersion);
#ifdef WIN32
	MSG_PUTS("\nWindows NT / Windows 95 version");
#endif
#ifdef MSDOS
# ifdef DJGPP
	MSG_PUTS("\n32 bit MS-DOS version");
# else
	MSG_PUTS("\n16 bit MS-DOS version");
# endif
#endif
	MSG_PUTS("\nCompiled with (+) or without (-):\n");
#ifdef AMIGA		/* only for Amiga systems */
# ifdef NO_ARP
	version_msg("-ARP ");
# else
	version_msg("+ARP ");
# endif
#endif
#ifdef AUTOCMD
	version_msg("+autocmd ");
#else
	version_msg("-autocmd ");
#endif
#ifdef NO_BUILTIN_TCAPS
	version_msg("-builtin_terms ");
#endif
#ifdef SOME_BUILTIN_TCAPS
	version_msg("+builtin_terms ");
#endif
#ifdef ALL_BUILTIN_TCAPS
	version_msg("++builtin_terms ");
#endif
#ifdef CINDENT
	version_msg("+cindent ");
#else
	version_msg("-cindent ");
#endif
#ifdef DEBUG
	version_msg("+debug ");
#endif
#ifdef DIGRAPHS
	version_msg("+digraphs ");
#else
	version_msg("-digraphs ");
#endif
#ifdef EMACS_TAGS
	version_msg("+emacs_tags ");
#else
	version_msg("-emacs_tags ");
#endif
#ifdef FKMAP
	version_msg("+farsi ");
#else
	version_msg("-farsi ");
#endif
	    /* only interesting on Unix systems */
#if !defined(USE_SYSTEM) && defined(UNIX)
	version_msg("+fork() ");
#endif
#ifdef UNIX
# ifdef USE_GUI_MOTIF
	version_msg("+GUI_Motif ");
# else
#  ifdef USE_GUI_ATHENA
	version_msg("+GUI_Athena ");
#  else
	version_msg("-GUI ");
#  endif
# endif
#endif
#ifdef INSERT_EXPAND
	version_msg("+insert_expand ");
#else
	version_msg("-insert_expand ");
#endif
#ifdef HAVE_LANGMAP
	version_msg("+langmap ");
#else
	version_msg("-langmap ");
#endif
#ifdef LISPINDENT
	version_msg("+lispindent ");
#else
	version_msg("-lispindent ");
#endif
#ifdef HAVE_PERL_INTERP
	version_msg("+perl ");
#else
	version_msg("-perl ");
#endif
#ifdef HAVE_PYTHON
	version_msg("+python ");
#else
	version_msg("-python ");
#endif
#ifdef RIGHTLEFT
	version_msg("+rightleft ");
#else
	version_msg("-rightleft ");
#endif
#ifdef SMARTINDENT
	version_msg("+smartindent ");
#else
	version_msg("-smartindent ");
#endif
	    /* only interesting on Unix systems */
#if defined(USE_SYSTEM) && (defined(UNIX) || defined(__EMX__))
	version_msg("+system() ");
#endif
#if defined(UNIX) || defined(__EMX__)
/* only unix (or OS/2 with EMX!) can have terminfo instead of termcap */
# ifdef TERMINFO
	version_msg("+terminfo ");
# else
	version_msg("-terminfo ");
# endif
#else		    /* unix always includes termcap support */
# ifdef HAVE_TGETENT
	version_msg("+tgetent ");
# else
	version_msg("-tgetent ");
# endif
#endif
#ifdef VIMINFO
	version_msg("+viminfo ");
#else
	version_msg("-viminfo ");
#endif
#ifdef WRITEBACKUP
	version_msg("+writebackup ");
#else
	version_msg("-writebackup ");
#endif
#ifdef UNIX
# if defined(WANT_X11) && defined(HAVE_X11)
	version_msg("+X11 ");
# else
	version_msg("-X11 ");
# endif
#endif
	msg_putchar('\n');
#ifdef USR_VIMRC_FILE
	version_msg("   user vimrc file: \"");
	version_msg(USR_VIMRC_FILE);
	version_msg("\" ");
#endif
#ifdef USR_EXRC_FILE
	version_msg("    user exrc file: \"");
	version_msg(USR_EXRC_FILE);
	version_msg("\" ");
#endif
#ifdef USE_GUI
	version_msg("  user gvimrc file: \"");
	version_msg(USR_GVIMRC_FILE);
	version_msg("\" ");
#endif
#ifdef SYS_VIMRC_FILE
	msg_putchar('\n');
	version_msg(" system vimrc file: \"");
	version_msg(SYS_VIMRC_FILE);
	version_msg("\"");
#endif
#ifdef USE_GUI
# ifdef SYS_GVIMRC_FILE
	msg_putchar('\n');
	version_msg("system gvimrc file: \"");
	version_msg(SYS_GVIMRC_FILE);
	MSG_PUTS("\"");
# endif
# ifdef SYS_MENU_FILE
	msg_putchar('\n');
	version_msg("  system menu file: \"");
	version_msg(SYS_MENU_FILE);
	MSG_PUTS("\"");
# endif
#endif
#ifdef HAVE_PATHDEF
	msg_putchar('\n');
	version_msg("  default for $VIM: \"");
	version_msg((char *)default_vim_dir);
	MSG_PUTS("\"\n");
	version_msg("Compilation: ");
	version_msg((char *)all_cflags);
	msg_putchar('\n');
	version_msg("Linking: ");
	version_msg((char *)all_lflags);
#endif
    }
}

/*
 * Output a string for the version message.  If it's going to wrap, output a
 * newline, unless the message is too long to fit on the screen anyway.
 */
    static void
version_msg(s)
    char	*s;
{
    int		len = strlen(s);

    if (len < (int)Columns && msg_col + len >= (int)Columns)
	msg_putchar('\n');
    MSG_PUTS(s);
}
