2
0

make_var_export.awk 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Based on apr's make_export.awk, which is
  2. # based on Ryan Bloom's make_export.pl
  3. /^#[ \t]*if(def)? (AP[RUI]?_|!?defined).*/ {
  4. if (old_filename != FILENAME) {
  5. if (old_filename != "") printf("%s", line)
  6. macro_no = 0
  7. found = 0
  8. count = 0
  9. old_filename = FILENAME
  10. line = ""
  11. }
  12. macro_stack[macro_no++] = macro
  13. macro = substr($0, length($1)+2)
  14. count++
  15. line = line "#ifdef " macro "\n"
  16. next
  17. }
  18. /^#[ \t]*endif/ {
  19. if (count > 0) {
  20. count--
  21. line = line "#endif /* " macro " */\n"
  22. macro = macro_stack[--macro_no]
  23. }
  24. if (count == 0) {
  25. if (found != 0) {
  26. printf("%s", line)
  27. }
  28. line = ""
  29. }
  30. next
  31. }
  32. function add_symbol (sym_name) {
  33. if (count) {
  34. found++
  35. }
  36. for (i = 0; i < count; i++) {
  37. line = line "\t"
  38. }
  39. line = line sym_name "\n"
  40. if (count == 0) {
  41. printf("%s", line)
  42. line = ""
  43. }
  44. }
  45. /^[ \t]*(extern[ \t]+)?AP[RUI]?_DECLARE_DATA .*;$/ {
  46. varname = $NF;
  47. gsub( /[*;]/, "", varname);
  48. gsub( /\[.*\]/, "", varname);
  49. add_symbol(varname);
  50. }
  51. END {
  52. printf("%s", line)
  53. }