Subversion Repositories planix.SVN

Compare Revisions

No changes between revisions

Ignore whitespace Rev 90 → Rev 91

/ports/branches/tendra/editors/vim/files/Makefile
0,0 → 1,2932
# Makefile for Vim on Unix and Unix-like systems vim:ts=8:sw=8:tw=78
#
# This Makefile is loosely based on the GNU Makefile conventions found in
# standards.info.
#
# Compiling Vim, summary:
#
# 3. make
# 5. make install
#
# Compiling Vim, details:
#
# Edit this file for adjusting to your system. You should not need to edit any
# other file for machine specific things!
# The name of this file MUST be Makefile (note the uppercase 'M').
#
# 1. Edit this Makefile {{{1
# The defaults for Vim should work on most machines, but you may want to
# uncomment some lines or make other changes below to tune it to your
# system, compiler or preferences. Uncommenting means that the '#' in
# the first column of a line is removed.
# - If you want a version of Vim that is small and starts up quickly,
# you might want to disable the GUI, X11, Perl, Python and Tcl.
# - Uncomment the line with --disable-gui if you have Motif, GTK and/or
# Athena but don't want to make gvim (the GUI version of Vim with nice
# menus and scrollbars, but makes Vim bigger and startup slower).
# - Uncomment --disable-darwin if on Mac OS X but you want to compile a
# Unix version.
# - Uncomment the line "CONF_OPT_X = --without-x" if you have X11 but
# want to disable using X11 libraries. This speeds up starting Vim,
# but the window title will not be set and the X11 selection can not
# used.
# - Uncomment the line "CONF_OPT_XSMP = --without-xsmp" if you have the
# X11 Session Management Protocol (XSMP) library (libSM) but do not
# want to use it.
# This can speedup Vim startup but Vim loses the ability to catch the
# user logging out from session-managers like GNOME and work
# could be lost.
# - Uncomment one or more of these lines to include an interface;
# each makes Vim quite a bit bigger:
# --enable-perlinterp for Perl interpreter
# --enable-pythoninterp for Python interpreter
# --enable-rubyinterp for Ruby interpreter
# --enable-tclinterp for Tcl interpreter
# --enable-cscope for Cscope interface
# - Uncomment one of the lines with --with-features= to enable a set of
# features (but not the interfaces just mentioned).
# - Uncomment the line with --disable-acl to disable ACL support even
# though your system supports it.
# - Uncomment the line with --disable-gpm to disable gpm support
# even though you have gpm libraries and includes
# - Uncomment one of the lines with CFLAGS and/or CC if you have
# something very special or want to tune the optimizer.
# - Search for the name of your system to see if it needs anything
# special.
# - A few versions of make use '.include "file"' instead of 'include
# file'. Adjust the include line below if yours does.
#
# 2. Edit feature.h {{{1
# Only if you do not agree with the default compile features, e.g.:
# - you want Vim to be as vi compatible as it can be
# - you want to use Emacs tags files
# - you want right-to-left editing (Hebrew)
# - you want 'langmap' support (Greek)
# - you want to remove features to make Vim smaller
#
# 3. "make" {{{1
# Will first run ./configure with the options in this file. Then it will
# start make again on this Makefile to do the compiling. You can also do
# this in two steps with:
# make config
# make
# The configuration phase creates/overwrites auto/config.h and
# auto/config.mk.
# The configure script is created with "make autoconf". It can detect
# different features of your system and act accordingly. However, it is
# not correct for all systems. Check this:
# - If you have X windows, but configure could not find it or reported
# another include/library directory then you wanted to use, you have
# to set CONF_OPT_X below. You might also check the installation of
# xmkmf.
# - If you have --enable-gui=motif and have Motif on your system, but
# configure reports "checking for location of gui... <not found>", you
# have to set GUI_INC_LOC and GUI_LIB_LOC below.
# If you changed something, do this to run configure again:
# make reconfig
#
# - If you do not trust the automatic configuration code, then inspect
# auto/config.h and auto/config.mk, before starting the actual build
# phase. If possible edit this Makefile, rather than auto/config.mk --
# especially look at the definition of VIMLOC below. Note that the
# configure phase overwrites auto/config.mk and auto/config.h again.
# - If you get error messages, find out what is wrong and try to correct
# it in this Makefile. You may need to do "make reconfig" when you
# change anything that configure uses (e.g. switching from an old C
# compiler to an ANSI C compiler). Only when auto/configure does
# something wrong you may need to change one of the other files. If
# you find a clean way to fix the problem, consider sending a note to
# the author of autoconf (bug-gnu-utils@prep.ai.mit.edu) or Vim
# (Bram@vim.org). Don't bother to do that when you made a hack
# solution for a non-standard system.
#
# 4. "make test" {{{1
# This is optional. This will run Vim scripts on a number of test
# files, and compare the produced output with the expected output.
# If all is well, you will get the "ALL DONE" message in the end. See
# below (search for "/^test").
#
# 5. "make install" {{{1
# If the new Vim seems to be working OK you can install it and the
# documentation in the appropriate location. The default is
# "/usr/local". Change "prefix" below to change the location.
# "auto/pathdef.c" will be compiled again after changing this to make
# the executable know where the help files are located.
# Note that any existing executable is removed or overwritten. If you
# want to keep it you will have to make a backup copy first.
# The runtime files are in a different directory for each version. You
# might want to delete an older version.
# If you don't want to install everything, there are other targets:
# make installvim only installs Vim, not the tools
# make installvimbin only installs the Vim executable
# make installruntime installs most of the runtime files
# make installrtbase only installs the Vim help and
# runtime files
# make installlinks only installs the Vim binary links
# make installmanlinks only installs the Vim manpage links
# make installmacros only installs the Vim macros
# make installtutorbin only installs the Vim tutor program
# make installtutor only installs the Vim tutor files
# make installspell only installs the spell files
# make installtools only installs xxd
# If you install Vim, not to install for real but to prepare a package
# or RPM, set DESTDIR to the root of the tree.
#
# 6. Use Vim until a new version comes out. {{{1
#
# 7. "make uninstall_runtime" {{{1
# Will remove the runtime files for the current version. This is safe
# to use while another version is being used, only version-specific
# files will be deleted.
# To remove the runtime files of another version:
# make uninstall_runtime VIMRTDIR=/vim54
# If you want to delete all installed files, use:
# make uninstall
# Note that this will delete files that have the same name for any
# version, thus you might need to do a "make install" soon after this.
# Be careful not to remove a version of Vim that is still being used!
# To find out which files and directories will be deleted, use:
# make -n uninstall
# }}}
#
### This Makefile has been successfully tested on many systems. {{{
### Only the ones that require special options are mentioned here.
### Check the (*) column for remarks, listed below.
### Later code changes may cause small problems, otherwise Vim is supposed to
### compile and run without problems.
 
#system: configurations: version (*) tested by:
#------------- ------------------------ ------- - ----------
#AIX 3.2.5 cc (not gcc) - 4.5 (M) Will Fiveash
#AIX 4 cc +X11 -GUI 3.27 (4) Axel Kielhorn
#AIX 4.1.4 cc +X11 +GUI 4.5 (5) Nico Bakker
#AIX 4.2.1 cc 5.2k (C) Will Fiveash
#AIX 4.3.3.12 xic 3.6.6 5.6 (5) David R. Favor
#A/UX 3.1.1 gcc +X11 4.0 (6) Jim Jagielski
#BeOS PR mwcc DR3 5.0n (T) Olaf Seibert
#BSDI 2.1 (x86) shlicc2 gcc-2.6.3 -X11 X11R6 4.5 (1) Jos Backus
#BSD/OS 3.0 (x86) gcc gcc-2.7.2.1 -X11 X11R6 4.6c (1) Jos Backus
#CX/UX 6.2 cc +X11 +GUI_Mofif 5.4 (V) Kipp E. Howard
#DG/UX 5.4* gcc 2.5.8 GUI 5.0e (H) Jonas Schlein
#DG/UX 5.4R4.20 gcc 2.7.2 GUI 5.0s (H) Rocky Olive
#HP-UX (most) c89 cc 5.1 (2) Bram Moolenaar
#HP-UX_9.04 cc +X11 +Motif 5.0 (2) Carton Lao
#Irix 6.3 (O2) cc ? 4.5 (L) Edouard Poor
#Irix 6.4 cc ? 5.0m (S) Rick Sayre
#Irix 6.5 cc ? 6.0 (S) David Harrison
#Irix 64 bit 4.5 (K) Jon Wright
#Linux 2.0 gcc-2.7.2 Infomagic Motif 4.3 (3) Ronald Rietman
#Linux 2.0.31 gcc +X11 +GUI Athena 5.0w (U) Darren Hiebert
#LynxOS 3.0.1 2.9-gnupro-98r2 +X11 +GUI Athena 5.7.1(O) Lorenz Hahn
#LynxOS 3.1.0 2.9-gnupro-98r2 +X11 +GUI Athena 5.7.1(O) Lorenz Hahn
#NEC UP4800 UNIX_SV 4.2MP cc +X11R6 Motif,Athena4.6b (Q) Lennart Schultz
#NetBSD 1.0A gcc-2.4.5 -X11 -GUI 3.21 (X) Juergen Weigert
#QNX 4.2 wcc386-10.6 -X11 4.2 (D) G.F. Desrochers
#QNX 4.23 Watcom -X11 4.2 (F) John Oleynick
#SCO Unix v3.2.5 cc +X11 Motif 3.27 (C) M. Kuperblum
#SCO Open Server 5 gcc 2.7.2.3 +X11 +GUI Motif 5.3 (A) Glauber Ribeiro
#SINIX-N 5.43 RM400 R4000 cc +X11 +GUI 5.0l (I) Martin Furter
#SINIX-Z 5.42 i386 gcc 2.7.2.3 +X11 +GUI Motif 5.1 (I) Joachim Fehn
#SINIX-Y 5.43 RM600 R4000 gcc 2.7.2.3 +X11 +GUI Motif 5.1 (I) Joachim Fehn
#Reliant/SINIX 5.44 cc +X11 +GUI 5.5a (I) B. Pruemmer
#SNI Targon31 TOS 4.1.11 gcc-2.4.5 +X11 -GUI 4.6c (B) Paul Slootman
#Solaris 2.4 (Sparc) cc +X11 +GUI 3.29 (9) Glauber
#Solaris 2.4/2.5 clcc +X11 -GUI openwin 3.20 (7) Robert Colon
#Solaris 2.5 (sun4m) cc (SC4.0) +X11R6 +GUI (CDE) 4.6b (E) Andrew Large
#Solaris 2.5 cc +X11 +GUI Athena 4.2 (9) Sonia Heimann
#Solaris 2.5 gcc 2.5.6 +X11 Motif 5.0m (R) Ant. Colombo
#Solaris 2.6 gcc 2.8.1 ncursus 5.3 (G) Larry W. Virden
#Solaris with -lthread 5.5 (W) K. Nagano
#Solaris gcc (b) Riccardo
#SunOS 4.1.x +X11 -GUI 5.1b (J) Bram Moolenaar
#SunOS 4.1.3_U1 (sun4c) gcc +X11 +GUI Athena 5.0w (J) Darren Hiebert
#SUPER-UX 6.2 (NEC SX-4) cc +X11R6 Motif,Athena4.6b (P) Lennart Schultz
#Tandem/NSK (c) Matthew Woehlke
#Unisys 6035 cc +X11 Motif 5.3 (8) Glauber Ribeiro
#ESIX V4.2 cc +X11 6.0 (a) Reinhard Wobst
#Mac OS X 10.[23] gcc Carbon 6.2 (x) Bram Moolenaar
# }}}
 
# (*) Remarks: {{{
#
# (1) Uncomment line below for shlicc2
# (2) HPUX with compile problems or wrong digraphs, uncomment line below
# (3) Infomagic Motif needs GUI_LIB_LOC and GUI_INC_LOC set, see below.
# And add "-lXpm" to MOTIF_LIBS2.
# (4) For cc the optimizer must be disabled (use CFLAGS= after running
# configure) (symptom: ":set termcap" output looks weird).
# (5) Compiler may need extra argument, see below.
# (6) See below for a few lines to uncomment
# (7) See below for lines which enable the use of clcc
# (8) Needs some EXTRA_LIBS, search for Unisys below
# (9) Needs an extra compiler flag to compile gui_at_sb.c, see below.
# (A) May need EXTRA_LIBS, see below
# (B) Can't compile GUI because there is no waitpid()... Disable GUI below.
# (C) Force the use of curses instead of termcap, see below.
# (D) Uncomment lines below for QNX
# (E) You might want to use termlib instead of termcap, see below.
# (F) See below for instructions.
# (G) Using ncursus version 4.2 has reported to cause a crash. Use the
# Sun cursus library instead.
# (H) See line for EXTRA_LIBS below.
# (I) SINIX-N 5.42 and 5.43 need some EXTRA_LIBS. Also for Reliant-Unix.
# (J) If you get undefined symbols, see below for a solution.
# (K) See lines to uncomment below for machines with 64 bit pointers.
# (L) For Silicon Graphics O2 workstations remove "-lnsl" from auto/config.mk
# (M) gcc version cygnus-2.0.1 does NOT work (symptom: "dl" deletes two
# characters instead of one).
# (N) SCO with decmouse.
# (O) LynxOS needs EXTRA_LIBS, see below.
# (P) For SuperUX 6.2 on NEC SX-4 see a few lines below to uncomment.
# (Q) For UNIXSVR 4.2MP on NEC UP4800 see below for lines to uncomment.
# (R) For Solaris 2.5 (or 2.5.1) with gcc > 2.5.6, uncomment line below.
# (S) For Irix 6.x with MipsPro compiler, use -OPT:Olimit. See line below.
# (T) See ../doc/os_beos.txt.
# (U) Must uncomment CONF_OPT_PYTHON option below to disable Python
# detection, since the configure script runs into an error when it
# detects Python (probably because of the bash shell).
# (V) See lines to uncomment below.
# (X) Need to use the .include "auto/config.mk" line below
# (Y) See line with c89 below
# (Z) See lines with cc or c89 below
# (a) See line with EXTRA_LIBS below.
# (b) When using gcc with the Solaris linker, make sure you don't use GNU
# strip, otherwise the binary may not run: "Cannot find ELF".
# (c) Add -lfloss to EXTRA_LIBS, see below.
# (x) When you get warnings for precompiled header files, run
# "sudo fixPrecomps". Also see CONF_OPT_DARWIN below.
# }}}
 
 
#DO NOT CHANGE the next line, we need it for configure to find the compiler
#instead of using the default from the "make" program.
#Use a line further down to change the value for CC.
CC=cc -D_POSIX_SOURCE -D_BSD_EXTENSION
 
# Change and use these defines if configure cannot find your Motif stuff.
# Unfortunately there is no "standard" location for Motif. {{{
# These defines can contain a single directory (recommended) or a list of
# directories (for when you are working with several systems). The LAST
# directory that exists is used.
# When changed, run "make reconfig" next!
#GUI_INC_LOC = -I/usr/include/Motif2.0 -I/usr/include/Motif1.2
#GUI_LIB_LOC = -L/usr/lib/Motif2.0 -L/usr/lib/Motif1.2
### Use these two lines for Infomagic Motif (3)
#GUI_INC_LOC = -I/usr/X11R6/include
#GUI_LIB_LOC = -L/usr/X11R6/lib
# }}}
 
######################## auto/config.mk ######################## {{{1
# At this position auto/config.mk is included. When starting from the
# distribution it is almost empty. After running auto/configure it contains
# settings that have been discovered for your system. Settings below this
# include override settings in auto/config.mk!
 
# Note: if auto/config.mk is lost somehow (e.g., because configure was
# interrupted), create an empty auto/config.mk file and do "make config".
 
# (X) How to include auto/config.mk depends on the version of "make" you have,
# if the current choice doesn't work, try the other one.
 
include auto/config.mk
#.include "auto/config.mk"
CClink = $(CC)
 
#}}}
 
# Include the configuration choices first, so we can override everything
# below. As shipped, this file contains a target that causes to run
# configure. Once configure was run, this file contains a list of
# make variables with predefined values instead. Thus any second invocation
# of make, will build Vim.
 
# CONFIGURE - configure arguments {{{1
# You can give a lot of options to configure.
# Change this to your desire and do 'make config' afterwards
 
# examples (can only use one!):
#CONF_ARGS = --exec-prefix=/usr
#CONF_ARGS = --with-vim-name=vim7 --with-ex-name=ex7 --with-view-name=view7
#CONF_ARGS = --with-global-runtime=/etc/vim
 
# Use this one if you distribute a modified version of Vim.
#CONF_ARGS = --with-modified-by="John Doe"
 
# GUI - For creating Vim with GUI (gvim) (B)
# Uncomment this line when you don't want to get the GUI version, although you
# have GTK, Motif and/or Athena. Also use --without-x if you don't want X11
# at all.
#CONF_OPT_GUI = --disable-gui
 
# Uncomment one of these lines if you have that GUI but don't want to use it.
# The automatic check will use another one that can be found.
# Gnome is disabled by default, it may cause trouble.
#CONF_OPT_GUI = --disable-gtk-check
#CONF_OPT_GUI = --disable-gtk2-check
#CONF_OPT_GUI = --enable-gnome-check
#CONF_OPT_GUI = --enable-gnome2-check
#CONF_OPT_GUI = --disable-motif-check
#CONF_OPT_GUI = --disable-athena-check
#CONF_OPT_GUI = --disable-nextaw-check
 
# Uncomment one of these lines to select a specific GUI to use.
# When using "yes" or nothing, configure will use the first one found: GTK+,
# Motif or Athena.
#
# GTK versions that are known not to work 100% are rejected.
# Use "--disable-gtktest" to accept them anyway.
#
# GNOME means GTK with Gnome support. If using GTK and --enable-gnome-check
# is used then GNOME will automatically be used if it is found. If you have
# GNOME, but do not want to use it (e.g., want a GTK-only version), then use
# --enable-gui=gtk or leave out --enable-gnome-check.
#
# If the selected GUI isn't found, the GUI is disabled automatically
#CONF_OPT_GUI = --enable-gui=gtk
#CONF_OPT_GUI = --enable-gui=gtk --disable-gtktest
#CONF_OPT_GUI = --enable-gui=gtk2
#CONF_OPT_GUI = --enable-gui=gtk2 --disable-gtktest
#CONF_OPT_GUI = --enable-gui=gnome
#CONF_OPT_GUI = --enable-gui=gnome2
#CONF_OPT_GUI = --enable-gui=gnome2 --disable-gtktest
#CONF_OPT_GUI = --enable-gui=motif
#CONF_OPT_GUI = --enable-gui=motif --with-motif-lib="-static -lXm -shared"
#CONF_OPT_GUI = --enable-gui=athena
#CONF_OPT_GUI = --enable-gui=nextaw
 
# DARWIN - detecting Mac OS X
# Uncomment this line when you want to compile a Unix version of Vim on
# Darwin. None of the Mac specific options or files will be used.
#CONF_OPT_DARWIN = --disable-darwin
 
# Select the architecture supported. Default is to build for the current
# platform. Use "both" for a universal binary. That probably doesn't work
# when including Perl, Python, etc.
#CONF_OPT_DARWIN = --with-mac-arch=i386
#CONF_OPT_DARWIN = --with-mac-arch=ppc
#CONF_OPT_DARWIN = --with-mac-arch=both
 
# PERL
# Uncomment this when you want to include the Perl interface.
# The Perl option sometimes causes problems, because it adds extra flags
# to the command line. If you see strange flags during compilation, check in
# auto/config.mk where they come from. If it's PERL_CFLAGS, try commenting
# the next line.
# When you get an error for a missing "perl.exp" file, try creating an emtpy
# one: "touch perl.exp".
# This requires at least "small" features, "tiny" doesn't work.
#CONF_OPT_PERL = --enable-perlinterp
 
# PYTHON
# Uncomment this when you want to include the Python interface.
# NOTE: This may cause threading to be enabled, which has side effects (such
# as using different libraries and debugging becomes more difficult).
# NOTE: Using this together with Perl may cause a crash in initialization.
#CONF_OPT_PYTHON = --enable-pythoninterp
 
# TCL
# Uncomment this when you want to include the Tcl interface.
#CONF_OPT_TCL = --enable-tclinterp
#CONF_OPT_TCL = --enable-tclinterp --with-tclsh=tclsh8.4
 
# RUBY
# Uncomment this when you want to include the Ruby interface.
#CONF_OPT_RUBY = --enable-rubyinterp
 
# MZSCHEME
# Uncomment this when you want to include the MzScheme interface.
#CONF_OPT_MZSCHEME = --enable-mzschemeinterp
# PLT/mrscheme/drscheme Home dir; the PLTHOME environment variable also works
#CONF_OPT_PLTHOME = --with-plthome=/usr/local/plt
#CONF_OPT_PLTHOME = --with-plthome=/usr/local/drscheme
#CONF_OPT_PLTHOME = --with-plthome=/home/me/mz
 
# CSCOPE
# Uncomment this when you want to include the Cscope interface.
#CONF_OPT_CSCOPE = --enable-cscope
 
# WORKSHOP - Sun Visual Workshop interface. Only works with Motif!
#CONF_OPT_WORKSHOP = --enable-workshop
 
# NETBEANS - NetBeans interface. Only works with Motif, GTK, and gnome.
# Motif version must have XPM libraries (see |workshop-xpm|).
# Uncomment this when you do not want the netbeans interface.
#CONF_OPT_NETBEANS = --disable-netbeans
 
# SNIFF - Include support for SNiFF+.
#CONF_OPT_SNIFF = --enable-sniff
 
# MULTIBYTE - To edit multi-byte characters.
# Uncomment this when you want to edit a multibyte language.
# It's automatically enabled with big features or IME support.
# Note: Compile on a machine where setlocale() actually works, otherwise the
# configure tests may fail.
#CONF_OPT_MULTIBYTE = --enable-multibyte
 
# NLS - National Language Support
# Uncomment this when you do not want to support translated messages, even
# though configure can find support for it.
#CONF_OPT_NLS = --disable-nls
 
# XIM - X Input Method. Special character input support for X11 (Chinese,
# Japanese, special symbols, etc). Also needed for dead-key support.
# When omitted it's automatically enabled for the X-windows GUI.
# HANGUL - Input Hangul (Korean) language using internal routines.
# Uncomment one of these when you want to input a multibyte language.
#CONF_OPT_INPUT = --enable-xim
#CONF_OPT_INPUT = --disable-xim
#CONF_OPT_INPUT = --enable-hangulinput
 
# FONTSET - X fontset support for output of languages with many characters.
# Uncomment this when you want to output a multibyte language.
#CONF_OPT_OUTPUT = --enable-fontset
 
# ACL - Uncomment this when you do not want to include ACL support, even
# though your system does support it. E.g., when it's buggy.
#CONF_OPT_ACL = --disable-acl
 
# gpm - For mouse support on Linux console via gpm
# Uncomment this when you do not want to include gpm support, even
# though you have gpm libraries and includes
#CONF_OPT_GPM = --disable-gpm
 
# FEATURES - For creating Vim with more or less features
# Uncomment one of these lines when you want to include few to many features.
# The default is "normal".
#CONF_OPT_FEAT = --with-features=tiny
#CONF_OPT_FEAT = --with-features=small
#CONF_OPT_FEAT = --with-features=normal
#CONF_OPT_FEAT = --with-features=big
#CONF_OPT_FEAT = --with-features=huge
 
# COMPILED BY - For including a specific e-mail address for ":version".
#CONF_OPT_COMPBY = "--with-compiledby=John Doe <JohnDoe@yahoo.com>"
 
# X WINDOWS DISABLE - For creating a plain Vim without any X11 related fancies
# (otherwise Vim configure will try to include xterm titlebar access)
# Also disable the GUI above, otherwise it will be included anyway.
# When both GUI and X11 have been disabled this may save about 15% of the
# code and make Vim startup quicker.
#CONF_OPT_X = --without-x
 
# X WINDOWS DIRECTORY - specify X directories
# If configure can't find you X stuff, or if you have multiple X11 derivatives
# installed, you may wish to specify which one to use.
# Select nothing to let configure choose.
# This here selects openwin (as found on sun).
#XROOT = /usr/openwin
#CONF_OPT_X = --x-include=$(XROOT)/include --x-libraries=$(XROOT)/lib
 
# X11 Session Management Protocol support
# Vim will try to use XSMP to catch the user logging out if there are unsaved
# files. Uncomment this line to disable that (it prevents vim trying to open
# communications with the session manager).
#CONF_OPT_XSMP = --disable-xsmp
 
# You may wish to include xsmp but use exclude xsmp-interact if the logout
# XSMP functionality does not work well with your session-manager (at time of
# writing, this would be early GNOME-1 gnome-session: it 'freezes' other
# applications after Vim has cancelled a logout (until Vim quits). This
# *might* be the Vim code, but is more likely a bug in early GNOME-1.
# This disables the dialog that asks you if you want to save files or not.
#CONF_OPT_XSMP = --disable-xsmp-interact
 
# COMPILER - Name of the compiler {{{1
# The default from configure will mostly be fine, no need to change this, just
# an example. If a compiler is defined here, configure will use it rather than
# probing for one. It is dangerous to change this after configure was run.
# Make will use your choice then -- but beware: Many things may change with
# another compiler. It is wise to run 'make reconfig' to start all over
# again.
#CC = cc
#CC = gcc
CC = cc -D_POSIX_SOURCE -D_PLAN9_SOURCE -D_BSD_EXTENSION -g
 
# COMPILER FLAGS - change as you please. Either before running {{{1
# configure or afterwards. For examples see below.
# When using -g with some older versions of Linux you might get a
# statically linked executable.
# When not defined, configure will try to use -O2 -g for gcc and -O for cc.
#CFLAGS = -g
#CFLAGS = -O
#CFLAGS = -D_BSD_EXTENSION
 
# Optimization limits - depends on the compiler. Automatic check in configure
# doesn't work very well, because many compilers only give a warning for
# unrecognized arguments.
#CFLAGS = -O -OPT:Olimit=2600
#CFLAGS = -O -Olimit 2000
#CFLAGS = -O -FOlimit,2000
 
# Often used for GCC: mixed optimizing, lot of optimizing, debugging
#CFLAGS = -g -O2 -fno-strength-reduce -Wall -Wshadow -Wmissing-prototypes
#CFLAGS = -g -O2 -fno-strength-reduce -Wall -Wmissing-prototypes
#CFLAGS = -g -Wall -Wmissing-prototypes
#CFLAGS = -O6 -fno-strength-reduce -Wall -Wshadow -Wmissing-prototypes
#CFLAGS = -g -DDEBUG -Wall -Wshadow -Wmissing-prototypes
#CFLAGS = -g -O2 '-DSTARTUPTIME="vimstartup"' -fno-strength-reduce -Wall -Wmissing-prototypes
 
# EFENCE - Electric-Fence malloc debugging: catches memory accesses beyond
# allocated memory (and makes every malloc()/free() very slow).
# Electric Fence is free (search ftp sites).
# You may want to set the EF_PROTECT_BELOW environment variable to check the
# other side of allocated memory.
# On FreeBSD you might need to enlarge the number of mmaps allowed. Do this
# as root: sysctl -w vm.max_proc_mmap=30000
#EXTRA_LIBS = /usr/local/lib/libefence.a
 
# PURIFY - remove the # to use the "purify" program (hoi Nia++!)
#PURIFY = purify
# }}}
 
# LINT - for running lint
LINT_OPTIONS = -beprxzF
 
# PROFILING - Uncomment the next two lines to do profiling with gcc and gprof.
# Might not work with GUI or Perl.
# For unknown reasons adding "-lc" fixes a linking problem with GCC. That's
# probably a bug in the "-pg" implementation.
# Need to recompile everything after changing this: "make clean" "make".
#PROFILE_CFLAGS = -pg -g
#PROFILE_LIBS = -pg
#PROFILE_LIBS = -pg -lc
 
# MEMORY LEAK DETECTION
# Requires installing the ccmalloc library.
# Configuration is in the .ccmalloc or ~/.ccmalloc file.
# Doesn't work very well, since memory linked to from global variables
# (in libraries) is also marked as leaked memory.
#PROFILE_CFLAGS = -DEXITFREE
#PROFILE_LIBS = -lccmalloc
 
#####################################################
### Specific systems, check if yours is listed! ### {{{
#####################################################
 
### Uncomment things here only if the values chosen by configure are wrong.
### It's better to adjust configure.in and "make autoconf", if you can!
### Then send the required changes to configure.in to the bugs list.
 
### (1) BSD/OS 2.0.1, 2.1 or 3.0 using shared libraries
###
#CC = shlicc2
#CFLAGS = -O2 -g -m486 -Wall -Wshadow -Wmissing-prototypes -fno-builtin
 
### (2) HP-UX with a non-ANSI cc, use the c89 ANSI compiler
### The first probably works on all systems
### The second should work a bit better on newer systems
### The third should work a bit better on HPUX 11.11
### Information provided by: Richard Allen <ra@rhi.hi.is>
#CC = c89 -D_HPUX_SOURCE
#CC = c89 -O +Onolimit +ESlit -D_HPUX_SOURCE
#CC = c89 -O +Onolimit +ESlit +e -D_HPUX_SOURCE
 
### (2) For HP-UX: Enable the use of a different set of digraphs. Use this
### when the default (ISO) digraphs look completely wrong.
### After changing this do "touch digraph.c; make".
#EXTRA_DEFS = -DHPUX_DIGRAPHS
 
### (2) For HP-UX: 9.04 cpp default macro definition table of 128000 bytes
### is too small to compile many routines. It produces too much defining
### and no space errors.
### Uncomment the following to specify a larger macro definition table.
#CFLAGS = -Wp,-H256000
 
### (2) For HP-UX 10.20 using the HP cc, with X11R6 and Motif 1.2, with
### libraries in /usr/lib instead of /lib (avoiding transition links).
### Information provided by: David Green
#XROOT = /usr
#CONF_OPT_X = --x-include=$(XROOT)/include/X11R6 --x-libraries=$(XROOT)/lib/X11R6
#GUI_INC_LOC = -I/usr/include/Motif1.2
#GUI_LIB_LOC = -L/usr/lib/Motif1.2_R6
 
### (5) AIX 4.1.4 with cc
#CFLAGS = -O -qmaxmem=8192
 
### AIX with c89 (Walter Briscoe)
#CC = c89
#CPPFLAGS = -D_ALL_SOURCE
 
### AIX 4.3.3.12 with xic 3.6.6 (David R. Favor)
# needed to avoid a problem where strings.h gets included
#CFLAGS = -qsrcmsg -O2 -qmaxmem=8192 -D__STR31__
 
### (W) Solaris with multi-threaded libraries (-lthread):
### If suspending doesn't work properly, try using this line:
#EXTRA_DEFS = -D_REENTRANT
 
### (7) Solaris 2.4/2.5 with Centerline compiler
#CC = clcc
#X_LIBS_DIR = -L/usr/openwin/lib -R/usr/openwin/lib
#CFLAGS = -O
 
### (9) Solaris 2.x with cc (SunPro), using Athena.
### Only required for compiling gui_at_sb.c.
### Symptom: "identifier redeclared: vim_XawScrollbarSetThumb"
### Use one of the lines (either Full ANSI or no ANSI at all)
#CFLAGS = $(CFLAGS) -Xc
#CFLAGS = $(CFLAGS) -Xs
 
### Solaris 2.3 with X11 and specific cc
#CC=/opt/SUNWspro/bin/cc -O -Xa -v -R/usr/openwin/lib
 
### Solaris with /usr/ucb/cc (it is rejected by autoconf as "cc")
#CC = /usr/ucb/cc
#EXTRA_LIBS = -R/usr/ucblib
 
### Solaris with Forte Developer and FEAT_SUN_WORKSHOP
# The Xpm library is available from http://koala.ilog.fr/ftp/pub/xpm.
#CC = cc
#XPM_DIR = /usr/local/xpm/xpm-3.4k-solaris
#XPM_LIB = -L$(XPM_DIR)/lib -R$(XPM_DIR)/lib -lXpm
#XPM_IPATH = -I$(XPM_DIR)/include
#EXTRA_LIBS = $(XPM_LIB)
#EXTRA_IPATHS = $(XPM_IPATH)
#EXTRA_DEFS = -xCC -DHAVE_X11_XPM_H
 
### Solaris with workshop compilers: Vim is unstable when compiled with
# "-fast". Use this instead. (Shea Martin)
#CFLAGS = -x02 -xtarget=ultra
 
### (R) for Solaris 2.5 (or 2.5.1) with gcc > 2.5.6 you might need this:
#LDFLAGS = -lw -ldl -lXmu
#GUI_LIB_LOC = -L/usr/local/lib
 
### (8) Unisys 6035 (Glauber Ribeiro)
#EXTRA_LIBS = -lnsl -lsocket -lgen
 
### When builtin functions cause problems with gcc (for Sun 4.1.x)
#CFLAGS = -O2 -Wall -traditional -Wno-implicit
 
### Apollo DOMAIN (with SYSTYPE = bsd4.3) (TESTED for version 3.0)
#EXTRA_DEFS = -DDOMAIN
#CFLAGS= -O -A systype,bsd4.3
 
### Coherent 4.2.10 on Intel 386 platform
#EXTRA_DEFS = -Dvoid=int
#EXTRA_LIBS = -lterm -lsocket
 
### SCO 3.2, with different library name for terminfo
#EXTRA_LIBS = -ltinfo
 
### UTS2 for Amdahl UTS 2.1.x
#EXTRA_DEFS = -DUTS2
#EXTRA_LIBS = -lsocket
 
### UTS4 for Amdahl UTS 4.x
#EXTRA_DEFS = -DUTS4 -Xa
 
### USL for Unix Systems Laboratories (SYSV 4.2)
#EXTRA_DEFS = -DUSL
 
### RISCos on MIPS without X11
#EXTRA_DEFS = -DMIPS
 
### RISCos on MIPS with X11
#EXTRA_LIBS = -lsun
 
### (6) A/UX 3.1.1 with gcc (Jim Jagielski)
#CC= gcc -D_POSIX_SOURCE
#CFLAGS= -O2
#EXTRA_LIBS = -lposix -lbsd -ltermcap -lX11
 
### (A) Some versions of SCO Open Server 5 (Jan Christiaan van Winkel)
### Also use the CONF_TERM_LIB below!
#EXTRA_LIBS = -lgen
 
### (D) QNX (by G.F. Desrochers)
#CFLAGS = -g -O -mf -4
 
### (F) QNX (by John Oleynick)
# 1. If you don't have an X server: Comment out CONF_OPT_GUI and uncomment
# CONF_OPT_X = --without-x.
# 2. make config
# 3. edit auto/config.mk and remove -ldir and -ltermcap from LIBS. It doesn't
# have -ldir (does config find it somewhere?) and -ltermcap has at
# least one problem so I use termlib.o instead. The problem with
# termcap is that it segfaults if you call it with the name of
# a non-existent terminal type.
# 4. edit auto/config.h and add #define USE_TMPNAM
# 5. add termlib.o to OBJ
# 6. make
 
### (H) for Data general DG/UX 5.4.2 and 5.4R3.10 (Jonas J. Schlein)
#EXTRA_LIBS = -lgen
 
### (I) SINIX-N 5.42 or 5.43 RM400 R4000 (also SINIX-Y and SINIX-Z)
#EXTRA_LIBS = -lgen -lnsl
### For SINIX-Y this is needed for the right prototype of gettimeofday()
#EXTRA_DEFS = -D_XPG_IV
 
### (I) Reliant-Unix (aka SINIX) 5.44 with standard cc
# Use both "-F O3" lines for optimization or the "-g" line for debugging
#EXTRA_LIBS = -lgen -lsocket -lnsl -lSM -lICE
#CFLAGS = -F O3 -DSINIXN
#LDFLAGS = -F O3
#CFLAGS = -g -DSINIXN
 
### (P) SCO 3.2.42, with different termcap names for some useful keys DJB
#EXTRA_DEFS = -DSCOKEYS -DNETTERM_MOUSE -DDEC_MOUSE -DXTERM_MOUSE -DHAVE_GETTIMEOFDAY
#EXTRA_LIBS = -lsocket -ltermcap -lmalloc -lc_s
 
### (P) SuperUX 6.2 on NEC SX-4 (Lennart Schultz)
#GUI_INC_LOC = -I/usr/include
#GUI_LIB_LOC = -L/usr/lib
#EXTRA_LIBS = -lgen
 
### (Q) UNIXSVR 4.2MP on NEC UP4800 (Lennart Schultz)
#GUI_INC_LOC = -I/usr/necccs/include
#GUI_LIB_LOC = -L/usr/necccs/lib/X11R6
#XROOT = /usr/necccs
#CONF_OPT_X = --x-include=$(XROOT)/include --x-libraries=$(XROOT)/lib/X11R6
#EXTRA_LIBS = -lsocket -lgen
 
### Irix 4.0 & 5.2 (Silicon Graphics Machines, __sgi will be defined)
# Not needed for Irix 5.3, Ives Aerts reported
#EXTRA_LIBS = -lmalloc -lc_s
# Irix 4.0, when regexp and regcmp cannot be found when linking:
#EXTRA_LIBS = -lmalloc -lc_s -lPW
 
### (S) Irix 6.x (MipsPro compiler): Uses different Olimit flag:
# Note: This newer option style is used with the MipsPro compilers ONLY if
# you are compiling an "n32" or "64" ABI binary (use either a -n32
# flag or a -64 flag for CFLAGS). If you explicitly use a -o32 flag,
# then the CFLAGS option format will be the typical style (i.e.
# -Olimit 3000).
#CFLAGS = -OPT:Olimit=3000 -O
 
### (S) Irix 6.5 with MipsPro C compiler. Try this as a test to see new
# compiler features! Beware, the optimization is EXTREMELY thorough
# and takes quite a long time.
# Note: See the note above. Here, the -mips3 option automatically
# enables either the "n32" or "64" ABI, depending on what machine you
# are compiling on (n32 is explicitly enabled here, just to make sure).
#CFLAGS = -OPT:Olimit=3500 -O -n32 -mips3 -IPA:aggr_cprop=ON -INLINE:dfe=ON:list=ON:must=screen_char,out_char,ui_write,out_flush
#LDFLAGS= -OPT:Olimit=3500 -O -n32 -mips3 -IPA:aggr_cprop=ON -INLINE:dfe=ON:list=ON:must=screen_char,out_char,ui_write,out_flush
 
### (K) for SGI Irix machines with 64 bit pointers ("uname -s" says IRIX64)
### Suggested by Jon Wright <jon@gate.sinica.edu.tw>.
### Tested on R8000 IRIX6.1 Power Indigo2.
### Check /etc/compiler.defaults for your compiler settings.
# either (for 64 bit pointers) uncomment the following line
#GUI_LIB_LOC = -L/usr/lib64
# then
# 1) make config
# 2) edit auto/config.mk and delete the -lelf entry in the LIBS line
# 3) make
#
# or (for 32bit pointers) uncomment the following line
#EXTRA_DEFS = -n32
#GUI_LIB_LOC = -L/usr/lib32
# then
# 1) make config
# 2) edit auto/config.mk, add -n32 to LDFLAGS
# 3) make
###
 
### (C) On SCO Unix v3.2.5 (and probably other versions) the termcap library,
### which is found by configure, doesn't work correctly. Symptom is the
### error message "Termcap entry too long". Uncomment the next line.
### On AIX 4.2.1 (and other versions probably), libtermcap is reported
### not to display properly.
### after changing this, you need to do "make reconfig".
#CONF_TERM_LIB = --with-tlib=curses
 
### (E) If you want to use termlib library instead of the automatically found
### one. After changing this, you need to do "make reconfig".
#CONF_TERM_LIB = --with-tlib=termlib
 
### (a) ESIX V4.2 (Reinhard Wobst)
#EXTRA_LIBS = -lnsl -lsocket -lgen -lXIM -lXmu -lXext
 
### (c) Tandem/NSK (Matthew Woehlke)
#EXTRA_LIBS = -lfloss
 
### If you want to use ncurses library instead of the automatically found one
### after changing this, you need to do "make reconfig".
#CONF_TERM_LIB = --with-tlib=ncurses
 
### For GCC on MSDOS, the ".exe" suffix will be added.
#EXEEXT = .exe
#LNKEXT = .exe
 
### (O) For LynxOS 2.5.0, tested on PC.
#EXTRA_LIBS = -lXext -lSM -lICE -lbsd
### For LynxOS 3.0.1, tested on PPC
#EXTRA_LIBS= -lXext -lSM -lICE -lnetinet -lXmu -liberty -lX11
### For LynxOS 3.1.0, tested on PC
#EXTRA_LIBS= -lXext -lSM -lICE -lnetinet -lXmu
 
 
### (V) For CX/UX 6.2 (on Harris/Concurrent NightHawk 4800, 5800). Remove
### -Qtarget if only in a 5800 environment. (Kipp E. Howard)
#CFLAGS = -O -Qtarget=m88110compat
#EXTRA_LIBS = -lgen
 
##################### end of system specific lines ################### }}}
 
### Names of the programs and targets {{{1
VIMTARGET = $(VIMNAME)$(EXEEXT)
EXTARGET = $(EXNAME)$(LNKEXT)
VIEWTARGET = $(VIEWNAME)$(LNKEXT)
GVIMNAME = g$(VIMNAME)
GVIMTARGET = $(GVIMNAME)$(LNKEXT)
GVIEWNAME = g$(VIEWNAME)
GVIEWTARGET = $(GVIEWNAME)$(LNKEXT)
RVIMNAME = r$(VIMNAME)
RVIMTARGET = $(RVIMNAME)$(LNKEXT)
RVIEWNAME = r$(VIEWNAME)
RVIEWTARGET = $(RVIEWNAME)$(LNKEXT)
RGVIMNAME = r$(GVIMNAME)
RGVIMTARGET = $(RGVIMNAME)$(LNKEXT)
RGVIEWNAME = r$(GVIEWNAME)
RGVIEWTARGET = $(RGVIEWNAME)$(LNKEXT)
VIMDIFFNAME = $(VIMNAME)diff
GVIMDIFFNAME = g$(VIMDIFFNAME)
VIMDIFFTARGET = $(VIMDIFFNAME)$(LNKEXT)
GVIMDIFFTARGET = $(GVIMDIFFNAME)$(LNKEXT)
EVIMNAME = e$(VIMNAME)
EVIMTARGET = $(EVIMNAME)$(LNKEXT)
EVIEWNAME = e$(VIEWNAME)
EVIEWTARGET = $(EVIEWNAME)$(LNKEXT)
 
### Names of the tools that are also made {{{1
TOOLS = xxd/xxd$(EXEEXT)
 
### Installation directories. The defaults come from configure. {{{1
#
### prefix the top directory for the data (default "/usr/local")
#
# Uncomment the next line to install Vim in your home directory.
#prefix = $(HOME)
 
### exec_prefix is the top directory for the executable (default $(prefix))
#
# Uncomment the next line to install the Vim executable in "/usr/machine/bin"
#exec_prefix = /usr/machine
 
### BINDIR dir for the executable (default "$(exec_prefix)/bin")
### MANDIR dir for the manual pages (default "$(prefix)/man")
### DATADIR dir for the other files (default "$(prefix)/lib" or
# "$(prefix)/share")
# They may be different when using different architectures for the
# executable and a common directory for the other files.
#
# Uncomment the next line to install Vim in "/usr/bin"
#BINDIR = /usr/bin
# Uncomment the next line to install Vim manuals in "/usr/share/man/man1"
#MANDIR = /usr/share/man
# Uncomment the next line to install Vim help files in "/usr/share/vim"
#DATADIR = /usr/share
 
### DESTDIR root of the installation tree. This is prepended to the other
# directories. This directory must exist.
#DESTDIR = ~/pkg/vim
 
### Directory of the man pages
MAN1DIR = /man1
 
### Vim version (adjusted by a script)
VIMMAJOR = 7
VIMMINOR = 1
 
### Location of Vim files (should not need to be changed, and {{{1
### some things might not work when they are changed!)
VIMDIR = /vim
VIMRTDIR = /vim$(VIMMAJOR)$(VIMMINOR)
HELPSUBDIR = /doc
COLSUBDIR = /colors
SYNSUBDIR = /syntax
INDSUBDIR = /indent
AUTOSUBDIR = /autoload
PLUGSUBDIR = /plugin
FTPLUGSUBDIR = /ftplugin
LANGSUBDIR = /lang
COMPSUBDIR = /compiler
KMAPSUBDIR = /keymap
MACROSUBDIR = /macros
TOOLSSUBDIR = /tools
TUTORSUBDIR = /tutor
SPELLSUBDIR = /spell
PRINTSUBDIR = /print
PODIR = po
 
### VIMLOC common root of the Vim files (all versions)
### VIMRTLOC common root of the runtime Vim files (this version)
### VIMRCLOC compiled-in location for global [g]vimrc files (all versions)
### VIMRUNTIMEDIR compiled-in location for runtime files (optional)
### HELPSUBLOC location for help files
### COLSUBLOC location for colorscheme files
### SYNSUBLOC location for syntax files
### INDSUBLOC location for indent files
### AUTOSUBLOC location for standard autoload files
### PLUGSUBLOC location for standard plugin files
### FTPLUGSUBLOC location for ftplugin files
### LANGSUBLOC location for language files
### COMPSUBLOC location for compiler files
### KMAPSUBLOC location for keymap files
### MACROSUBLOC location for macro files
### TOOLSSUBLOC location for tools files
### TUTORSUBLOC location for tutor files
### SPELLSUBLOC location for spell files
### PRINTSUBLOC location for PostScript files (prolog, latin1, ..)
### SCRIPTLOC location for script files (menu.vim, bugreport.vim, ..)
### You can override these if you want to install them somewhere else.
### Edit feature.h for compile-time settings.
VIMLOC = $(DATADIR)$(VIMDIR)
VIMRTLOC = $(DATADIR)$(VIMDIR)$(VIMRTDIR)
VIMRCLOC = $(VIMLOC)
HELPSUBLOC = $(VIMRTLOC)$(HELPSUBDIR)
COLSUBLOC = $(VIMRTLOC)$(COLSUBDIR)
SYNSUBLOC = $(VIMRTLOC)$(SYNSUBDIR)
INDSUBLOC = $(VIMRTLOC)$(INDSUBDIR)
AUTOSUBLOC = $(VIMRTLOC)$(AUTOSUBDIR)
PLUGSUBLOC = $(VIMRTLOC)$(PLUGSUBDIR)
FTPLUGSUBLOC = $(VIMRTLOC)$(FTPLUGSUBDIR)
LANGSUBLOC = $(VIMRTLOC)$(LANGSUBDIR)
COMPSUBLOC = $(VIMRTLOC)$(COMPSUBDIR)
KMAPSUBLOC = $(VIMRTLOC)$(KMAPSUBDIR)
MACROSUBLOC = $(VIMRTLOC)$(MACROSUBDIR)
TOOLSSUBLOC = $(VIMRTLOC)$(TOOLSSUBDIR)
TUTORSUBLOC = $(VIMRTLOC)$(TUTORSUBDIR)
SPELLSUBLOC = $(VIMRTLOC)$(SPELLSUBDIR)
PRINTSUBLOC = $(VIMRTLOC)$(PRINTSUBDIR)
SCRIPTLOC = $(VIMRTLOC)
 
### Only set VIMRUNTIMEDIR when VIMRTLOC is set to a different location and
### the runtime directory is not below it.
#VIMRUNTIMEDIR = $(VIMRTLOC)
 
### Name of the evim file target.
EVIM_FILE = $(DESTDIR)$(SCRIPTLOC)/evim.vim
MSWIN_FILE = $(DESTDIR)$(SCRIPTLOC)/mswin.vim
 
### Name of the menu file target.
SYS_MENU_FILE = $(DESTDIR)$(SCRIPTLOC)/menu.vim
SYS_SYNMENU_FILE = $(DESTDIR)$(SCRIPTLOC)/synmenu.vim
SYS_DELMENU_FILE = $(DESTDIR)$(SCRIPTLOC)/delmenu.vim
 
### Name of the bugreport file target.
SYS_BUGR_FILE = $(DESTDIR)$(SCRIPTLOC)/bugreport.vim
 
### Name of the file type detection file target.
SYS_FILETYPE_FILE = $(DESTDIR)$(SCRIPTLOC)/filetype.vim
 
### Name of the file type detection file target.
SYS_FTOFF_FILE = $(DESTDIR)$(SCRIPTLOC)/ftoff.vim
 
### Name of the file type detection script file target.
SYS_SCRIPTS_FILE = $(DESTDIR)$(SCRIPTLOC)/scripts.vim
 
### Name of the ftplugin-on file target.
SYS_FTPLUGIN_FILE = $(DESTDIR)$(SCRIPTLOC)/ftplugin.vim
 
### Name of the ftplugin-off file target.
SYS_FTPLUGOF_FILE = $(DESTDIR)$(SCRIPTLOC)/ftplugof.vim
 
### Name of the indent-on file target.
SYS_INDENT_FILE = $(DESTDIR)$(SCRIPTLOC)/indent.vim
 
### Name of the indent-off file target.
SYS_INDOFF_FILE = $(DESTDIR)$(SCRIPTLOC)/indoff.vim
 
### Name of the option window script file target.
SYS_OPTWIN_FILE = $(DESTDIR)$(SCRIPTLOC)/optwin.vim
 
# Program to install the program in the target directory. Could also be "mv".
INSTALL_PROG = cp
 
# Program to install the data in the target directory. Cannot be "mv"!
INSTALL_DATA = cp
INSTALL_DATA_R = cp -r
 
### Program to run on installed binary
#STRIP = strip
 
### Permissions for binaries {{{1
BINMOD = 755
 
### Permissions for man page
MANMOD = 644
 
### Permissions for help files
HELPMOD = 644
 
### Permissions for Perl and shell scripts
SCRIPTMOD = 755
 
### Permission for Vim script files (menu.vim, bugreport.vim, ..)
VIMSCRIPTMOD = 644
 
### Permissions for all directories that are created
DIRMOD = 755
 
### Permissions for all other files that are created
FILEMOD = 644
 
# Where to copy the man and help files from
HELPSOURCE = ../runtime/doc
 
# Where to copy the script files from (menu, bugreport)
SCRIPTSOURCE = ../runtime
 
# Where to copy the colorscheme files from
COLSOURCE = ../runtime/colors
 
# Where to copy the syntax files from
SYNSOURCE = ../runtime/syntax
 
# Where to copy the indent files from
INDSOURCE = ../runtime/indent
 
# Where to copy the standard plugin files from
AUTOSOURCE = ../runtime/autoload
 
# Where to copy the standard plugin files from
PLUGSOURCE = ../runtime/plugin
 
# Where to copy the ftplugin files from
FTPLUGSOURCE = ../runtime/ftplugin
 
# Where to copy the macro files from
MACROSOURCE = ../runtime/macros
 
# Where to copy the tools files from
TOOLSSOURCE = ../runtime/tools
 
# Where to copy the tutor files from
TUTORSOURCE = ../runtime/tutor
 
# Where to copy the spell files from
SPELLSOURCE = ../runtime/spell
 
# Where to look for language specific files
LANGSOURCE = ../runtime/lang
 
# Where to look for compiler files
COMPSOURCE = ../runtime/compiler
 
# Where to look for keymap files
KMAPSOURCE = ../runtime/keymap
 
# Where to look for print resource files
PRINTSOURCE = ../runtime/print
 
# If you are using Linux, you might want to use this to make vim the
# default vi editor, it will create a link from vi to Vim when doing
# "make install". An existing file will be overwritten!
# When not using it, some make programs can't handle an undefined $(LINKIT).
#LINKIT = -ln -f -s $(BINDIR)/$(VIMTARGET) /usr/bin/vi
LINKIT = @echo >/dev/null
 
###
### GRAPHICAL USER INTERFACE (GUI). {{{1
### 'configure --enable-gui' can enable one of these for you if you did set
### a corresponding CONF_OPT_GUI above and have X11.
### Override configures choice by uncommenting all the following lines.
### As they are, the GUI is disabled. Replace "NONE" with "ATHENA" or "MOTIF"
### for enabling the Athena or Motif GUI.
#GUI_SRC = $(NONE_SRC)
#GUI_OBJ = $(NONE_OBJ)
#GUI_DEFS = $(NONE_DEFS)
#GUI_IPATH = $(NONE_IPATH)
#GUI_LIBS_DIR = $(NONE_LIBS_DIR)
#GUI_LIBS1 = $(NONE_LIBS1)
#GUI_LIBS2 = $(NONE_LIBS2)
#GUI_INSTALL = $(NONE_INSTALL)
#GUI_TARGETS = $(NONE_TARGETS)
#GUI_MAN_TARGETS= $(NONE_MAN_TARGETS)
#GUI_TESTTARGET = $(NONE_TESTTARGET)
#GUI_BUNDLE = $(NONE_BUNDLE)
 
# Without a GUI install the normal way.
NONE_INSTALL = install_normal
 
### GTK GUI
GTK_SRC = gui.c gui_gtk.c gui_gtk_x11.c pty.c gui_gtk_f.c \
gui_beval.c
GTK_OBJ = objects/gui.o objects/gui_gtk.o objects/gui_gtk_x11.o \
objects/pty.o objects/gui_gtk_f.o \
objects/gui_beval.o
GTK_DEFS = -DFEAT_GUI_GTK $(NARROW_PROTO)
GTK_IPATH = $(GUI_INC_LOC)
GTK_LIBS_DIR = $(GUI_LIB_LOC)
GTK_LIBS1 =
GTK_LIBS2 = $(GTK_LIBNAME)
GTK_INSTALL = install_normal
GTK_TARGETS = installglinks
GTK_MAN_TARGETS = yes
GTK_TESTTARGET = gui
GTK_BUNDLE =
 
### Motif GUI
MOTIF_SRC = gui.c gui_motif.c gui_x11.c pty.c gui_beval.c \
gui_xmdlg.c gui_xmebw.c
MOTIF_OBJ = objects/gui.o objects/gui_motif.o objects/gui_x11.o \
objects/pty.o objects/gui_beval.o \
objects/gui_xmdlg.o objects/gui_xmebw.o
MOTIF_DEFS = -DFEAT_GUI_MOTIF $(NARROW_PROTO)
MOTIF_IPATH = $(GUI_INC_LOC)
MOTIF_LIBS_DIR = $(GUI_LIB_LOC)
MOTIF_LIBS1 =
MOTIF_LIBS2 = $(MOTIF_LIBNAME) -lXt
MOTIF_INSTALL = install_normal
MOTIF_TARGETS = installglinks
MOTIF_MAN_TARGETS = yes
MOTIF_TESTTARGET = gui
MOTIF_BUNDLE =
 
### Athena GUI
### Use Xaw3d to make the menus look a little bit nicer
#XAW_LIB = -lXaw3d
XAW_LIB = -lXaw
 
### When using Xaw3d, uncomment/comment the following lines to also get the
### scrollbars from Xaw3d.
#ATHENA_SRC = gui.c gui_athena.c gui_x11.c pty.c gui_beval.c gui_at_fs.c
#ATHENA_OBJ = objects/gui.o objects/gui_athena.o objects/gui_x11.o \
# objects/pty.o objects/gui_beval.o objects/gui_at_fs.o
#ATHENA_DEFS = -DFEAT_GUI_ATHENA $(NARROW_PROTO) \
# -Dvim_scrollbarWidgetClass=scrollbarWidgetClass \
# -Dvim_XawScrollbarSetThumb=XawScrollbarSetThumb
ATHENA_SRC = gui.c gui_athena.c gui_x11.c pty.c gui_beval.c \
gui_at_sb.c gui_at_fs.c
ATHENA_OBJ = objects/gui.o objects/gui_athena.o objects/gui_x11.o \
objects/pty.o objects/gui_beval.o \
objects/gui_at_sb.o objects/gui_at_fs.o
ATHENA_DEFS = -DFEAT_GUI_ATHENA $(NARROW_PROTO)
 
ATHENA_IPATH = $(GUI_INC_LOC)
ATHENA_LIBS_DIR = $(GUI_LIB_LOC)
ATHENA_LIBS1 = $(XAW_LIB)
ATHENA_LIBS2 = -lXt
ATHENA_INSTALL = install_normal
ATHENA_TARGETS = installglinks
ATHENA_MAN_TARGETS = yes
ATHENA_TESTTARGET = gui
ATHENA_BUNDLE =
 
### neXtaw GUI
NEXTAW_LIB = -lneXtaw
 
NEXTAW_SRC = gui.c gui_athena.c gui_x11.c pty.c gui_beval.c gui_at_fs.c
NEXTAW_OBJ = objects/gui.o objects/gui_athena.o objects/gui_x11.o \
objects/pty.o objects/gui_beval.o objects/gui_at_fs.o
NEXTAW_DEFS = -DFEAT_GUI_ATHENA -DFEAT_GUI_NEXTAW $(NARROW_PROTO)
 
NEXTAW_IPATH = $(GUI_INC_LOC)
NEXTAW_LIBS_DIR = $(GUI_LIB_LOC)
NEXTAW_LIBS1 = $(NEXTAW_LIB)
NEXTAW_LIBS2 = -lXt
NEXTAW_INSTALL = install_normal
NEXTAW_TARGETS = installglinks
NEXTAW_MAN_TARGETS = yes
NEXTAW_TESTTARGET = gui
NEXTAW_BUNDLE =
 
### (J) Sun OpenWindows 3.2 (SunOS 4.1.x) or earlier that produce these ld
# errors: ld: Undefined symbol
# _get_wmShellWidgetClass
# _get_applicationShellWidgetClass
# then you need to get patches 100512-02 and 100573-03 from Sun. In the
# meantime, uncomment the following GUI_X_LIBS definition as a workaround:
#GUI_X_LIBS = -Bstatic -lXmu -Bdynamic -lXext
# If you also get cos, sin etc. as undefined symbols, try uncommenting this
# too:
#EXTRA_LIBS = /usr/openwin/lib/libXmu.sa -lm
 
# PHOTON GUI
PHOTONGUI_SRC = gui.c gui_photon.c pty.c
PHOTONGUI_OBJ = objects/gui.o objects/gui_photon.o objects/pty.o
PHOTONGUI_DEFS = -DFEAT_GUI_PHOTON
PHOTONGUI_IPATH =
PHOTONGUI_LIBS_DIR =
PHOTONGUI_LIBS1 = -lph -lphexlib
PHOTONGUI_LIBS2 =
PHOTONGUI_INSTALL = install_normal
PHOTONGUI_TARGETS = installglinks
PHOTONGUI_MAN_TARGETS = yes
PHOTONGUI_TESTTARGET = gui
PHOTONGUI_BUNDLE =
 
# CARBON GUI
CARBONGUI_SRC = gui.c gui_mac.c
CARBONGUI_OBJ = objects/gui.o objects/gui_mac.o objects/pty.o
CARBONGUI_DEFS = -DFEAT_GUI_MAC -fno-common -fpascal-strings \
-Wall -Wno-unknown-pragmas \
-mdynamic-no-pic -pipe
CARBONGUI_IPATH = -I. -Iproto
CARBONGUI_LIBS_DIR =
CARBONGUI_LIBS1 = -framework Carbon
CARBONGUI_LIBS2 =
CARBONGUI_INSTALL = install_macosx
CARBONGUI_TARGETS =
CARBONGUI_MAN_TARGETS =
CARBONGUI_TESTTARGET = gui
CARBONGUI_BUNDLE = gui_bundle
APPDIR = $(VIMNAME).app
CARBONGUI_TESTARG = VIMPROG=../$(APPDIR)/Contents/MacOS/$(VIMTARGET)
 
# All GUI files
ALL_GUI_SRC = gui.c gui_gtk.c gui_gtk_f.c gui_motif.c gui_xmdlg.c gui_xmebw.c gui_athena.c gui_gtk_x11.c gui_x11.c gui_at_sb.c gui_at_fs.c pty.c
ALL_GUI_PRO = gui.pro gui_gtk.pro gui_motif.pro gui_xmdlg.pro gui_athena.pro gui_gtk_x11.pro gui_x11.pro gui_w16.pro gui_w32.pro gui_photon.pro
 
# }}}
 
### Command to create dependencies based on #include "..."
### prototype headers are ignored due to -DPROTO, system
### headers #include <...> are ignored if we use the -MM option, as
### e.g. provided by gcc-cpp.
### Include FEAT_GUI to get gependency on gui.h
### Need to change "-I /<path>" to "-isystem /<path>" for GCC 3.x.
CPP_DEPEND = $(CC) -I$(srcdir) -M$(CPP_MM) \
`echo "$(DEPEND_CFLAGS)" $(DEPEND_CFLAGS_FILTER)`
 
# flags for cproto
# This is for cproto 3 patchlevel 8 or below
# __inline, __attribute__ and __extension__ are not recognized by cproto
# G_IMPLEMENT_INLINES is to avoid functions defined in glib/gutils.h.
NO_ATTR = -D__inline= -D__inline__= -DG_IMPLEMENT_INLINES \
-D"__attribute__\\(x\\)=" -D"__asm__\\(x\\)=" \
-D__extension__= -D__restrict="" \
-D__gnuc_va_list=char -D__builtin_va_list=char
 
#
# This is for cproto 3 patchlevel 9 or above (currently 4.6)
# __inline and __attribute__ are now recognized by cproto
# -D"foo()=" is not supported by all compilers so do not use it
# NO_ATTR=
#
# maybe the "/usr/bin/cc -E" has to be adjusted for some systems
# This is for cproto 3.5 patchlevel 3:
# PROTO_FLAGS = -f4 -m__ARGS -d -E"$(CPP)" $(NO_ATTR)
#
# Use this for cproto 3 patchlevel 6 or below (use "cproto -V" to check):
# PROTO_FLAGS = -f4 -m__ARGS -d -E"$(CPP)" $(NO_ATTR)
#
# Use this for cproto 3 patchlevel 7 or above (use "cproto -V" to check):
PROTO_FLAGS = -m -M__ARGS -d -E"$(CPP)" $(NO_ATTR)
 
 
################################################
## no changes required below this line ##
################################################
 
SHELL = /bin/sh
 
.SUFFIXES:
.SUFFIXES: .c .o .pro
 
PRE_DEFS = -Iproto $(DEFS) $(GUI_DEFS) $(GUI_IPATH) $(CPPFLAGS) $(EXTRA_IPATHS)
POST_DEFS = $(X_CFLAGS) $(MZSCHEME_CFLAGS) $(PERL_CFLAGS) $(PYTHON_CFLAGS) $(TCL_CFLAGS) $(RUBY_CFLAGS) $(EXTRA_DEFS)
 
ALL_CFLAGS = $(PRE_DEFS) $(CFLAGS) $(PROFILE_CFLAGS) $(POST_DEFS)
 
# Exclude $CFLAGS for osdef.sh, for Mac 10.4 some flags don't work together
# with "-E".
OSDEF_CFLAGS = $(PRE_DEFS) $(POST_DEFS)
 
LINT_CFLAGS = -DLINT -I. $(PRE_DEFS) $(POST_DEFS) -Dinline= -D__extension__= -Dalloca=alloca
 
LINT_EXTRA = -DUSE_SNIFF -DHANGUL_INPUT -D"__attribute__(x)="
 
DEPEND_CFLAGS = -DPROTO -DDEPEND -DFEAT_GUI $(LINT_CFLAGS)
 
PFLAGS = $(PROTO_FLAGS) -DPROTO $(LINT_CFLAGS)
 
ALL_LIB_DIRS = $(GUI_LIBS_DIR) $(X_LIBS_DIR)
ALL_LIBS = $(GUI_LIBS1) $(GUI_X_LIBS) $(GUI_LIBS2) $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS) $(LIBS) $(EXTRA_LIBS) $(MZSCHEME_LIBS) $(PERL_LIBS) $(PYTHON_LIBS) $(TCL_LIBS) $(RUBY_LIBS) $(PROFILE_LIBS)
 
# abbreviations
DEST_BIN = $(DESTDIR)$(BINDIR)
DEST_VIM = $(DESTDIR)$(VIMLOC)
DEST_RT = $(DESTDIR)$(VIMRTLOC)
DEST_HELP = $(DESTDIR)$(HELPSUBLOC)
DEST_COL = $(DESTDIR)$(COLSUBLOC)
DEST_SYN = $(DESTDIR)$(SYNSUBLOC)
DEST_IND = $(DESTDIR)$(INDSUBLOC)
DEST_AUTO = $(DESTDIR)$(AUTOSUBLOC)
DEST_PLUG = $(DESTDIR)$(PLUGSUBLOC)
DEST_FTP = $(DESTDIR)$(FTPLUGSUBLOC)
DEST_LANG = $(DESTDIR)$(LANGSUBLOC)
DEST_COMP = $(DESTDIR)$(COMPSUBLOC)
DEST_KMAP = $(DESTDIR)$(KMAPSUBLOC)
DEST_MACRO = $(DESTDIR)$(MACROSUBLOC)
DEST_TOOLS = $(DESTDIR)$(TOOLSSUBLOC)
DEST_TUTOR = $(DESTDIR)$(TUTORSUBLOC)
DEST_SPELL = $(DESTDIR)$(SPELLSUBLOC)
DEST_SCRIPT = $(DESTDIR)$(SCRIPTLOC)
DEST_PRINT = $(DESTDIR)$(PRINTSUBLOC)
DEST_MAN_TOP = $(DESTDIR)$(MANDIR)
 
# We assume that the ".../man/xx/man1/" directory is for latin1 manual pages.
# Some systems use UTF-8, but these should find the ".../man/xx.UTF-8/man1/"
# directory first.
# FreeBSD uses ".../man/xx.ISO8859-1/man1" for latin1, use that one too.
DEST_MAN = $(DEST_MAN_TOP)$(MAN1DIR)
DEST_MAN_FR = $(DEST_MAN_TOP)/fr$(MAN1DIR)
DEST_MAN_FR_I = $(DEST_MAN_TOP)/fr.ISO8859-1$(MAN1DIR)
DEST_MAN_FR_U = $(DEST_MAN_TOP)/fr.UTF-8$(MAN1DIR)
DEST_MAN_IT = $(DEST_MAN_TOP)/it$(MAN1DIR)
DEST_MAN_IT_I = $(DEST_MAN_TOP)/it.ISO8859-1$(MAN1DIR)
DEST_MAN_IT_U = $(DEST_MAN_TOP)/it.UTF-8$(MAN1DIR)
DEST_MAN_PL = $(DEST_MAN_TOP)/pl$(MAN1DIR)
DEST_MAN_PL_I = $(DEST_MAN_TOP)/pl.ISO8859-2$(MAN1DIR)
DEST_MAN_PL_U = $(DEST_MAN_TOP)/pl.UTF-8$(MAN1DIR)
DEST_MAN_RU = $(DEST_MAN_TOP)/ru.KOI8-R$(MAN1DIR)
DEST_MAN_RU_U = $(DEST_MAN_TOP)/ru.UTF-8$(MAN1DIR)
 
# BASIC_SRC: files that are always used
# GUI_SRC: extra GUI files for current configuration
# ALL_GUI_SRC: all GUI files for Unix
#
# SRC: files used for current configuration
# TAGS_SRC: source files used for make tags
# TAGS_INCL: include files used for make tags
# ALL_SRC: source files used for make depend and make lint
 
TAGS_INCL = *.h
 
BASIC_SRC = \
buffer.c \
charset.c \
diff.c \
digraph.c \
edit.c \
eval.c \
ex_cmds.c \
ex_cmds2.c \
ex_docmd.c \
ex_eval.c \
ex_getln.c \
fileio.c \
fold.c \
getchar.c \
hardcopy.c \
hashtab.c \
if_cscope.c \
if_xcmdsrv.c \
main.c \
mark.c \
memfile.c \
memline.c \
menu.c \
message.c \
misc1.c \
misc2.c \
move.c \
mbyte.c \
normal.c \
ops.c \
option.c \
os_unix.c \
auto/pathdef.c \
popupmnu.c \
quickfix.c \
regexp.c \
screen.c \
search.c \
spell.c \
syntax.c \
tag.c \
term.c \
ui.c \
undo.c \
version.c \
window.c \
$(OS_EXTRA_SRC)
 
SRC = $(BASIC_SRC) $(GUI_SRC) $(HANGULIN_SRC) $(MZSCHEME_SRC) \
$(PERL_SRC) $(PYTHON_SRC) $(TCL_SRC) $(RUBY_SRC) \
$(SNIFF_SRC) $(WORKSHOP_SRC) $(WSDEBUG_SRC)
 
TAGS_SRC = *.c *.cpp if_perl.xs
 
EXTRA_SRC = hangulin.c if_mzsch.c auto/if_perl.c if_perlsfio.c \
if_python.c if_tcl.c if_ruby.c if_sniff.c gui_beval.c \
workshop.c wsdebug.c integration.c netbeans.c
 
# All sources, also the ones that are not configured
ALL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(EXTRA_SRC)
 
# Which files to check with lint. Select one of these three lines. ALL_SRC
# checks more, but may not work well for checking a GUI that wasn't configured.
# The perl sources also don't work well with lint.
LINT_SRC = $(BASIC_SRC) $(GUI_SRC) $(HANGULIN_SRC) $(PYTHON_SRC) $(TCL_SRC) \
$(SNIFF_SRC) $(WORKSHOP_SRC) $(WSDEBUG_SRC) $(NETBEANS_SRC)
#LINT_SRC = $(SRC)
#LINT_SRC = $(ALL_SRC)
 
OBJ = \
objects/buffer.o \
objects/charset.o \
objects/diff.o \
objects/digraph.o \
objects/edit.o \
objects/eval.o \
objects/ex_cmds.o \
objects/ex_cmds2.o \
objects/ex_docmd.o \
objects/ex_eval.o \
objects/ex_getln.o \
objects/fileio.o \
objects/fold.o \
objects/getchar.o \
objects/hardcopy.o \
objects/hashtab.o \
$(HANGULIN_OBJ) \
objects/if_cscope.o \
objects/if_xcmdsrv.o \
objects/main.o \
objects/mark.o \
objects/memfile.o \
objects/memline.o \
objects/menu.o \
objects/message.o \
objects/misc1.o \
objects/misc2.o \
objects/move.o \
objects/mbyte.o \
objects/normal.o \
objects/ops.o \
objects/option.o \
objects/os_unix.o \
objects/pathdef.o \
objects/popupmnu.o \
objects/quickfix.o \
objects/regexp.o \
objects/screen.o \
objects/search.o \
objects/spell.o \
objects/syntax.o \
$(SNIFF_OBJ) \
objects/tag.o \
objects/term.o \
objects/ui.o \
objects/undo.o \
objects/window.o \
$(GUI_OBJ) \
$(MZSCHEME_OBJ) \
$(PERL_OBJ) \
$(PYTHON_OBJ) \
$(TCL_OBJ) \
$(RUBY_OBJ) \
$(OS_EXTRA_OBJ) \
$(WORKSHOP_OBJ) \
$(NETBEANS_OBJ) \
$(WSDEBUG_OBJ)
 
PRO_AUTO = \
buffer.pro \
charset.pro \
diff.pro \
digraph.pro \
edit.pro \
eval.pro \
ex_cmds.pro \
ex_cmds2.pro \
ex_docmd.pro \
ex_eval.pro \
ex_getln.pro \
fileio.pro \
fold.pro \
getchar.pro \
hardcopy.pro \
hashtab.pro \
hangulin.pro \
if_cscope.pro \
if_xcmdsrv.pro \
if_python.pro \
if_ruby.pro \
main.pro \
mark.pro \
memfile.pro \
memline.pro \
menu.pro \
message.pro \
misc1.pro \
misc2.pro \
move.pro \
mbyte.pro \
normal.pro \
ops.pro \
option.pro \
os_unix.pro \
popupmnu.pro \
quickfix.pro \
regexp.pro \
screen.pro \
search.pro \
spell.pro \
syntax.pro \
tag.pro \
term.pro \
termlib.pro \
ui.pro \
undo.pro \
version.pro \
window.pro \
gui_beval.pro \
workshop.pro \
netbeans.pro \
$(ALL_GUI_PRO) \
$(TCL_PRO)
 
# Resources used for the Mac are in one directory.
RSRC_DIR = os_mac_rsrc
 
PRO_MANUAL = os_amiga.pro os_msdos.pro os_win16.pro os_win32.pro \
os_mswin.pro os_beos.pro os_vms.pro os_riscos.pro $(PERL_PRO)
 
# Default target is making the executable and tools
all: $(VIMTARGET) $(TOOLS) languages $(GUI_BUNDLE)
 
tools: $(TOOLS)
 
# Run configure with all the setting from above.
#
# Note: auto/config.h doesn't depend on configure, because running configure
# doesn't always update auto/config.h. The timestamp isn't changed if the
# file contents didn't change (to avoid recompiling everything). Including a
# dependency on auto/config.h would cause running configure each time when
# auto/config.h isn't updated. The dependency on auto/config.mk should make
# sure configure is run when it's needed.
#
config auto/config.mk: auto/configure config.mk.in config.h.in
GUI_INC_LOC="$(GUI_INC_LOC)" GUI_LIB_LOC="$(GUI_LIB_LOC)" \
CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" \
LDFLAGS="$(LDFLAGS)" $(CONF_SHELL) srcdir="$(srcdir)" \
./configure $(CONF_OPT_GUI) $(CONF_OPT_X) $(CONF_OPT_XSMP) \
$(CONF_OPT_DARWIN) $(CONF_OPT_PERL) $(CONF_OPT_PYTHON) \
$(CONF_OPT_TCL) $(CONF_OPT_RUBY) $(CONF_OPT_NLS) \
$(CONF_OPT_CSCOPE) $(CONF_OPT_MULTIBYTE) $(CONF_OPT_INPUT) \
$(CONF_OPT_OUTPUT) $(CONF_OPT_GPM) $(CONF_OPT_WORKSHOP) \
$(CONF_OPT_SNIFF) $(CONF_OPT_FEAT) $(CONF_TERM_LIB) \
$(CONF_OPT_COMPBY) $(CONF_OPT_ACL) $(CONF_OPT_NETBEANS) \
$(CONF_ARGS) $(CONF_OPT_MZSCHEME) $(CONF_OPT_PLTHOME)
 
# Use "make reconfig" to rerun configure without cached values.
# When config.h changes, most things will be recompiled automatically.
# Invoke $(MAKE) to run config with the empty auto/config.mk.
# Invoke $(MAKE) to build all with the filled auto/config.mk.
reconfig: scratch clean
$(MAKE) -f Makefile config
$(MAKE) -f Makefile all
 
# Run autoconf to produce auto/configure.
# Note:
# - DO NOT RUN autoconf MANUALLY! It will overwrite ./configure instead of
# producing auto/configure.
# - autoconf is not run automatically, because a patch usually changes both
# configure.in and auto/configure but can't update the timestamps. People
# who do not have (the correct version of) autoconf would run into trouble.
#
# Two tricks are required to make autoconf put its output in the "auto" dir:
# - Temporarily move the ./configure script to ./configure.save. Don't
# overwrite it, it's probably the result of an aborted autoconf.
# - Use sed to change ./config.log to auto/config.log in the configure script.
# Autoconf 2.5x (2.59 at least) produces a few more files that we need to take
# care of:
# - configure.lineno: has the line numbers replaced with $LINENO. That
# improves patches a LOT, thus use it instead (until someone says it doesn't
# work on some system).
# - autom4te.cache directory is created and not cleaned up. Delete it.
# - Uses ">config.log" instead of "./config.log".
autoconf:
if test ! -f configure.save; then mv configure configure.save; fi
autoconf
sed -e 's+>config.log+>auto/config.log+' -e 's+\./config.log+auto/config.log+' configure > auto/configure
chmod 755 auto/configure
mv -f configure.save configure
-rm -rf autom4te.cache
-rm -f auto/config.status auto/config.cache
 
# Re-execute this Makefile to include the new auto/config.mk produced by
# configure Only used when typing "make" with a fresh auto/config.mk.
myself:
$(MAKE) -f Makefile all
 
 
# The normal command to compile a .c file to its .o file.
CCC = $(CC) -c -I$(srcdir) $(ALL_CFLAGS)
 
 
# Link the target for normal use or debugging.
# A shell script is used to try linking without unneccesary libraries.
$(VIMTARGET): auto/config.mk objects $(OBJ) version.c version.h
$(CCC) version.c -o objects/version.o
@LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
-o $(VIMTARGET) $(OBJ) objects/version.o $(ALL_LIBS)" \
MAKE="$(MAKE)" sh $(srcdir)/link.sh
 
xxd/xxd$(EXEEXT): xxd/xxd.c
cd xxd; CC="$(CC)" CFLAGS="$(CPPFLAGS) $(CFLAGS)" \
$(MAKE) -f Makefile
 
# Build the language specific files if they were unpacked.
# Generate the converted .mo files separately, it's no problem if this fails.
languages:
@if test -n "$(MAKEMO)" -a -f $(PODIR)/Makefile; then \
cd $(PODIR); \
CC="$(CC)" $(MAKE) prefix=$(DESTDIR)$(prefix); \
fi
-@if test -n "$(MAKEMO)" -a -f $(PODIR)/Makefile; then \
cd $(PODIR); CC="$(CC)" $(MAKE) prefix=$(DESTDIR)$(prefix) converted; \
fi
 
# Update the *.po files for changes in the sources. Only run manually.
update-po:
cd $(PODIR); CC="$(CC)" $(MAKE) prefix=$(DESTDIR)$(prefix) update-po
 
# Generate function prototypes. This is not needed to compile vim, but if
# you want to use it, cproto is out there on the net somewhere -- Webb
#
# When generating os_amiga.pro, os_msdos.pro and os_win32.pro there will be a
# few include files that can not be found, that's OK.
 
proto: $(PRO_AUTO) $(PRO_MANUAL)
 
### Would be nice if this would work for "normal" make.
### Currently it only works for (Free)BSD make.
#$(PRO_AUTO): $$(*F).c
# cproto $(PFLAGS) -DFEAT_GUI $(*F).c > $@
 
# Always define FEAT_GUI. This may generate a few warnings if it's also
# defined in auto/config.h, you can ignore that.
.c.pro:
cproto $(PFLAGS) -DFEAT_GUI $< > proto/$@
echo "/* vim: set ft=c : */" >> proto/$@
 
os_amiga.pro: os_amiga.c
cproto $(PFLAGS) -DAMIGA -UHAVE_CONFIG_H -DBPTR=char* $< > proto/$@
echo "/* vim: set ft=c : */" >> proto/$@
 
os_msdos.pro: os_msdos.c
cproto $(PFLAGS) -DMSDOS -UHAVE_CONFIG_H $< > proto/$@
echo "/* vim: set ft=c : */" >> proto/$@
 
os_win16.pro: os_win16.c
cproto $(PFLAGS) -DWIN16 -UHAVE_CONFIG_H $< > proto/$@
echo "/* vim: set ft=c : */" >> proto/$@
 
os_win32.pro: os_win32.c
cproto $(PFLAGS) -DWIN32 -UHAVE_CONFIG_H $< > proto/$@
echo "/* vim: set ft=c : */" >> proto/$@
 
os_mswin.pro: os_mswin.c
cproto $(PFLAGS) -DWIN16 -DWIN32 -UHAVE_CONFIG_H $< > proto/$@
echo "/* vim: set ft=c : */" >> proto/$@
 
os_beos.pro: os_beos.c
cproto $(PFLAGS) -D__BEOS__ -UHAVE_CONFIG_H $< > proto/$@
echo "/* vim: set ft=c : */" >> proto/$@
 
os_vms.pro: os_vms.c
# must use os_vms_conf.h for auto/config.h
mv auto/config.h auto/config.h.save
cp os_vms_conf.h auto/config.h
cproto $(PFLAGS) -DVMS -UFEAT_GUI_ATHENA -UFEAT_GUI_NEXTAW -UFEAT_GUI_MOTIF -UFEAT_GUI_GTK $< > proto/$@
echo "/* vim: set ft=c : */" >> proto/$@
rm auto/config.h
mv auto/config.h.save auto/config.h
 
# if_perl.pro is special: Use the generated if_perl.c for input and remove
# prototypes for local functions.
if_perl.pro: auto/if_perl.c
cproto $(PFLAGS) -DFEAT_GUI auto/if_perl.c | sed "/_VI/d" > proto/$@
 
 
notags:
-rm -f tags
 
# Note: tags is made for the currently configured version, can't include both
# Motif and Athena GUI
# You can ignore error messages for missing files.
tags TAGS: notags
$(TAGPRG) $(TAGS_SRC) $(TAGS_INCL)
 
# Make a highlight file for types. Requires Exuberant ctags and awk
types: types.vim
types.vim: $(TAGS_SRC) $(TAGS_INCL)
ctags --c-kinds=gstu -o- $(TAGS_SRC) $(TAGS_INCL) |\
awk 'BEGIN{printf("syntax keyword Type\t")}\
{printf("%s ", $$1)}END{print ""}' > $@
 
# Execute the test scripts. Run these after compiling Vim, before installing.
# This doesn't depend on $(VIMTARGET), because that won't work when configure
# wasn't run yet. Restart make to build it instead.
#
# This will produce a lot of garbage on your screen, including a few error
# messages. Don't worry about that.
# If there is a real error, there will be a difference between "test.out" and
# a "test99.ok" file.
# If everything is alright, the final message will be "ALL DONE".
#
test check:
$(MAKE) -f Makefile $(VIMTARGET)
-if test -n "$(MAKEMO)" -a -f $(PODIR)/Makefile; then \
cd $(PODIR); $(MAKE) -f Makefile check VIM=../$(VIMTARGET); \
fi
-if test $(VIMTARGET) != vim -a ! -e vim; then \
ln -s $(VIMTARGET) vim; \
fi
cd testdir; $(MAKE) -f Makefile $(GUI_TESTTARGET) VIMPROG=../$(VIMTARGET) $(GUI_TESTARG)
 
testclean:
cd testdir; $(MAKE) -f Makefile clean
if test -d $(PODIR); then \
cd $(PODIR); $(MAKE) checkclean; \
fi
 
#
# Avoid overwriting an existing executable, somebody might be running it and
# overwriting it could cause it to crash. Deleting it is OK, it won't be
# really deleted until all running processes for it have exited. It is
# renamed first, in case the deleting doesn't work.
#
# If you want to keep an older version, rename it before running "make
# install".
#
install: $(GUI_INSTALL)
 
install_normal: installvim installtools $(INSTALL_LANGS) install-icons
 
installvim: installvimbin installtutorbin \
installruntime installlinks installmanlinks
 
installvimbin: $(VIMTARGET) $(DESTDIR)$(exec_prefix) $(DEST_BIN)
-if test -f $(DEST_BIN)/$(VIMTARGET); then \
mv -f $(DEST_BIN)/$(VIMTARGET) $(DEST_BIN)/$(VIMNAME).rm; \
rm -f $(DEST_BIN)/$(VIMNAME).rm; \
fi
$(INSTALL_PROG) $(VIMTARGET) $(DEST_BIN)
$(STRIP) $(DEST_BIN)/$(VIMTARGET)
chmod $(BINMOD) $(DEST_BIN)/$(VIMTARGET)
# may create a link to the new executable from /usr/bin/vi
-$(LINKIT)
 
# Long list of arguments for the shell script that installs the manual pages
# for one language.
INSTALLMANARGS = $(VIMLOC) $(SCRIPTLOC) $(VIMRCLOC) $(HELPSOURCE) $(MANMOD) \
$(VIMNAME) $(VIMDIFFNAME) $(EVIMNAME)
 
# Install most of the runtime files
installruntime: installrtbase installmacros installtutor installspell
 
# install the help files; first adjust the contents for the final location
installrtbase: $(HELPSOURCE)/vim.1 $(DEST_VIM) $(DEST_RT) \
$(DEST_HELP) $(DEST_PRINT) $(DEST_COL) $(DEST_SYN) $(DEST_IND) \
$(DEST_FTP) $(DEST_AUTO) $(DEST_AUTO)/xml $(DEST_PLUG) \
$(DEST_TUTOR) $(DEST_SPELL) $(DEST_COMP)
-$(SHELL) ./installman.sh install $(DEST_MAN) "" $(INSTALLMANARGS)
@echo generating help tags
# Generate the help tags with ":helptags" to handle all languages.
-@cd $(HELPSOURCE); $(MAKE) VIMEXE=$(DEST_BIN)/$(VIMTARGET) vimtags
cd $(HELPSOURCE); \
files=`ls *.txt tags`; \
files="$$files `ls *.??x tags-?? 2>/dev/null || true`"; \
$(INSTALL_DATA) $$files $(DEST_HELP); \
cd $(DEST_HELP); \
chmod $(HELPMOD) $$files
$(INSTALL_DATA) $(HELPSOURCE)/*.pl $(DEST_HELP)
chmod $(SCRIPTMOD) $(DEST_HELP)/*.pl
# install the menu files
$(INSTALL_DATA) $(SCRIPTSOURCE)/menu.vim $(SYS_MENU_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_MENU_FILE)
$(INSTALL_DATA) $(SCRIPTSOURCE)/synmenu.vim $(SYS_SYNMENU_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_SYNMENU_FILE)
$(INSTALL_DATA) $(SCRIPTSOURCE)/delmenu.vim $(SYS_DELMENU_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_DELMENU_FILE)
# install the evim file
$(INSTALL_DATA) $(SCRIPTSOURCE)/mswin.vim $(MSWIN_FILE)
chmod $(VIMSCRIPTMOD) $(MSWIN_FILE)
$(INSTALL_DATA) $(SCRIPTSOURCE)/evim.vim $(EVIM_FILE)
chmod $(VIMSCRIPTMOD) $(EVIM_FILE)
# install the bugreport file
$(INSTALL_DATA) $(SCRIPTSOURCE)/bugreport.vim $(SYS_BUGR_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_BUGR_FILE)
# install the example vimrc files
$(INSTALL_DATA) $(SCRIPTSOURCE)/vimrc_example.vim $(DEST_SCRIPT)
chmod $(VIMSCRIPTMOD) $(DEST_SCRIPT)/vimrc_example.vim
$(INSTALL_DATA) $(SCRIPTSOURCE)/gvimrc_example.vim $(DEST_SCRIPT)
chmod $(VIMSCRIPTMOD) $(DEST_SCRIPT)/gvimrc_example.vim
# install the file type detection files
$(INSTALL_DATA) $(SCRIPTSOURCE)/filetype.vim $(SYS_FILETYPE_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_FILETYPE_FILE)
$(INSTALL_DATA) $(SCRIPTSOURCE)/ftoff.vim $(SYS_FTOFF_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_FTOFF_FILE)
$(INSTALL_DATA) $(SCRIPTSOURCE)/scripts.vim $(SYS_SCRIPTS_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_SCRIPTS_FILE)
$(INSTALL_DATA) $(SCRIPTSOURCE)/ftplugin.vim $(SYS_FTPLUGIN_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_FTPLUGIN_FILE)
$(INSTALL_DATA) $(SCRIPTSOURCE)/ftplugof.vim $(SYS_FTPLUGOF_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_FTPLUGOF_FILE)
$(INSTALL_DATA) $(SCRIPTSOURCE)/indent.vim $(SYS_INDENT_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_INDENT_FILE)
$(INSTALL_DATA) $(SCRIPTSOURCE)/indoff.vim $(SYS_INDOFF_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_INDOFF_FILE)
$(INSTALL_DATA) $(SCRIPTSOURCE)/optwin.vim $(SYS_OPTWIN_FILE)
chmod $(VIMSCRIPTMOD) $(SYS_OPTWIN_FILE)
# install the print resource files
cd $(PRINTSOURCE); $(INSTALL_DATA) *.ps $(DEST_PRINT)
cd $(DEST_PRINT); chmod $(FILEMOD) *.ps
# install the colorscheme files
cd $(COLSOURCE); $(INSTALL_DATA) *.vim README.txt $(DEST_COL)
cd $(DEST_COL); chmod $(HELPMOD) *.vim README.txt
# install the syntax files
cd $(SYNSOURCE); $(INSTALL_DATA) *.vim README.txt $(DEST_SYN)
cd $(DEST_SYN); chmod $(HELPMOD) *.vim README.txt
# install the indent files
cd $(INDSOURCE); $(INSTALL_DATA) *.vim README.txt $(DEST_IND)
cd $(DEST_IND); chmod $(HELPMOD) *.vim README.txt
# install the standard autoload files
cd $(AUTOSOURCE); $(INSTALL_DATA) *.vim README.txt $(DEST_AUTO)
cd $(DEST_AUTO); chmod $(HELPMOD) *.vim README.txt
cd $(AUTOSOURCE)/xml; $(INSTALL_DATA) *.vim $(DEST_AUTO)/xml
cd $(DEST_AUTO)/xml; chmod $(HELPMOD) *.vim
# install the standard plugin files
cd $(PLUGSOURCE); $(INSTALL_DATA) *.vim README.txt $(DEST_PLUG)
cd $(DEST_PLUG); chmod $(HELPMOD) *.vim README.txt
# install the ftplugin files
cd $(FTPLUGSOURCE); $(INSTALL_DATA) *.vim README.txt $(DEST_FTP)
cd $(DEST_FTP); chmod $(HELPMOD) *.vim README.txt
# install the compiler files
cd $(COMPSOURCE); $(INSTALL_DATA) *.vim README.txt $(DEST_COMP)
cd $(DEST_COMP); chmod $(HELPMOD) *.vim README.txt
 
installmacros: $(DEST_VIM) $(DEST_RT) $(DEST_MACRO)
$(INSTALL_DATA_R) $(MACROSOURCE)/* $(DEST_MACRO)
chmod $(DIRMOD) `find $(DEST_MACRO) -type d -print`
chmod $(FILEMOD) `find $(DEST_MACRO) -type f -print`
chmod $(SCRIPTMOD) $(DEST_MACRO)/less.sh
# When using CVS some CVS directories might have been copied.
cvs=`find $(DEST_MACRO) \( -name CVS -o -name AAPDIR \) -print`; \
if test -n "$$cvs"; then \
rm -rf $$cvs; \
fi
 
# install the tutor files
installtutorbin: $(DEST_VIM)
$(INSTALL_DATA) vimtutor $(DEST_BIN)/$(VIMNAME)tutor
chmod $(SCRIPTMOD) $(DEST_BIN)/$(VIMNAME)tutor
 
installtutor: $(DEST_RT) $(DEST_TUTOR)
-$(INSTALL_DATA) $(TUTORSOURCE)/README* $(TUTORSOURCE)/tutor* $(DEST_TUTOR)
chmod $(HELPMOD) $(DEST_TUTOR)/*
 
# Install the spell files, if they exist. This assumes at least the English
# spell file is there.
installspell: $(DEST_VIM) $(DEST_RT) $(DEST_SPELL)
if test -f $(SPELLSOURCE)/en.latin1.spl; then \
$(INSTALL_DATA) $(SPELLSOURCE)/*.spl $(SPELLSOURCE)/*.sug $(SPELLSOURCE)/*.vim $(DEST_SPELL); \
chmod $(HELPMOD) $(DEST_SPELL)/*.spl $(DEST_SPELL)/*.sug $(DEST_SPELL)/*.vim; \
fi
 
# install helper program xxd
installtools: $(TOOLS) $(DESTDIR)$(exec_prefix) $(DEST_BIN) \
$(TOOLSSOURCE) $(DEST_VIM) $(DEST_RT) $(DEST_TOOLS) \
$(INSTALL_TOOL_LANGS)
if test -f $(DEST_BIN)/xxd$(EXEEXT); then \
mv -f $(DEST_BIN)/xxd$(EXEEXT) $(DEST_BIN)/xxd.rm; \
rm -f $(DEST_BIN)/xxd.rm; \
fi
$(INSTALL_PROG) xxd/xxd$(EXEEXT) $(DEST_BIN)
$(STRIP) $(DEST_BIN)/xxd$(EXEEXT)
chmod $(BINMOD) $(DEST_BIN)/xxd$(EXEEXT)
-$(SHELL) ./installman.sh xxd $(DEST_MAN) "" $(INSTALLMANARGS)
 
# install the runtime tools
$(INSTALL_DATA_R) $(TOOLSSOURCE)/* $(DEST_TOOLS)
# When using CVS some CVS directories might have been copied.
cvs=`find $(DEST_TOOLS) \( -name CVS -o -name AAPDIR \) -print`; \
if test -n "$$cvs"; then \
rm -rf $$cvs; \
fi
-chmod $(FILEMOD) $(DEST_TOOLS)/*
# replace the path in some tools
perlpath=`./which.sh perl` && sed -e "s+/usr/bin/perl+$$perlpath+" $(TOOLSSOURCE)/efm_perl.pl >$(DEST_TOOLS)/efm_perl.pl
awkpath=`./which.sh nawk` && sed -e "s+/usr/bin/nawk+$$awkpath+" $(TOOLSSOURCE)/mve.awk >$(DEST_TOOLS)/mve.awk; if test -z "$$awkpath"; then \
awkpath=`./which.sh gawk` && sed -e "s+/usr/bin/nawk+$$awkpath+" $(TOOLSSOURCE)/mve.awk >$(DEST_TOOLS)/mve.awk; if test -z "$$awkpath"; then \
awkpath=`./which.sh awk` && sed -e "s+/usr/bin/nawk+$$awkpath+" $(TOOLSSOURCE)/mve.awk >$(DEST_TOOLS)/mve.awk; fi; fi
-chmod $(SCRIPTMOD) `grep -l "^#!" $(DEST_TOOLS)/*`
 
# install the language specific files for tools, if they were unpacked
install-tool-languages:
-$(SHELL) ./installman.sh xxd $(DEST_MAN_FR) "-fr" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh xxd $(DEST_MAN_FR_I) "-fr" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh xxd $(DEST_MAN_FR_U) "-fr.UTF-8" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh xxd $(DEST_MAN_IT) "-it" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh xxd $(DEST_MAN_IT_I) "-it" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh xxd $(DEST_MAN_IT_U) "-it.UTF-8" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh xxd $(DEST_MAN_PL) "-pl" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh xxd $(DEST_MAN_PL_I) "-pl" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh xxd $(DEST_MAN_PL_U) "-pl.UTF-8" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh xxd $(DEST_MAN_RU) "-ru" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh xxd $(DEST_MAN_RU_U) "-ru.UTF-8" $(INSTALLMANARGS)
 
# install the language specific files, if they were unpacked
install-languages: languages $(DEST_LANG) $(DEST_KMAP)
-$(SHELL) ./installman.sh install $(DEST_MAN_FR) "-fr" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh install $(DEST_MAN_FR_I) "-fr" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh install $(DEST_MAN_FR_U) "-fr.UTF-8" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh install $(DEST_MAN_IT) "-it" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh install $(DEST_MAN_IT_I) "-it" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh install $(DEST_MAN_IT_U) "-it.UTF-8" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh install $(DEST_MAN_PL) "-pl" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh install $(DEST_MAN_PL_I) "-pl" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh install $(DEST_MAN_PL_U) "-pl.UTF-8" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh install $(DEST_MAN_RU) "-ru" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh install $(DEST_MAN_RU_U) "-ru.UTF-8" $(INSTALLMANARGS)
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_FR) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_FR_I) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_FR_U) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_IT) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_IT_I) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_IT_U) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_PL) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_PL_I) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_PL_U) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_RU) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_RU_U) $(INSTALLMLARGS)
if test -n "$(MAKEMO)" -a -f $(PODIR)/Makefile; then \
cd $(PODIR); $(MAKE) prefix=$(DESTDIR)$(prefix) LOCALEDIR=$(DEST_LANG) \
INSTALL_DATA=$(INSTALL_DATA) FILEMOD=$(FILEMOD) install; \
fi
if test -d $(LANGSOURCE); then \
$(INSTALL_DATA) $(LANGSOURCE)/README.txt $(LANGSOURCE)/*.vim $(DEST_LANG); \
chmod $(FILEMOD) $(DEST_LANG)/README.txt $(DEST_LANG)/*.vim; \
fi
if test -d $(KMAPSOURCE); then \
$(INSTALL_DATA) $(KMAPSOURCE)/README.txt $(KMAPSOURCE)/*.vim $(DEST_KMAP); \
chmod $(FILEMOD) $(DEST_KMAP)/README.txt $(DEST_KMAP)/*.vim; \
fi
 
# install the icons for KDE, if the directory exists and the icon doesn't.
ICON48PATH = $(DESTDIR)$(DATADIR)/icons/hicolor/48x48/apps
ICON32PATH = $(DESTDIR)$(DATADIR)/icons/locolor/32x32/apps
ICON16PATH = $(DESTDIR)$(DATADIR)/icons/locolor/16x16/apps
KDEPATH = $(HOME)/.kde/share/icons
install-icons:
if test -d $(ICON48PATH) -a -w $(ICON48PATH) \
-a ! -f $(ICON48PATH)/gvim.png; then \
$(INSTALL_DATA) $(SCRIPTSOURCE)/vim48x48.png $(ICON48PATH)/gvim.png; \
fi
if test -d $(ICON32PATH) -a -w $(ICON32PATH) \
-a ! -f $(ICON32PATH)/gvim.png; then \
$(INSTALL_DATA) $(SCRIPTSOURCE)/vim32x32.png $(ICON32PATH)/gvim.png; \
fi
if test -d $(ICON16PATH) -a -w $(ICON16PATH) \
-a ! -f $(ICON16PATH)/gvim.png; then \
$(INSTALL_DATA) $(SCRIPTSOURCE)/vim16x16.png $(ICON16PATH)/gvim.png; \
fi
 
 
$(HELPSOURCE)/vim.1 $(MACROSOURCE) $(TOOLSSOURCE):
@echo Runtime files not found.
@echo You need to unpack the runtime archive before running "make install".
test -f error
 
$(DESTDIR)$(exec_prefix) $(DEST_BIN) \
$(DEST_VIM) $(DEST_RT) $(DEST_HELP) \
$(DEST_PRINT) $(DEST_COL) $(DEST_SYN) $(DEST_IND) $(DEST_FTP) \
$(DEST_LANG) $(DEST_KMAP) $(DEST_COMP) \
$(DEST_MACRO) $(DEST_TOOLS) $(DEST_TUTOR) $(DEST_SPELL) \
$(DEST_AUTO) $(DEST_AUTO)/xml $(DEST_PLUG):
-$(SHELL) ./mkinstalldirs $@
-chmod $(DIRMOD) $@
 
# create links from various names to vim. This is only done when the links
# (or executables with the same name) don't exist yet.
installlinks: $(GUI_TARGETS) \
$(DEST_BIN)/$(EXTARGET) \
$(DEST_BIN)/$(VIEWTARGET) \
$(DEST_BIN)/$(RVIMTARGET) \
$(DEST_BIN)/$(RVIEWTARGET) \
$(INSTALLVIMDIFF)
 
installglinks: $(DEST_BIN)/$(GVIMTARGET) \
$(DEST_BIN)/$(GVIEWTARGET) \
$(DEST_BIN)/$(RGVIMTARGET) \
$(DEST_BIN)/$(RGVIEWTARGET) \
$(DEST_BIN)/$(EVIMTARGET) \
$(DEST_BIN)/$(EVIEWTARGET) \
$(INSTALLGVIMDIFF)
 
installvimdiff: $(DEST_BIN)/$(VIMDIFFTARGET)
installgvimdiff: $(DEST_BIN)/$(GVIMDIFFTARGET)
 
$(DEST_BIN)/$(EXTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(EXTARGET)
 
$(DEST_BIN)/$(VIEWTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(VIEWTARGET)
 
$(DEST_BIN)/$(GVIMTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(GVIMTARGET)
 
$(DEST_BIN)/$(GVIEWTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(GVIEWTARGET)
 
$(DEST_BIN)/$(RVIMTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(RVIMTARGET)
 
$(DEST_BIN)/$(RVIEWTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(RVIEWTARGET)
 
$(DEST_BIN)/$(RGVIMTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(RGVIMTARGET)
 
$(DEST_BIN)/$(RGVIEWTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(RGVIEWTARGET)
 
$(DEST_BIN)/$(VIMDIFFTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(VIMDIFFTARGET)
 
$(DEST_BIN)/$(GVIMDIFFTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(GVIMDIFFTARGET)
 
$(DEST_BIN)/$(EVIMTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(EVIMTARGET)
 
$(DEST_BIN)/$(EVIEWTARGET):
cd $(DEST_BIN); ln -s $(VIMTARGET) $(EVIEWTARGET)
 
# Create links for the manual pages with various names to vim. This is only
# done when the links (or manpages with the same name) don't exist yet.
 
INSTALLMLARGS = $(VIMNAME) $(VIMDIFFNAME) $(EVIMNAME) \
$(EXNAME) $(VIEWNAME) $(RVIMNAME) $(RVIEWNAME) \
$(GVIMNAME) $(GVIEWNAME) $(RGVIMNAME) $(RGVIEWNAME) \
$(GVIMDIFFNAME) $(EVIEWNAME)
 
installmanlinks:
-$(SHELL) ./installml.sh install "$(GUI_MAN_TARGETS)" \
$(DEST_MAN) $(INSTALLMLARGS)
 
uninstall: uninstall_runtime
-rm -f $(DEST_BIN)/$(VIMTARGET)
-rm -f $(DEST_BIN)/vimtutor
-rm -f $(DEST_BIN)/$(EXTARGET) $(DEST_BIN)/$(VIEWTARGET)
-rm -f $(DEST_BIN)/$(GVIMTARGET) $(DEST_BIN)/$(GVIEWTARGET)
-rm -f $(DEST_BIN)/$(RVIMTARGET) $(DEST_BIN)/$(RVIEWTARGET)
-rm -f $(DEST_BIN)/$(RGVIMTARGET) $(DEST_BIN)/$(RGVIEWTARGET)
-rm -f $(DEST_BIN)/$(VIMDIFFTARGET) $(DEST_BIN)/$(GVIMDIFFTARGET)
-rm -f $(DEST_BIN)/$(EVIMTARGET) $(DEST_BIN)/$(EVIEWTARGET)
-rm -f $(DEST_BIN)/xxd$(EXEEXT)
 
# Note: the "rmdir" will fail if any files were added after "make install"
uninstall_runtime:
-$(SHELL) ./installman.sh uninstall $(DEST_MAN) "" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh uninstall $(DEST_MAN_FR) "" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh uninstall $(DEST_MAN_FR_I) "" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh uninstall $(DEST_MAN_FR_U) "" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh uninstall $(DEST_MAN_IT) "" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh uninstall $(DEST_MAN_IT_I) "" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh uninstall $(DEST_MAN_IT_U) "" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh uninstall $(DEST_MAN_PL) "" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh uninstall $(DEST_MAN_PL_I) "" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh uninstall $(DEST_MAN_PL_U) "" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh uninstall $(DEST_MAN_RU) "" $(INSTALLMANARGS)
-$(SHELL) ./installman.sh uninstall $(DEST_MAN_RU_U) "" $(INSTALLMANARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_FR) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_FR_I) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_FR_U) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_IT) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_IT_I) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_IT_U) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_PL) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_PL_I) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_PL_U) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_RU) $(INSTALLMLARGS)
-$(SHELL) ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
$(DEST_MAN_RU_U) $(INSTALLMLARGS)
-rm -f $(DEST_MAN)/xxd.1
-rm -f $(DEST_MAN_FR)/xxd.1 $(DEST_MAN_FR_I)/xxd.1 $(DEST_MAN_FR_U)/xxd.1
-rm -f $(DEST_MAN_IT)/xxd.1 $(DEST_MAN_IT_I)/xxd.1 $(DEST_MAN_IT_U)/xxd.1
-rm -f $(DEST_MAN_PL)/xxd.1 $(DEST_MAN_PL_I)/xxd.1 $(DEST_MAN_PL_U)/xxd.1
-rm -f $(DEST_MAN_RU)/xxd.1 $(DEST_MAN_RU_U)/xxd.1
-rm -f $(DEST_HELP)/*.txt $(DEST_HELP)/tags $(DEST_HELP)/*.pl
-rm -f $(DEST_HELP)/*.??x $(DEST_HELP)/tags-??
-rm -f $(SYS_MENU_FILE) $(SYS_SYNMENU_FILE) $(SYS_DELMENU_FILE)
-rm -f $(SYS_BUGR_FILE) $(EVIM_FILE) $(MSWIN_FILE)
-rm -f $(DEST_SCRIPT)/gvimrc_example.vim $(DEST_SCRIPT)/vimrc_example.vim
-rm -f $(SYS_FILETYPE_FILE) $(SYS_FTOFF_FILE) $(SYS_SCRIPTS_FILE)
-rm -f $(SYS_INDOFF_FILE) $(SYS_INDENT_FILE)
-rm -f $(SYS_FTPLUGOF_FILE) $(SYS_FTPLUGIN_FILE)
-rm -f $(SYS_OPTWIN_FILE)
-rm -f $(DEST_COL)/*.vim $(DEST_COL)/README.txt
-rm -f $(DEST_SYN)/*.vim $(DEST_SYN)/README.txt
-rm -f $(DEST_IND)/*.vim $(DEST_IND)/README.txt
-rm -rf $(DEST_MACRO)
-rm -rf $(DEST_TUTOR)
-rm -rf $(DEST_SPELL)
-rm -rf $(DEST_TOOLS)
-rm -rf $(DEST_LANG)
-rm -rf $(DEST_KMAP)
-rm -rf $(DEST_COMP)
-rm -f $(DEST_PRINT)/*.ps
-rmdir $(DEST_HELP) $(DEST_PRINT) $(DEST_COL) $(DEST_SYN) $(DEST_IND)
-rm -rf $(DEST_FTP)/*.vim $(DEST_FTP)/README.txt
-rm -f $(DEST_AUTO)/*.vim $(DEST_AUTO)/README.txt $(DEST_AUTO)/xml/*.vim
-rm -f $(DEST_PLUG)/*.vim $(DEST_PLUG)/README.txt
-rmdir $(DEST_FTP) $(DEST_AUTO)/xml $(DEST_AUTO) $(DEST_PLUG) $(DEST_RT)
# This will fail when other Vim versions are installed, no worries.
-rmdir $(DEST_VIM)
 
# Clean up all the files that have been produced, except configure's.
# We support common typing mistakes for Juergen! :-)
clean celan: testclean
-rm -f *.o objects/* core $(VIMTARGET).core $(VIMTARGET) vim xxd/*.o
-rm -f $(TOOLS) auto/osdef.h auto/pathdef.c auto/if_perl.c
-rm -f conftest* *~ auto/link.sed
-rm -rf $(APPDIR)
if test -d $(PODIR); then \
cd $(PODIR); $(MAKE) prefix=$(DESTDIR)$(prefix) clean; \
fi
 
# Make a shadow directory for compilation on another system or with different
# features.
SHADOWDIR = shadow
 
shadow: runtime pixmaps
mkdir $(SHADOWDIR)
cd $(SHADOWDIR); ln -s ../*.[ch] ../*.in ../*.sh ../*.xs ../*.xbm ../toolcheck ../proto ../vimtutor ../mkinstalldirs .
mkdir $(SHADOWDIR)/auto
cd $(SHADOWDIR)/auto; ln -s ../../auto/configure .
cd $(SHADOWDIR); rm -f auto/link.sed
cp Makefile configure $(SHADOWDIR)
rm -f $(SHADOWDIR)/auto/config.mk $(SHADOWDIR)/config.mk.dist
cp config.mk.dist $(SHADOWDIR)/auto/config.mk
cp config.mk.dist $(SHADOWDIR)
mkdir $(SHADOWDIR)/xxd
cd $(SHADOWDIR)/xxd; ln -s ../../xxd/*.[ch] ../../xxd/Make* .
if test -d $(RSRC_DIR); then \
cd $(SHADOWDIR); \
ln -s ../infplist.xml .; \
ln -s ../$(RSRC_DIR) ../os_mac.rsr.hqx ../dehqx.py .; \
fi
mkdir $(SHADOWDIR)/testdir
cd $(SHADOWDIR)/testdir; ln -s ../../testdir/Makefile \
../../testdir/vimrc.unix \
../../testdir/*.in \
../../testdir/unix.vim \
../../testdir/*.ok .
 
# Link needed for doing "make install" in a shadow directory.
runtime:
-ln -s ../runtime .
 
# Link needed for doing "make" using GTK in a shadow directory.
pixmaps:
-ln -s ../pixmaps .
 
# Update the synmenu.vim file with the latest Syntax menu.
# This is only needed when runtime/makemenu.vim was changed.
menu: ./vim ../runtime/makemenu.vim
./vim -u ../runtime/makemenu.vim
 
# Start configure from scratch
scrub scratch:
-rm -f auto/config.status auto/config.cache config.log auto/config.log
-rm -f auto/config.h auto/link.log auto/link.sed auto/config.mk
touch auto/config.h
cp config.mk.dist auto/config.mk
 
distclean: clean scratch
-rm -f tags
 
dist: distclean
@echo
@echo Making the distribution has to be done in the top directory
 
mdepend:
-@rm -f Makefile~
cp Makefile Makefile~
sed -e '/\#\#\# Dependencies/q' < Makefile > tmp_make
@for i in $(ALL_SRC) ; do \
echo "$$i" ; \
echo `echo "$$i" | sed -e 's/[^ ]*\.c$$/objects\/\1.o/'`": $$i" `\
$(CPP) $$i |\
grep '^# .*"\./.*\.h"' |\
sort -t'"' -u +1 -2 |\
sed -e 's/.*"\.\/\(.*\)".*/\1/'\
` >> tmp_make ; \
done
mv tmp_make Makefile
 
depend:
-@rm -f Makefile~
cp Makefile Makefile~
sed -e '/\#\#\# Dependencies/q' < Makefile > tmp_make
-for i in $(ALL_SRC); do echo $$i; \
$(CPP_DEPEND) $$i | \
sed -e 's+^\([^ ]*\.o\)+objects/\1+' >> tmp_make; done
mv tmp_make Makefile
 
# Run lint. Clean up the *.ln files that are sometimes left behind.
lint:
lint $(LINT_OPTIONS) $(LINT_CFLAGS) $(LINT_EXTRA) $(LINT_SRC)
-rm -f *.ln
 
# Check dosinst.c with lint.
lintinstall:
lint $(LINT_OPTIONS) -DWIN32 -DUNIX_LINT dosinst.c
-rm -f dosinst.ln
 
###########################################################################
 
.c.o:
$(CCC) $<
 
auto/if_perl.c: if_perl.xs
$(PERL) -e 'unless ( $$] >= 5.005 ) { for (qw(na defgv errgv)) { print "#define PL_$$_ $$_\n" }}' > $@
$(PERL) $(PERLLIB)/ExtUtils/xsubpp -prototypes -typemap \
$(PERLLIB)/ExtUtils/typemap if_perl.xs >> $@
 
auto/osdef.h: auto/config.h osdef.sh osdef1.h.in osdef2.h.in
CC="$(CC) $(OSDEF_CFLAGS)" srcdir=$(srcdir) sh $(srcdir)/osdef.sh
 
QUOTESED = sed -e 's/[\\"]/\\&/g' -e 's/\\"/"/' -e 's/\\";$$/";/'
auto/pathdef.c: Makefile auto/config.mk
-@echo creating $@
-@echo '/* pathdef.c */' > $@
-@echo '/* This file is automatically created by Makefile' >> $@
-@echo ' * DO NOT EDIT! Change Makefile only. */' >> $@
-@echo '#include "vim.h"' >> $@
-@echo 'char_u *default_vim_dir = (char_u *)"$(VIMRCLOC)";' | $(QUOTESED) >> $@
-@echo 'char_u *default_vimruntime_dir = (char_u *)"$(VIMRUNTIMEDIR)";' | $(QUOTESED) >> $@
-@echo 'char_u *all_cflags = (char_u *)"$(CC) -c -I$(srcdir) $(ALL_CFLAGS)";' | $(QUOTESED) >> $@
-@echo 'char_u *all_lflags = (char_u *)"$(CC) $(ALL_LIB_DIRS) $(LDFLAGS) -o $(VIMTARGET) $(ALL_LIBS) ";' | $(QUOTESED) >> $@
-@echo 'char_u *compiled_user = (char_u *)"' | tr -d $(NL) >> $@
-@if test -n "$(COMPILEDBY)"; then \
echo "$(COMPILEDBY)" | tr -d $(NL) >> $@; \
else ((logname) 2>/dev/null || whoami) | tr -d $(NL) >> $@; fi
-@echo '";' >> $@
-@echo 'char_u *compiled_sys = (char_u *)"' | tr -d $(NL) >> $@
-@if test -z "$(COMPILEDBY)"; then hostname | tr -d $(NL) >> $@; fi
-@echo '";' >> $@
-@sh $(srcdir)/pathdef.sh
 
# All the object files are put in the "objects" directory. Since not all make
# commands understand putting object files in another directory, it must be
# specified for each file separately.
 
objects:
mkdir objects
 
objects/buffer.o: buffer.c
$(CCC) -o $@ buffer.c
 
objects/charset.o: charset.c
$(CCC) -o $@ charset.c
 
objects/diff.o: diff.c
$(CCC) -o $@ diff.c
 
objects/digraph.o: digraph.c
$(CCC) -o $@ digraph.c
 
objects/edit.o: edit.c
$(CCC) -o $@ edit.c
 
objects/eval.o: eval.c
$(CCC) -o $@ eval.c
 
objects/ex_cmds.o: ex_cmds.c
$(CCC) -o $@ ex_cmds.c
 
objects/ex_cmds2.o: ex_cmds2.c
$(CCC) -o $@ ex_cmds2.c
 
objects/ex_docmd.o: ex_docmd.c
$(CCC) -o $@ ex_docmd.c
 
objects/ex_eval.o: ex_eval.c
$(CCC) -o $@ ex_eval.c
 
objects/ex_getln.o: ex_getln.c
$(CCC) -o $@ ex_getln.c
 
objects/fileio.o: fileio.c
$(CCC) -o $@ fileio.c
 
objects/fold.o: fold.c
$(CCC) -o $@ fold.c
 
objects/getchar.o: getchar.c
$(CCC) -o $@ getchar.c
 
objects/hardcopy.o: hardcopy.c
$(CCC) -o $@ hardcopy.c
 
objects/hashtab.o: hashtab.c
$(CCC) -o $@ hashtab.c
 
objects/gui.o: gui.c
$(CCC) -o $@ gui.c
 
objects/gui_at_fs.o: gui_at_fs.c
$(CCC) -o $@ gui_at_fs.c
 
objects/gui_at_sb.o: gui_at_sb.c
$(CCC) -o $@ gui_at_sb.c
 
objects/gui_athena.o: gui_athena.c
$(CCC) -o $@ gui_athena.c
 
objects/gui_beval.o: gui_beval.c
$(CCC) -o $@ gui_beval.c
 
objects/gui_gtk.o: gui_gtk.c
$(CCC) -o $@ gui_gtk.c
 
objects/gui_gtk_f.o: gui_gtk_f.c
$(CCC) -o $@ gui_gtk_f.c
 
objects/gui_gtk_x11.o: gui_gtk_x11.c
$(CCC) -o $@ gui_gtk_x11.c
 
objects/gui_motif.o: gui_motif.c
$(CCC) -o $@ gui_motif.c
 
objects/gui_xmdlg.o: gui_xmdlg.c
$(CCC) -o $@ gui_xmdlg.c
 
objects/gui_xmebw.o: gui_xmebw.c
$(CCC) -o $@ gui_xmebw.c
 
objects/gui_x11.o: gui_x11.c
$(CCC) -o $@ gui_x11.c
 
objects/gui_photon.o: gui_photon.c
$(CCC) -o $@ gui_photon.c
 
objects/gui_mac.o: gui_mac.c
$(CCC) -o $@ gui_mac.c
 
objects/hangulin.o: hangulin.c
$(CCC) -o $@ hangulin.c
 
objects/if_cscope.o: if_cscope.c
$(CCC) -o $@ if_cscope.c
 
objects/if_xcmdsrv.o: if_xcmdsrv.c
$(CCC) -o $@ if_xcmdsrv.c
 
objects/if_mzsch.o: if_mzsch.c
$(CCC) -o $@ if_mzsch.c
 
objects/if_perl.o: auto/if_perl.c
$(CCC) -o $@ auto/if_perl.c
 
objects/if_perlsfio.o: if_perlsfio.c
$(CCC) -o $@ if_perlsfio.c
 
objects/if_python.o: if_python.c
$(CCC) -o $@ if_python.c
 
objects/if_ruby.o: if_ruby.c
$(CCC) -o $@ if_ruby.c
 
objects/if_sniff.o: if_sniff.c
$(CCC) -o $@ if_sniff.c
 
objects/if_tcl.o: if_tcl.c
$(CCC) -o $@ if_tcl.c
 
objects/integration.o: integration.c
$(CCC) -o $@ integration.c
 
objects/main.o: main.c
$(CCC) -o $@ main.c
 
objects/mark.o: mark.c
$(CCC) -o $@ mark.c
 
objects/memfile.o: memfile.c
$(CCC) -o $@ memfile.c
 
objects/memline.o: memline.c
$(CCC) -o $@ memline.c
 
objects/menu.o: menu.c
$(CCC) -o $@ menu.c
 
objects/message.o: message.c
$(CCC) -o $@ message.c
 
objects/misc1.o: misc1.c
$(CCC) -o $@ misc1.c
 
objects/misc2.o: misc2.c
$(CCC) -o $@ misc2.c
 
objects/move.o: move.c
$(CCC) -o $@ move.c
 
objects/mbyte.o: mbyte.c
$(CCC) -o $@ mbyte.c
 
objects/normal.o: normal.c
$(CCC) -o $@ normal.c
 
objects/ops.o: ops.c
$(CCC) -o $@ ops.c
 
objects/option.o: option.c
$(CCC) -o $@ option.c
 
objects/os_beos.o: os_beos.c
$(CCC) -o $@ os_beos.c
 
objects/os_qnx.o: os_qnx.c
$(CCC) -o $@ os_qnx.c
 
objects/os_macosx.o: os_macosx.c
$(CCC) -o $@ os_macosx.c
 
objects/os_mac_conv.o: os_mac_conv.c
$(CCC) -o $@ os_mac_conv.c
 
objects/os_unix.o: os_unix.c
$(CCC) -o $@ os_unix.c
 
objects/pathdef.o: auto/pathdef.c
$(CCC) -o $@ auto/pathdef.c
 
objects/py_config.o: $(PYTHON_CONFDIR)/config.c
$(CCC) -o $@ $(PYTHON_CONFDIR)/config.c \
-I$(PYTHON_CONFDIR) -DHAVE_CONFIG_H -DNO_MAIN
 
objects/py_getpath.o: $(PYTHON_CONFDIR)/getpath.c
$(CCC) -o $@ $(PYTHON_CONFDIR)/getpath.c \
-I$(PYTHON_CONFDIR) -DHAVE_CONFIG_H -DNO_MAIN \
$(PYTHON_GETPATH_CFLAGS)
 
objects/pty.o: pty.c
$(CCC) -o $@ pty.c
 
objects/popupmnu.o: popupmnu.c
$(CCC) -o $@ popupmnu.c
 
objects/quickfix.o: quickfix.c
$(CCC) -o $@ quickfix.c
 
objects/regexp.o: regexp.c
$(CCC) -o $@ regexp.c
 
objects/screen.o: screen.c
$(CCC) -o $@ screen.c
 
objects/search.o: search.c
$(CCC) -o $@ search.c
 
objects/spell.o: spell.c
$(CCC) -o $@ spell.c
 
objects/syntax.o: syntax.c
$(CCC) -o $@ syntax.c
 
objects/tag.o: tag.c
$(CCC) -o $@ tag.c
 
objects/term.o: term.c
$(CCC) -o $@ term.c
 
objects/ui.o: ui.c
$(CCC) -o $@ ui.c
 
objects/undo.o: undo.c
$(CCC) -o $@ undo.c
 
objects/window.o: window.c
$(CCC) -o $@ window.c
 
objects/workshop.o: workshop.c
$(CCC) -o $@ workshop.c
 
objects/wsdebug.o: wsdebug.c
$(CCC) -o $@ wsdebug.c
 
objects/netbeans.o: netbeans.c
$(CCC) -o $@ netbeans.c
 
Makefile:
@echo The name of the makefile MUST be "Makefile" (with capital M)!!!!
 
###############################################################################
### MacOS X installation
###
### This installs a runnable Vim.app in $(prefix)
 
REZ = /Developer/Tools/Rez
RESDIR = $(APPDIR)/Contents/Resources
VERSION = $(VIMMAJOR).$(VIMMINOR)
 
### Common flags
M4FLAGSX = $(M4FLAGS) -DAPP_EXE=$(VIMNAME) -DAPP_NAME=$(VIMNAME) \
-DAPP_VER=$(VERSION)
 
install_macosx: gui_bundle
# Remove the link to the runtime dir, don't want to copy all of that.
-rm $(RESDIR)/vim/runtime
$(INSTALL_DATA_R) $(APPDIR) $(DESTDIR)$(prefix)
# Generate the help tags file now, it won't work with "make installruntime".
-@srcdir=`pwd`; cd $(HELPSOURCE); $(MAKE) VIMEXE=$$srcdir/$(VIMTARGET) vimtags
# Install the runtime files. Recursive!
-mkdir -p $(DESTDIR)$(prefix)/$(RESDIR)/vim/runtime
# -mkdir $(DESTDIR)$(prefix)/$(APPDIR)/bin
srcdir=`pwd`; $(MAKE) -f Makefile installruntime \
VIMEXE=$$srcdir/$(VIMTARGET) \
prefix=$(DESTDIR)$(prefix)/$(RESDIR)/vim \
VIMRTLOC=$(DESTDIR)$(prefix)/$(RESDIR)/vim/runtime
# Put the link back.
ln -s `pwd`/../runtime $(RESDIR)/vim
# Copy rgb.txt, Mac doesn't always have X11
$(INSTALL_DATA) $(SCRIPTSOURCE)/rgb.txt $(DESTDIR)$(prefix)/$(RESDIR)/vim/runtime
# TODO: Create the vimtutor application.
 
gui_bundle: $(RESDIR) bundle-dir bundle-executable bundle-info bundle-resource \
bundle-language
 
$(RESDIR):
mkdir -p $@
 
bundle-dir: $(APPDIR)/Contents $(VIMTARGET)
# Make a link to the runtime directory, so that we can try out the executable
# without installing it.
mkdir -p $(RESDIR)/vim
-ln -s `pwd`/../runtime $(RESDIR)/vim
 
bundle-executable: $(VIMTARGET)
mkdir -p $(APPDIR)/Contents/MacOS
cp $(VIMTARGET) $(APPDIR)/Contents/MacOS/$(VIMTARGET)
 
bundle-info: bundle-dir
@echo "Creating PkgInfo"
@echo -n "APPLVIM!" > $(APPDIR)/Contents/PkgInfo
@echo "Creating Info.plist"
m4 $(M4FLAGSX) infplist.xml > $(APPDIR)/Contents/Info.plist
 
bundle-resource: bundle-dir bundle-rsrc
cp -f $(RSRC_DIR)/*.icns $(RESDIR)
 
### Classic resources
# Resource fork (in the form of a .rsrc file) for Classic Vim (Mac OS 9)
# This file is also required for OS X Vim.
bundle-rsrc: os_mac.rsr.hqx
@echo "Creating resource fork"
python dehqx.py $<
rm -f gui_mac.rsrc
mv gui_mac.rsrc.rsrcfork $(RESDIR)/$(VIMNAME).rsrc
 
# po/Make_osx.pl says something about generating a Mac message file
# for Ukrananian. Would somebody using Mac OS X in Ukranian
# *really* be upset that Carbon Vim was not localised in
# Ukranian?
#
#bundle-language: bundle-dir po/Make_osx.pl
# cd po && perl Make_osx.pl --outdir ../$(RESDIR) $(MULTILANG)
bundle-language: bundle-dir
 
$(APPDIR)/Contents:
-$(SHELL) ./mkinstalldirs $(APPDIR)/Contents/MacOS
-$(SHELL) ./mkinstalldirs $(RESDIR)/English.lproj
 
 
###############################################################################
### (automatically generated by 'make depend')
### Dependencies:
objects/buffer.o: buffer.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h version.h
objects/charset.o: charset.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/diff.o: diff.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/digraph.o: digraph.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/edit.o: edit.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/eval.o: eval.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h version.h
objects/ex_cmds.o: ex_cmds.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h version.h
objects/ex_cmds2.o: ex_cmds2.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h version.h
objects/ex_docmd.o: ex_docmd.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h
objects/ex_eval.o: ex_eval.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/ex_getln.o: ex_getln.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h
objects/fileio.o: fileio.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/fold.o: fold.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/getchar.o: getchar.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/hardcopy.o: hardcopy.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h version.h
objects/hashtab.o: hashtab.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/if_cscope.o: if_cscope.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h if_cscope.h
objects/if_xcmdsrv.o: if_xcmdsrv.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h version.h
objects/main.o: main.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h farsi.c arabic.c
objects/mark.o: mark.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/memfile.o: memfile.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/memline.o: memline.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/menu.o: menu.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/message.o: message.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/misc1.o: misc1.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h version.h
objects/misc2.o: misc2.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/move.o: move.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/mbyte.o: mbyte.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/normal.o: normal.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/ops.o: ops.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h ascii.h \
keymap.h term.h macros.h option.h structs.h regexp.h gui.h gui_beval.h \
proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h arabic.h
objects/option.o: option.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/os_unix.o: os_unix.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h if_mzsch.h os_unixx.h
objects/pathdef.o: auto/pathdef.c ./vim.h ./auto/config.h ./feature.h ./os_unix.h \
./auto/osdef.h ./ascii.h ./keymap.h ./term.h ./macros.h ./option.h \
./structs.h ./regexp.h ./gui.h ./gui_beval.h proto/gui_beval.pro \
./ex_cmds.h ./proto.h ./globals.h ./farsi.h ./arabic.h
objects/popupmnu.o: popupmnu.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h
objects/quickfix.o: quickfix.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h
objects/regexp.o: regexp.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/screen.o: screen.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/search.o: search.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/spell.o: spell.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/syntax.o: syntax.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/tag.o: tag.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h ascii.h \
keymap.h term.h macros.h option.h structs.h regexp.h gui.h gui_beval.h \
proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h arabic.h
objects/term.o: term.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/ui.o: ui.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h ascii.h \
keymap.h term.h macros.h option.h structs.h regexp.h gui.h gui_beval.h \
proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h arabic.h
objects/undo.o: undo.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/version.o: version.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h version.h
objects/window.o: window.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/gui.o: gui.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h ascii.h \
keymap.h term.h macros.h option.h structs.h regexp.h gui.h gui_beval.h \
proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h arabic.h
objects/gui_gtk.o: gui_gtk.c gui_gtk_f.h vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h ../pixmaps/stock_icons.h
objects/gui_gtk_f.o: gui_gtk_f.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_gtk_f.h
objects/gui_motif.o: gui_motif.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_xmebw.h ../pixmaps/alert.xpm \
../pixmaps/error.xpm ../pixmaps/generic.xpm ../pixmaps/info.xpm \
../pixmaps/quest.xpm gui_x11_pm.h ../pixmaps/tb_new.xpm \
../pixmaps/tb_open.xpm ../pixmaps/tb_close.xpm ../pixmaps/tb_save.xpm \
../pixmaps/tb_print.xpm ../pixmaps/tb_cut.xpm ../pixmaps/tb_copy.xpm \
../pixmaps/tb_paste.xpm ../pixmaps/tb_find.xpm \
../pixmaps/tb_find_next.xpm ../pixmaps/tb_find_prev.xpm \
../pixmaps/tb_find_help.xpm ../pixmaps/tb_exit.xpm \
../pixmaps/tb_undo.xpm ../pixmaps/tb_redo.xpm ../pixmaps/tb_help.xpm \
../pixmaps/tb_macro.xpm ../pixmaps/tb_make.xpm \
../pixmaps/tb_save_all.xpm ../pixmaps/tb_jump.xpm \
../pixmaps/tb_ctags.xpm ../pixmaps/tb_load_session.xpm \
../pixmaps/tb_save_session.xpm ../pixmaps/tb_new_session.xpm \
../pixmaps/tb_blank.xpm ../pixmaps/tb_maximize.xpm \
../pixmaps/tb_split.xpm ../pixmaps/tb_minimize.xpm \
../pixmaps/tb_shell.xpm ../pixmaps/tb_replace.xpm \
../pixmaps/tb_vsplit.xpm ../pixmaps/tb_maxwidth.xpm \
../pixmaps/tb_minwidth.xpm
objects/gui_xmdlg.o: gui_xmdlg.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h
objects/gui_xmebw.o: gui_xmebw.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_xmebwp.h gui_xmebw.h
objects/gui_athena.o: gui_athena.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_at_sb.h gui_x11_pm.h \
../pixmaps/tb_new.xpm ../pixmaps/tb_open.xpm ../pixmaps/tb_close.xpm \
../pixmaps/tb_save.xpm ../pixmaps/tb_print.xpm ../pixmaps/tb_cut.xpm \
../pixmaps/tb_copy.xpm ../pixmaps/tb_paste.xpm ../pixmaps/tb_find.xpm \
../pixmaps/tb_find_next.xpm ../pixmaps/tb_find_prev.xpm \
../pixmaps/tb_find_help.xpm ../pixmaps/tb_exit.xpm \
../pixmaps/tb_undo.xpm ../pixmaps/tb_redo.xpm ../pixmaps/tb_help.xpm \
../pixmaps/tb_macro.xpm ../pixmaps/tb_make.xpm \
../pixmaps/tb_save_all.xpm ../pixmaps/tb_jump.xpm \
../pixmaps/tb_ctags.xpm ../pixmaps/tb_load_session.xpm \
../pixmaps/tb_save_session.xpm ../pixmaps/tb_new_session.xpm \
../pixmaps/tb_blank.xpm ../pixmaps/tb_maximize.xpm \
../pixmaps/tb_split.xpm ../pixmaps/tb_minimize.xpm \
../pixmaps/tb_shell.xpm ../pixmaps/tb_replace.xpm \
../pixmaps/tb_vsplit.xpm ../pixmaps/tb_maxwidth.xpm \
../pixmaps/tb_minwidth.xpm
objects/gui_gtk_x11.o: gui_gtk_x11.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_gtk_f.h ../runtime/vim32x32.xpm \
../runtime/vim16x16.xpm ../runtime/vim48x48.xpm
objects/gui_x11.o: gui_x11.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h ../runtime/vim32x32.xpm ../runtime/vim16x16.xpm \
../runtime/vim48x48.xpm
objects/gui_at_sb.o: gui_at_sb.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_at_sb.h
objects/gui_at_fs.o: gui_at_fs.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h gui_at_sb.h
objects/pty.o: pty.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h ascii.h \
keymap.h term.h macros.h option.h structs.h regexp.h gui.h gui_beval.h \
proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h arabic.h
objects/hangulin.o: hangulin.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h
objects/if_mzsch.o: if_mzsch.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h if_mzsch.h
objects/if_perl.o: auto/if_perl.c ./vim.h ./auto/config.h ./feature.h ./os_unix.h \
./auto/osdef.h ./ascii.h ./keymap.h ./term.h ./macros.h ./option.h \
./structs.h ./regexp.h ./gui.h ./gui_beval.h proto/gui_beval.pro \
./ex_cmds.h ./proto.h ./globals.h ./farsi.h ./arabic.h
objects/if_perlsfio.o: if_perlsfio.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h
objects/if_python.o: if_python.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h
objects/if_tcl.o: if_tcl.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h
objects/if_ruby.o: if_ruby.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h version.h
objects/if_sniff.o: if_sniff.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h os_unixx.h
objects/gui_beval.o: gui_beval.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h
objects/workshop.o: workshop.c auto/config.h integration.h vim.h feature.h \
os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h \
structs.h regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h \
proto.h globals.h farsi.h arabic.h version.h workshop.h
objects/wsdebug.o: wsdebug.c
objects/integration.o: integration.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h integration.h
objects/netbeans.o: netbeans.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
globals.h farsi.h arabic.h version.h
/ports/branches/tendra/editors/vim/files/ascii.h
0,0 → 1,193
/* vi:set ts=8 sts=4 sw=4:
*
* 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.
*/
 
/*
* Definitions of various common control characters.
* For EBCDIC we have to use different values.
*/
 
#ifndef EBCDIC
 
/* IF_EB(ASCII_constant, EBCDIC_constant) */
#define IF_EB(a, b) a
 
#define CharOrd(x) ((x) < 'a' ? (x) - 'A' : (x) - 'a')
#define CharOrdLow(x) ((x) - 'a')
#define CharOrdUp(x) ((x) - 'A')
#define ROT13(c, a) (((((c) - (a)) + 13) % 26) + (a))
 
#define NUL '\000'
#define BELL '\007'
#define BS '\010'
#define TAB '\011'
#define NL '\012'
#define NL_STR (char_u *)"\012"
#define FF '\014'
#define CAR '\015' /* CR is used by Mac OS X */
#define ESC '\033'
#define ESC_STR (char_u *)"\033"
#define ESC_STR_nc "\033"
#define DEL 0x7f
#define DEL_STR (char_u *)"\177"
#define CSI 0x9b /* Control Sequence Introducer */
#define CSI_STR "\233"
#define DCS 0x90 /* Device Control String */
#define STERM 0x9c /* String Terminator */
 
#define POUND 0xA3
 
#define Ctrl_chr(x) (TOUPPER_ASC(x) ^ 0x40) /* '?' -> DEL, '@' -> ^@, etc. */
#define Meta(x) ((x) | 0x80)
 
#define CTRL_F_STR "\006"
#define CTRL_H_STR "\010"
#define CTRL_V_STR "\026"
 
#define Ctrl_AT 0 /* @ */
#define Ctrl_A 1
#define Ctrl_B 2
#define Ctrl_C 3
#define Ctrl_D 4
#define Ctrl_E 5
#define Ctrl_F 6
#define Ctrl_G 7
#define Ctrl_H 8
#define Ctrl_I 9
#define Ctrl_J 10
#define Ctrl_K 11
#define Ctrl_L 12
#define Ctrl_M 13
#define Ctrl_N 14
#define Ctrl_O 15
#define Ctrl_P 16
#define Ctrl_Q 17
#define Ctrl_R 18
#define Ctrl_S 19
#define Ctrl_T 20
#define Ctrl_U 21
#define Ctrl_V 22
#define Ctrl_W 23
#define Ctrl_X 24
#define Ctrl_Y 25
#define Ctrl_Z 26
/* CTRL- [ Left Square Bracket == ESC*/
#define Ctrl_BSL 28 /* \ BackSLash */
#define Ctrl_RSB 29 /* ] Right Square Bracket */
#define Ctrl_HAT 30 /* ^ */
#define Ctrl__ 31
 
#else
 
/* EBCDIC */
 
/* IF_EB(ASCII_constant, EBCDIC_constant) */
#define IF_EB(a, b) b
 
/*
* Finding the position in the alphabet is not straightforward in EBCDIC.
* There are gaps in the code table.
* 'a' + 1 == 'b', but: 'i' + 7 == 'j' and 'r' + 8 == 's'
*/
#define CharOrd__(c) ((c) < ('j' - 'a') ? (c) : ((c) < ('s' - 'a') ? (c) - 7 : (c) - 7 - 8))
#define CharOrdLow(x) (CharOrd__((x) - 'a'))
#define CharOrdUp(x) (CharOrd__((x) - 'A'))
#define CharOrd(x) (isupper(x) ? CharOrdUp(x) : CharOrdLow(x))
 
#define EBCDIC_CHAR_ADD_(x) ((x) < 0?'a':(x)>25?'z':"abcdefghijklmnopqrstuvwxyz"[x])
#define EBCDIC_CHAR_ADD(c,s) (isupper(c) ? toupper(EBCDIC_CHAR_ADD_(CharOrdUp(c)+(s))) : EBCDIC_CHAR_ADD_(CharOrdLow(c)+(s)))
 
#define R13_(c) ("abcdefghijklmnopqrstuvwxyz"[((c) + 13) % 26])
#define ROT13(c, a) (isupper(c) ? toupper(R13_(CharOrdUp(c))) : R13_(CharOrdLow(c)))
 
#define NUL '\000'
#define BELL '\x2f'
#define BS '\x16'
#define TAB '\x05'
#define NL '\x15'
#define NL_STR (char_u *)"\x15"
#define FF '\x0C'
#define CAR '\x0D'
#define ESC '\x27'
#define ESC_STR (char_u *)"\x27"
#define ESC_STR_nc "\x27"
#define DEL 0x07
#define DEL_STR (char_u *)"\007"
/* TODO: EBCDIC Code page dependent (here 1047) */
#define CSI 0x9b /* Control Sequence Introducer */
#define CSI_STR "\233"
#define DCS 0x90 /* Device Control String */
#define STERM 0x9c /* String Terminator */
 
#define POUND 0xa3 /* Pound sign */
 
#define CTRL_F_STR "\056"
#define CTRL_H_STR "\026"
#define CTRL_V_STR "\062"
 
#define Ctrl_AT 0x00 /* @ */
#define Ctrl_A 0x01
#define Ctrl_B 0x02
#define Ctrl_C 0x03
#define Ctrl_D 0x37
#define Ctrl_E 0x2D
#define Ctrl_F 0x2E
#define Ctrl_G 0x2F
#define Ctrl_H 0x16
#define Ctrl_I 0x05
#define Ctrl_J 0x15
#define Ctrl_K 0x0B
#define Ctrl_L 0x0C
#define Ctrl_M 0x0D
#define Ctrl_N 0x0E
#define Ctrl_O 0x0F
#define Ctrl_P 0x10
#define Ctrl_Q 0x11
#define Ctrl_R 0x12
#define Ctrl_S 0x13
#define Ctrl_T 0x3C
#define Ctrl_U 0x3D
#define Ctrl_V 0x32
#define Ctrl_W 0x26
#define Ctrl_X 0x18
#define Ctrl_Y 0x19
#define Ctrl_Z 0x3F
/* CTRL- [ Left Square Bracket == ESC*/
#define Ctrl_RSB 0x1D /* ] Right Square Bracket */
#define Ctrl_BSL 0x1C /* \ BackSLash */
#define Ctrl_HAT 0x1E /* ^ */
#define Ctrl__ 0x1F
 
#define Ctrl_chr(x) (CtrlTable[(x)])
extern char CtrlTable[];
 
#define CtrlChar(x) ((x < ' ') ? CtrlCharTable[(x)] : 0)
extern char CtrlCharTable[];
 
#define MetaChar(x) ((x < ' ') ? MetaCharTable[(x)] : 0)
extern char MetaCharTable[];
 
#endif /* defined EBCDIC */
 
/*
* Character that separates dir names in a path.
* For MS-DOS, WIN32 and OS/2 we use a backslash. A slash mostly works
* fine, but there are places where it doesn't (e.g. in a command name).
* For Acorn we use a dot.
*/
#ifdef BACKSLASH_IN_FILENAME
# define PATHSEP psepc
# define PATHSEPSTR pseps
#else
# ifdef RISCOS
# define PATHSEP '.'
# define PATHSEPSTR "."
# else
# define PATHSEP '/'
# define PATHSEPSTR "/"
# endif
#endif
/ports/branches/tendra/editors/vim/files/charset.c
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/ports/branches/tendra/editors/vim/files/eval.c
0,0 → 1,21309
/* vi:set ts=8 sts=4 sw=4:
*
* 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.
* See README.txt for an overview of the Vim source code.
*/
 
/*
* eval.c: Expression evaluation.
*/
#if defined(MSDOS) || defined(MSWIN)
# include "vimio.h" /* for mch_open(), must be before vim.h */
#endif
 
#include "vim.h"
 
#ifdef AMIGA
# include <time.h> /* for strftime() */
#endif
 
#ifdef MACOS
# include <time.h> /* for time_t */
#endif
 
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
 
#if defined(FEAT_EVAL) || defined(PROTO)
 
#define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */
 
/*
* In a hashtab item "hi_key" points to "di_key" in a dictitem.
* This avoids adding a pointer to the hashtab item.
* DI2HIKEY() converts a dictitem pointer to a hashitem key pointer.
* HIKEY2DI() converts a hashitem key pointer to a dictitem pointer.
* HI2DI() converts a hashitem pointer to a dictitem pointer.
*/
static dictitem_T dumdi;
#define DI2HIKEY(di) ((di)->di_key)
#define HIKEY2DI(p) ((dictitem_T *)(p - (dumdi.di_key - (char_u *)&dumdi)))
#define HI2DI(hi) HIKEY2DI((hi)->hi_key)
 
/*
* Structure returned by get_lval() and used by set_var_lval().
* For a plain name:
* "name" points to the variable name.
* "exp_name" is NULL.
* "tv" is NULL
* For a magic braces name:
* "name" points to the expanded variable name.
* "exp_name" is non-NULL, to be freed later.
* "tv" is NULL
* For an index in a list:
* "name" points to the (expanded) variable name.
* "exp_name" NULL or non-NULL, to be freed later.
* "tv" points to the (first) list item value
* "li" points to the (first) list item
* "range", "n1", "n2" and "empty2" indicate what items are used.
* For an existing Dict item:
* "name" points to the (expanded) variable name.
* "exp_name" NULL or non-NULL, to be freed later.
* "tv" points to the dict item value
* "newkey" is NULL
* For a non-existing Dict item:
* "name" points to the (expanded) variable name.
* "exp_name" NULL or non-NULL, to be freed later.
* "tv" points to the Dictionary typval_T
* "newkey" is the key for the new item.
*/
typedef struct lval_S
{
char_u *ll_name; /* start of variable name (can be NULL) */
char_u *ll_exp_name; /* NULL or expanded name in allocated memory. */
typval_T *ll_tv; /* Typeval of item being used. If "newkey"
isn't NULL it's the Dict to which to add
the item. */
listitem_T *ll_li; /* The list item or NULL. */
list_T *ll_list; /* The list or NULL. */
int ll_range; /* TRUE when a [i:j] range was used */
long ll_n1; /* First index for list */
long ll_n2; /* Second index for list range */
int ll_empty2; /* Second index is empty: [i:] */
dict_T *ll_dict; /* The Dictionary or NULL */
dictitem_T *ll_di; /* The dictitem or NULL */
char_u *ll_newkey; /* New key for Dict in alloc. mem or NULL. */
} lval_T;
 
 
static char *e_letunexp = N_("E18: Unexpected characters in :let");
static char *e_listidx = N_("E684: list index out of range: %ld");
static char *e_undefvar = N_("E121: Undefined variable: %s");
static char *e_missbrac = N_("E111: Missing ']'");
static char *e_listarg = N_("E686: Argument of %s must be a List");
static char *e_listdictarg = N_("E712: Argument of %s must be a List or Dictionary");
static char *e_emptykey = N_("E713: Cannot use empty key for Dictionary");
static char *e_listreq = N_("E714: List required");
static char *e_dictreq = N_("E715: Dictionary required");
static char *e_toomanyarg = N_("E118: Too many arguments for function: %s");
static char *e_dictkey = N_("E716: Key not present in Dictionary: %s");
static char *e_funcexts = N_("E122: Function %s already exists, add ! to replace it");
static char *e_funcdict = N_("E717: Dictionary entry already exists");
static char *e_funcref = N_("E718: Funcref required");
static char *e_dictrange = N_("E719: Cannot use [:] with a Dictionary");
static char *e_letwrong = N_("E734: Wrong variable type for %s=");
static char *e_nofunc = N_("E130: Unknown function: %s");
static char *e_illvar = N_("E461: Illegal variable name: %s");
/*
* All user-defined global variables are stored in dictionary "globvardict".
* "globvars_var" is the variable that is used for "g:".
*/
static dict_T globvardict;
static dictitem_T globvars_var;
#define globvarht globvardict.dv_hashtab
 
/*
* Old Vim variables such as "v:version" are also available without the "v:".
* Also in functions. We need a special hashtable for them.
*/
static hashtab_T compat_hashtab;
 
/*
* When recursively copying lists and dicts we need to remember which ones we
* have done to avoid endless recursiveness. This unique ID is used for that.
*/
static int current_copyID = 0;
 
/*
* Array to hold the hashtab with variables local to each sourced script.
* Each item holds a variable (nameless) that points to the dict_T.
*/
typedef struct
{
dictitem_T sv_var;
dict_T sv_dict;
} scriptvar_T;
 
static garray_T ga_scripts = {0, 0, sizeof(scriptvar_T), 4, NULL};
#define SCRIPT_SV(id) (((scriptvar_T *)ga_scripts.ga_data)[(id) - 1])
#define SCRIPT_VARS(id) (SCRIPT_SV(id).sv_dict.dv_hashtab)
 
static int echo_attr = 0; /* attributes used for ":echo" */
 
/* Values for trans_function_name() argument: */
#define TFN_INT 1 /* internal function name OK */
#define TFN_QUIET 2 /* no error messages */
 
/*
* Structure to hold info for a user function.
*/
typedef struct ufunc ufunc_T;
 
struct ufunc
{
int uf_varargs; /* variable nr of arguments */
int uf_flags;
int uf_calls; /* nr of active calls */
garray_T uf_args; /* arguments */
garray_T uf_lines; /* function lines */
#ifdef FEAT_PROFILE
int uf_profiling; /* TRUE when func is being profiled */
/* profiling the function as a whole */
int uf_tm_count; /* nr of calls */
proftime_T uf_tm_total; /* time spend in function + children */
proftime_T uf_tm_self; /* time spend in function itself */
proftime_T uf_tm_children; /* time spent in children this call */
/* profiling the function per line */
int *uf_tml_count; /* nr of times line was executed */
proftime_T *uf_tml_total; /* time spend in a line + children */
proftime_T *uf_tml_self; /* time spend in a line itself */
proftime_T uf_tml_start; /* start time for current line */
proftime_T uf_tml_children; /* time spent in children for this line */
proftime_T uf_tml_wait; /* start wait time for current line */
int uf_tml_idx; /* index of line being timed; -1 if none */
int uf_tml_execed; /* line being timed was executed */
#endif
scid_T uf_script_ID; /* ID of script where function was defined,
used for s: variables */
int uf_refcount; /* for numbered function: reference count */
char_u uf_name[1]; /* name of function (actually longer); can
start with <SNR>123_ (<SNR> is K_SPECIAL
KS_EXTRA KE_SNR) */
};
 
/* function flags */
#define FC_ABORT 1 /* abort function on error */
#define FC_RANGE 2 /* function accepts range */
#define FC_DICT 4 /* Dict function, uses "self" */
 
/*
* All user-defined functions are found in this hashtable.
*/
static hashtab_T func_hashtab;
 
/* The names of packages that once were loaded are remembered. */
static garray_T ga_loaded = {0, 0, sizeof(char_u *), 4, NULL};
 
/* list heads for garbage collection */
static dict_T *first_dict = NULL; /* list of all dicts */
static list_T *first_list = NULL; /* list of all lists */
 
/* From user function to hashitem and back. */
static ufunc_T dumuf;
#define UF2HIKEY(fp) ((fp)->uf_name)
#define HIKEY2UF(p) ((ufunc_T *)(p - (dumuf.uf_name - (char_u *)&dumuf)))
#define HI2UF(hi) HIKEY2UF((hi)->hi_key)
 
#define FUNCARG(fp, j) ((char_u **)(fp->uf_args.ga_data))[j]
#define FUNCLINE(fp, j) ((char_u **)(fp->uf_lines.ga_data))[j]
 
#define MAX_FUNC_ARGS 20 /* maximum number of function arguments */
#define VAR_SHORT_LEN 20 /* short variable name length */
#define FIXVAR_CNT 12 /* number of fixed variables */
 
/* structure to hold info for a function that is currently being executed. */
typedef struct funccall_S funccall_T;
 
struct funccall_S
{
ufunc_T *func; /* function being called */
int linenr; /* next line to be executed */
int returned; /* ":return" used */
struct /* fixed variables for arguments */
{
dictitem_T var; /* variable (without room for name) */
char_u room[VAR_SHORT_LEN]; /* room for the name */
} fixvar[FIXVAR_CNT];
dict_T l_vars; /* l: local function variables */
dictitem_T l_vars_var; /* variable for l: scope */
dict_T l_avars; /* a: argument variables */
dictitem_T l_avars_var; /* variable for a: scope */
list_T l_varlist; /* list for a:000 */
listitem_T l_listitems[MAX_FUNC_ARGS]; /* listitems for a:000 */
typval_T *rettv; /* return value */
linenr_T breakpoint; /* next line with breakpoint or zero */
int dbg_tick; /* debug_tick when breakpoint was set */
int level; /* top nesting level of executed function */
#ifdef FEAT_PROFILE
proftime_T prof_child; /* time spent in a child */
#endif
funccall_T *caller; /* calling function or NULL */
};
 
/*
* Info used by a ":for" loop.
*/
typedef struct
{
int fi_semicolon; /* TRUE if ending in '; var]' */
int fi_varcount; /* nr of variables in the list */
listwatch_T fi_lw; /* keep an eye on the item used. */
list_T *fi_list; /* list being used */
} forinfo_T;
 
/*
* Struct used by trans_function_name()
*/
typedef struct
{
dict_T *fd_dict; /* Dictionary used */
char_u *fd_newkey; /* new key in "dict" in allocated memory */
dictitem_T *fd_di; /* Dictionary item used */
} funcdict_T;
 
 
/*
* Array to hold the value of v: variables.
* The value is in a dictitem, so that it can also be used in the v: scope.
* The reason to use this table anyway is for very quick access to the
* variables with the VV_ defines.
*/
#include "version.h"
 
/* values for vv_flags: */
#define VV_COMPAT 1 /* compatible, also used without "v:" */
#define VV_RO 2 /* read-only */
#define VV_RO_SBX 4 /* read-only in the sandbox */
 
#define VV_NAME(s, t) s, {{t}}, {0}
 
static struct vimvar
{
char *vv_name; /* name of variable, without v: */
dictitem_T vv_di; /* value and name for key */
char vv_filler[16]; /* space for LONGEST name below!!! */
char vv_flags; /* VV_COMPAT, VV_RO, VV_RO_SBX */
} vimvars[VV_LEN] =
{
/*
* The order here must match the VV_ defines in vim.h!
* Initializing a union does not work, leave tv.vval empty to get zero's.
*/
{VV_NAME("count", VAR_NUMBER), VV_COMPAT+VV_RO},
{VV_NAME("count1", VAR_NUMBER), VV_RO},
{VV_NAME("prevcount", VAR_NUMBER), VV_RO},
{VV_NAME("errmsg", VAR_STRING), VV_COMPAT},
{VV_NAME("warningmsg", VAR_STRING), 0},
{VV_NAME("statusmsg", VAR_STRING), 0},
{VV_NAME("shell_error", VAR_NUMBER), VV_COMPAT+VV_RO},
{VV_NAME("this_session", VAR_STRING), VV_COMPAT},
{VV_NAME("version", VAR_NUMBER), VV_COMPAT+VV_RO},
{VV_NAME("lnum", VAR_NUMBER), VV_RO_SBX},
{VV_NAME("termresponse", VAR_STRING), VV_RO},
{VV_NAME("fname", VAR_STRING), VV_RO},
{VV_NAME("lang", VAR_STRING), VV_RO},
{VV_NAME("lc_time", VAR_STRING), VV_RO},
{VV_NAME("ctype", VAR_STRING), VV_RO},
{VV_NAME("charconvert_from", VAR_STRING), VV_RO},
{VV_NAME("charconvert_to", VAR_STRING), VV_RO},
{VV_NAME("fname_in", VAR_STRING), VV_RO},
{VV_NAME("fname_out", VAR_STRING), VV_RO},
{VV_NAME("fname_new", VAR_STRING), VV_RO},
{VV_NAME("fname_diff", VAR_STRING), VV_RO},
{VV_NAME("cmdarg", VAR_STRING), VV_RO},
{VV_NAME("foldstart", VAR_NUMBER), VV_RO_SBX},
{VV_NAME("foldend", VAR_NUMBER), VV_RO_SBX},
{VV_NAME("folddashes", VAR_STRING), VV_RO_SBX},
{VV_NAME("foldlevel", VAR_NUMBER), VV_RO_SBX},
{VV_NAME("progname", VAR_STRING), VV_RO},
{VV_NAME("servername", VAR_STRING), VV_RO},
{VV_NAME("dying", VAR_NUMBER), VV_RO},
{VV_NAME("exception", VAR_STRING), VV_RO},
{VV_NAME("throwpoint", VAR_STRING), VV_RO},
{VV_NAME("register", VAR_STRING), VV_RO},
{VV_NAME("cmdbang", VAR_NUMBER), VV_RO},
{VV_NAME("insertmode", VAR_STRING), VV_RO},
{VV_NAME("val", VAR_UNKNOWN), VV_RO},
{VV_NAME("key", VAR_UNKNOWN), VV_RO},
{VV_NAME("profiling", VAR_NUMBER), VV_RO},
{VV_NAME("fcs_reason", VAR_STRING), VV_RO},
{VV_NAME("fcs_choice", VAR_STRING), 0},
{VV_NAME("beval_bufnr", VAR_NUMBER), VV_RO},
{VV_NAME("beval_winnr", VAR_NUMBER), VV_RO},
{VV_NAME("beval_lnum", VAR_NUMBER), VV_RO},
{VV_NAME("beval_col", VAR_NUMBER), VV_RO},
{VV_NAME("beval_text", VAR_STRING), VV_RO},
{VV_NAME("scrollstart", VAR_STRING), 0},
{VV_NAME("swapname", VAR_STRING), VV_RO},
{VV_NAME("swapchoice", VAR_STRING), 0},
{VV_NAME("swapcommand", VAR_STRING), VV_RO},
{VV_NAME("char", VAR_STRING), VV_RO},
{VV_NAME("mouse_win", VAR_NUMBER), 0},
{VV_NAME("mouse_lnum", VAR_NUMBER), 0},
{VV_NAME("mouse_col", VAR_NUMBER), 0},
};
 
/* shorthand */
#define vv_type vv_di.di_tv.v_type
#define vv_nr vv_di.di_tv.vval.v_number
#define vv_str vv_di.di_tv.vval.v_string
#define vv_tv vv_di.di_tv
 
/*
* The v: variables are stored in dictionary "vimvardict".
* "vimvars_var" is the variable that is used for the "l:" scope.
*/
static dict_T vimvardict;
static dictitem_T vimvars_var;
#define vimvarht vimvardict.dv_hashtab
 
static void prepare_vimvar __ARGS((int idx, typval_T *save_tv));
static void restore_vimvar __ARGS((int idx, typval_T *save_tv));
#if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)
static int call_vim_function __ARGS((char_u *func, int argc, char_u **argv, int safe, typval_T *rettv));
#endif
static int ex_let_vars __ARGS((char_u *arg, typval_T *tv, int copy, int semicolon, int var_count, char_u *nextchars));
static char_u *skip_var_list __ARGS((char_u *arg, int *var_count, int *semicolon));
static char_u *skip_var_one __ARGS((char_u *arg));
static void list_hashtable_vars __ARGS((hashtab_T *ht, char_u *prefix, int empty));
static void list_glob_vars __ARGS((void));
static void list_buf_vars __ARGS((void));
static void list_win_vars __ARGS((void));
#ifdef FEAT_WINDOWS
static void list_tab_vars __ARGS((void));
#endif
static void list_vim_vars __ARGS((void));
static void list_script_vars __ARGS((void));
static void list_func_vars __ARGS((void));
static char_u *list_arg_vars __ARGS((exarg_T *eap, char_u *arg));
static char_u *ex_let_one __ARGS((char_u *arg, typval_T *tv, int copy, char_u *endchars, char_u *op));
static int check_changedtick __ARGS((char_u *arg));
static char_u *get_lval __ARGS((char_u *name, typval_T *rettv, lval_T *lp, int unlet, int skip, int quiet, int fne_flags));
static void clear_lval __ARGS((lval_T *lp));
static void set_var_lval __ARGS((lval_T *lp, char_u *endp, typval_T *rettv, int copy, char_u *op));
static int tv_op __ARGS((typval_T *tv1, typval_T *tv2, char_u *op));
static void list_add_watch __ARGS((list_T *l, listwatch_T *lw));
static void list_rem_watch __ARGS((list_T *l, listwatch_T *lwrem));
static void list_fix_watch __ARGS((list_T *l, listitem_T *item));
static void ex_unletlock __ARGS((exarg_T *eap, char_u *argstart, int deep));
static int do_unlet_var __ARGS((lval_T *lp, char_u *name_end, int forceit));
static int do_lock_var __ARGS((lval_T *lp, char_u *name_end, int deep, int lock));
static void item_lock __ARGS((typval_T *tv, int deep, int lock));
static int tv_islocked __ARGS((typval_T *tv));
 
static int eval0 __ARGS((char_u *arg, typval_T *rettv, char_u **nextcmd, int evaluate));
static int eval1 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static int eval2 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static int eval3 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static int eval4 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static int eval5 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static int eval6 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static int eval7 __ARGS((char_u **arg, typval_T *rettv, int evaluate));
 
static int eval_index __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose));
static int get_option_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static int get_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static int get_lit_string_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static int get_list_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static int rettv_list_alloc __ARGS((typval_T *rettv));
static listitem_T *listitem_alloc __ARGS((void));
static void listitem_free __ARGS((listitem_T *item));
static void listitem_remove __ARGS((list_T *l, listitem_T *item));
static long list_len __ARGS((list_T *l));
static int list_equal __ARGS((list_T *l1, list_T *l2, int ic));
static int dict_equal __ARGS((dict_T *d1, dict_T *d2, int ic));
static int tv_equal __ARGS((typval_T *tv1, typval_T *tv2, int ic));
static listitem_T *list_find __ARGS((list_T *l, long n));
static long list_find_nr __ARGS((list_T *l, long idx, int *errorp));
static long list_idx_of_item __ARGS((list_T *l, listitem_T *item));
static void list_append __ARGS((list_T *l, listitem_T *item));
static int list_append_tv __ARGS((list_T *l, typval_T *tv));
static int list_append_string __ARGS((list_T *l, char_u *str, int len));
static int list_append_number __ARGS((list_T *l, varnumber_T n));
static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item));
static int list_extend __ARGS((list_T *l1, list_T *l2, listitem_T *bef));
static int list_concat __ARGS((list_T *l1, list_T *l2, typval_T *tv));
static list_T *list_copy __ARGS((list_T *orig, int deep, int copyID));
static void list_remove __ARGS((list_T *l, listitem_T *item, listitem_T *item2));
static char_u *list2string __ARGS((typval_T *tv, int copyID));
static int list_join __ARGS((garray_T *gap, list_T *l, char_u *sep, int echo, int copyID));
static void set_ref_in_ht __ARGS((hashtab_T *ht, int copyID));
static void set_ref_in_list __ARGS((list_T *l, int copyID));
static void set_ref_in_item __ARGS((typval_T *tv, int copyID));
static void dict_unref __ARGS((dict_T *d));
static void dict_free __ARGS((dict_T *d, int recurse));
static dictitem_T *dictitem_alloc __ARGS((char_u *key));
static dictitem_T *dictitem_copy __ARGS((dictitem_T *org));
static void dictitem_remove __ARGS((dict_T *dict, dictitem_T *item));
static void dictitem_free __ARGS((dictitem_T *item));
static dict_T *dict_copy __ARGS((dict_T *orig, int deep, int copyID));
static int dict_add __ARGS((dict_T *d, dictitem_T *item));
static long dict_len __ARGS((dict_T *d));
static dictitem_T *dict_find __ARGS((dict_T *d, char_u *key, int len));
static char_u *dict2string __ARGS((typval_T *tv, int copyID));
static int get_dict_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static char_u *echo_string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf, int copyID));
static char_u *tv2string __ARGS((typval_T *tv, char_u **tofree, char_u *numbuf, int copyID));
static char_u *string_quote __ARGS((char_u *str, int function));
static int get_env_tv __ARGS((char_u **arg, typval_T *rettv, int evaluate));
static int find_internal_func __ARGS((char_u *name));
static char_u *deref_func_name __ARGS((char_u *name, int *lenp));
static int get_func_tv __ARGS((char_u *name, int len, typval_T *rettv, char_u **arg, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
static int call_func __ARGS((char_u *name, int len, typval_T *rettv, int argcount, typval_T *argvars, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
static void emsg_funcname __ARGS((char *ermsg, char_u *name));
 
static void f_add __ARGS((typval_T *argvars, typval_T *rettv));
static void f_append __ARGS((typval_T *argvars, typval_T *rettv));
static void f_argc __ARGS((typval_T *argvars, typval_T *rettv));
static void f_argidx __ARGS((typval_T *argvars, typval_T *rettv));
static void f_argv __ARGS((typval_T *argvars, typval_T *rettv));
static void f_browse __ARGS((typval_T *argvars, typval_T *rettv));
static void f_browsedir __ARGS((typval_T *argvars, typval_T *rettv));
static void f_bufexists __ARGS((typval_T *argvars, typval_T *rettv));
static void f_buflisted __ARGS((typval_T *argvars, typval_T *rettv));
static void f_bufloaded __ARGS((typval_T *argvars, typval_T *rettv));
static void f_bufname __ARGS((typval_T *argvars, typval_T *rettv));
static void f_bufnr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_bufwinnr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_byte2line __ARGS((typval_T *argvars, typval_T *rettv));
static void f_byteidx __ARGS((typval_T *argvars, typval_T *rettv));
static void f_call __ARGS((typval_T *argvars, typval_T *rettv));
static void f_changenr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_char2nr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_cindent __ARGS((typval_T *argvars, typval_T *rettv));
static void f_col __ARGS((typval_T *argvars, typval_T *rettv));
#if defined(FEAT_INS_EXPAND)
static void f_complete __ARGS((typval_T *argvars, typval_T *rettv));
static void f_complete_add __ARGS((typval_T *argvars, typval_T *rettv));
static void f_complete_check __ARGS((typval_T *argvars, typval_T *rettv));
#endif
static void f_confirm __ARGS((typval_T *argvars, typval_T *rettv));
static void f_copy __ARGS((typval_T *argvars, typval_T *rettv));
static void f_count __ARGS((typval_T *argvars, typval_T *rettv));
static void f_cscope_connection __ARGS((typval_T *argvars, typval_T *rettv));
static void f_cursor __ARGS((typval_T *argsvars, typval_T *rettv));
static void f_deepcopy __ARGS((typval_T *argvars, typval_T *rettv));
static void f_delete __ARGS((typval_T *argvars, typval_T *rettv));
static void f_did_filetype __ARGS((typval_T *argvars, typval_T *rettv));
static void f_diff_filler __ARGS((typval_T *argvars, typval_T *rettv));
static void f_diff_hlID __ARGS((typval_T *argvars, typval_T *rettv));
static void f_empty __ARGS((typval_T *argvars, typval_T *rettv));
static void f_escape __ARGS((typval_T *argvars, typval_T *rettv));
static void f_eval __ARGS((typval_T *argvars, typval_T *rettv));
static void f_eventhandler __ARGS((typval_T *argvars, typval_T *rettv));
static void f_executable __ARGS((typval_T *argvars, typval_T *rettv));
static void f_exists __ARGS((typval_T *argvars, typval_T *rettv));
static void f_expand __ARGS((typval_T *argvars, typval_T *rettv));
static void f_extend __ARGS((typval_T *argvars, typval_T *rettv));
static void f_feedkeys __ARGS((typval_T *argvars, typval_T *rettv));
static void f_filereadable __ARGS((typval_T *argvars, typval_T *rettv));
static void f_filewritable __ARGS((typval_T *argvars, typval_T *rettv));
static void f_filter __ARGS((typval_T *argvars, typval_T *rettv));
static void f_finddir __ARGS((typval_T *argvars, typval_T *rettv));
static void f_findfile __ARGS((typval_T *argvars, typval_T *rettv));
static void f_fnamemodify __ARGS((typval_T *argvars, typval_T *rettv));
static void f_foldclosed __ARGS((typval_T *argvars, typval_T *rettv));
static void f_foldclosedend __ARGS((typval_T *argvars, typval_T *rettv));
static void f_foldlevel __ARGS((typval_T *argvars, typval_T *rettv));
static void f_foldtext __ARGS((typval_T *argvars, typval_T *rettv));
static void f_foldtextresult __ARGS((typval_T *argvars, typval_T *rettv));
static void f_foreground __ARGS((typval_T *argvars, typval_T *rettv));
static void f_function __ARGS((typval_T *argvars, typval_T *rettv));
static void f_garbagecollect __ARGS((typval_T *argvars, typval_T *rettv));
static void f_get __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getbufline __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getbufvar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getchar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getcharmod __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getcmdline __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getcmdpos __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getcmdtype __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getcwd __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getfontname __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getfperm __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getfsize __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getftime __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getftype __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getline __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getpos __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getqflist __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getreg __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getregtype __ARGS((typval_T *argvars, typval_T *rettv));
static void f_gettabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getwinposx __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getwinposy __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getwinvar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_glob __ARGS((typval_T *argvars, typval_T *rettv));
static void f_globpath __ARGS((typval_T *argvars, typval_T *rettv));
static void f_has __ARGS((typval_T *argvars, typval_T *rettv));
static void f_has_key __ARGS((typval_T *argvars, typval_T *rettv));
static void f_haslocaldir __ARGS((typval_T *argvars, typval_T *rettv));
static void f_hasmapto __ARGS((typval_T *argvars, typval_T *rettv));
static void f_histadd __ARGS((typval_T *argvars, typval_T *rettv));
static void f_histdel __ARGS((typval_T *argvars, typval_T *rettv));
static void f_histget __ARGS((typval_T *argvars, typval_T *rettv));
static void f_histnr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_hlID __ARGS((typval_T *argvars, typval_T *rettv));
static void f_hlexists __ARGS((typval_T *argvars, typval_T *rettv));
static void f_hostname __ARGS((typval_T *argvars, typval_T *rettv));
static void f_iconv __ARGS((typval_T *argvars, typval_T *rettv));
static void f_indent __ARGS((typval_T *argvars, typval_T *rettv));
static void f_index __ARGS((typval_T *argvars, typval_T *rettv));
static void f_input __ARGS((typval_T *argvars, typval_T *rettv));
static void f_inputdialog __ARGS((typval_T *argvars, typval_T *rettv));
static void f_inputlist __ARGS((typval_T *argvars, typval_T *rettv));
static void f_inputrestore __ARGS((typval_T *argvars, typval_T *rettv));
static void f_inputsave __ARGS((typval_T *argvars, typval_T *rettv));
static void f_inputsecret __ARGS((typval_T *argvars, typval_T *rettv));
static void f_insert __ARGS((typval_T *argvars, typval_T *rettv));
static void f_isdirectory __ARGS((typval_T *argvars, typval_T *rettv));
static void f_islocked __ARGS((typval_T *argvars, typval_T *rettv));
static void f_items __ARGS((typval_T *argvars, typval_T *rettv));
static void f_join __ARGS((typval_T *argvars, typval_T *rettv));
static void f_keys __ARGS((typval_T *argvars, typval_T *rettv));
static void f_last_buffer_nr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_len __ARGS((typval_T *argvars, typval_T *rettv));
static void f_libcall __ARGS((typval_T *argvars, typval_T *rettv));
static void f_libcallnr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_line __ARGS((typval_T *argvars, typval_T *rettv));
static void f_line2byte __ARGS((typval_T *argvars, typval_T *rettv));
static void f_lispindent __ARGS((typval_T *argvars, typval_T *rettv));
static void f_localtime __ARGS((typval_T *argvars, typval_T *rettv));
static void f_map __ARGS((typval_T *argvars, typval_T *rettv));
static void f_maparg __ARGS((typval_T *argvars, typval_T *rettv));
static void f_mapcheck __ARGS((typval_T *argvars, typval_T *rettv));
static void f_match __ARGS((typval_T *argvars, typval_T *rettv));
static void f_matcharg __ARGS((typval_T *argvars, typval_T *rettv));
static void f_matchend __ARGS((typval_T *argvars, typval_T *rettv));
static void f_matchlist __ARGS((typval_T *argvars, typval_T *rettv));
static void f_matchstr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_max __ARGS((typval_T *argvars, typval_T *rettv));
static void f_min __ARGS((typval_T *argvars, typval_T *rettv));
#ifdef vim_mkdir
static void f_mkdir __ARGS((typval_T *argvars, typval_T *rettv));
#endif
static void f_mode __ARGS((typval_T *argvars, typval_T *rettv));
static void f_nextnonblank __ARGS((typval_T *argvars, typval_T *rettv));
static void f_nr2char __ARGS((typval_T *argvars, typval_T *rettv));
static void f_pathshorten __ARGS((typval_T *argvars, typval_T *rettv));
static void f_prevnonblank __ARGS((typval_T *argvars, typval_T *rettv));
static void f_printf __ARGS((typval_T *argvars, typval_T *rettv));
static void f_pumvisible __ARGS((typval_T *argvars, typval_T *rettv));
static void f_range __ARGS((typval_T *argvars, typval_T *rettv));
static void f_readfile __ARGS((typval_T *argvars, typval_T *rettv));
static void f_reltime __ARGS((typval_T *argvars, typval_T *rettv));
static void f_reltimestr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_remote_expr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_remote_foreground __ARGS((typval_T *argvars, typval_T *rettv));
static void f_remote_peek __ARGS((typval_T *argvars, typval_T *rettv));
static void f_remote_read __ARGS((typval_T *argvars, typval_T *rettv));
static void f_remote_send __ARGS((typval_T *argvars, typval_T *rettv));
static void f_remove __ARGS((typval_T *argvars, typval_T *rettv));
static void f_rename __ARGS((typval_T *argvars, typval_T *rettv));
static void f_repeat __ARGS((typval_T *argvars, typval_T *rettv));
static void f_resolve __ARGS((typval_T *argvars, typval_T *rettv));
static void f_reverse __ARGS((typval_T *argvars, typval_T *rettv));
static void f_search __ARGS((typval_T *argvars, typval_T *rettv));
static void f_searchdecl __ARGS((typval_T *argvars, typval_T *rettv));
static void f_searchpair __ARGS((typval_T *argvars, typval_T *rettv));
static void f_searchpairpos __ARGS((typval_T *argvars, typval_T *rettv));
static void f_searchpos __ARGS((typval_T *argvars, typval_T *rettv));
static void f_server2client __ARGS((typval_T *argvars, typval_T *rettv));
static void f_serverlist __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setbufvar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setcmdpos __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setline __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setloclist __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setpos __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setqflist __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setreg __ARGS((typval_T *argvars, typval_T *rettv));
static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv));
static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv));
static void f_sort __ARGS((typval_T *argvars, typval_T *rettv));
static void f_soundfold __ARGS((typval_T *argvars, typval_T *rettv));
static void f_spellbadword __ARGS((typval_T *argvars, typval_T *rettv));
static void f_spellsuggest __ARGS((typval_T *argvars, typval_T *rettv));
static void f_split __ARGS((typval_T *argvars, typval_T *rettv));
static void f_str2nr __ARGS((typval_T *argvars, typval_T *rettv));
#ifdef HAVE_STRFTIME
static void f_strftime __ARGS((typval_T *argvars, typval_T *rettv));
#endif
static void f_stridx __ARGS((typval_T *argvars, typval_T *rettv));
static void f_string __ARGS((typval_T *argvars, typval_T *rettv));
static void f_strlen __ARGS((typval_T *argvars, typval_T *rettv));
static void f_strpart __ARGS((typval_T *argvars, typval_T *rettv));
static void f_strridx __ARGS((typval_T *argvars, typval_T *rettv));
static void f_strtrans __ARGS((typval_T *argvars, typval_T *rettv));
static void f_submatch __ARGS((typval_T *argvars, typval_T *rettv));
static void f_substitute __ARGS((typval_T *argvars, typval_T *rettv));
static void f_synID __ARGS((typval_T *argvars, typval_T *rettv));
static void f_synIDattr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_synIDtrans __ARGS((typval_T *argvars, typval_T *rettv));
static void f_system __ARGS((typval_T *argvars, typval_T *rettv));
static void f_tabpagebuflist __ARGS((typval_T *argvars, typval_T *rettv));
static void f_tabpagenr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_tabpagewinnr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_taglist __ARGS((typval_T *argvars, typval_T *rettv));
static void f_tagfiles __ARGS((typval_T *argvars, typval_T *rettv));
static void f_tempname __ARGS((typval_T *argvars, typval_T *rettv));
static void f_test __ARGS((typval_T *argvars, typval_T *rettv));
static void f_tolower __ARGS((typval_T *argvars, typval_T *rettv));
static void f_toupper __ARGS((typval_T *argvars, typval_T *rettv));
static void f_tr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_type __ARGS((typval_T *argvars, typval_T *rettv));
static void f_values __ARGS((typval_T *argvars, typval_T *rettv));
static void f_virtcol __ARGS((typval_T *argvars, typval_T *rettv));
static void f_visualmode __ARGS((typval_T *argvars, typval_T *rettv));
static void f_winbufnr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_wincol __ARGS((typval_T *argvars, typval_T *rettv));
static void f_winheight __ARGS((typval_T *argvars, typval_T *rettv));
static void f_winline __ARGS((typval_T *argvars, typval_T *rettv));
static void f_winnr __ARGS((typval_T *argvars, typval_T *rettv));
static void f_winrestcmd __ARGS((typval_T *argvars, typval_T *rettv));
static void f_winrestview __ARGS((typval_T *argvars, typval_T *rettv));
static void f_winsaveview __ARGS((typval_T *argvars, typval_T *rettv));
static void f_winwidth __ARGS((typval_T *argvars, typval_T *rettv));
static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
 
static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump));
static pos_T *var2fpos __ARGS((typval_T *varp, int lnum, int *fnum));
static int get_env_len __ARGS((char_u **arg));
static int get_id_len __ARGS((char_u **arg));
static int get_name_len __ARGS((char_u **arg, char_u **alias, int evaluate, int verbose));
static char_u *find_name_end __ARGS((char_u *arg, char_u **expr_start, char_u **expr_end, int flags));
#define FNE_INCL_BR 1 /* find_name_end(): include [] in name */
#define FNE_CHECK_START 2 /* find_name_end(): check name starts with
valid character */
static char_u * make_expanded_name __ARGS((char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end));
static int eval_isnamec __ARGS((int c));
static int eval_isnamec1 __ARGS((int c));
static int get_var_tv __ARGS((char_u *name, int len, typval_T *rettv, int verbose));
static int handle_subscript __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose));
static typval_T *alloc_tv __ARGS((void));
static typval_T *alloc_string_tv __ARGS((char_u *string));
static void init_tv __ARGS((typval_T *varp));
static long get_tv_number __ARGS((typval_T *varp));
static linenr_T get_tv_lnum __ARGS((typval_T *argvars));
static linenr_T get_tv_lnum_buf __ARGS((typval_T *argvars, buf_T *buf));
static char_u *get_tv_string __ARGS((typval_T *varp));
static char_u *get_tv_string_buf __ARGS((typval_T *varp, char_u *buf));
static char_u *get_tv_string_buf_chk __ARGS((typval_T *varp, char_u *buf));
static dictitem_T *find_var __ARGS((char_u *name, hashtab_T **htp));
static dictitem_T *find_var_in_ht __ARGS((hashtab_T *ht, char_u *varname, int writing));
static hashtab_T *find_var_ht __ARGS((char_u *name, char_u **varname));
static void vars_clear_ext __ARGS((hashtab_T *ht, int free_val));
static void delete_var __ARGS((hashtab_T *ht, hashitem_T *hi));
static void list_one_var __ARGS((dictitem_T *v, char_u *prefix));
static void list_one_var_a __ARGS((char_u *prefix, char_u *name, int type, char_u *string));
static void set_var __ARGS((char_u *name, typval_T *varp, int copy));
static int var_check_ro __ARGS((int flags, char_u *name));
static int var_check_fixed __ARGS((int flags, char_u *name));
static int tv_check_lock __ARGS((int lock, char_u *name));
static void copy_tv __ARGS((typval_T *from, typval_T *to));
static int item_copy __ARGS((typval_T *from, typval_T *to, int deep, int copyID));
static char_u *find_option_end __ARGS((char_u **arg, int *opt_flags));
static char_u *trans_function_name __ARGS((char_u **pp, int skip, int flags, funcdict_T *fd));
static int eval_fname_script __ARGS((char_u *p));
static int eval_fname_sid __ARGS((char_u *p));
static void list_func_head __ARGS((ufunc_T *fp, int indent));
static ufunc_T *find_func __ARGS((char_u *name));
static int function_exists __ARGS((char_u *name));
static int builtin_function __ARGS((char_u *name));
#ifdef FEAT_PROFILE
static void func_do_profile __ARGS((ufunc_T *fp));
static void prof_sort_list __ARGS((FILE *fd, ufunc_T **sorttab, int st_len, char *title, int prefer_self));
static void prof_func_line __ARGS((FILE *fd, int count, proftime_T *total, proftime_T *self, int prefer_self));
static int
# ifdef __BORLANDC__
_RTLENTRYF
# endif
prof_total_cmp __ARGS((const void *s1, const void *s2));
static int
# ifdef __BORLANDC__
_RTLENTRYF
# endif
prof_self_cmp __ARGS((const void *s1, const void *s2));
#endif
static int script_autoload __ARGS((char_u *name, int reload));
static char_u *autoload_name __ARGS((char_u *name));
static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp));
static void func_free __ARGS((ufunc_T *fp));
static void func_unref __ARGS((char_u *name));
static void func_ref __ARGS((char_u *name));
static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict));
static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr));
static win_T *find_win_by_nr __ARGS((typval_T *vp, tabpage_T *tp));
static void getwinvar __ARGS((typval_T *argvars, typval_T *rettv, int off));
static int searchpair_cmn __ARGS((typval_T *argvars, pos_T *match_pos));
static int search_cmn __ARGS((typval_T *argvars, pos_T *match_pos, int *flagsp));
static void setwinvar __ARGS((typval_T *argvars, typval_T *rettv, int off));
 
/* Character used as separated in autoload function/variable names. */
#define AUTOLOAD_CHAR '#'
 
/*
* Initialize the global and v: variables.
*/
void
eval_init()
{
int i;
struct vimvar *p;
 
init_var_dict(&globvardict, &globvars_var);
init_var_dict(&vimvardict, &vimvars_var);
hash_init(&compat_hashtab);
hash_init(&func_hashtab);
 
for (i = 0; i < VV_LEN; ++i)
{
p = &vimvars[i];
STRCPY(p->vv_di.di_key, p->vv_name);
if (p->vv_flags & VV_RO)
p->vv_di.di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
else if (p->vv_flags & VV_RO_SBX)
p->vv_di.di_flags = DI_FLAGS_RO_SBX | DI_FLAGS_FIX;
else
p->vv_di.di_flags = DI_FLAGS_FIX;
 
/* add to v: scope dict, unless the value is not always available */
if (p->vv_type != VAR_UNKNOWN)
hash_add(&vimvarht, p->vv_di.di_key);
if (p->vv_flags & VV_COMPAT)
/* add to compat scope dict */
hash_add(&compat_hashtab, p->vv_di.di_key);
}
}
 
#if defined(EXITFREE) || defined(PROTO)
void
eval_clear()
{
int i;
struct vimvar *p;
 
for (i = 0; i < VV_LEN; ++i)
{
p = &vimvars[i];
if (p->vv_di.di_tv.v_type == VAR_STRING)
{
vim_free(p->vv_di.di_tv.vval.v_string);
p->vv_di.di_tv.vval.v_string = NULL;
}
}
hash_clear(&vimvarht);
hash_clear(&compat_hashtab);
 
/* script-local variables */
for (i = 1; i <= ga_scripts.ga_len; ++i)
vars_clear(&SCRIPT_VARS(i));
ga_clear(&ga_scripts);
free_scriptnames();
 
/* global variables */
vars_clear(&globvarht);
 
/* functions */
free_all_functions();
hash_clear(&func_hashtab);
 
/* autoloaded script names */
ga_clear_strings(&ga_loaded);
 
/* unreferenced lists and dicts */
(void)garbage_collect();
}
#endif
 
/*
* Return the name of the executed function.
*/
char_u *
func_name(cookie)
void *cookie;
{
return ((funccall_T *)cookie)->func->uf_name;
}
 
/*
* Return the address holding the next breakpoint line for a funccall cookie.
*/
linenr_T *
func_breakpoint(cookie)
void *cookie;
{
return &((funccall_T *)cookie)->breakpoint;
}
 
/*
* Return the address holding the debug tick for a funccall cookie.
*/
int *
func_dbg_tick(cookie)
void *cookie;
{
return &((funccall_T *)cookie)->dbg_tick;
}
 
/*
* Return the nesting level for a funccall cookie.
*/
int
func_level(cookie)
void *cookie;
{
return ((funccall_T *)cookie)->level;
}
 
/* pointer to funccal for currently active function */
funccall_T *current_funccal = NULL;
 
/*
* Return TRUE when a function was ended by a ":return" command.
*/
int
current_func_returned()
{
return current_funccal->returned;
}
 
 
/*
* Set an internal variable to a string value. Creates the variable if it does
* not already exist.
*/
void
set_internal_string_var(name, value)
char_u *name;
char_u *value;
{
char_u *val;
typval_T *tvp;
 
val = vim_strsave(value);
if (val != NULL)
{
tvp = alloc_string_tv(val);
if (tvp != NULL)
{
set_var(name, tvp, FALSE);
free_tv(tvp);
}
}
}
 
static lval_T *redir_lval = NULL;
static garray_T redir_ga; /* only valid when redir_lval is not NULL */
static char_u *redir_endp = NULL;
static char_u *redir_varname = NULL;
 
/*
* Start recording command output to a variable
* Returns OK if successfully completed the setup. FAIL otherwise.
*/
int
var_redir_start(name, append)
char_u *name;
int append; /* append to an existing variable */
{
int save_emsg;
int err;
typval_T tv;
 
/* Make sure a valid variable name is specified */
if (!eval_isnamec1(*name))
{
EMSG(_(e_invarg));
return FAIL;
}
 
redir_varname = vim_strsave(name);
if (redir_varname == NULL)
return FAIL;
 
redir_lval = (lval_T *)alloc_clear((unsigned)sizeof(lval_T));
if (redir_lval == NULL)
{
var_redir_stop();
return FAIL;
}
 
/* The output is stored in growarray "redir_ga" until redirection ends. */
ga_init2(&redir_ga, (int)sizeof(char), 500);
 
/* Parse the variable name (can be a dict or list entry). */
redir_endp = get_lval(redir_varname, NULL, redir_lval, FALSE, FALSE, FALSE,
FNE_CHECK_START);
if (redir_endp == NULL || redir_lval->ll_name == NULL || *redir_endp != NUL)
{
if (redir_endp != NULL && *redir_endp != NUL)
/* Trailing characters are present after the variable name */
EMSG(_(e_trailing));
else
EMSG(_(e_invarg));
var_redir_stop();
return FAIL;
}
 
/* check if we can write to the variable: set it to or append an empty
* string */
save_emsg = did_emsg;
did_emsg = FALSE;
tv.v_type = VAR_STRING;
tv.vval.v_string = (char_u *)"";
if (append)
set_var_lval(redir_lval, redir_endp, &tv, TRUE, (char_u *)".");
else
set_var_lval(redir_lval, redir_endp, &tv, TRUE, (char_u *)"=");
err = did_emsg;
did_emsg |= save_emsg;
if (err)
{
var_redir_stop();
return FAIL;
}
if (redir_lval->ll_newkey != NULL)
{
/* Dictionary item was created, don't do it again. */
vim_free(redir_lval->ll_newkey);
redir_lval->ll_newkey = NULL;
}
 
return OK;
}
 
/*
* Append "value[value_len]" to the variable set by var_redir_start().
* The actual appending is postponed until redirection ends, because the value
* appended may in fact be the string we write to, changing it may cause freed
* memory to be used:
* :redir => foo
* :let foo
* :redir END
*/
void
var_redir_str(value, value_len)
char_u *value;
int value_len;
{
size_t len;
 
if (redir_lval == NULL)
return;
 
if (value_len == -1)
len = STRLEN(value); /* Append the entire string */
else
len = value_len; /* Append only "value_len" characters */
 
if (ga_grow(&redir_ga, (int)len) == OK)
{
mch_memmove((char *)redir_ga.ga_data + redir_ga.ga_len, value, len);
redir_ga.ga_len += (int)len;
}
else
var_redir_stop();
}
 
/*
* Stop redirecting command output to a variable.
*/
void
var_redir_stop()
{
typval_T tv;
 
if (redir_lval != NULL)
{
/* Append the trailing NUL. */
ga_append(&redir_ga, NUL);
 
/* Assign the text to the variable. */
tv.v_type = VAR_STRING;
tv.vval.v_string = redir_ga.ga_data;
set_var_lval(redir_lval, redir_endp, &tv, FALSE, (char_u *)".");
vim_free(tv.vval.v_string);
 
clear_lval(redir_lval);
vim_free(redir_lval);
redir_lval = NULL;
}
vim_free(redir_varname);
redir_varname = NULL;
}
 
# if defined(FEAT_MBYTE) || defined(PROTO)
int
eval_charconvert(enc_from, enc_to, fname_from, fname_to)
char_u *enc_from;
char_u *enc_to;
char_u *fname_from;
char_u *fname_to;
{
int err = FALSE;
 
set_vim_var_string(VV_CC_FROM, enc_from, -1);
set_vim_var_string(VV_CC_TO, enc_to, -1);
set_vim_var_string(VV_FNAME_IN, fname_from, -1);
set_vim_var_string(VV_FNAME_OUT, fname_to, -1);
if (eval_to_bool(p_ccv, &err, NULL, FALSE))
err = TRUE;
set_vim_var_string(VV_CC_FROM, NULL, -1);
set_vim_var_string(VV_CC_TO, NULL, -1);
set_vim_var_string(VV_FNAME_IN, NULL, -1);
set_vim_var_string(VV_FNAME_OUT, NULL, -1);
 
if (err)
return FAIL;
return OK;
}
# endif
 
# if defined(FEAT_POSTSCRIPT) || defined(PROTO)
int
eval_printexpr(fname, args)
char_u *fname;
char_u *args;
{
int err = FALSE;
 
set_vim_var_string(VV_FNAME_IN, fname, -1);
set_vim_var_string(VV_CMDARG, args, -1);
if (eval_to_bool(p_pexpr, &err, NULL, FALSE))
err = TRUE;
set_vim_var_string(VV_FNAME_IN, NULL, -1);
set_vim_var_string(VV_CMDARG, NULL, -1);
 
if (err)
{
mch_remove(fname);
return FAIL;
}
return OK;
}
# endif
 
# if defined(FEAT_DIFF) || defined(PROTO)
void
eval_diff(origfile, newfile, outfile)
char_u *origfile;
char_u *newfile;
char_u *outfile;
{
int err = FALSE;
 
set_vim_var_string(VV_FNAME_IN, origfile, -1);
set_vim_var_string(VV_FNAME_NEW, newfile, -1);
set_vim_var_string(VV_FNAME_OUT, outfile, -1);
(void)eval_to_bool(p_dex, &err, NULL, FALSE);
set_vim_var_string(VV_FNAME_IN, NULL, -1);
set_vim_var_string(VV_FNAME_NEW, NULL, -1);
set_vim_var_string(VV_FNAME_OUT, NULL, -1);
}
 
void
eval_patch(origfile, difffile, outfile)
char_u *origfile;
char_u *difffile;
char_u *outfile;
{
int err;
 
set_vim_var_string(VV_FNAME_IN, origfile, -1);
set_vim_var_string(VV_FNAME_DIFF, difffile, -1);
set_vim_var_string(VV_FNAME_OUT, outfile, -1);
(void)eval_to_bool(p_pex, &err, NULL, FALSE);
set_vim_var_string(VV_FNAME_IN, NULL, -1);
set_vim_var_string(VV_FNAME_DIFF, NULL, -1);
set_vim_var_string(VV_FNAME_OUT, NULL, -1);
}
# endif
 
/*
* Top level evaluation function, returning a boolean.
* Sets "error" to TRUE if there was an error.
* Return TRUE or FALSE.
*/
int
eval_to_bool(arg, error, nextcmd, skip)
char_u *arg;
int *error;
char_u **nextcmd;
int skip; /* only parse, don't execute */
{
typval_T tv;
int retval = FALSE;
 
if (skip)
++emsg_skip;
if (eval0(arg, &tv, nextcmd, !skip) == FAIL)
*error = TRUE;
else
{
*error = FALSE;
if (!skip)
{
retval = (get_tv_number_chk(&tv, error) != 0);
clear_tv(&tv);
}
}
if (skip)
--emsg_skip;
 
return retval;
}
 
/*
* Top level evaluation function, returning a string. If "skip" is TRUE,
* only parsing to "nextcmd" is done, without reporting errors. Return
* pointer to allocated memory, or NULL for failure or when "skip" is TRUE.
*/
char_u *
eval_to_string_skip(arg, nextcmd, skip)
char_u *arg;
char_u **nextcmd;
int skip; /* only parse, don't execute */
{
typval_T tv;
char_u *retval;
 
if (skip)
++emsg_skip;
if (eval0(arg, &tv, nextcmd, !skip) == FAIL || skip)
retval = NULL;
else
{
retval = vim_strsave(get_tv_string(&tv));
clear_tv(&tv);
}
if (skip)
--emsg_skip;
 
return retval;
}
 
/*
* Skip over an expression at "*pp".
* Return FAIL for an error, OK otherwise.
*/
int
skip_expr(pp)
char_u **pp;
{
typval_T rettv;
 
*pp = skipwhite(*pp);
return eval1(pp, &rettv, FALSE);
}
 
/*
* Top level evaluation function, returning a string.
* Return pointer to allocated memory, or NULL for failure.
*/
char_u *
eval_to_string(arg, nextcmd, dolist)
char_u *arg;
char_u **nextcmd;
int dolist; /* turn List into sequence of lines */
{
typval_T tv;
char_u *retval;
garray_T ga;
 
if (eval0(arg, &tv, nextcmd, TRUE) == FAIL)
retval = NULL;
else
{
if (dolist && tv.v_type == VAR_LIST)
{
ga_init2(&ga, (int)sizeof(char), 80);
list_join(&ga, tv.vval.v_list, (char_u *)"\n", TRUE, 0);
ga_append(&ga, NUL);
retval = (char_u *)ga.ga_data;
}
else
retval = vim_strsave(get_tv_string(&tv));
clear_tv(&tv);
}
 
return retval;
}
 
/*
* Call eval_to_string() without using current local variables and using
* textlock. When "use_sandbox" is TRUE use the sandbox.
*/
char_u *
eval_to_string_safe(arg, nextcmd, use_sandbox)
char_u *arg;
char_u **nextcmd;
int use_sandbox;
{
char_u *retval;
void *save_funccalp;
 
save_funccalp = save_funccal();
if (use_sandbox)
++sandbox;
++textlock;
retval = eval_to_string(arg, nextcmd, FALSE);
if (use_sandbox)
--sandbox;
--textlock;
restore_funccal(save_funccalp);
return retval;
}
 
/*
* Top level evaluation function, returning a number.
* Evaluates "expr" silently.
* Returns -1 for an error.
*/
int
eval_to_number(expr)
char_u *expr;
{
typval_T rettv;
int retval;
char_u *p = skipwhite(expr);
 
++emsg_off;
 
if (eval1(&p, &rettv, TRUE) == FAIL)
retval = -1;
else
{
retval = get_tv_number_chk(&rettv, NULL);
clear_tv(&rettv);
}
--emsg_off;
 
return retval;
}
 
/*
* Prepare v: variable "idx" to be used.
* Save the current typeval in "save_tv".
* When not used yet add the variable to the v: hashtable.
*/
static void
prepare_vimvar(idx, save_tv)
int idx;
typval_T *save_tv;
{
*save_tv = vimvars[idx].vv_tv;
if (vimvars[idx].vv_type == VAR_UNKNOWN)
hash_add(&vimvarht, vimvars[idx].vv_di.di_key);
}
 
/*
* Restore v: variable "idx" to typeval "save_tv".
* When no longer defined, remove the variable from the v: hashtable.
*/
static void
restore_vimvar(idx, save_tv)
int idx;
typval_T *save_tv;
{
hashitem_T *hi;
 
clear_tv(&vimvars[idx].vv_tv);
vimvars[idx].vv_tv = *save_tv;
if (vimvars[idx].vv_type == VAR_UNKNOWN)
{
hi = hash_find(&vimvarht, vimvars[idx].vv_di.di_key);
if (HASHITEM_EMPTY(hi))
EMSG2(_(e_intern2), "restore_vimvar()");
else
hash_remove(&vimvarht, hi);
}
}
 
#if defined(FEAT_SPELL) || defined(PROTO)
/*
* Evaluate an expression to a list with suggestions.
* For the "expr:" part of 'spellsuggest'.
*/
list_T *
eval_spell_expr(badword, expr)
char_u *badword;
char_u *expr;
{
typval_T save_val;
typval_T rettv;
list_T *list = NULL;
char_u *p = skipwhite(expr);
 
/* Set "v:val" to the bad word. */
prepare_vimvar(VV_VAL, &save_val);
vimvars[VV_VAL].vv_type = VAR_STRING;
vimvars[VV_VAL].vv_str = badword;
if (p_verbose == 0)
++emsg_off;
 
if (eval1(&p, &rettv, TRUE) == OK)
{
if (rettv.v_type != VAR_LIST)
clear_tv(&rettv);
else
list = rettv.vval.v_list;
}
 
if (p_verbose == 0)
--emsg_off;
vimvars[VV_VAL].vv_str = NULL;
restore_vimvar(VV_VAL, &save_val);
 
return list;
}
 
/*
* "list" is supposed to contain two items: a word and a number. Return the
* word in "pp" and the number as the return value.
* Return -1 if anything isn't right.
* Used to get the good word and score from the eval_spell_expr() result.
*/
int
get_spellword(list, pp)
list_T *list;
char_u **pp;
{
listitem_T *li;
 
li = list->lv_first;
if (li == NULL)
return -1;
*pp = get_tv_string(&li->li_tv);
 
li = li->li_next;
if (li == NULL)
return -1;
return get_tv_number(&li->li_tv);
}
#endif
 
/*
* Top level evaluation function.
* Returns an allocated typval_T with the result.
* Returns NULL when there is an error.
*/
typval_T *
eval_expr(arg, nextcmd)
char_u *arg;
char_u **nextcmd;
{
typval_T *tv;
 
tv = (typval_T *)alloc(sizeof(typval_T));
if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL)
{
vim_free(tv);
tv = NULL;
}
 
return tv;
}
 
 
#if (defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)) || defined(PROTO)
/*
* Call some vimL function and return the result in "*rettv".
* Uses argv[argc] for the function arguments.
* Returns OK or FAIL.
*/
static int
call_vim_function(func, argc, argv, safe, rettv)
char_u *func;
int argc;
char_u **argv;
int safe; /* use the sandbox */
typval_T *rettv;
{
typval_T *argvars;
long n;
int len;
int i;
int doesrange;
void *save_funccalp = NULL;
int ret;
 
argvars = (typval_T *)alloc((unsigned)((argc + 1) * sizeof(typval_T)));
if (argvars == NULL)
return FAIL;
 
for (i = 0; i < argc; i++)
{
/* Pass a NULL or empty argument as an empty string */
if (argv[i] == NULL || *argv[i] == NUL)
{
argvars[i].v_type = VAR_STRING;
argvars[i].vval.v_string = (char_u *)"";
continue;
}
 
/* Recognize a number argument, the others must be strings. */
vim_str2nr(argv[i], NULL, &len, TRUE, TRUE, &n, NULL);
if (len != 0 && len == (int)STRLEN(argv[i]))
{
argvars[i].v_type = VAR_NUMBER;
argvars[i].vval.v_number = n;
}
else
{
argvars[i].v_type = VAR_STRING;
argvars[i].vval.v_string = argv[i];
}
}
 
if (safe)
{
save_funccalp = save_funccal();
++sandbox;
}
 
rettv->v_type = VAR_UNKNOWN; /* clear_tv() uses this */
ret = call_func(func, (int)STRLEN(func), rettv, argc, argvars,
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
&doesrange, TRUE, NULL);
if (safe)
{
--sandbox;
restore_funccal(save_funccalp);
}
vim_free(argvars);
 
if (ret == FAIL)
clear_tv(rettv);
 
return ret;
}
 
/*
* Call vimL function "func" and return the result as a string.
* Returns NULL when calling the function fails.
* Uses argv[argc] for the function arguments.
*/
void *
call_func_retstr(func, argc, argv, safe)
char_u *func;
int argc;
char_u **argv;
int safe; /* use the sandbox */
{
typval_T rettv;
char_u *retval;
 
if (call_vim_function(func, argc, argv, safe, &rettv) == FAIL)
return NULL;
 
retval = vim_strsave(get_tv_string(&rettv));
clear_tv(&rettv);
return retval;
}
 
#if defined(FEAT_COMPL_FUNC) || defined(PROTO)
/*
* Call vimL function "func" and return the result as a number.
* Returns -1 when calling the function fails.
* Uses argv[argc] for the function arguments.
*/
long
call_func_retnr(func, argc, argv, safe)
char_u *func;
int argc;
char_u **argv;
int safe; /* use the sandbox */
{
typval_T rettv;
long retval;
 
if (call_vim_function(func, argc, argv, safe, &rettv) == FAIL)
return -1;
 
retval = get_tv_number_chk(&rettv, NULL);
clear_tv(&rettv);
return retval;
}
#endif
 
/*
* Call vimL function "func" and return the result as a list
* Uses argv[argc] for the function arguments.
*/
void *
call_func_retlist(func, argc, argv, safe)
char_u *func;
int argc;
char_u **argv;
int safe; /* use the sandbox */
{
typval_T rettv;
 
if (call_vim_function(func, argc, argv, safe, &rettv) == FAIL)
return NULL;
 
if (rettv.v_type != VAR_LIST)
{
clear_tv(&rettv);
return NULL;
}
 
return rettv.vval.v_list;
}
 
#endif
 
/*
* Save the current function call pointer, and set it to NULL.
* Used when executing autocommands and for ":source".
*/
void *
save_funccal()
{
funccall_T *fc = current_funccal;
 
current_funccal = NULL;
return (void *)fc;
}
 
void
restore_funccal(vfc)
void *vfc;
{
funccall_T *fc = (funccall_T *)vfc;
 
current_funccal = fc;
}
 
#if defined(FEAT_PROFILE) || defined(PROTO)
/*
* Prepare profiling for entering a child or something else that is not
* counted for the script/function itself.
* Should always be called in pair with prof_child_exit().
*/
void
prof_child_enter(tm)
proftime_T *tm; /* place to store waittime */
{
funccall_T *fc = current_funccal;
 
if (fc != NULL && fc->func->uf_profiling)
profile_start(&fc->prof_child);
script_prof_save(tm);
}
 
/*
* Take care of time spent in a child.
* Should always be called after prof_child_enter().
*/
void
prof_child_exit(tm)
proftime_T *tm; /* where waittime was stored */
{
funccall_T *fc = current_funccal;
 
if (fc != NULL && fc->func->uf_profiling)
{
profile_end(&fc->prof_child);
profile_sub_wait(tm, &fc->prof_child); /* don't count waiting time */
profile_add(&fc->func->uf_tm_children, &fc->prof_child);
profile_add(&fc->func->uf_tml_children, &fc->prof_child);
}
script_prof_restore(tm);
}
#endif
 
 
#ifdef FEAT_FOLDING
/*
* Evaluate 'foldexpr'. Returns the foldlevel, and any character preceding
* it in "*cp". Doesn't give error messages.
*/
int
eval_foldexpr(arg, cp)
char_u *arg;
int *cp;
{
typval_T tv;
int retval;
char_u *s;
int use_sandbox = was_set_insecurely((char_u *)"foldexpr",
OPT_LOCAL);
 
++emsg_off;
if (use_sandbox)
++sandbox;
++textlock;
*cp = NUL;
if (eval0(arg, &tv, NULL, TRUE) == FAIL)
retval = 0;
else
{
/* If the result is a number, just return the number. */
if (tv.v_type == VAR_NUMBER)
retval = tv.vval.v_number;
else if (tv.v_type != VAR_STRING || tv.vval.v_string == NULL)
retval = 0;
else
{
/* If the result is a string, check if there is a non-digit before
* the number. */
s = tv.vval.v_string;
if (!VIM_ISDIGIT(*s) && *s != '-')
*cp = *s++;
retval = atol((char *)s);
}
clear_tv(&tv);
}
--emsg_off;
if (use_sandbox)
--sandbox;
--textlock;
 
return retval;
}
#endif
 
/*
* ":let" list all variable values
* ":let var1 var2" list variable values
* ":let var = expr" assignment command.
* ":let var += expr" assignment command.
* ":let var -= expr" assignment command.
* ":let var .= expr" assignment command.
* ":let [var1, var2] = expr" unpack list.
*/
void
ex_let(eap)
exarg_T *eap;
{
char_u *arg = eap->arg;
char_u *expr = NULL;
typval_T rettv;
int i;
int var_count = 0;
int semicolon = 0;
char_u op[2];
char_u *argend;
 
argend = skip_var_list(arg, &var_count, &semicolon);
if (argend == NULL)
return;
if (argend > arg && argend[-1] == '.') /* for var.='str' */
--argend;
expr = vim_strchr(argend, '=');
if (expr == NULL)
{
/*
* ":let" without "=": list variables
*/
if (*arg == '[')
EMSG(_(e_invarg));
else if (!ends_excmd(*arg))
/* ":let var1 var2" */
arg = list_arg_vars(eap, arg);
else if (!eap->skip)
{
/* ":let" */
list_glob_vars();
list_buf_vars();
list_win_vars();
#ifdef FEAT_WINDOWS
list_tab_vars();
#endif
list_script_vars();
list_func_vars();
list_vim_vars();
}
eap->nextcmd = check_nextcmd(arg);
}
else
{
op[0] = '=';
op[1] = NUL;
if (expr > argend)
{
if (vim_strchr((char_u *)"+-.", expr[-1]) != NULL)
op[0] = expr[-1]; /* +=, -= or .= */
}
expr = skipwhite(expr + 1);
 
if (eap->skip)
++emsg_skip;
i = eval0(expr, &rettv, &eap->nextcmd, !eap->skip);
if (eap->skip)
{
if (i != FAIL)
clear_tv(&rettv);
--emsg_skip;
}
else if (i != FAIL)
{
(void)ex_let_vars(eap->arg, &rettv, FALSE, semicolon, var_count,
op);
clear_tv(&rettv);
}
}
}
 
/*
* Assign the typevalue "tv" to the variable or variables at "arg_start".
* Handles both "var" with any type and "[var, var; var]" with a list type.
* When "nextchars" is not NULL it points to a string with characters that
* must appear after the variable(s). Use "+", "-" or "." for add, subtract
* or concatenate.
* Returns OK or FAIL;
*/
static int
ex_let_vars(arg_start, tv, copy, semicolon, var_count, nextchars)
char_u *arg_start;
typval_T *tv;
int copy; /* copy values from "tv", don't move */
int semicolon; /* from skip_var_list() */
int var_count; /* from skip_var_list() */
char_u *nextchars;
{
char_u *arg = arg_start;
list_T *l;
int i;
listitem_T *item;
typval_T ltv;
 
if (*arg != '[')
{
/*
* ":let var = expr" or ":for var in list"
*/
if (ex_let_one(arg, tv, copy, nextchars, nextchars) == NULL)
return FAIL;
return OK;
}
 
/*
* ":let [v1, v2] = list" or ":for [v1, v2] in listlist"
*/
if (tv->v_type != VAR_LIST || (l = tv->vval.v_list) == NULL)
{
EMSG(_(e_listreq));
return FAIL;
}
 
i = list_len(l);
if (semicolon == 0 && var_count < i)
{
EMSG(_("E687: Less targets than List items"));
return FAIL;
}
if (var_count - semicolon > i)
{
EMSG(_("E688: More targets than List items"));
return FAIL;
}
 
item = l->lv_first;
while (*arg != ']')
{
arg = skipwhite(arg + 1);
arg = ex_let_one(arg, &item->li_tv, TRUE, (char_u *)",;]", nextchars);
item = item->li_next;
if (arg == NULL)
return FAIL;
 
arg = skipwhite(arg);
if (*arg == ';')
{
/* Put the rest of the list (may be empty) in the var after ';'.
* Create a new list for this. */
l = list_alloc();
if (l == NULL)
return FAIL;
while (item != NULL)
{
list_append_tv(l, &item->li_tv);
item = item->li_next;
}
 
ltv.v_type = VAR_LIST;
ltv.v_lock = 0;
ltv.vval.v_list = l;
l->lv_refcount = 1;
 
arg = ex_let_one(skipwhite(arg + 1), &ltv, FALSE,
(char_u *)"]", nextchars);
clear_tv(&ltv);
if (arg == NULL)
return FAIL;
break;
}
else if (*arg != ',' && *arg != ']')
{
EMSG2(_(e_intern2), "ex_let_vars()");
return FAIL;
}
}
 
return OK;
}
 
/*
* Skip over assignable variable "var" or list of variables "[var, var]".
* Used for ":let varvar = expr" and ":for varvar in expr".
* For "[var, var]" increment "*var_count" for each variable.
* for "[var, var; var]" set "semicolon".
* Return NULL for an error.
*/
static char_u *
skip_var_list(arg, var_count, semicolon)
char_u *arg;
int *var_count;
int *semicolon;
{
char_u *p, *s;
 
if (*arg == '[')
{
/* "[var, var]": find the matching ']'. */
p = arg;
for (;;)
{
p = skipwhite(p + 1); /* skip whites after '[', ';' or ',' */
s = skip_var_one(p);
if (s == p)
{
EMSG2(_(e_invarg2), p);
return NULL;
}
++*var_count;
 
p = skipwhite(s);
if (*p == ']')
break;
else if (*p == ';')
{
if (*semicolon == 1)
{
EMSG(_("Double ; in list of variables"));
return NULL;
}
*semicolon = 1;
}
else if (*p != ',')
{
EMSG2(_(e_invarg2), p);
return NULL;
}
}
return p + 1;
}
else
return skip_var_one(arg);
}
 
/*
* Skip one (assignable) variable name, including @r, $VAR, &option, d.key,
* l[idx].
*/
static char_u *
skip_var_one(arg)
char_u *arg;
{
if (*arg == '@' && arg[1] != NUL)
return arg + 2;
return find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg,
NULL, NULL, FNE_INCL_BR | FNE_CHECK_START);
}
 
/*
* List variables for hashtab "ht" with prefix "prefix".
* If "empty" is TRUE also list NULL strings as empty strings.
*/
static void
list_hashtable_vars(ht, prefix, empty)
hashtab_T *ht;
char_u *prefix;
int empty;
{
hashitem_T *hi;
dictitem_T *di;
int todo;
 
todo = (int)ht->ht_used;
for (hi = ht->ht_array; todo > 0 && !got_int; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
di = HI2DI(hi);
if (empty || di->di_tv.v_type != VAR_STRING
|| di->di_tv.vval.v_string != NULL)
list_one_var(di, prefix);
}
}
}
 
/*
* List global variables.
*/
static void
list_glob_vars()
{
list_hashtable_vars(&globvarht, (char_u *)"", TRUE);
}
 
/*
* List buffer variables.
*/
static void
list_buf_vars()
{
char_u numbuf[NUMBUFLEN];
 
list_hashtable_vars(&curbuf->b_vars.dv_hashtab, (char_u *)"b:", TRUE);
 
sprintf((char *)numbuf, "%ld", (long)curbuf->b_changedtick);
list_one_var_a((char_u *)"b:", (char_u *)"changedtick", VAR_NUMBER, numbuf);
}
 
/*
* List window variables.
*/
static void
list_win_vars()
{
list_hashtable_vars(&curwin->w_vars.dv_hashtab, (char_u *)"w:", TRUE);
}
 
#ifdef FEAT_WINDOWS
/*
* List tab page variables.
*/
static void
list_tab_vars()
{
list_hashtable_vars(&curtab->tp_vars.dv_hashtab, (char_u *)"t:", TRUE);
}
#endif
 
/*
* List Vim variables.
*/
static void
list_vim_vars()
{
list_hashtable_vars(&vimvarht, (char_u *)"v:", FALSE);
}
 
/*
* List script-local variables, if there is a script.
*/
static void
list_script_vars()
{
if (current_SID > 0 && current_SID <= ga_scripts.ga_len)
list_hashtable_vars(&SCRIPT_VARS(current_SID), (char_u *)"s:", FALSE);
}
 
/*
* List function variables, if there is a function.
*/
static void
list_func_vars()
{
if (current_funccal != NULL)
list_hashtable_vars(&current_funccal->l_vars.dv_hashtab,
(char_u *)"l:", FALSE);
}
 
/*
* List variables in "arg".
*/
static char_u *
list_arg_vars(eap, arg)
exarg_T *eap;
char_u *arg;
{
int error = FALSE;
int len;
char_u *name;
char_u *name_start;
char_u *arg_subsc;
char_u *tofree;
typval_T tv;
 
while (!ends_excmd(*arg) && !got_int)
{
if (error || eap->skip)
{
arg = find_name_end(arg, NULL, NULL, FNE_INCL_BR | FNE_CHECK_START);
if (!vim_iswhite(*arg) && !ends_excmd(*arg))
{
emsg_severe = TRUE;
EMSG(_(e_trailing));
break;
}
}
else
{
/* get_name_len() takes care of expanding curly braces */
name_start = name = arg;
len = get_name_len(&arg, &tofree, TRUE, TRUE);
if (len <= 0)
{
/* This is mainly to keep test 49 working: when expanding
* curly braces fails overrule the exception error message. */
if (len < 0 && !aborting())
{
emsg_severe = TRUE;
EMSG2(_(e_invarg2), arg);
break;
}
error = TRUE;
}
else
{
if (tofree != NULL)
name = tofree;
if (get_var_tv(name, len, &tv, TRUE) == FAIL)
error = TRUE;
else
{
/* handle d.key, l[idx], f(expr) */
arg_subsc = arg;
if (handle_subscript(&arg, &tv, TRUE, TRUE) == FAIL)
error = TRUE;
else
{
if (arg == arg_subsc && len == 2 && name[1] == ':')
{
switch (*name)
{
case 'g': list_glob_vars(); break;
case 'b': list_buf_vars(); break;
case 'w': list_win_vars(); break;
#ifdef FEAT_WINDOWS
case 't': list_tab_vars(); break;
#endif
case 'v': list_vim_vars(); break;
case 's': list_script_vars(); break;
case 'l': list_func_vars(); break;
default:
EMSG2(_("E738: Can't list variables for %s"), name);
}
}
else
{
char_u numbuf[NUMBUFLEN];
char_u *tf;
int c;
char_u *s;
 
s = echo_string(&tv, &tf, numbuf, 0);
c = *arg;
*arg = NUL;
list_one_var_a((char_u *)"",
arg == arg_subsc ? name : name_start,
tv.v_type, s == NULL ? (char_u *)"" : s);
*arg = c;
vim_free(tf);
}
clear_tv(&tv);
}
}
}
 
vim_free(tofree);
}
 
arg = skipwhite(arg);
}
 
return arg;
}
 
/*
* Set one item of ":let var = expr" or ":let [v1, v2] = list" to its value.
* Returns a pointer to the char just after the var name.
* Returns NULL if there is an error.
*/
static char_u *
ex_let_one(arg, tv, copy, endchars, op)
char_u *arg; /* points to variable name */
typval_T *tv; /* value to assign to variable */
int copy; /* copy value from "tv" */
char_u *endchars; /* valid chars after variable name or NULL */
char_u *op; /* "+", "-", "." or NULL*/
{
int c1;
char_u *name;
char_u *p;
char_u *arg_end = NULL;
int len;
int opt_flags;
char_u *tofree = NULL;
 
/*
* ":let $VAR = expr": Set environment variable.
*/
if (*arg == '$')
{
/* Find the end of the name. */
++arg;
name = arg;
len = get_env_len(&arg);
if (len == 0)
EMSG2(_(e_invarg2), name - 1);
else
{
if (op != NULL && (*op == '+' || *op == '-'))
EMSG2(_(e_letwrong), op);
else if (endchars != NULL
&& vim_strchr(endchars, *skipwhite(arg)) == NULL)
EMSG(_(e_letunexp));
else
{
c1 = name[len];
name[len] = NUL;
p = get_tv_string_chk(tv);
if (p != NULL && op != NULL && *op == '.')
{
int mustfree = FALSE;
char_u *s = vim_getenv(name, &mustfree);
 
if (s != NULL)
{
p = tofree = concat_str(s, p);
if (mustfree)
vim_free(s);
}
}
if (p != NULL)
{
vim_setenv(name, p);
if (STRICMP(name, "HOME") == 0)
init_homedir();
else if (didset_vim && STRICMP(name, "VIM") == 0)
didset_vim = FALSE;
else if (didset_vimruntime
&& STRICMP(name, "VIMRUNTIME") == 0)
didset_vimruntime = FALSE;
arg_end = arg;
}
name[len] = c1;
vim_free(tofree);
}
}
}
 
/*
* ":let &option = expr": Set option value.
* ":let &l:option = expr": Set local option value.
* ":let &g:option = expr": Set global option value.
*/
else if (*arg == '&')
{
/* Find the end of the name. */
p = find_option_end(&arg, &opt_flags);
if (p == NULL || (endchars != NULL
&& vim_strchr(endchars, *skipwhite(p)) == NULL))
EMSG(_(e_letunexp));
else
{
long n;
int opt_type;
long numval;
char_u *stringval = NULL;
char_u *s;
 
c1 = *p;
*p = NUL;
 
n = get_tv_number(tv);
s = get_tv_string_chk(tv); /* != NULL if number or string */
if (s != NULL && op != NULL && *op != '=')
{
opt_type = get_option_value(arg, &numval,
&stringval, opt_flags);
if ((opt_type == 1 && *op == '.')
|| (opt_type == 0 && *op != '.'))
EMSG2(_(e_letwrong), op);
else
{
if (opt_type == 1) /* number */
{
if (*op == '+')
n = numval + n;
else
n = numval - n;
}
else if (opt_type == 0 && stringval != NULL) /* string */
{
s = concat_str(stringval, s);
vim_free(stringval);
stringval = s;
}
}
}
if (s != NULL)
{
set_option_value(arg, n, s, opt_flags);
arg_end = p;
}
*p = c1;
vim_free(stringval);
}
}
 
/*
* ":let @r = expr": Set register contents.
*/
else if (*arg == '@')
{
++arg;
if (op != NULL && (*op == '+' || *op == '-'))
EMSG2(_(e_letwrong), op);
else if (endchars != NULL
&& vim_strchr(endchars, *skipwhite(arg + 1)) == NULL)
EMSG(_(e_letunexp));
else
{
char_u *ptofree = NULL;
char_u *s;
 
p = get_tv_string_chk(tv);
if (p != NULL && op != NULL && *op == '.')
{
s = get_reg_contents(*arg == '@' ? '"' : *arg, TRUE, TRUE);
if (s != NULL)
{
p = ptofree = concat_str(s, p);
vim_free(s);
}
}
if (p != NULL)
{
write_reg_contents(*arg == '@' ? '"' : *arg, p, -1, FALSE);
arg_end = arg + 1;
}
vim_free(ptofree);
}
}
 
/*
* ":let var = expr": Set internal variable.
* ":let {expr} = expr": Idem, name made with curly braces
*/
else if (eval_isnamec1(*arg) || *arg == '{')
{
lval_T lv;
 
p = get_lval(arg, tv, &lv, FALSE, FALSE, FALSE, FNE_CHECK_START);
if (p != NULL && lv.ll_name != NULL)
{
if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL)
EMSG(_(e_letunexp));
else
{
set_var_lval(&lv, p, tv, copy, op);
arg_end = p;
}
}
clear_lval(&lv);
}
 
else
EMSG2(_(e_invarg2), arg);
 
return arg_end;
}
 
/*
* If "arg" is equal to "b:changedtick" give an error and return TRUE.
*/
static int
check_changedtick(arg)
char_u *arg;
{
if (STRNCMP(arg, "b:changedtick", 13) == 0 && !eval_isnamec(arg[13]))
{
EMSG2(_(e_readonlyvar), arg);
return TRUE;
}
return FALSE;
}
 
/*
* Get an lval: variable, Dict item or List item that can be assigned a value
* to: "name", "na{me}", "name[expr]", "name[expr:expr]", "name[expr][expr]",
* "name.key", "name.key[expr]" etc.
* Indexing only works if "name" is an existing List or Dictionary.
* "name" points to the start of the name.
* If "rettv" is not NULL it points to the value to be assigned.
* "unlet" is TRUE for ":unlet": slightly different behavior when something is
* wrong; must end in space or cmd separator.
*
* Returns a pointer to just after the name, including indexes.
* When an evaluation error occurs "lp->ll_name" is NULL;
* Returns NULL for a parsing error. Still need to free items in "lp"!
*/
static char_u *
get_lval(name, rettv, lp, unlet, skip, quiet, fne_flags)
char_u *name;
typval_T *rettv;
lval_T *lp;
int unlet;
int skip;
int quiet; /* don't give error messages */
int fne_flags; /* flags for find_name_end() */
{
char_u *p;
char_u *expr_start, *expr_end;
int cc;
dictitem_T *v;
typval_T var1;
typval_T var2;
int empty1 = FALSE;
listitem_T *ni;
char_u *key = NULL;
int len;
hashtab_T *ht;
 
/* Clear everything in "lp". */
vim_memset(lp, 0, sizeof(lval_T));
 
if (skip)
{
/* When skipping just find the end of the name. */
lp->ll_name = name;
return find_name_end(name, NULL, NULL, FNE_INCL_BR | fne_flags);
}
 
/* Find the end of the name. */
p = find_name_end(name, &expr_start, &expr_end, fne_flags);
if (expr_start != NULL)
{
/* Don't expand the name when we already know there is an error. */
if (unlet && !vim_iswhite(*p) && !ends_excmd(*p)
&& *p != '[' && *p != '.')
{
EMSG(_(e_trailing));
return NULL;
}
 
lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p);
if (lp->ll_exp_name == NULL)
{
/* Report an invalid expression in braces, unless the
* expression evaluation has been cancelled due to an
* aborting error, an interrupt, or an exception. */
if (!aborting() && !quiet)
{
emsg_severe = TRUE;
EMSG2(_(e_invarg2), name);
return NULL;
}
}
lp->ll_name = lp->ll_exp_name;
}
else
lp->ll_name = name;
 
/* Without [idx] or .key we are done. */
if ((*p != '[' && *p != '.') || lp->ll_name == NULL)
return p;
 
cc = *p;
*p = NUL;
v = find_var(lp->ll_name, &ht);
if (v == NULL && !quiet)
EMSG2(_(e_undefvar), lp->ll_name);
*p = cc;
if (v == NULL)
return NULL;
 
/*
* Loop until no more [idx] or .key is following.
*/
lp->ll_tv = &v->di_tv;
while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT))
{
if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL)
&& !(lp->ll_tv->v_type == VAR_DICT
&& lp->ll_tv->vval.v_dict != NULL))
{
if (!quiet)
EMSG(_("E689: Can only index a List or Dictionary"));
return NULL;
}
if (lp->ll_range)
{
if (!quiet)
EMSG(_("E708: [:] must come last"));
return NULL;
}
 
len = -1;
if (*p == '.')
{
key = p + 1;
for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len)
;
if (len == 0)
{
if (!quiet)
EMSG(_(e_emptykey));
return NULL;
}
p = key + len;
}
else
{
/* Get the index [expr] or the first index [expr: ]. */
p = skipwhite(p + 1);
if (*p == ':')
empty1 = TRUE;
else
{
empty1 = FALSE;
if (eval1(&p, &var1, TRUE) == FAIL) /* recursive! */
return NULL;
if (get_tv_string_chk(&var1) == NULL)
{
/* not a number or string */
clear_tv(&var1);
return NULL;
}
}
 
/* Optionally get the second index [ :expr]. */
if (*p == ':')
{
if (lp->ll_tv->v_type == VAR_DICT)
{
if (!quiet)
EMSG(_(e_dictrange));
if (!empty1)
clear_tv(&var1);
return NULL;
}
if (rettv != NULL && (rettv->v_type != VAR_LIST
|| rettv->vval.v_list == NULL))
{
if (!quiet)
EMSG(_("E709: [:] requires a List value"));
if (!empty1)
clear_tv(&var1);
return NULL;
}
p = skipwhite(p + 1);
if (*p == ']')
lp->ll_empty2 = TRUE;
else
{
lp->ll_empty2 = FALSE;
if (eval1(&p, &var2, TRUE) == FAIL) /* recursive! */
{
if (!empty1)
clear_tv(&var1);
return NULL;
}
if (get_tv_string_chk(&var2) == NULL)
{
/* not a number or string */
if (!empty1)
clear_tv(&var1);
clear_tv(&var2);
return NULL;
}
}
lp->ll_range = TRUE;
}
else
lp->ll_range = FALSE;
 
if (*p != ']')
{
if (!quiet)
EMSG(_(e_missbrac));
if (!empty1)
clear_tv(&var1);
if (lp->ll_range && !lp->ll_empty2)
clear_tv(&var2);
return NULL;
}
 
/* Skip to past ']'. */
++p;
}
 
if (lp->ll_tv->v_type == VAR_DICT)
{
if (len == -1)
{
/* "[key]": get key from "var1" */
key = get_tv_string(&var1); /* is number or string */
if (*key == NUL)
{
if (!quiet)
EMSG(_(e_emptykey));
clear_tv(&var1);
return NULL;
}
}
lp->ll_list = NULL;
lp->ll_dict = lp->ll_tv->vval.v_dict;
lp->ll_di = dict_find(lp->ll_dict, key, len);
if (lp->ll_di == NULL)
{
/* Key does not exist in dict: may need to add it. */
if (*p == '[' || *p == '.' || unlet)
{
if (!quiet)
EMSG2(_(e_dictkey), key);
if (len == -1)
clear_tv(&var1);
return NULL;
}
if (len == -1)
lp->ll_newkey = vim_strsave(key);
else
lp->ll_newkey = vim_strnsave(key, len);
if (len == -1)
clear_tv(&var1);
if (lp->ll_newkey == NULL)
p = NULL;
break;
}
if (len == -1)
clear_tv(&var1);
lp->ll_tv = &lp->ll_di->di_tv;
}
else
{
/*
* Get the number and item for the only or first index of the List.
*/
if (empty1)
lp->ll_n1 = 0;
else
{
lp->ll_n1 = get_tv_number(&var1); /* is number or string */
clear_tv(&var1);
}
lp->ll_dict = NULL;
lp->ll_list = lp->ll_tv->vval.v_list;
lp->ll_li = list_find(lp->ll_list, lp->ll_n1);
if (lp->ll_li == NULL)
{
if (lp->ll_n1 < 0)
{
lp->ll_n1 = 0;
lp->ll_li = list_find(lp->ll_list, lp->ll_n1);
}
}
if (lp->ll_li == NULL)
{
if (lp->ll_range && !lp->ll_empty2)
clear_tv(&var2);
return NULL;
}
 
/*
* May need to find the item or absolute index for the second
* index of a range.
* When no index given: "lp->ll_empty2" is TRUE.
* Otherwise "lp->ll_n2" is set to the second index.
*/
if (lp->ll_range && !lp->ll_empty2)
{
lp->ll_n2 = get_tv_number(&var2); /* is number or string */
clear_tv(&var2);
if (lp->ll_n2 < 0)
{
ni = list_find(lp->ll_list, lp->ll_n2);
if (ni == NULL)
return NULL;
lp->ll_n2 = list_idx_of_item(lp->ll_list, ni);
}
 
/* Check that lp->ll_n2 isn't before lp->ll_n1. */
if (lp->ll_n1 < 0)
lp->ll_n1 = list_idx_of_item(lp->ll_list, lp->ll_li);
if (lp->ll_n2 < lp->ll_n1)
return NULL;
}
 
lp->ll_tv = &lp->ll_li->li_tv;
}
}
 
return p;
}
 
/*
* Clear lval "lp" that was filled by get_lval().
*/
static void
clear_lval(lp)
lval_T *lp;
{
vim_free(lp->ll_exp_name);
vim_free(lp->ll_newkey);
}
 
/*
* Set a variable that was parsed by get_lval() to "rettv".
* "endp" points to just after the parsed name.
* "op" is NULL, "+" for "+=", "-" for "-=", "." for ".=" or "=" for "=".
*/
static void
set_var_lval(lp, endp, rettv, copy, op)
lval_T *lp;
char_u *endp;
typval_T *rettv;
int copy;
char_u *op;
{
int cc;
listitem_T *ri;
dictitem_T *di;
 
if (lp->ll_tv == NULL)
{
if (!check_changedtick(lp->ll_name))
{
cc = *endp;
*endp = NUL;
if (op != NULL && *op != '=')
{
typval_T tv;
 
/* handle +=, -= and .= */
if (get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name),
&tv, TRUE) == OK)
{
if (tv_op(&tv, rettv, op) == OK)
set_var(lp->ll_name, &tv, FALSE);
clear_tv(&tv);
}
}
else
set_var(lp->ll_name, rettv, copy);
*endp = cc;
}
}
else if (tv_check_lock(lp->ll_newkey == NULL
? lp->ll_tv->v_lock
: lp->ll_tv->vval.v_dict->dv_lock, lp->ll_name))
;
else if (lp->ll_range)
{
/*
* Assign the List values to the list items.
*/
for (ri = rettv->vval.v_list->lv_first; ri != NULL; )
{
if (op != NULL && *op != '=')
tv_op(&lp->ll_li->li_tv, &ri->li_tv, op);
else
{
clear_tv(&lp->ll_li->li_tv);
copy_tv(&ri->li_tv, &lp->ll_li->li_tv);
}
ri = ri->li_next;
if (ri == NULL || (!lp->ll_empty2 && lp->ll_n2 == lp->ll_n1))
break;
if (lp->ll_li->li_next == NULL)
{
/* Need to add an empty item. */
if (list_append_number(lp->ll_list, 0) == FAIL)
{
ri = NULL;
break;
}
}
lp->ll_li = lp->ll_li->li_next;
++lp->ll_n1;
}
if (ri != NULL)
EMSG(_("E710: List value has more items than target"));
else if (lp->ll_empty2
? (lp->ll_li != NULL && lp->ll_li->li_next != NULL)
: lp->ll_n1 != lp->ll_n2)
EMSG(_("E711: List value has not enough items"));
}
else
{
/*
* Assign to a List or Dictionary item.
*/
if (lp->ll_newkey != NULL)
{
if (op != NULL && *op != '=')
{
EMSG2(_(e_letwrong), op);
return;
}
 
/* Need to add an item to the Dictionary. */
di = dictitem_alloc(lp->ll_newkey);
if (di == NULL)
return;
if (dict_add(lp->ll_tv->vval.v_dict, di) == FAIL)
{
vim_free(di);
return;
}
lp->ll_tv = &di->di_tv;
}
else if (op != NULL && *op != '=')
{
tv_op(lp->ll_tv, rettv, op);
return;
}
else
clear_tv(lp->ll_tv);
 
/*
* Assign the value to the variable or list item.
*/
if (copy)
copy_tv(rettv, lp->ll_tv);
else
{
*lp->ll_tv = *rettv;
lp->ll_tv->v_lock = 0;
init_tv(rettv);
}
}
}
 
/*
* Handle "tv1 += tv2", "tv1 -= tv2" and "tv1 .= tv2"
* Returns OK or FAIL.
*/
static int
tv_op(tv1, tv2, op)
typval_T *tv1;
typval_T *tv2;
char_u *op;
{
long n;
char_u numbuf[NUMBUFLEN];
char_u *s;
 
/* Can't do anything with a Funcref or a Dict on the right. */
if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT)
{
switch (tv1->v_type)
{
case VAR_DICT:
case VAR_FUNC:
break;
 
case VAR_LIST:
if (*op != '+' || tv2->v_type != VAR_LIST)
break;
/* List += List */
if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL)
list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL);
return OK;
 
case VAR_NUMBER:
case VAR_STRING:
if (tv2->v_type == VAR_LIST)
break;
if (*op == '+' || *op == '-')
{
/* nr += nr or nr -= nr*/
n = get_tv_number(tv1);
if (*op == '+')
n += get_tv_number(tv2);
else
n -= get_tv_number(tv2);
clear_tv(tv1);
tv1->v_type = VAR_NUMBER;
tv1->vval.v_number = n;
}
else
{
/* str .= str */
s = get_tv_string(tv1);
s = concat_str(s, get_tv_string_buf(tv2, numbuf));
clear_tv(tv1);
tv1->v_type = VAR_STRING;
tv1->vval.v_string = s;
}
return OK;
}
}
 
EMSG2(_(e_letwrong), op);
return FAIL;
}
 
/*
* Add a watcher to a list.
*/
static void
list_add_watch(l, lw)
list_T *l;
listwatch_T *lw;
{
lw->lw_next = l->lv_watch;
l->lv_watch = lw;
}
 
/*
* Remove a watcher from a list.
* No warning when it isn't found...
*/
static void
list_rem_watch(l, lwrem)
list_T *l;
listwatch_T *lwrem;
{
listwatch_T *lw, **lwp;
 
lwp = &l->lv_watch;
for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next)
{
if (lw == lwrem)
{
*lwp = lw->lw_next;
break;
}
lwp = &lw->lw_next;
}
}
 
/*
* Just before removing an item from a list: advance watchers to the next
* item.
*/
static void
list_fix_watch(l, item)
list_T *l;
listitem_T *item;
{
listwatch_T *lw;
 
for (lw = l->lv_watch; lw != NULL; lw = lw->lw_next)
if (lw->lw_item == item)
lw->lw_item = item->li_next;
}
 
/*
* Evaluate the expression used in a ":for var in expr" command.
* "arg" points to "var".
* Set "*errp" to TRUE for an error, FALSE otherwise;
* Return a pointer that holds the info. Null when there is an error.
*/
void *
eval_for_line(arg, errp, nextcmdp, skip)
char_u *arg;
int *errp;
char_u **nextcmdp;
int skip;
{
forinfo_T *fi;
char_u *expr;
typval_T tv;
list_T *l;
 
*errp = TRUE; /* default: there is an error */
 
fi = (forinfo_T *)alloc_clear(sizeof(forinfo_T));
if (fi == NULL)
return NULL;
 
expr = skip_var_list(arg, &fi->fi_varcount, &fi->fi_semicolon);
if (expr == NULL)
return fi;
 
expr = skipwhite(expr);
if (expr[0] != 'i' || expr[1] != 'n' || !vim_iswhite(expr[2]))
{
EMSG(_("E690: Missing \"in\" after :for"));
return fi;
}
 
if (skip)
++emsg_skip;
if (eval0(skipwhite(expr + 2), &tv, nextcmdp, !skip) == OK)
{
*errp = FALSE;
if (!skip)
{
l = tv.vval.v_list;
if (tv.v_type != VAR_LIST || l == NULL)
{
EMSG(_(e_listreq));
clear_tv(&tv);
}
else
{
/* No need to increment the refcount, it's already set for the
* list being used in "tv". */
fi->fi_list = l;
list_add_watch(l, &fi->fi_lw);
fi->fi_lw.lw_item = l->lv_first;
}
}
}
if (skip)
--emsg_skip;
 
return fi;
}
 
/*
* Use the first item in a ":for" list. Advance to the next.
* Assign the values to the variable (list). "arg" points to the first one.
* Return TRUE when a valid item was found, FALSE when at end of list or
* something wrong.
*/
int
next_for_item(fi_void, arg)
void *fi_void;
char_u *arg;
{
forinfo_T *fi = (forinfo_T *)fi_void;
int result;
listitem_T *item;
 
item = fi->fi_lw.lw_item;
if (item == NULL)
result = FALSE;
else
{
fi->fi_lw.lw_item = item->li_next;
result = (ex_let_vars(arg, &item->li_tv, TRUE,
fi->fi_semicolon, fi->fi_varcount, NULL) == OK);
}
return result;
}
 
/*
* Free the structure used to store info used by ":for".
*/
void
free_for_info(fi_void)
void *fi_void;
{
forinfo_T *fi = (forinfo_T *)fi_void;
 
if (fi != NULL && fi->fi_list != NULL)
{
list_rem_watch(fi->fi_list, &fi->fi_lw);
list_unref(fi->fi_list);
}
vim_free(fi);
}
 
#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
 
void
set_context_for_expression(xp, arg, cmdidx)
expand_T *xp;
char_u *arg;
cmdidx_T cmdidx;
{
int got_eq = FALSE;
int c;
char_u *p;
 
if (cmdidx == CMD_let)
{
xp->xp_context = EXPAND_USER_VARS;
if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL)
{
/* ":let var1 var2 ...": find last space. */
for (p = arg + STRLEN(arg); p >= arg; )
{
xp->xp_pattern = p;
mb_ptr_back(arg, p);
if (vim_iswhite(*p))
break;
}
return;
}
}
else
xp->xp_context = cmdidx == CMD_call ? EXPAND_FUNCTIONS
: EXPAND_EXPRESSION;
while ((xp->xp_pattern = vim_strpbrk(arg,
(char_u *)"\"'+-*/%.=!?~|&$([<>,#")) != NULL)
{
c = *xp->xp_pattern;
if (c == '&')
{
c = xp->xp_pattern[1];
if (c == '&')
{
++xp->xp_pattern;
xp->xp_context = cmdidx != CMD_let || got_eq
? EXPAND_EXPRESSION : EXPAND_NOTHING;
}
else if (c != ' ')
{
xp->xp_context = EXPAND_SETTINGS;
if ((c == 'l' || c == 'g') && xp->xp_pattern[2] == ':')
xp->xp_pattern += 2;
 
}
}
else if (c == '$')
{
/* environment variable */
xp->xp_context = EXPAND_ENV_VARS;
}
else if (c == '=')
{
got_eq = TRUE;
xp->xp_context = EXPAND_EXPRESSION;
}
else if (c == '<'
&& xp->xp_context == EXPAND_FUNCTIONS
&& vim_strchr(xp->xp_pattern, '(') == NULL)
{
/* Function name can start with "<SNR>" */
break;
}
else if (cmdidx != CMD_let || got_eq)
{
if (c == '"') /* string */
{
while ((c = *++xp->xp_pattern) != NUL && c != '"')
if (c == '\\' && xp->xp_pattern[1] != NUL)
++xp->xp_pattern;
xp->xp_context = EXPAND_NOTHING;
}
else if (c == '\'') /* literal string */
{
/* Trick: '' is like stopping and starting a literal string. */
while ((c = *++xp->xp_pattern) != NUL && c != '\'')
/* skip */ ;
xp->xp_context = EXPAND_NOTHING;
}
else if (c == '|')
{
if (xp->xp_pattern[1] == '|')
{
++xp->xp_pattern;
xp->xp_context = EXPAND_EXPRESSION;
}
else
xp->xp_context = EXPAND_COMMANDS;
}
else
xp->xp_context = EXPAND_EXPRESSION;
}
else
/* Doesn't look like something valid, expand as an expression
* anyway. */
xp->xp_context = EXPAND_EXPRESSION;
arg = xp->xp_pattern;
if (*arg != NUL)
while ((c = *++arg) != NUL && (c == ' ' || c == '\t'))
/* skip */ ;
}
xp->xp_pattern = arg;
}
 
#endif /* FEAT_CMDL_COMPL */
 
/*
* ":1,25call func(arg1, arg2)" function call.
*/
void
ex_call(eap)
exarg_T *eap;
{
char_u *arg = eap->arg;
char_u *startarg;
char_u *name;
char_u *tofree;
int len;
typval_T rettv;
linenr_T lnum;
int doesrange;
int failed = FALSE;
funcdict_T fudi;
 
tofree = trans_function_name(&arg, eap->skip, TFN_INT, &fudi);
if (fudi.fd_newkey != NULL)
{
/* Still need to give an error message for missing key. */
EMSG2(_(e_dictkey), fudi.fd_newkey);
vim_free(fudi.fd_newkey);
}
if (tofree == NULL)
return;
 
/* Increase refcount on dictionary, it could get deleted when evaluating
* the arguments. */
if (fudi.fd_dict != NULL)
++fudi.fd_dict->dv_refcount;
 
/* If it is the name of a variable of type VAR_FUNC use its contents. */
len = (int)STRLEN(tofree);
name = deref_func_name(tofree, &len);
 
/* Skip white space to allow ":call func ()". Not good, but required for
* backward compatibility. */
startarg = skipwhite(arg);
rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */
 
if (*startarg != '(')
{
EMSG2(_("E107: Missing braces: %s"), eap->arg);
goto end;
}
 
/*
* When skipping, evaluate the function once, to find the end of the
* arguments.
* When the function takes a range, this is discovered after the first
* call, and the loop is broken.
*/
if (eap->skip)
{
++emsg_skip;
lnum = eap->line2; /* do it once, also with an invalid range */
}
else
lnum = eap->line1;
for ( ; lnum <= eap->line2; ++lnum)
{
if (!eap->skip && eap->addr_count > 0)
{
curwin->w_cursor.lnum = lnum;
curwin->w_cursor.col = 0;
}
arg = startarg;
if (get_func_tv(name, (int)STRLEN(name), &rettv, &arg,
eap->line1, eap->line2, &doesrange,
!eap->skip, fudi.fd_dict) == FAIL)
{
failed = TRUE;
break;
}
 
/* Handle a function returning a Funcref, Dictionary or List. */
if (handle_subscript(&arg, &rettv, !eap->skip, TRUE) == FAIL)
{
failed = TRUE;
break;
}
 
clear_tv(&rettv);
if (doesrange || eap->skip)
break;
 
/* Stop when immediately aborting on error, or when an interrupt
* occurred or an exception was thrown but not caught.
* get_func_tv() returned OK, so that the check for trailing
* characters below is executed. */
if (aborting())
break;
}
if (eap->skip)
--emsg_skip;
 
if (!failed)
{
/* Check for trailing illegal characters and a following command. */
if (!ends_excmd(*arg))
{
emsg_severe = TRUE;
EMSG(_(e_trailing));
}
else
eap->nextcmd = check_nextcmd(arg);
}
 
end:
dict_unref(fudi.fd_dict);
vim_free(tofree);
}
 
/*
* ":unlet[!] var1 ... " command.
*/
void
ex_unlet(eap)
exarg_T *eap;
{
ex_unletlock(eap, eap->arg, 0);
}
 
/*
* ":lockvar" and ":unlockvar" commands
*/
void
ex_lockvar(eap)
exarg_T *eap;
{
char_u *arg = eap->arg;
int deep = 2;
 
if (eap->forceit)
deep = -1;
else if (vim_isdigit(*arg))
{
deep = getdigits(&arg);
arg = skipwhite(arg);
}
 
ex_unletlock(eap, arg, deep);
}
 
/*
* ":unlet", ":lockvar" and ":unlockvar" are quite similar.
*/
static void
ex_unletlock(eap, argstart, deep)
exarg_T *eap;
char_u *argstart;
int deep;
{
char_u *arg = argstart;
char_u *name_end;
int error = FALSE;
lval_T lv;
 
do
{
/* Parse the name and find the end. */
name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, FALSE,
FNE_CHECK_START);
if (lv.ll_name == NULL)
error = TRUE; /* error but continue parsing */
if (name_end == NULL || (!vim_iswhite(*name_end)
&& !ends_excmd(*name_end)))
{
if (name_end != NULL)
{
emsg_severe = TRUE;
EMSG(_(e_trailing));
}
if (!(eap->skip || error))
clear_lval(&lv);
break;
}
 
if (!error && !eap->skip)
{
if (eap->cmdidx == CMD_unlet)
{
if (do_unlet_var(&lv, name_end, eap->forceit) == FAIL)
error = TRUE;
}
else
{
if (do_lock_var(&lv, name_end, deep,
eap->cmdidx == CMD_lockvar) == FAIL)
error = TRUE;
}
}
 
if (!eap->skip)
clear_lval(&lv);
 
arg = skipwhite(name_end);
} while (!ends_excmd(*arg));
 
eap->nextcmd = check_nextcmd(arg);
}
 
static int
do_unlet_var(lp, name_end, forceit)
lval_T *lp;
char_u *name_end;
int forceit;
{
int ret = OK;
int cc;
 
if (lp->ll_tv == NULL)
{
cc = *name_end;
*name_end = NUL;
 
/* Normal name or expanded name. */
if (check_changedtick(lp->ll_name))
ret = FAIL;
else if (do_unlet(lp->ll_name, forceit) == FAIL)
ret = FAIL;
*name_end = cc;
}
else if (tv_check_lock(lp->ll_tv->v_lock, lp->ll_name))
return FAIL;
else if (lp->ll_range)
{
listitem_T *li;
 
/* Delete a range of List items. */
while (lp->ll_li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1))
{
li = lp->ll_li->li_next;
listitem_remove(lp->ll_list, lp->ll_li);
lp->ll_li = li;
++lp->ll_n1;
}
}
else
{
if (lp->ll_list != NULL)
/* unlet a List item. */
listitem_remove(lp->ll_list, lp->ll_li);
else
/* unlet a Dictionary item. */
dictitem_remove(lp->ll_dict, lp->ll_di);
}
 
return ret;
}
 
/*
* "unlet" a variable. Return OK if it existed, FAIL if not.
* When "forceit" is TRUE don't complain if the variable doesn't exist.
*/
int
do_unlet(name, forceit)
char_u *name;
int forceit;
{
hashtab_T *ht;
hashitem_T *hi;
char_u *varname;
 
ht = find_var_ht(name, &varname);
if (ht != NULL && *varname != NUL)
{
hi = hash_find(ht, varname);
if (!HASHITEM_EMPTY(hi))
{
if (var_check_fixed(HI2DI(hi)->di_flags, name))
return FAIL;
if (var_check_ro(HI2DI(hi)->di_flags, name))
return FAIL;
delete_var(ht, hi);
return OK;
}
}
if (forceit)
return OK;
EMSG2(_("E108: No such variable: \"%s\""), name);
return FAIL;
}
 
/*
* Lock or unlock variable indicated by "lp".
* "deep" is the levels to go (-1 for unlimited);
* "lock" is TRUE for ":lockvar", FALSE for ":unlockvar".
*/
static int
do_lock_var(lp, name_end, deep, lock)
lval_T *lp;
char_u *name_end;
int deep;
int lock;
{
int ret = OK;
int cc;
dictitem_T *di;
 
if (deep == 0) /* nothing to do */
return OK;
 
if (lp->ll_tv == NULL)
{
cc = *name_end;
*name_end = NUL;
 
/* Normal name or expanded name. */
if (check_changedtick(lp->ll_name))
ret = FAIL;
else
{
di = find_var(lp->ll_name, NULL);
if (di == NULL)
ret = FAIL;
else
{
if (lock)
di->di_flags |= DI_FLAGS_LOCK;
else
di->di_flags &= ~DI_FLAGS_LOCK;
item_lock(&di->di_tv, deep, lock);
}
}
*name_end = cc;
}
else if (lp->ll_range)
{
listitem_T *li = lp->ll_li;
 
/* (un)lock a range of List items. */
while (li != NULL && (lp->ll_empty2 || lp->ll_n2 >= lp->ll_n1))
{
item_lock(&li->li_tv, deep, lock);
li = li->li_next;
++lp->ll_n1;
}
}
else if (lp->ll_list != NULL)
/* (un)lock a List item. */
item_lock(&lp->ll_li->li_tv, deep, lock);
else
/* un(lock) a Dictionary item. */
item_lock(&lp->ll_di->di_tv, deep, lock);
 
return ret;
}
 
/*
* Lock or unlock an item. "deep" is nr of levels to go.
*/
static void
item_lock(tv, deep, lock)
typval_T *tv;
int deep;
int lock;
{
static int recurse = 0;
list_T *l;
listitem_T *li;
dict_T *d;
hashitem_T *hi;
int todo;
 
if (recurse >= DICT_MAXNEST)
{
EMSG(_("E743: variable nested too deep for (un)lock"));
return;
}
if (deep == 0)
return;
++recurse;
 
/* lock/unlock the item itself */
if (lock)
tv->v_lock |= VAR_LOCKED;
else
tv->v_lock &= ~VAR_LOCKED;
 
switch (tv->v_type)
{
case VAR_LIST:
if ((l = tv->vval.v_list) != NULL)
{
if (lock)
l->lv_lock |= VAR_LOCKED;
else
l->lv_lock &= ~VAR_LOCKED;
if (deep < 0 || deep > 1)
/* recursive: lock/unlock the items the List contains */
for (li = l->lv_first; li != NULL; li = li->li_next)
item_lock(&li->li_tv, deep - 1, lock);
}
break;
case VAR_DICT:
if ((d = tv->vval.v_dict) != NULL)
{
if (lock)
d->dv_lock |= VAR_LOCKED;
else
d->dv_lock &= ~VAR_LOCKED;
if (deep < 0 || deep > 1)
{
/* recursive: lock/unlock the items the List contains */
todo = (int)d->dv_hashtab.ht_used;
for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
item_lock(&HI2DI(hi)->di_tv, deep - 1, lock);
}
}
}
}
}
--recurse;
}
 
/*
* Return TRUE if typeval "tv" is locked: Either tha value is locked itself or
* it refers to a List or Dictionary that is locked.
*/
static int
tv_islocked(tv)
typval_T *tv;
{
return (tv->v_lock & VAR_LOCKED)
|| (tv->v_type == VAR_LIST
&& tv->vval.v_list != NULL
&& (tv->vval.v_list->lv_lock & VAR_LOCKED))
|| (tv->v_type == VAR_DICT
&& tv->vval.v_dict != NULL
&& (tv->vval.v_dict->dv_lock & VAR_LOCKED));
}
 
#if (defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)) || defined(PROTO)
/*
* Delete all "menutrans_" variables.
*/
void
del_menutrans_vars()
{
hashitem_T *hi;
int todo;
 
hash_lock(&globvarht);
todo = (int)globvarht.ht_used;
for (hi = globvarht.ht_array; todo > 0 && !got_int; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
if (STRNCMP(HI2DI(hi)->di_key, "menutrans_", 10) == 0)
delete_var(&globvarht, hi);
}
}
hash_unlock(&globvarht);
}
#endif
 
#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
 
/*
* Local string buffer for the next two functions to store a variable name
* with its prefix. Allocated in cat_prefix_varname(), freed later in
* get_user_var_name().
*/
 
static char_u *cat_prefix_varname __ARGS((int prefix, char_u *name));
 
static char_u *varnamebuf = NULL;
static int varnamebuflen = 0;
 
/*
* Function to concatenate a prefix and a variable name.
*/
static char_u *
cat_prefix_varname(prefix, name)
int prefix;
char_u *name;
{
int len;
 
len = (int)STRLEN(name) + 3;
if (len > varnamebuflen)
{
vim_free(varnamebuf);
len += 10; /* some additional space */
varnamebuf = alloc(len);
if (varnamebuf == NULL)
{
varnamebuflen = 0;
return NULL;
}
varnamebuflen = len;
}
*varnamebuf = prefix;
varnamebuf[1] = ':';
STRCPY(varnamebuf + 2, name);
return varnamebuf;
}
 
/*
* Function given to ExpandGeneric() to obtain the list of user defined
* (global/buffer/window/built-in) variable names.
*/
/*ARGSUSED*/
char_u *
get_user_var_name(xp, idx)
expand_T *xp;
int idx;
{
static long_u gdone;
static long_u bdone;
static long_u wdone;
#ifdef FEAT_WINDOWS
static long_u tdone;
#endif
static int vidx;
static hashitem_T *hi;
hashtab_T *ht;
 
if (idx == 0)
{
gdone = bdone = wdone = vidx = 0;
#ifdef FEAT_WINDOWS
tdone = 0;
#endif
}
 
/* Global variables */
if (gdone < globvarht.ht_used)
{
if (gdone++ == 0)
hi = globvarht.ht_array;
else
++hi;
while (HASHITEM_EMPTY(hi))
++hi;
if (STRNCMP("g:", xp->xp_pattern, 2) == 0)
return cat_prefix_varname('g', hi->hi_key);
return hi->hi_key;
}
 
/* b: variables */
ht = &curbuf->b_vars.dv_hashtab;
if (bdone < ht->ht_used)
{
if (bdone++ == 0)
hi = ht->ht_array;
else
++hi;
while (HASHITEM_EMPTY(hi))
++hi;
return cat_prefix_varname('b', hi->hi_key);
}
if (bdone == ht->ht_used)
{
++bdone;
return (char_u *)"b:changedtick";
}
 
/* w: variables */
ht = &curwin->w_vars.dv_hashtab;
if (wdone < ht->ht_used)
{
if (wdone++ == 0)
hi = ht->ht_array;
else
++hi;
while (HASHITEM_EMPTY(hi))
++hi;
return cat_prefix_varname('w', hi->hi_key);
}
 
#ifdef FEAT_WINDOWS
/* t: variables */
ht = &curtab->tp_vars.dv_hashtab;
if (tdone < ht->ht_used)
{
if (tdone++ == 0)
hi = ht->ht_array;
else
++hi;
while (HASHITEM_EMPTY(hi))
++hi;
return cat_prefix_varname('t', hi->hi_key);
}
#endif
 
/* v: variables */
if (vidx < VV_LEN)
return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name);
 
vim_free(varnamebuf);
varnamebuf = NULL;
varnamebuflen = 0;
return NULL;
}
 
#endif /* FEAT_CMDL_COMPL */
 
/*
* types for expressions.
*/
typedef enum
{
TYPE_UNKNOWN = 0
, TYPE_EQUAL /* == */
, TYPE_NEQUAL /* != */
, TYPE_GREATER /* > */
, TYPE_GEQUAL /* >= */
, TYPE_SMALLER /* < */
, TYPE_SEQUAL /* <= */
, TYPE_MATCH /* =~ */
, TYPE_NOMATCH /* !~ */
} exptype_T;
 
/*
* The "evaluate" argument: When FALSE, the argument is only parsed but not
* executed. The function may return OK, but the rettv will be of type
* VAR_UNKNOWN. The function still returns FAIL for a syntax error.
*/
 
/*
* Handle zero level expression.
* This calls eval1() and handles error message and nextcmd.
* Put the result in "rettv" when returning OK and "evaluate" is TRUE.
* Note: "rettv.v_lock" is not set.
* Return OK or FAIL.
*/
static int
eval0(arg, rettv, nextcmd, evaluate)
char_u *arg;
typval_T *rettv;
char_u **nextcmd;
int evaluate;
{
int ret;
char_u *p;
 
p = skipwhite(arg);
ret = eval1(&p, rettv, evaluate);
if (ret == FAIL || !ends_excmd(*p))
{
if (ret != FAIL)
clear_tv(rettv);
/*
* Report the invalid expression unless the expression evaluation has
* been cancelled due to an aborting error, an interrupt, or an
* exception.
*/
if (!aborting())
EMSG2(_(e_invexpr2), arg);
ret = FAIL;
}
if (nextcmd != NULL)
*nextcmd = check_nextcmd(p);
 
return ret;
}
 
/*
* Handle top level expression:
* expr1 ? expr0 : expr0
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
*
* Note: "rettv.v_lock" is not set.
*
* Return OK or FAIL.
*/
static int
eval1(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
int result;
typval_T var2;
 
/*
* Get the first variable.
*/
if (eval2(arg, rettv, evaluate) == FAIL)
return FAIL;
 
if ((*arg)[0] == '?')
{
result = FALSE;
if (evaluate)
{
int error = FALSE;
 
if (get_tv_number_chk(rettv, &error) != 0)
result = TRUE;
clear_tv(rettv);
if (error)
return FAIL;
}
 
/*
* Get the second variable.
*/
*arg = skipwhite(*arg + 1);
if (eval1(arg, rettv, evaluate && result) == FAIL) /* recursive! */
return FAIL;
 
/*
* Check for the ":".
*/
if ((*arg)[0] != ':')
{
EMSG(_("E109: Missing ':' after '?'"));
if (evaluate && result)
clear_tv(rettv);
return FAIL;
}
 
/*
* Get the third variable.
*/
*arg = skipwhite(*arg + 1);
if (eval1(arg, &var2, evaluate && !result) == FAIL) /* recursive! */
{
if (evaluate && result)
clear_tv(rettv);
return FAIL;
}
if (evaluate && !result)
*rettv = var2;
}
 
return OK;
}
 
/*
* Handle first level expression:
* expr2 || expr2 || expr2 logical OR
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
*
* Return OK or FAIL.
*/
static int
eval2(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
typval_T var2;
long result;
int first;
int error = FALSE;
 
/*
* Get the first variable.
*/
if (eval3(arg, rettv, evaluate) == FAIL)
return FAIL;
 
/*
* Repeat until there is no following "||".
*/
first = TRUE;
result = FALSE;
while ((*arg)[0] == '|' && (*arg)[1] == '|')
{
if (evaluate && first)
{
if (get_tv_number_chk(rettv, &error) != 0)
result = TRUE;
clear_tv(rettv);
if (error)
return FAIL;
first = FALSE;
}
 
/*
* Get the second variable.
*/
*arg = skipwhite(*arg + 2);
if (eval3(arg, &var2, evaluate && !result) == FAIL)
return FAIL;
 
/*
* Compute the result.
*/
if (evaluate && !result)
{
if (get_tv_number_chk(&var2, &error) != 0)
result = TRUE;
clear_tv(&var2);
if (error)
return FAIL;
}
if (evaluate)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = result;
}
}
 
return OK;
}
 
/*
* Handle second level expression:
* expr3 && expr3 && expr3 logical AND
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
*
* Return OK or FAIL.
*/
static int
eval3(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
typval_T var2;
long result;
int first;
int error = FALSE;
 
/*
* Get the first variable.
*/
if (eval4(arg, rettv, evaluate) == FAIL)
return FAIL;
 
/*
* Repeat until there is no following "&&".
*/
first = TRUE;
result = TRUE;
while ((*arg)[0] == '&' && (*arg)[1] == '&')
{
if (evaluate && first)
{
if (get_tv_number_chk(rettv, &error) == 0)
result = FALSE;
clear_tv(rettv);
if (error)
return FAIL;
first = FALSE;
}
 
/*
* Get the second variable.
*/
*arg = skipwhite(*arg + 2);
if (eval4(arg, &var2, evaluate && result) == FAIL)
return FAIL;
 
/*
* Compute the result.
*/
if (evaluate && result)
{
if (get_tv_number_chk(&var2, &error) == 0)
result = FALSE;
clear_tv(&var2);
if (error)
return FAIL;
}
if (evaluate)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = result;
}
}
 
return OK;
}
 
/*
* Handle third level expression:
* var1 == var2
* var1 =~ var2
* var1 != var2
* var1 !~ var2
* var1 > var2
* var1 >= var2
* var1 < var2
* var1 <= var2
* var1 is var2
* var1 isnot var2
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
*
* Return OK or FAIL.
*/
static int
eval4(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
typval_T var2;
char_u *p;
int i;
exptype_T type = TYPE_UNKNOWN;
int type_is = FALSE; /* TRUE for "is" and "isnot" */
int len = 2;
long n1, n2;
char_u *s1, *s2;
char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
regmatch_T regmatch;
int ic;
char_u *save_cpo;
 
/*
* Get the first variable.
*/
if (eval5(arg, rettv, evaluate) == FAIL)
return FAIL;
 
p = *arg;
switch (p[0])
{
case '=': if (p[1] == '=')
type = TYPE_EQUAL;
else if (p[1] == '~')
type = TYPE_MATCH;
break;
case '!': if (p[1] == '=')
type = TYPE_NEQUAL;
else if (p[1] == '~')
type = TYPE_NOMATCH;
break;
case '>': if (p[1] != '=')
{
type = TYPE_GREATER;
len = 1;
}
else
type = TYPE_GEQUAL;
break;
case '<': if (p[1] != '=')
{
type = TYPE_SMALLER;
len = 1;
}
else
type = TYPE_SEQUAL;
break;
case 'i': if (p[1] == 's')
{
if (p[2] == 'n' && p[3] == 'o' && p[4] == 't')
len = 5;
if (!vim_isIDc(p[len]))
{
type = len == 2 ? TYPE_EQUAL : TYPE_NEQUAL;
type_is = TRUE;
}
}
break;
}
 
/*
* If there is a comparitive operator, use it.
*/
if (type != TYPE_UNKNOWN)
{
/* extra question mark appended: ignore case */
if (p[len] == '?')
{
ic = TRUE;
++len;
}
/* extra '#' appended: match case */
else if (p[len] == '#')
{
ic = FALSE;
++len;
}
/* nothing appened: use 'ignorecase' */
else
ic = p_ic;
 
/*
* Get the second variable.
*/
*arg = skipwhite(p + len);
if (eval5(arg, &var2, evaluate) == FAIL)
{
clear_tv(rettv);
return FAIL;
}
 
if (evaluate)
{
if (type_is && rettv->v_type != var2.v_type)
{
/* For "is" a different type always means FALSE, for "notis"
* it means TRUE. */
n1 = (type == TYPE_NEQUAL);
}
else if (rettv->v_type == VAR_LIST || var2.v_type == VAR_LIST)
{
if (type_is)
{
n1 = (rettv->v_type == var2.v_type
&& rettv->vval.v_list == var2.vval.v_list);
if (type == TYPE_NEQUAL)
n1 = !n1;
}
else if (rettv->v_type != var2.v_type
|| (type != TYPE_EQUAL && type != TYPE_NEQUAL))
{
if (rettv->v_type != var2.v_type)
EMSG(_("E691: Can only compare List with List"));
else
EMSG(_("E692: Invalid operation for Lists"));
clear_tv(rettv);
clear_tv(&var2);
return FAIL;
}
else
{
/* Compare two Lists for being equal or unequal. */
n1 = list_equal(rettv->vval.v_list, var2.vval.v_list, ic);
if (type == TYPE_NEQUAL)
n1 = !n1;
}
}
 
else if (rettv->v_type == VAR_DICT || var2.v_type == VAR_DICT)
{
if (type_is)
{
n1 = (rettv->v_type == var2.v_type
&& rettv->vval.v_dict == var2.vval.v_dict);
if (type == TYPE_NEQUAL)
n1 = !n1;
}
else if (rettv->v_type != var2.v_type
|| (type != TYPE_EQUAL && type != TYPE_NEQUAL))
{
if (rettv->v_type != var2.v_type)
EMSG(_("E735: Can only compare Dictionary with Dictionary"));
else
EMSG(_("E736: Invalid operation for Dictionary"));
clear_tv(rettv);
clear_tv(&var2);
return FAIL;
}
else
{
/* Compare two Dictionaries for being equal or unequal. */
n1 = dict_equal(rettv->vval.v_dict, var2.vval.v_dict, ic);
if (type == TYPE_NEQUAL)
n1 = !n1;
}
}
 
else if (rettv->v_type == VAR_FUNC || var2.v_type == VAR_FUNC)
{
if (rettv->v_type != var2.v_type
|| (type != TYPE_EQUAL && type != TYPE_NEQUAL))
{
if (rettv->v_type != var2.v_type)
EMSG(_("E693: Can only compare Funcref with Funcref"));
else
EMSG(_("E694: Invalid operation for Funcrefs"));
clear_tv(rettv);
clear_tv(&var2);
return FAIL;
}
else
{
/* Compare two Funcrefs for being equal or unequal. */
if (rettv->vval.v_string == NULL
|| var2.vval.v_string == NULL)
n1 = FALSE;
else
n1 = STRCMP(rettv->vval.v_string,
var2.vval.v_string) == 0;
if (type == TYPE_NEQUAL)
n1 = !n1;
}
}
 
/*
* If one of the two variables is a number, compare as a number.
* When using "=~" or "!~", always compare as string.
*/
else if ((rettv->v_type == VAR_NUMBER || var2.v_type == VAR_NUMBER)
&& type != TYPE_MATCH && type != TYPE_NOMATCH)
{
n1 = get_tv_number(rettv);
n2 = get_tv_number(&var2);
switch (type)
{
case TYPE_EQUAL: n1 = (n1 == n2); break;
case TYPE_NEQUAL: n1 = (n1 != n2); break;
case TYPE_GREATER: n1 = (n1 > n2); break;
case TYPE_GEQUAL: n1 = (n1 >= n2); break;
case TYPE_SMALLER: n1 = (n1 < n2); break;
case TYPE_SEQUAL: n1 = (n1 <= n2); break;
case TYPE_UNKNOWN:
case TYPE_MATCH:
case TYPE_NOMATCH: break; /* avoid gcc warning */
}
}
else
{
s1 = get_tv_string_buf(rettv, buf1);
s2 = get_tv_string_buf(&var2, buf2);
if (type != TYPE_MATCH && type != TYPE_NOMATCH)
i = ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2);
else
i = 0;
n1 = FALSE;
switch (type)
{
case TYPE_EQUAL: n1 = (i == 0); break;
case TYPE_NEQUAL: n1 = (i != 0); break;
case TYPE_GREATER: n1 = (i > 0); break;
case TYPE_GEQUAL: n1 = (i >= 0); break;
case TYPE_SMALLER: n1 = (i < 0); break;
case TYPE_SEQUAL: n1 = (i <= 0); break;
 
case TYPE_MATCH:
case TYPE_NOMATCH:
/* avoid 'l' flag in 'cpoptions' */
save_cpo = p_cpo;
p_cpo = (char_u *)"";
regmatch.regprog = vim_regcomp(s2,
RE_MAGIC + RE_STRING);
regmatch.rm_ic = ic;
if (regmatch.regprog != NULL)
{
n1 = vim_regexec_nl(&regmatch, s1, (colnr_T)0);
vim_free(regmatch.regprog);
if (type == TYPE_NOMATCH)
n1 = !n1;
}
p_cpo = save_cpo;
break;
 
case TYPE_UNKNOWN: break; /* avoid gcc warning */
}
}
clear_tv(rettv);
clear_tv(&var2);
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = n1;
}
}
 
return OK;
}
 
/*
* Handle fourth level expression:
* + number addition
* - number subtraction
* . string concatenation
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
*
* Return OK or FAIL.
*/
static int
eval5(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
typval_T var2;
typval_T var3;
int op;
long n1, n2;
char_u *s1, *s2;
char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
char_u *p;
 
/*
* Get the first variable.
*/
if (eval6(arg, rettv, evaluate) == FAIL)
return FAIL;
 
/*
* Repeat computing, until no '+', '-' or '.' is following.
*/
for (;;)
{
op = **arg;
if (op != '+' && op != '-' && op != '.')
break;
 
if (op != '+' || rettv->v_type != VAR_LIST)
{
/* For "list + ...", an illegal use of the first operand as
* a number cannot be determined before evaluating the 2nd
* operand: if this is also a list, all is ok.
* For "something . ...", "something - ..." or "non-list + ...",
* we know that the first operand needs to be a string or number
* without evaluating the 2nd operand. So check before to avoid
* side effects after an error. */
if (evaluate && get_tv_string_chk(rettv) == NULL)
{
clear_tv(rettv);
return FAIL;
}
}
 
/*
* Get the second variable.
*/
*arg = skipwhite(*arg + 1);
if (eval6(arg, &var2, evaluate) == FAIL)
{
clear_tv(rettv);
return FAIL;
}
 
if (evaluate)
{
/*
* Compute the result.
*/
if (op == '.')
{
s1 = get_tv_string_buf(rettv, buf1); /* already checked */
s2 = get_tv_string_buf_chk(&var2, buf2);
if (s2 == NULL) /* type error ? */
{
clear_tv(rettv);
clear_tv(&var2);
return FAIL;
}
p = concat_str(s1, s2);
clear_tv(rettv);
rettv->v_type = VAR_STRING;
rettv->vval.v_string = p;
}
else if (op == '+' && rettv->v_type == VAR_LIST
&& var2.v_type == VAR_LIST)
{
/* concatenate Lists */
if (list_concat(rettv->vval.v_list, var2.vval.v_list,
&var3) == FAIL)
{
clear_tv(rettv);
clear_tv(&var2);
return FAIL;
}
clear_tv(rettv);
*rettv = var3;
}
else
{
int error = FALSE;
 
n1 = get_tv_number_chk(rettv, &error);
if (error)
{
/* This can only happen for "list + non-list".
* For "non-list + ..." or "something - ...", we returned
* before evaluating the 2nd operand. */
clear_tv(rettv);
return FAIL;
}
n2 = get_tv_number_chk(&var2, &error);
if (error)
{
clear_tv(rettv);
clear_tv(&var2);
return FAIL;
}
clear_tv(rettv);
if (op == '+')
n1 = n1 + n2;
else
n1 = n1 - n2;
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = n1;
}
clear_tv(&var2);
}
}
return OK;
}
 
/*
* Handle fifth level expression:
* * number multiplication
* / number division
* % number modulo
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
*
* Return OK or FAIL.
*/
static int
eval6(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
typval_T var2;
int op;
long n1, n2;
int error = FALSE;
 
/*
* Get the first variable.
*/
if (eval7(arg, rettv, evaluate) == FAIL)
return FAIL;
 
/*
* Repeat computing, until no '*', '/' or '%' is following.
*/
for (;;)
{
op = **arg;
if (op != '*' && op != '/' && op != '%')
break;
 
if (evaluate)
{
n1 = get_tv_number_chk(rettv, &error);
clear_tv(rettv);
if (error)
return FAIL;
}
else
n1 = 0;
 
/*
* Get the second variable.
*/
*arg = skipwhite(*arg + 1);
if (eval7(arg, &var2, evaluate) == FAIL)
return FAIL;
 
if (evaluate)
{
n2 = get_tv_number_chk(&var2, &error);
clear_tv(&var2);
if (error)
return FAIL;
 
/*
* Compute the result.
*/
if (op == '*')
n1 = n1 * n2;
else if (op == '/')
{
if (n2 == 0) /* give an error message? */
n1 = 0x7fffffffL;
else
n1 = n1 / n2;
}
else
{
if (n2 == 0) /* give an error message? */
n1 = 0;
else
n1 = n1 % n2;
}
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = n1;
}
}
 
return OK;
}
 
/*
* Handle sixth level expression:
* number number constant
* "string" string constant
* 'string' literal string constant
* &option-name option value
* @r register contents
* identifier variable value
* function() function call
* $VAR environment variable
* (expression) nested expression
* [expr, expr] List
* {key: val, key: val} Dictionary
*
* Also handle:
* ! in front logical NOT
* - in front unary minus
* + in front unary plus (ignored)
* trailing [] subscript in String or List
* trailing .name entry in Dictionary
*
* "arg" must point to the first non-white of the expression.
* "arg" is advanced to the next non-white after the recognized expression.
*
* Return OK or FAIL.
*/
static int
eval7(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
long n;
int len;
char_u *s;
int val;
char_u *start_leader, *end_leader;
int ret = OK;
char_u *alias;
 
/*
* Initialise variable so that clear_tv() can't mistake this for a
* string and free a string that isn't there.
*/
rettv->v_type = VAR_UNKNOWN;
 
/*
* Skip '!' and '-' characters. They are handled later.
*/
start_leader = *arg;
while (**arg == '!' || **arg == '-' || **arg == '+')
*arg = skipwhite(*arg + 1);
end_leader = *arg;
 
switch (**arg)
{
/*
* Number constant.
*/
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
vim_str2nr(*arg, NULL, &len, TRUE, TRUE, &n, NULL);
*arg += len;
if (evaluate)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = n;
}
break;
 
/*
* String constant: "string".
*/
case '"': ret = get_string_tv(arg, rettv, evaluate);
break;
 
/*
* Literal string constant: 'str''ing'.
*/
case '\'': ret = get_lit_string_tv(arg, rettv, evaluate);
break;
 
/*
* List: [expr, expr]
*/
case '[': ret = get_list_tv(arg, rettv, evaluate);
break;
 
/*
* Dictionary: {key: val, key: val}
*/
case '{': ret = get_dict_tv(arg, rettv, evaluate);
break;
 
/*
* Option value: &name
*/
case '&': ret = get_option_tv(arg, rettv, evaluate);
break;
 
/*
* Environment variable: $VAR.
*/
case '$': ret = get_env_tv(arg, rettv, evaluate);
break;
 
/*
* Register contents: @r.
*/
case '@': ++*arg;
if (evaluate)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = get_reg_contents(**arg, TRUE, TRUE);
}
if (**arg != NUL)
++*arg;
break;
 
/*
* nested expression: (expression).
*/
case '(': *arg = skipwhite(*arg + 1);
ret = eval1(arg, rettv, evaluate); /* recursive! */
if (**arg == ')')
++*arg;
else if (ret == OK)
{
EMSG(_("E110: Missing ')'"));
clear_tv(rettv);
ret = FAIL;
}
break;
 
default: ret = NOTDONE;
break;
}
 
if (ret == NOTDONE)
{
/*
* Must be a variable or function name.
* Can also be a curly-braces kind of name: {expr}.
*/
s = *arg;
len = get_name_len(arg, &alias, evaluate, TRUE);
if (alias != NULL)
s = alias;
 
if (len <= 0)
ret = FAIL;
else
{
if (**arg == '(') /* recursive! */
{
/* If "s" is the name of a variable of type VAR_FUNC
* use its contents. */
s = deref_func_name(s, &len);
 
/* Invoke the function. */
ret = get_func_tv(s, len, rettv, arg,
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
&len, evaluate, NULL);
/* Stop the expression evaluation when immediately
* aborting on error, or when an interrupt occurred or
* an exception was thrown but not caught. */
if (aborting())
{
if (ret == OK)
clear_tv(rettv);
ret = FAIL;
}
}
else if (evaluate)
ret = get_var_tv(s, len, rettv, TRUE);
else
ret = OK;
}
 
if (alias != NULL)
vim_free(alias);
}
 
*arg = skipwhite(*arg);
 
/* Handle following '[', '(' and '.' for expr[expr], expr.name,
* expr(expr). */
if (ret == OK)
ret = handle_subscript(arg, rettv, evaluate, TRUE);
 
/*
* Apply logical NOT and unary '-', from right to left, ignore '+'.
*/
if (ret == OK && evaluate && end_leader > start_leader)
{
int error = FALSE;
 
val = get_tv_number_chk(rettv, &error);
if (error)
{
clear_tv(rettv);
ret = FAIL;
}
else
{
while (end_leader > start_leader)
{
--end_leader;
if (*end_leader == '!')
val = !val;
else if (*end_leader == '-')
val = -val;
}
clear_tv(rettv);
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = val;
}
}
 
return ret;
}
 
/*
* Evaluate an "[expr]" or "[expr:expr]" index. Also "dict.key".
* "*arg" points to the '[' or '.'.
* Returns FAIL or OK. "*arg" is advanced to after the ']'.
*/
static int
eval_index(arg, rettv, evaluate, verbose)
char_u **arg;
typval_T *rettv;
int evaluate;
int verbose; /* give error messages */
{
int empty1 = FALSE, empty2 = FALSE;
typval_T var1, var2;
long n1, n2 = 0;
long len = -1;
int range = FALSE;
char_u *s;
char_u *key = NULL;
 
if (rettv->v_type == VAR_FUNC)
{
if (verbose)
EMSG(_("E695: Cannot index a Funcref"));
return FAIL;
}
 
if (**arg == '.')
{
/*
* dict.name
*/
key = *arg + 1;
for (len = 0; ASCII_ISALNUM(key[len]) || key[len] == '_'; ++len)
;
if (len == 0)
return FAIL;
*arg = skipwhite(key + len);
}
else
{
/*
* something[idx]
*
* Get the (first) variable from inside the [].
*/
*arg = skipwhite(*arg + 1);
if (**arg == ':')
empty1 = TRUE;
else if (eval1(arg, &var1, evaluate) == FAIL) /* recursive! */
return FAIL;
else if (evaluate && get_tv_string_chk(&var1) == NULL)
{
/* not a number or string */
clear_tv(&var1);
return FAIL;
}
 
/*
* Get the second variable from inside the [:].
*/
if (**arg == ':')
{
range = TRUE;
*arg = skipwhite(*arg + 1);
if (**arg == ']')
empty2 = TRUE;
else if (eval1(arg, &var2, evaluate) == FAIL) /* recursive! */
{
if (!empty1)
clear_tv(&var1);
return FAIL;
}
else if (evaluate && get_tv_string_chk(&var2) == NULL)
{
/* not a number or string */
if (!empty1)
clear_tv(&var1);
clear_tv(&var2);
return FAIL;
}
}
 
/* Check for the ']'. */
if (**arg != ']')
{
if (verbose)
EMSG(_(e_missbrac));
clear_tv(&var1);
if (range)
clear_tv(&var2);
return FAIL;
}
*arg = skipwhite(*arg + 1); /* skip the ']' */
}
 
if (evaluate)
{
n1 = 0;
if (!empty1 && rettv->v_type != VAR_DICT)
{
n1 = get_tv_number(&var1);
clear_tv(&var1);
}
if (range)
{
if (empty2)
n2 = -1;
else
{
n2 = get_tv_number(&var2);
clear_tv(&var2);
}
}
 
switch (rettv->v_type)
{
case VAR_NUMBER:
case VAR_STRING:
s = get_tv_string(rettv);
len = (long)STRLEN(s);
if (range)
{
/* The resulting variable is a substring. If the indexes
* are out of range the result is empty. */
if (n1 < 0)
{
n1 = len + n1;
if (n1 < 0)
n1 = 0;
}
if (n2 < 0)
n2 = len + n2;
else if (n2 >= len)
n2 = len;
if (n1 >= len || n2 < 0 || n1 > n2)
s = NULL;
else
s = vim_strnsave(s + n1, (int)(n2 - n1 + 1));
}
else
{
/* The resulting variable is a string of a single
* character. If the index is too big or negative the
* result is empty. */
if (n1 >= len || n1 < 0)
s = NULL;
else
s = vim_strnsave(s + n1, 1);
}
clear_tv(rettv);
rettv->v_type = VAR_STRING;
rettv->vval.v_string = s;
break;
 
case VAR_LIST:
len = list_len(rettv->vval.v_list);
if (n1 < 0)
n1 = len + n1;
if (!empty1 && (n1 < 0 || n1 >= len))
{
/* For a range we allow invalid values and return an empty
* list. A list index out of range is an error. */
if (!range)
{
if (verbose)
EMSGN(_(e_listidx), n1);
return FAIL;
}
n1 = len;
}
if (range)
{
list_T *l;
listitem_T *item;
 
if (n2 < 0)
n2 = len + n2;
else if (n2 >= len)
n2 = len - 1;
if (!empty2 && (n2 < 0 || n2 + 1 < n1))
n2 = -1;
l = list_alloc();
if (l == NULL)
return FAIL;
for (item = list_find(rettv->vval.v_list, n1);
n1 <= n2; ++n1)
{
if (list_append_tv(l, &item->li_tv) == FAIL)
{
list_free(l, TRUE);
return FAIL;
}
item = item->li_next;
}
clear_tv(rettv);
rettv->v_type = VAR_LIST;
rettv->vval.v_list = l;
++l->lv_refcount;
}
else
{
copy_tv(&list_find(rettv->vval.v_list, n1)->li_tv, &var1);
clear_tv(rettv);
*rettv = var1;
}
break;
 
case VAR_DICT:
if (range)
{
if (verbose)
EMSG(_(e_dictrange));
if (len == -1)
clear_tv(&var1);
return FAIL;
}
{
dictitem_T *item;
 
if (len == -1)
{
key = get_tv_string(&var1);
if (*key == NUL)
{
if (verbose)
EMSG(_(e_emptykey));
clear_tv(&var1);
return FAIL;
}
}
 
item = dict_find(rettv->vval.v_dict, key, (int)len);
 
if (item == NULL && verbose)
EMSG2(_(e_dictkey), key);
if (len == -1)
clear_tv(&var1);
if (item == NULL)
return FAIL;
 
copy_tv(&item->di_tv, &var1);
clear_tv(rettv);
*rettv = var1;
}
break;
}
}
 
return OK;
}
 
/*
* Get an option value.
* "arg" points to the '&' or '+' before the option name.
* "arg" is advanced to character after the option name.
* Return OK or FAIL.
*/
static int
get_option_tv(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv; /* when NULL, only check if option exists */
int evaluate;
{
char_u *option_end;
long numval;
char_u *stringval;
int opt_type;
int c;
int working = (**arg == '+'); /* has("+option") */
int ret = OK;
int opt_flags;
 
/*
* Isolate the option name and find its value.
*/
option_end = find_option_end(arg, &opt_flags);
if (option_end == NULL)
{
if (rettv != NULL)
EMSG2(_("E112: Option name missing: %s"), *arg);
return FAIL;
}
 
if (!evaluate)
{
*arg = option_end;
return OK;
}
 
c = *option_end;
*option_end = NUL;
opt_type = get_option_value(*arg, &numval,
rettv == NULL ? NULL : &stringval, opt_flags);
 
if (opt_type == -3) /* invalid name */
{
if (rettv != NULL)
EMSG2(_("E113: Unknown option: %s"), *arg);
ret = FAIL;
}
else if (rettv != NULL)
{
if (opt_type == -2) /* hidden string option */
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
}
else if (opt_type == -1) /* hidden number option */
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
}
else if (opt_type == 1) /* number option */
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = numval;
}
else /* string option */
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = stringval;
}
}
else if (working && (opt_type == -2 || opt_type == -1))
ret = FAIL;
 
*option_end = c; /* put back for error messages */
*arg = option_end;
 
return ret;
}
 
/*
* Allocate a variable for a string constant.
* Return OK or FAIL.
*/
static int
get_string_tv(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
char_u *p;
char_u *name;
int extra = 0;
 
/*
* Find the end of the string, skipping backslashed characters.
*/
for (p = *arg + 1; *p != NUL && *p != '"'; mb_ptr_adv(p))
{
if (*p == '\\' && p[1] != NUL)
{
++p;
/* A "\<x>" form occupies at least 4 characters, and produces up
* to 6 characters: reserve space for 2 extra */
if (*p == '<')
extra += 2;
}
}
 
if (*p != '"')
{
EMSG2(_("E114: Missing quote: %s"), *arg);
return FAIL;
}
 
/* If only parsing, set *arg and return here */
if (!evaluate)
{
*arg = p + 1;
return OK;
}
 
/*
* Copy the string into allocated memory, handling backslashed
* characters.
*/
name = alloc((unsigned)(p - *arg + extra));
if (name == NULL)
return FAIL;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = name;
 
for (p = *arg + 1; *p != NUL && *p != '"'; )
{
if (*p == '\\')
{
switch (*++p)
{
case 'b': *name++ = BS; ++p; break;
case 'e': *name++ = ESC; ++p; break;
case 'f': *name++ = FF; ++p; break;
case 'n': *name++ = NL; ++p; break;
case 'r': *name++ = CAR; ++p; break;
case 't': *name++ = TAB; ++p; break;
 
case 'X': /* hex: "\x1", "\x12" */
case 'x':
case 'u': /* Unicode: "\u0023" */
case 'U':
if (vim_isxdigit(p[1]))
{
int n, nr;
int c = toupper(*p);
 
if (c == 'X')
n = 2;
else
n = 4;
nr = 0;
while (--n >= 0 && vim_isxdigit(p[1]))
{
++p;
nr = (nr << 4) + hex2nr(*p);
}
++p;
#ifdef FEAT_MBYTE
/* For "\u" store the number according to
* 'encoding'. */
if (c != 'X')
name += (*mb_char2bytes)(nr, name);
else
#endif
*name++ = nr;
}
break;
 
/* octal: "\1", "\12", "\123" */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7': *name = *p++ - '0';
if (*p >= '0' && *p <= '7')
{
*name = (*name << 3) + *p++ - '0';
if (*p >= '0' && *p <= '7')
*name = (*name << 3) + *p++ - '0';
}
++name;
break;
 
/* Special key, e.g.: "\<C-W>" */
case '<': extra = trans_special(&p, name, TRUE);
if (extra != 0)
{
name += extra;
break;
}
/* FALLTHROUGH */
 
default: MB_COPY_CHAR(p, name);
break;
}
}
else
MB_COPY_CHAR(p, name);
 
}
*name = NUL;
*arg = p + 1;
 
return OK;
}
 
/*
* Allocate a variable for a 'str''ing' constant.
* Return OK or FAIL.
*/
static int
get_lit_string_tv(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
char_u *p;
char_u *str;
int reduce = 0;
 
/*
* Find the end of the string, skipping ''.
*/
for (p = *arg + 1; *p != NUL; mb_ptr_adv(p))
{
if (*p == '\'')
{
if (p[1] != '\'')
break;
++reduce;
++p;
}
}
 
if (*p != '\'')
{
EMSG2(_("E115: Missing quote: %s"), *arg);
return FAIL;
}
 
/* If only parsing return after setting "*arg" */
if (!evaluate)
{
*arg = p + 1;
return OK;
}
 
/*
* Copy the string into allocated memory, handling '' to ' reduction.
*/
str = alloc((unsigned)((p - *arg) - reduce));
if (str == NULL)
return FAIL;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = str;
 
for (p = *arg + 1; *p != NUL; )
{
if (*p == '\'')
{
if (p[1] != '\'')
break;
++p;
}
MB_COPY_CHAR(p, str);
}
*str = NUL;
*arg = p + 1;
 
return OK;
}
 
/*
* Allocate a variable for a List and fill it from "*arg".
* Return OK or FAIL.
*/
static int
get_list_tv(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
list_T *l = NULL;
typval_T tv;
listitem_T *item;
 
if (evaluate)
{
l = list_alloc();
if (l == NULL)
return FAIL;
}
 
*arg = skipwhite(*arg + 1);
while (**arg != ']' && **arg != NUL)
{
if (eval1(arg, &tv, evaluate) == FAIL) /* recursive! */
goto failret;
if (evaluate)
{
item = listitem_alloc();
if (item != NULL)
{
item->li_tv = tv;
item->li_tv.v_lock = 0;
list_append(l, item);
}
else
clear_tv(&tv);
}
 
if (**arg == ']')
break;
if (**arg != ',')
{
EMSG2(_("E696: Missing comma in List: %s"), *arg);
goto failret;
}
*arg = skipwhite(*arg + 1);
}
 
if (**arg != ']')
{
EMSG2(_("E697: Missing end of List ']': %s"), *arg);
failret:
if (evaluate)
list_free(l, TRUE);
return FAIL;
}
 
*arg = skipwhite(*arg + 1);
if (evaluate)
{
rettv->v_type = VAR_LIST;
rettv->vval.v_list = l;
++l->lv_refcount;
}
 
return OK;
}
 
/*
* Allocate an empty header for a list.
* Caller should take care of the reference count.
*/
list_T *
list_alloc()
{
list_T *l;
 
l = (list_T *)alloc_clear(sizeof(list_T));
if (l != NULL)
{
/* Prepend the list to the list of lists for garbage collection. */
if (first_list != NULL)
first_list->lv_used_prev = l;
l->lv_used_prev = NULL;
l->lv_used_next = first_list;
first_list = l;
}
return l;
}
 
/*
* Allocate an empty list for a return value.
* Returns OK or FAIL.
*/
static int
rettv_list_alloc(rettv)
typval_T *rettv;
{
list_T *l = list_alloc();
 
if (l == NULL)
return FAIL;
 
rettv->vval.v_list = l;
rettv->v_type = VAR_LIST;
++l->lv_refcount;
return OK;
}
 
/*
* Unreference a list: decrement the reference count and free it when it
* becomes zero.
*/
void
list_unref(l)
list_T *l;
{
if (l != NULL && --l->lv_refcount <= 0)
list_free(l, TRUE);
}
 
/*
* Free a list, including all items it points to.
* Ignores the reference count.
*/
void
list_free(l, recurse)
list_T *l;
int recurse; /* Free Lists and Dictionaries recursively. */
{
listitem_T *item;
 
/* Remove the list from the list of lists for garbage collection. */
if (l->lv_used_prev == NULL)
first_list = l->lv_used_next;
else
l->lv_used_prev->lv_used_next = l->lv_used_next;
if (l->lv_used_next != NULL)
l->lv_used_next->lv_used_prev = l->lv_used_prev;
 
for (item = l->lv_first; item != NULL; item = l->lv_first)
{
/* Remove the item before deleting it. */
l->lv_first = item->li_next;
if (recurse || (item->li_tv.v_type != VAR_LIST
&& item->li_tv.v_type != VAR_DICT))
clear_tv(&item->li_tv);
vim_free(item);
}
vim_free(l);
}
 
/*
* Allocate a list item.
*/
static listitem_T *
listitem_alloc()
{
return (listitem_T *)alloc(sizeof(listitem_T));
}
 
/*
* Free a list item. Also clears the value. Does not notify watchers.
*/
static void
listitem_free(item)
listitem_T *item;
{
clear_tv(&item->li_tv);
vim_free(item);
}
 
/*
* Remove a list item from a List and free it. Also clears the value.
*/
static void
listitem_remove(l, item)
list_T *l;
listitem_T *item;
{
list_remove(l, item, item);
listitem_free(item);
}
 
/*
* Get the number of items in a list.
*/
static long
list_len(l)
list_T *l;
{
if (l == NULL)
return 0L;
return l->lv_len;
}
 
/*
* Return TRUE when two lists have exactly the same values.
*/
static int
list_equal(l1, l2, ic)
list_T *l1;
list_T *l2;
int ic; /* ignore case for strings */
{
listitem_T *item1, *item2;
 
if (l1 == l2)
return TRUE;
if (list_len(l1) != list_len(l2))
return FALSE;
 
for (item1 = l1->lv_first, item2 = l2->lv_first;
item1 != NULL && item2 != NULL;
item1 = item1->li_next, item2 = item2->li_next)
if (!tv_equal(&item1->li_tv, &item2->li_tv, ic))
return FALSE;
return item1 == NULL && item2 == NULL;
}
 
#if defined(FEAT_PYTHON) || defined(PROTO)
/*
* Return the dictitem that an entry in a hashtable points to.
*/
dictitem_T *
dict_lookup(hi)
hashitem_T *hi;
{
return HI2DI(hi);
}
#endif
 
/*
* Return TRUE when two dictionaries have exactly the same key/values.
*/
static int
dict_equal(d1, d2, ic)
dict_T *d1;
dict_T *d2;
int ic; /* ignore case for strings */
{
hashitem_T *hi;
dictitem_T *item2;
int todo;
 
if (d1 == d2)
return TRUE;
if (dict_len(d1) != dict_len(d2))
return FALSE;
 
todo = (int)d1->dv_hashtab.ht_used;
for (hi = d1->dv_hashtab.ht_array; todo > 0; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
item2 = dict_find(d2, hi->hi_key, -1);
if (item2 == NULL)
return FALSE;
if (!tv_equal(&HI2DI(hi)->di_tv, &item2->di_tv, ic))
return FALSE;
--todo;
}
}
return TRUE;
}
 
/*
* Return TRUE if "tv1" and "tv2" have the same value.
* Compares the items just like "==" would compare them, but strings and
* numbers are different.
*/
static int
tv_equal(tv1, tv2, ic)
typval_T *tv1;
typval_T *tv2;
int ic; /* ignore case */
{
char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN];
char_u *s1, *s2;
static int recursive = 0; /* cach recursive loops */
int r;
 
if (tv1->v_type != tv2->v_type)
return FALSE;
/* Catch lists and dicts that have an endless loop by limiting
* recursiveness to 1000. We guess they are equal then. */
if (recursive >= 1000)
return TRUE;
 
switch (tv1->v_type)
{
case VAR_LIST:
++recursive;
r = list_equal(tv1->vval.v_list, tv2->vval.v_list, ic);
--recursive;
return r;
 
case VAR_DICT:
++recursive;
r = dict_equal(tv1->vval.v_dict, tv2->vval.v_dict, ic);
--recursive;
return r;
 
case VAR_FUNC:
return (tv1->vval.v_string != NULL
&& tv2->vval.v_string != NULL
&& STRCMP(tv1->vval.v_string, tv2->vval.v_string) == 0);
 
case VAR_NUMBER:
return tv1->vval.v_number == tv2->vval.v_number;
 
case VAR_STRING:
s1 = get_tv_string_buf(tv1, buf1);
s2 = get_tv_string_buf(tv2, buf2);
return ((ic ? MB_STRICMP(s1, s2) : STRCMP(s1, s2)) == 0);
}
 
EMSG2(_(e_intern2), "tv_equal()");
return TRUE;
}
 
/*
* Locate item with index "n" in list "l" and return it.
* A negative index is counted from the end; -1 is the last item.
* Returns NULL when "n" is out of range.
*/
static listitem_T *
list_find(l, n)
list_T *l;
long n;
{
listitem_T *item;
long idx;
 
if (l == NULL)
return NULL;
 
/* Negative index is relative to the end. */
if (n < 0)
n = l->lv_len + n;
 
/* Check for index out of range. */
if (n < 0 || n >= l->lv_len)
return NULL;
 
/* When there is a cached index may start search from there. */
if (l->lv_idx_item != NULL)
{
if (n < l->lv_idx / 2)
{
/* closest to the start of the list */
item = l->lv_first;
idx = 0;
}
else if (n > (l->lv_idx + l->lv_len) / 2)
{
/* closest to the end of the list */
item = l->lv_last;
idx = l->lv_len - 1;
}
else
{
/* closest to the cached index */
item = l->lv_idx_item;
idx = l->lv_idx;
}
}
else
{
if (n < l->lv_len / 2)
{
/* closest to the start of the list */
item = l->lv_first;
idx = 0;
}
else
{
/* closest to the end of the list */
item = l->lv_last;
idx = l->lv_len - 1;
}
}
 
while (n > idx)
{
/* search forward */
item = item->li_next;
++idx;
}
while (n < idx)
{
/* search backward */
item = item->li_prev;
--idx;
}
 
/* cache the used index */
l->lv_idx = idx;
l->lv_idx_item = item;
 
return item;
}
 
/*
* Get list item "l[idx]" as a number.
*/
static long
list_find_nr(l, idx, errorp)
list_T *l;
long idx;
int *errorp; /* set to TRUE when something wrong */
{
listitem_T *li;
 
li = list_find(l, idx);
if (li == NULL)
{
if (errorp != NULL)
*errorp = TRUE;
return -1L;
}
return get_tv_number_chk(&li->li_tv, errorp);
}
 
/*
* Locate "item" list "l" and return its index.
* Returns -1 when "item" is not in the list.
*/
static long
list_idx_of_item(l, item)
list_T *l;
listitem_T *item;
{
long idx = 0;
listitem_T *li;
 
if (l == NULL)
return -1;
idx = 0;
for (li = l->lv_first; li != NULL && li != item; li = li->li_next)
++idx;
if (li == NULL)
return -1;
return idx;
}
 
/*
* Append item "item" to the end of list "l".
*/
static void
list_append(l, item)
list_T *l;
listitem_T *item;
{
if (l->lv_last == NULL)
{
/* empty list */
l->lv_first = item;
l->lv_last = item;
item->li_prev = NULL;
}
else
{
l->lv_last->li_next = item;
item->li_prev = l->lv_last;
l->lv_last = item;
}
++l->lv_len;
item->li_next = NULL;
}
 
/*
* Append typval_T "tv" to the end of list "l".
* Return FAIL when out of memory.
*/
static int
list_append_tv(l, tv)
list_T *l;
typval_T *tv;
{
listitem_T *li = listitem_alloc();
 
if (li == NULL)
return FAIL;
copy_tv(tv, &li->li_tv);
list_append(l, li);
return OK;
}
 
/*
* Add a dictionary to a list. Used by getqflist().
* Return FAIL when out of memory.
*/
int
list_append_dict(list, dict)
list_T *list;
dict_T *dict;
{
listitem_T *li = listitem_alloc();
 
if (li == NULL)
return FAIL;
li->li_tv.v_type = VAR_DICT;
li->li_tv.v_lock = 0;
li->li_tv.vval.v_dict = dict;
list_append(list, li);
++dict->dv_refcount;
return OK;
}
 
/*
* Make a copy of "str" and append it as an item to list "l".
* When "len" >= 0 use "str[len]".
* Returns FAIL when out of memory.
*/
static int
list_append_string(l, str, len)
list_T *l;
char_u *str;
int len;
{
listitem_T *li = listitem_alloc();
 
if (li == NULL)
return FAIL;
list_append(l, li);
li->li_tv.v_type = VAR_STRING;
li->li_tv.v_lock = 0;
if (str == NULL)
li->li_tv.vval.v_string = NULL;
else if ((li->li_tv.vval.v_string = (len >= 0 ? vim_strnsave(str, len)
: vim_strsave(str))) == NULL)
return FAIL;
return OK;
}
 
/*
* Append "n" to list "l".
* Returns FAIL when out of memory.
*/
static int
list_append_number(l, n)
list_T *l;
varnumber_T n;
{
listitem_T *li;
 
li = listitem_alloc();
if (li == NULL)
return FAIL;
li->li_tv.v_type = VAR_NUMBER;
li->li_tv.v_lock = 0;
li->li_tv.vval.v_number = n;
list_append(l, li);
return OK;
}
 
/*
* Insert typval_T "tv" in list "l" before "item".
* If "item" is NULL append at the end.
* Return FAIL when out of memory.
*/
static int
list_insert_tv(l, tv, item)
list_T *l;
typval_T *tv;
listitem_T *item;
{
listitem_T *ni = listitem_alloc();
 
if (ni == NULL)
return FAIL;
copy_tv(tv, &ni->li_tv);
if (item == NULL)
/* Append new item at end of list. */
list_append(l, ni);
else
{
/* Insert new item before existing item. */
ni->li_prev = item->li_prev;
ni->li_next = item;
if (item->li_prev == NULL)
{
l->lv_first = ni;
++l->lv_idx;
}
else
{
item->li_prev->li_next = ni;
l->lv_idx_item = NULL;
}
item->li_prev = ni;
++l->lv_len;
}
return OK;
}
 
/*
* Extend "l1" with "l2".
* If "bef" is NULL append at the end, otherwise insert before this item.
* Returns FAIL when out of memory.
*/
static int
list_extend(l1, l2, bef)
list_T *l1;
list_T *l2;
listitem_T *bef;
{
listitem_T *item;
 
for (item = l2->lv_first; item != NULL; item = item->li_next)
if (list_insert_tv(l1, &item->li_tv, bef) == FAIL)
return FAIL;
return OK;
}
 
/*
* Concatenate lists "l1" and "l2" into a new list, stored in "tv".
* Return FAIL when out of memory.
*/
static int
list_concat(l1, l2, tv)
list_T *l1;
list_T *l2;
typval_T *tv;
{
list_T *l;
 
/* make a copy of the first list. */
l = list_copy(l1, FALSE, 0);
if (l == NULL)
return FAIL;
tv->v_type = VAR_LIST;
tv->vval.v_list = l;
 
/* append all items from the second list */
return list_extend(l, l2, NULL);
}
 
/*
* Make a copy of list "orig". Shallow if "deep" is FALSE.
* The refcount of the new list is set to 1.
* See item_copy() for "copyID".
* Returns NULL when out of memory.
*/
static list_T *
list_copy(orig, deep, copyID)
list_T *orig;
int deep;
int copyID;
{
list_T *copy;
listitem_T *item;
listitem_T *ni;
 
if (orig == NULL)
return NULL;
 
copy = list_alloc();
if (copy != NULL)
{
if (copyID != 0)
{
/* Do this before adding the items, because one of the items may
* refer back to this list. */
orig->lv_copyID = copyID;
orig->lv_copylist = copy;
}
for (item = orig->lv_first; item != NULL && !got_int;
item = item->li_next)
{
ni = listitem_alloc();
if (ni == NULL)
break;
if (deep)
{
if (item_copy(&item->li_tv, &ni->li_tv, deep, copyID) == FAIL)
{
vim_free(ni);
break;
}
}
else
copy_tv(&item->li_tv, &ni->li_tv);
list_append(copy, ni);
}
++copy->lv_refcount;
if (item != NULL)
{
list_unref(copy);
copy = NULL;
}
}
 
return copy;
}
 
/*
* Remove items "item" to "item2" from list "l".
* Does not free the listitem or the value!
*/
static void
list_remove(l, item, item2)
list_T *l;
listitem_T *item;
listitem_T *item2;
{
listitem_T *ip;
 
/* notify watchers */
for (ip = item; ip != NULL; ip = ip->li_next)
{
--l->lv_len;
list_fix_watch(l, ip);
if (ip == item2)
break;
}
 
if (item2->li_next == NULL)
l->lv_last = item->li_prev;
else
item2->li_next->li_prev = item->li_prev;
if (item->li_prev == NULL)
l->lv_first = item2->li_next;
else
item->li_prev->li_next = item2->li_next;
l->lv_idx_item = NULL;
}
 
/*
* Return an allocated string with the string representation of a list.
* May return NULL.
*/
static char_u *
list2string(tv, copyID)
typval_T *tv;
int copyID;
{
garray_T ga;
 
if (tv->vval.v_list == NULL)
return NULL;
ga_init2(&ga, (int)sizeof(char), 80);
ga_append(&ga, '[');
if (list_join(&ga, tv->vval.v_list, (char_u *)", ", FALSE, copyID) == FAIL)
{
vim_free(ga.ga_data);
return NULL;
}
ga_append(&ga, ']');
ga_append(&ga, NUL);
return (char_u *)ga.ga_data;
}
 
/*
* Join list "l" into a string in "*gap", using separator "sep".
* When "echo" is TRUE use String as echoed, otherwise as inside a List.
* Return FAIL or OK.
*/
static int
list_join(gap, l, sep, echo, copyID)
garray_T *gap;
list_T *l;
char_u *sep;
int echo;
int copyID;
{
int first = TRUE;
char_u *tofree;
char_u numbuf[NUMBUFLEN];
listitem_T *item;
char_u *s;
 
for (item = l->lv_first; item != NULL && !got_int; item = item->li_next)
{
if (first)
first = FALSE;
else
ga_concat(gap, sep);
 
if (echo)
s = echo_string(&item->li_tv, &tofree, numbuf, copyID);
else
s = tv2string(&item->li_tv, &tofree, numbuf, copyID);
if (s != NULL)
ga_concat(gap, s);
vim_free(tofree);
if (s == NULL)
return FAIL;
}
return OK;
}
 
/*
* Garbage collection for lists and dictionaries.
*
* We use reference counts to be able to free most items right away when they
* are no longer used. But for composite items it's possible that it becomes
* unused while the reference count is > 0: When there is a recursive
* reference. Example:
* :let l = [1, 2, 3]
* :let d = {9: l}
* :let l[1] = d
*
* Since this is quite unusual we handle this with garbage collection: every
* once in a while find out which lists and dicts are not referenced from any
* variable.
*
* Here is a good reference text about garbage collection (refers to Python
* but it applies to all reference-counting mechanisms):
* http://python.ca/nas/python/gc/
*/
 
/*
* Do garbage collection for lists and dicts.
* Return TRUE if some memory was freed.
*/
int
garbage_collect()
{
dict_T *dd;
list_T *ll;
int copyID = ++current_copyID;
buf_T *buf;
win_T *wp;
int i;
funccall_T *fc;
int did_free = FALSE;
#ifdef FEAT_WINDOWS
tabpage_T *tp;
#endif
 
/* Only do this once. */
want_garbage_collect = FALSE;
may_garbage_collect = FALSE;
 
/*
* 1. Go through all accessible variables and mark all lists and dicts
* with copyID.
*/
/* script-local variables */
for (i = 1; i <= ga_scripts.ga_len; ++i)
set_ref_in_ht(&SCRIPT_VARS(i), copyID);
 
/* buffer-local variables */
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
set_ref_in_ht(&buf->b_vars.dv_hashtab, copyID);
 
/* window-local variables */
FOR_ALL_TAB_WINDOWS(tp, wp)
set_ref_in_ht(&wp->w_vars.dv_hashtab, copyID);
 
#ifdef FEAT_WINDOWS
/* tabpage-local variables */
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
set_ref_in_ht(&tp->tp_vars.dv_hashtab, copyID);
#endif
 
/* global variables */
set_ref_in_ht(&globvarht, copyID);
 
/* function-local variables */
for (fc = current_funccal; fc != NULL; fc = fc->caller)
{
set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID);
set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID);
}
 
/*
* 2. Go through the list of dicts and free items without the copyID.
*/
for (dd = first_dict; dd != NULL; )
if (dd->dv_copyID != copyID)
{
/* Free the Dictionary and ordinary items it contains, but don't
* recurse into Lists and Dictionaries, they will be in the list
* of dicts or list of lists. */
dict_free(dd, FALSE);
did_free = TRUE;
 
/* restart, next dict may also have been freed */
dd = first_dict;
}
else
dd = dd->dv_used_next;
 
/*
* 3. Go through the list of lists and free items without the copyID.
* But don't free a list that has a watcher (used in a for loop), these
* are not referenced anywhere.
*/
for (ll = first_list; ll != NULL; )
if (ll->lv_copyID != copyID && ll->lv_watch == NULL)
{
/* Free the List and ordinary items it contains, but don't recurse
* into Lists and Dictionaries, they will be in the list of dicts
* or list of lists. */
list_free(ll, FALSE);
did_free = TRUE;
 
/* restart, next list may also have been freed */
ll = first_list;
}
else
ll = ll->lv_used_next;
 
return did_free;
}
 
/*
* Mark all lists and dicts referenced through hashtab "ht" with "copyID".
*/
static void
set_ref_in_ht(ht, copyID)
hashtab_T *ht;
int copyID;
{
int todo;
hashitem_T *hi;
 
todo = (int)ht->ht_used;
for (hi = ht->ht_array; todo > 0; ++hi)
if (!HASHITEM_EMPTY(hi))
{
--todo;
set_ref_in_item(&HI2DI(hi)->di_tv, copyID);
}
}
 
/*
* Mark all lists and dicts referenced through list "l" with "copyID".
*/
static void
set_ref_in_list(l, copyID)
list_T *l;
int copyID;
{
listitem_T *li;
 
for (li = l->lv_first; li != NULL; li = li->li_next)
set_ref_in_item(&li->li_tv, copyID);
}
 
/*
* Mark all lists and dicts referenced through typval "tv" with "copyID".
*/
static void
set_ref_in_item(tv, copyID)
typval_T *tv;
int copyID;
{
dict_T *dd;
list_T *ll;
 
switch (tv->v_type)
{
case VAR_DICT:
dd = tv->vval.v_dict;
if (dd->dv_copyID != copyID)
{
/* Didn't see this dict yet. */
dd->dv_copyID = copyID;
set_ref_in_ht(&dd->dv_hashtab, copyID);
}
break;
 
case VAR_LIST:
ll = tv->vval.v_list;
if (ll->lv_copyID != copyID)
{
/* Didn't see this list yet. */
ll->lv_copyID = copyID;
set_ref_in_list(ll, copyID);
}
break;
}
return;
}
 
/*
* Allocate an empty header for a dictionary.
*/
dict_T *
dict_alloc()
{
dict_T *d;
 
d = (dict_T *)alloc(sizeof(dict_T));
if (d != NULL)
{
/* Add the list to the list of dicts for garbage collection. */
if (first_dict != NULL)
first_dict->dv_used_prev = d;
d->dv_used_next = first_dict;
d->dv_used_prev = NULL;
first_dict = d;
 
hash_init(&d->dv_hashtab);
d->dv_lock = 0;
d->dv_refcount = 0;
d->dv_copyID = 0;
}
return d;
}
 
/*
* Unreference a Dictionary: decrement the reference count and free it when it
* becomes zero.
*/
static void
dict_unref(d)
dict_T *d;
{
if (d != NULL && --d->dv_refcount <= 0)
dict_free(d, TRUE);
}
 
/*
* Free a Dictionary, including all items it contains.
* Ignores the reference count.
*/
static void
dict_free(d, recurse)
dict_T *d;
int recurse; /* Free Lists and Dictionaries recursively. */
{
int todo;
hashitem_T *hi;
dictitem_T *di;
 
/* Remove the dict from the list of dicts for garbage collection. */
if (d->dv_used_prev == NULL)
first_dict = d->dv_used_next;
else
d->dv_used_prev->dv_used_next = d->dv_used_next;
if (d->dv_used_next != NULL)
d->dv_used_next->dv_used_prev = d->dv_used_prev;
 
/* Lock the hashtab, we don't want it to resize while freeing items. */
hash_lock(&d->dv_hashtab);
todo = (int)d->dv_hashtab.ht_used;
for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
/* Remove the item before deleting it, just in case there is
* something recursive causing trouble. */
di = HI2DI(hi);
hash_remove(&d->dv_hashtab, hi);
if (recurse || (di->di_tv.v_type != VAR_LIST
&& di->di_tv.v_type != VAR_DICT))
clear_tv(&di->di_tv);
vim_free(di);
--todo;
}
}
hash_clear(&d->dv_hashtab);
vim_free(d);
}
 
/*
* Allocate a Dictionary item.
* The "key" is copied to the new item.
* Note that the value of the item "di_tv" still needs to be initialized!
* Returns NULL when out of memory.
*/
static dictitem_T *
dictitem_alloc(key)
char_u *key;
{
dictitem_T *di;
 
di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) + STRLEN(key)));
if (di != NULL)
{
STRCPY(di->di_key, key);
di->di_flags = 0;
}
return di;
}
 
/*
* Make a copy of a Dictionary item.
*/
static dictitem_T *
dictitem_copy(org)
dictitem_T *org;
{
dictitem_T *di;
 
di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
+ STRLEN(org->di_key)));
if (di != NULL)
{
STRCPY(di->di_key, org->di_key);
di->di_flags = 0;
copy_tv(&org->di_tv, &di->di_tv);
}
return di;
}
 
/*
* Remove item "item" from Dictionary "dict" and free it.
*/
static void
dictitem_remove(dict, item)
dict_T *dict;
dictitem_T *item;
{
hashitem_T *hi;
 
hi = hash_find(&dict->dv_hashtab, item->di_key);
if (HASHITEM_EMPTY(hi))
EMSG2(_(e_intern2), "dictitem_remove()");
else
hash_remove(&dict->dv_hashtab, hi);
dictitem_free(item);
}
 
/*
* Free a dict item. Also clears the value.
*/
static void
dictitem_free(item)
dictitem_T *item;
{
clear_tv(&item->di_tv);
vim_free(item);
}
 
/*
* Make a copy of dict "d". Shallow if "deep" is FALSE.
* The refcount of the new dict is set to 1.
* See item_copy() for "copyID".
* Returns NULL when out of memory.
*/
static dict_T *
dict_copy(orig, deep, copyID)
dict_T *orig;
int deep;
int copyID;
{
dict_T *copy;
dictitem_T *di;
int todo;
hashitem_T *hi;
 
if (orig == NULL)
return NULL;
 
copy = dict_alloc();
if (copy != NULL)
{
if (copyID != 0)
{
orig->dv_copyID = copyID;
orig->dv_copydict = copy;
}
todo = (int)orig->dv_hashtab.ht_used;
for (hi = orig->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
 
di = dictitem_alloc(hi->hi_key);
if (di == NULL)
break;
if (deep)
{
if (item_copy(&HI2DI(hi)->di_tv, &di->di_tv, deep,
copyID) == FAIL)
{
vim_free(di);
break;
}
}
else
copy_tv(&HI2DI(hi)->di_tv, &di->di_tv);
if (dict_add(copy, di) == FAIL)
{
dictitem_free(di);
break;
}
}
}
 
++copy->dv_refcount;
if (todo > 0)
{
dict_unref(copy);
copy = NULL;
}
}
 
return copy;
}
 
/*
* Add item "item" to Dictionary "d".
* Returns FAIL when out of memory and when key already existed.
*/
static int
dict_add(d, item)
dict_T *d;
dictitem_T *item;
{
return hash_add(&d->dv_hashtab, item->di_key);
}
 
/*
* Add a number or string entry to dictionary "d".
* When "str" is NULL use number "nr", otherwise use "str".
* Returns FAIL when out of memory and when key already exists.
*/
int
dict_add_nr_str(d, key, nr, str)
dict_T *d;
char *key;
long nr;
char_u *str;
{
dictitem_T *item;
 
item = dictitem_alloc((char_u *)key);
if (item == NULL)
return FAIL;
item->di_tv.v_lock = 0;
if (str == NULL)
{
item->di_tv.v_type = VAR_NUMBER;
item->di_tv.vval.v_number = nr;
}
else
{
item->di_tv.v_type = VAR_STRING;
item->di_tv.vval.v_string = vim_strsave(str);
}
if (dict_add(d, item) == FAIL)
{
dictitem_free(item);
return FAIL;
}
return OK;
}
 
/*
* Get the number of items in a Dictionary.
*/
static long
dict_len(d)
dict_T *d;
{
if (d == NULL)
return 0L;
return (long)d->dv_hashtab.ht_used;
}
 
/*
* Find item "key[len]" in Dictionary "d".
* If "len" is negative use strlen(key).
* Returns NULL when not found.
*/
static dictitem_T *
dict_find(d, key, len)
dict_T *d;
char_u *key;
int len;
{
#define AKEYLEN 200
char_u buf[AKEYLEN];
char_u *akey;
char_u *tofree = NULL;
hashitem_T *hi;
 
if (len < 0)
akey = key;
else if (len >= AKEYLEN)
{
tofree = akey = vim_strnsave(key, len);
if (akey == NULL)
return NULL;
}
else
{
/* Avoid a malloc/free by using buf[]. */
vim_strncpy(buf, key, len);
akey = buf;
}
 
hi = hash_find(&d->dv_hashtab, akey);
vim_free(tofree);
if (HASHITEM_EMPTY(hi))
return NULL;
return HI2DI(hi);
}
 
/*
* Get a string item from a dictionary.
* When "save" is TRUE allocate memory for it.
* Returns NULL if the entry doesn't exist or out of memory.
*/
char_u *
get_dict_string(d, key, save)
dict_T *d;
char_u *key;
int save;
{
dictitem_T *di;
char_u *s;
 
di = dict_find(d, key, -1);
if (di == NULL)
return NULL;
s = get_tv_string(&di->di_tv);
if (save && s != NULL)
s = vim_strsave(s);
return s;
}
 
/*
* Get a number item from a dictionary.
* Returns 0 if the entry doesn't exist or out of memory.
*/
long
get_dict_number(d, key)
dict_T *d;
char_u *key;
{
dictitem_T *di;
 
di = dict_find(d, key, -1);
if (di == NULL)
return 0;
return get_tv_number(&di->di_tv);
}
 
/*
* Return an allocated string with the string representation of a Dictionary.
* May return NULL.
*/
static char_u *
dict2string(tv, copyID)
typval_T *tv;
int copyID;
{
garray_T ga;
int first = TRUE;
char_u *tofree;
char_u numbuf[NUMBUFLEN];
hashitem_T *hi;
char_u *s;
dict_T *d;
int todo;
 
if ((d = tv->vval.v_dict) == NULL)
return NULL;
ga_init2(&ga, (int)sizeof(char), 80);
ga_append(&ga, '{');
 
todo = (int)d->dv_hashtab.ht_used;
for (hi = d->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
 
if (first)
first = FALSE;
else
ga_concat(&ga, (char_u *)", ");
 
tofree = string_quote(hi->hi_key, FALSE);
if (tofree != NULL)
{
ga_concat(&ga, tofree);
vim_free(tofree);
}
ga_concat(&ga, (char_u *)": ");
s = tv2string(&HI2DI(hi)->di_tv, &tofree, numbuf, copyID);
if (s != NULL)
ga_concat(&ga, s);
vim_free(tofree);
if (s == NULL)
break;
}
}
if (todo > 0)
{
vim_free(ga.ga_data);
return NULL;
}
 
ga_append(&ga, '}');
ga_append(&ga, NUL);
return (char_u *)ga.ga_data;
}
 
/*
* Allocate a variable for a Dictionary and fill it from "*arg".
* Return OK or FAIL. Returns NOTDONE for {expr}.
*/
static int
get_dict_tv(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
dict_T *d = NULL;
typval_T tvkey;
typval_T tv;
char_u *key;
dictitem_T *item;
char_u *start = skipwhite(*arg + 1);
char_u buf[NUMBUFLEN];
 
/*
* First check if it's not a curly-braces thing: {expr}.
* Must do this without evaluating, otherwise a function may be called
* twice. Unfortunately this means we need to call eval1() twice for the
* first item.
* But {} is an empty Dictionary.
*/
if (*start != '}')
{
if (eval1(&start, &tv, FALSE) == FAIL) /* recursive! */
return FAIL;
if (*start == '}')
return NOTDONE;
}
 
if (evaluate)
{
d = dict_alloc();
if (d == NULL)
return FAIL;
}
tvkey.v_type = VAR_UNKNOWN;
tv.v_type = VAR_UNKNOWN;
 
*arg = skipwhite(*arg + 1);
while (**arg != '}' && **arg != NUL)
{
if (eval1(arg, &tvkey, evaluate) == FAIL) /* recursive! */
goto failret;
if (**arg != ':')
{
EMSG2(_("E720: Missing colon in Dictionary: %s"), *arg);
clear_tv(&tvkey);
goto failret;
}
key = get_tv_string_buf_chk(&tvkey, buf);
if (key == NULL || *key == NUL)
{
/* "key" is NULL when get_tv_string_buf_chk() gave an errmsg */
if (key != NULL)
EMSG(_(e_emptykey));
clear_tv(&tvkey);
goto failret;
}
 
*arg = skipwhite(*arg + 1);
if (eval1(arg, &tv, evaluate) == FAIL) /* recursive! */
{
clear_tv(&tvkey);
goto failret;
}
if (evaluate)
{
item = dict_find(d, key, -1);
if (item != NULL)
{
EMSG2(_("E721: Duplicate key in Dictionary: \"%s\""), key);
clear_tv(&tvkey);
clear_tv(&tv);
goto failret;
}
item = dictitem_alloc(key);
clear_tv(&tvkey);
if (item != NULL)
{
item->di_tv = tv;
item->di_tv.v_lock = 0;
if (dict_add(d, item) == FAIL)
dictitem_free(item);
}
}
 
if (**arg == '}')
break;
if (**arg != ',')
{
EMSG2(_("E722: Missing comma in Dictionary: %s"), *arg);
goto failret;
}
*arg = skipwhite(*arg + 1);
}
 
if (**arg != '}')
{
EMSG2(_("E723: Missing end of Dictionary '}': %s"), *arg);
failret:
if (evaluate)
dict_free(d, TRUE);
return FAIL;
}
 
*arg = skipwhite(*arg + 1);
if (evaluate)
{
rettv->v_type = VAR_DICT;
rettv->vval.v_dict = d;
++d->dv_refcount;
}
 
return OK;
}
 
/*
* Return a string with the string representation of a variable.
* If the memory is allocated "tofree" is set to it, otherwise NULL.
* "numbuf" is used for a number.
* Does not put quotes around strings, as ":echo" displays values.
* When "copyID" is not NULL replace recursive lists and dicts with "...".
* May return NULL;
*/
static char_u *
echo_string(tv, tofree, numbuf, copyID)
typval_T *tv;
char_u **tofree;
char_u *numbuf;
int copyID;
{
static int recurse = 0;
char_u *r = NULL;
 
if (recurse >= DICT_MAXNEST)
{
EMSG(_("E724: variable nested too deep for displaying"));
*tofree = NULL;
return NULL;
}
++recurse;
 
switch (tv->v_type)
{
case VAR_FUNC:
*tofree = NULL;
r = tv->vval.v_string;
break;
 
case VAR_LIST:
if (tv->vval.v_list == NULL)
{
*tofree = NULL;
r = NULL;
}
else if (copyID != 0 && tv->vval.v_list->lv_copyID == copyID)
{
*tofree = NULL;
r = (char_u *)"[...]";
}
else
{
tv->vval.v_list->lv_copyID = copyID;
*tofree = list2string(tv, copyID);
r = *tofree;
}
break;
 
case VAR_DICT:
if (tv->vval.v_dict == NULL)
{
*tofree = NULL;
r = NULL;
}
else if (copyID != 0 && tv->vval.v_dict->dv_copyID == copyID)
{
*tofree = NULL;
r = (char_u *)"{...}";
}
else
{
tv->vval.v_dict->dv_copyID = copyID;
*tofree = dict2string(tv, copyID);
r = *tofree;
}
break;
 
case VAR_STRING:
case VAR_NUMBER:
*tofree = NULL;
r = get_tv_string_buf(tv, numbuf);
break;
 
default:
EMSG2(_(e_intern2), "echo_string()");
*tofree = NULL;
}
 
--recurse;
return r;
}
 
/*
* Return a string with the string representation of a variable.
* If the memory is allocated "tofree" is set to it, otherwise NULL.
* "numbuf" is used for a number.
* Puts quotes around strings, so that they can be parsed back by eval().
* May return NULL;
*/
static char_u *
tv2string(tv, tofree, numbuf, copyID)
typval_T *tv;
char_u **tofree;
char_u *numbuf;
int copyID;
{
switch (tv->v_type)
{
case VAR_FUNC:
*tofree = string_quote(tv->vval.v_string, TRUE);
return *tofree;
case VAR_STRING:
*tofree = string_quote(tv->vval.v_string, FALSE);
return *tofree;
case VAR_NUMBER:
case VAR_LIST:
case VAR_DICT:
break;
default:
EMSG2(_(e_intern2), "tv2string()");
}
return echo_string(tv, tofree, numbuf, copyID);
}
 
/*
* Return string "str" in ' quotes, doubling ' characters.
* If "str" is NULL an empty string is assumed.
* If "function" is TRUE make it function('string').
*/
static char_u *
string_quote(str, function)
char_u *str;
int function;
{
unsigned len;
char_u *p, *r, *s;
 
len = (function ? 13 : 3);
if (str != NULL)
{
len += (unsigned)STRLEN(str);
for (p = str; *p != NUL; mb_ptr_adv(p))
if (*p == '\'')
++len;
}
s = r = alloc(len);
if (r != NULL)
{
if (function)
{
STRCPY(r, "function('");
r += 10;
}
else
*r++ = '\'';
if (str != NULL)
for (p = str; *p != NUL; )
{
if (*p == '\'')
*r++ = '\'';
MB_COPY_CHAR(p, r);
}
*r++ = '\'';
if (function)
*r++ = ')';
*r++ = NUL;
}
return s;
}
 
/*
* Get the value of an environment variable.
* "arg" is pointing to the '$'. It is advanced to after the name.
* If the environment variable was not set, silently assume it is empty.
* Always return OK.
*/
static int
get_env_tv(arg, rettv, evaluate)
char_u **arg;
typval_T *rettv;
int evaluate;
{
char_u *string = NULL;
int len;
int cc;
char_u *name;
int mustfree = FALSE;
 
++*arg;
name = *arg;
len = get_env_len(arg);
if (evaluate)
{
if (len != 0)
{
cc = name[len];
name[len] = NUL;
/* first try vim_getenv(), fast for normal environment vars */
string = vim_getenv(name, &mustfree);
if (string != NULL && *string != NUL)
{
if (!mustfree)
string = vim_strsave(string);
}
else
{
if (mustfree)
vim_free(string);
 
/* next try expanding things like $VIM and ${HOME} */
string = expand_env_save(name - 1);
if (string != NULL && *string == '$')
{
vim_free(string);
string = NULL;
}
}
name[len] = cc;
}
rettv->v_type = VAR_STRING;
rettv->vval.v_string = string;
}
 
return OK;
}
 
/*
* Array with names and number of arguments of all internal functions
* MUST BE KEPT SORTED IN strcmp() ORDER FOR BINARY SEARCH!
*/
static struct fst
{
char *f_name; /* function name */
char f_min_argc; /* minimal number of arguments */
char f_max_argc; /* maximal number of arguments */
void (*f_func) __ARGS((typval_T *args, typval_T *rvar));
/* implementation of function */
} functions[] =
{
{"add", 2, 2, f_add},
{"append", 2, 2, f_append},
{"argc", 0, 0, f_argc},
{"argidx", 0, 0, f_argidx},
{"argv", 0, 1, f_argv},
{"browse", 4, 4, f_browse},
{"browsedir", 2, 2, f_browsedir},
{"bufexists", 1, 1, f_bufexists},
{"buffer_exists", 1, 1, f_bufexists}, /* obsolete */
{"buffer_name", 1, 1, f_bufname}, /* obsolete */
{"buffer_number", 1, 1, f_bufnr}, /* obsolete */
{"buflisted", 1, 1, f_buflisted},
{"bufloaded", 1, 1, f_bufloaded},
{"bufname", 1, 1, f_bufname},
{"bufnr", 1, 2, f_bufnr},
{"bufwinnr", 1, 1, f_bufwinnr},
{"byte2line", 1, 1, f_byte2line},
{"byteidx", 2, 2, f_byteidx},
{"call", 2, 3, f_call},
{"changenr", 0, 0, f_changenr},
{"char2nr", 1, 1, f_char2nr},
{"cindent", 1, 1, f_cindent},
{"col", 1, 1, f_col},
#if defined(FEAT_INS_EXPAND)
{"complete", 2, 2, f_complete},
{"complete_add", 1, 1, f_complete_add},
{"complete_check", 0, 0, f_complete_check},
#endif
{"confirm", 1, 4, f_confirm},
{"copy", 1, 1, f_copy},
{"count", 2, 4, f_count},
{"cscope_connection",0,3, f_cscope_connection},
{"cursor", 1, 3, f_cursor},
{"deepcopy", 1, 2, f_deepcopy},
{"delete", 1, 1, f_delete},
{"did_filetype", 0, 0, f_did_filetype},
{"diff_filler", 1, 1, f_diff_filler},
{"diff_hlID", 2, 2, f_diff_hlID},
{"empty", 1, 1, f_empty},
{"escape", 2, 2, f_escape},
{"eval", 1, 1, f_eval},
{"eventhandler", 0, 0, f_eventhandler},
{"executable", 1, 1, f_executable},
{"exists", 1, 1, f_exists},
{"expand", 1, 2, f_expand},
{"extend", 2, 3, f_extend},
{"feedkeys", 1, 2, f_feedkeys},
{"file_readable", 1, 1, f_filereadable}, /* obsolete */
{"filereadable", 1, 1, f_filereadable},
{"filewritable", 1, 1, f_filewritable},
{"filter", 2, 2, f_filter},
{"finddir", 1, 3, f_finddir},
{"findfile", 1, 3, f_findfile},
{"fnamemodify", 2, 2, f_fnamemodify},
{"foldclosed", 1, 1, f_foldclosed},
{"foldclosedend", 1, 1, f_foldclosedend},
{"foldlevel", 1, 1, f_foldlevel},
{"foldtext", 0, 0, f_foldtext},
{"foldtextresult", 1, 1, f_foldtextresult},
{"foreground", 0, 0, f_foreground},
{"function", 1, 1, f_function},
{"garbagecollect", 0, 0, f_garbagecollect},
{"get", 2, 3, f_get},
{"getbufline", 2, 3, f_getbufline},
{"getbufvar", 2, 2, f_getbufvar},
{"getchar", 0, 1, f_getchar},
{"getcharmod", 0, 0, f_getcharmod},
{"getcmdline", 0, 0, f_getcmdline},
{"getcmdpos", 0, 0, f_getcmdpos},
{"getcmdtype", 0, 0, f_getcmdtype},
{"getcwd", 0, 0, f_getcwd},
{"getfontname", 0, 1, f_getfontname},
{"getfperm", 1, 1, f_getfperm},
{"getfsize", 1, 1, f_getfsize},
{"getftime", 1, 1, f_getftime},
{"getftype", 1, 1, f_getftype},
{"getline", 1, 2, f_getline},
{"getloclist", 1, 1, f_getqflist},
{"getpos", 1, 1, f_getpos},
{"getqflist", 0, 0, f_getqflist},
{"getreg", 0, 2, f_getreg},
{"getregtype", 0, 1, f_getregtype},
{"gettabwinvar", 3, 3, f_gettabwinvar},
{"getwinposx", 0, 0, f_getwinposx},
{"getwinposy", 0, 0, f_getwinposy},
{"getwinvar", 2, 2, f_getwinvar},
{"glob", 1, 1, f_glob},
{"globpath", 2, 2, f_globpath},
{"has", 1, 1, f_has},
{"has_key", 2, 2, f_has_key},
{"haslocaldir", 0, 0, f_haslocaldir},
{"hasmapto", 1, 3, f_hasmapto},
{"highlightID", 1, 1, f_hlID}, /* obsolete */
{"highlight_exists",1, 1, f_hlexists}, /* obsolete */
{"histadd", 2, 2, f_histadd},
{"histdel", 1, 2, f_histdel},
{"histget", 1, 2, f_histget},
{"histnr", 1, 1, f_histnr},
{"hlID", 1, 1, f_hlID},
{"hlexists", 1, 1, f_hlexists},
{"hostname", 0, 0, f_hostname},
{"iconv", 3, 3, f_iconv},
{"indent", 1, 1, f_indent},
{"index", 2, 4, f_index},
{"input", 1, 3, f_input},
{"inputdialog", 1, 3, f_inputdialog},
{"inputlist", 1, 1, f_inputlist},
{"inputrestore", 0, 0, f_inputrestore},
{"inputsave", 0, 0, f_inputsave},
{"inputsecret", 1, 2, f_inputsecret},
{"insert", 2, 3, f_insert},
{"isdirectory", 1, 1, f_isdirectory},
{"islocked", 1, 1, f_islocked},
{"items", 1, 1, f_items},
{"join", 1, 2, f_join},
{"keys", 1, 1, f_keys},
{"last_buffer_nr", 0, 0, f_last_buffer_nr},/* obsolete */
{"len", 1, 1, f_len},
{"libcall", 3, 3, f_libcall},
{"libcallnr", 3, 3, f_libcallnr},
{"line", 1, 1, f_line},
{"line2byte", 1, 1, f_line2byte},
{"lispindent", 1, 1, f_lispindent},
{"localtime", 0, 0, f_localtime},
{"map", 2, 2, f_map},
{"maparg", 1, 3, f_maparg},
{"mapcheck", 1, 3, f_mapcheck},
{"match", 2, 4, f_match},
{"matcharg", 1, 1, f_matcharg},
{"matchend", 2, 4, f_matchend},
{"matchlist", 2, 4, f_matchlist},
{"matchstr", 2, 4, f_matchstr},
{"max", 1, 1, f_max},
{"min", 1, 1, f_min},
#ifdef vim_mkdir
{"mkdir", 1, 3, f_mkdir},
#endif
{"mode", 0, 0, f_mode},
{"nextnonblank", 1, 1, f_nextnonblank},
{"nr2char", 1, 1, f_nr2char},
{"pathshorten", 1, 1, f_pathshorten},
{"prevnonblank", 1, 1, f_prevnonblank},
{"printf", 2, 19, f_printf},
{"pumvisible", 0, 0, f_pumvisible},
{"range", 1, 3, f_range},
{"readfile", 1, 3, f_readfile},
{"reltime", 0, 2, f_reltime},
{"reltimestr", 1, 1, f_reltimestr},
{"remote_expr", 2, 3, f_remote_expr},
{"remote_foreground", 1, 1, f_remote_foreground},
{"remote_peek", 1, 2, f_remote_peek},
{"remote_read", 1, 1, f_remote_read},
{"remote_send", 2, 3, f_remote_send},
{"remove", 2, 3, f_remove},
{"rename", 2, 2, f_rename},
{"repeat", 2, 2, f_repeat},
{"resolve", 1, 1, f_resolve},
{"reverse", 1, 1, f_reverse},
{"search", 1, 3, f_search},
{"searchdecl", 1, 3, f_searchdecl},
{"searchpair", 3, 6, f_searchpair},
{"searchpairpos", 3, 6, f_searchpairpos},
{"searchpos", 1, 3, f_searchpos},
{"server2client", 2, 2, f_server2client},
{"serverlist", 0, 0, f_serverlist},
{"setbufvar", 3, 3, f_setbufvar},
{"setcmdpos", 1, 1, f_setcmdpos},
{"setline", 2, 2, f_setline},
{"setloclist", 2, 3, f_setloclist},
{"setpos", 2, 2, f_setpos},
{"setqflist", 1, 2, f_setqflist},
{"setreg", 2, 3, f_setreg},
{"settabwinvar", 4, 4, f_settabwinvar},
{"setwinvar", 3, 3, f_setwinvar},
{"shellescape", 1, 1, f_shellescape},
{"simplify", 1, 1, f_simplify},
{"sort", 1, 2, f_sort},
{"soundfold", 1, 1, f_soundfold},
{"spellbadword", 0, 1, f_spellbadword},
{"spellsuggest", 1, 3, f_spellsuggest},
{"split", 1, 3, f_split},
{"str2nr", 1, 2, f_str2nr},
#ifdef HAVE_STRFTIME
{"strftime", 1, 2, f_strftime},
#endif
{"stridx", 2, 3, f_stridx},
{"string", 1, 1, f_string},
{"strlen", 1, 1, f_strlen},
{"strpart", 2, 3, f_strpart},
{"strridx", 2, 3, f_strridx},
{"strtrans", 1, 1, f_strtrans},
{"submatch", 1, 1, f_submatch},
{"substitute", 4, 4, f_substitute},
{"synID", 3, 3, f_synID},
{"synIDattr", 2, 3, f_synIDattr},
{"synIDtrans", 1, 1, f_synIDtrans},
{"system", 1, 2, f_system},
{"tabpagebuflist", 0, 1, f_tabpagebuflist},
{"tabpagenr", 0, 1, f_tabpagenr},
{"tabpagewinnr", 1, 2, f_tabpagewinnr},
{"tagfiles", 0, 0, f_tagfiles},
{"taglist", 1, 1, f_taglist},
{"tempname", 0, 0, f_tempname},
{"test", 1, 1, f_test},
{"tolower", 1, 1, f_tolower},
{"toupper", 1, 1, f_toupper},
{"tr", 3, 3, f_tr},
{"type", 1, 1, f_type},
{"values", 1, 1, f_values},
{"virtcol", 1, 1, f_virtcol},
{"visualmode", 0, 1, f_visualmode},
{"winbufnr", 1, 1, f_winbufnr},
{"wincol", 0, 0, f_wincol},
{"winheight", 1, 1, f_winheight},
{"winline", 0, 0, f_winline},
{"winnr", 0, 1, f_winnr},
{"winrestcmd", 0, 0, f_winrestcmd},
{"winrestview", 1, 1, f_winrestview},
{"winsaveview", 0, 0, f_winsaveview},
{"winwidth", 1, 1, f_winwidth},
{"writefile", 2, 3, f_writefile},
};
 
#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
 
/*
* Function given to ExpandGeneric() to obtain the list of internal
* or user defined function names.
*/
char_u *
get_function_name(xp, idx)
expand_T *xp;
int idx;
{
static int intidx = -1;
char_u *name;
 
if (idx == 0)
intidx = -1;
if (intidx < 0)
{
name = get_user_func_name(xp, idx);
if (name != NULL)
return name;
}
if (++intidx < (int)(sizeof(functions) / sizeof(struct fst)))
{
STRCPY(IObuff, functions[intidx].f_name);
STRCAT(IObuff, "(");
if (functions[intidx].f_max_argc == 0)
STRCAT(IObuff, ")");
return IObuff;
}
 
return NULL;
}
 
/*
* Function given to ExpandGeneric() to obtain the list of internal or
* user defined variable or function names.
*/
/*ARGSUSED*/
char_u *
get_expr_name(xp, idx)
expand_T *xp;
int idx;
{
static int intidx = -1;
char_u *name;
 
if (idx == 0)
intidx = -1;
if (intidx < 0)
{
name = get_function_name(xp, idx);
if (name != NULL)
return name;
}
return get_user_var_name(xp, ++intidx);
}
 
#endif /* FEAT_CMDL_COMPL */
 
/*
* Find internal function in table above.
* Return index, or -1 if not found
*/
static int
find_internal_func(name)
char_u *name; /* name of the function */
{
int first = 0;
int last = (int)(sizeof(functions) / sizeof(struct fst)) - 1;
int cmp;
int x;
 
/*
* Find the function name in the table. Binary search.
*/
while (first <= last)
{
x = first + ((unsigned)(last - first) >> 1);
cmp = STRCMP(name, functions[x].f_name);
if (cmp < 0)
last = x - 1;
else if (cmp > 0)
first = x + 1;
else
return x;
}
return -1;
}
 
/*
* Check if "name" is a variable of type VAR_FUNC. If so, return the function
* name it contains, otherwise return "name".
*/
static char_u *
deref_func_name(name, lenp)
char_u *name;
int *lenp;
{
dictitem_T *v;
int cc;
 
cc = name[*lenp];
name[*lenp] = NUL;
v = find_var(name, NULL);
name[*lenp] = cc;
if (v != NULL && v->di_tv.v_type == VAR_FUNC)
{
if (v->di_tv.vval.v_string == NULL)
{
*lenp = 0;
return (char_u *)""; /* just in case */
}
*lenp = (int)STRLEN(v->di_tv.vval.v_string);
return v->di_tv.vval.v_string;
}
 
return name;
}
 
/*
* Allocate a variable for the result of a function.
* Return OK or FAIL.
*/
static int
get_func_tv(name, len, rettv, arg, firstline, lastline, doesrange,
evaluate, selfdict)
char_u *name; /* name of the function */
int len; /* length of "name" */
typval_T *rettv;
char_u **arg; /* argument, pointing to the '(' */
linenr_T firstline; /* first line of range */
linenr_T lastline; /* last line of range */
int *doesrange; /* return: function handled range */
int evaluate;
dict_T *selfdict; /* Dictionary for "self" */
{
char_u *argp;
int ret = OK;
typval_T argvars[MAX_FUNC_ARGS + 1]; /* vars for arguments */
int argcount = 0; /* number of arguments found */
 
/*
* Get the arguments.
*/
argp = *arg;
while (argcount < MAX_FUNC_ARGS)
{
argp = skipwhite(argp + 1); /* skip the '(' or ',' */
if (*argp == ')' || *argp == ',' || *argp == NUL)
break;
if (eval1(&argp, &argvars[argcount], evaluate) == FAIL)
{
ret = FAIL;
break;
}
++argcount;
if (*argp != ',')
break;
}
if (*argp == ')')
++argp;
else
ret = FAIL;
 
if (ret == OK)
ret = call_func(name, len, rettv, argcount, argvars,
firstline, lastline, doesrange, evaluate, selfdict);
else if (!aborting())
{
if (argcount == MAX_FUNC_ARGS)
emsg_funcname("E740: Too many arguments for function %s", name);
else
emsg_funcname("E116: Invalid arguments for function %s", name);
}
 
while (--argcount >= 0)
clear_tv(&argvars[argcount]);
 
*arg = skipwhite(argp);
return ret;
}
 
 
/*
* Call a function with its resolved parameters
* Return OK when the function can't be called, FAIL otherwise.
* Also returns OK when an error was encountered while executing the function.
*/
static int
call_func(name, len, rettv, argcount, argvars, firstline, lastline,
doesrange, evaluate, selfdict)
char_u *name; /* name of the function */
int len; /* length of "name" */
typval_T *rettv; /* return value goes here */
int argcount; /* number of "argvars" */
typval_T *argvars; /* vars for arguments, must have "argcount"
PLUS ONE elements! */
linenr_T firstline; /* first line of range */
linenr_T lastline; /* last line of range */
int *doesrange; /* return: function handled range */
int evaluate;
dict_T *selfdict; /* Dictionary for "self" */
{
int ret = FAIL;
#define ERROR_UNKNOWN 0
#define ERROR_TOOMANY 1
#define ERROR_TOOFEW 2
#define ERROR_SCRIPT 3
#define ERROR_DICT 4
#define ERROR_NONE 5
#define ERROR_OTHER 6
int error = ERROR_NONE;
int i;
int llen;
ufunc_T *fp;
int cc;
#define FLEN_FIXED 40
char_u fname_buf[FLEN_FIXED + 1];
char_u *fname;
 
/*
* In a script change <SID>name() and s:name() to K_SNR 123_name().
* Change <SNR>123_name() to K_SNR 123_name().
* Use fname_buf[] when it fits, otherwise allocate memory (slow).
*/
cc = name[len];
name[len] = NUL;
llen = eval_fname_script(name);
if (llen > 0)
{
fname_buf[0] = K_SPECIAL;
fname_buf[1] = KS_EXTRA;
fname_buf[2] = (int)KE_SNR;
i = 3;
if (eval_fname_sid(name)) /* "<SID>" or "s:" */
{
if (current_SID <= 0)
error = ERROR_SCRIPT;
else
{
sprintf((char *)fname_buf + 3, "%ld_", (long)current_SID);
i = (int)STRLEN(fname_buf);
}
}
if (i + STRLEN(name + llen) < FLEN_FIXED)
{
STRCPY(fname_buf + i, name + llen);
fname = fname_buf;
}
else
{
fname = alloc((unsigned)(i + STRLEN(name + llen) + 1));
if (fname == NULL)
error = ERROR_OTHER;
else
{
mch_memmove(fname, fname_buf, (size_t)i);
STRCPY(fname + i, name + llen);
}
}
}
else
fname = name;
 
*doesrange = FALSE;
 
 
/* execute the function if no errors detected and executing */
if (evaluate && error == ERROR_NONE)
{
rettv->v_type = VAR_NUMBER; /* default is number rettv */
error = ERROR_UNKNOWN;
 
if (!builtin_function(fname))
{
/*
* User defined function.
*/
fp = find_func(fname);
 
#ifdef FEAT_AUTOCMD
/* Trigger FuncUndefined event, may load the function. */
if (fp == NULL
&& apply_autocmds(EVENT_FUNCUNDEFINED,
fname, fname, TRUE, NULL)
&& !aborting())
{
/* executed an autocommand, search for the function again */
fp = find_func(fname);
}
#endif
/* Try loading a package. */
if (fp == NULL && script_autoload(fname, TRUE) && !aborting())
{
/* loaded a package, search for the function again */
fp = find_func(fname);
}
 
if (fp != NULL)
{
if (fp->uf_flags & FC_RANGE)
*doesrange = TRUE;
if (argcount < fp->uf_args.ga_len)
error = ERROR_TOOFEW;
else if (!fp->uf_varargs && argcount > fp->uf_args.ga_len)
error = ERROR_TOOMANY;
else if ((fp->uf_flags & FC_DICT) && selfdict == NULL)
error = ERROR_DICT;
else
{
/*
* Call the user function.
* Save and restore search patterns, script variables and
* redo buffer.
*/
save_search_patterns();
saveRedobuff();
++fp->uf_calls;
call_user_func(fp, argcount, argvars, rettv,
firstline, lastline,
(fp->uf_flags & FC_DICT) ? selfdict : NULL);
if (--fp->uf_calls <= 0 && isdigit(*fp->uf_name)
&& fp->uf_refcount <= 0)
/* Function was unreferenced while being used, free it
* now. */
func_free(fp);
restoreRedobuff();
restore_search_patterns();
error = ERROR_NONE;
}
}
}
else
{
/*
* Find the function name in the table, call its implementation.
*/
i = find_internal_func(fname);
if (i >= 0)
{
if (argcount < functions[i].f_min_argc)
error = ERROR_TOOFEW;
else if (argcount > functions[i].f_max_argc)
error = ERROR_TOOMANY;
else
{
argvars[argcount].v_type = VAR_UNKNOWN;
functions[i].f_func(argvars, rettv);
error = ERROR_NONE;
}
}
}
/*
* The function call (or "FuncUndefined" autocommand sequence) might
* have been aborted by an error, an interrupt, or an explicitly thrown
* exception that has not been caught so far. This situation can be
* tested for by calling aborting(). For an error in an internal
* function or for the "E132" error in call_user_func(), however, the
* throw point at which the "force_abort" flag (temporarily reset by
* emsg()) is normally updated has not been reached yet. We need to
* update that flag first to make aborting() reliable.
*/
update_force_abort();
}
if (error == ERROR_NONE)
ret = OK;
 
/*
* Report an error unless the argument evaluation or function call has been
* cancelled due to an aborting error, an interrupt, or an exception.
*/
if (!aborting())
{
switch (error)
{
case ERROR_UNKNOWN:
emsg_funcname(N_("E117: Unknown function: %s"), name);
break;
case ERROR_TOOMANY:
emsg_funcname(e_toomanyarg, name);
break;
case ERROR_TOOFEW:
emsg_funcname(N_("E119: Not enough arguments for function: %s"),
name);
break;
case ERROR_SCRIPT:
emsg_funcname(N_("E120: Using <SID> not in a script context: %s"),
name);
break;
case ERROR_DICT:
emsg_funcname(N_("E725: Calling dict function without Dictionary: %s"),
name);
break;
}
}
 
name[len] = cc;
if (fname != name && fname != fname_buf)
vim_free(fname);
 
return ret;
}
 
/*
* Give an error message with a function name. Handle <SNR> things.
*/
static void
emsg_funcname(ermsg, name)
char *ermsg;
char_u *name;
{
char_u *p;
 
if (*name == K_SPECIAL)
p = concat_str((char_u *)"<SNR>", name + 3);
else
p = name;
EMSG2(_(ermsg), p);
if (p != name)
vim_free(p);
}
 
/*********************************************
* Implementation of the built-in functions
*/
 
/*
* "add(list, item)" function
*/
static void
f_add(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
list_T *l;
 
rettv->vval.v_number = 1; /* Default: Failed */
if (argvars[0].v_type == VAR_LIST)
{
if ((l = argvars[0].vval.v_list) != NULL
&& !tv_check_lock(l->lv_lock, (char_u *)"add()")
&& list_append_tv(l, &argvars[1]) == OK)
copy_tv(&argvars[0], rettv);
}
else
EMSG(_(e_listreq));
}
 
/*
* "append(lnum, string/list)" function
*/
static void
f_append(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
long lnum;
char_u *line;
list_T *l = NULL;
listitem_T *li = NULL;
typval_T *tv;
long added = 0;
 
lnum = get_tv_lnum(argvars);
if (lnum >= 0
&& lnum <= curbuf->b_ml.ml_line_count
&& u_save(lnum, lnum + 1) == OK)
{
if (argvars[1].v_type == VAR_LIST)
{
l = argvars[1].vval.v_list;
if (l == NULL)
return;
li = l->lv_first;
}
rettv->vval.v_number = 0; /* Default: Success */
for (;;)
{
if (l == NULL)
tv = &argvars[1]; /* append a string */
else if (li == NULL)
break; /* end of list */
else
tv = &li->li_tv; /* append item from list */
line = get_tv_string_chk(tv);
if (line == NULL) /* type error */
{
rettv->vval.v_number = 1; /* Failed */
break;
}
ml_append(lnum + added, line, (colnr_T)0, FALSE);
++added;
if (l == NULL)
break;
li = li->li_next;
}
 
appended_lines_mark(lnum, added);
if (curwin->w_cursor.lnum > lnum)
curwin->w_cursor.lnum += added;
}
else
rettv->vval.v_number = 1; /* Failed */
}
 
/*
* "argc()" function
*/
/* ARGSUSED */
static void
f_argc(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = ARGCOUNT;
}
 
/*
* "argidx()" function
*/
/* ARGSUSED */
static void
f_argidx(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = curwin->w_arg_idx;
}
 
/*
* "argv(nr)" function
*/
static void
f_argv(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
int idx;
 
if (argvars[0].v_type != VAR_UNKNOWN)
{
idx = get_tv_number_chk(&argvars[0], NULL);
if (idx >= 0 && idx < ARGCOUNT)
rettv->vval.v_string = vim_strsave(alist_name(&ARGLIST[idx]));
else
rettv->vval.v_string = NULL;
rettv->v_type = VAR_STRING;
}
else if (rettv_list_alloc(rettv) == OK)
for (idx = 0; idx < ARGCOUNT; ++idx)
list_append_string(rettv->vval.v_list,
alist_name(&ARGLIST[idx]), -1);
}
 
/*
* "browse(save, title, initdir, default)" function
*/
/* ARGSUSED */
static void
f_browse(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_BROWSE
int save;
char_u *title;
char_u *initdir;
char_u *defname;
char_u buf[NUMBUFLEN];
char_u buf2[NUMBUFLEN];
int error = FALSE;
 
save = get_tv_number_chk(&argvars[0], &error);
title = get_tv_string_chk(&argvars[1]);
initdir = get_tv_string_buf_chk(&argvars[2], buf);
defname = get_tv_string_buf_chk(&argvars[3], buf2);
 
if (error || title == NULL || initdir == NULL || defname == NULL)
rettv->vval.v_string = NULL;
else
rettv->vval.v_string =
do_browse(save ? BROWSE_SAVE : 0,
title, defname, NULL, initdir, NULL, curbuf);
#else
rettv->vval.v_string = NULL;
#endif
rettv->v_type = VAR_STRING;
}
 
/*
* "browsedir(title, initdir)" function
*/
/* ARGSUSED */
static void
f_browsedir(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_BROWSE
char_u *title;
char_u *initdir;
char_u buf[NUMBUFLEN];
 
title = get_tv_string_chk(&argvars[0]);
initdir = get_tv_string_buf_chk(&argvars[1], buf);
 
if (title == NULL || initdir == NULL)
rettv->vval.v_string = NULL;
else
rettv->vval.v_string = do_browse(BROWSE_DIR,
title, NULL, NULL, initdir, NULL, curbuf);
#else
rettv->vval.v_string = NULL;
#endif
rettv->v_type = VAR_STRING;
}
 
static buf_T *find_buffer __ARGS((typval_T *avar));
 
/*
* Find a buffer by number or exact name.
*/
static buf_T *
find_buffer(avar)
typval_T *avar;
{
buf_T *buf = NULL;
 
if (avar->v_type == VAR_NUMBER)
buf = buflist_findnr((int)avar->vval.v_number);
else if (avar->v_type == VAR_STRING && avar->vval.v_string != NULL)
{
buf = buflist_findname_exp(avar->vval.v_string);
if (buf == NULL)
{
/* No full path name match, try a match with a URL or a "nofile"
* buffer, these don't use the full path. */
for (buf = firstbuf; buf != NULL; buf = buf->b_next)
if (buf->b_fname != NULL
&& (path_with_url(buf->b_fname)
#ifdef FEAT_QUICKFIX
|| bt_nofile(buf)
#endif
)
&& STRCMP(buf->b_fname, avar->vval.v_string) == 0)
break;
}
}
return buf;
}
 
/*
* "bufexists(expr)" function
*/
static void
f_bufexists(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = (find_buffer(&argvars[0]) != NULL);
}
 
/*
* "buflisted(expr)" function
*/
static void
f_buflisted(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
buf_T *buf;
 
buf = find_buffer(&argvars[0]);
rettv->vval.v_number = (buf != NULL && buf->b_p_bl);
}
 
/*
* "bufloaded(expr)" function
*/
static void
f_bufloaded(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
buf_T *buf;
 
buf = find_buffer(&argvars[0]);
rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL);
}
 
static buf_T *get_buf_tv __ARGS((typval_T *tv));
 
/*
* Get buffer by number or pattern.
*/
static buf_T *
get_buf_tv(tv)
typval_T *tv;
{
char_u *name = tv->vval.v_string;
int save_magic;
char_u *save_cpo;
buf_T *buf;
 
if (tv->v_type == VAR_NUMBER)
return buflist_findnr((int)tv->vval.v_number);
if (tv->v_type != VAR_STRING)
return NULL;
if (name == NULL || *name == NUL)
return curbuf;
if (name[0] == '$' && name[1] == NUL)
return lastbuf;
 
/* Ignore 'magic' and 'cpoptions' here to make scripts portable */
save_magic = p_magic;
p_magic = TRUE;
save_cpo = p_cpo;
p_cpo = (char_u *)"";
 
buf = buflist_findnr(buflist_findpat(name, name + STRLEN(name),
TRUE, FALSE));
 
p_magic = save_magic;
p_cpo = save_cpo;
 
/* If not found, try expanding the name, like done for bufexists(). */
if (buf == NULL)
buf = find_buffer(tv);
 
return buf;
}
 
/*
* "bufname(expr)" function
*/
static void
f_bufname(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
buf_T *buf;
 
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
++emsg_off;
buf = get_buf_tv(&argvars[0]);
rettv->v_type = VAR_STRING;
if (buf != NULL && buf->b_fname != NULL)
rettv->vval.v_string = vim_strsave(buf->b_fname);
else
rettv->vval.v_string = NULL;
--emsg_off;
}
 
/*
* "bufnr(expr)" function
*/
static void
f_bufnr(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
buf_T *buf;
int error = FALSE;
char_u *name;
 
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
++emsg_off;
buf = get_buf_tv(&argvars[0]);
--emsg_off;
 
/* If the buffer isn't found and the second argument is not zero create a
* new buffer. */
if (buf == NULL
&& argvars[1].v_type != VAR_UNKNOWN
&& get_tv_number_chk(&argvars[1], &error) != 0
&& !error
&& (name = get_tv_string_chk(&argvars[0])) != NULL
&& !error)
buf = buflist_new(name, NULL, (linenr_T)1, 0);
 
if (buf != NULL)
rettv->vval.v_number = buf->b_fnum;
else
rettv->vval.v_number = -1;
}
 
/*
* "bufwinnr(nr)" function
*/
static void
f_bufwinnr(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_WINDOWS
win_T *wp;
int winnr = 0;
#endif
buf_T *buf;
 
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
++emsg_off;
buf = get_buf_tv(&argvars[0]);
#ifdef FEAT_WINDOWS
for (wp = firstwin; wp; wp = wp->w_next)
{
++winnr;
if (wp->w_buffer == buf)
break;
}
rettv->vval.v_number = (wp != NULL ? winnr : -1);
#else
rettv->vval.v_number = (curwin->w_buffer == buf ? 1 : -1);
#endif
--emsg_off;
}
 
/*
* "byte2line(byte)" function
*/
/*ARGSUSED*/
static void
f_byte2line(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifndef FEAT_BYTEOFF
rettv->vval.v_number = -1;
#else
long boff = 0;
 
boff = get_tv_number(&argvars[0]) - 1; /* boff gets -1 on type error */
if (boff < 0)
rettv->vval.v_number = -1;
else
rettv->vval.v_number = ml_find_line_or_offset(curbuf,
(linenr_T)0, &boff);
#endif
}
 
/*
* "byteidx()" function
*/
/*ARGSUSED*/
static void
f_byteidx(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_MBYTE
char_u *t;
#endif
char_u *str;
long idx;
 
str = get_tv_string_chk(&argvars[0]);
idx = get_tv_number_chk(&argvars[1], NULL);
rettv->vval.v_number = -1;
if (str == NULL || idx < 0)
return;
 
#ifdef FEAT_MBYTE
t = str;
for ( ; idx > 0; idx--)
{
if (*t == NUL) /* EOL reached */
return;
t += (*mb_ptr2len)(t);
}
rettv->vval.v_number = (varnumber_T)(t - str);
#else
if (idx <= STRLEN(str))
rettv->vval.v_number = idx;
#endif
}
 
/*
* "call(func, arglist)" function
*/
static void
f_call(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *func;
typval_T argv[MAX_FUNC_ARGS + 1];
int argc = 0;
listitem_T *item;
int dummy;
dict_T *selfdict = NULL;
 
rettv->vval.v_number = 0;
if (argvars[1].v_type != VAR_LIST)
{
EMSG(_(e_listreq));
return;
}
if (argvars[1].vval.v_list == NULL)
return;
 
if (argvars[0].v_type == VAR_FUNC)
func = argvars[0].vval.v_string;
else
func = get_tv_string(&argvars[0]);
if (*func == NUL)
return; /* type error or empty name */
 
if (argvars[2].v_type != VAR_UNKNOWN)
{
if (argvars[2].v_type != VAR_DICT)
{
EMSG(_(e_dictreq));
return;
}
selfdict = argvars[2].vval.v_dict;
}
 
for (item = argvars[1].vval.v_list->lv_first; item != NULL;
item = item->li_next)
{
if (argc == MAX_FUNC_ARGS)
{
EMSG(_("E699: Too many arguments"));
break;
}
/* Make a copy of each argument. This is needed to be able to set
* v_lock to VAR_FIXED in the copy without changing the original list.
*/
copy_tv(&item->li_tv, &argv[argc++]);
}
 
if (item == NULL)
(void)call_func(func, (int)STRLEN(func), rettv, argc, argv,
curwin->w_cursor.lnum, curwin->w_cursor.lnum,
&dummy, TRUE, selfdict);
 
/* Free the arguments. */
while (argc > 0)
clear_tv(&argv[--argc]);
}
 
/*
* "changenr()" function
*/
/*ARGSUSED*/
static void
f_changenr(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = curbuf->b_u_seq_cur;
}
 
/*
* "char2nr(string)" function
*/
static void
f_char2nr(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_MBYTE
if (has_mbyte)
rettv->vval.v_number = (*mb_ptr2char)(get_tv_string(&argvars[0]));
else
#endif
rettv->vval.v_number = get_tv_string(&argvars[0])[0];
}
 
/*
* "cindent(lnum)" function
*/
static void
f_cindent(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_CINDENT
pos_T pos;
linenr_T lnum;
 
pos = curwin->w_cursor;
lnum = get_tv_lnum(argvars);
if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
{
curwin->w_cursor.lnum = lnum;
rettv->vval.v_number = get_c_indent();
curwin->w_cursor = pos;
}
else
#endif
rettv->vval.v_number = -1;
}
 
/*
* "col(string)" function
*/
static void
f_col(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
colnr_T col = 0;
pos_T *fp;
int fnum = curbuf->b_fnum;
 
fp = var2fpos(&argvars[0], FALSE, &fnum);
if (fp != NULL && fnum == curbuf->b_fnum)
{
if (fp->col == MAXCOL)
{
/* '> can be MAXCOL, get the length of the line then */
if (fp->lnum <= curbuf->b_ml.ml_line_count)
col = (colnr_T)STRLEN(ml_get(fp->lnum)) + 1;
else
col = MAXCOL;
}
else
{
col = fp->col + 1;
#ifdef FEAT_VIRTUALEDIT
/* col(".") when the cursor is on the NUL at the end of the line
* because of "coladd" can be seen as an extra column. */
if (virtual_active() && fp == &curwin->w_cursor)
{
char_u *p = ml_get_cursor();
 
if (curwin->w_cursor.coladd >= (colnr_T)chartabsize(p,
curwin->w_virtcol - curwin->w_cursor.coladd))
{
# ifdef FEAT_MBYTE
int l;
 
if (*p != NUL && p[(l = (*mb_ptr2len)(p))] == NUL)
col += l;
# else
if (*p != NUL && p[1] == NUL)
++col;
# endif
}
}
#endif
}
}
rettv->vval.v_number = col;
}
 
#if defined(FEAT_INS_EXPAND)
/*
* "complete()" function
*/
/*ARGSUSED*/
static void
f_complete(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
int startcol;
 
if ((State & INSERT) == 0)
{
EMSG(_("E785: complete() can only be used in Insert mode"));
return;
}
 
/* Check for undo allowed here, because if something was already inserted
* the line was already saved for undo and this check isn't done. */
if (!undo_allowed())
return;
 
if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL)
{
EMSG(_(e_invarg));
return;
}
 
startcol = get_tv_number_chk(&argvars[0], NULL);
if (startcol <= 0)
return;
 
set_completion(startcol - 1, argvars[1].vval.v_list);
}
 
/*
* "complete_add()" function
*/
/*ARGSUSED*/
static void
f_complete_add(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0);
}
 
/*
* "complete_check()" function
*/
/*ARGSUSED*/
static void
f_complete_check(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
int saved = RedrawingDisabled;
 
RedrawingDisabled = 0;
ins_compl_check_keys(0);
rettv->vval.v_number = compl_interrupted;
RedrawingDisabled = saved;
}
#endif
 
/*
* "confirm(message, buttons[, default [, type]])" function
*/
/*ARGSUSED*/
static void
f_confirm(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
char_u *message;
char_u *buttons = NULL;
char_u buf[NUMBUFLEN];
char_u buf2[NUMBUFLEN];
int def = 1;
int type = VIM_GENERIC;
char_u *vim_typestr;
int error = FALSE;
 
message = get_tv_string_chk(&argvars[0]);
if (message == NULL)
error = TRUE;
if (argvars[1].v_type != VAR_UNKNOWN)
{
buttons = get_tv_string_buf_chk(&argvars[1], buf);
if (buttons == NULL)
error = TRUE;
if (argvars[2].v_type != VAR_UNKNOWN)
{
def = get_tv_number_chk(&argvars[2], &error);
if (argvars[3].v_type != VAR_UNKNOWN)
{
vim_typestr = get_tv_string_buf_chk(&argvars[3], buf2);
if (vim_typestr == NULL)
error = TRUE;
else
{
switch (TOUPPER_ASC(*vim_typestr))
{
case 'E': type = VIM_ERROR; break;
case 'Q': type = VIM_QUESTION; break;
case 'I': type = VIM_INFO; break;
case 'W': type = VIM_WARNING; break;
case 'G': type = VIM_GENERIC; break;
}
}
}
}
}
 
if (buttons == NULL || *buttons == NUL)
buttons = (char_u *)_("&Ok");
 
if (error)
rettv->vval.v_number = 0;
else
rettv->vval.v_number = do_dialog(type, NULL, message, buttons,
def, NULL);
#else
rettv->vval.v_number = 0;
#endif
}
 
/*
* "copy()" function
*/
static void
f_copy(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
item_copy(&argvars[0], rettv, FALSE, 0);
}
 
/*
* "count()" function
*/
static void
f_count(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
long n = 0;
int ic = FALSE;
 
if (argvars[0].v_type == VAR_LIST)
{
listitem_T *li;
list_T *l;
long idx;
 
if ((l = argvars[0].vval.v_list) != NULL)
{
li = l->lv_first;
if (argvars[2].v_type != VAR_UNKNOWN)
{
int error = FALSE;
 
ic = get_tv_number_chk(&argvars[2], &error);
if (argvars[3].v_type != VAR_UNKNOWN)
{
idx = get_tv_number_chk(&argvars[3], &error);
if (!error)
{
li = list_find(l, idx);
if (li == NULL)
EMSGN(_(e_listidx), idx);
}
}
if (error)
li = NULL;
}
 
for ( ; li != NULL; li = li->li_next)
if (tv_equal(&li->li_tv, &argvars[1], ic))
++n;
}
}
else if (argvars[0].v_type == VAR_DICT)
{
int todo;
dict_T *d;
hashitem_T *hi;
 
if ((d = argvars[0].vval.v_dict) != NULL)
{
int error = FALSE;
 
if (argvars[2].v_type != VAR_UNKNOWN)
{
ic = get_tv_number_chk(&argvars[2], &error);
if (argvars[3].v_type != VAR_UNKNOWN)
EMSG(_(e_invarg));
}
 
todo = error ? 0 : (int)d->dv_hashtab.ht_used;
for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
if (tv_equal(&HI2DI(hi)->di_tv, &argvars[1], ic))
++n;
}
}
}
}
else
EMSG2(_(e_listdictarg), "count()");
rettv->vval.v_number = n;
}
 
/*
* "cscope_connection([{num} , {dbpath} [, {prepend}]])" function
*
* Checks the existence of a cscope connection.
*/
/*ARGSUSED*/
static void
f_cscope_connection(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_CSCOPE
int num = 0;
char_u *dbpath = NULL;
char_u *prepend = NULL;
char_u buf[NUMBUFLEN];
 
if (argvars[0].v_type != VAR_UNKNOWN
&& argvars[1].v_type != VAR_UNKNOWN)
{
num = (int)get_tv_number(&argvars[0]);
dbpath = get_tv_string(&argvars[1]);
if (argvars[2].v_type != VAR_UNKNOWN)
prepend = get_tv_string_buf(&argvars[2], buf);
}
 
rettv->vval.v_number = cs_connection(num, dbpath, prepend);
#else
rettv->vval.v_number = 0;
#endif
}
 
/*
* "cursor(lnum, col)" function
*
* Moves the cursor to the specified line and column
*/
/*ARGSUSED*/
static void
f_cursor(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
long line, col;
#ifdef FEAT_VIRTUALEDIT
long coladd = 0;
#endif
 
if (argvars[1].v_type == VAR_UNKNOWN)
{
pos_T pos;
 
if (list2fpos(argvars, &pos, NULL) == FAIL)
return;
line = pos.lnum;
col = pos.col;
#ifdef FEAT_VIRTUALEDIT
coladd = pos.coladd;
#endif
}
else
{
line = get_tv_lnum(argvars);
col = get_tv_number_chk(&argvars[1], NULL);
#ifdef FEAT_VIRTUALEDIT
if (argvars[2].v_type != VAR_UNKNOWN)
coladd = get_tv_number_chk(&argvars[2], NULL);
#endif
}
if (line < 0 || col < 0
#ifdef FEAT_VIRTUALEDIT
|| coladd < 0
#endif
)
return; /* type error; errmsg already given */
if (line > 0)
curwin->w_cursor.lnum = line;
if (col > 0)
curwin->w_cursor.col = col - 1;
#ifdef FEAT_VIRTUALEDIT
curwin->w_cursor.coladd = coladd;
#endif
 
/* Make sure the cursor is in a valid position. */
check_cursor();
#ifdef FEAT_MBYTE
/* Correct cursor for multi-byte character. */
if (has_mbyte)
mb_adjust_cursor();
#endif
 
curwin->w_set_curswant = TRUE;
}
 
/*
* "deepcopy()" function
*/
static void
f_deepcopy(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
int noref = 0;
 
if (argvars[1].v_type != VAR_UNKNOWN)
noref = get_tv_number_chk(&argvars[1], NULL);
if (noref < 0 || noref > 1)
EMSG(_(e_invarg));
else
item_copy(&argvars[0], rettv, TRUE, noref == 0 ? ++current_copyID : 0);
}
 
/*
* "delete()" function
*/
static void
f_delete(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
if (check_restricted() || check_secure())
rettv->vval.v_number = -1;
else
rettv->vval.v_number = mch_remove(get_tv_string(&argvars[0]));
}
 
/*
* "did_filetype()" function
*/
/*ARGSUSED*/
static void
f_did_filetype(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_AUTOCMD
rettv->vval.v_number = did_filetype;
#else
rettv->vval.v_number = 0;
#endif
}
 
/*
* "diff_filler()" function
*/
/*ARGSUSED*/
static void
f_diff_filler(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_DIFF
rettv->vval.v_number = diff_check_fill(curwin, get_tv_lnum(argvars));
#endif
}
 
/*
* "diff_hlID()" function
*/
/*ARGSUSED*/
static void
f_diff_hlID(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_DIFF
linenr_T lnum = get_tv_lnum(argvars);
static linenr_T prev_lnum = 0;
static int changedtick = 0;
static int fnum = 0;
static int change_start = 0;
static int change_end = 0;
static hlf_T hlID = 0;
int filler_lines;
int col;
 
if (lnum < 0) /* ignore type error in {lnum} arg */
lnum = 0;
if (lnum != prev_lnum
|| changedtick != curbuf->b_changedtick
|| fnum != curbuf->b_fnum)
{
/* New line, buffer, change: need to get the values. */
filler_lines = diff_check(curwin, lnum);
if (filler_lines < 0)
{
if (filler_lines == -1)
{
change_start = MAXCOL;
change_end = -1;
if (diff_find_change(curwin, lnum, &change_start, &change_end))
hlID = HLF_ADD; /* added line */
else
hlID = HLF_CHD; /* changed line */
}
else
hlID = HLF_ADD; /* added line */
}
else
hlID = (hlf_T)0;
prev_lnum = lnum;
changedtick = curbuf->b_changedtick;
fnum = curbuf->b_fnum;
}
 
if (hlID == HLF_CHD || hlID == HLF_TXD)
{
col = get_tv_number(&argvars[1]) - 1; /* ignore type error in {col} */
if (col >= change_start && col <= change_end)
hlID = HLF_TXD; /* changed text */
else
hlID = HLF_CHD; /* changed line */
}
rettv->vval.v_number = hlID == (hlf_T)0 ? 0 : (int)hlID;
#endif
}
 
/*
* "empty({expr})" function
*/
static void
f_empty(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
int n;
 
switch (argvars[0].v_type)
{
case VAR_STRING:
case VAR_FUNC:
n = argvars[0].vval.v_string == NULL
|| *argvars[0].vval.v_string == NUL;
break;
case VAR_NUMBER:
n = argvars[0].vval.v_number == 0;
break;
case VAR_LIST:
n = argvars[0].vval.v_list == NULL
|| argvars[0].vval.v_list->lv_first == NULL;
break;
case VAR_DICT:
n = argvars[0].vval.v_dict == NULL
|| argvars[0].vval.v_dict->dv_hashtab.ht_used == 0;
break;
default:
EMSG2(_(e_intern2), "f_empty()");
n = 0;
}
 
rettv->vval.v_number = n;
}
 
/*
* "escape({string}, {chars})" function
*/
static void
f_escape(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u buf[NUMBUFLEN];
 
rettv->vval.v_string = vim_strsave_escaped(get_tv_string(&argvars[0]),
get_tv_string_buf(&argvars[1], buf));
rettv->v_type = VAR_STRING;
}
 
/*
* "eval()" function
*/
/*ARGSUSED*/
static void
f_eval(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *s;
 
s = get_tv_string_chk(&argvars[0]);
if (s != NULL)
s = skipwhite(s);
 
if (s == NULL || eval1(&s, rettv, TRUE) == FAIL)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
}
else if (*s != NUL)
EMSG(_(e_trailing));
}
 
/*
* "eventhandler()" function
*/
/*ARGSUSED*/
static void
f_eventhandler(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = vgetc_busy;
}
 
/*
* "executable()" function
*/
static void
f_executable(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = mch_can_exe(get_tv_string(&argvars[0]));
}
 
/*
* "exists()" function
*/
static void
f_exists(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *p;
char_u *name;
int n = FALSE;
int len = 0;
 
p = get_tv_string(&argvars[0]);
if (*p == '$') /* environment variable */
{
/* first try "normal" environment variables (fast) */
if (mch_getenv(p + 1) != NULL)
n = TRUE;
else
{
/* try expanding things like $VIM and ${HOME} */
p = expand_env_save(p);
if (p != NULL && *p != '$')
n = TRUE;
vim_free(p);
}
}
else if (*p == '&' || *p == '+') /* option */
{
n = (get_option_tv(&p, NULL, TRUE) == OK);
if (*skipwhite(p) != NUL)
n = FALSE; /* trailing garbage */
}
else if (*p == '*') /* internal or user defined function */
{
n = function_exists(p + 1);
}
else if (*p == ':')
{
n = cmd_exists(p + 1);
}
else if (*p == '#')
{
#ifdef FEAT_AUTOCMD
if (p[1] == '#')
n = autocmd_supported(p + 2);
else
n = au_exists(p + 1);
#endif
}
else /* internal variable */
{
char_u *tofree;
typval_T tv;
 
/* get_name_len() takes care of expanding curly braces */
name = p;
len = get_name_len(&p, &tofree, TRUE, FALSE);
if (len > 0)
{
if (tofree != NULL)
name = tofree;
n = (get_var_tv(name, len, &tv, FALSE) == OK);
if (n)
{
/* handle d.key, l[idx], f(expr) */
n = (handle_subscript(&p, &tv, TRUE, FALSE) == OK);
if (n)
clear_tv(&tv);
}
}
if (*p != NUL)
n = FALSE;
 
vim_free(tofree);
}
 
rettv->vval.v_number = n;
}
 
/*
* "expand()" function
*/
static void
f_expand(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *s;
int len;
char_u *errormsg;
int flags = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND;
expand_T xpc;
int error = FALSE;
 
rettv->v_type = VAR_STRING;
s = get_tv_string(&argvars[0]);
if (*s == '%' || *s == '#' || *s == '<')
{
++emsg_off;
rettv->vval.v_string = eval_vars(s, s, &len, NULL, &errormsg, NULL);
--emsg_off;
}
else
{
/* When the optional second argument is non-zero, don't remove matches
* for 'suffixes' and 'wildignore' */
if (argvars[1].v_type != VAR_UNKNOWN
&& get_tv_number_chk(&argvars[1], &error))
flags |= WILD_KEEP_ALL;
if (!error)
{
ExpandInit(&xpc);
xpc.xp_context = EXPAND_FILES;
rettv->vval.v_string = ExpandOne(&xpc, s, NULL, flags, WILD_ALL);
}
else
rettv->vval.v_string = NULL;
}
}
 
/*
* "extend(list, list [, idx])" function
* "extend(dict, dict [, action])" function
*/
static void
f_extend(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = 0;
if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_LIST)
{
list_T *l1, *l2;
listitem_T *item;
long before;
int error = FALSE;
 
l1 = argvars[0].vval.v_list;
l2 = argvars[1].vval.v_list;
if (l1 != NULL && !tv_check_lock(l1->lv_lock, (char_u *)"extend()")
&& l2 != NULL)
{
if (argvars[2].v_type != VAR_UNKNOWN)
{
before = get_tv_number_chk(&argvars[2], &error);
if (error)
return; /* type error; errmsg already given */
 
if (before == l1->lv_len)
item = NULL;
else
{
item = list_find(l1, before);
if (item == NULL)
{
EMSGN(_(e_listidx), before);
return;
}
}
}
else
item = NULL;
list_extend(l1, l2, item);
 
copy_tv(&argvars[0], rettv);
}
}
else if (argvars[0].v_type == VAR_DICT && argvars[1].v_type == VAR_DICT)
{
dict_T *d1, *d2;
dictitem_T *di1;
char_u *action;
int i;
hashitem_T *hi2;
int todo;
 
d1 = argvars[0].vval.v_dict;
d2 = argvars[1].vval.v_dict;
if (d1 != NULL && !tv_check_lock(d1->dv_lock, (char_u *)"extend()")
&& d2 != NULL)
{
/* Check the third argument. */
if (argvars[2].v_type != VAR_UNKNOWN)
{
static char *(av[]) = {"keep", "force", "error"};
 
action = get_tv_string_chk(&argvars[2]);
if (action == NULL)
return; /* type error; errmsg already given */
for (i = 0; i < 3; ++i)
if (STRCMP(action, av[i]) == 0)
break;
if (i == 3)
{
EMSG2(_(e_invarg2), action);
return;
}
}
else
action = (char_u *)"force";
 
/* Go over all entries in the second dict and add them to the
* first dict. */
todo = (int)d2->dv_hashtab.ht_used;
for (hi2 = d2->dv_hashtab.ht_array; todo > 0; ++hi2)
{
if (!HASHITEM_EMPTY(hi2))
{
--todo;
di1 = dict_find(d1, hi2->hi_key, -1);
if (di1 == NULL)
{
di1 = dictitem_copy(HI2DI(hi2));
if (di1 != NULL && dict_add(d1, di1) == FAIL)
dictitem_free(di1);
}
else if (*action == 'e')
{
EMSG2(_("E737: Key already exists: %s"), hi2->hi_key);
break;
}
else if (*action == 'f')
{
clear_tv(&di1->di_tv);
copy_tv(&HI2DI(hi2)->di_tv, &di1->di_tv);
}
}
}
 
copy_tv(&argvars[0], rettv);
}
}
else
EMSG2(_(e_listdictarg), "extend()");
}
 
/*
* "feedkeys()" function
*/
/*ARGSUSED*/
static void
f_feedkeys(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
int remap = TRUE;
char_u *keys, *flags;
char_u nbuf[NUMBUFLEN];
int typed = FALSE;
char_u *keys_esc;
 
/* This is not allowed in the sandbox. If the commands would still be
* executed in the sandbox it would be OK, but it probably happens later,
* when "sandbox" is no longer set. */
if (check_secure())
return;
 
rettv->vval.v_number = 0;
keys = get_tv_string(&argvars[0]);
if (*keys != NUL)
{
if (argvars[1].v_type != VAR_UNKNOWN)
{
flags = get_tv_string_buf(&argvars[1], nbuf);
for ( ; *flags != NUL; ++flags)
{
switch (*flags)
{
case 'n': remap = FALSE; break;
case 'm': remap = TRUE; break;
case 't': typed = TRUE; break;
}
}
}
 
/* Need to escape K_SPECIAL and CSI before putting the string in the
* typeahead buffer. */
keys_esc = vim_strsave_escape_csi(keys);
if (keys_esc != NULL)
{
ins_typebuf(keys_esc, (remap ? REMAP_YES : REMAP_NONE),
typebuf.tb_len, !typed, FALSE);
vim_free(keys_esc);
if (vgetc_busy)
typebuf_was_filled = TRUE;
}
}
}
 
/*
* "filereadable()" function
*/
static void
f_filereadable(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
FILE *fd;
char_u *p;
int n;
 
p = get_tv_string(&argvars[0]);
if (*p && !mch_isdir(p) && (fd = mch_fopen((char *)p, "r")) != NULL)
{
n = TRUE;
fclose(fd);
}
else
n = FALSE;
 
rettv->vval.v_number = n;
}
 
/*
* Return 0 for not writable, 1 for writable file, 2 for a dir which we have
* rights to write into.
*/
static void
f_filewritable(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = filewritable(get_tv_string(&argvars[0]));
}
 
static void findfilendir __ARGS((typval_T *argvars, typval_T *rettv, int dir));
 
static void
findfilendir(argvars, rettv, dir)
typval_T *argvars;
typval_T *rettv;
int dir;
{
#ifdef FEAT_SEARCHPATH
char_u *fname;
char_u *fresult = NULL;
char_u *path = *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path;
char_u *p;
char_u pathbuf[NUMBUFLEN];
int count = 1;
int first = TRUE;
int error = FALSE;
#endif
 
rettv->vval.v_string = NULL;
rettv->v_type = VAR_STRING;
 
#ifdef FEAT_SEARCHPATH
fname = get_tv_string(&argvars[0]);
 
if (argvars[1].v_type != VAR_UNKNOWN)
{
p = get_tv_string_buf_chk(&argvars[1], pathbuf);
if (p == NULL)
error = TRUE;
else
{
if (*p != NUL)
path = p;
 
if (argvars[2].v_type != VAR_UNKNOWN)
count = get_tv_number_chk(&argvars[2], &error);
}
}
 
if (count < 0 && rettv_list_alloc(rettv) == FAIL)
error = TRUE;
 
if (*fname != NUL && !error)
{
do
{
if (rettv->v_type == VAR_STRING)
vim_free(fresult);
fresult = find_file_in_path_option(first ? fname : NULL,
first ? (int)STRLEN(fname) : 0,
0, first, path, dir, curbuf->b_ffname,
dir ? (char_u *)"" : curbuf->b_p_sua);
first = FALSE;
 
if (fresult != NULL && rettv->v_type == VAR_LIST)
list_append_string(rettv->vval.v_list, fresult, -1);
 
} while ((rettv->v_type == VAR_LIST || --count > 0) && fresult != NULL);
}
 
if (rettv->v_type == VAR_STRING)
rettv->vval.v_string = fresult;
#endif
}
 
static void filter_map __ARGS((typval_T *argvars, typval_T *rettv, int map));
static int filter_map_one __ARGS((typval_T *tv, char_u *expr, int map, int *remp));
 
/*
* Implementation of map() and filter().
*/
static void
filter_map(argvars, rettv, map)
typval_T *argvars;
typval_T *rettv;
int map;
{
char_u buf[NUMBUFLEN];
char_u *expr;
listitem_T *li, *nli;
list_T *l = NULL;
dictitem_T *di;
hashtab_T *ht;
hashitem_T *hi;
dict_T *d = NULL;
typval_T save_val;
typval_T save_key;
int rem;
int todo;
char_u *ermsg = map ? (char_u *)"map()" : (char_u *)"filter()";
int save_did_emsg;
 
rettv->vval.v_number = 0;
if (argvars[0].v_type == VAR_LIST)
{
if ((l = argvars[0].vval.v_list) == NULL
|| (map && tv_check_lock(l->lv_lock, ermsg)))
return;
}
else if (argvars[0].v_type == VAR_DICT)
{
if ((d = argvars[0].vval.v_dict) == NULL
|| (map && tv_check_lock(d->dv_lock, ermsg)))
return;
}
else
{
EMSG2(_(e_listdictarg), ermsg);
return;
}
 
expr = get_tv_string_buf_chk(&argvars[1], buf);
/* On type errors, the preceding call has already displayed an error
* message. Avoid a misleading error message for an empty string that
* was not passed as argument. */
if (expr != NULL)
{
prepare_vimvar(VV_VAL, &save_val);
expr = skipwhite(expr);
 
/* We reset "did_emsg" to be able to detect whether an error
* occurred during evaluation of the expression. */
save_did_emsg = did_emsg;
did_emsg = FALSE;
 
if (argvars[0].v_type == VAR_DICT)
{
prepare_vimvar(VV_KEY, &save_key);
vimvars[VV_KEY].vv_type = VAR_STRING;
 
ht = &d->dv_hashtab;
hash_lock(ht);
todo = (int)ht->ht_used;
for (hi = ht->ht_array; todo > 0; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
di = HI2DI(hi);
if (tv_check_lock(di->di_tv.v_lock, ermsg))
break;
vimvars[VV_KEY].vv_str = vim_strsave(di->di_key);
if (filter_map_one(&di->di_tv, expr, map, &rem) == FAIL
|| did_emsg)
break;
if (!map && rem)
dictitem_remove(d, di);
clear_tv(&vimvars[VV_KEY].vv_tv);
}
}
hash_unlock(ht);
 
restore_vimvar(VV_KEY, &save_key);
}
else
{
for (li = l->lv_first; li != NULL; li = nli)
{
if (tv_check_lock(li->li_tv.v_lock, ermsg))
break;
nli = li->li_next;
if (filter_map_one(&li->li_tv, expr, map, &rem) == FAIL
|| did_emsg)
break;
if (!map && rem)
listitem_remove(l, li);
}
}
 
restore_vimvar(VV_VAL, &save_val);
 
did_emsg |= save_did_emsg;
}
 
copy_tv(&argvars[0], rettv);
}
 
static int
filter_map_one(tv, expr, map, remp)
typval_T *tv;
char_u *expr;
int map;
int *remp;
{
typval_T rettv;
char_u *s;
 
copy_tv(tv, &vimvars[VV_VAL].vv_tv);
s = expr;
if (eval1(&s, &rettv, TRUE) == FAIL)
return FAIL;
if (*s != NUL) /* check for trailing chars after expr */
{
EMSG2(_(e_invexpr2), s);
return FAIL;
}
if (map)
{
/* map(): replace the list item value */
clear_tv(tv);
rettv.v_lock = 0;
*tv = rettv;
}
else
{
int error = FALSE;
 
/* filter(): when expr is zero remove the item */
*remp = (get_tv_number_chk(&rettv, &error) == 0);
clear_tv(&rettv);
/* On type error, nothing has been removed; return FAIL to stop the
* loop. The error message was given by get_tv_number_chk(). */
if (error)
return FAIL;
}
clear_tv(&vimvars[VV_VAL].vv_tv);
return OK;
}
 
/*
* "filter()" function
*/
static void
f_filter(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
filter_map(argvars, rettv, FALSE);
}
 
/*
* "finddir({fname}[, {path}[, {count}]])" function
*/
static void
f_finddir(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
findfilendir(argvars, rettv, TRUE);
}
 
/*
* "findfile({fname}[, {path}[, {count}]])" function
*/
static void
f_findfile(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
findfilendir(argvars, rettv, FALSE);
}
 
/*
* "fnamemodify({fname}, {mods})" function
*/
static void
f_fnamemodify(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *fname;
char_u *mods;
int usedlen = 0;
int len;
char_u *fbuf = NULL;
char_u buf[NUMBUFLEN];
 
fname = get_tv_string_chk(&argvars[0]);
mods = get_tv_string_buf_chk(&argvars[1], buf);
if (fname == NULL || mods == NULL)
fname = NULL;
else
{
len = (int)STRLEN(fname);
(void)modify_fname(mods, &usedlen, &fname, &fbuf, &len);
}
 
rettv->v_type = VAR_STRING;
if (fname == NULL)
rettv->vval.v_string = NULL;
else
rettv->vval.v_string = vim_strnsave(fname, len);
vim_free(fbuf);
}
 
static void foldclosed_both __ARGS((typval_T *argvars, typval_T *rettv, int end));
 
/*
* "foldclosed()" function
*/
static void
foldclosed_both(argvars, rettv, end)
typval_T *argvars;
typval_T *rettv;
int end;
{
#ifdef FEAT_FOLDING
linenr_T lnum;
linenr_T first, last;
 
lnum = get_tv_lnum(argvars);
if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
{
if (hasFoldingWin(curwin, lnum, &first, &last, FALSE, NULL))
{
if (end)
rettv->vval.v_number = (varnumber_T)last;
else
rettv->vval.v_number = (varnumber_T)first;
return;
}
}
#endif
rettv->vval.v_number = -1;
}
 
/*
* "foldclosed()" function
*/
static void
f_foldclosed(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
foldclosed_both(argvars, rettv, FALSE);
}
 
/*
* "foldclosedend()" function
*/
static void
f_foldclosedend(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
foldclosed_both(argvars, rettv, TRUE);
}
 
/*
* "foldlevel()" function
*/
static void
f_foldlevel(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_FOLDING
linenr_T lnum;
 
lnum = get_tv_lnum(argvars);
if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
rettv->vval.v_number = foldLevel(lnum);
else
#endif
rettv->vval.v_number = 0;
}
 
/*
* "foldtext()" function
*/
/*ARGSUSED*/
static void
f_foldtext(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_FOLDING
linenr_T lnum;
char_u *s;
char_u *r;
int len;
char *txt;
#endif
 
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
#ifdef FEAT_FOLDING
if ((linenr_T)vimvars[VV_FOLDSTART].vv_nr > 0
&& (linenr_T)vimvars[VV_FOLDEND].vv_nr
<= curbuf->b_ml.ml_line_count
&& vimvars[VV_FOLDDASHES].vv_str != NULL)
{
/* Find first non-empty line in the fold. */
lnum = (linenr_T)vimvars[VV_FOLDSTART].vv_nr;
while (lnum < (linenr_T)vimvars[VV_FOLDEND].vv_nr)
{
if (!linewhite(lnum))
break;
++lnum;
}
 
/* Find interesting text in this line. */
s = skipwhite(ml_get(lnum));
/* skip C comment-start */
if (s[0] == '/' && (s[1] == '*' || s[1] == '/'))
{
s = skipwhite(s + 2);
if (*skipwhite(s) == NUL
&& lnum + 1 < (linenr_T)vimvars[VV_FOLDEND].vv_nr)
{
s = skipwhite(ml_get(lnum + 1));
if (*s == '*')
s = skipwhite(s + 1);
}
}
txt = _("+-%s%3ld lines: ");
r = alloc((unsigned)(STRLEN(txt)
+ STRLEN(vimvars[VV_FOLDDASHES].vv_str) /* for %s */
+ 20 /* for %3ld */
+ STRLEN(s))); /* concatenated */
if (r != NULL)
{
sprintf((char *)r, txt, vimvars[VV_FOLDDASHES].vv_str,
(long)((linenr_T)vimvars[VV_FOLDEND].vv_nr
- (linenr_T)vimvars[VV_FOLDSTART].vv_nr + 1));
len = (int)STRLEN(r);
STRCAT(r, s);
/* remove 'foldmarker' and 'commentstring' */
foldtext_cleanup(r + len);
rettv->vval.v_string = r;
}
}
#endif
}
 
/*
* "foldtextresult(lnum)" function
*/
/*ARGSUSED*/
static void
f_foldtextresult(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_FOLDING
linenr_T lnum;
char_u *text;
char_u buf[51];
foldinfo_T foldinfo;
int fold_count;
#endif
 
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
#ifdef FEAT_FOLDING
lnum = get_tv_lnum(argvars);
/* treat illegal types and illegal string values for {lnum} the same */
if (lnum < 0)
lnum = 0;
fold_count = foldedCount(curwin, lnum, &foldinfo);
if (fold_count > 0)
{
text = get_foldtext(curwin, lnum, lnum + fold_count - 1,
&foldinfo, buf);
if (text == buf)
text = vim_strsave(text);
rettv->vval.v_string = text;
}
#endif
}
 
/*
* "foreground()" function
*/
/*ARGSUSED*/
static void
f_foreground(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = 0;
#ifdef FEAT_GUI
if (gui.in_use)
gui_mch_set_foreground();
#else
# ifdef WIN32
win32_set_foreground();
# endif
#endif
}
 
/*
* "function()" function
*/
/*ARGSUSED*/
static void
f_function(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *s;
 
rettv->vval.v_number = 0;
s = get_tv_string(&argvars[0]);
if (s == NULL || *s == NUL || VIM_ISDIGIT(*s))
EMSG2(_(e_invarg2), s);
else if (!function_exists(s))
EMSG2(_("E700: Unknown function: %s"), s);
else
{
rettv->vval.v_string = vim_strsave(s);
rettv->v_type = VAR_FUNC;
}
}
 
/*
* "garbagecollect()" function
*/
/*ARGSUSED*/
static void
f_garbagecollect(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
/* This is postponed until we are back at the toplevel, because we may be
* using Lists and Dicts internally. E.g.: ":echo [garbagecollect()]". */
want_garbage_collect = TRUE;
}
 
/*
* "get()" function
*/
static void
f_get(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
listitem_T *li;
list_T *l;
dictitem_T *di;
dict_T *d;
typval_T *tv = NULL;
 
if (argvars[0].v_type == VAR_LIST)
{
if ((l = argvars[0].vval.v_list) != NULL)
{
int error = FALSE;
 
li = list_find(l, get_tv_number_chk(&argvars[1], &error));
if (!error && li != NULL)
tv = &li->li_tv;
}
}
else if (argvars[0].v_type == VAR_DICT)
{
if ((d = argvars[0].vval.v_dict) != NULL)
{
di = dict_find(d, get_tv_string(&argvars[1]), -1);
if (di != NULL)
tv = &di->di_tv;
}
}
else
EMSG2(_(e_listdictarg), "get()");
 
if (tv == NULL)
{
if (argvars[2].v_type == VAR_UNKNOWN)
rettv->vval.v_number = 0;
else
copy_tv(&argvars[2], rettv);
}
else
copy_tv(tv, rettv);
}
 
static void get_buffer_lines __ARGS((buf_T *buf, linenr_T start, linenr_T end, int retlist, typval_T *rettv));
 
/*
* Get line or list of lines from buffer "buf" into "rettv".
* Return a range (from start to end) of lines in rettv from the specified
* buffer.
* If 'retlist' is TRUE, then the lines are returned as a Vim List.
*/
static void
get_buffer_lines(buf, start, end, retlist, rettv)
buf_T *buf;
linenr_T start;
linenr_T end;
int retlist;
typval_T *rettv;
{
char_u *p;
 
if (retlist)
{
if (rettv_list_alloc(rettv) == FAIL)
return;
}
else
rettv->vval.v_number = 0;
 
if (buf == NULL || buf->b_ml.ml_mfp == NULL || start < 0)
return;
 
if (!retlist)
{
if (start >= 1 && start <= buf->b_ml.ml_line_count)
p = ml_get_buf(buf, start, FALSE);
else
p = (char_u *)"";
 
rettv->v_type = VAR_STRING;
rettv->vval.v_string = vim_strsave(p);
}
else
{
if (end < start)
return;
 
if (start < 1)
start = 1;
if (end > buf->b_ml.ml_line_count)
end = buf->b_ml.ml_line_count;
while (start <= end)
if (list_append_string(rettv->vval.v_list,
ml_get_buf(buf, start++, FALSE), -1) == FAIL)
break;
}
}
 
/*
* "getbufline()" function
*/
static void
f_getbufline(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
linenr_T lnum;
linenr_T end;
buf_T *buf;
 
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
++emsg_off;
buf = get_buf_tv(&argvars[0]);
--emsg_off;
 
lnum = get_tv_lnum_buf(&argvars[1], buf);
if (argvars[2].v_type == VAR_UNKNOWN)
end = lnum;
else
end = get_tv_lnum_buf(&argvars[2], buf);
 
get_buffer_lines(buf, lnum, end, TRUE, rettv);
}
 
/*
* "getbufvar()" function
*/
static void
f_getbufvar(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
buf_T *buf;
buf_T *save_curbuf;
char_u *varname;
dictitem_T *v;
 
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
varname = get_tv_string_chk(&argvars[1]);
++emsg_off;
buf = get_buf_tv(&argvars[0]);
 
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
 
if (buf != NULL && varname != NULL)
{
if (*varname == '&') /* buffer-local-option */
{
/* set curbuf to be our buf, temporarily */
save_curbuf = curbuf;
curbuf = buf;
 
get_option_tv(&varname, rettv, TRUE);
 
/* restore previous notion of curbuf */
curbuf = save_curbuf;
}
else
{
if (*varname == NUL)
/* let getbufvar({nr}, "") return the "b:" dictionary. The
* scope prefix before the NUL byte is required by
* find_var_in_ht(). */
varname = (char_u *)"b:" + 2;
/* look up the variable */
v = find_var_in_ht(&buf->b_vars.dv_hashtab, varname, FALSE);
if (v != NULL)
copy_tv(&v->di_tv, rettv);
}
}
 
--emsg_off;
}
 
/*
* "getchar()" function
*/
static void
f_getchar(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
varnumber_T n;
int error = FALSE;
 
/* Position the cursor. Needed after a message that ends in a space. */
windgoto(msg_row, msg_col);
 
++no_mapping;
++allow_keys;
if (argvars[0].v_type == VAR_UNKNOWN)
/* getchar(): blocking wait. */
n = safe_vgetc();
else if (get_tv_number_chk(&argvars[0], &error) == 1)
/* getchar(1): only check if char avail */
n = vpeekc();
else if (error || vpeekc() == NUL)
/* illegal argument or getchar(0) and no char avail: return zero */
n = 0;
else
/* getchar(0) and char avail: return char */
n = safe_vgetc();
--no_mapping;
--allow_keys;
 
vimvars[VV_MOUSE_WIN].vv_nr = 0;
vimvars[VV_MOUSE_LNUM].vv_nr = 0;
vimvars[VV_MOUSE_COL].vv_nr = 0;
 
rettv->vval.v_number = n;
if (IS_SPECIAL(n) || mod_mask != 0)
{
char_u temp[10]; /* modifier: 3, mbyte-char: 6, NUL: 1 */
int i = 0;
 
/* Turn a special key into three bytes, plus modifier. */
if (mod_mask != 0)
{
temp[i++] = K_SPECIAL;
temp[i++] = KS_MODIFIER;
temp[i++] = mod_mask;
}
if (IS_SPECIAL(n))
{
temp[i++] = K_SPECIAL;
temp[i++] = K_SECOND(n);
temp[i++] = K_THIRD(n);
}
#ifdef FEAT_MBYTE
else if (has_mbyte)
i += (*mb_char2bytes)(n, temp + i);
#endif
else
temp[i++] = n;
temp[i++] = NUL;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = vim_strsave(temp);
 
#ifdef FEAT_MOUSE
if (n == K_LEFTMOUSE
|| n == K_LEFTMOUSE_NM
|| n == K_LEFTDRAG
|| n == K_LEFTRELEASE
|| n == K_LEFTRELEASE_NM
|| n == K_MIDDLEMOUSE
|| n == K_MIDDLEDRAG
|| n == K_MIDDLERELEASE
|| n == K_RIGHTMOUSE
|| n == K_RIGHTDRAG
|| n == K_RIGHTRELEASE
|| n == K_X1MOUSE
|| n == K_X1DRAG
|| n == K_X1RELEASE
|| n == K_X2MOUSE
|| n == K_X2DRAG
|| n == K_X2RELEASE
|| n == K_MOUSEDOWN
|| n == K_MOUSEUP)
{
int row = mouse_row;
int col = mouse_col;
win_T *win;
linenr_T lnum;
# ifdef FEAT_WINDOWS
win_T *wp;
# endif
int n = 1;
 
if (row >= 0 && col >= 0)
{
/* Find the window at the mouse coordinates and compute the
* text position. */
win = mouse_find_win(&row, &col);
(void)mouse_comp_pos(win, &row, &col, &lnum);
# ifdef FEAT_WINDOWS
for (wp = firstwin; wp != win; wp = wp->w_next)
++n;
# endif
vimvars[VV_MOUSE_WIN].vv_nr = n;
vimvars[VV_MOUSE_LNUM].vv_nr = lnum;
vimvars[VV_MOUSE_COL].vv_nr = col + 1;
}
}
#endif
}
}
 
/*
* "getcharmod()" function
*/
/*ARGSUSED*/
static void
f_getcharmod(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = mod_mask;
}
 
/*
* "getcmdline()" function
*/
/*ARGSUSED*/
static void
f_getcmdline(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = get_cmdline_str();
}
 
/*
* "getcmdpos()" function
*/
/*ARGSUSED*/
static void
f_getcmdpos(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = get_cmdline_pos() + 1;
}
 
/*
* "getcmdtype()" function
*/
/*ARGSUSED*/
static void
f_getcmdtype(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = alloc(2);
if (rettv->vval.v_string != NULL)
{
rettv->vval.v_string[0] = get_cmdline_type();
rettv->vval.v_string[1] = NUL;
}
}
 
/*
* "getcwd()" function
*/
/*ARGSUSED*/
static void
f_getcwd(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u cwd[MAXPATHL];
 
rettv->v_type = VAR_STRING;
if (mch_dirname(cwd, MAXPATHL) == FAIL)
rettv->vval.v_string = NULL;
else
{
rettv->vval.v_string = vim_strsave(cwd);
#ifdef BACKSLASH_IN_FILENAME
if (rettv->vval.v_string != NULL)
slash_adjust(rettv->vval.v_string);
#endif
}
}
 
/*
* "getfontname()" function
*/
/*ARGSUSED*/
static void
f_getfontname(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
#ifdef FEAT_GUI
if (gui.in_use)
{
GuiFont font;
char_u *name = NULL;
 
if (argvars[0].v_type == VAR_UNKNOWN)
{
/* Get the "Normal" font. Either the name saved by
* hl_set_font_name() or from the font ID. */
font = gui.norm_font;
name = hl_get_font_name();
}
else
{
name = get_tv_string(&argvars[0]);
if (STRCMP(name, "*") == 0) /* don't use font dialog */
return;
font = gui_mch_get_font(name, FALSE);
if (font == NOFONT)
return; /* Invalid font name, return empty string. */
}
rettv->vval.v_string = gui_mch_get_fontname(font, name);
if (argvars[0].v_type != VAR_UNKNOWN)
gui_mch_free_font(font);
}
#endif
}
 
/*
* "getfperm({fname})" function
*/
static void
f_getfperm(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *fname;
struct stat st;
char_u *perm = NULL;
char_u flags[] = "rwx";
int i;
 
fname = get_tv_string(&argvars[0]);
 
rettv->v_type = VAR_STRING;
if (mch_stat((char *)fname, &st) >= 0)
{
perm = vim_strsave((char_u *)"---------");
if (perm != NULL)
{
for (i = 0; i < 9; i++)
{
if (st.st_mode & (1 << (8 - i)))
perm[i] = flags[i % 3];
}
}
}
rettv->vval.v_string = perm;
}
 
/*
* "getfsize({fname})" function
*/
static void
f_getfsize(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *fname;
struct stat st;
 
fname = get_tv_string(&argvars[0]);
 
rettv->v_type = VAR_NUMBER;
 
if (mch_stat((char *)fname, &st) >= 0)
{
if (mch_isdir(fname))
rettv->vval.v_number = 0;
else
rettv->vval.v_number = (varnumber_T)st.st_size;
}
else
rettv->vval.v_number = -1;
}
 
/*
* "getftime({fname})" function
*/
static void
f_getftime(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *fname;
struct stat st;
 
fname = get_tv_string(&argvars[0]);
 
if (mch_stat((char *)fname, &st) >= 0)
rettv->vval.v_number = (varnumber_T)st.st_mtime;
else
rettv->vval.v_number = -1;
}
 
/*
* "getftype({fname})" function
*/
static void
f_getftype(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *fname;
struct stat st;
char_u *type = NULL;
char *t;
 
fname = get_tv_string(&argvars[0]);
 
rettv->v_type = VAR_STRING;
if (mch_lstat((char *)fname, &st) >= 0)
{
#ifdef S_ISREG
if (S_ISREG(st.st_mode))
t = "file";
else if (S_ISDIR(st.st_mode))
t = "dir";
# ifdef S_ISLNK
else if (S_ISLNK(st.st_mode))
t = "link";
# endif
# ifdef S_ISBLK
else if (S_ISBLK(st.st_mode))
t = "bdev";
# endif
# ifdef S_ISCHR
else if (S_ISCHR(st.st_mode))
t = "cdev";
# endif
# ifdef S_ISFIFO
else if (S_ISFIFO(st.st_mode))
t = "fifo";
# endif
# ifdef S_ISSOCK
else if (S_ISSOCK(st.st_mode))
t = "fifo";
# endif
else
t = "other";
#else
# ifdef S_IFMT
switch (st.st_mode & S_IFMT)
{
case S_IFREG: t = "file"; break;
case S_IFDIR: t = "dir"; break;
# ifdef S_IFLNK
case S_IFLNK: t = "link"; break;
# endif
# ifdef S_IFBLK
case S_IFBLK: t = "bdev"; break;
# endif
# ifdef S_IFCHR
case S_IFCHR: t = "cdev"; break;
# endif
# ifdef S_IFIFO
case S_IFIFO: t = "fifo"; break;
# endif
# ifdef S_IFSOCK
case S_IFSOCK: t = "socket"; break;
# endif
default: t = "other";
}
# else
if (mch_isdir(fname))
t = "dir";
else
t = "file";
# endif
#endif
type = vim_strsave((char_u *)t);
}
rettv->vval.v_string = type;
}
 
/*
* "getline(lnum, [end])" function
*/
static void
f_getline(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
linenr_T lnum;
linenr_T end;
int retlist;
 
lnum = get_tv_lnum(argvars);
if (argvars[1].v_type == VAR_UNKNOWN)
{
end = 0;
retlist = FALSE;
}
else
{
end = get_tv_lnum(&argvars[1]);
retlist = TRUE;
}
 
get_buffer_lines(curbuf, lnum, end, retlist, rettv);
}
 
/*
* "getpos(string)" function
*/
static void
f_getpos(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
pos_T *fp;
list_T *l;
int fnum = -1;
 
if (rettv_list_alloc(rettv) == OK)
{
l = rettv->vval.v_list;
fp = var2fpos(&argvars[0], TRUE, &fnum);
if (fnum != -1)
list_append_number(l, (varnumber_T)fnum);
else
list_append_number(l, (varnumber_T)0);
list_append_number(l, (fp != NULL) ? (varnumber_T)fp->lnum
: (varnumber_T)0);
list_append_number(l, (fp != NULL) ? (varnumber_T)fp->col + 1
: (varnumber_T)0);
list_append_number(l,
#ifdef FEAT_VIRTUALEDIT
(fp != NULL) ? (varnumber_T)fp->coladd :
#endif
(varnumber_T)0);
}
else
rettv->vval.v_number = FALSE;
}
 
/*
* "getqflist()" and "getloclist()" functions
*/
/*ARGSUSED*/
static void
f_getqflist(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
#ifdef FEAT_QUICKFIX
win_T *wp;
#endif
 
rettv->vval.v_number = 0;
#ifdef FEAT_QUICKFIX
if (rettv_list_alloc(rettv) == OK)
{
wp = NULL;
if (argvars[0].v_type != VAR_UNKNOWN) /* getloclist() */
{
wp = find_win_by_nr(&argvars[0], NULL);
if (wp == NULL)
return;
}
 
(void)get_errorlist(wp, rettv->vval.v_list);
}
#endif
}
 
/*
* "getreg()" function
*/
static void
f_getreg(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *strregname;
int regname;
int arg2 = FALSE;
int error = FALSE;
 
if (argvars[0].v_type != VAR_UNKNOWN)
{
strregname = get_tv_string_chk(&argvars[0]);
error = strregname == NULL;
if (argvars[1].v_type != VAR_UNKNOWN)
arg2 = get_tv_number_chk(&argvars[1], &error);
}
else
strregname = vimvars[VV_REG].vv_str;
regname = (strregname == NULL ? '"' : *strregname);
if (regname == 0)
regname = '"';
 
rettv->v_type = VAR_STRING;
rettv->vval.v_string = error ? NULL :
get_reg_contents(regname, TRUE, arg2);
}
 
/*
* "getregtype()" function
*/
static void
f_getregtype(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u *strregname;
int regname;
char_u buf[NUMBUFLEN + 2];
long reglen = 0;
 
if (argvars[0].v_type != VAR_UNKNOWN)
{
strregname = get_tv_string_chk(&argvars[0]);
if (strregname == NULL) /* type error; errmsg already given */
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
return;
}
}
else
/* Default to v:register */
strregname = vimvars[VV_REG].vv_str;
 
regname = (strregname == NULL ? '"' : *strregname);
if (regname == 0)
regname = '"';
 
buf[0] = NUL;
buf[1] = NUL;
switch (get_reg_type(regname, &reglen))
{
case MLINE: buf[0] = 'V'; break;
case MCHAR: buf[0] = 'v'; break;
#ifdef FEAT_VISUAL
case MBLOCK:
buf[0] = Ctrl_V;
sprintf((char *)buf + 1, "%ld", reglen + 1);
break;
#endif
}
rettv->v_type = VAR_STRING;
rettv->vval.v_string = vim_strsave(buf);
}
 
/*
* "gettabwinvar()" function
*/
static void
f_gettabwinvar(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
getwinvar(argvars, rettv, 1);
}
 
/*
* "getwinposx()" function
*/
/*ARGSUSED*/
static void
f_getwinposx(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = -1;
#ifdef FEAT_GUI
if (gui.in_use)
{
int x, y;
 
if (gui_mch_get_winpos(&x, &y) == OK)
rettv->vval.v_number = x;
}
#endif
}
 
/*
* "getwinposy()" function
*/
/*ARGSUSED*/
static void
f_getwinposy(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
rettv->vval.v_number = -1;
#ifdef FEAT_GUI
if (gui.in_use)
{
int x, y;
 
if (gui_mch_get_winpos(&x, &y) == OK)
rettv->vval.v_number = y;
}
#endif
}
 
/*
* Find window specifed by "vp" in tabpage "tp".
*/
static win_T *
find_win_by_nr(vp, tp)
typval_T *vp;
tabpage_T *tp; /* NULL for current tab page */
{
#ifdef FEAT_WINDOWS
win_T *wp;
#endif
int nr;
 
nr = get_tv_number_chk(vp, NULL);
 
#ifdef FEAT_WINDOWS
if (nr < 0)
return NULL;
if (nr == 0)
return curwin;
 
for (wp = (tp == NULL || tp == curtab) ? firstwin : tp->tp_firstwin;
wp != NULL; wp = wp->w_next)
if (--nr <= 0)
break;
return wp;
#else
if (nr == 0 || nr == 1)
return curwin;
return NULL;
#endif
}
 
/*
* "getwinvar()" function
*/
static void
f_getwinvar(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
getwinvar(argvars, rettv, 0);
}
 
/*
* getwinvar() and gettabwinvar()
*/
static void
getwinvar(argvars, rettv, off)
typval_T *argvars;
typval_T *rettv;
int off; /* 1 for gettabwinvar() */
{
win_T *win, *oldcurwin;
char_u *varname;
dictitem_T *v;
tabpage_T *tp;
 
#ifdef FEAT_WINDOWS
if (off == 1)
tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL));
else
tp = curtab;
#endif
win = find_win_by_nr(&argvars[off], tp);
varname = get_tv_string_chk(&argvars[off + 1]);
++emsg_off;
 
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
 
if (win != NULL && varname != NULL)
{
/* Set curwin to be our win, temporarily. Also set curbuf, so
* that we can get buffer-local options. */
oldcurwin = curwin;
curwin = win;
curbuf = win->w_buffer;
 
if (*varname == '&') /* window-local-option */
get_option_tv(&varname, rettv, 1);
else
{
if (*varname == NUL)
/* let getwinvar({nr}, "") return the "w:" dictionary. The
* scope prefix before the NUL byte is required by
* find_var_in_ht(). */
varname = (char_u *)"w:" + 2;
/* look up the variable */
v = find_var_in_ht(&win->w_vars.dv_hashtab, varname, FALSE);
if (v != NULL)
copy_tv(&v->di_tv, rettv);
}
 
/* restore previous notion of curwin */
curwin = oldcurwin;
curbuf = curwin->w_buffer;
}
 
--emsg_off;
}
 
/*
* "glob()" function
*/
static void
f_glob(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
expand_T xpc;
 
ExpandInit(&xpc);
xpc.xp_context = EXPAND_FILES;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]),
NULL, WILD_USE_NL|WILD_SILENT, WILD_ALL);
}
 
/*
* "globpath()" function
*/
static void
f_globpath(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
char_u buf1[NUMBUFLEN];
char_u *file = get_tv_string_buf_chk(&argvars[1], buf1);
 
rettv->v_type = VAR_STRING;
if (file == NULL)
rettv->vval.v_string = NULL;
else
rettv->vval.v_string = globpath(get_tv_string(&argvars[0]), file);
}
 
/*
* "has()" function
*/
static void
f_has(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
int i;
char_u *name;
int n = FALSE;
static char *(has_list[]) =
{
#ifdef AMIGA
"amiga",
# ifdef FEAT_ARP
"arp",
# endif
#endif
#ifdef __BEOS__
"beos",
#endif
#ifdef MSDOS
# ifdef DJGPP
"dos32",
# else
"dos16",
# endif
#endif
#ifdef MACOS
"mac",
#endif
#if defined(MACOS_X_UNIX)
"macunix",
#endif
#ifdef OS2
"os2",
#endif
#ifdef __QNX__
"qnx",
#endif
#ifdef RISCOS
"riscos",
#endif
#ifdef UNIX
"unix",
#endif
#ifdef VMS
"vms",
#endif
#ifdef WIN16
"win16",
#endif
#ifdef WIN32
"win32",
#endif
#if defined(UNIX) && (defined(__CYGWIN32__) || defined(__CYGWIN__))
"win32unix",
#endif
#ifdef WIN64
"win64",
#endif
#ifdef EBCDIC
"ebcdic",
#endif
#ifndef CASE_INSENSITIVE_FILENAME
"fname_case",
#endif
#ifdef FEAT_ARABIC
"arabic",
#endif
#ifdef FEAT_AUTOCMD
"autocmd",
#endif
#ifdef FEAT_BEVAL
"balloon_eval",
# ifndef FEAT_GUI_W32 /* other GUIs always have multiline balloons */
"balloon_multiline",