mirror of
https://git.FreeBSD.org/doc.git
synced 2026-06-02 19:35:07 +00:00
040006ae08
fixes mandoc generation of left bracket adds messages, when HARDWARE section is absent or empty remains hwlist macro in hardware.adoc for next cycles hwlist macro has warning message text in the same line Reviewed by: carlavilla Approved by: carlavilla Differential Revision: https://reviews.freebsd.org/D57133
84 lines
2.6 KiB
Ruby
84 lines
2.6 KiB
Ruby
#!/usr/bin/env ruby
|
|
=begin
|
|
|
|
BSD 2-Clause License
|
|
Copyright (c) 2020-2026, The FreeBSD Project
|
|
Copyright (c) 2020-2026, Sergio Carlavilla <carlavilla@FreeBSD.org>
|
|
|
|
This script will generate the hardware notes
|
|
|
|
=end
|
|
require 'open3'
|
|
|
|
# Main method
|
|
puts "Processing hardware notes..."
|
|
|
|
if ARGV.length < 1 || ARGV.length > 1
|
|
puts "Only expecting the release version"
|
|
exit
|
|
end
|
|
|
|
hardwareNotesPath = ARGV[0]
|
|
hardwareNotesContent = ""
|
|
|
|
File.foreach(hardwareNotesPath).with_index do |line|
|
|
if (line[/&hwlist.\b/])
|
|
macro = line.match(/&hwlist\.[^\s;]+;?/)[0]
|
|
manualPage = macro.gsub("&hwlist.", "").gsub(";", "").gsub("\n", "")
|
|
|
|
if(File.exist?("tmp/share/man/man4/" + manualPage + ".4"))
|
|
cmd = "mandoc -Tmarkdown tmp/share/man/man4/" + manualPage + ".4 | sed -n '/^# HARDWARE/,/^# /{ /^# /d; p; }'"
|
|
mandocOut, err, s = Open3::capture3(cmd)
|
|
if s.success?
|
|
#replace \_ to _ and \[ to [ in drivers name and description
|
|
mandocOut.gsub!(/\\_/, '_')
|
|
mandocOut.gsub!(/\\\[/, '[')
|
|
|
|
# extract Nm (real driver name)
|
|
nm_cmd = "grep -m1 '^\\.Nm' tmp/share/man/man4/#{manualPage}.4"
|
|
nmOut, err2, s2 = Open3.capture3(nm_cmd)
|
|
|
|
if s2.success?
|
|
|
|
nm = nmOut.split[1]
|
|
|
|
if nm && !nm.empty?
|
|
driverName = File.basename(manualPage)
|
|
|
|
if nm != driverName
|
|
# f.e man ar40xx has driver name ar40xx_switch
|
|
man_link = "link:https://man.freebsd.org/cgi/man.cgi?query=#{driverName}&apropos=&&sektion=4&format=html[#{nm}]"
|
|
else
|
|
man_link = "man:#{driverName}[4]"
|
|
end
|
|
# replace only first occurrence, preserving markdown formatting
|
|
mandocOut.sub!(/[*_]*#{nm}[*_]*/) do
|
|
man_link
|
|
end
|
|
end
|
|
end
|
|
|
|
if mandocOut.strip.empty?
|
|
puts "WARNING: No HARDWARE section content for manual page #{manualPage}"
|
|
hardwareNotesContent << "#{macro} WARNING: No HARDWARE section content for manual page #{manualPage}\n"
|
|
next
|
|
end
|
|
|
|
hardwareNotesContent << mandocOut
|
|
else
|
|
puts "WARNING: The manual page " + manualPage + " without HARDWARE exists or malformed"
|
|
hardwareNotesContent << "#{macro} WARNING: The manual page " + manualPage + " without HARDWARE exists or malformed\n"
|
|
end
|
|
else
|
|
puts "WARNING: The manual page " + manualPage + " does not exists"
|
|
hardwareNotesContent << "#{macro} WARNING: The manual page " + manualPage + " does not exists\n"
|
|
end
|
|
else
|
|
hardwareNotesContent << line
|
|
end
|
|
end
|
|
|
|
File.open(hardwareNotesPath, 'w') do |out|
|
|
out << hardwareNotesContent
|
|
end
|