3333from build_link_map import build_link_map
3434from ddg_parse_html import get_declarations , get_short_description , DdgException
3535
36- MAX_CODE_LINES = 6
37-
3836# Entry types
3937# a class or struct
4038ITEM_TYPE_CLASS = 1
@@ -187,8 +185,7 @@ def get_version(decls):
187185 return None
188186 return rv
189187
190- def build_abstract (decls , desc , debug = DDGDebug ()):
191- line_limit = MAX_CODE_LINES
188+ def build_abstract (decls , desc , max_code_lines , debug = DDGDebug ()):
192189 num_lines = 0
193190
194191 limited = False
@@ -201,26 +198,26 @@ def build_abstract(decls, desc, debug=DDGDebug()):
201198 code_num_lines = code .count ('\n ' ) + 1
202199
203200 # limit the number of code snippets to be included so that total number
204- # of lines is less than MAX_CODE_LINES . The limit becomes active only
201+ # of lines is less than max_code_lines . The limit becomes active only
205202 # for the second and subsequent snippets.
206203 first = True if i == 0 else False ;
207204 last = True if i == len (decls )- 1 else False ;
208205
209206 if not first :
210207 if last :
211- if code_num_lines > line_limit :
208+ if code_num_lines > max_code_lines :
212209 limited = True
213210 break
214211 else :
215- if code_num_lines > line_limit - 1 :
212+ if code_num_lines > max_code_lines - 1 :
216213 # -1 because we need to take into account
217214 # < omitted declarations > message
218215 limited = True
219216 break
220217
221218 all_code += code
222219 num_lines += 1
223- line_limit -= code_num_lines
220+ max_code_lines -= code_num_lines
224221
225222 if limited :
226223 all_code += '<pre><code> < omitted declarations > </code></pre>'
@@ -372,7 +369,7 @@ def output_redirects(out, redirects):
372369 out .write (line )
373370
374371def process_identifier (out , redirects , root , link , item_ident , item_type ,
375- debug = DDGDebug ()):
372+ max_code_lines , debug = DDGDebug ()):
376373 # get the name by extracting the unqualified identifier
377374 name = get_name (item_ident )
378375 debug_verbose = True if debug .enabled and debug .ident_match is not None else False
@@ -381,14 +378,14 @@ def process_identifier(out, redirects, root, link, item_ident, item_type,
381378 if item_type == ITEM_TYPE_CLASS :
382379 decls = get_declarations (root , name )
383380 desc = get_short_description (root , get_version (decls ), debug = debug_verbose )
384- abstract = build_abstract (decls , desc , debug = debug )
381+ abstract = build_abstract (decls , desc , max_code_lines , debug = debug )
385382
386383 elif item_type in [ ITEM_TYPE_FUNCTION ,
387384 ITEM_TYPE_CONSTRUCTOR ,
388385 ITEM_TYPE_DESTRUCTOR ]:
389386 decls = get_declarations (root , name )
390387 desc = get_short_description (root , get_version (decls ), debug = debug_verbose )
391- abstract = build_abstract (decls , desc , debug = debug )
388+ abstract = build_abstract (decls , desc , max_code_lines , debug = debug )
392389
393390 elif item_type in [ ITEM_TYPE_FUNCTION_INLINEMEM ,
394391 ITEM_TYPE_CONSTRUCTOR_INLINEMEM ,
@@ -447,6 +444,8 @@ def main():
447444 help = 'The path to the XML index containing identifier data' )
448445 parser .add_argument ('output' , type = str ,
449446 help = 'The path to destination output.txt file' )
447+ parser .add_argument ('--max_code_lines' , type = int , default = 6 ,
448+ help = 'Maximum number of lines of code to show in abstract' )
450449 parser .add_argument ('--debug' , action = 'store_true' , default = False ,
451450 help = 'Enables debug mode.' )
452451 parser .add_argument ('--debug_ident' , type = str , default = None ,
@@ -461,6 +460,7 @@ def main():
461460
462461 index_file = args .index
463462 output_file = args .output
463+ max_code_lines = args .max_code_lines
464464
465465 # a map that stores information about location and type of identifiers
466466 # it's two level map: full_link maps to a dict that has full_name map to
@@ -518,7 +518,7 @@ def main():
518518 item_type = ident ['type' ]
519519
520520 process_identifier (out , redirects , root , link , item_ident , item_type ,
521- debug = debug )
521+ max_code_lines , debug = debug )
522522
523523 output_redirects (out , redirects )
524524
0 commit comments