Class: C::Preprocessor
- Inherits:
-
Object
- Object
- C::Preprocessor
- Defined in:
- lib/casty/preprocessor.rb
Defined Under Namespace
Classes: Error
Class Attribute Summary collapse
-
.command ⇒ Object
Returns the value of attribute command.
Instance Attribute Summary collapse
-
#include_path ⇒ Object
Returns the value of attribute include_path.
-
#macros ⇒ Object
Returns the value of attribute macros.
-
#pwd ⇒ Object
Returns the value of attribute pwd.
-
#undef_macros ⇒ Object
Returns the value of attribute undef_macros.
Instance Method Summary collapse
-
#initialize ⇒ Preprocessor
constructor
A new instance of Preprocessor.
- #preprocess(text) ⇒ Object
- #preprocess_file(file_name, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Preprocessor
Returns a new instance of Preprocessor.
24 25 26 27 28 |
# File 'lib/casty/preprocessor.rb', line 24 def initialize @include_path = [] @macros = {} @undef_macros = Set.new end |
Class Attribute Details
.command ⇒ Object
Returns the value of attribute command.
18 19 20 |
# File 'lib/casty/preprocessor.rb', line 18 def command @command end |
Instance Attribute Details
#include_path ⇒ Object
Returns the value of attribute include_path.
22 23 24 |
# File 'lib/casty/preprocessor.rb', line 22 def include_path @include_path end |
#macros ⇒ Object
Returns the value of attribute macros.
22 23 24 |
# File 'lib/casty/preprocessor.rb', line 22 def macros @macros end |
#pwd ⇒ Object
Returns the value of attribute pwd.
22 23 24 |
# File 'lib/casty/preprocessor.rb', line 22 def pwd @pwd end |
#undef_macros ⇒ Object
Returns the value of attribute undef_macros.
22 23 24 |
# File 'lib/casty/preprocessor.rb', line 22 def undef_macros @undef_macros end |
Instance Method Details
#preprocess(text) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/casty/preprocessor.rb', line 29 def preprocess(text) filename = nil temp_file = nil Tempfile.open(['cast-preprocessor-input.', '.c'], File.(pwd || '.')) do |file| temp_file = file filename = file.path file.puts text end return preprocess_file(filename); ensure if temp_file temp_file.close temp_file.unlink end end |
#preprocess_file(file_name, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/casty/preprocessor.rb', line 44 def preprocess_file(file_name, ={}) file_name = File.(file_name) dir = File.dirname(file_name) stderr_buf = Tempfile.new('cast-preprocessor-stderr.txt') FileUtils.cd(dir) do output = `#{full_command(file_name)} 2>#{shellquote(stderr_buf.path)}` if $? == 0 || [:force] && !output.empty? return output else raise Error, stderr_buf.read end end ensure stderr_buf.close stderr_buf.unlink end |