Leaked source code of windows server 2003
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.

159 lines
3.9 KiB

  1. #!/usr/bin/perl
  2. ##############################################################################
  3. #
  4. # qpidpars.pl -- QPID table generator
  5. #
  6. # author: [email protected]
  7. #
  8. ##############################################################################
  9. # Lookup for characters below the cutoff will be a simple array lookup
  10. $table_cutoff = 128;
  11. #-----------------------------------------------------------------------------
  12. #
  13. # Read in table
  14. #
  15. #-----------------------------------------------------------------------------
  16. # Contact michelsu for the format of the datafile
  17. %table = (); # empty the table
  18. while (<>)
  19. {
  20. if (/^\"*\d+\.\d+\.(\d+) (.) - (.*) *\"*$/) # new category
  21. {
  22. $t_index = $1;
  23. $enum_name = "$2_$3";
  24. $enum_name =~ s/\W/_/g; # convert non-alpha to underscore
  25. $enum_name =~ s/__/_/g; # remove double underscores
  26. $enum_name =~ s/_$//; # remove trailing underscore
  27. $enum_table[$t_index] = $enum_name;
  28. }
  29. if (/^(([\da-fA-F]){4})/) # range specification
  30. {
  31. @args = split("[ \n\t-]+", $_);
  32. $index = $args[0];
  33. $index =~ tr/a-f/A-F/;
  34. $index_end = (substr($_, 4, 1) eq "-") ? $args[1] : $index;
  35. $table{$index} = $t_index;
  36. $table_end{$index} = $index_end;
  37. }
  38. }
  39. #-----------------------------------------------------------------------------
  40. #
  41. # Collapse ranges
  42. #
  43. #-----------------------------------------------------------------------------
  44. $last_value = -1;
  45. $count = 0;
  46. foreach $index (sort keys %table)
  47. {
  48. $value = $table{$index};
  49. if ($value != $last_value && hex($table_end{$index}) >= $table_cutoff)
  50. {
  51. $collapsed_table[$count] = $index;
  52. $last_value = $value;
  53. $count++;
  54. }
  55. }
  56. #-----------------------------------------------------------------------------
  57. #
  58. # Print tables
  59. #
  60. #-----------------------------------------------------------------------------
  61. printf("//\n");
  62. printf("// This file was generate by the QPID parser application (%s)\n", __FILE__);
  63. printf("//\n");
  64. printf("// Generated on %s\n", scalar localtime);
  65. printf("//\n\n");
  66. #
  67. # Constants
  68. #
  69. printf("#define QPID_CHARRANGES %d\n\n", $count + 1);
  70. #printf("#define QPID_QUICKLOOKUPCUTOFF %d\n\n", $table_cutoff);
  71. #printf("#define QPID_MAX %d\n\n", $#enum_table + 1);
  72. #
  73. # Quick lookup table
  74. #
  75. #printf("static const QPID s_rgCharRangeSizeQuick[QPID_QUICKLOOKUPCUTOFF] =\n{\n");
  76. printf("QPID s_rgCharRangeSizeQuick[QPID_QUICKLOOKUPCUTOFF] =\n{\n");
  77. $last_value = 0;
  78. for ($i=0; $i<$table_cutoff; $i++)
  79. {
  80. printf(" ") if (($i & 7) == 0);
  81. $index = sprintf("%04X", $i);
  82. $value = $table{$index};
  83. printf("%4d,", $value ? $value : $last_value);
  84. $last_value = $table{$index} if $value;
  85. printf(" // U+%04x - U+%s\n", $i-7, $index) if (($i & 7) == 7);
  86. }
  87. printf("};\n\n");
  88. #
  89. # Range maximum character table
  90. #
  91. printf("// if r = range(wch), s_rgMaxCharForRange[r-1] < wch <= s_rgMaxCharForRange[r]\n\n");
  92. printf("static const WCHAR s_rgMaxCharForRange[QPID_CHARRANGES] =\n{\n");
  93. for ($index=0; $index <= $#collapsed_table; $index++)
  94. {
  95. $h = hex($collapsed_table[$index]) - ($index ? 1 : 0);
  96. printf(" 0x%04X, // %d\n", $h, $index);
  97. }
  98. printf(" 0xFFFF // %d\n};\n\n", $index);
  99. #
  100. # Range QPID table
  101. #
  102. print "static const QPID s_rgQpidRangeValue[QPID_CHARRANGES] =\n{\n";
  103. $last_value = 0;
  104. for ($index=0; $index <= $#collapsed_table; $index++)
  105. {
  106. printf(" %3d, // %d\n", $last_value, $index);
  107. $last_value = $table{$collapsed_table[$index]};
  108. }
  109. printf(" %3d // %d\n};\n\n", $last_value, $index);
  110. #
  111. # QPID Name enumeration
  112. #
  113. printf("enum QPIDNAME\n{\n X_Invalid = 0,\n");
  114. print "$enum_table";
  115. for ($index=1; $index <= $#enum_table; $index++)
  116. {
  117. printf(" %s = %d,\n", $enum_table[$index], $index);
  118. }
  119. printf("};\n");