#!/usr/bin/ruby
# Takes a command line for GCC (or similar) on as a file or on its
# standard input, extracts the preprocessor macros defined and the
# include paths, and outputs them in a format suitable for
# pasting into c_cpp_properties.json so that VSCode can understand
# your C/C++ project better.
require 'json'
input = ARGF.read
defines = []
include_path = []
input.split do |i|
if i.start_with?('-D')
defines << i[2..-1]
end
if i.start_with?('-I')
include_path << i[2..-1].sub(/^\/C\//, 'C:/')
end
end
data = {defines: defines, includePath: include_path}
puts JSON.generate(data, indent: " ", object_nl: "\n", array_nl: "\n")