87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/erubis/main.rb', line 87
def execute(argv=ARGV)
options, properties = parse_argv(argv, @single_options, @arg_options)
filenames = argv
options[?h] = true if properties[:help]
opts = Object.new
arr = @option_names.collect { |ch, name| "def #{name}; @#{name}; end\n" }
opts.instance_eval arr.join
options.each do |ch, val|
name = @option_names[ch]
opts.instance_variable_set("@#{name}", val)
end
if opts.help || opts.version
puts version() if opts.version
puts usage() if opts.help
puts show_properties() if opts.help
puts show_enhancers() if opts.help
return
end
opts.includes.split(/,/).each do |path|
$: << path
end if opts.includes
opts.requires.split(/,/).each do |library|
require library
end if opts.requires
action = opts.action
action ||= 'syntax' if opts.syntax
action ||= 'convert' if opts.source || opts.notext
lang = opts.lang || 'ruby'
action ||= 'convert' if opts.lang
classname = nil
klass = get_classobj(classname, lang, properties[:pi])
$KCODE = opts.kanji if opts.kanji
datafiles = opts.datafiles
context = load_datafiles(datafiles, opts)
if opts.context
context = parse_context_data(opts.context, opts)
end
properties[:escape] = true if opts.escape && !properties.key?(:escape)
properties[:pattern] = opts.pattern if opts.pattern
properties[:preamble] = properties[:postamble] = false if opts.bodyonly
properties[:pi] = nil if properties[:pi] == true
engine = klass.new(nil, properties)
enhancers = get_enhancers(opts.enhancers)
enhancers.each do |enhancer|
engine.extend(enhancer)
engine.bipattern = properties[:bipattern] if enhancer == Erubis::BiPatternEnhancer
end
engine.extend(Erubis::NoTextEnhancer) if opts.notext
val = nil
msg = "Syntax OK\n"
if filenames && !filenames.empty?
filenames.each do |filename|
test(?f, filename) or raise CommandOptionError.new("#{filename}: file not found.")
engine.filename = filename
engine.convert!(File.read(filename))
val = do_action(action, engine, context, filename, opts)
msg = nil if val
end
else
engine.filename = filename = '(stdin)'
engine.convert!($stdin.read())
val = do_action(action, engine, context, filename, opts)
msg = nil if val
end
print msg if action == 'syntax' && msg
end
|