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.

95 lines
2.5 KiB

  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. #
  18. use vars qw($opt_h $opt_x);
  19. use Getopt::Std;
  20. my %charMapping = ( ':', 'chColon',
  21. '\\', 'chBackSlash',
  22. '[', 'chOpenSquare',
  23. ']', 'chCloseSquare',
  24. '{', 'chOpenCurly',
  25. '}', 'chCloseCurly',
  26. '?', 'chQuestion',
  27. '(', 'chOpenParen',
  28. ')', 'chCloseParen',
  29. '/', 'chForwardSlash',
  30. '*', 'chAsterisk',
  31. '+', 'chPlus',
  32. '.', 'chPeriod',
  33. '-', 'chDash',
  34. '|', 'chPipe',
  35. '_', 'chUnderscore',
  36. ',', 'chComma',
  37. '&', 'chAmpersand',
  38. '0', 'chDigit_0', '1', 'chDigit_1', '2', 'chDigit_2',
  39. '3', 'chDigit_3', '4', 'chDigit_4', '5', 'chDigit_5',
  40. '6', 'chDigit_6', '7', 'chDigit_7', '8', 'chDigit_8',
  41. '9', 'chDigit_9');
  42. #
  43. # usage: display usage message
  44. #
  45. sub usage() {
  46. print<<EOF;
  47. usage: $0 [ options ] word
  48. Takes a word and produces a static XMLCh * definition for it.
  49. Options:
  50. -h Displays this help message
  51. -x add the XERCES_CPP_NAMESPACE_QUALIFIER before each item
  52. EOF
  53. exit(1);
  54. }
  55. #
  56. # main:
  57. #
  58. getopts("hx");
  59. if ($opt_h or @ARGV == 0) {
  60. usage();
  61. }
  62. my $word = $ARGV[0];
  63. print "{ ";
  64. while ($word=~s/^(.)//) {
  65. if (defined($charMapping{$1})) {
  66. $ch = $charMapping{$1};
  67. } else {
  68. $ch = $1;
  69. if ($ch=~/[A-Za-z]/) {
  70. $ch = "chLatin_$ch";
  71. } else {
  72. $ch = "UNKNOWN_CHAR_$ch";
  73. }
  74. }
  75. if($opt_x) {
  76. print "XERCES_CPP_NAMESPACE_QUALIFIER ";
  77. }
  78. print "$ch, ";
  79. }
  80. if($opt_x) {
  81. print "XERCES_CPP_NAMESPACE_QUALIFIER ";
  82. }
  83. print "chNull };\n";