Created
June 5, 2012 05:33
-
-
Save mattn/2872887 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int | |
main(int argc, char* argv[]) { | |
int n; | |
for (n = 0; n < argc; n++) { | |
printf("%s\n", argv[n]); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! s:system(...) | |
let cmd = '' | |
for a in a:000 | |
if len(cmd) | let cmd .= ' ' | endif | |
if a =~ '\s' | |
if len(split(a, '"', 1)) % 2 == 0 | |
let a = '^"'.substitute(a, '"', '"""', 'g').'"' | |
else | |
let a = '"'.substitute(a, '"', '"""', 'g').'"' | |
endif | |
else | |
let a = substitute(a, '"', '""""', 'g') | |
endif | |
let a = substitute(a, "'", "''", 'g') | |
let cmd .= a | |
endfor | |
return system(cmd) | |
endfunction | |
function! s:test(...) | |
let ret = call('s:system', a:000) | |
let arr = split(ret, "\n", 1)[:-2] | |
echo (string(arr[1:]) ==# string(a:000[1:]) ? "OK" : "NG") . ": " . string(arr) | |
endfunction | |
call s:test('arglist', '-"foo"', "bar") | |
call s:test('arglist', '-foo', "bar") | |
call s:test('arglist', '-f oo', "bar") | |
call s:test('arglist', '-f "oo', "bar") | |
call s:test('arglist', '-f ""oo', "bar") | |
call s:test('arglist', '-f """oo', "bar") | |
call s:test('arglist', '"-f """oo', "bar") | |
call s:test('arglist', '"-f """oo"', "bar") | |
call s:test('arglist', 'bar', '-"foo"', "bar") | |
call s:test('arglist', 'b ar', '-foo', "bar") | |
call s:test('arglist', 'ba r', '-f oo', "bar") | |
call s:test('arglist', 'b a r', '-f "oo', "bar") | |
call s:test('arglist', 'bar', '-f ""oo', "bar") | |
call s:test('arglist', ' bar', '-f """oo', "bar") | |
call s:test('arglist', 'bar ', '"-f """oo', "bar") | |
call s:test('arglist', ' b a r ', '"-f """oo"', "bar") | |
call s:test('arglist', ' "b a r" ', '"-f """oo"', "bar") | |
call s:test('arglist', ' "b "a" r" ', '"-f """oo"', "bar") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment