19
19
parser = argparse .ArgumentParser (description = desc )
20
20
parser .add_argument ('yaml_files' , nargs = '+' )
21
21
parser .add_argument ('output_dir' )
22
+ parser .add_argument ('-source-dir' , '-s' , default = '' , help = 'set source directory' )
22
23
args = parser .parse_args ()
23
24
24
25
p = subprocess .Popen (['c++filt' , '-n' ], stdin = subprocess .PIPE , stdout = subprocess .PIPE )
@@ -115,8 +116,25 @@ def color(self): return "red"
115
116
116
117
class SourceFileRenderer :
117
118
def __init__ (self , filename ):
118
- self .source_stream = open (filename )
119
+ existing_filename = None
120
+ if os .path .exists (filename ):
121
+ existing_filename = filename
122
+ else :
123
+ fn = os .path .join (args .source_dir , filename )
124
+ if os .path .exists (fn ):
125
+ existing_filename = fn
126
+
119
127
self .stream = open (os .path .join (args .output_dir , SourceFileRenderer .html_file_name (filename )), 'w' )
128
+ if existing_filename :
129
+ self .source_stream = open (existing_filename )
130
+ else :
131
+ self .source_stream = None
132
+ print ('''
133
+ <html>
134
+ <h1>Unable to locate file {}</h1>
135
+ </html>
136
+ ''' .format (filename ), file = self .stream )
137
+
120
138
self .html_formatter = HtmlFormatter ()
121
139
self .cpp_lexer = CppLexer ()
122
140
@@ -140,6 +158,9 @@ def render_inline_remarks(self, r):
140
158
</tr>''' .format (** locals ()), file = self .stream )
141
159
142
160
def render (self , line_remarks ):
161
+ if not self .source_stream :
162
+ return
163
+
143
164
print ('''
144
165
<html>
145
166
<head>
0 commit comments