Mercurial > vim
annotate runtime/autoload/zip.vim @ 27507:b8a5de86e9d1 v8.2.4281
patch 8.2.4281: using freed memory with :lopen and :bwipe
Commit: https://github.com/vim/vim/commit/9b4a80a66544f2782040b641498754bcb5b8d461
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 1 13:54:17 2022 +0000
patch 8.2.4281: using freed memory with :lopen and :bwipe
Problem: Using freed memory with :lopen and :bwipe.
Solution: Do not use a wiped out buffer.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 01 Feb 2022 15:00:05 +0100 |
parents | 624439a39432 |
children | b2e8663e6dcc |
rev | line source |
---|---|
530 | 1 " zip.vim: Handles browsing zipfiles |
2 " AUTOLOAD PORTION | |
26148 | 3 " Date: Nov 08, 2021 |
4 " Version: 32 | |
19099 | 5 " Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> |
1121 | 6 " License: Vim License (see vim's :help license) |
19099 | 7 " Copyright: Copyright (C) 2005-2019 Charles E. Campbell {{{1 |
530 | 8 " Permission is hereby granted to use and distribute this code, |
9 " with or without modifications, provided that this copyright | |
10 " notice is copied with it. Like anything else that's free, | |
1621 | 11 " zip.vim and zipPlugin.vim are provided *as is* and comes with |
12 " no warranty of any kind, either expressed or implied. By using | |
13 " this plugin, you agree that in no event will the copyright | |
530 | 14 " holder be liable for any damages resulting from the use |
15 " of this software. | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
16 "redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
530 | 17 |
18 " --------------------------------------------------------------------- | |
1121 | 19 " Load Once: {{{1 |
2152 | 20 if &cp || exists("g:loaded_zip") |
21 finish | |
22 endif | |
26148 | 23 let g:loaded_zip= "v32" |
2152 | 24 if v:version < 702 |
25 echohl WarningMsg | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
26 echo "***warning*** this version of zip needs vim 7.2 or later" |
2152 | 27 echohl Normal |
28 finish | |
29 endif | |
530 | 30 let s:keepcpo= &cpo |
31 set cpo&vim | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
32 "DechoTabOn |
530 | 33 |
798 | 34 let s:zipfile_escape = ' ?&;\' |
1121 | 35 let s:ERROR = 2 |
36 let s:WARNING = 1 | |
37 let s:NOTE = 0 | |
38 | |
39 " --------------------------------------------------------------------- | |
40 " Global Values: {{{1 | |
41 if !exists("g:zip_shq") | |
1621 | 42 if &shq != "" |
43 let g:zip_shq= &shq | |
44 elseif has("unix") | |
1121 | 45 let g:zip_shq= "'" |
46 else | |
47 let g:zip_shq= '"' | |
48 endif | |
49 endif | |
1214 | 50 if !exists("g:zip_zipcmd") |
51 let g:zip_zipcmd= "zip" | |
52 endif | |
53 if !exists("g:zip_unzipcmd") | |
54 let g:zip_unzipcmd= "unzip" | |
55 endif | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
56 if !exists("g:zip_extractcmd") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
57 let g:zip_extractcmd= g:zip_unzipcmd |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
58 endif |
530 | 59 |
60 " ---------------- | |
61 " Functions: {{{1 | |
62 " ---------------- | |
63 | |
64 " --------------------------------------------------------------------- | |
65 " zip#Browse: {{{2 | |
66 fun! zip#Browse(zipfile) | |
67 " call Dfunc("zip#Browse(zipfile<".a:zipfile.">)") | |
22723 | 68 " sanity check: insure that the zipfile has "PK" as its first two letters |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
69 " (zipped files have a leading PK as a "magic cookie") |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
70 if !filereadable(a:zipfile) || readfile(a:zipfile, "", 1)[0] !~ '^PK' |
19099 | 71 exe "noswapfile noautocmd noswapfile e ".fnameescape(a:zipfile) |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
72 " call Dret("zip#Browse : not a zipfile<".a:zipfile.">") |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
73 return |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
74 " else " Decho |
19116 | 75 " call Decho("zip#Browse: a:zipfile<".a:zipfile."> passed PK test - it's a zip file") |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
76 endif |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
77 |
568 | 78 let repkeep= &report |
79 set report=10 | |
530 | 80 |
81 " sanity checks | |
1698 | 82 if !exists("*fnameescape") |
83 if &verbose > 1 | |
25773 | 84 echoerr "the zip plugin is not available (your vim doesn't support fnameescape())" |
1698 | 85 endif |
86 return | |
87 endif | |
1214 | 88 if !executable(g:zip_unzipcmd) |
1121 | 89 redraw! |
530 | 90 echohl Error | echo "***error*** (zip#Browse) unzip not available on your system" |
1121 | 91 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 92 let &report= repkeep |
530 | 93 " call Dret("zip#Browse") |
94 return | |
95 endif | |
96 if !filereadable(a:zipfile) | |
557 | 97 if a:zipfile !~# '^\a\+://' |
19116 | 98 " if it's an url, don't complain, let url-handlers such as vim do its thing |
1121 | 99 redraw! |
557 | 100 echohl Error | echo "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None |
1121 | 101 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
557 | 102 endif |
568 | 103 let &report= repkeep |
557 | 104 " call Dret("zip#Browse : file<".a:zipfile."> not readable") |
530 | 105 return |
106 endif | |
798 | 107 " call Decho("passed sanity checks") |
530 | 108 if &ma != 1 |
109 set ma | |
110 endif | |
1214 | 111 let b:zipfile= a:zipfile |
530 | 112 |
113 setlocal noswapfile | |
114 setlocal buftype=nofile | |
115 setlocal bufhidden=hide | |
116 setlocal nobuflisted | |
117 setlocal nowrap | |
26148 | 118 |
119 " Oct 12, 2021: need to re-use Bram's syntax/tar.vim. | |
120 " Setting the filetype to zip doesn't do anything (currently), | |
121 " but it is perhaps less confusing to curious perusers who do | |
122 " a :echo &ft | |
123 setf zip | |
124 run! syntax/tar.vim | |
530 | 125 |
126 " give header | |
2908 | 127 call append(0, ['" zip.vim version '.g:loaded_zip, |
3281 | 128 \ '" Browsing zipfile '.a:zipfile, |
129 \ '" Select a file with cursor and press ENTER']) | |
2908 | 130 keepj $ |
530 | 131 |
1698 | 132 " call Decho("exe silent r! ".g:zip_unzipcmd." -l -- ".s:Escape(a:zipfile,1)) |
3281 | 133 exe "keepj sil! r! ".g:zip_unzipcmd." -Z -1 -- ".s:Escape(a:zipfile,1) |
857 | 134 if v:shell_error != 0 |
1121 | 135 redraw! |
1668 | 136 echohl WarningMsg | echo "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file" | echohl None |
1121 | 137 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
2908 | 138 keepj sil! %d |
857 | 139 let eikeep= &ei |
140 set ei=BufReadCmd,FileReadCmd | |
2908 | 141 exe "keepj r ".fnameescape(a:zipfile) |
857 | 142 let &ei= eikeep |
2908 | 143 keepj 1d |
857 | 144 " call Dret("zip#Browse") |
145 return | |
146 endif | |
530 | 147 |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
148 " Maps associated with zip plugin |
530 | 149 setlocal noma nomod ro |
19099 | 150 noremap <silent> <buffer> <cr> :call <SID>ZipBrowseSelect()<cr> |
151 noremap <silent> <buffer> x :call zip#Extract()<cr> | |
152 if &mouse != "" | |
153 noremap <silent> <buffer> <leftmouse> <leftmouse>:call <SID>ZipBrowseSelect()<cr> | |
154 endif | |
530 | 155 |
568 | 156 let &report= repkeep |
530 | 157 " call Dret("zip#Browse") |
158 endfun | |
159 | |
160 " --------------------------------------------------------------------- | |
161 " ZipBrowseSelect: {{{2 | |
162 fun! s:ZipBrowseSelect() | |
1214 | 163 " call Dfunc("ZipBrowseSelect() zipfile<".b:zipfile."> curfile<".expand("%").">") |
568 | 164 let repkeep= &report |
165 set report=10 | |
530 | 166 let fname= getline(".") |
167 | |
168 " sanity check | |
169 if fname =~ '^"' | |
568 | 170 let &report= repkeep |
530 | 171 " call Dret("ZipBrowseSelect") |
172 return | |
173 endif | |
174 if fname =~ '/$' | |
1121 | 175 redraw! |
530 | 176 echohl Error | echo "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None |
1121 | 177 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 178 let &report= repkeep |
530 | 179 " call Dret("ZipBrowseSelect") |
180 return | |
181 endif | |
182 | |
183 " call Decho("fname<".fname.">") | |
184 | |
185 " get zipfile to the new-window | |
1214 | 186 let zipfile = b:zipfile |
19099 | 187 let curfile = expand("%") |
798 | 188 " call Decho("zipfile<".zipfile.">") |
189 " call Decho("curfile<".curfile.">") | |
530 | 190 |
19099 | 191 noswapfile new |
1621 | 192 if !exists("g:zip_nomax") || g:zip_nomax == 0 |
193 wincmd _ | |
194 endif | |
557 | 195 let s:zipfile_{winnr()}= curfile |
26148 | 196 " call Decho("exe e ".fnameescape("zipfile://".zipfile.'::'.fname)) |
197 exe "noswapfile e ".fnameescape("zipfile://".zipfile.'::'.fname) | |
530 | 198 filetype detect |
199 | |
568 | 200 let &report= repkeep |
557 | 201 " call Dret("ZipBrowseSelect : s:zipfile_".winnr()."<".s:zipfile_{winnr()}.">") |
530 | 202 endfun |
203 | |
204 " --------------------------------------------------------------------- | |
205 " zip#Read: {{{2 | |
206 fun! zip#Read(fname,mode) | |
207 " call Dfunc("zip#Read(fname<".a:fname.">,mode=".a:mode.")") | |
568 | 208 let repkeep= &report |
209 set report=10 | |
210 | |
857 | 211 if has("unix") |
26148 | 212 let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','') |
213 let fname = substitute(a:fname,'zipfile://.\{-}::\([^\\].*\)$','\1','') | |
857 | 214 else |
26148 | 215 let zipfile = substitute(a:fname,'^.\{-}zipfile://\(.\{-}\)::[^\\].*$','\1','') |
216 let fname = substitute(a:fname,'^.\{-}zipfile://.\{-}::\([^\\].*\)$','\1','') | |
4339 | 217 let fname = substitute(fname, '[', '[[]', 'g') |
857 | 218 endif |
219 " call Decho("zipfile<".zipfile.">") | |
220 " call Decho("fname <".fname.">") | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
221 " sanity check |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
222 if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','','')) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
223 redraw! |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
224 echohl Error | echo "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program" | echohl None |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
225 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
226 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
227 " call Dret("zip#Write") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
228 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
229 endif |
530 | 230 |
4339 | 231 " the following code does much the same thing as |
232 " exe "keepj sil! r! ".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1) | |
26148 | 233 " but allows zipfile://... entries in quickfix lists |
4339 | 234 let temp = tempname() |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
235 " call Decho("using temp file<".temp.">") |
4339 | 236 let fn = expand('%:p') |
237 exe "sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp | |
238 " call Decho("exe sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp) | |
239 sil exe 'keepalt file '.temp | |
240 sil keepj e! | |
241 sil exe 'keepalt file '.fnameescape(fn) | |
242 call delete(temp) | |
243 | |
2908 | 244 filetype detect |
530 | 245 |
246 " cleanup | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
247 " keepj 0d " used to be needed for the ...r! ... method |
530 | 248 set nomod |
249 | |
568 | 250 let &report= repkeep |
530 | 251 " call Dret("zip#Read") |
252 endfun | |
253 | |
254 " --------------------------------------------------------------------- | |
255 " zip#Write: {{{2 | |
256 fun! zip#Write(fname) | |
819 | 257 " call Dfunc("zip#Write(fname<".a:fname.">) zipfile_".winnr()."<".s:zipfile_{winnr()}.">") |
568 | 258 let repkeep= &report |
259 set report=10 | |
530 | 260 |
261 " sanity checks | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
262 if !executable(substitute(g:zip_zipcmd,'\s\+.*$','','')) |
1121 | 263 redraw! |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
264 echohl Error | echo "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program" | echohl None |
1121 | 265 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 266 let &report= repkeep |
530 | 267 " call Dret("zip#Write") |
268 return | |
269 endif | |
270 if !exists("*mkdir") | |
1121 | 271 redraw! |
530 | 272 echohl Error | echo "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None |
1121 | 273 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 274 let &report= repkeep |
530 | 275 " call Dret("zip#Write") |
276 return | |
277 endif | |
278 | |
279 let curdir= getcwd() | |
280 let tmpdir= tempname() | |
281 " call Decho("orig tempname<".tmpdir.">") | |
282 if tmpdir =~ '\.' | |
283 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e') | |
284 endif | |
285 " call Decho("tmpdir<".tmpdir.">") | |
286 call mkdir(tmpdir,"p") | |
287 | |
288 " attempt to change to the indicated directory | |
1121 | 289 if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory") |
568 | 290 let &report= repkeep |
530 | 291 " call Dret("zip#Write") |
292 return | |
1121 | 293 endif |
530 | 294 " call Decho("current directory now: ".getcwd()) |
295 | |
296 " place temporary files under .../_ZIPVIM_/ | |
297 if isdirectory("_ZIPVIM_") | |
298 call s:Rmdir("_ZIPVIM_") | |
299 endif | |
300 call mkdir("_ZIPVIM_") | |
301 cd _ZIPVIM_ | |
302 " call Decho("current directory now: ".getcwd()) | |
303 | |
857 | 304 if has("unix") |
26148 | 305 let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','') |
306 let fname = substitute(a:fname,'zipfile://.\{-}::\([^\\].*\)$','\1','') | |
857 | 307 else |
26148 | 308 let zipfile = substitute(a:fname,'^.\{-}zipfile://\(.\{-}\)::[^\\].*$','\1','') |
309 let fname = substitute(a:fname,'^.\{-}zipfile://.\{-}::\([^\\].*\)$','\1','') | |
857 | 310 endif |
311 " call Decho("zipfile<".zipfile.">") | |
312 " call Decho("fname <".fname.">") | |
623 | 313 |
314 if fname =~ '/' | |
315 let dirpath = substitute(fname,'/[^/]\+$','','e') | |
4339 | 316 if has("win32unix") && executable("cygpath") |
1668 | 317 let dirpath = substitute(system("cygpath ".s:Escape(dirpath,0)),'\n','','e') |
623 | 318 endif |
819 | 319 " call Decho("mkdir(dirpath<".dirpath.">,p)") |
623 | 320 call mkdir(dirpath,"p") |
321 endif | |
530 | 322 if zipfile !~ '/' |
323 let zipfile= curdir.'/'.zipfile | |
324 endif | |
325 " call Decho("zipfile<".zipfile."> fname<".fname.">") | |
326 | |
1668 | 327 exe "w! ".fnameescape(fname) |
4339 | 328 if has("win32unix") && executable("cygpath") |
1668 | 329 let zipfile = substitute(system("cygpath ".s:Escape(zipfile,0)),'\n','','e') |
530 | 330 endif |
331 | |
1121 | 332 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$' |
333 let fname = substitute(fname, '[', '[[]', 'g') | |
334 endif | |
335 | |
1698 | 336 " call Decho(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) |
337 call system(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) | |
530 | 338 if v:shell_error != 0 |
1121 | 339 redraw! |
530 | 340 echohl Error | echo "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None |
1121 | 341 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
557 | 342 |
343 elseif s:zipfile_{winnr()} =~ '^\a\+://' | |
344 " support writing zipfiles across a network | |
345 let netzipfile= s:zipfile_{winnr()} | |
1121 | 346 " call Decho("handle writing <".zipfile."> across network as <".netzipfile.">") |
557 | 347 1split|enew |
348 let binkeep= &binary | |
349 let eikeep = &ei | |
350 set binary ei=all | |
19099 | 351 exe "noswapfile e! ".fnameescape(zipfile) |
557 | 352 call netrw#NetWrite(netzipfile) |
353 let &ei = eikeep | |
354 let &binary = binkeep | |
355 q! | |
356 unlet s:zipfile_{winnr()} | |
530 | 357 endif |
358 | |
359 " cleanup and restore current directory | |
360 cd .. | |
361 call s:Rmdir("_ZIPVIM_") | |
1121 | 362 call s:ChgDir(curdir,s:WARNING,"(zip#Write) unable to return to ".curdir."!") |
363 call s:Rmdir(tmpdir) | |
530 | 364 setlocal nomod |
365 | |
568 | 366 let &report= repkeep |
530 | 367 " call Dret("zip#Write") |
368 endfun | |
369 | |
370 " --------------------------------------------------------------------- | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
371 " zip#Extract: extract a file from a zip archive {{{2 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
372 fun! zip#Extract() |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
373 " call Dfunc("zip#Extract()") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
374 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
375 let repkeep= &report |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
376 set report=10 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
377 let fname= getline(".") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
378 " call Decho("fname<".fname.">") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
379 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
380 " sanity check |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
381 if fname =~ '^"' |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
382 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
383 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
384 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
385 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
386 if fname =~ '/$' |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
387 redraw! |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
388 echohl Error | echo "***error*** (zip#Extract) Please specify a file, not a directory" | echohl None |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
389 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
390 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
391 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
392 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
393 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
394 " extract the file mentioned under the cursor |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
395 " call Decho("system(".g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell).")") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
396 call system(g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell)) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
397 " call Decho("zipfile<".b:zipfile.">") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
398 if v:shell_error != 0 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
399 echohl Error | echo "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!" | echohl NONE |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
400 elseif !filereadable(fname) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
401 echohl Error | echo "***error*** attempted to extract ".fname." but it doesn't appear to be present!" |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
402 else |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
403 echo "***note*** successfully extracted ".fname |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
404 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
405 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
406 " restore option |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
407 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
408 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
409 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
410 endfun |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
411 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
412 " --------------------------------------------------------------------- |
1668 | 413 " s:Escape: {{{2 |
414 fun! s:Escape(fname,isfilt) | |
415 " call Dfunc("QuoteFileDir(fname<".a:fname."> isfilt=".a:isfilt.")") | |
416 if exists("*shellescape") | |
417 if a:isfilt | |
418 let qnameq= shellescape(a:fname,1) | |
419 else | |
420 let qnameq= shellescape(a:fname) | |
421 endif | |
1621 | 422 else |
423 let qnameq= g:zip_shq.escape(a:fname,g:zip_shq).g:zip_shq | |
424 endif | |
425 " call Dret("QuoteFileDir <".qnameq.">") | |
426 return qnameq | |
1121 | 427 endfun |
428 | |
429 " --------------------------------------------------------------------- | |
430 " ChgDir: {{{2 | |
431 fun! s:ChgDir(newdir,errlvl,errmsg) | |
432 " call Dfunc("ChgDir(newdir<".a:newdir."> errlvl=".a:errlvl." errmsg<".a:errmsg.">)") | |
433 | |
434 try | |
1698 | 435 exe "cd ".fnameescape(a:newdir) |
1121 | 436 catch /^Vim\%((\a\+)\)\=:E344/ |
437 redraw! | |
438 if a:errlvl == s:NOTE | |
439 echo "***note*** ".a:errmsg | |
440 elseif a:errlvl == s:WARNING | |
441 echohl WarningMsg | echo "***warning*** ".a:errmsg | echohl NONE | |
442 elseif a:errlvl == s:ERROR | |
443 echohl Error | echo "***error*** ".a:errmsg | echohl NONE | |
444 endif | |
445 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
446 " call Dret("ChgDir 1") | |
447 return 1 | |
448 endtry | |
449 | |
450 " call Dret("ChgDir 0") | |
451 return 0 | |
452 endfun | |
453 | |
454 " --------------------------------------------------------------------- | |
1668 | 455 " s:Rmdir: {{{2 |
530 | 456 fun! s:Rmdir(fname) |
457 " call Dfunc("Rmdir(fname<".a:fname.">)") | |
1121 | 458 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$' |
1668 | 459 call system("rmdir /S/Q ".s:Escape(a:fname,0)) |
1121 | 460 else |
1668 | 461 call system("/bin/rm -rf ".s:Escape(a:fname,0)) |
530 | 462 endif |
463 " call Dret("Rmdir") | |
464 endfun | |
465 | |
466 " ------------------------------------------------------------------------ | |
467 " Modelines And Restoration: {{{1 | |
468 let &cpo= s:keepcpo | |
469 unlet s:keepcpo | |
1214 | 470 " vim:ts=8 fdm=marker |