lib/nasldoc/cli/application.rb
# Processes each .inc file and sets instance variables for each template
Processes each .inc file and sets instance variables for each template
Processes each . inc file and sets instance variables for each template
def build_file_page path
				puts "[*] Processing file: #{path}"
				@current_file = File.basename(path)
				contents = File.open(path, "rb") { |f| f.read }
				begin
					tree = Nasl::Parser.new.parse(contents, path)
				rescue Nasl::ParseException, Nasl::TokenException
					puts "[!!!] File '#{path}' couldn't be parsed. It should be added to the blacklist."
					return nil
				end
				build_namespace_map(tree, @namespaces, @fn_ns_map, @obj_ns_map, @obj_fn_map)
				@functions = Hash.new()
				tree.all(:Function).map do |fn|
					ns = @fn_ns_map[fn.to_s]
					show_ns = 0
					if(fn.fn_type == "normal" and !ns.nil?)
						show_ns = 1
					end
					code_snip = fn.context(nil, false, false)
					if (!code_snip.nil?)
						code_snip = code_snip.gsub(/#*$/, "").rstrip
					end
					@functions[fn.to_s] = {
						:name => fn.name.name,
						:code => code_snip,
						:params => fn.params.map(&:name),
						:namespace => ns,
						:fn_type => fn.fn_type,
						:show_ns => show_ns,
						:object => @obj_fn_map[fn.to_s]
					}
					@function_count += 1
				end
				@funcs_prv = {}
				@funcs_pub = {}
				for function in tree.all(:Function) do
					if (defined? function.tokens[0].type and function.tokens[0].type == :PUBLIC)
						@funcs_pub[function.to_s] = @functions[function.to_s]
					elsif (defined? function.tokens[0].type and function.tokens[0].type == :PRIVATE)
						@funcs_prv[function.to_s] = @functions[function.to_s]
					elsif (function.fn_type == 'obj' and defined? function.tokens[0].type and function.tokens[0].type.nil?)
						if(obj_fn_map[function.to_s] == function.name.name) 
							@funcs_pub[function.to_s] = @functions[function.to_s]
						else
							@funcs_prv[function.to_s] = @functions[function.to_s]
						end
					elsif (function.name.name =~ /^_/)
						@funcs_prv[function.to_s] = @functions[function.to_s]
					else
						@funcs_pub[function.to_s] = @functions[function.to_s]
					end
				end
				@globals = tree.all(:Global).map(&:idents).flatten.map do |id|
					if id.is_a? Nasl::Assignment
						id.lval.name
					else
						id.name
					end
				end.sort
				@globs_prv = @globals.select { |n| n =~ /^_/ }
				@globs_pub = @globals.reject { |n| @globs_prv.include? n }
				@includes = tree.all(:Include).map(&:filename).map(&:text).sort
				@comments = tree.all(:Comment)
				puts "[**] #{@comments.size} comment(s) were found"
				@comments.map! do |comm|
					begin
						NaslDoc::CLI::Comment.new(comm, path)
					rescue CommentException => e
						puts "[!!!] #{e.class.name} #{e.message}"
						@error_count += 1
						nil
					rescue Exception => e
						puts "[!!!] #{e.class.name} #{e.message}"
						puts e.backtrace.map{ |l| l.prepend "[!!!!] " }.join("\n")
						nil
					end
				end
				@comments.compact!
				@comments.keep_if &:valid
				puts "[**] #{@comments.size} nasldoc comment(s) were parsed"
				@overview = @comments.select{ |c| c.type == :file }.shift
				build_template "file", path
			end
def build_file_page path puts "[*] Processing file: #{path}" @current_file = File . basename ( path ) contents = File . open ( path , "rb" ) { | f | f . read } begin tree = Nasl :: Parser . new . parse ( contents , path ) rescue Nasl :: ParseException , Nasl :: TokenException puts "[!!!] File '#{path}' couldn't be parsed. It should be added to the blacklist." return nil end build_namespace_map ( tree , @namespaces , @fn_ns_map , @obj_ns_map , @obj_fn_map ) @functions = Hash . new ( ) tree . all ( :Function ) . map do | fn | ns = @fn_ns_map [ fn . to_s ] show_ns = 0 if ( fn . fn_type == "normal" and ! ns . nil? ) show_ns = 1 end code_snip = fn . context ( nil , false , false ) if ( ! code_snip . nil? ) code_snip = code_snip . gsub ( / #*$ / , "" ) . rstrip end @functions [ fn . to_s ] = { :name => fn . name . name , :code => code_snip , :params => fn . params . map ( & :name ) , :namespace => ns , :fn_type => fn . fn_type , :show_ns => show_ns , :object => @obj_fn_map [ fn . to_s ] } @function_count += 1 end @funcs_prv = { } @funcs_pub = { } for function in tree . all ( :Function ) do if ( defined? function . tokens [ 0 ] . type and function . tokens [ 0 ] . type == :PUBLIC ) @funcs_pub [ function . to_s ] = @functions [ function . to_s ] elsif ( defined? function . tokens [ 0 ] . type and function . tokens [ 0 ] . type == :PRIVATE ) @funcs_prv [ function . to_s ] = @functions [ function . to_s ] elsif ( function . fn_type == 'obj' and defined? function . tokens [ 0 ] . type and function . tokens [ 0 ] . type . nil? ) if ( obj_fn_map [ function . to_s ] == function . name . name ) @funcs_pub [ function . to_s ] = @functions [ function . to_s ] else @funcs_prv [ function . to_s ] = @functions [ function . to_s ] end elsif ( function . name . name =~ / ^_ / ) @funcs_prv [ function . to_s ] = @functions [ function . to_s ] else @funcs_pub [ function . to_s ] = @functions [ function . to_s ] end end @globals = tree . all ( :Global ) . map ( & :idents ) . flatten . map do | id | if id . is_a? Nasl :: Assignment id . lval . name else id . name end end . sort @globs_prv = @globals . select { | n | n =~ / ^_ / } @globs_pub = @globals . reject { | n | @globs_prv . include? n } @includes = tree . all ( :Include ) . map ( & :filename ) . map ( & :text ) . sort @comments = tree . all ( :Comment ) puts "[**] #{@comments.size} comment(s) were found" @comments . map! do | comm | begin NaslDoc :: CLI :: Comment . new ( comm , path ) rescue CommentException => e puts "[!!!] #{e.class.name} #{e.message}" @error_count += 1 nil rescue Exception => e puts "[!!!] #{e.class.name} #{e.message}" puts e . backtrace . map { | l | l . prepend "[!!!!] " } . join ( "\n" ) nil end end @comments . compact! @comments . keep_if & :valid puts "[**] #{@comments.size} nasldoc comment(s) were parsed" @overview = @comments . select { | c | c . type == :file } . shift build_template "file" , path end
Processes each .inc file and sets instance variables for each template
Processes each . inc file and sets instance variables for each template
# Parse the input file. # get namespace mapping # Collect the functions. # handle constructor #				@funcs_prv = @functions.select { |n, p| n =~ /^_/ } #				@funcs_pub = @functions.reject { |n, p| @funcs_prv.key? n } # Collect the globals. # Collect the includes. # Parse the comments. # A short message is okay for format errors. # A detailed message is given for programming errors. # Find the overview comment.
path
<not_specific>