Browse Source

organize into folders (why didn't i think of this sooner?)

pull/1/head
Alison Watson 9 months ago
parent
commit
94e70bd557
80 changed files with 227 additions and 220 deletions
  1. +63
    -63
      api.md
  2. +0
    -0
      api/actor/State.md
  3. +0
    -0
      api/base/Array.md
  4. +0
    -0
      api/base/CVar.md
  5. +0
    -0
      api/base/Color.md
  6. +0
    -0
      api/base/FixedArray.md
  7. +0
    -0
      api/base/Object.md
  8. +0
    -0
      api/base/String.md
  9. +0
    -0
      api/base/StringTable.md
  10. +0
    -0
      api/base/Thinker.md
  11. +0
    -0
      api/base/Vector.md
  12. +0
    -0
      api/drawing/BrokenLines.md
  13. +0
    -0
      api/drawing/Console.md
  14. +0
    -0
      api/drawing/Font.md
  15. +0
    -0
      api/drawing/GIFont.md
  16. +0
    -0
      api/drawing/Screen.md
  17. +0
    -0
      api/drawing/Shape2D.md
  18. +0
    -0
      api/drawing/TexMan.md
  19. +0
    -0
      api/drawing/TextureID.md
  20. +0
    -0
      api/events/ConsoleEvent.md
  21. +0
    -0
      api/events/EventHandler.md
  22. +0
    -0
      api/events/RenderEvent.md
  23. +0
    -0
      api/events/ReplaceEvent.md
  24. +0
    -0
      api/events/StaticEventHandler.md
  25. +0
    -0
      api/files/Wads.md
  26. +0
    -0
      api/global/data/Client.md
  27. +0
    -0
      api/global/data/Constants.md
  28. +0
    -0
      api/global/data/Game.md
  29. +0
    -0
      api/global/data/Information.md
  30. +0
    -0
      api/global/data/Player.md
  31. +0
    -0
      api/global/func/Classes.md
  32. +0
    -0
      api/global/func/Game.md
  33. +0
    -0
      api/global/func/Math.md
  34. +0
    -0
      api/global/func/Random.md
  35. +0
    -0
      api/global/func/Sound.md
  36. +0
    -0
      api/global/func/System.md
  37. +0
    -0
      api/global/type/DehInfo.md
  38. +0
    -0
      api/global/type/FOptionMenuSettings.md
  39. +0
    -0
      api/global/type/GameInfoStruct.md
  40. +0
    -0
      api/global/type/LevelLocals.md
  41. +0
    -0
      api/inter/InterBackground.md
  42. +0
    -0
      api/inter/PatchInfo.md
  43. +0
    -0
      api/inter/StatusScreen.md
  44. +0
    -0
      api/inter/WBPlayerStruct.md
  45. +0
    -0
      api/inter/WBStartStruct.md
  46. +0
    -0
      api/level/F3DFloor.md
  47. +0
    -0
      api/level/FColorMap.md
  48. +0
    -0
      api/level/Line.md
  49. +0
    -0
      api/level/LineIdIterator.md
  50. +0
    -0
      api/level/SecPlane.md
  51. +0
    -0
      api/level/SecSpecial.md
  52. +0
    -0
      api/level/Sector.md
  53. +0
    -0
      api/level/SectorEffect.md
  54. +0
    -0
      api/level/SectorTagIterator.md
  55. +0
    -0
      api/level/Side.md
  56. +0
    -0
      api/level/Vertex.md
  57. +0
    -0
      api/player/PlayerClass.md
  58. +0
    -0
      api/player/PlayerSkin.md
  59. +0
    -0
      api/player/Team.md
  60. +0
    -0
      api/sound/SeqNode.md
  61. +0
    -0
      api/weapon/PSprite.md
  62. +5
    -5
      glossary.md
  63. +0
    -0
      glossary/Classes.md
  64. +0
    -0
      glossary/Concepts.md
  65. +0
    -0
      glossary/Structures.md
  66. +0
    -0
      glossary/Style.md
  67. +0
    -0
      glossary/Versions.md
  68. +9
    -9
      language.md
  69. +0
    -0
      language/Classes.md
  70. +0
    -0
      language/Constants.md
  71. +0
    -0
      language/Enumerations.md
  72. +0
    -0
      language/Expressions.md
  73. +0
    -0
      language/Members.md
  74. +0
    -0
      language/Methods.md
  75. +0
    -0
      language/Statements.md
  76. +0
    -0
      language/Structures.md
  77. +0
    -0
      language/Types.md
  78. +42
    -35
      tools/tocgen.rb
  79. +17
    -17
      tools/treegen.rb
  80. +91
    -91
      tools/zsclasstree.rb

+ 63
- 63
api.md View File

@@ -26,7 +26,7 @@ modder rather than for the engine.

<!-- inter-toc actor -->

* [State](api-actor-State.md)
* [State](api/actor/State.md)

<!-- end -->

@@ -36,15 +36,15 @@ TODO

<!-- inter-toc base -->

* [Array](api-base-Array.md)
* [Color](api-base-Color.md)
* [CVar](api-base-CVar.md)
* [FixedArray](api-base-FixedArray.md)
* [Object](api-base-Object.md)
* [String](api-base-String.md)
* [StringTable](api-base-StringTable.md)
* [Thinker](api-base-Thinker.md)
* [Vector](api-base-Vector.md)
* [Array](api/base/Array.md)
* [CVar](api/base/CVar.md)
* [Color](api/base/Color.md)
* [FixedArray](api/base/FixedArray.md)
* [Object](api/base/Object.md)
* [StringTable](api/base/StringTable.md)
* [String](api/base/String.md)
* [Thinker](api/base/Thinker.md)
* [Vector](api/base/Vector.md)

<!-- end -->

@@ -54,14 +54,14 @@ TODO

<!-- inter-toc drawing -->

* [BrokenLines](api-drawing-BrokenLines.md)
* [Console](api-drawing-Console.md)
* [Font](api-drawing-Font.md)
* [GIFont](api-drawing-GIFont.md)
* [Screen](api-drawing-Screen.md)
* [Shape2D](api-drawing-Shape2D.md)
* [TexMan](api-drawing-TexMan.md)
* [TextureID](api-drawing-TextureID.md)
* [BrokenLines](api/drawing/BrokenLines.md)
* [Console](api/drawing/Console.md)
* [Font](api/drawing/Font.md)
* [GIFont](api/drawing/GIFont.md)
* [Screen](api/drawing/Screen.md)
* [Shape2D](api/drawing/Shape2D.md)
* [TexMan](api/drawing/TexMan.md)
* [TextureID](api/drawing/TextureID.md)

<!-- end -->

@@ -71,11 +71,11 @@ TODO

<!-- inter-toc events -->

* [ConsoleEvent](api-events-ConsoleEvent.md)
* [EventHandler](api-events-EventHandler.md)
* [RenderEvent](api-events-RenderEvent.md)
* [ReplaceEvent](api-events-ReplaceEvent.md)
* [StaticEventHandler](api-events-StaticEventHandler.md)
* [ConsoleEvent](api/events/ConsoleEvent.md)
* [EventHandler](api/events/EventHandler.md)
* [RenderEvent](api/events/RenderEvent.md)
* [ReplaceEvent](api/events/ReplaceEvent.md)
* [StaticEventHandler](api/events/StaticEventHandler.md)

<!-- end -->

@@ -85,7 +85,7 @@ TODO

<!-- inter-toc files -->

* [Wads](api-files-Wads.md)
* [Wads](api/files/Wads.md)

<!-- end -->

@@ -95,11 +95,11 @@ TODO

<!-- inter-toc inter -->

* [InterBackground](api-inter-InterBackground.md)
* [PatchInfo](api-inter-PatchInfo.md)
* [StatusScreen](api-inter-StatusScreen.md)
* [WBPlayerStruct](api-inter-WBPlayerStruct.md)
* [WBStartStruct](api-inter-WBStartStruct.md)
* [InterBackground](api/inter/InterBackground.md)
* [PatchInfo](api/inter/PatchInfo.md)
* [StatusScreen](api/inter/StatusScreen.md)
* [WBPlayerStruct](api/inter/WBPlayerStruct.md)
* [WBStartStruct](api/inter/WBStartStruct.md)

<!-- end -->

@@ -115,17 +115,17 @@ for [statistics drivers][1].

<!-- inter-toc level -->

* [F3DFloor](api-level-F3DFloor.md)
* [FColorMap](api-level-FColorMap.md)
* [Line](api-level-Line.md)
* [LineIdIterator](api-level-LineIdIterator.md)
* [SecPlane](api-level-SecPlane.md)
* [SecSpecial](api-level-SecSpecial.md)
* [Sector](api-level-Sector.md)
* [SectorEffect](api-level-SectorEffect.md)
* [SectorTagIterator](api-level-SectorTagIterator.md)
* [Side](api-level-Side.md)
* [Vertex](api-level-Vertex.md)
* [F3DFloor](api/level/F3DFloor.md)
* [FColorMap](api/level/FColorMap.md)
* [LineIdIterator](api/level/LineIdIterator.md)
* [Line](api/level/Line.md)
* [SecPlane](api/level/SecPlane.md)
* [SecSpecial](api/level/SecSpecial.md)
* [SectorEffect](api/level/SectorEffect.md)
* [SectorTagIterator](api/level/SectorTagIterator.md)
* [Sector](api/level/Sector.md)
* [Side](api/level/Side.md)
* [Vertex](api/level/Vertex.md)

<!-- end -->

@@ -135,9 +135,9 @@ TODO

<!-- inter-toc player -->

* [PlayerClass](api-player-PlayerClass.md)
* [PlayerSkin](api-player-PlayerSkin.md)
* [Team](api-player-Team.md)
* [PlayerClass](api/player/PlayerClass.md)
* [PlayerSkin](api/player/PlayerSkin.md)
* [Team](api/player/Team.md)

<!-- end -->

@@ -147,7 +147,7 @@ TODO

<!-- inter-toc sound -->

* [SeqNode](api-sound-SeqNode.md)
* [SeqNode](api/sound/SeqNode.md)

<!-- end -->

@@ -157,7 +157,7 @@ TODO

<!-- inter-toc wep -->

* [PSprite](api-wep-PSprite.md)

<!-- end -->

@@ -165,39 +165,39 @@ TODO

# Global Objects

<!-- inter-toc global-data -->
<!-- inter-toc global/data -->

* [Client](api-global-data-Client.md)
* [Constants](api-global-data-Constants.md)
* [Game](api-global-data-Game.md)
* [Information](api-global-data-Information.md)
* [Player](api-global-data-Player.md)
* [Client](api/global/data/Client.md)
* [Constants](api/global/data/Constants.md)
* [Game](api/global/data/Game.md)
* [Information](api/global/data/Information.md)
* [Player](api/global/data/Player.md)

<!-- end -->

These variables are accessible in any context and are not bound by any specific
object. Generally these mirror global information within the engine itself.

<!-- inter-toc global-func -->
<!-- inter-toc global/func -->

* [Classes](api-global-func-Classes.md)
* [Game](api-global-func-Game.md)
* [Math](api-global-func-Math.md)
* [Random](api-global-func-Random.md)
* [Sound](api-global-func-Sound.md)
* [System](api-global-func-System.md)
* [Classes](api/global/func/Classes.md)
* [Game](api/global/func/Game.md)
* [Math](api/global/func/Math.md)
* [Random](api/global/func/Random.md)
* [Sound](api/global/func/Sound.md)
* [System](api/global/func/System.md)

<!-- end -->

These functions are accessible in any context and are not bound by any specific
object. Generally these are utility functions.

<!-- inter-toc global-type -->
<!-- inter-toc global/type -->

* [DehInfo](api-global-type-DehInfo.md)
* [FOptionMenuSettings](api-global-type-FOptionMenuSettings.md)
* [GameInfoStruct](api-global-type-GameInfoStruct.md)
* [LevelLocals](api-global-type-LevelLocals.md)
* [DehInfo](api/global/type/DehInfo.md)
* [FOptionMenuSettings](api/global/type/FOptionMenuSettings.md)
* [GameInfoStruct](api/global/type/GameInfoStruct.md)
* [LevelLocals](api/global/type/LevelLocals.md)

<!-- end -->



api-actor-State.md → api/actor/State.md View File


api-base-Array.md → api/base/Array.md View File


api-base-CVar.md → api/base/CVar.md View File


api-base-Color.md → api/base/Color.md View File


api-base-FixedArray.md → api/base/FixedArray.md View File


api-base-Object.md → api/base/Object.md View File


api-base-String.md → api/base/String.md View File


api-base-StringTable.md → api/base/StringTable.md View File


api-base-Thinker.md → api/base/Thinker.md View File


api-base-Vector.md → api/base/Vector.md View File


api-drawing-BrokenLines.md → api/drawing/BrokenLines.md View File


api-drawing-Console.md → api/drawing/Console.md View File


api-drawing-Font.md → api/drawing/Font.md View File


api-drawing-GIFont.md → api/drawing/GIFont.md View File


api-drawing-Screen.md → api/drawing/Screen.md View File


api-drawing-Shape2D.md → api/drawing/Shape2D.md View File


api-drawing-TexMan.md → api/drawing/TexMan.md View File


api-drawing-TextureID.md → api/drawing/TextureID.md View File


api-events-ConsoleEvent.md → api/events/ConsoleEvent.md View File


api-events-EventHandler.md → api/events/EventHandler.md View File


api-events-RenderEvent.md → api/events/RenderEvent.md View File


api-events-ReplaceEvent.md → api/events/ReplaceEvent.md View File


api-events-StaticEventHandler.md → api/events/StaticEventHandler.md View File


api-files-Wads.md → api/files/Wads.md View File


api-global-data-Client.md → api/global/data/Client.md View File


api-global-data-Constants.md → api/global/data/Constants.md View File


api-global-data-Game.md → api/global/data/Game.md View File


api-global-data-Information.md → api/global/data/Information.md View File


api-global-data-Player.md → api/global/data/Player.md View File


api-global-func-Classes.md → api/global/func/Classes.md View File


api-global-func-Game.md → api/global/func/Game.md View File


api-global-func-Math.md → api/global/func/Math.md View File


api-global-func-Random.md → api/global/func/Random.md View File


api-global-func-Sound.md → api/global/func/Sound.md View File


api-global-func-System.md → api/global/func/System.md View File


api-global-type-DehInfo.md → api/global/type/DehInfo.md View File


api-global-type-FOptionMenuSettings.md → api/global/type/FOptionMenuSettings.md View File


api-global-type-GameInfoStruct.md → api/global/type/GameInfoStruct.md View File


api-global-type-LevelLocals.md → api/global/type/LevelLocals.md View File


api-inter-InterBackground.md → api/inter/InterBackground.md View File


api-inter-PatchInfo.md → api/inter/PatchInfo.md View File


api-inter-StatusScreen.md → api/inter/StatusScreen.md View File


api-inter-WBPlayerStruct.md → api/inter/WBPlayerStruct.md View File


api-inter-WBStartStruct.md → api/inter/WBStartStruct.md View File


api-level-F3DFloor.md → api/level/F3DFloor.md View File


api-level-FColorMap.md → api/level/FColorMap.md View File


api-level-Line.md → api/level/Line.md View File


api-level-LineIdIterator.md → api/level/LineIdIterator.md View File


api-level-SecPlane.md → api/level/SecPlane.md View File


api-level-SecSpecial.md → api/level/SecSpecial.md View File


api-level-Sector.md → api/level/Sector.md View File


api-level-SectorEffect.md → api/level/SectorEffect.md View File


api-level-SectorTagIterator.md → api/level/SectorTagIterator.md View File


api-level-Side.md → api/level/Side.md View File


api-level-Vertex.md → api/level/Vertex.md View File


api-player-PlayerClass.md → api/player/PlayerClass.md View File


api-player-PlayerSkin.md → api/player/PlayerSkin.md View File


api-player-Team.md → api/player/Team.md View File


api-sound-SeqNode.md → api/sound/SeqNode.md View File


api-wep-PSprite.md → api/weapon/PSprite.md View File


+ 5
- 5
glossary.md View File

@@ -2,11 +2,11 @@

<!-- inter-toc -->

* [Classes](glossary-Classes.md)
* [Concepts](glossary-Concepts.md)
* [Structures](glossary-Structures.md)
* [Style](glossary-Style.md)
* [Versions](glossary-Versions.md)
* [Classes](glossary/Classes.md)
* [Concepts](glossary/Concepts.md)
* [Structures](glossary/Structures.md)
* [Style](glossary/Style.md)
* [Versions](glossary/Versions.md)

<!-- end -->



glossary-Classes.md → glossary/Classes.md View File


glossary-Concepts.md → glossary/Concepts.md View File


glossary-Structures.md → glossary/Structures.md View File


glossary-Style.md → glossary/Style.md View File


glossary-Versions.md → glossary/Versions.md View File


lang.md → language.md View File

@@ -127,15 +127,15 @@ Finally, here is a table of contents for each language element:

<!-- inter-toc -->

* [Classes](lang-Classes.md)
* [Constants](lang-Constants.md)
* [Enumerations](lang-Enumerations.md)
* [Expressions](lang-Expressions.md)
* [Members](lang-Members.md)
* [Methods](lang-Methods.md)
* [Statements](lang-Statements.md)
* [Structures](lang-Structures.md)
* [Types](lang-Types.md)
* [Classes](language/Classes.md)
* [Constants](language/Constants.md)
* [Enumerations](language/Enumerations.md)
* [Expressions](language/Expressions.md)
* [Members](language/Members.md)
* [Methods](language/Methods.md)
* [Statements](language/Statements.md)
* [Structures](language/Structures.md)
* [Types](language/Types.md)

<!-- end -->


lang-Classes.md → language/Classes.md View File


lang-Constants.md → language/Constants.md View File


lang-Enumerations.md → language/Enumerations.md View File


lang-Expressions.md → language/Expressions.md View File


lang-Members.md → language/Members.md View File


lang-Methods.md → language/Methods.md View File


lang-Statements.md → language/Statements.md View File


lang-Structures.md → language/Structures.md View File


lang-Types.md → language/Types.md View File


+ 42
- 35
tools/tocgen.rb View File

@@ -3,55 +3,62 @@
## By Alison Sanderson. Attribution is encouraged, though not required.
## <https://creativecommons.org/publicdomain/zero/1.0/legalcode>
## TOCGen: Generates inter-file TOCs.
## Example usage:
## tools/tocgen.rb

$d = Dir["*.md"]
def emit_filtered_file_toc file_matcher
links = []
files = ALL_MD_FILES.map do |p| p.match file_matcher end.compact

def filter_emit r
res = []
for m in $d.map{|p| p.match r}.compact
res << "* [#{m[1]}](#{m[0]})"
end
res.join ?\n
for md_file in files
links << "* [#{md_file[1]}](#{md_file[0]})"
end

links.sort.join ?\n
end

def find_toc_areas f
re = /^(<!-- inter-toc\s*([^\s]+)\s*-->)(?:.|\n)*?(<!-- end -->)/i
f.to_enum(:scan, re).map{$~}
TOC_REGEX = /^(<!-- inter-toc\s*([^\s]+)?\s*-->)(?:.|\n)*?(<!-- end -->)/i
def find_inter_toc_areas file
file.to_enum(:scan, TOC_REGEX).map do $~ end
end

def filter_toc_areas f
o = String.new
lof = 0
for area in find_toc_areas f
of = area.offset 0
o << f[lof...of[0]]
o << area[1]
o << "\n\n"
o << filter_emit(yield area[2])
o << "\n\n"
o << area[3]
lof = of[1]
end
o << f[lof..-1]
o
def filter_toc_areas file
content = ""
last_offset = 0

for area in find_inter_toc_areas file
offset = area.offset 0
content << file[last_offset...offset[0]]
content << area[1]
content << "\n\n"
content << emit_filtered_file_toc(yield area[2])
content << "\n\n"
content << area[3]
last_offset = offset[1]
end

content << file[last_offset..-1]
content
end

def rewrite fnam
f = File.read fnam
o = yield f
File.write fnam, o
def rewrite filename
file = File.read filename
output = yield file
File.write filename, output
end

rewrite "api.md" do |f|
filter_toc_areas f do |a| /api-#{a}-(\w+).md/ end
ALL_MD_FILES = Dir["{api,glossary,language}/**/*.md"]

rewrite "api.md" do |file|
filter_toc_areas file do |folder| /api\/#{folder}\/(\w+).md/ end
end

rewrite "glossary.md" do |f|
filter_toc_areas f do |a| /glossary-(\w+).md/ end
rewrite "glossary.md" do |file|
filter_toc_areas file do |_| /glossary\/(\w+).md/ end
end

rewrite "lang.md" do |f|
filter_toc_areas f do |a| /lang-(\w+).md/ end
rewrite "language.md" do |file|
filter_toc_areas file do |_| /language\/(\w+).md/ end
end

## EOF

+ 17
- 17
tools/treegen.rb View File

@@ -4,51 +4,51 @@
## <https://creativecommons.org/publicdomain/zero/1.0/legalcode>
## TreeGen: Generates the glossary files for classes.
## Example usage:
## tools/treegen.rb \
## tools/treegen.rb \
## '/mnt/g/Archive/gzdoom-g4.1.0/wadsrc/static/zscript/**/*.zs' \
## 4.1.0

require "./tools/zsclasstree.rb"

DIR = ARGV.shift
VER = ARGV.shift
FILES = ARGV.shift
VERSION = ARGV.shift

si = ClassSiphon.new DIR
siphon = ClassSiphon.new FILES

f = open "glossary-Classes.md", "wb"
f.puts <<_end_
file = open "glossary-Classes.md", "wb"
file.puts <<_end_
# Classes

Here is a full tree of all classes in ZScript as of GZDoom #{VER}. There are
#{si.classes.count + 1} classes total.
Here is a full tree of all classes in ZScript as of GZDoom #{VERSION}. There
are #{siphon.classes.count + 1} classes total.

```
Object
_end_

si.print_classes f
siphon.print_classes file

f.puts <<_end_
file.puts <<_end_
```

<!-- EOF -->
_end_

f = open "glossary-Structures.md", "wb"
f.puts <<_end_
file = open "glossary-Structures.md", "wb"
file.puts <<_end_
# Structures

Here is a full list of all structures in ZScript as of GZDoom #{VER}. There are
#{si.structs.count} structures total. Note that some of these are merely
implementation details and should not be used in code.
Here is a full list of all structures in ZScript as of GZDoom #{VERSION}.
There are #{siphon.structs.count} structures total. Note that some of these
are merely implementation details and should not be used in code.

```
Struct
_end_

si.print_structs f
siphon.print_structs file

f.puts <<_end_
file.puts <<_end_
```

<!-- EOF -->


+ 91
- 91
tools/zsclasstree.rb View File

@@ -11,101 +11,101 @@
require 'set'

class ClassSiphon
attr_reader :structs, :classes, :clstree, :strtree, :caps
def initialize dirs
@subcls = {}
@classes = Set[]
@structs = Set[]
@caps = {}
Dir.glob dirs do |f| proc_file File.read f end
@clstree = make_tree "OBJECT", @subcls["OBJECT"]
@strtree = @structs.map {|type| [type, nil]}
@classes.freeze
@structs.freeze
@clstree.freeze
@strtree.freeze
@caps.freeze
end
def print_classes out, filter = []
print_tree out, filter, "OBJECT", clstree
end
def print_structs out, filter = []
print_tree out, filter, "STRUCT", strtree
end
private
def add_class m
ctype = m[0] .strip
cbase = (m[1] or "Object").strip
type = ctype.upcase
base = cbase.upcase
@caps[type] = ctype
@caps[base] = cbase
if base != type
if @subcls[base]
@subcls[base] << type
else
@subcls[base] = [type]
end
raise "duplicate class #{type}" if @classes === type
@classes << type
end
end
def add_struct m
ctype = m[0]
type = ctype.upcase
@caps[type] = ctype
@structs << type
end
def proc_file f
f.gsub! /\/\*(?!\*\/)+\*\//m, ""
f.gsub! /\/\/.+/, ""
f.scan(/^class\s*(\w*)[\s\w]+(?::\s+(\w*))?/).each {|m| add_class m}
f.scan(/^struct\s*(\w*)/) .each {|m| add_struct m}
end
# work our way down the subclasses recursively, making them into a tree structure
def make_tree bcl, subs
return nil unless subs
node = {}
subs.each do |cl| node[cl] = make_tree cl, @subcls[cl] end
node
end
def print_tree out, filter, base, tree, tab = ""
return if !tree or filter.include? base
tree = tree.map do |type, base| [type, base] end
tree.sort!
for type, base in tree
last = type == tree[-1][0]
sep = last ? "└ " : "├ "
nxt = last ? " " : "│ "
out.puts tab + sep + @caps[type]
print_tree out, filter, type, base, tab + nxt
end
end
attr_reader :structs, :classes, :clstree, :strtree, :caps
def initialize dirs
@subcls = {}
@classes = Set[]
@structs = Set[]
@caps = {}
Dir.glob dirs do |f| proc_file File.read f end
@clstree = make_tree "OBJECT", @subcls["OBJECT"]
@strtree = @structs.map {|type| [type, nil]}
@classes.freeze
@structs.freeze
@clstree.freeze
@strtree.freeze
@caps.freeze
end
def print_classes out, filter = []
print_tree out, filter, "OBJECT", clstree
end
def print_structs out, filter = []
print_tree out, filter, "STRUCT", strtree
end
private
def add_class m
ctype = m[0] .strip
cbase = (m[1] or "Object").strip
type = ctype.upcase
base = cbase.upcase
@caps[type] = ctype
@caps[base] = cbase
if base != type
if @subcls[base]
@subcls[base] << type
else
@subcls[base] = [type]
end
raise "duplicate class #{type}" if @classes === type
@classes << type
end
end
def add_struct m
ctype = m[0]
type = ctype.upcase
@caps[type] = ctype
@structs << type
end
def proc_file f
f.gsub! /\/\*(?!\*\/)+\*\//m, ""
f.gsub! /\/\/.+/, ""
f.scan(/^class\s*(\w*)[\s\w]+(?::\s+(\w*))?/).each {|m| add_class m}
f.scan(/^struct\s*(\w*)/) .each {|m| add_struct m}
end
# work our way down the subclasses recursively, making them into a tree structure
def make_tree bcl, subs
return nil unless subs
node = {}
subs.each do |cl| node[cl] = make_tree cl, @subcls[cl] end
node
end
def print_tree out, filter, base, tree, tab = ""
return if !tree or filter.include? base
tree = tree.map do |type, base| [type, base] end
tree.sort!
for type, base in tree
last = type == tree[-1][0]
sep = last ? "└ " : "├ "
nxt = last ? " " : "│ "
out.puts tab + sep + @caps[type]
print_tree out, filter, type, base, tab + nxt
end
end
end

if __FILE__ == $0
in_dirs = ARGV.shift
filters = ARGV
in_dirs = ARGV.shift
filters = ARGV

si = ClassSiphon.new in_dirs
puts "Object"; si.print_classes STDOUT, filters
puts "Struct"; si.print_structs STDOUT, filters
si = ClassSiphon.new in_dirs
puts "Object"; si.print_classes STDOUT, filters
puts "Struct"; si.print_structs STDOUT, filters
end

## EOF

Loading…
Cancel
Save