diff options
| author | _Tradam <[email protected]> | 2022-04-07 17:40:21 -0400 |
|---|---|---|
| committer | _Tradam <[email protected]> | 2022-04-07 17:40:21 -0400 |
| commit | d54cd794f6ed086f05b2631f73173b73f312b19f (patch) | |
| tree | 7d236d9b5c15fd68ef8c440d4a2ad8d7fbd378a3 /scan.rb | |
| parent | 2ae12787183ceb253e8f6abfc57de009d5e71aab (diff) | |
| download | FelBind-d54cd794f6ed086f05b2631f73173b73f312b19f.tar.gz FelBind-d54cd794f6ed086f05b2631f73173b73f312b19f.zip | |
streamlined build process for testing
Diffstat (limited to 'scan.rb')
| -rw-r--r-- | scan.rb | 125 |
1 files changed, 67 insertions, 58 deletions
@@ -1,74 +1,83 @@ require 'json' -file_to_scan = 'raylib.h' +#file_to_scan = '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 #{file_to_scan}` -File.write('json.json', parse) -$garbage = [] +class Scan + class << self + # ctags --list-kinds=c + # p function prototypes + # s structure names + # z function parameters inside function or prototype definitions + # m struct, and union members + def ctag(file) + `ctags --output-format=json --c-kinds=pm --fields=+S --language-force=c #{file}` + end + #File.write('json.json', parse) + #$garbage = [] -def param_strip(signature) - signature[1...-1].split(',') -end + 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['typeref'].sub(/^[^ ][^ ]* /,'')} #{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 + def parse_header(path) + parse = `ctags --output-format=json --c-kinds=pm --fields=+S --language-force=c #{path}` + structs = {} + functions = {} + failed = [] + parse.each_line do |line| + json_line = JSON.parse line + if json_line['kind'] == 'prototype' + functions["#{json_line['typeref'].sub(/^[^ ][^ ]* /,'')} #{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 + failed.push json_line + end + elsif json_line['kind'] == 'struct' + structs[json_line['name']] = json_line + else + failed.push json_line + end end - elsif json_line['kind'] == 'struct' - structs[json_line['name']] = json_line - else - $garbage.push json_line + [functions, structs, failed] end - end - [functions, structs] -end -functions, structs = parse_header(file_to_scan) -def debug_show(type, hash) - puts "#{type.upcase}:" - puts '---' - hash.each do |key, params| - puts "#{type.capitalize}: #{key}" - params.each do |param| - puts param + 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 end - puts '---' - end - puts -end - -debug_show('functions', functions) -debug_show('structs', structs) -if !$garbage.empty? - pp $garbage - puts -end + def scan(file, destination) + functions, structs, failed = parse_header(file) + debug_show('functions', functions) + debug_show('structs', structs) -puts "Functions: #{functions.size}" -puts "Structs: #{structs.size}" -puts "Garbage: #{$garbage.size}(should be 0)" -puts + if !failed.empty? + puts "-- Failed: --" + pp failed + puts + end -result = [functions, structs] + puts "Functions: #{functions.size}" + puts "Structs: #{structs.size}" + puts "Failed: #{failed.size}" + puts -File.write('glue.json', JSON.generate(result)) + result = [functions, structs] + File.write(destination, JSON.generate(result)) + end + end +end |
