Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.0 KiB

  1. ;# $RCSfile: getopt.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:23:58 $
  2. ;# Process single-character switches with switch clustering. Pass one argument
  3. ;# which is a string containing all switches that take an argument. For each
  4. ;# switch found, sets $opt_x (where x is the switch name) to the value of the
  5. ;# argument, or 1 if no argument. Switches which take an argument don't care
  6. ;# whether there is a space between the switch and the argument.
  7. ;# Usage:
  8. ;# do Getopt('oDI'); # -o, -D & -I take arg. Sets opt_* as a side effect.
  9. sub Getopt {
  10. local($argumentative) = @_;
  11. local($_,$first,$rest);
  12. local($[) = 0;
  13. while (@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
  14. ($first,$rest) = ($1,$2);
  15. if (index($argumentative,$first) >= $[) {
  16. if ($rest ne '') {
  17. shift(@ARGV);
  18. }
  19. else {
  20. shift(@ARGV);
  21. $rest = shift(@ARGV);
  22. }
  23. ${"opt_$first"} = $rest;
  24. }
  25. else {
  26. ${"opt_$first"} = 1;
  27. if ($rest ne '') {
  28. $ARGV[0] = "-$rest";
  29. }
  30. else {
  31. shift(@ARGV);
  32. }
  33. }
  34. }
  35. }
  36. 1;