diff options
| author | realtradam <[email protected]> | 2022-03-04 21:48:50 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2022-03-04 21:48:50 -0500 |
| commit | 4dec6210af82ce63585e1bf5c3a3b5bea1fa83e3 (patch) | |
| tree | 9659eb7bd77853bf682a5ab5b9d7b0bfa0633a72 | |
| parent | 137f30dc1799e87d7e19becca08a8b870e281ed1 (diff) | |
| download | FelBind-4dec6210af82ce63585e1bf5c3a3b5bea1fa83e3.tar.gz FelBind-4dec6210af82ce63585e1bf5c3a3b5bea1fa83e3.zip | |
working parsing
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | scan.rb | 83 |
2 files changed, 55 insertions, 31 deletions
@@ -1,2 +1,5 @@ json.json raylib.h +result.txt +output +output/* @@ -1,46 +1,67 @@ require 'json' -parse = `ctags --output-format=json --c-kinds=pmz --language-force=c raylib.h` +# ctags --list-kinds=c +# p function prototypes +# s structure names +# z function parameters inside function or prototype definitions +# m struct, and union members +parse = `ctags --output-format=json --c-kinds=pm --fields=+S --language-force=c raylib.h` File.write('json.json', parse) -$params = {} -$members = {} $garbage = [] -$struct = [] -parse.each_line do |line| - json_line = JSON.parse line - puts json_line['kind'] - if json_line['kind'] == 'parameter' - if $params[json_line['scope']].nil? - $params[json_line['scope']] = [] - end - $params[json_line['scope']].push json_line - elsif json_line['kind'] == 'prototype' - $members[json_line['name']] = json_line - elsif json_line['kind'] == 'member' - if json_line['scopeKind'] == 'struct' - $struct.push json_line + +def param_strip(signature) + signature[1...-1].split(',') +end + + +def parse_header(path) + parse = `ctags --output-format=json --c-kinds=pm --fields=+S --language-force=c #{path}` + structs = {} + functions = {} + parse.each_line do |line| + json_line = JSON.parse line + if json_line['kind'] == 'prototype' + functions[json_line['name']] = param_strip(json_line['signature']) + elsif json_line['kind'] == 'member' + if json_line['scopeKind'] == 'struct' + structs[json_line['scope']] ||= [] + structs[json_line['scope']].push "#{json_line['typeref'].delete_prefix('typename:')} #{json_line['name']}" + else + $garbage.push json_line + end + elsif json_line['kind'] == 'struct' + structs[json_line['name']] = json_line else $garbage.push json_line end - else - if json_line['scopeKind'] == 'struct' - $garbage.push json_line - end end + [functions, structs] end -$members.each do |key, item| - puts "Function: #{item['typeref'].gsub(/typename:[^ ]* /,'')} #{item['name']}" - $params.each do |key, param_arry| - param_arry.each do |param| - if param['scope'] == item['name'] - puts "#{param['typeref'].gsub('typename:','')} #{param['name']}" - end +functions, structs = parse_header('raylib.h') + +def debug_show(type, hash) + puts "#{type.upcase}:" + puts '---' + hash.each do |key, params| + puts "#{type.capitalize}: #{key}" + params.each do |param| + puts param end + puts '---' end - puts '---' + puts +end + +debug_show('functions', functions) +debug_show('structs', structs) + +if !$garbage.empty? + pp $garbage + puts end -puts -puts "Struct: #{$struct.size}" +puts "Functions: #{functions.size}" +puts "Structs: #{structs.size}" puts "Garbage: #{$garbage.size}(should be 0)" +puts |
