diff options
| author | realtradam <[email protected]> | 2022-08-31 08:29:23 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2022-08-31 08:29:23 -0400 |
| commit | c51ded6c4efef4e0ef5a157a72ae79c402b7964b (patch) | |
| tree | 46802e9bfaae9d97538ab94285c3357f7ca65c94 /scan.rb | |
| parent | 8caf4473882f3eab9018b0ed4500792d459bdc98 (diff) | |
| download | FelBind-c51ded6c4efef4e0ef5a157a72ae79c402b7964b.tar.gz FelBind-c51ded6c4efef4e0ef5a157a72ae79c402b7964b.zip | |
starting work on the backend system
Diffstat (limited to 'scan.rb')
| -rw-r--r-- | scan.rb | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/scan.rb b/scan.rb deleted file mode 100644 index 38dd95b..0000000 --- a/scan.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'json' - -#file_to_scan = 'raylib.h' - -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 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 - [functions, structs, failed] - end - - - 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 - - def scan(file, destination) - functions, structs, failed = parse_header(file) - debug_show('functions', functions) - debug_show('structs', structs) - - if !failed.empty? - puts "-- Failed: --" - pp failed - puts - end - - puts "Functions: #{functions.size}" - puts "Structs: #{structs.size}" - puts "Failed: #{failed.size}" - puts - - result = [functions, structs] - - File.write(destination, JSON.generate(result)) - end - end -end |
