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.

33 lines
561 B

  1. ;# Usage:
  2. ;# %foo = ();
  3. ;# &abbrev(*foo,LIST);
  4. ;# ...
  5. ;# $long = $foo{$short};
  6. package abbrev;
  7. sub main'abbrev {
  8. local(*domain) = @_;
  9. shift(@_);
  10. @cmp = @_;
  11. local($[) = 0;
  12. foreach $name (@_) {
  13. @extra = split(//,$name);
  14. $abbrev = shift(@extra);
  15. $len = 1;
  16. foreach $cmp (@cmp) {
  17. next if $cmp eq $name;
  18. while (@extra && substr($cmp,0,$len) eq $abbrev) {
  19. $abbrev .= shift(@extra);
  20. ++$len;
  21. }
  22. }
  23. $domain{$abbrev} = $name;
  24. while ($#extra >= 0) {
  25. $abbrev .= shift(@extra);
  26. $domain{$abbrev} = $name;
  27. }
  28. }
  29. }
  30. 1;