/IronPython_Main/Runtime/Tests/LinqDlrTests/testenv/perl/lib/getopts.pl

# · Perl · 66 lines · 54 code · 3 blank · 9 comment · 11 complexity · 328bb8208c076f6cb9274f0983f0a312 MD5 · raw file

  1. ;# getopts.pl - a better getopt.pl
  2. #
  3. # This library is no longer being maintained, and is included for backward
  4. # compatibility with Perl 4 programs which may require it.
  5. #
  6. # In particular, this should not be used as an example of modern Perl
  7. # programming techniques.
  8. #
  9. # Suggested alternatives: Getopt::Long or Getopt::Std
  10. #
  11. ;# Usage:
  12. ;# do Getopts('a:bc'); # -a takes arg. -b & -c not. Sets opt_* as a
  13. ;# # side effect.
  14. sub Getopts {
  15. local($argumentative) = @_;
  16. local(@args,$_,$first,$rest);
  17. local($errs) = 0;
  18. local($[) = 0;
  19. @args = split( / */, $argumentative );
  20. while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
  21. ($first,$rest) = ($1,$2);
  22. $pos = index($argumentative,$first);
  23. if($pos >= $[) {
  24. if($args[$pos+1] eq ':') {
  25. shift(@ARGV);
  26. if($rest eq '') {
  27. ++$errs unless(@ARGV);
  28. $rest = shift(@ARGV);
  29. }
  30. eval "
  31. push(\@opt_$first, \$rest);
  32. if(\$opt_$first eq '') {
  33. \$opt_$first = \$rest;
  34. }
  35. else {
  36. \$opt_$first .= ' ' . \$rest;
  37. }
  38. ";
  39. }
  40. else {
  41. eval "\$opt_$first = 1";
  42. if($rest eq '') {
  43. shift(@ARGV);
  44. }
  45. else {
  46. $ARGV[0] = "-$rest";
  47. }
  48. }
  49. }
  50. else {
  51. print STDERR "Unknown option: $first\n";
  52. ++$errs;
  53. if($rest ne '') {
  54. $ARGV[0] = "-$rest";
  55. }
  56. else {
  57. shift(@ARGV);
  58. }
  59. }
  60. }
  61. $errs == 0;
  62. }
  63. 1;