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.

104 lines
3.7 KiB

  1. ;# $RCSfile: validate.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:19 $
  2. ;# The validate routine takes a single multiline string consisting of
  3. ;# lines containing a filename plus a file test to try on it. (The
  4. ;# file test may also be a 'cd', causing subsequent relative filenames
  5. ;# to be interpreted relative to that directory.) After the file test
  6. ;# you may put '|| die' to make it a fatal error if the file test fails.
  7. ;# The default is '|| warn'. The file test may optionally have a ! prepended
  8. ;# to test for the opposite condition. If you do a cd and then list some
  9. ;# relative filenames, you may want to indent them slightly for readability.
  10. ;# If you supply your own "die" or "warn" message, you can use $file to
  11. ;# interpolate the filename.
  12. ;# Filetests may be bunched: -rwx tests for all of -r, -w and -x.
  13. ;# Only the first failed test of the bunch will produce a warning.
  14. ;# The routine returns the number of warnings issued.
  15. ;# Usage:
  16. ;# require "validate.pl";
  17. ;# $warnings += do validate('
  18. ;# /vmunix -e || die
  19. ;# /boot -e || die
  20. ;# /bin cd
  21. ;# csh -ex
  22. ;# csh !-ug
  23. ;# sh -ex
  24. ;# sh !-ug
  25. ;# /usr -d || warn "What happened to $file?\n"
  26. ;# ');
  27. sub validate {
  28. local($file,$test,$warnings,$oldwarnings);
  29. foreach $check (split(/\n/,$_[0])) {
  30. next if $check =~ /^#/;
  31. next if $check =~ /^$/;
  32. ($file,$test) = split(' ',$check,2);
  33. if ($test =~ s/^(!?-)(\w{2,}\b)/$1Z/) {
  34. $testlist = $2;
  35. @testlist = split(//,$testlist);
  36. }
  37. else {
  38. @testlist = ('Z');
  39. }
  40. $oldwarnings = $warnings;
  41. foreach $one (@testlist) {
  42. $this = $test;
  43. $this =~ s/(-\w\b)/$1 \$file/g;
  44. $this =~ s/-Z/-$one/;
  45. $this .= ' || warn' unless $this =~ /\|\|/;
  46. $this =~ s/^(.*\S)\s*\|\|\s*(die|warn)$/$1 || do valmess('$2','$1')/;
  47. $this =~ s/\bcd\b/chdir (\$cwd = \$file)/g;
  48. eval $this;
  49. last if $warnings > $oldwarnings;
  50. }
  51. }
  52. $warnings;
  53. }
  54. sub valmess {
  55. local($disposition,$this) = @_;
  56. $file = $cwd . '/' . $file unless $file =~ m|^/|;
  57. if ($this =~ /^(!?)-(\w)\s+\$file\s*$/) {
  58. $neg = $1;
  59. $tmp = $2;
  60. $tmp eq 'r' && ($mess = "$file is not readable by uid $>.");
  61. $tmp eq 'w' && ($mess = "$file is not writable by uid $>.");
  62. $tmp eq 'x' && ($mess = "$file is not executable by uid $>.");
  63. $tmp eq 'o' && ($mess = "$file is not owned by uid $>.");
  64. $tmp eq 'R' && ($mess = "$file is not readable by you.");
  65. $tmp eq 'W' && ($mess = "$file is not writable by you.");
  66. $tmp eq 'X' && ($mess = "$file is not executable by you.");
  67. $tmp eq 'O' && ($mess = "$file is not owned by you.");
  68. $tmp eq 'e' && ($mess = "$file does not exist.");
  69. $tmp eq 'z' && ($mess = "$file does not have zero size.");
  70. $tmp eq 's' && ($mess = "$file does not have non-zero size.");
  71. $tmp eq 'f' && ($mess = "$file is not a plain file.");
  72. $tmp eq 'd' && ($mess = "$file is not a directory.");
  73. $tmp eq 'l' && ($mess = "$file is not a symbolic link.");
  74. $tmp eq 'p' && ($mess = "$file is not a named pipe (FIFO).");
  75. $tmp eq 'S' && ($mess = "$file is not a socket.");
  76. $tmp eq 'b' && ($mess = "$file is not a block special file.");
  77. $tmp eq 'c' && ($mess = "$file is not a character special file.");
  78. $tmp eq 'u' && ($mess = "$file does not have the setuid bit set.");
  79. $tmp eq 'g' && ($mess = "$file does not have the setgid bit set.");
  80. $tmp eq 'k' && ($mess = "$file does not have the sticky bit set.");
  81. $tmp eq 'T' && ($mess = "$file is not a text file.");
  82. $tmp eq 'B' && ($mess = "$file is not a binary file.");
  83. if ($neg eq '!') {
  84. $mess =~ s/ is not / should not be / ||
  85. $mess =~ s/ does not / should not / ||
  86. $mess =~ s/ not / /;
  87. }
  88. print STDERR $mess,"\n";
  89. }
  90. else {
  91. $this =~ s/\$file/'$file'/g;
  92. print STDERR "Can't do $this.\n";
  93. }
  94. if ($disposition eq 'die') { exit 1; }
  95. ++$warnings;
  96. }
  97. 1;