home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-User.iso / usr / lib / perl5 / auto / Text / ParseWords / old_shellwords.al < prev    next >
Text File  |  1997-03-29  |  882b  |  48 lines

  1. # NOTE: Derived from lib/Text/ParseWords.pm.  Changes made here will be lost.
  2. package Text::ParseWords;
  3.  
  4. sub old_shellwords {
  5.  
  6.     # Usage:
  7.     #    use ParseWords;
  8.     #    @words = old_shellwords($line);
  9.     #    or
  10.     #    @words = old_shellwords(@lines);
  11.  
  12.     local($_) = join('', @_);
  13.     my(@words,$snippet,$field);
  14.  
  15.     s/^\s+//;
  16.     while ($_ ne '') {
  17.     $field = '';
  18.     for (;;) {
  19.         if (s/^"(([^"\\]|\\.)*)"//) {
  20.         ($snippet = $1) =~ s#\\(.)#$1#g;
  21.         }
  22.         elsif (/^"/) {
  23.         croak "Unmatched double quote: $_";
  24.         }
  25.         elsif (s/^'(([^'\\]|\\.)*)'//) {
  26.         ($snippet = $1) =~ s#\\(.)#$1#g;
  27.         }
  28.         elsif (/^'/) {
  29.         croak "Unmatched single quote: $_";
  30.         }
  31.         elsif (s/^\\(.)//) {
  32.         $snippet = $1;
  33.         }
  34.         elsif (s/^([^\s\\'"]+)//) {
  35.         $snippet = $1;
  36.         }
  37.         else {
  38.         s/^\s+//;
  39.         last;
  40.         }
  41.         $field .= $snippet;
  42.     }
  43.     push(@words, $field);
  44.     }
  45.     @words;
  46. }
  47. 1;
  48.