extract-docs.awk 910 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. BEGIN {
  2. OBJ_MAP["f"] = "function";
  3. OBJ_MAP["m"] = "member";
  4. OBJ_MAP["M"] = "macro";
  5. OBJ_MAP["t"] = "type";
  6. OBJ_MAP["v"] = "var";
  7. in_doc = 0;
  8. indent = 0;
  9. }
  10. /^[[:space:]]*\/\*[\*\~][fmMtv]?/ {
  11. if (!in_doc) {
  12. in_doc = 1;
  13. }
  14. objtype = substr($1, length($1));
  15. if (objtype in OBJ_MAP) {
  16. objtype = OBJ_MAP[objtype];
  17. indent = (index($0, "/") - 1);
  18. if (indent) {
  19. indent = indent / 4;
  20. }
  21. indent++;
  22. } else {
  23. indent = 0;
  24. objtype = "";
  25. }
  26. if (length(objtype)) {
  27. for (i = 1; i < indent; i++) printf(" ");
  28. printf(".. c:%s::", objtype);
  29. for (i = 2; i <= NF; i++) printf(" %s", $(i));
  30. }
  31. printf("\n\n");
  32. next;
  33. }
  34. /^[[:space:]]*\*\// {
  35. in_doc = 0;
  36. printf("\n");
  37. next;
  38. }
  39. /^[[:space:]]*\*[[:space:]]*$/ {
  40. if (in_doc) print "";
  41. next;
  42. }
  43. {
  44. if (in_doc != 0) {
  45. gsub(/^[[:space:]]*\*[[:space:]]/, "");
  46. if (indent) {
  47. for (i = 0; i < indent; i++) printf(" ");
  48. }
  49. print;
  50. }
  51. }