1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:10:04 +08:00

Add vimproc into bundle dir

This commit is contained in:
Shidong Wang 2020-06-14 23:42:40 +08:00
parent 87ef8b3ef5
commit a466c0d700
47 changed files with 8870 additions and 1 deletions

View File

@ -24,7 +24,7 @@ function! SpaceVim#layers#core#plugins() abort
\ 'merged' : 0,
\ 'loadconf' : 1
\ }])
call add(plugins, ['Shougo/vimproc.vim', {'build' : [(executable('gmake') ? 'gmake' : 'make')]}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/vimproc.vim', {'build' : [(executable('gmake') ? 'gmake' : 'make')]}])
elseif g:spacevim_filemanager ==# 'defx'
call add(plugins, [g:_spacevim_root_dir . 'bundle/defx.nvim',{'merged' : 0, 'loadconf' : 1 , 'loadconf_before' : 1}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/defx-git',{'merged' : 0, 'loadconf' : 1}])

1
bundle/vimproc.vim/.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.bat text eol=crlf

8
bundle/vimproc.vim/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
lib/*
doc/tags
*.obj
*.o
*.so
*.dll
*.swp
*~

View File

@ -0,0 +1,40 @@
matrix:
include:
- os: linux
env:
- VIM_VERSION=7.4
- os: linux
env:
- VIM_VERSION=8.0.0000
- os: linux
env:
- VIM_VERSION=8.1.0000
- os: linux
env:
- VIM_VERSION=8.2.0000
- os: osx
sudo: false
before_script:
- git clone https://github.com/thinca/vim-themis /tmp/vim-themis
- |
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
(if ! test -d $HOME/vim-$VIM_VERSION/bin; then
git clone https://github.com/vim/vim $HOME/vim &&
cd $HOME/vim &&
git checkout v$VIM_VERSION &&
./configure --prefix=$HOME/vim-$VIM_VERSION &&
make &&
make install;
fi)
fi
export PATH=$HOME/vim-$VIM_VERSION/bin:$PATH
cache:
directories:
- $HOME/vim-$VIM_VERSION
script:
- make
- vim --version
- /tmp/vim-themis/bin/themis

View File

@ -0,0 +1,70 @@
ifeq ($(OS),Windows_NT)
# Need to figure out if Cygwin/Mingw is installed
SYS := $(shell gcc -dumpmachine)
ifeq ($(findstring cygwin, $(SYS)),cygwin)
ifeq ($(findstring x86_64, $(SYS)),x86_64)
PLATFORM = cygwin64
else
PLATFORM = cygwin
endif
endif
ifeq ($(findstring msys, $(SYS)),msys)
ifeq ($(findstring x86_64, $(SYS)),x86_64)
PLATFORM = cygwin64
else
PLATFORM = cygwin
endif
endif
ifeq ($(findstring mingw, $(SYS)),mingw)
ifeq ($(findstring x86_64, $(SYS)),x86_64)
PLATFORM = mingw64
else
PLATFORM = mingw32
endif
endif
else
# Grab the output of `uname -s` and switch to set the platform
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
PLATFORM = unix
endif
ifeq ($(UNAME_S),GNU)
# GNU/Hurd
PLATFORM = unix
endif
ifeq ($(UNAME_S),FreeBSD)
MAKE = make # BSD Make
PLATFORM = bsd
endif
ifeq ($(UNAME_S),DragonFly)
MAKE = make # BSD Make
PLATFORM = bsd
endif
ifeq ($(UNAME_S),NetBSD)
MAKE = make # BSD Make
PLATFORM = bsd
endif
ifeq ($(UNAME_S),OpenBSD)
MAKE = make # BSD Make
PLATFORM = bsd
endif
ifeq ($(UNAME_S),Darwin)
PLATFORM = mac
endif
ifeq ($(UNAME_S),SunOS)
PLATFORM = sunos
endif
endif
# Verify that the PLATFORM was detected
ifndef PLATFORM
$(error Autodetection of platform failed, please use appropriate .mak file)
endif
# Invoke the platform specific make files
all:
$(MAKE) -f make_$(PLATFORM).mak
clean:
$(MAKE) -f make_$(PLATFORM).mak clean

View File

@ -0,0 +1,171 @@
# vimproc
[![Travis Build Status](https://travis-ci.org/Shougo/vimproc.vim.svg?branch=master)](https://travis-ci.org/Shougo/vimproc.vim)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/nutwxuj2poauar2b/branch/master?svg=true)](https://ci.appveyor.com/project/Shougo/vimproc-vim/branch/master)
[![GitHub release](https://img.shields.io/github/release/Shougo/vimproc.vim.svg)](https://github.com/Shougo/vimproc.vim/releases)
vimproc is a great asynchronous execution library for Vim. It is a fork of
proc.vim by Yukihiro Nakadaira. I added some features and fixed some bugs and
I'm maintaining it now. Instead of an external shell (example: 'shell'),
vimproc uses an external DLL file.
Supported platforms:
* Windows 32/64bit (Compiled by MinGW or Visual Studio)
* macOS (10.5 or later)
* Linux
* Cygwin
* Solaris
* BSD (but cannot check)
* Android (experimental)
Not supported platforms:
* Other UNIX platforms
## Install
### Manual Install
* Clone this repo
* Build vimproc's native extensions (see Building for details)
* Copy `autoload/*`, `lib/*` and `plugin/*` files to your 'runtimepath'
directory (see `:help runtimepath`).
### dein.vim
If you use [dein.vim](http://github.com/Shougo/dein.vim), you can
update and build vimproc automatically. This is the recommended package manager.
```vim
call dein#add('Shougo/vimproc.vim', {'build' : 'make'})
```
### Vim-Plug
If you use [vim-plug](https://github.com/junegunn/vim-plug), you can update and build vimproc automatically.
```vim
Plug 'Shougo/vimproc.vim', {'do' : 'make'}
```
### Vundle
If you use [Vundle](https://github.com/VundleVim/Vundle.vim), add the following to your `.vimrc`.
```vim
Plugin 'Shougo/vimproc.vim'
```
Then compile the plugin manually where it was installed.
i.e. on Linux & Mac
```bash
$ cd ~/.vim/bundle/vimproc.vim && make
```
See [building](https://github.com/Shougo/vimproc.vim#building)
### NeoBundle
If you use [neobundle.vim](http://github.com/Shougo/neobundle.vim), you can
update and build vimproc automatically.
```vim
NeoBundle 'Shougo/vimproc.vim', {
\ 'build' : {
\ 'windows' : 'tools\\update-dll-mingw',
\ 'cygwin' : 'make -f make_cygwin.mak',
\ 'mac' : 'make',
\ 'linux' : 'make',
\ 'unix' : 'gmake',
\ },
\ }
```
### Pathogen
vimproc uses a pathogen compatible structure, so it can be managed with
[pathogen](https://github.com/tpope/vim-pathogen), however you must remember to
compile after cloning the repo.
```sh
git clone https://github.com/Shougo/vimproc.vim.git ~/.vim/bundle/vimproc.vim
cd ~/.vim/bundle/vimproc.vim
make
```
## Building
Note: You must use GNU make to build vimproc.
You can install the dll using |VimProcInstall|. If you are having any trouble
or want to build manually then read on.
### Linux
$ make
### macOS
Note: Users of macOS 10.15 (Catalina) cannot directly use this library with the system-provided vi. (SIP prevents binaries in the write-only `/usr/bin` directory from calling `dlopen` on unsigned libraries like `vimproc_mac.so`.) The simplest solution is to build or install another version of vi in a non-SIP protected location. For example, using homebrew, `brew install vim` (or `nvim`) will install an unrestricted executable in `/usr/local/bin`. (Don't forget to set up aliases or `$PATH` so that you don't accidentally invoke the system `vi`.)
$ make
Note: If you want to build for multiple architectures, you can use `ARCHS` and `CC` variables.
Build for i386 and x86-64:
$ make ARCHS='i386 x86_64'
### FreeBSD
$ gmake
If you want to use BSD make, use the platform specific makefile:
$ make -f make_bsd.mak
### Solaris
$ gmake
Note: If you want to use Sun Compiler, you can use `SUNCC` variable.
$ gmake SUNCC=cc
### Windows
Note: In Windows, using MinGW is recommended.
Note: If you have not "gcc" binary, you must change $CC value.
Windows using MinGW (32bit Vim):
$ mingw32-make -f make_mingw32.mak
Windows using MinGW (If you want to use MinGW compiler in Cygwin):
$ mingw32-make -f make_mingw32.mak CC=mingw32-gcc
Windows using MinGW (64bit Vim):
$ mingw32-make -f make_mingw64.mak
Windows using Visual Studio (32bit/64bit Vim):
$ nmake -f make_msvc.mak
You should run this from VS command prompt.
The architecture will be automatically detected, but you can also specify the
architecture explicitly. E.g.:
32bit: nmake -f make_msvc.mak CPU=i386
64bit: nmake -f make_msvc.mak CPU=AMD64
Cygwin:
$ make
Note: The `vimproc_cygwin.dll` compiled in Cygwin won't work with Windows Vim.
### Windows Binaries
* [Kaoriya Vim](http://www.kaoriya.net/software/vim/) comes bundled with a precompiled version
for vimproc in Windows environment
* https://github.com/Shougo/vimproc.vim/releases

View File

@ -0,0 +1,45 @@
---
version: '{build}'
shallow_clone: true
environment:
global:
AUTH_TOKEN:
secure: rKd6JLXUIl3vcA8d0S9w14bl+uvUlZLt0d1M8bmlOh+owQqr5c40+/4ITCNBpHG3
matrix:
- COMPILER: msvc
CPU: i386
ENV: /x86
BIT: 32
- COMPILER: msvc
CPU: AMD64
ENV: /x64
BIT: 64
- COMPILER: cygwin
BIT: 32
- COMPILER: cygwin
BIT: 64
- COMPILER: msys2
MSYS2_ARCH: i686
MSYS2_DIR: msys64
MSYSTEM: MINGW32
BIT: 32
- COMPILER: msys2
MSYS2_ARCH: x86_64
MSYS2_DIR: msys64
MSYSTEM: MINGW64
BIT: 64
build_script:
- '%APPVEYOR_BUILD_FOLDER%\tools\appveyor.bat'
test_script:
- '%APPVEYOR_BUILD_FOLDER%\tools\appveyor.bat test'
artifacts:
- path: lib/vimproc_*.dll
name: vimproc.dll
deploy:
provider: GitHub
description: vimproc
auth_token:
secure: rKd6JLXUIl3vcA8d0S9w14bl+uvUlZLt0d1M8bmlOh+owQqr5c40+/4ITCNBpHG3
on:
appveyor_repo_tag: true
COMPILER: msvc

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,103 @@
"=============================================================================
" FILE: cmd.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
" the following conditions:
"
" The above copyright notice and this permission notice shall be included
" in all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
"=============================================================================
" Saving 'cpoptions' {{{
let s:save_cpo = &cpo
set cpo&vim
" }}}
if !vimproc#util#is_windows()
function! vimproc#cmd#system(expr) abort
return vimproc#system(a:expr)
endfunction
let &cpo = s:save_cpo
finish
endif
" Based from : http://d.hatena.ne.jp/osyo-manga/20130611/1370950114
let s:cmd = {}
augroup vimproc
autocmd VimLeave * call s:cmd.close()
augroup END
function! s:cmd.open() abort "{{{
let cmd = 'cmd.exe'
let self.vimproc = vimproc#popen3(cmd)
let self.cwd = getcwd()
" Wait until getting first prompt.
let output = ''
while output !~ '.\+>$'
let output .= self.vimproc.stdout.read()
endwhile
endfunction"}}}
function! s:cmd.close() abort "{{{
call self.vimproc.waitpid()
endfunction"}}}
function! s:cmd.system(cmd) abort "{{{
" Execute cmd.
if self.cwd !=# getcwd()
" Execute cd.
let input = '(cd /D "' . getcwd() . '" & ' . a:cmd . ')'
let self.cwd = getcwd()
else
let input = a:cmd
endif
call self.vimproc.stdin.write(input . "\n")
" Wait until getting prompt.
let output = ''
while 1
let output .= self.vimproc.stdout.read()
let lastnl = strridx(output, "\n")
if lastnl >= 0 &&
\ output[lastnl + 1:] =~ '^\%([A-Z]:\\\|\\\\.\+\\.\+\\\).*>$'
break
endif
endwhile
let result = split(output, '\r\n\|\n')[1:-2]
return join(result, "\n")
endfunction"}}}
call s:cmd.open()
function! vimproc#cmd#system(expr) abort
let cmd = type(a:expr) == type('') ? a:expr :
\ join(map(a:expr,
\ 'match(v:val, "\\s") >= 0 ? "\"".v:val."\"" : v:val'))
return s:cmd.system(cmd)
endfunction
" Restore 'cpoptions' {{{
let &cpo = s:save_cpo
" }}}
" vim:foldmethod=marker:fen:sw=2:sts=2

View File

@ -0,0 +1,110 @@
"=============================================================================
" FILE: commands.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
" the following conditions:
"
" The above copyright notice and this permission notice shall be included
" in all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
"=============================================================================
" Saving 'cpoptions' {{{
let s:save_cpo = &cpo
set cpo&vim
" }}}
" Command functions:
function! vimproc#commands#_install(args) abort "{{{
let savemp = &makeprg
let savecwd = getcwd()
try
if executable('gmake')
let &makeprg = 'gmake'
elseif executable('make')
let &makeprg = 'make'
elseif executable('nmake')
let &makeprg = 'nmake -f make_msvc.mak nodebug=1'
endif
" Change to the correct directory and run make
execute 'lcd' fnameescape(fnamemodify(g:vimproc#dll_path, ':h:h'))
execute 'make' a:args
finally
" Restore working directory and makeprg
execute 'lcd' fnameescape(savecwd)
let &makeprg = savemp
endtry
endfunction"}}}
function! vimproc#commands#_bang(cmdline) abort "{{{
" Expand % and #.
let cmdline = join(map(vimproc#parser#split_args_through(
\ vimproc#util#iconv(a:cmdline,
\ vimproc#util#termencoding(), &encoding)),
\ 'substitute(expand(v:val), "\n", " ", "g")'))
" Open pipe.
let subproc = vimproc#pgroup_open(cmdline, 1)
call subproc.stdin.close()
while !subproc.stdout.eof || !subproc.stderr.eof
if !subproc.stdout.eof
let output = subproc.stdout.read(10000, 0)
if output != ''
let output = vimproc#util#iconv(output,
\ vimproc#util#stdoutencoding(), &encoding)
echon output
sleep 1m
endif
endif
if !subproc.stderr.eof
let output = subproc.stderr.read(10000, 0)
if output != ''
let output = vimproc#util#iconv(output,
\ vimproc#util#stderrencoding(), &encoding)
echohl WarningMsg | echon output | echohl None
sleep 1m
endif
endif
endwhile
call subproc.stdout.close()
call subproc.stderr.close()
call subproc.waitpid()
endfunction"}}}
function! vimproc#commands#_read(cmdline) abort "{{{
" Expand % and #.
let cmdline = join(map(vimproc#parser#split_args_through(
\ vimproc#util#iconv(a:cmdline,
\ vimproc#util#termencoding(), &encoding)),
\ 'substitute(expand(v:val), "\n", " ", "g")'))
" Expand args.
call append('.', split(vimproc#util#iconv(vimproc#system(cmdline),
\ vimproc#util#stdoutencoding(), &encoding), '\r\n\|\n'))
endfunction"}}}
" Restore 'cpoptions' {{{
let &cpo = s:save_cpo
" }}}
" vim:foldmethod=marker:fen:sw=2:sts=2

View File

@ -0,0 +1,176 @@
" This file from vital.vim.
" https://github.com/vim-jp/vital.vim
" You should check the following related builtin functions.
" fnamemodify()
" resolve()
" simplify()
let s:save_cpo = &cpo
set cpo&vim
let s:path_sep_pattern = (exists('+shellslash') ? '[\\/]' : '/') . '\+'
let s:is_windows = has('win16') || has('win32') || has('win64')
let s:is_cygwin = has('win32unix')
let s:is_mac = !s:is_windows && !s:is_cygwin
\ && (has('mac') || has('macunix') || has('gui_macvim') ||
\ (!executable('xdg-open') && system('uname') =~? '^darwin'))
" Get the directory separator.
function! s:separator() abort
return !exists('+shellslash') || &shellslash ? '/' : '\'
endfunction
" Get the path separator.
let s:path_separator = s:is_windows ? ';' : ':'
function! s:path_separator() abort
return s:path_separator
endfunction
" Get the path extensions
function! s:path_extensions() abort
if !exists('s:path_extensions')
if s:is_windows
if exists('$PATHEXT')
let pathext = $PATHEXT
else
" get default PATHEXT
let pathext = matchstr(system('set pathext'), '^pathext=\zs.*\ze\n', 'i')
endif
let s:path_extensions = split(tolower(pathext), s:path_separator)
elseif s:is_cygwin
" cygwin is not use $PATHEXT
let s:path_extensions = ['', '.exe']
else
let s:path_extensions = ['']
endif
endif
return s:path_extensions
endfunction
" Convert all directory separators to "/".
function! s:unify_separator(path) abort
return substitute(a:path, s:path_sep_pattern, '/', 'g')
endfunction
" Get the full path of command.
function! s:which(command, ...) abort
let maxcount = (a:0 >= 2 && type(a:2) == type(0)) ? a:2 : 1
if maxcount == 1 && exists('*exepath')
let full = exepath(a:command)
if s:is_windows && (full =~? '\.lnk$') && (getftype(full) ==# 'file')
return resolve(full)
endif
return full
endif
let pathlist = a:command =~# s:path_sep_pattern ? [''] :
\ !a:0 ? split($PATH, s:path_separator) :
\ type(a:1) == type([]) ? copy(a:1) :
\ split(a:1, s:path_separator)
let pathlist = vimproc#util#uniq(pathlist)
let pathext = s:path_extensions()
if index(pathext, '.' . tolower(fnamemodify(a:command, ':e'))) != -1
let pathext = ['']
endif
let dirsep = s:separator()
let cmdlist = []
for dir in pathlist
let head = dir ==# '' ? '' : dir . dirsep
for ext in pathext
let full = fnamemodify(head . a:command . ext, ':p')
if s:is_windows && (full =~? '\.lnk$') && (getftype(full) ==# 'file')
let full = resolve(full)
endif
if executable(full)
if s:is_case_tolerant()
let full = glob(substitute(
\ vimproc#util#substitute_path_separator(
\ toupper(full)), '\u:\@!', '[\0\L\0]', 'g'), 1)
endif
if full != ''
let cmdlist += [full]
if maxcount > 0 && len(cmdlist) >= maxcount
return join(cmdlist, "\n")
endif
endif
endif
endfor
endfor
return join(cmdlist, "\n")
endfunction
" Split the path with directory separator.
" Note that this includes the drive letter of MS Windows.
function! s:split(path) abort
return split(a:path, s:path_sep_pattern)
endfunction
" Join the paths.
" join('foo', 'bar') => 'foo/bar'
" join('foo/', 'bar') => 'foo/bar'
" join('/foo/', ['bar', 'buz/']) => '/foo/bar/buz/'
function! s:join(...) abort
let sep = s:separator()
let path = ''
for part in a:000
let path .= sep .
\ (type(part) is type([]) ? call('s:join', part) :
\ part)
unlet part
endfor
return substitute(path[1 :], s:path_sep_pattern, sep, 'g')
endfunction
" Check if the path is absolute path.
if s:is_windows
function! s:is_absolute(path) abort
return a:path =~? '^[a-z]:[/\]'
endfunction
else
function! s:is_absolute(path) abort
return a:path[0] ==# '/'
endfunction
endif
" Return the parent directory of the path.
" NOTE: fnamemodify(path, ':h') does not return the parent directory
" when path[-1] is the separator.
function! s:dirname(path) abort
let path = a:path
let orig = a:path
let path = s:remove_last_separator(path)
if path == ''
return orig " root directory
endif
let path = fnamemodify(path, ':h')
return path
endfunction
" Remove the separator at the end of a:path.
function! s:remove_last_separator(path) abort
let sep = s:separator()
let pat = (sep == '\' ? '\\' : '/') . '\+$'
return substitute(a:path, pat, '', '')
endfunction
" Return true if filesystem ignores alphabetic case of a filename.
" Return false otherwise.
let s:is_case_tolerant = filereadable(expand('<sfile>:r') . '.VIM')
function! s:is_case_tolerant() abort
return s:is_case_tolerant
endfunction
function! vimproc#filepath#which(command, path, maxcount) abort
return s:which(a:command, a:path, a:maxcount)
endfunction
let &cpo = s:save_cpo
" vim:set et ts=2 sts=2 sw=2 tw=0:

View File

@ -0,0 +1,130 @@
"=============================================================================
" FILE: parser.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
" the following conditions:
"
" The above copyright notice and this permission notice shall be included
" in all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
"=============================================================================
" Saving 'cpoptions' {{{
let s:save_cpo = &cpo
set cpo&vim
" }}}
" Constants. {{{
let g:vimproc#lexer#token_type = {
\ 'int' : 257,
\ 'string' : 258,
\ }
" }}}
function! vimproc#lexer#init_lexer(text) abort
let lexer = deepcopy(s:lexer)
let lexer.reader = vimproc#lexer#init_reader(a:text)
return lexer
endfunction
let s:lexer = {}
function! s:lexer.advance() abort
call self.skip_spaces()
let c = self.reader.read()
if c < 0
return 0
endif
if c =~ '\d'
call self.reader.unread()
call self.lex_digit()
let self.tok = g:vimproc#lexer#token_type.int
else
throw 'Exception: Not int.'
endif
return 1
endfunction
function! s:lexer.lex_digit() abort
let self.val = 0
while 1
let c = self.reader.read()
if c < 0
break
elseif c !~ '\d'
call self.reader.unread()
break
endif
let self.val = self.val * 10 + c
endwhile
endfunction
function! s:lexer.skip_spaces() abort
while 1
let c = self.reader.read()
if c < 0
break
elseif c !~ '\s'
call self.reader.unread()
break
endif
endwhile
endfunction
function! s:lexer.token() abort
return self.tok
endfunction
function! s:lexer.value() abort
return self.val
endfunction
function! vimproc#lexer#init_reader(text) abort
let reader = deepcopy(s:reader)
let reader.text = split(a:text, '\zs')
let reader.pos = 0
return reader
endfunction
let s:reader = {}
function! s:reader.read() abort
if self.pos >= len(self.text)
" Buffer over.
return -1
endif
let c = self.text[self.pos]
let self.pos += 1
return c
endfunction
function! s:reader.unread() abort
let self.pos -= 1
endfunction
" Restore 'cpoptions' {{{
let &cpo = s:save_cpo
" }}}
" vim:foldmethod=marker:fen:sw=2:sts=2

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,174 @@
"=============================================================================
" FILE: util.vim
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
" the following conditions:
"
" The above copyright notice and this permission notice shall be included
" in all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
"=============================================================================
" Saving 'cpoptions' {{{
let s:save_cpo = &cpo
set cpo&vim
" }}}
let s:is_windows = has('win32')
let s:is_cygwin = has('win32unix')
let s:is_mac = !s:is_windows && !s:is_cygwin
\ && (has('mac') || has('macunix') || has('gui_macvim') ||
\ (!isdirectory('/proc') && executable('sw_vers')))
" iconv() wrapper for safety.
function! vimproc#util#has_iconv() abort "{{{
" On Windows, some encodings can be converted by iconv() even if
" libiconv.dll is not available.
return (has('iconv') || (s:is_windows && exists('*iconv')))
endfunction"}}}
function! vimproc#util#iconv(expr, from, to) abort "{{{
if !vimproc#util#has_iconv()
\ || a:expr == '' || a:from == ''
\ || a:to == '' || a:from ==# a:to
return a:expr
endif
let result = iconv(a:expr, a:from, a:to)
return result != '' ? result : a:expr
endfunction"}}}
function! vimproc#util#systemencoding() abort "{{{
return s:is_windows ? 'utf-8' : 'char'
endfunction"}}}
function! vimproc#util#termencoding() abort "{{{
return 'char'
endfunction"}}}
function! vimproc#util#stdinencoding() abort "{{{
return exists('g:stdinencoding') && type(g:stdinencoding) == type("") ?
\ g:stdinencoding : vimproc#util#termencoding()
endfunction"}}}
function! vimproc#util#stdoutencoding() abort "{{{
return exists('g:stdoutencoding') && type(g:stdoutencoding) == type("") ?
\ g:stdoutencoding : vimproc#util#termencoding()
endfunction"}}}
function! vimproc#util#stderrencoding() abort "{{{
return exists('g:stderrencoding') && type(g:stderrencoding) == type("") ?
\ g:stderrencoding : vimproc#util#termencoding()
endfunction"}}}
function! vimproc#util#expand(path) abort "{{{
return vimproc#util#substitute_path_separator(
\ (a:path =~ '^\~') ? fnamemodify(a:path, ':p') :
\ (a:path =~ '^\$\h\w*') ? substitute(a:path,
\ '^\$\h\w*', '\=eval(submatch(0))', '') :
\ a:path)
endfunction"}}}
function! vimproc#util#is_windows() abort "{{{
return s:is_windows
endfunction"}}}
function! vimproc#util#is_mac() abort "{{{
return s:is_mac
endfunction"}}}
function! vimproc#util#is_cygwin() abort "{{{
return s:is_cygwin
endfunction"}}}
function! vimproc#util#has_lua() abort "{{{
" Note: Disabled if_lua feature if less than 7.3.885.
" Because if_lua has double free problem.
return has('lua') && (v:version > 703 || v:version == 703 && has('patch885'))
endfunction"}}}
function! vimproc#util#substitute_path_separator(path) abort "{{{
return s:is_windows ? substitute(a:path, '\\', '/', 'g') : a:path
endfunction"}}}
function! vimproc#util#cd(path) abort "{{{
execute (haslocaldir() ? 'lcd' : 'cd') fnameescape(a:path)
endfunction"}}}
function! vimproc#util#uniq(list, ...) abort "{{{
let list = a:0 ? map(copy(a:list), printf('[v:val, %s]', a:1)) : copy(a:list)
let i = 0
let seen = {}
while i < len(list)
let key = string(a:0 ? list[i][1] : list[i])
if has_key(seen, key)
call remove(list, i)
else
let seen[key] = 1
let i += 1
endif
endwhile
return a:0 ? map(list, 'v:val[0]') : list
endfunction"}}}
function! vimproc#util#set_default(var, val, ...) abort "{{{
if !exists(a:var) || type({a:var}) != type(a:val)
let alternate_var = get(a:000, 0, '')
let {a:var} = exists(alternate_var) ?
\ {alternate_var} : a:val
endif
endfunction"}}}
function! vimproc#util#try_update_windows_dll(version) abort "{{{
let old_path = g:vimproc#dll_path . '.old'
if filereadable(old_path)
if delete(old_path) == -1
return 0
endif
endif
if filereadable(g:vimproc#dll_path)
if delete(g:vimproc#dll_path) == -1
if rename(g:vimproc#dll_path, old_path)
return 0
endif
endif
endif
return vimproc#util#try_download_windows_dll(a:version)
endfunction"}}}
function! vimproc#util#try_download_windows_dll(version) abort "{{{
let fname = printf('vimproc_win%s.dll', has('win64') ? '64' : '32')
let url = printf('https://github.com/Shougo/vimproc.vim/releases/download/ver.%s/%s', a:version, fname)
if executable('curl')
let cmd = printf('curl --insecure --silent --location --output %s %s',
\ s:win_escape(g:vimproc#dll_path),
\ s:win_escape(url))
call system(cmd)
return filereadable(g:vimproc#dll_path)
elseif executable('powershell')
let pscmd = printf("(New-Object Net.WebClient).DownloadFile('%s', '%s')",
\ url, g:vimproc#dll_path)
let cmd = printf('powershell -Command %s', s:win_escape(pscmd))
call system(cmd)
return filereadable(g:vimproc#dll_path)
endif
return 0
endfunction"}}}
function! s:win_escape(str) abort "{{{
return '"' . substitute(a:str, '"', '""', 'g') . '"'
endfunction"}}}
" Global options definition. "{{{
call vimproc#util#set_default(
\ 'g:stdinencoding', 'char')
call vimproc#util#set_default(
\ 'g:stdoutencoding', 'char')
call vimproc#util#set_default(
\ 'g:stderrencoding', 'char')
"}}}
" Restore 'cpoptions' {{{
let &cpo = s:save_cpo
" }}}
" vim: foldmethod=marker

View File

@ -0,0 +1,534 @@
*vimproc.txt* Asynchronous execution plugin for Vim
Version: 9.3
Author : Shougo <Shougo.Matsu at gmail.com>
Original Author : Yukihiro Nakadaira <yukihiro.nakadaira at gmail.com>
License: MIT license {{{
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}}}
CONTENTS *vimproc-contents*
Introduction |vimproc-introduction|
Install |vimproc-install|
Interface |vimproc-interface|
Commands |vimproc-commands|
Functions |vimproc-functions|
Variables |vimproc-variables|
Objects |vimproc-objects|
Tips |vimproc-tips|
Examples |vimproc-examples|
FAQ |vimproc-faq|
==============================================================================
INTRODUCTION *vimproc-introduction*
*vimproc* is a great asynchronous execution library for Vim. It is a fork of
proc.vim by Yukihiro Nakadaira. I added some features and fixed some bugs and
I'm maintaining it now. Instead of an external shell (example: 'shell'),
|vimproc| uses an external DLL file.
==============================================================================
INSTALL *vimproc-install*
First, download vimproc by cloning the Git repository:
http://github.com/Shougo/vimproc.vim
Next, you have to compile the external DLL "vimproc_xxx.so" (or
"vimproc_win32.dll" for Windows, "vimproc_cygwin.dll" for Windows/Cygwin).
Because vimproc depends on the functions of the DLL, vimproc will show an
error message if the compiled DLL doesn't exist.
You can install the DLL using |VimProcInstall|. If you are having any trouble
or want to build manually then read on.
Supported platforms:
* Windows 32/64bit (Compiled by MinGW or Visual Studio)
* macOS (10.5 or later)
* Linux
* Cygwin
* Solaris
* BSD (but cannot check)
* Android (experimental)
Unsupported platforms:
* Other UNIX platforms
Build Steps:
Note: You must use GNU make to build vimproc.
Note: You must execute the command from the root of the vimproc repository
Linux *vimproc-linux*
>
$ make
<
macOS *vimproc-macos* *vimproc-macosx*
>
$ make
<
Note: If you want to build for multiple architectures, you can use $ARCHS and
$CC variables.
Build for i386 and x86-64: *vimproc-multiarch*
>
$ make ARCHS='i386 x86_64'
<
FreeBSD *vimproc-freebsd*
>
$ gmake
If you want to use BSD make, use the platform specific makefile: >
$ make -f make_bsd.mak
Solaris *vimproc-solaris*
>
$ gmake
<
Note: If you want to use Sun Compiler, you can use $SUNCC variable.
>
$ gmake SUNCC=cc
<
Windows *vimproc-windows*
Note: In Windows, using MinGW is recommended.
Note: If you do not have the "gcc" or "x86_64-w64-mingw32-gcc" binary in your
%PATH, you must change CC variable accordingly.
Windows using MinGW (32bit Vim):
>
$ mingw32-make -f make_mingw32.mak
<
Windows using MinGW (If you want to use MinGW compiler in Cygwin):
>
$ mingw32-make -f make_mingw32.mak CC=mingw32-gcc
<
Windows using MinGW (64bit Vim):
>
$ mingw32-make -f make_mingw64.mak
<
Windows using Visual Studio (32bit/64bit Vim):
>
$ nmake -f make_msvc.mak
<
You should run this from VS command prompt.
The architecture will be automatically detected, but you can also specify the
architecture explicitly. E.g.:
>
32bit: nmake -f make_msvc.mak CPU=i386
64bit: nmake -f make_msvc.mak CPU=AMD64
<
* Cygwin: *vimproc-cygwin*
>
$ make
<
Note: The `vimproc_cygwin.dll` compiled in Cygwin won't work with Windows Vim.
If you use |dein.vim| or |neobundle.vim|, you can update and build vimproc
automatically.
http://github.com/Shougo/dein.vim
http://github.com/Shougo/neobundle.vim
Example for dein.vim:
>
call dein#add('Shougo/vimproc.vim', {'build': 'make'})
<
Example for neobundle.vim:
>
NeoBundle 'Shougo/vimproc.vim', {
\ 'build' : {
\ 'windows' : 'tools\\update-dll-mingw',
\ 'cygwin' : 'make -f make_cygwin.mak',
\ 'mac' : 'make -f make_mac.mak',
\ 'linux' : 'make',
\ 'unix' : 'gmake',
\ }
\ }
<
Windows Binaries:
* Kaoriya Vim (http://www.kaoriya.net/software/vim/) comes bundled with a
precompiled version for vimproc in Windows environment
* https://github.com/Shougo/vimproc.vim/releases
==============================================================================
INTERFACE *vimproc-interface*
------------------------------------------------------------------------------
COMMANDS *vimproc-commands*
:VimProcBang {path} *:VimProcBang*
Executes {path} command and echo result. This
command replaces |:!|.
Note: It is not asynchronous.
:VimProcRead {path} *:VimProcRead*
Executes {path} command and paste result in current
buffer. This command replaces |:read|.
:VimProcInstall {args} *:VimProcInstall*
Tries to build the necessary DLL using `gmake`/`make`.
You can supply extra arguments to `make`, for example
to compile using clang `:VimProcInstall CC=clang`.
------------------------------------------------------------------------------
FUNCTIONS *vimproc-functions*
vimproc#version() *vimproc#version()*
Returns vimproc version number. Version 5.0 is 500. Version
5.1 (5.01) is 501. It has the same format as |v:version|.
vimproc#dll_version() *vimproc#dll_version()*
Same to |vimproc#version()|, but it returns vimproc DLL
version.
vimproc#open({filename}) *vimproc#open()*
Opens {filename} with a system associated command.
*vimproc#get_command_name()*
vimproc#get_command_name({command} [, {path} [, {count}]])
Searches {command} from {path} and returns command name. If
you omit {path}, uses $PATH instead. If you set {count},
returns {count}th candidate. If you set {count} to a negative
number, it returns a list which contains all candidates. If
{count} is omitted, then 1 is used.
vimproc#system({expr} [, {input} [, {timeout}]]) *vimproc#system()*
It replaces |system()|. If you call |system()| in Windows
environment, DOS window will appear. But, |vimproc#system()|
is not.
Note: It does not execute a shell. So a shell internal
command is invalid. Ex: pwd, cd, ...
The {expr} is same to |vimproc#plineopen3()|. The type is
String or arguments list. If {expr} is a String, it is parsed
automatically.
If the end of {expr} is "&", executes a command in the
background.
>
call vimproc#system('ls &')
<
If you set {timeout}, vimproc will kill the process after
{timeout} and throw "vimproc: vimproc#system(): Timeout."
exception.
The unit is millisecond.
Note: |+reltime| and Vim 7.2 is required.
If you set {input}, inputs the string to the command.
vimproc#system2({expr} [, {input} [, {timeout}]]) *vimproc#system2()*
Same as |vimproc#system()|. But it converts the encoding of
inputs and outputs automatically.
*vimproc#system_passwd()*
vimproc#system_passwd({expr} [, {input} [, {timeout}]])
Same as |vimproc#system()|. But it supports password input.
vimproc#system_bg({expr}) *vimproc#system_bg()*
Same as |vimproc#system()|. But it executes a command in the
background.
Note: It disables user input.
Note: This function does not support the following statements:
";", "&&" and "||".
vimproc#system_gui({expr}) *vimproc#system_gui()*
Same as |vimproc#system_bg()|.
Note: It is obsolete API.
vimproc#cmd#system({expr}) *vimproc#cmd#system()*
Same as |vimproc#system()| on non-Windows platforms.
On Windows, it is similar to |vimproc#system()| but faster.
It executes a "cmd.exe" process in the background when it is
called first time. After the next call, it reuses the
"cmd.exe" process. The process will be automatically closed
when Vim exits.
vimproc#get_last_status() *vimproc#get_last_status()*
Gets the last |vimproc#system()| status value.
vimproc#get_last_errmsg() *vimproc#get_last_errmsg()*
Gets the last |vimproc#system()| error messages.
vimproc#shellescape({string}) *vimproc#shellescape()*
Escapes {string} for vimproc function arguments.
vimproc#fopen({path} [, {flags} [, {mode}]]) *vimproc#fopen()*
Opens {path} file and returns a |vimproc-file-object|.
The optional {flags} is only either one of fopen() mode
string (e.g. "r", "wb+") or open() flag values as string
(e.g. "O_RDONLY | O_BINARY"). If {flags} is omitted,
"r" (read-only) is used.
The optional {mode} number specifies the permissions in case
a new file is created. If {mode} is omitted, 0644 (octal)
is used.
vimproc#socket_open({host}, {port}) *vimproc#socket_open()*
Opens the {host}:{port} socket and returns a
|vimproc-socket-object|.
The {host} is a String. The {port} is a Number.
vimproc#host_exists({host}) *vimproc#host_exists()*
Checks to see if {host} exists.
Note: Protocol name and path are ignored.
vimproc#popen2({args} [, {is-pty}]) *vimproc#popen2()*
Executes {args} command and returns a |vimproc-process-object|.
If {args} is a String, {args} is parsed automatically.
Otherwise the {args} is a list of a command and its arguments.
If {is-pty} is 1, vimproc will use pty.
vimproc#popen3({args} [, {is-pty}]) *vimproc#popen3()*
Same as |vimproc#popen2()|, but this function splits
stderr output.
vimproc#plineopen2({commands} [, {is-pty}]) *vimproc#plineopen2()*
Executes {commands} command and returns a
|vimproc-process-object|.
If {commands} is a String, {commands} is parsed automatically.
Note: You can use pipes.
Otherwise the {commands} is a list of dictionaries.
The keys are follows:
args The arguments list.
fd The output filename. If it is empty, the
output is sent to the next process.
If {is-pty} is 1, vimproc will use pty.
vimproc#plineopen3({commands} [, {is-pty}]) *vimproc#plineopen3()*
Same as |vimproc#plineopen2()|, but this function splits
stderr output.
vimproc#pgroup_open({statements} [, {is-pty}]) *vimproc#pgroup_open()*
Executes {statements} command and returns a
|vimproc-process-object|.
If {statements} is a String, {statements} is parsed
automatically.
Note: You can use pipes, ";", "&&" and "||".
Otherwise the {statements} is a dictionary list split by
commands.
The keys are follows:
statement The execute pipeline information same as
|vimproc#plineopen2()|'s {commands} argument.
condition The condition which executes next command.
"always" : execute always. (";")
"true" : execute if previous command is
succeeded. ("&&")
"false" : execute if previous command is
failed. ("||")
If {is-pty} is 1, vimproc will use pty.
vimproc#ptyopen({args} [, {npipe}]) *vimproc#ptyopen()*
Executes {args} command and returns a |vimproc-process-object|.
If {args} is a String, {args} is parsed automatically.
The {npipe} is 2 or 3. If it is 2, combines stdout and
stderr.
Note: You can use pipes.
Otherwise the {args} is a list of a command and its arguments.
vimproc#kill({pid}, {sig}) *vimproc#kill()*
Sends {sig} signal to {pid} process.
If an error is occurred, it returns 1 for error and sets
|vimproc#get_last_errmsg()|.
If {sig} is 0, it checks whether {pid} exists.
vimproc#write({filename}, {string} [, {mode}]) *vimproc#write()*
Writes {string} to {filename} file.
The {mode} is a write mode. "w", "b" or "a" is valid.
"w" : normal mode.
"b" : binary mode.
"a" : append mode.
If you omit {mode}, use "w".
But {filename} head is ">", "a" is used.
vimproc#readdir({dirname}) *vimproc#readdir()*
Returns files in {dirname}. If {dirname} is not found,
returns an empty list.
Note: Filename encoding is converted to 'termencoding'.
vimproc#delete_trash({filename}) *vimproc#delete_trash()*
Moves a file {filename} to a trashbox directory.
Note: Windows environment only.
Note: Filename encoding is converted to 'termencoding'.
------------------------------------------------------------------------------
VARIABLES *vimproc-variables*
*g:vimproc#dll_path*
g:vimproc#dll_path (default
Win32: "$VIMRUNTIME/lib/vimproc_win32.dll"
Win64: "$VIMRUNTIME/lib/vimproc_win64.dll"
Cygwin: "$VIMRUNTIME/lib/vimproc_cygwin.dll"
Mac: "$VIMRUNTIME/lib/vimproc_mac.so"
Linux32: "$VIMRUNTIME/lib/vimproc_linux32.so"
Linux64: "$VIMRUNTIME/lib/vimproc_linux64.so"
Others: "$VIMRUNTIME/lib/vimproc_unix.so")
This variable stores a DLL name used by vimproc. You must
compile this DLL file. If this DLL does not exist, vimproc
will echo error.
*g:vimproc_dll_path*
Note: |g:vimproc_dll_path| is obsolete name.
*g:vimproc#disable*
g:vimproc#disable (default : not defined)
If it is defined, you cannot call vimproc functions.
You can use it to disable vimproc before loading it.
*g:vimproc#download_windows_dll*
g:vimproc#download_windows_dll (default : 0)
If this is non-zero, vimproc tries downloading MS Windows DLL
file from GitHub Releases page(*).
Vimproc also tries updating DLL file if it is outdated.
Vimproc does nothing if you don't use MS Windows.
(*) https://github.com/Shougo/vimproc.vim/releases
*g:vimproc#popen2_commands*
g:vimproc#popen2_commands (default : refer to autoload/vimproc.vim)
This variable is that vimproc use popen2 commands instead of
popen3 as dictionary. The key is command name and the value
is 1 or 0. If the command does not work in popen3, you can
set this variable.
*g:vimproc_popen2_commands*
Note: |g:vimproc_popen2_commands| is obsolete name.
*g:vimproc#password_pattern*
g:vimproc#password_pattern (default : refer to autoload/vimproc.vim)
The default password pattern.
Note: This variable is used for vimshell.
*g:vimproc_password_pattern*
Note: |g:vimproc_password_pattern| is obsolete name.
*g:stdinencoding*
g:stdinencoding (default : "char")
The default vimproc stdin encoding.
*g:stdoutencoding*
g:stdoutencoding (default : "char")
The default vimproc stdout encoding.
*g:stderrencoding*
g:stderrencoding (default : "char")
The default vimproc stderr encoding.
------------------------------------------------------------------------------
OBJECTS *vimproc-objects*
*vimproc-file-object*
File object
The file object provides some operations for file io.
It has functions and attributes follows:
eof If reaches end of file, it is 1.
Otherwise, 0.
is_valid Todo
read([{number}[, {timeout}[, {oneline}]]])
Read this file content up to the {number}
characters.
read_line([{number}[, {timeout}[, {oneline}]]])
Read next line from this file up to the
{number} characters.
read_lines([{number}[, {timeout}[, {oneline}]]])
Read all lines from this file up to the
{number} characters.
write({str}[, {timeout}])
Write given {str} to this file.
close() Close this file.
*vimproc-socket-object*
Socket object
The socket object provides some operations for socket io.
It functions and attributes same to |vimproc-file-object|.
*vimproc-process-object*
Process object
The process object provides some operations for piped io.
It has functions and attributes follows:
pid The pid of a child process was started.
pid_list Todo
stderr The |vimproc-file-object|.
stdout The |vimproc-file-object|.
stdin The |vimproc-file-object|.
is_pty Todo
is_valid Todo
checkpid() Todo
kill({signal}) It is similar to kill command. It can send
{signal} to a child process.
waitpid() Wait for a child process to stop or terminate.
get_winsize() Todo
set_winsize({width}, {height})
Todo
==============================================================================
TIPS *vimproc-tips*
Pseudo devices *vimproc-tips-pseudo-devices*
vimproc supports pseudo devices:
/dev/null
Remove all output.
/dev/clip
Print to clipboard.
/dev/quickfix
Print to |quickfix|.
==============================================================================
EXAMPLES *vimproc-examples*
>
" File open test.
let file = vimproc#fopen("./test1.vim", "O_RDONLY", 0)
let res = file.read()
call file.close()
new
call append(0, split(res, '\r\n\|\r\|\n'))
" Pipe open test.
let sub = vimproc#popen2('ls')
let res = ''
while !sub.stdout.eof
let res .= sub.stdout.read()
endwhile
let [cond, status] = sub.waitpid()
new
call append(0, split(res, '\r\n\|\r\|\n') + [string([cond, status])])
" Socket open test.
let sock = vimproc#socket_open('www.yahoo.com', 80)
call sock.write("GET / HTTP/1.0\r\n\r\n")
let res = ''
while !sock.eof
let res .= sock.read()
endwhile
call sock.close()
new
call append(0, split(res, '\r\n\|\r\|\n'))
<
==============================================================================
FAQ *vimproc-faq*
Q: I want to check a process is a zombie process.
A: You can use vimproc#kill({pid}, 0) or {process}.kill(0).
==============================================================================
vim:tw=78:ts=8:ft=help:norl:noet:fen:

View File

@ -0,0 +1,21 @@
# You must set environment variables to suit your environment, in this Makefile or your shell.
# For example, using Android NDK on Mac OSX:
# NDK_TOP=/path/to/your/ndk/android-ndk-r8d
# SYSROOT=$(NDK_TOP)/platforms/android-8/arch-arm
# CFLAGS=-march=armv5te -msoft-float
# CC=$(NDK_TOP)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gcc -mandroid --sysroot=$(SYSROOT)
CFLAGS+=-W -Wall -Wno-unused -Wno-unused-parameter -std=c99 -O2 -fPIC -pedantic
LDFLAGS+=-shared
TARGET=lib/vimproc_unix.so
SRC=src/proc.c src/ptytty.c
INC=src/vimstack.c src/ptytty.h
all: $(TARGET)
$(TARGET): $(SRC) $(INC)
$(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS)
clean:
rm -f $(TARGET)

View File

@ -0,0 +1,17 @@
# for *BSD platform.
SUFFIX!=uname -sm | tr '[:upper:]' '[:lower:]' | sed -e 's/ /_/'
TARGET=lib/vimproc_$(SUFFIX).so
SRC=src/proc.c
CFLAGS+=-W -O2 -Wall -Wno-unused -Wno-unused-parameter -std=gnu99 -pedantic -shared -fPIC
LDFLAGS+=-lutil
all: $(TARGET)
$(TARGET): $(SRC) src/vimstack.c
$(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS)
clean:
rm -f $(TARGET)

View File

@ -0,0 +1,12 @@
CFLAGS+=-O2 -W -Wall -Wno-unused -Wno-unused-parameter -use=gnu99 -shared
TARGET=lib/vimproc_cygwin.dll
SRC=src/proc.c
LDFLAGS+=-lutil
all: $(TARGET)
$(TARGET): $(SRC) src/vimstack.c
$(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS)
clean:
rm -f $(TARGET)

View File

@ -0,0 +1,12 @@
CFLAGS+=-O2 -W -Wall -Wno-unused -Wno-unused-parameter -use=gnu99 -shared
TARGET=lib/vimproc_cygwin64.dll
SRC=src/proc.c
LDFLAGS+=-lutil
all: $(TARGET)
$(TARGET): $(SRC) src/vimstack.c
$(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS)
clean:
rm -f $(TARGET)

View File

@ -0,0 +1,26 @@
# for Mac.
ifneq ($(shell which clang),)
CC=clang
else
ifneq ($(shell which llvm-gcc),)
CC=llvm-gcc
else
CC=gcc
endif
endif
TARGET=lib/vimproc_mac.so
SRC=src/proc.c
ARCHS=
CFLAGS+=-O2 -W -Wall -Wno-unused -Wno-unused-parameter -bundle -fPIC $(foreach ARCH,$(ARCHS),-arch $(ARCH))
LDFLAGS=
all: $(TARGET)
$(TARGET): $(SRC) src/vimstack.c
$(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS)
.PHONY : clean
clean:
-rm -f $(TARGET)

View File

@ -0,0 +1,15 @@
# for MinGW.
TARGET=lib/vimproc_win32.dll
SRC=src/proc_w32.c
CC=gcc
CFLAGS+=-O2 -Wall -shared -m32
LDFLAGS+=-lwsock32
all: $(TARGET)
$(TARGET): $(SRC) src/vimstack.c
$(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS)
clean:
rm -f $(TARGET)

View File

@ -0,0 +1,15 @@
# for MinGW.
TARGET=lib/vimproc_win64.dll
SRC=src/proc_w32.c
CC=x86_64-w64-mingw32-gcc
CFLAGS+=-O2 -Wall -shared -m64
LDFLAGS+=-lwsock32
all: $(TARGET)
$(TARGET): $(SRC) src/vimstack.c
$(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS)
clean:
rm -f $(TARGET)

View File

@ -0,0 +1,74 @@
# WINDOWS BUILD SETTINGS.
WINVER = 0x0500
APPVER = 5.0
TARGET = WINNT
_WIN32_IE = 0x0500
!ifdef CPU
! if "$(CPU)" == "I386"
CPU = i386
! endif
!else # !CPU
CPU = i386
! if !defined(PLATFORM) && defined(TARGET_CPU)
PLATFORM = $(TARGET_CPU)
! endif
! ifdef PLATFORM
! if ("$(PLATFORM)" == "x64") || ("$(PLATFORM)" == "X64")
CPU = AMD64
! elseif ("$(PLATFORM)" != "x86") && ("$(PLATFORM)" != "X86")
! error *** ERROR Unknown target platform "$(PLATFORM)". Make aborted.
! endif
! endif
!endif
# CONTROL BUILD MODE
!IFDEF DEBUG
CFLAGS = $(CFLAGS) -D_DEBUG
!ELSE
CFLAGS = $(CFLAGS) -D_NDEBUG
!ENDIF
# VIMPROC SPECIFICS
!if "$(CPU)" == "AMD64"
VIMPROC=vimproc_win64
!else
VIMPROC=vimproc_win32
!endif
SRCDIR = src
LIBDIR = lib
OUTDIR = $(SRCDIR)\obj$(CPU)
OBJS = $(OUTDIR)/proc_w32.obj
LINK = link
LFLAGS = /nologo /dll
DEFINES = -D_CRT_SECURE_NO_WARNINGS=1 -D_BIND_TO_CURRENT_VCLIBS_VERSION=1
CFLAGS = /nologo $(CFLAGS) $(DEFINES) /wd4100 /wd4127 /O2 /LD /c
# RULES
build: $(LIBDIR)\$(VIMPROC).dll
clean:
-IF EXIST $(OUTDIR)/nul RMDIR /s /q $(OUTDIR)
-DEL /F /Q $(LIBDIR)\$(VIMPROC).*
$(LIBDIR)\$(VIMPROC).dll: $(OBJS)
$(LINK) $(LFLAGS) /OUT:$@ $(OBJS) shell32.lib ws2_32.lib
IF EXIST $@.manifest \
mt -nologo -manifest $@.manifest -outputresource:$@;2
{$(SRCDIR)}.c{$(OUTDIR)}.obj::
$(CC) $(CFLAGS) -Fo$(OUTDIR)\ $<
$(OUTDIR):
IF NOT EXIST $(OUTDIR)/nul MKDIR $(OUTDIR)
$(OUTDIR)/proc_w32.obj: $(OUTDIR) $(SRCDIR)/proc_w32.c $(SRCDIR)/vimstack.c
.PHONY: build clean

View File

@ -0,0 +1,24 @@
# For SunOS
ifneq ($(SUNCC),)
CC=$(SUNCC)
CFLAGS+=-errwarn -xc99 -xO3 -native -KPIC
LDFLAGS+=-G
else # gcc
CC=gcc
CFLAGS+=-W -Wall -Wno-unused -Wno-unused-parameter -std=c99 -O2 -fPIC -pedantic
LDFLAGS+=-shared
endif
CPPFLAGS+=-D_XPG6 -D__EXTENSIONS__
TARGET=lib/vimproc_unix.so
SRC=src/proc.c src/ptytty.c
INC=src/vimstack.c src/ptytty.h
all: $(TARGET)
$(TARGET): $(SRC) $(INC)
$(CC) $(CFLAGS) $(CPPFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS)
clean:
rm -f $(TARGET)

View File

@ -0,0 +1,20 @@
# for *nix platform.
ifneq (,$(wildcard /lib*/ld-linux*.so.2))
SUFFIX=linux$(if $(wildcard /lib*/ld-linux*64.so.2),64,32)
else
SUFFIX=unix
endif
TARGET=lib/vimproc_$(SUFFIX).so
SRC=src/proc.c
CFLAGS+=-W -O2 -Wall -Wno-unused -Wno-unused-parameter -std=gnu99 -pedantic -shared -fPIC
LIBS=-lutil
all: $(TARGET)
$(TARGET): $(SRC) src/vimstack.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(SRC) $(LIBS)
clean:
rm -f $(TARGET)

View File

@ -0,0 +1,51 @@
"=============================================================================
" FILE: vimproc.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
" the following conditions:
"
" The above copyright notice and this permission notice shall be included
" in all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
"=============================================================================
if exists('g:loaded_vimproc')
finish
elseif v:version < 702
echoerr 'vimproc does not work this version of Vim "' . v:version . '".'
finish
endif
let g:loaded_vimproc = 1
" Saving 'cpoptions' {{{
let s:save_cpo = &cpo
set cpo&vim
" }}}
command! -nargs=* VimProcInstall
\ call vimproc#commands#_install(<q-args>)
command! -nargs=+ -complete=shellcmd VimProcBang
\ call vimproc#commands#_bang(<q-args>)
command! -nargs=+ -complete=shellcmd VimProcRead
\ call vimproc#commands#_read(<q-args>)
" Restore 'cpoptions' {{{
let &cpo = s:save_cpo
unlet s:save_cpo
" }}}
" vim: foldmethod=marker

View File

@ -0,0 +1,161 @@
/* fakepoll.h */
/* poll using select */
/* Warning: a call to this poll() takes about 4K of stack space. */
/* Greg Parker gparker-web@sealiesoftware.com December 2000 */
/* This code is in the public domain and may be copied or modified without */
/* permission. */
/* Nico Raffato gparker-web@sealiesoftware.com September 2009 */
/* Updated Sep 2009: */
/* * fix crash when an fd is less than 0 */
/* * don't set POLLIN or POLLOUT in revents if it wasn't requested */
/* in events (only happens when an fd is in the poll set twice) */
#ifndef _FAKE_POLL_H
#define _FAKE_POLL_H
#include <limits.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>
#ifndef OPEN_MAX
#define OPEN_MAX (sysconf(_SC_OPEN_MAX))
#endif
typedef struct pollfd {
int fd; /* file desc to poll */
short events; /* events of interest on fd */
short revents; /* events that occurred on fd */
} pollfd_t;
/* poll flags */
#define POLLIN 0x0001
#define POLLOUT 0x0004
#define POLLERR 0x0008
/* synonyms */
#define POLLNORM POLLIN
#define POLLPRI POLLIN
#define POLLRDNORM POLLIN
#define POLLRDBAND POLLIN
#define POLLWRNORM POLLOUT
#define POLLWRBAND POLLOUT
/* ignored */
#define POLLHUP 0x0010
#define POLLNVAL 0x0020
int poll(struct pollfd *pollSet, int pollCount, int pollTimeout)
{
struct timeval tv;
struct timeval *tvp;
fd_set readFDs, writeFDs, exceptFDs;
fd_set *readp, *writep, *exceptp;
struct pollfd *pollEnd, *p;
int selected;
int result;
int maxFD;
if (!pollSet) {
pollEnd = NULL;
readp = NULL;
writep = NULL;
exceptp = NULL;
maxFD = 0;
} else {
pollEnd = pollSet + pollCount;
readp = &readFDs;
writep = &writeFDs;
exceptp = &exceptFDs;
FD_ZERO(readp);
FD_ZERO(writep);
FD_ZERO(exceptp);
/* Find the biggest fd in the poll set */
maxFD = 0;
for (p = pollSet; p < pollEnd; p++) {
if (p->fd > maxFD) maxFD = p->fd;
}
if (maxFD >= OPEN_MAX) {
/* At least one fd is too big */
errno = EINVAL;
return -1;
}
/* Transcribe flags from the poll set to the fd sets */
for (p = pollSet; p < pollEnd; p++) {
if (p->fd < 0) {
/* Negative fd checks nothing and always reports zero */
} else {
if (p->events & POLLIN) FD_SET(p->fd, readp);
if (p->events & POLLOUT) FD_SET(p->fd, writep);
if (p->events != 0) FD_SET(p->fd, exceptp);
/* POLLERR is never set coming in; poll() always reports errors */
/* But don't report if we're not listening to anything at all. */
}
}
}
/* poll timeout is in milliseconds. Convert to struct timeval. */
/* poll timeout == -1 : wait forever : select timeout of NULL */
/* poll timeout == 0 : return immediately : select timeout of zero */
if (pollTimeout >= 0) {
tv.tv_sec = pollTimeout / 1000;
tv.tv_usec = (pollTimeout % 1000) * 1000;
tvp = &tv;
} else {
tvp = NULL;
}
selected = select(maxFD+1, readp, writep, exceptp, tvp);
if (selected < 0) {
/* Error during select */
result = -1;
} else if (selected > 0) {
/* Select found something */
/* Transcribe result from fd sets to poll set. */
/* Also count the number of selected fds. poll returns the */
/* number of ready fds; select returns the number of bits set. */
int polled = 0;
for (p = pollSet; p < pollEnd; p++) {
p->revents = 0;
if (p->fd < 0) {
/* Negative fd always reports zero */
} else {
if ((p->events & POLLIN) && FD_ISSET(p->fd, readp)) {
p->revents |= POLLIN;
}
if ((p->events & POLLOUT) && FD_ISSET(p->fd, writep)) {
p->revents |= POLLOUT;
}
if ((p->events != 0) && FD_ISSET(p->fd, exceptp)) {
p->revents |= POLLERR;
}
if (p->revents) polled++;
}
}
result = polled;
} else {
/* selected == 0, select timed out before anything happened */
/* Clear all result bits and return zero. */
for (p = pollSet; p < pollEnd; p++) {
p->revents = 0;
}
result = 0;
}
return result;
}
#endif /* _FAKE_POLL_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,171 @@
/* vim:set sw=4 sts=4 et: */
/* for ptsname_r */
#if defined __ANDROID__
# define _GNU_SOURCE
#endif
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#if defined __sun__
# include <stropts.h>
#endif
#include <unistd.h>
#include <termios.h>
#include "ptytty.h"
static int
ptsname_compat(int fd, char **buf)
{
#if defined __ANDROID__
static char b[16];
if (ptsname_r(fd, b, sizeof(b)) == -1)
return -1;
*buf = b;
#else
if ((*buf = ptsname(fd)) == NULL)
return -1;
#endif
return 0;
}
static int
_internal_get_pty(int *master, char **path)
{
if ((*master = open("/dev/ptmx", O_RDWR|O_NOCTTY)) == -1)
return -1;
if (grantpt(*master) != 0)
return -1;
if (unlockpt(*master) != 0)
return -1;
if (ptsname_compat(*master, path) == -1)
return -1;
return 0;
}
static int
_internal_get_tty(int *slave, const char *path,
struct termios *termp, struct winsize *winp, int ctty)
{
if (path != NULL) {
if ((*slave = open(path, O_RDWR|O_NOCTTY)) == -1)
return -1;
}
#ifdef TIOCSCTTY
if (ctty && ioctl(*slave, TIOCSCTTY, NULL) == -1)
return -1;
#endif
#ifdef I_PUSH
if (ioctl(*slave, I_PUSH, "ptem") == -1)
return -1;
if (ioctl(*slave, I_PUSH, "ldterm") == -1)
return -1;
#if defined __sun__
if (ioctl(*slave, I_PUSH, "ttcompat") == -1)
return -1;
#endif
#endif
if (termp != NULL)
tcsetattr(*slave, TCSAFLUSH, termp);
if (winp != NULL)
ioctl(*slave, TIOCSWINSZ, winp);
return 0;
}
static int
_internal_login_tty(int fd, const char *path,
struct termios *termp, struct winsize *winp)
{
setsid();
if (_internal_get_tty(&fd, path, termp, winp, 1) != 0)
return -1;
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
if (fd > 2)
close(fd);
return 0;
}
int
openpty(int *amaster, int *aslave, char *name,
struct termios *termp, struct winsize *winp)
{
char *path = NULL;
int master = -1, slave = -1;
if (amaster == NULL || aslave == NULL)
return -1;
if (_internal_get_pty(&master, &path) != 0)
goto out;
if (_internal_get_tty(&slave, path, termp, winp, 0) != 0)
goto out;
if (name != NULL)
strcpy(name, path);
*amaster = master;
*aslave = slave;
return 0;
out:
if (master != -1)
close(master);
if (slave != -1)
close(slave);
return -1;
}
int
forkpty(int *amaster, char *name,
struct termios *termp, struct winsize *winp)
{
char *path;
int master = -1;
pid_t pid;
if (amaster == NULL)
return -1;
if (_internal_get_pty(&master, &path) != 0)
goto out;
if (name != NULL)
strcpy(name, path);
if ((pid = fork()) == -1)
goto out;
if (pid == 0) {
close(master);
if (_internal_login_tty(-1, path, termp, winp) != 0)
_exit(EXIT_FAILURE);
return 0;
}
*amaster = master;
return pid;
out:
if (master != -1)
close(master);
return -1;
}
int
login_tty(int fd)
{
return _internal_login_tty(fd, NULL, NULL, NULL);
}

View File

@ -0,0 +1,10 @@
#ifndef VP_PTYTTY_H_
#define VP_PTYTTY_H_
#include <termios.h>
int openpty(int *, int *, char *, struct termios *, struct winsize *);
int forkpty(int *, char *, struct termios *, struct winsize *);
int login_tty(int);
#endif /* VP_PTYTTY_H_ */

View File

@ -0,0 +1,295 @@
/* 2006-06-23
* vim:set sw=4 sts=4 et:
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdarg.h>
#include <errno.h>
/*
* Function arguments and return values are stored in stack. Each value consists of DataSize, Data,
* and EOV. DataSize is a 32-bit integer encoded into a 5-byte string.
* Number should be stored as String.
*
* Return values not started with EOV are error message, except NULL
* which indicates no result.
*
* Successful Result:
* EOV | DataSize0, Data0, EOV | DataSize1, Data1, EOV | ... | NUL
* or
* NULL
*
* Error Result:
* String
*/
/* End Of Value */
#define VP_EOV '\xFF'
#define VP_EOV_STR "\xFF"
#define VP_NUM_BUFSIZE 64
#define VP_NUMFMT_BUFSIZE 16
#define VP_INITIAL_BUFSIZE 512
#define VP_ERRMSG_SIZE 512
#define VP_HEADER_SIZE 5
#define VP_RETURN_IF_FAIL(expr) \
do { \
const char *vp_err = expr; \
if (vp_err) return vp_err; \
} while (0)
/* buf:|EOV|var|var|top:free buffer|buf+size */
typedef struct vp_stack_t {
size_t size; /* stack size */
char *buf; /* stack buffer */
char *top; /* stack top */
} vp_stack_t;
/* use for initialize */
#define VP_STACK_NULL {0, NULL, NULL}
static const char CHR2XD[0x100] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00 - 0x0F */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10 - 0x1F */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20 - 0x2F */
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0x30 - 0x3F */
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40 - 0x4F */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50 - 0x5F */
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x6F */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x7F */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80 - 0x8F */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x90 - 0x9F */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xA0 - 0xAF */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xB0 - 0xBF */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xC0 - 0xCF */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xD0 - 0xDF */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xE0 - 0xEF */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0xF0 - 0xFF */
};
#if 0
static const char *XD2CHR =
"00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A" "0B" "0C" "0D" "0E" "0F"
"10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "1A" "1B" "1C" "1D" "1E" "1F"
"20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "2A" "2B" "2C" "2D" "2E" "2F"
"30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "3A" "3B" "3C" "3D" "3E" "3F"
"40" "41" "42" "43" "44" "45" "46" "47" "48" "49" "4A" "4B" "4C" "4D" "4E" "4F"
"50" "51" "52" "53" "54" "55" "56" "57" "58" "59" "5A" "5B" "5C" "5D" "5E" "5F"
"60" "61" "62" "63" "64" "65" "66" "67" "68" "69" "6A" "6B" "6C" "6D" "6E" "6F"
"70" "71" "72" "73" "74" "75" "76" "77" "78" "79" "7A" "7B" "7C" "7D" "7E" "7F"
"80" "81" "82" "83" "84" "85" "86" "87" "88" "89" "8A" "8B" "8C" "8D" "8E" "8F"
"90" "91" "92" "93" "94" "95" "96" "97" "98" "99" "9A" "9B" "9C" "9D" "9E" "9F"
"A0" "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "AA" "AB" "AC" "AD" "AE" "AF"
"B0" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" "B9" "BA" "BB" "BC" "BD" "BE" "BF"
"C0" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "CA" "CB" "CC" "CD" "CE" "CF"
"D0" "D1" "D2" "D3" "D4" "D5" "D6" "D7" "D8" "D9" "DA" "DB" "DC" "DD" "DE" "DF"
"E0" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "EA" "EB" "EC" "ED" "EE" "EF"
"F0" "F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "FA" "FB" "FC" "FD" "FE" "FF";
#endif
static void vp_stack_free(vp_stack_t *stack);
static const char *vp_stack_from_args(vp_stack_t *stack, char *args);
static const char *vp_stack_return(vp_stack_t *stack);
static const char *vp_stack_return_error(vp_stack_t *stack, const char *fmt, ...);
static const char *vp_stack_reserve(vp_stack_t *stack, size_t needsize);
static const char *vp_stack_pop_num(vp_stack_t *stack, const char *fmt, void *ptr);
static const char *vp_stack_pop_str(vp_stack_t *stack, char **str);
static const char *vp_stack_push_num(vp_stack_t *stack, const char *fmt, ...);
static const char *vp_stack_push_str(vp_stack_t *stack, const char *str);
#define vp_stack_used(stack) ((stack)->top - (stack)->buf)
/* Encode a 32-bit integer into a 5-byte string. */
static char *
vp_encode_size(unsigned int size, char *buf)
{
if (buf == NULL)
return NULL;
buf[0] = ((size >> 28) & 0x7f) | 0x80;
buf[1] = ((size >> 21) & 0x7f) | 0x80;
buf[2] = ((size >> 14) & 0x7f) | 0x80;
buf[3] = ((size >> 7) & 0x7f) | 0x80;
buf[4] = ( size & 0x7f) | 0x80;
return buf;
}
/* Decode a 32-bit integer from a 5-byte string. */
unsigned int
vp_decode_size(const char *buf)
{
if (buf == NULL)
return 0;
return ((unsigned int) (buf[0] & 0x7f) << 28)
+ ((unsigned int) (buf[1] & 0x7f) << 21)
+ ((unsigned int) (buf[2] & 0x7f) << 14)
+ ((unsigned int) (buf[3] & 0x7f) << 7)
+ ((unsigned int) (buf[4] & 0x7f));
}
static void
vp_stack_free(vp_stack_t *stack)
{
if (stack->buf != NULL) {
free((void *)stack->buf);
stack->size = 0;
stack->buf = NULL;
stack->top = NULL;
}
}
/* make readonly stack from arguments */
static const char *
vp_stack_from_args(vp_stack_t *stack, char *args)
{
if (args == NULL || args[0] == '\0') {
stack->size = 0;
stack->buf = NULL;
stack->top = NULL;
} else {
stack->size = strlen(args); /* don't count end of NUL. */
stack->buf = args;
stack->top = stack->buf;
if (stack->top[0] != VP_EOV)
return "vp_stack_from_buf: no EOV";
stack->top++;
}
return NULL;
}
/* clear stack top and return stack buffer */
static const char *
vp_stack_return(vp_stack_t *stack)
{
size_t needsize;
const char *ret;
/* add the last EOV and NUL */
needsize = vp_stack_used(stack) + 1;
ret = vp_stack_reserve(stack, needsize);
if (ret != NULL)
return ret;
stack->top[0] = VP_EOV;
stack->top[1] = '\0';
/* Clear the stack. */
stack->top = stack->buf;
return stack->buf;
}
/* push error message and return */
static const char *
vp_stack_return_error(vp_stack_t *stack, const char *fmt, ...)
{
va_list ap;
size_t needsize;
int ret;
/* Initialize buffer */
stack->top = stack->buf;
needsize = VP_ERRMSG_SIZE;
if (vp_stack_reserve(stack, needsize) != NULL)
return fmt;
va_start(ap, fmt);
ret = vsnprintf(stack->top, stack->size, fmt, ap);
stack->top[ret] = '\0';
va_end(ap);
/* Clear the stack. */
stack->top = stack->buf;
return stack->buf;
}
/* ensure stack buffer is needsize or more bytes */
static const char *
vp_stack_reserve(vp_stack_t *stack, size_t needsize)
{
if (needsize > stack->size) {
size_t newsize;
char *newbuf;
newsize = (stack->size == 0) ? VP_INITIAL_BUFSIZE : (stack->size * 2);
while (needsize > newsize) {
newsize *= 2;
if (newsize <= stack->size) /* paranoid check */
return "vp_stack_reserve: too big";
}
if ((newbuf = (char *)realloc(stack->buf, newsize)) == NULL)
return "vp_stack_reserve: NOMEM";
stack->top = newbuf + vp_stack_used(stack);
stack->buf = newbuf;
stack->size = newsize;
}
return NULL;
}
static const char *
vp_stack_pop_num(vp_stack_t *stack, const char *fmt, void *ptr)
{
char *str;
const char *ret;
if ((size_t)vp_stack_used(stack) == stack->size)
return "vp_stack_pop_num: stack empty";
ret = vp_stack_pop_str(stack, &str);
if (ret != NULL)
return ret;
if (sscanf(str, fmt, ptr) != 1)
return "vp_stack_pop_num: sscanf error";
return NULL;
}
/* str will be invalid after vp_stack_push_*() */
static const char *
vp_stack_pop_str(vp_stack_t *stack, char **str)
{
unsigned int size;
if ((size_t)vp_stack_used(stack) == stack->size)
return "vp_stack_pop_str: stack empty";
size = vp_decode_size(stack->top);
*str = stack->top + VP_HEADER_SIZE;
stack->top += VP_HEADER_SIZE + size + 1;
stack->top[-1] = '\0'; /* Overwrite EOV. */
return NULL;
}
static const char *
vp_stack_push_num(vp_stack_t *stack, const char *fmt, ...)
{
va_list ap;
char buf[VP_NUM_BUFSIZE];
va_start(ap, fmt);
if (vsprintf(buf, fmt, ap) < 0) {
va_end(ap);
return "vp_stack_push_num: vsprintf error";
}
va_end(ap);
return vp_stack_push_str(stack, buf);
}
static const char *
vp_stack_push_str(vp_stack_t *stack, const char *str)
{
size_t needsize;
unsigned int size;
size = strlen(str);
needsize = vp_stack_used(stack) + 1 + VP_HEADER_SIZE + size + 1;
VP_RETURN_IF_FAIL(vp_stack_reserve(stack, needsize));
stack->top[0] = VP_EOV; /* Set previous EOV. */
sprintf(stack->top + 1 + VP_HEADER_SIZE, "%s", str);
vp_encode_size(size, stack->top + 1);
stack->top += 1 + VP_HEADER_SIZE + size;
stack->top[0] = '\0';
return NULL;
}

View File

@ -0,0 +1,177 @@
let s:suite = themis#suite('fopen')
let s:assert = themis#helper('assert')
call themis#helper('command').with(s:)
let s:filename = 'test.txt'
let s:contents = ['foo', 'bar']
function! s:suite.before_each() abort
call writefile(s:contents, s:filename, 'b')
endfunction
function! s:suite.after_each() abort
if filereadable(s:filename)
call delete(s:filename)
endif
endfunction
function! s:suite.read() abort
let file = vimproc#fopen(s:filename)
let res = file.read()
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ split(res, '\r\n\|\r\|\n'))
endfunction
function! s:suite.read_lines() abort
let file = vimproc#fopen(s:filename, 'r')
let res = file.read_lines()
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename, 'b'), res)
endfunction
function! s:suite.read_line() abort
let file = vimproc#fopen(s:filename, 'r', 0)
let res = []
while !file.eof
let res += [file.read_line()]
endwhile
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(readfile(s:filename), res)
endfunction
function! s:suite.write() abort
let file = vimproc#fopen(s:filename, 'w')
let res = "hello\nvimproc\n.vim"
call s:assert.true(file.is_valid)
call file.write(res)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ split(res, '\r\n\|\r\|\n'))
endfunction
function! s:suite.append() abort
let file = vimproc#fopen(s:filename, 'a')
let res = "\nhello\nvimproc\n.vim"
call s:assert.true(file.is_valid)
call file.write(res)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ s:contents + split(res, '\r\n\|\r\|\n'))
endfunction
function! s:suite.read_write() abort
let file = vimproc#fopen(s:filename, 'r+')
let res = file.read()
call s:assert.equals(
\ readfile(s:filename),
\ split(res, '\r\n\|\r\|\n'))
call s:assert.true(file.is_valid)
let res = "\nhello\nvimproc\n.vim"
call file.write(res)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ s:contents + split(res, '\r\n\|\r\|\n'))
endfunction
function! s:suite.with_oflag() abort
let file = vimproc#fopen(s:filename, 'O_RDONLY')
let res = file.read()
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ split(res, '\r\n\|\r\|\n'))
let file = vimproc#fopen(s:filename, 'O_WRONLY|O_TRUNC')
let res = "hello\nvimproc\n.vim"
call file.write(res)
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ split(res, '\r\n\|\r\|\n'))
let file = vimproc#fopen(s:filename, 'O_RDWR|O_APPEND')
let res2 = "\nworld\n!"
call file.write(res2)
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ split(res . res2, '\r\n\|\r\|\n'))
endfunction
function! s:suite.invalid_fmode() abort
let file = vimproc#fopen(s:filename, 'r')
Throws /write() error/ file.write('foo')
call file.close()
call s:assert.equals(readfile(s:filename), s:contents)
let file = vimproc#fopen(s:filename, 'w')
Throws /read() error/ file.read()
call file.close()
call s:assert.true(empty(readfile(s:filename)))
endfunction
" vim:foldmethod=marker:fen:

View File

@ -0,0 +1,10 @@
let s:suite = themis#suite('functions')
let s:assert = themis#helper('assert')
function! s:suite.functions() abort
let errmsg_save = v:exception
call s:assert.true(vimproc#kill(9999, 0))
call s:assert.not_equals(errmsg_save, vimproc#get_last_errmsg())
endfunction
" vim:foldmethod=marker:fen:

View File

@ -0,0 +1,20 @@
let s:suite = themis#suite('lexer')
let s:assert = themis#helper('assert')
function! s:suite.token() abort
let lex = vimproc#lexer#init_lexer('1234 5678')
call s:assert.true(lex.advance())
call s:assert.equals(lex.token(), g:vimproc#lexer#token_type.int)
call s:assert.true(lex.advance())
call s:assert.equals(lex.token(), g:vimproc#lexer#token_type.int)
endfunction
function! s:suite.value() abort
let lex = vimproc#lexer#init_lexer('1234 5678')
call s:assert.true(lex.advance())
call s:assert.equals(lex.value(), 1234)
call s:assert.true(lex.advance())
call s:assert.equals(lex.value(), 5678)
endfunction
" vim:foldmethod=marker:fen:

View File

@ -0,0 +1,97 @@
let s:suite = themis#suite('parser')
let s:assert = themis#helper('assert')
function! s:suite.escape() abort
call s:assert.equals(
\ vimproc#parser#split_args('echo "\""'),
\ ['echo', '"'])
call s:assert.equals(
\ vimproc#parser#split_args('echo "\`test\`"'),
\ ['echo', '`test`'])
call s:assert.equals(vimproc#shellescape('hoge'), "'hoge'")
call s:assert.equals(vimproc#shellescape('ho''ge'), "'ho''ge'")
endfunction
function! s:suite.comment() abort
call s:assert.equals(
\ vimproc#parser#split_args('echo file#1.txt'),
\ ['echo', 'file#1.txt'])
call s:assert.equals(
\ vimproc#parser#split_args('echo file #1.txt'),
\ ['echo', 'file'])
endfunction
function! s:suite.quote() abort
let is_catched = 0
try
call vimproc#parser#split_args('echo "\"')
catch /^Exception: Quote/
let is_catched = 1
endtry
call s:assert.equals(is_catched, 1)
endfunction
function! s:suite.join() abort
let is_catched = 0
try
call vimproc#parser#split_args('echo \')
catch /^Exception: Join to next line/
let is_catched = 1
endtry
call s:assert.equals(is_catched, 1)
endfunction
function! s:suite.parse_statements() abort
let statements =
\ vimproc#parser#split_statements(
\ '"/usr/bin/clang++" --std=c++0x `pkg-config'.
\ ' --libs opencv` "/home/me/opencv/capture.cpp"'.
\ ' -o "/home/me/opencv/capture" && "/home/me/opencv/capture"')
call s:assert.equals(statements,
\ ['"/usr/bin/clang++" --std=c++0x `pkg-config'.
\ ' --libs opencv` "/home/me/opencv/capture.cpp"'.
\ ' -o "/home/me/opencv/capture" ', ' "/home/me/opencv/capture"'
\ ])
endfunction
function! s:suite.backquote() abort
call s:assert.equals(
\ vimproc#parser#split_args('echo `echo "hoge" "piyo" "hogera"`'),
\ [ 'echo', 'hoge', 'piyo', 'hogera' ])
call s:assert.equals(
\ vimproc#parser#split_args(
\ 'echo "`curl -fs https://gist.github.com/raw/4349265/sudden-vim.py`"'),
\ [ 'echo', system('curl -fs https://gist.github.com/raw/4349265/sudden-vim.py')])
endfunction
function! s:suite.slash_convertion() abort
" For Vital.DateTime
call s:assert.equals(vimproc#parser#split_args(
\ printf('reg query "%s" /v Bias',
\ 'HKLM\System\CurrentControlSet\Control\TimeZoneInformation')),
\ ['reg', 'query',
\ 'HKLM\System\CurrentControlSet\Control\TimeZoneInformation',
\ '/v', 'Bias'])
endfunction
function! s:suite.block_convertion() abort
call s:assert.equals(vimproc#parser#parse_pipe(
\ 'grep -inH --exclude-dir={foo} -R vim .')[0].args,
\ ['grep', '-inH',
\ '--exclude-dir=f', '--exclude-dir=o',
\ '-R', 'vim', '.'])
call s:assert.equals(vimproc#parser#parse_pipe(
\ 'grep -inH --exclude-dir={foo,bar,baz} -R vim .')[0].args,
\ ['grep', '-inH',
\ '--exclude-dir=foo', '--exclude-dir=bar', '--exclude-dir=baz',
\ '-R', 'vim', '.'])
endfunction
function! s:suite.parse_redirection() abort
call s:assert.equals(vimproc#parser#parse_pipe(
\ 'echo "foo" > hoge\piyo'),
\ [{ 'args' : ['echo', 'foo'], 'fd' :
\ { 'stdin' : '', 'stdout' : 'hogepiyo', 'stderr' : '' }}])
endfunction
" vim:foldmethod=marker:fen:

View File

@ -0,0 +1,122 @@
let s:suite = themis#suite('popen')
let s:assert = themis#helper('assert')
function! s:suite.popen2() abort
if !vimproc#util#is_windows() && !executable('ls')
call s:assert.skip('ls command is not installed.')
return
endif
if vimproc#util#is_windows()
let cmd = ['cmd', '/c', 'DIR', '/B']
else
let cmd = ['ls']
endif
let sub = vimproc#popen2(cmd)
let res = ''
while !sub.stdout.eof
let res .= sub.stdout.read()
endwhile
" Newline conversion.
let res = substitute(res, '\r\n', '\n', 'g')
call s:assert.true(sub.is_valid)
let [cond, status] = sub.waitpid()
call s:assert.equals(cond, 'exit')
call s:assert.equals(status, 0)
call s:assert.false(sub.is_valid)
call s:assert.equals(res, system(join(cmd)))
unlet cmd
unlet sub
if vimproc#util#is_windows()
let cmd = ['cmd', '/c', 'DIR', '/B', '/A']
else
let cmd = ['ls', '-la']
endif
let sub = vimproc#popen2(cmd)
let res = ''
while !sub.stdout.eof
let res .= sub.stdout.read()
endwhile
" Newline conversion.
let res = substitute(res, '\r\n', '\n', 'g')
call s:assert.true(sub.is_valid)
let [cond, status] = sub.waitpid()
call s:assert.equals(cond, 'exit')
call s:assert.equals(status, 0)
call s:assert.false(sub.is_valid)
call s:assert.equals(res, system(join(cmd)))
unlet cmd
unlet sub
endfunction
function! s:suite.popen3() abort
if vimproc#util#is_windows()
let cmd = ['cmd', '/c', 'DIR', '/B']
else
let cmd = ['ls']
endif
let sub = vimproc#popen3(cmd)
let res = ''
while !sub.stdout.eof
let res .= sub.stdout.read()
endwhile
" Newline conversion.
let res = substitute(res, '\r\n', '\n', 'g')
call s:assert.true(sub.is_valid)
let [cond, status] = sub.waitpid()
call s:assert.equals(cond, 'exit')
call s:assert.equals(status, 0)
call s:assert.false(sub.is_valid)
call s:assert.equals(res, system(join(cmd)))
unlet cmd
unlet sub
endfunction
function! s:suite.redirection1() abort
let output = vimproc#system('echo "foo" > test.txt | echo "bar"')
call s:assert.equals(output, "bar\n")
sleep 3
call s:assert.equals(readfile('test.txt'), ['foo'])
if filereadable('test.txt')
call delete('test.txt')
endif
endfunction
function! s:suite.redirection2() abort
let sub = vimproc#ptyopen('echo "foo" > test.txt | echo "bar"')
let res = ''
while !sub.stdout.eof
let res .= sub.stdout.read()
endwhile
" Newline conversion.
let res = substitute(res, '\r\n', '\n', 'g')
sleep 3
call s:assert.equals(readfile('test.txt'), ['foo'])
if filereadable('test.txt')
call delete('test.txt')
endif
endfunction
" vim:foldmethod=marker:fen:

View File

@ -0,0 +1,30 @@
let s:suite = themis#suite('socket')
let s:assert = themis#helper('assert')
function! s:suite.socket() abort
call s:assert.true(vimproc#host_exists(
\ 'www.yahoo.com'))
call s:assert.true(vimproc#host_exists(
\ 'https://www.yahoo.com'))
call s:assert.true(vimproc#host_exists(
\ 'https://www.yahoo.com/hoge/piyo'))
let sock = vimproc#socket_open('www.yahoo.com', 80)
call sock.write("GET / HTTP/1.0\r\n\r\n", 100)
let res = ''
let out = sock.read(-1, 100)
while !sock.eof && out != ''
let out = sock.read(-1, 100)
let res .= out
endwhile
call s:assert.true(sock.is_valid)
call sock.close()
call s:assert.false(sock.is_valid)
echo res
endfunction
" vim:foldmethod=marker:fen:

View File

@ -0,0 +1,87 @@
let s:suite = themis#suite('system')
let s:assert = themis#helper('assert')
function! s:check_ls() abort
if !executable('ls')
call s:assert.skip('ls command is not installed.')
endif
endfunction
function! s:suite.system1() abort
call s:check_ls()
call s:assert.equals(vimproc#system('ls'), system('ls'))
endfunction
function! s:suite.system2() abort
call s:check_ls()
call s:assert.equals(vimproc#system(['ls']), system('ls'))
endfunction
function! s:suite.cmd_system1() abort
call s:check_ls()
call s:assert.equals(vimproc#cmd#system('ls'), system('ls'))
endfunction
function! s:suite.cmd_system2() abort
call s:check_ls()
call s:assert.equals(vimproc#cmd#system(['ls']), system('ls'))
endfunction
function! s:suite.cmd_system3() abort
call s:assert.equals(
\ vimproc#cmd#system(['echo', '"Foo"']),
\ "\"Foo\"\n")
endfunction
function! s:suite.system_passwd1() abort
if vimproc#util#is_windows()
call s:assert.skip('')
endif
call s:assert.equals(
\ vimproc#system_passwd('echo -n test'),
\ system('echo -n test'))
endfunction
function! s:suite.system_passwd2() abort
if vimproc#util#is_windows()
call s:assert.skip('')
endif
call s:assert.equals(
\ vimproc#system_passwd(['echo', '-n', 'test']),
\ system('echo -n test'))
endfunction
function! s:suite.system_and1() abort
if vimproc#util#is_windows()
call s:assert.skip('')
endif
call s:check_ls()
call s:assert.equals(vimproc#system('ls&'), '')
endfunction
function! s:suite.system_and2() abort
if vimproc#util#is_windows()
call s:assert.skip('')
endif
call s:check_ls()
call s:assert.equals(vimproc#system('ls&'),
\ vimproc#system_bg('ls'))
endfunction
function! s:suite.system_bg1() abort
call s:check_ls()
call s:assert.equals(vimproc#system_bg('ls'), '')
endfunction
function! s:suite.system_bg2() abort
call s:check_ls()
call s:assert.equals(vimproc#system_bg(['ls']), '')
endfunction
function! s:suite.password_pattern() abort
call s:assert.match(
\ 'Enter passphrase for key ''.ssh/id_rsa''',
\ g:vimproc_password_pattern)
endfunction
" vim:foldmethod=marker:fen:

View File

@ -0,0 +1,130 @@
@echo off
:: Batch file for building/testing vimproc on AppVeyor
cd %APPVEYOR_BUILD_FOLDER%
if /I "%1"=="test" (
set _target=_test
) else (
set _target=
)
for %%i in (msvc mingw msys2 cygwin) do if "%compiler%"=="%%i" goto %compiler%%_target%
echo Unknown build target.
exit 1
:msvc
:: ----------------------------------------------------------------------
:: Using VC10 with nmake
::call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" %ARCH%
call :install_vim
call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" %ENV%
@echo on
nmake -f make_msvc.mak CPU=%CPU% cflags=/MD
@echo off
goto :eof
:msvc_test
set THEMIS_VIM=%APPVEYOR_BUILD_FOLDER%\vim-kaoriya\vim.exe
@echo on
themis\bin\themis
@echo off
goto :eof
:mingw
:: ----------------------------------------------------------------------
:: Using MinGW
call :install_vim
@echo on
path C:\MinGW\bin;C:\MinGW\msys\1.0\bin;%path%
make -f make_mingw32.mak
@echo off
goto :eof
:mingw_test
set THEMIS_VIM=%APPVEYOR_BUILD_FOLDER%\vim-kaoriya\vim.exe
@echo on
themis\bin\themis
@echo off
goto :eof
:msys2
:: ----------------------------------------------------------------------
:: Using MSYS2
call :install_vim
@echo on
PATH C:\%MSYS2_DIR%\%MSYSTEM%\bin;C:\%MSYS2_DIR%\usr\bin;%PATH%
set CHERE_INVOKING=yes
:: Install and update necessary packages
rem bash -lc "for i in {1..3}; do update-core && break || sleep 15; done"
rem bash -lc "for i in {1..3}; do pacman --noconfirm -Su mingw-w64-%MSYS2_ARCH%-{gcc,make} make && break || sleep 15; done"
bash -lc "make"
@echo off
goto :eof
:msys2_test
set THEMIS_VIM=%APPVEYOR_BUILD_FOLDER%\vim-kaoriya\vim.exe
@echo on
themis\bin\themis
@echo off
goto :eof
:cygwin
:: ----------------------------------------------------------------------
:: Using Cygwin
@echo on
goto cygwin%BIT%
:cygwin32
@echo on
c:\cygwin\setup-x86.exe -qnNdO -R C:/cygwin -s http://cygwin.mirror.constant.com -l C:/cygwin/var/cache/setup -P vim
PATH c:\cygwin\bin;%PATH%
set CHERE_INVOKING=yes
bash -lc ""
bash -lc "make"
@echo off
goto :eof
:cygwin64
@echo on
c:\cygwin64\setup-x86_64.exe -qnNdO -R C:/cygwin64 -s http://cygwin.mirror.constant.com -l C:/cygwin/var/cache/setup -P vim
PATH c:\cygwin64\bin;%PATH%
set CHERE_INVOKING=yes
bash -lc ""
bash -lc "make"
@echo off
goto :eof
:cygwin_test
@echo on
rem bash -lc "git clone -q https://github.com/thinca/vim-themis.git themis --depth=1"
rem bash -lc "themis/bin/themis"
@echo off
goto :eof
:install_vim
:: ----------------------------------------------------------------------
:: Install Vim and themis
echo Downloading Vim
py tools\dl-kaoriya-vim.py --arch win%BIT% --filename vim.zip
echo Installing Vim
7z x vim.zip > nul
move vim??-kaoriya-win%BIT% vim-kaoriya
git clone -q https://github.com/thinca/vim-themis.git themis --depth=1
exit /b

View File

@ -0,0 +1,17 @@
let cnt = 25
let start = reltime()
for i in range(1, cnt)
call system('ls')
endfor
echomsg 'system() = ' . reltimestr(reltime(start))
let start = reltime()
for i in range(1, cnt)
call vimproc#system('ls')
endfor
echomsg 'vimproc#system() = ' . reltimestr(reltime(start))

View File

@ -0,0 +1,136 @@
#!/usr/bin/python3
# Download the latest KaoriYa Vim from the GitHub releases
import argparse
import calendar
import io
import json
import os
import sys
import time
import urllib.request, urllib.error
# Repository Name
repo_name = 'koron/vim-kaoriya'
gh_releases_url = 'https://api.github.com/repos/' + repo_name + '/releases'
# Asset name checker
def does_skip_asset(asset):
return asset['name'].find('pdb') >= 0
# Arguments properties
arg_desc = 'Download the latest KaoriYa Vim from the GitHub releases'
arg_archs = ['all', 'win32', 'win64']
arg_default_arch = 'all'
arg_allow_prerelease = False
# Parse arguments
def parse_args():
global parser
parser = argparse.ArgumentParser(description=arg_desc)
parser.add_argument('-c', '--check', action='store_true',
help='only check the information of the latest release')
parser.add_argument('--noprogress', action='store_true',
help="Don't show the progress")
parser.add_argument('-f', '--force', action='store_true',
help='overwrite the download file')
parser.add_argument('-n', '--filename', type=str, action='store',
help='filename to save')
parser.add_argument('-p', '--prerelease', action='store_true',
default=arg_allow_prerelease,
help='Allow downloading prerelease')
parser.add_argument('-a', '--arch', type=str, action='store',
choices=arg_archs, default=arg_default_arch,
help='architecture to download')
parser.add_argument('--auth', type=str, action='store',
default=os.getenv('AUTH_TOKEN'),
metavar="TOKEN", help='GitHub API token (Environment variable AUTH_TOKEN can be also used.)')
return parser.parse_args()
# Get information of GitHub release
# see: https://developer.github.com/v3/repos/releases/
def get_rel_info(url, auth):
if auth:
# Unauthenticated requests are limited up to 60 requests per hour.
# Authenticated requests are allowed up to 5,000 requests per hour.
# See: https://developer.github.com/v3/#rate-limiting
request = urllib.request.Request(url)
request.add_header("Authorization", "token " + auth)
else:
request = url
try:
response = urllib.request.urlopen(request)
except urllib.error.HTTPError as err:
print('GitHub release not found. (%s)' % err.reason, file=sys.stderr)
exit(1)
return json.load(io.StringIO(str(response.read(), 'utf-8')))
# Show progress
def reporthook(count, blocksize, totalsize):
size = count * blocksize
if totalsize <= 0:
print("\r{:,}".format(size))
else:
size = min(size, totalsize)
print("\r{:,} / {:,} ({:.1%})".format(size, totalsize, size / totalsize), end='')
# Download the files
def download(args, rel_info):
for asset in rel_info['assets']:
if args.filename:
name = args.filename
else:
name = asset['name']
if does_skip_asset(asset):
continue
if args.arch != 'all' and asset['name'].find(args.arch) < 0:
continue
if os.path.isfile(name) and not args.force:
print('File exists:', name)
continue
print('Downloading from:', asset['browser_download_url'])
print('Downloading to:', name)
if args.noprogress:
hook = None
else:
hook = reporthook
urllib.request.urlretrieve(asset['browser_download_url'], name, hook)
# Set timestamp
asset_time = time.strptime(asset['updated_at'], '%Y-%m-%dT%H:%M:%SZ')
os.utime(name, times=(time.time(), calendar.timegm(asset_time)))
if not args.noprogress:
print()
def main():
args = parse_args()
if args.filename and args.arch == 'all':
parser.error('-a must be specified when you specify -n.')
if args.prerelease:
rels_info = get_rel_info(gh_releases_url, args.auth)
for rel in rels_info:
if rel['draft']:
continue
gh_release_url = rel['url']
break
else:
print('GitHub release not found.', file=sys.stderr)
exit(1)
else:
gh_release_url = gh_releases_url + '/latest'
rel_info = get_rel_info(gh_release_url, args.auth)
print('Last release:', rel_info['name'])
print('Created at:', rel_info['created_at'])
if args.check:
exit(0)
download(args, rel_info)
exit(0)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,16 @@
import os
import sys
import time
# Create new process
pid = os.fork()
# Print text
c = 'p' if pid == 0 else 'c'
if pid == 0:
sys.exit(0)
while True:
time.sleep(1)
sys.stderr.write(c)

View File

@ -0,0 +1,21 @@
" Resource leak checker.
let max = 2048
for i in range(1, max)
redraw
echo i.'/'.max
call vimproc#system('ls | head -20')
endfor
for i in range(1, max)
redraw
echo i.'/'.max
let process = vimproc#pgroup_open('ls')
while !process.stdout.eof
call process.stdout.read(-1)
endwhile
let [_, status] = process.waitpid()
endfor

View File

@ -0,0 +1,20 @@
" Resource leak checker version2(for process group).
let pwd = fnamemodify(expand('<sfile>'), ':p:h')
let process = vimproc#pgroup_open('python ' . pwd . '/fork.py')
call process.waitpid()
" call process.kill()
let process = vimproc#pgroup_open('ls && ls')
while !process.stdout.eof
call process.stdout.read(-1)
endwhile
call process.waitpid()
if executable('ps')
echomsg string(split(system('ps -eo pid,pgid,sid,args | grep defunct'), '\n'))
echomsg 'Current pid = ' . getpid()
endif

View File

@ -0,0 +1,51 @@
@echo off
rem Update the DLL using MinGW.
rem If the old DLL is in use, rename it to avoid compilation error.
rem
rem usage: update-dll-mingw [arch] [makeopts]
rem
rem [arch] is 32 or 64. If omitted, it is automatically detected from the
rem %PROCESSOR_ARCHITECTURE% environment.
rem [makeopts] is option(s) for mingw32-make.
rem
rem
rem Sample .vimrc:
rem
rem NeoBundle 'Shougo/vimproc.vim', {
rem \ 'build' : {
rem \ 'windows' : 'tools\\update-dll-mingw',
rem \ 'cygwin' : 'make -f make_cygwin.mak',
rem \ 'mac' : 'make -f make_mac.mak',
rem \ 'linux' : 'make',
rem \ 'unix' : 'gmake',
rem \ },
rem \ }
if "%1"=="32" (
set vimproc_arch=%1
shift
) else if "%1"=="64" (
set vimproc_arch=%1
shift
) else (
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
set vimproc_arch=64
) else (
set vimproc_arch=32
)
)
set vimproc_dllname=vimproc_win%vimproc_arch%.dll
where mingw32-make >nul 2>&1
if ERRORLEVEL 1 (
echo mingw32-make not found.
goto :EOF
)
rem Try to delete old DLLs.
if exist lib\%vimproc_dllname%.old del lib\%vimproc_dllname%.old
if exist lib\%vimproc_dllname% del lib\%vimproc_dllname%
rem If the DLL couldn't delete (may be it is in use), rename it.
if exist lib\%vimproc_dllname% ren lib\%vimproc_dllname% %vimproc_dllname%.old
mingw32-make -f make_mingw%vimproc_arch%.mak %1 %2 %3 %4 %5 %6 %7 %8 %9

View File

@ -0,0 +1,67 @@
@echo off
rem Update the DLL using MSVC.
rem If the old DLL is in use, rename it to avoid compilation error.
rem current support version of Visual C compiler is 2012 or later.
rem
rem usage: update-dll-msvc
rem
rem
rem Sample .vimrc:
rem
rem NeoBundle 'Shougo/vimproc.vim', {
rem \ 'build' : {
rem \ 'windows' : 'tools\\update-dll-msvc',
rem \ 'cygwin' : 'make -f make_cygwin.mak',
rem \ 'mac' : 'make -f make_mac.mak',
rem \ 'linux' : 'make',
rem \ 'unix' : 'gmake',
rem \ },
rem \ }
setlocal enabledelayedexpansion
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
set vimproc_arch=64
set msvc_arch=x86_amd64
set cpu_arch=AMD64
) else (
set vimproc_arch=32
set msvc_arch=x86
set cpu_arch=i386
)
set vimproc_dllname=vimproc_win%vimproc_arch%.dll
if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
REM found the lasted version of Visual C compiler
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
set InstallDir=%%i
if exist "!InstallDir!\VC\Auxiliary\Build\vcvars%vimproc_arch%.bat" (
call "!InstallDir!\VC\Auxiliary\Build\vcvars%vimproc_arch%.bat"
)
)
) else if defined VS140COMNTOOLS (
REM Microsoft Visual Studio 2015 installed
call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" %msvc_arch%
) else if defined VS120COMNTOOLS (
REM Microsoft Visual Studio 2013 installed
call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" %msvc_arch%
) else if defined VS110COMNTOOLS (
REM Microsoft Visual Studio 2012 installed
call "%VS110COMNTOOLS%\..\..\VC\vcvarsall.bat" %msvc_arch%
)
where nmake >nul 2>&1
if errorlevel 1 (
echo nmake not found.
goto :eof
)
rem Try to delete old DLLs.
if exist lib\%vimproc_dllname%.old del lib\%vimproc_dllname%.old
if exist lib\%vimproc_dllname% del lib\%vimproc_dllname%
rem If the DLL couldn't delete (may be it is in use), rename it.
if exist lib\%vimproc_dllname% ren lib\%vimproc_dllname% %vimproc_dllname%.old
nmake -f make_msvc.mak CPU=%cpu_arch%