mkDBErrStrs.pl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/local/bin/perl
  2. #
  3. # BEGIN COPYRIGHT BLOCK
  4. # Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  5. # Copyright (C) 2005 Red Hat, Inc.
  6. # All rights reserved.
  7. #
  8. # License: GPL (version 3 or any later version).
  9. # See LICENSE for details.
  10. # END COPYRIGHT BLOCK
  11. #
  12. #
  13. # Perl script to generate dberrstrs.h, which is used in errormap.c.
  14. #
  15. sub numerically { $a <=> $b; }
  16. $dbdir = "";
  17. $isNT = 0;
  18. $i = 0;
  19. $outdir = "";
  20. while ($i <= $#ARGV) {
  21. if ("$ARGV[$i]" eq "-nt" || "$ARGV[$i]" eq "-NT") { # NT
  22. $isNT = 1;
  23. } elsif ("$ARGV[$i]" eq "-o" || "$ARGV[$i]" eq "-O") { # output dir
  24. $i++;
  25. $outdir = $ARGV[$i];
  26. } elsif ("$ARGV[$i]" eq "-i" || "$ARGV[$i]" eq "-I") { # input db dir
  27. $i++;
  28. $dbdir = $ARGV[$i];
  29. }
  30. $i++;
  31. }
  32. if ($dbdir eq "") {
  33. print(STDERR "Usage: $0 [-nt] <db_dir_path>\n");
  34. exit(1);
  35. }
  36. if ($isNT == 1) {
  37. $dirsep = "\\";
  38. } else {
  39. $dirsep = "/";
  40. }
  41. $dbh = sprintf("%s%sdb.h", $dbdir, $dirsep);
  42. open(FOO, $dbh) || die "Cannot open $dbh\n";
  43. @lines = <FOO>;
  44. close(FOO);
  45. $i = 0;
  46. $j = 0;
  47. while ($i < $#lines) {
  48. chop($lines[$i]);
  49. if ($lines[$i] =~ /^#define[ ][_A-Z]*[ ]*\(-[0-9]*/) {
  50. ($h, $t) = split(/\(/, $lines[$i], 2);
  51. ($num[$j], $tt) = split(/\)/, $t, 2);
  52. ($h, $ttt) = split(/\/\* /, $tt, 2);
  53. ($errstr, $tttt) = split(/ \*\//, $ttt, 2);
  54. if ($errstr ne "") {
  55. $errstr =~ s/\"/\\\"/g; # Escape quotes
  56. $numStrPair{$num[$j]} = $errstr;
  57. }
  58. $j++;
  59. }
  60. $i++;
  61. }
  62. sort numerically num;
  63. if ($outdir eq "") {
  64. $myheader = "dberrstrs.h";
  65. } else {
  66. $myheader = sprintf("%s%sdberrstrs.h", $outdir, $dirsep);
  67. }
  68. open(FOO, "> $myheader") || die "Cannot open $myheader\n";
  69. print( FOO "/* DO NOT EDIT: This is an automatically generated file by $0 */\n" );
  70. $i = 0;
  71. while ($i < $j) {
  72. print( FOO "{$num[$i],\t\"$numStrPair{$num[$i]}\"},\n" );
  73. $i++;
  74. }
  75. close(FOO);