Skip to content

Instantly share code, notes, and snippets.

@DavidEGrayson
Created September 12, 2022 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidEGrayson/072036c16215cc812212676dbe483c94 to your computer and use it in GitHub Desktop.
Save DavidEGrayson/072036c16215cc812212676dbe483c94 to your computer and use it in GitHub Desktop.
Convert GCC command in VSCode configuration
#!/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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment