Work around MinGW mangling of "host:/path"
[msysgit/historical-msysgit.git] / lib / perl5 / 5.6.1 / shellwords.pl
blob1c45a5a0903579fb0f58870242ce95d933e05065
1 ;# shellwords.pl
2 ;#
3 ;# Usage:
4 ;# require 'shellwords.pl';
5 ;# @words = &shellwords($line);
6 ;# or
7 ;# @words = &shellwords(@lines);
8 ;# or
9 ;# @words = &shellwords; # defaults to $_ (and clobbers it)
11 sub shellwords {
12 package shellwords;
13 local($_) = join('', @_) if @_;
14 local(@words,$snippet,$field);
16 s/^\s+//;
17 while ($_ ne '') {
18 $field = '';
19 for (;;) {
20 if (s/^"(([^"\\]|\\.)*)"//) {
21 ($snippet = $1) =~ s#\\(.)#$1#g;
23 elsif (/^"/) {
24 die "Unmatched double quote: $_\n";
26 elsif (s/^'(([^'\\]|\\.)*)'//) {
27 ($snippet = $1) =~ s#\\(.)#$1#g;
29 elsif (/^'/) {
30 die "Unmatched single quote: $_\n";
32 elsif (s/^\\(.)//) {
33 $snippet = $1;
35 elsif (s/^([^\s\\'"]+)//) {
36 $snippet = $1;
38 else {
39 s/^\s+//;
40 last;
42 $field .= $snippet;
44 push(@words, $field);
46 @words;