#!/usr/bin/gawk -f# SPDX-License-Identifier: GPL-2.0# Script to check sysctl documentation against source files## Copyright (c) 2020 Stephen Kitt# Example invocation:# scripts/check-sysctl-docs -vtable="kernel" \# Documentation/admin-guide/sysctl/kernel.rst \# $(git grep -l register_sysctl_)## Specify -vdebug=1 to see debugging informationBEGIN {if (!table) {print "Please specify the table to look for using the table variable" > "/dev/stderr"exit 1}}# The following globals are used:# children: maps ctl_table names and procnames to child ctl_table names# documented: maps documented entries (each key is an entry)# entries: maps ctl_table names and procnames to counts (so# enumerating the subkeys for a given ctl_table lists its# procnames)# files: maps procnames to source file names# paths: maps ctl_path names to paths# curpath: the name of the current ctl_path struct# curtable: the name of the current ctl_table struct# curentry: the name of the current proc entry (procname when parsing# a ctl_table, constructed path when parsing a ctl_path)# Remove punctuation from the given valuefunction trimpunct(value) {while (value ~ /^["&]/) {value = substr(value, 2)}while (value ~ /[]["&,}]$/) {value = substr(value, 1, length(value) - 1)}return value}# Print the information for the given entryfunction printentry(entry) {seen[entry]++printf "* %s from %s", entry, file[entry]if (documented[entry]) {printf " (documented)"}print ""}# Stage 1: build the list of documented entriesFNR == NR && /^=+$/ {if (prevline ~ /Documentation for/) {# This is the main titlenext}# The previous line is a section title, parse it0ドル = prevlineif (debug) print "Parsing " 0ドルinbrackets = 0for (i = 1; i <= NF; i++) {if (length($i) == 0) {continue}if (!inbrackets && substr($i, 1, 1) == "(") {inbrackets = 1}if (!inbrackets) {token = trimpunct($i)if (length(token) > 0 && token != "and") {if (debug) print trimpunct($i)documented[trimpunct($i)]++}}if (inbrackets && substr($i, length($i), 1) == ")") {inbrackets = 0}}}FNR == NR {prevline = 0ドルnext}# Stage 2: process each file and find all sysctl tablesBEGINFILE {delete childrendelete entriesdelete pathscurpath = ""curtable = ""curentry = ""if (debug) print "Processing file " FILENAME}/^static struct ctl_path/ {match(0,ドル /static struct ctl_path ([^][]+)/, tables)curpath = tables[1]if (debug) print "Processing path " curpath}/^static struct ctl_table/ {match(0,ドル /static struct ctl_table ([^][]+)/, tables)curtable = tables[1]if (debug) print "Processing table " curtable}/^};$/ {curpath = ""curtable = ""curentry = ""}curpath && /\.procname[\t ]*=[\t ]*".+"/ {match(0,ドル /.procname[\t ]*=[\t ]*"([^"]+)"/, names)if (curentry) {curentry = curentry "/" names[1]} else {curentry = names[1]}if (debug) print "Setting path " curpath " to " curentrypaths[curpath] = curentry}curtable && /\.procname[\t ]*=[\t ]*".+"/ {match(0,ドル /.procname[\t ]*=[\t ]*"([^"]+)"/, names)curentry = names[1]if (debug) print "Adding entry " curentry " to table " curtableentries[curtable][curentry]++file[curentry] = FILENAME}/\.child[\t ]*=/ {child = trimpunct($NF)if (debug) print "Linking child " child " to table " curtable " entry " curentrychildren[curtable][curentry] = child}/register_sysctl_table\(.*\)/ {match(0,ドル /register_sysctl_table\(([^)]+)\)/, tables)if (debug) print "Registering table " tables[1]if (children[tables[1]][table]) {for (entry in entries[children[tables[1]][table]]) {printentry(entry)}}}/register_sysctl_paths\(.*\)/ {match(0,ドル /register_sysctl_paths\(([^)]+), ([^)]+)\)/, tables)if (debug) print "Attaching table " tables[2] " to path " tables[1]if (paths[tables[1]] == table) {for (entry in entries[tables[2]]) {printentry(entry)}}split(paths[tables[1]], components, "/")if (length(components) > 1 && components[1] == table) {# Count the first subdirectory as seenseen[components[2]]++}}END {for (entry in documented) {if (!seen[entry]) {print "No implementation for " entry}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型