XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
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.

164 lines
2.7 KiB

  1. #! /usr/bin/awk -f
  2. # vim:ts=4:sw=4
  3. BEGIN {
  4. brace = 0;
  5. incomment = 0;
  6. buffer_len = 0;
  7. }
  8. # multiline comment handling
  9. {
  10. # removes one line comment
  11. gsub(/\/\*(.+?)\*\//, " ");
  12. }
  13. /\*\// {
  14. if (incomment) {
  15. sub(/.*\*\//, "");
  16. incomment = 0;
  17. }
  18. }
  19. incomment {
  20. next;
  21. }
  22. /\/\*/ {
  23. sub(/\/\*.*/, "");
  24. incomment = 1;
  25. # fall through
  26. }
  27. # skip file/line mark here to be faster
  28. /^#/ {
  29. next;
  30. }
  31. /^}.*;/ {
  32. if (instruct) {
  33. sub(";", "");
  34. if (instruct == 1 && $2) {
  35. instruct = $2;
  36. }
  37. if (instruct in typedefs) {
  38. instruct = typedefs[instruct];
  39. }
  40. sizeinfo = "";
  41. elms = "";
  42. for (i = 0; i in buffer; i ++) {
  43. if (i) {
  44. sizeinfo = sizeinfo " + ";
  45. }
  46. sizeinfo = sizeinfo "sizeof(((" instruct "*)NULL)->" buffer[i] ")";
  47. if (i == 0) {
  48. elms = buffer[i];
  49. }
  50. else {
  51. elms = elms "," buffer[i];
  52. }
  53. }
  54. printf "define(`ELEMENTSOF_%s', `%s')\n", instruct, elms;
  55. printf "define(`COUNTOF_%s', `%s')\n", instruct, i;
  56. printf "define(`SIZEOF_%s', `( %s )')\n", instruct, sizeinfo;
  57. print "\n";
  58. for (i in buffer) {
  59. delete buffer[i];
  60. }
  61. buffer_len = 0;
  62. instruct = 0;
  63. }
  64. next;
  65. }
  66. /.\{/ {
  67. brace = brace + 1;
  68. }
  69. /.}/ {
  70. brace = brace - 1;
  71. }
  72. {
  73. if (brace == 1 && instruct) {
  74. gsub(/(^[\t ]+|[\t ]+$)/, ""); # trim whitespaces
  75. sub(/.*[{}]/, "");
  76. gsub(/\[[^\]]+\]/, ""); # ignore [...]
  77. gsub(/:[0-9]+/, ""); # ignore struct bit
  78. if (match($0, /^[^(]*\([ ]*\*([^)]+)\)/)) {
  79. sub(/ +/, "")
  80. sub(/^[^(]*\(\*/, "");
  81. sub(/\).*/, "");
  82. # function pointer
  83. buffer[buffer_len] = $0;
  84. buffer_len ++;
  85. }
  86. else {
  87. # process normal variables
  88. # ignore any ()s
  89. while (gsub(/(\([^)]*\))/, "")) {
  90. }
  91. if (match($0, /[()]/)) {
  92. next;
  93. }
  94. # unsigned int *a, b; int c;
  95. gsub(/[*]/, " ");
  96. # unsigned int a, b; int c;
  97. gsub(/ +/, " ");
  98. # unsigned int a, b; int c;
  99. gsub(/ *[,;]/, ";");
  100. # unsigned int a; b; int c;
  101. if (!match($0, /;/)) {
  102. next;
  103. }
  104. # print "=DEBUG=" $0 "==";
  105. split($0, chunks, ";");
  106. # [unsigned int a, b, c]
  107. for (i = 1; i in chunks; i ++) {
  108. if (chunks[i] == "") {
  109. delete chunks[i];
  110. continue;
  111. }
  112. split(chunks[i], pieces, " ");
  113. # [unsigned, int, a]
  114. # [b]
  115. # [c]
  116. last_piece = "";
  117. for (j = 1; j in pieces; j ++) {
  118. last_piece = pieces[j];
  119. delete pieces[j];
  120. }
  121. if (last_piece == "") {
  122. # print "=ERROR=" chunks[i] "==";
  123. delete chunks[i];
  124. continue;
  125. }
  126. # a
  127. # b
  128. # c
  129. buffer[buffer_len] = last_piece;
  130. buffer_len ++;
  131. delete chunks[i]
  132. }
  133. last_piece = "";
  134. }
  135. next;
  136. }
  137. }
  138. /^typedef struct [^{]*;/ {
  139. sub(";", "");
  140. typedefs[$3] = $4;
  141. next;
  142. }
  143. /^typedef struct .*\{[^}]*$/ {
  144. brace = 1;
  145. instruct = 1;
  146. next;
  147. }
  148. /^struct .*\{/ {
  149. instruct = $2;
  150. brace = 1;
  151. next;
  152. }