cf9f5ab
" tar.vim: Handles browsing tarfiles
cf9f5ab
"            AUTOLOAD PORTION
cf9f5ab
" Date:			Aug 08, 2008
cf9f5ab
" Version:		23 + modifications by Bram
cf9f5ab
" Maintainer:	Charles E Campbell, Jr <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
cf9f5ab
" License:		Vim License  (see vim's :help license)
cf9f5ab
"
cf9f5ab
"	Contains many ideas from Michael Toren's <tar.vim>
cf9f5ab
"
cf9f5ab
" Copyright:    Copyright (C) 2005-2008 Charles E. Campbell, Jr. {{{1
cf9f5ab
"               Permission is hereby granted to use and distribute this code,
cf9f5ab
"               with or without modifications, provided that this copyright
cf9f5ab
"               notice is copied with it. Like anything else that's free,
cf9f5ab
"               tar.vim and tarPlugin.vim are provided *as is* and comes
cf9f5ab
"               with no warranty of any kind, either expressed or implied.
cf9f5ab
"               By using this plugin, you agree that in no event will the
cf9f5ab
"               copyright holder be liable for any damages resulting from
cf9f5ab
"               the use of this software.
cf9f5ab
cf9f5ab
" ---------------------------------------------------------------------
cf9f5ab
" Load Once: {{{1
cf9f5ab
let s:keepcpo= &cpo
cf9f5ab
set cpo&vim
cf9f5ab
if &cp || exists("g:loaded_tar") || v:version < 700
cf9f5ab
 finish
cf9f5ab
endif
cf9f5ab
let g:loaded_tar= "v23b"
cf9f5ab
"call Decho("loading autoload/tar.vim")
cf9f5ab
if v:version < 701 || (v:version == 701 && !has("patch299"))
cf9f5ab
 echoerr "(autoload/tar.vim) need vim v7.1 with patchlevel 299"
cf9f5ab
endif
cf9f5ab
cf9f5ab
" ---------------------------------------------------------------------
cf9f5ab
"  Default Settings: {{{1
cf9f5ab
if !exists("g:tar_browseoptions")
cf9f5ab
 let g:tar_browseoptions= "Ptf"
cf9f5ab
endif
cf9f5ab
if !exists("g:tar_readoptions")
cf9f5ab
 let g:tar_readoptions= "OPxf"
cf9f5ab
endif
cf9f5ab
if !exists("g:tar_cmd")
cf9f5ab
 let g:tar_cmd= "tar"
cf9f5ab
endif
cf9f5ab
if !exists("g:tar_writeoptions")
cf9f5ab
 let g:tar_writeoptions= "uf"
cf9f5ab
endif
cf9f5ab
cf9f5ab
if !exists("g:netrw_cygwin")
cf9f5ab
 if has("win32") || has("win95") || has("win64") || has("win16")
cf9f5ab
  if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
cf9f5ab
   let g:netrw_cygwin= 1
cf9f5ab
  else
cf9f5ab
   let g:netrw_cygwin= 0
cf9f5ab
  endif
cf9f5ab
 else
cf9f5ab
  let g:netrw_cygwin= 0
cf9f5ab
 endif
cf9f5ab
endif
cf9f5ab
cf9f5ab
" set up shell quoting character
cf9f5ab
if !exists("g:tar_shq")
cf9f5ab
 if exists("&shq") && &shq != ""
cf9f5ab
  let g:tar_shq= &shq
cf9f5ab
 elseif has("win32") || has("win95") || has("win64") || has("win16")
cf9f5ab
  if exists("g:netrw_cygwin") && g:netrw_cygwin
cf9f5ab
   let g:tar_shq= "'"
cf9f5ab
  else
cf9f5ab
   let g:tar_shq= '"'
cf9f5ab
  endif
cf9f5ab
 else
cf9f5ab
  let g:tar_shq= "'"
cf9f5ab
 endif
cf9f5ab
" call Decho("g:tar_shq<".g:tar_shq.">")
cf9f5ab
endif
cf9f5ab
cf9f5ab
" ----------------
cf9f5ab
"  Functions: {{{1
cf9f5ab
" ----------------
cf9f5ab
cf9f5ab
" ---------------------------------------------------------------------
cf9f5ab
" tar#Browse: {{{2
cf9f5ab
fun! tar#Browse(tarfile)
cf9f5ab
"  call Dfunc("tar#Browse(tarfile<".a:tarfile.">)")
cf9f5ab
  let repkeep= &report
cf9f5ab
  set report=10
cf9f5ab
cf9f5ab
  " sanity checks
cf9f5ab
  if !executable(g:tar_cmd)
cf9f5ab
   redraw!
cf9f5ab
   echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system'
cf9f5ab
"   call inputsave()|call input("Press <cr> to continue")|call inputrestore()
cf9f5ab
   let &report= repkeep
cf9f5ab
"   call Dret("tar#Browse")
cf9f5ab
   return
cf9f5ab
  endif
cf9f5ab
  if !filereadable(a:tarfile)
cf9f5ab
"   call Decho('a:tarfile<'.a:tarfile.'> not filereadable')
cf9f5ab
   if a:tarfile !~# '^\a\+://'
cf9f5ab
    " if its an url, don't complain, let url-handlers such as vim do its thing
cf9f5ab
    redraw!
cf9f5ab
    echohl Error | echo "***error*** (tar#Browse) File not readable<".a:tarfile.">" | echohl None
cf9f5ab
"    call inputsave()|call input("Press <cr> to continue")|call inputrestore()
cf9f5ab
   endif
cf9f5ab
   let &report= repkeep
cf9f5ab
"   call Dret("tar#Browse : file<".a:tarfile."> not readable")
cf9f5ab
   return
cf9f5ab
  endif
cf9f5ab
  if &ma != 1
cf9f5ab
   set ma
cf9f5ab
  endif
cf9f5ab
  let w:tarfile= a:tarfile
cf9f5ab
cf9f5ab
  setlocal noswapfile
cf9f5ab
  setlocal buftype=nofile
cf9f5ab
  setlocal bufhidden=hide
cf9f5ab
  setlocal nobuflisted
cf9f5ab
  setlocal nowrap
cf9f5ab
  set ft=tar
cf9f5ab
cf9f5ab
  " give header
cf9f5ab
"  call Decho("printing header")
cf9f5ab
  let lastline= line("$")
cf9f5ab
  call setline(lastline+1,'" tar.vim version '.g:loaded_tar)
cf9f5ab
  call setline(lastline+2,'" Browsing tarfile '.a:tarfile)
cf9f5ab
  call setline(lastline+3,'" Select a file with cursor and press ENTER')
cf9f5ab
  $put =''
cf9f5ab
  0d
cf9f5ab
  $
cf9f5ab
cf9f5ab
  let tarfile= a:tarfile
cf9f5ab
  if has("win32") && executable("cygpath")
cf9f5ab
   " assuming cygwin
cf9f5ab
   let tarfile=substitute(system("cygpath -u ".s:Escape(tarfile,0)),'\n$','','e')
cf9f5ab
  endif
cf9f5ab
  let curlast= line("$")
cf9f5ab
  if tarfile =~# '\.\(gz\|tgz\)$'
cf9f5ab
"   call Decho("1: exe silent r! gzip -d -c -- ".s:Escape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ")
cf9f5ab
   exe "silent r! gzip -d -c -- ".s:Escape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
cf9f5ab
  elseif tarfile =~# '\.lrp'
cf9f5ab
"   call Decho("2: exe silent r! cat -- ".s:Escape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ")
cf9f5ab
   exe "silent r! cat -- ".s:Escape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - "
cf9f5ab
  elseif tarfile =~# '\.bz2$'
cf9f5ab
"   call Decho("3: exe silent r! bzip2 -d -c -- ".s:Escape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ")
cf9f5ab
   exe "silent r! bzip2 -d -c -- ".s:Escape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
cf9f5ab
  else
cf9f5ab
   if tarfile =~ '^\s*-'
cf9f5ab
    " A file name starting with a dash may be taken as an option.  Prepend ./ to avoid that.
cf9f5ab
    let tarfile = substitute(tarfile, '-', './-', '')
cf9f5ab
   endif
cf9f5ab
"   call Decho("4: exe silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".s:Escape(tarfile,1))
cf9f5ab
   exe "silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".s:Escape(tarfile,1)
cf9f5ab
  endif
cf9f5ab
  if v:shell_error != 0
cf9f5ab
   redraw!
cf9f5ab
   echohl WarningMsg | echo "***warning*** (tar#Browse) please check your g:tar_browseoptions<".g:tar_browseoptions.">"
cf9f5ab
"   call inputsave()|call input("Press <cr> to continue")|call inputrestore()
cf9f5ab
"   call Dret("tar#Browse : a:tarfile<".a:tarfile.">")
cf9f5ab
   return
cf9f5ab
  endif
cf9f5ab
  if line("$") == curlast || ( line("$") == (curlast + 1) && getline("$") =~ '\c\%(warning\|error\|inappropriate\|unrecognized\)')
cf9f5ab
   redraw!
cf9f5ab
   echohl WarningMsg | echo "***warning*** (tar#Browse) ".a:tarfile." doesn't appear to be a tar file" | echohl None
cf9f5ab
"   call inputsave()|call input("Press <cr> to continue")|call inputrestore()
cf9f5ab
   silent %d
cf9f5ab
   let eikeep= &ei
cf9f5ab
   set ei=BufReadCmd,FileReadCmd
cf9f5ab
   exe "r ".fnameescape(a:tarfile)
cf9f5ab
   let &ei= eikeep
cf9f5ab
   1d
cf9f5ab
"   call Dret("tar#Browse : a:tarfile<".a:tarfile.">")
cf9f5ab
   return
cf9f5ab
  endif
cf9f5ab
cf9f5ab
  setlocal noma nomod ro
cf9f5ab
  noremap <silent> <buffer> <cr> :call <SID>TarBrowseSelect()<cr>
cf9f5ab
cf9f5ab
  let &report= repkeep
cf9f5ab
"  call Dret("tar#Browse : w:tarfile<".w:tarfile.">")
cf9f5ab
endfun
cf9f5ab
cf9f5ab
" ---------------------------------------------------------------------
cf9f5ab
" TarBrowseSelect: {{{2
cf9f5ab
fun! s:TarBrowseSelect()
cf9f5ab
"  call Dfunc("TarBrowseSelect() w:tarfile<".w:tarfile."> curfile<".expand("%").">")
cf9f5ab
  let repkeep= &report
cf9f5ab
  set report=10
cf9f5ab
  let fname= getline(".")
cf9f5ab
"  call Decho("fname<".fname.">")
cf9f5ab
cf9f5ab
  if !exists("g:tar_secure") && fname =~ '^\s*-\|\s\+-'
cf9f5ab
   redraw!
cf9f5ab
   echohl WarningMsg | echo '***error*** (tar#BrowseSelect) rejecting tarfile member<'.fname.'> because of embedded "-"; See :help tar-options'
cf9f5ab
"   call Dret('tar#BrowseSelect : rejecting tarfile member<'.fname.'> because of embedded "-"')
cf9f5ab
   return
cf9f5ab
  endif
cf9f5ab
cf9f5ab
  " sanity check
cf9f5ab
  if fname =~ '^"'
cf9f5ab
   let &report= repkeep
cf9f5ab
"   call Dret("TarBrowseSelect")
cf9f5ab
   return
cf9f5ab
  endif
cf9f5ab
cf9f5ab
  " about to make a new window, need to use w:tarfile
cf9f5ab
  let tarfile= w:tarfile
cf9f5ab
  let curfile= expand("%")
cf9f5ab
  if has("win32") && executable("cygpath")
cf9f5ab
   " assuming cygwin
cf9f5ab
   let tarfile=substitute(system("cygpath -u ".s:Escape(tarfile,0)),'\n$','','e')
cf9f5ab
  endif
cf9f5ab
cf9f5ab
  new
cf9f5ab
  if !exists("g:tar_nomax") || g:tar_nomax == 0
cf9f5ab
   wincmd _
cf9f5ab
  endif
cf9f5ab
  let s:tblfile_{winnr()}= curfile
cf9f5ab
  call tar#Read("tarfile:".tarfile.'::'.fname,1)
cf9f5ab
  filetype detect
cf9f5ab
cf9f5ab
  let &report= repkeep
cf9f5ab
"  call Dret("TarBrowseSelect : s:tblfile_".winnr()."<".s:tblfile_{winnr()}.">")
cf9f5ab
endfun
cf9f5ab
cf9f5ab
" ---------------------------------------------------------------------
cf9f5ab
" tar#Read: {{{2
cf9f5ab
fun! tar#Read(fname,mode)
cf9f5ab
"  call Dfunc("tar#Read(fname<".a:fname.">,mode=".a:mode.")")
cf9f5ab
  let repkeep= &report
cf9f5ab
  set report=10
cf9f5ab
  let tarfile = substitute(a:fname,'tarfile:\(.\{-}\)::.*$','\1','')
cf9f5ab
  let fname   = substitute(a:fname,'tarfile:.\{-}::\(.*\)$','\1','')
cf9f5ab
  if has("win32") && executable("cygpath")
cf9f5ab
   " assuming cygwin
cf9f5ab
   let tarfile=substitute(system("cygpath -u ".s:Escape(tarfile,0)),'\n$','','e')
cf9f5ab
  endif
cf9f5ab
"  call Decho("tarfile<".tarfile.">")
cf9f5ab
"  call Decho("fname<".fname.">")
cf9f5ab
cf9f5ab
  if      fname =~ '\.gz$'  && executable("zcat")
cf9f5ab
   let decmp= "|zcat"
cf9f5ab
   let doro = 1
cf9f5ab
  elseif  fname =~ '\.bz2$' && executable("bzcat")
cf9f5ab
   let decmp= "|bzcat"
cf9f5ab
   let doro = 1
cf9f5ab
  else
cf9f5ab
   let decmp=""
cf9f5ab
   let doro = 0
cf9f5ab
   if fname =~ '\.gz$\|\.bz2$\|\.Z$\|\.zip$'
cf9f5ab
    setlocal bin
cf9f5ab
   endif
cf9f5ab
  endif
cf9f5ab
cf9f5ab
  if exists("g:tar_secure")
cf9f5ab
   let tar_secure= " -- "
cf9f5ab
  else
cf9f5ab
   let tar_secure= " "
cf9f5ab
  endif
cf9f5ab
  if tarfile =~# '\.\(gz\|tgz\)$'
cf9f5ab
"   call Decho("5: exe silent r! gzip -d -c -- ".s:Escape(tarfile,1)."| ".g:tar_cmd.' -'.g:tar_readoptions.' - '.tar_secure.s:Escape(fname,1))
cf9f5ab
   exe "silent r! gzip -d -c -- ".s:Escape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.s:Escape(fname,1).decmp
cf9f5ab
  elseif tarfile =~# '\.lrp$'
cf9f5ab
"   call Decho("6: exe silent r! cat ".s:Escape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.s:Escape(fname,1).decmp)
cf9f5ab
   exe "silent r! cat -- ".s:Escape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.s:Escape(fname,1).decmp
cf9f5ab
  elseif tarfile =~# '\.bz2$'
cf9f5ab
"   call Decho("7: exe silent r! bzip2 -d -c ".s:Escape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.s:Escape(fname,1).decmp)
cf9f5ab
   exe "silent r! bzip2 -d -c -- ".s:Escape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.s:Escape(fname,1).decmp
cf9f5ab
  else
cf9f5ab
   if tarfile =~ '^\s*-'
cf9f5ab
    " A file name starting with a dash may be taken as an option.  Prepend ./ to avoid that.
cf9f5ab
    let tarfile = substitute(tarfile, '-', './-', '')
cf9f5ab
   endif
cf9f5ab
"   call Decho("8: exe silent r! ".g:tar_cmd." -".g:tar_readoptions." "s:Escape(tarfile,1).tar_secure..s:Escape(fname,1).decmp)
cf9f5ab
   exe "silent r! ".g:tar_cmd." -".g:tar_readoptions." ".s:Escape(tarfile,1).tar_secure.s:Escape(fname,1).decmp
cf9f5ab
  endif
cf9f5ab
cf9f5ab
  if doro
cf9f5ab
   " because the reverse process of compressing changed files back into the tarball is not currently supported
cf9f5ab
   setlocal ro
cf9f5ab
  endif
cf9f5ab
cf9f5ab
  let w:tarfile= a:fname
cf9f5ab
  exe "file tarfile::".fnameescape(fname)
cf9f5ab
cf9f5ab
  " cleanup
cf9f5ab
  0d
cf9f5ab
  set nomod
cf9f5ab
cf9f5ab
  let &report= repkeep
cf9f5ab
"  call Dret("tar#Read : w:tarfile<".w:tarfile.">")
cf9f5ab
endfun
cf9f5ab
cf9f5ab
" ---------------------------------------------------------------------
cf9f5ab
" tar#Write: {{{2
cf9f5ab
fun! tar#Write(fname)
cf9f5ab
"  call Dfunc("tar#Write(fname<".a:fname.">) w:tarfile<".w:tarfile."> tblfile_".winnr()."<".s:tblfile_{winnr()}.">")
cf9f5ab
  let repkeep= &report
cf9f5ab
  set report=10
cf9f5ab
cf9f5ab
  if !exists("g:tar_secure") && a:fname =~ '^\s*-\|\s\+-'
cf9f5ab
   redraw!
cf9f5ab
   echohl WarningMsg | echo '***error*** (tar#Write) rejecting tarfile member<'.a:fname.'> because of embedded "-"; See :help tar-options'
cf9f5ab
"   call Dret('tar#Write : rejecting tarfile member<'.fname.'> because of embedded "-"')
cf9f5ab
   return
cf9f5ab
  endif
cf9f5ab
cf9f5ab
  " sanity checks
cf9f5ab
  if !executable(g:tar_cmd)
cf9f5ab
   redraw!
cf9f5ab
   echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system'
cf9f5ab
"   call inputsave()|call input("Press <cr> to continue")|call inputrestore()
cf9f5ab
   let &report= repkeep
cf9f5ab
"   call Dret("tar#Write")
cf9f5ab
   return
cf9f5ab
  endif
cf9f5ab
  if !exists("*mkdir")
cf9f5ab
   redraw!
cf9f5ab
   echohl Error | echo "***error*** (tar#Write) sorry, mkdir() doesn't work on your system" | echohl None
cf9f5ab
"   call inputsave()|call input("Press <cr> to continue")|call inputrestore()
cf9f5ab
   let &report= repkeep
cf9f5ab
"   call Dret("tar#Write")
cf9f5ab
   return
cf9f5ab
  endif
cf9f5ab
cf9f5ab
  let curdir= getcwd()
cf9f5ab
  let tmpdir= tempname()
cf9f5ab
"  call Decho("orig tempname<".tmpdir.">")
cf9f5ab
  if tmpdir =~ '\.'
cf9f5ab
   let tmpdir= substitute(tmpdir,'\.[^.]*$','','e')
cf9f5ab
  endif
cf9f5ab
"  call Decho("tmpdir<".tmpdir.">")
cf9f5ab
  call mkdir(tmpdir,"p")
cf9f5ab
cf9f5ab
  " attempt to change to the indicated directory
cf9f5ab
  try
cf9f5ab
   exe "cd ".fnameescape(tmpdir)
cf9f5ab
  catch /^Vim\%((\a\+)\)\=:E344/
cf9f5ab
   redraw!
cf9f5ab
   echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None
cf9f5ab
"   call inputsave()|call input("Press <cr> to continue")|call inputrestore()
cf9f5ab
   let &report= repkeep
cf9f5ab
"   call Dret("tar#Write")
cf9f5ab
   return
cf9f5ab
  endtry
cf9f5ab
"  call Decho("current directory now: ".getcwd())
cf9f5ab
cf9f5ab
  " place temporary files under .../_ZIPVIM_/
cf9f5ab
  if isdirectory("_ZIPVIM_")
cf9f5ab
   call s:Rmdir("_ZIPVIM_")
cf9f5ab
  endif
cf9f5ab
  call mkdir("_ZIPVIM_")
cf9f5ab
  cd _ZIPVIM_
cf9f5ab
"  call Decho("current directory now: ".getcwd())
cf9f5ab
cf9f5ab
  let tarfile = substitute(w:tarfile,'tarfile:\(.\{-}\)::.*$','\1','')
cf9f5ab
  let fname   = substitute(w:tarfile,'tarfile:.\{-}::\(.*\)$','\1','')
cf9f5ab
cf9f5ab
  " handle compressed archives
cf9f5ab
  if tarfile =~# '\.gz'
cf9f5ab
   call system("gzip -d -- ".s:Escape(tarfile,0))
cf9f5ab
   let tarfile = substitute(tarfile,'\.gz','','e')
cf9f5ab
   let compress= "gzip -- ".s:Escape(tarfile,0)
cf9f5ab
"   call Decho("compress<".compress.">")
cf9f5ab
  elseif tarfile =~# '\.tgz'
cf9f5ab
   call system("gzip -d -- ".s:Escape(tarfile,0))
cf9f5ab
   let tarfile = substitute(tarfile,'\.tgz','.tar','e')
cf9f5ab
   let compress= "gzip -- ".s:Escape(tarfile,0)
cf9f5ab
   let tgz     = 1
cf9f5ab
"   call Decho("compress<".compress.">")
cf9f5ab
  elseif tarfile =~# '\.bz2'
cf9f5ab
   call system("bzip2 -d -- ".s:Escape(tarfile,0))
cf9f5ab
   let tarfile = substitute(tarfile,'\.bz2','','e')
cf9f5ab
   let compress= "bzip2 -- ".s:Escape(tarfile,0)
cf9f5ab
"   call Decho("compress<".compress.">")
cf9f5ab
  endif
cf9f5ab
"  call Decho("tarfile<".tarfile.">")
cf9f5ab
cf9f5ab
  if v:shell_error != 0
cf9f5ab
   redraw!
cf9f5ab
   echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname | echohl None
cf9f5ab
"   call inputsave()|call input("Press <cr> to continue")|call inputrestore()
cf9f5ab
  else
cf9f5ab
cf9f5ab
"   call Decho("tarfile<".tarfile."> fname<".fname.">")
cf9f5ab
 
cf9f5ab
   if fname =~ '/'
cf9f5ab
    let dirpath = substitute(fname,'/[^/]\+$','','e')
cf9f5ab
    if executable("cygpath")
cf9f5ab
     let dirpath = substitute(system("cygpath ".s:Escape(dirpath, 0)),'\n','','e')
cf9f5ab
    endif
cf9f5ab
    call mkdir(dirpath,"p")
cf9f5ab
   endif
cf9f5ab
   if tarfile !~ '/'
cf9f5ab
    let tarfile= curdir.'/'.tarfile
cf9f5ab
   endif
cf9f5ab
   if tarfile =~ '^\s*-'
cf9f5ab
    " A file name starting with a dash may be taken as an option.  Prepend ./ to avoid that.
cf9f5ab
    let tarfile = substitute(tarfile, '-', './-', '')
cf9f5ab
   endif
cf9f5ab
"   call Decho("tarfile<".tarfile."> fname<".fname.">")
cf9f5ab
 
cf9f5ab
   if exists("g:tar_secure")
cf9f5ab
    let tar_secure= " -- "
cf9f5ab
   else
cf9f5ab
    let tar_secure= " "
cf9f5ab
   endif
cf9f5ab
   exe "w! ".fnameescape(fname)
cf9f5ab
   if executable("cygpath")
cf9f5ab
    let tarfile = substitute(system("cygpath ".s:Escape(tarfile,0)),'\n','','e')
cf9f5ab
   endif
cf9f5ab
 
cf9f5ab
   " delete old file from tarfile
cf9f5ab
"   call Decho("system(".g:tar_cmd." --delete -f ".s:Escape(tarfile,0)." -- ".s:Escape(fname,0).")")
cf9f5ab
   call system(g:tar_cmd." --delete -f ".s:Escape(tarfile,0).tar_secure.s:Escape(fname,0))
cf9f5ab
   if v:shell_error != 0
cf9f5ab
    redraw!
cf9f5ab
    echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None
cf9f5ab
"    call inputsave()|call input("Press <cr> to continue")|call inputrestore()
cf9f5ab
   else
cf9f5ab
 
cf9f5ab
    " update tarfile with new file 
cf9f5ab
"    call Decho(g:tar_cmd." -".g:tar_writeoptions." ".s:Escape(tarfile,0).tar_secure.s:Escape(fname,0))
cf9f5ab
    call system(g:tar_cmd." -".g:tar_writeoptions." ".s:Escape(tarfile,0).tar_secure.s:Escape(fname,0))
cf9f5ab
    if v:shell_error != 0
cf9f5ab
     redraw!
cf9f5ab
     echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None
cf9f5ab
"     call inputsave()|call input("Press <cr> to continue")|call inputrestore()
cf9f5ab
    elseif exists("compress")
cf9f5ab
"     call Decho("call system(".compress.")")
cf9f5ab
     call system(compress)
cf9f5ab
     if exists("tgz")
cf9f5ab
"      call Decho("rename(".tarfile.".gz,".substitute(tarfile,'\.tar$','.tgz','e').")")
cf9f5ab
      call rename(tarfile.".gz",substitute(tarfile,'\.tar$','.tgz','e'))
cf9f5ab
     endif
cf9f5ab
    endif
cf9f5ab
   endif
cf9f5ab
cf9f5ab
   " support writing tarfiles across a network
cf9f5ab
   if s:tblfile_{winnr()} =~ '^\a\+://'
cf9f5ab
"    call Decho("handle writing <".tarfile."> across network to <".s:tblfile_{winnr()}.">")
cf9f5ab
    let tblfile= s:tblfile_{winnr()}
cf9f5ab
    1split|enew
cf9f5ab
    let binkeep= &binary
cf9f5ab
    let eikeep = &ei
cf9f5ab
    set binary ei=all
cf9f5ab
    exe "e! ".fnameescape(tarfile)
cf9f5ab
    call netrw#NetWrite(tblfile)
cf9f5ab
    let &ei     = eikeep
cf9f5ab
    let &binary = binkeep
cf9f5ab
    q!
cf9f5ab
    unlet s:tblfile_{winnr()}
cf9f5ab
   endif
cf9f5ab
  endif
cf9f5ab
  
cf9f5ab
  " cleanup and restore current directory
cf9f5ab
  cd ..
cf9f5ab
  call s:Rmdir("_ZIPVIM_")
cf9f5ab
  exe "cd ".fnameescape(curdir)
cf9f5ab
  setlocal nomod
cf9f5ab
cf9f5ab
  let &report= repkeep
cf9f5ab
"  call Dret("tar#Write")
cf9f5ab
endfun
cf9f5ab
cf9f5ab
" ---------------------------------------------------------------------
cf9f5ab
" Rmdir: {{{2
cf9f5ab
fun! s:Rmdir(fname)
cf9f5ab
"  call Dfunc("Rmdir(fname<".a:fname.">)")
cf9f5ab
  if has("unix")
cf9f5ab
   call system("/bin/rm -rf -- ".s:Escape(a:fname,0))
cf9f5ab
  elseif has("win32") || has("win95") || has("win64") || has("win16")
cf9f5ab
   if &shell =~? "sh$"
cf9f5ab
    call system("/bin/rm -rf -- ".s:Escape(a:fname,0))
cf9f5ab
   else
cf9f5ab
    call system("del /S ".s:Escape(a:fname,0))
cf9f5ab
   endif
cf9f5ab
  endif
cf9f5ab
"  call Dret("Rmdir")
cf9f5ab
endfun
cf9f5ab
cf9f5ab
" ---------------------------------------------------------------------
cf9f5ab
" s:Escape: {{{2
cf9f5ab
fun s:Escape(name,isfilt)
cf9f5ab
  " shellescape() was added by patch 7.0.111
cf9f5ab
  if exists("*shellescape")
cf9f5ab
   if a:isfilt
cf9f5ab
    let qnameq= shellescape(a:name,1)
cf9f5ab
   else
cf9f5ab
    let qnameq= shellescape(a:name)
cf9f5ab
   endif
cf9f5ab
  else
cf9f5ab
   let qnameq= g:tar_shq . a:name . g:tar_shq
cf9f5ab
  endif
cf9f5ab
  return qnameq
cf9f5ab
endfun
cf9f5ab
cf9f5ab
" ---------------------------------------------------------------------
cf9f5ab
" Modelines And Restoration: {{{1
cf9f5ab
let &cpo= s:keepcpo
cf9f5ab
unlet s:keepcpo
cf9f5ab
" vim:ts=8 fdm=marker