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.

55 lines
1.3 KiB

  1. # assert.pl
  2. # [email protected] (Tom Christiansen)
  3. #
  4. # Usage:
  5. #
  6. # &assert('@x > @y');
  7. # &assert('$var > 10', $var, $othervar, @various_info);
  8. #
  9. # That is, if the first expression evals false, we blow up. The
  10. # rest of the args, if any, are nice to know because they will
  11. # be printed out by &panic, which is just the stack-backtrace
  12. # routine shamelessly borrowed from the perl debugger.
  13. sub assert {
  14. &panic("ASSERTION BOTCHED: $_[$[]",$@) unless eval $_[$[];
  15. }
  16. sub panic {
  17. package DB;
  18. select(STDERR);
  19. print "\npanic: @_\n";
  20. exit 1 if $] <= 4.003; # caller broken
  21. # stack traceback gratefully borrowed from perl debugger
  22. local $_;
  23. my $i;
  24. my ($p,$f,$l,$s,$h,$a,@a,@frames);
  25. for ($i = 0; ($p,$f,$l,$s,$h,$w) = caller($i); $i++) {
  26. @a = @args;
  27. for (@a) {
  28. if (/^StB\000/ && length($_) == length($_main{'_main'})) {
  29. $_ = sprintf("%s",$_);
  30. }
  31. else {
  32. s/'/\\'/g;
  33. s/([^\0]*)/'$1'/ unless /^-?[\d.]+$/;
  34. s/([\200-\377])/sprintf("M-%c",ord($1)&0177)/eg;
  35. s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg;
  36. }
  37. }
  38. $w = $w ? '@ = ' : '$ = ';
  39. $a = $h ? '(' . join(', ', @a) . ')' : '';
  40. push(@frames, "$w&$s$a from file $f line $l\n");
  41. }
  42. for ($i=0; $i <= $#frames; $i++) {
  43. print $frames[$i];
  44. }
  45. exit 1;
  46. }
  47. 1;