summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>2025-08-22 17:19:31 +0300
committerJonathan Corbet <corbet@lwn.net>2025-08-30 00:54:43 +0300
commit01dba1680cb4047d4f6e057276f805f93b7eea00 (patch)
treeac7cad59cf2fdad3b6ab8715efb248e11672478d
parent4ad9cabc34d1b45ef77fa9c70e446658f6f5934b (diff)
downloadlinux-01dba1680cb4047d4f6e057276f805f93b7eea00.tar.xz
docs: kernel_include.py: move apply_range() and add a docstring
While not required, better to have caller functions at the end. As apply_range() is now called by xref_text(), move it to be before the latter. No functional changes. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Link: https://lore.kernel.org/r/a6ce0fd7c03a01338753fd81ed0c4631f78311d6.1755872208.git.mchehab+huawei@kernel.org
-rwxr-xr-xDocumentation/sphinx/kernel_include.py68
1 files changed, 36 insertions, 32 deletions
diff --git a/Documentation/sphinx/kernel_include.py b/Documentation/sphinx/kernel_include.py
index 90ed8428f776..fd4887f80577 100755
--- a/Documentation/sphinx/kernel_include.py
+++ b/Documentation/sphinx/kernel_include.py
@@ -113,6 +113,42 @@ class KernelInclude(Include):
except UnicodeError as error:
raise self.severe('Problem with directive:\n%s' % ErrorString(error))
+ def apply_range(self, rawtext):
+ """
+ Handles start-line, end-line, start-after and end-before parameters
+ """
+
+ # Get to-be-included content
+ startline = self.options.get('start-line', None)
+ endline = self.options.get('end-line', None)
+ try:
+ if startline or (endline is not None):
+ lines = rawtext.splitlines()
+ rawtext = '\n'.join(lines[startline:endline])
+ except UnicodeError as error:
+ raise self.severe(f'Problem with "{self.name}" directive:\n'
+ + io.error_string(error))
+ # start-after/end-before: no restrictions on newlines in match-text,
+ # and no restrictions on matching inside lines vs. line boundaries
+ after_text = self.options.get("start-after", None)
+ if after_text:
+ # skip content in rawtext before *and incl.* a matching text
+ after_index = rawtext.find(after_text)
+ if after_index < 0:
+ raise self.severe('Problem with "start-after" option of "%s" '
+ "directive:\nText not found." % self.name)
+ rawtext = rawtext[after_index + len(after_text) :]
+ before_text = self.options.get("end-before", None)
+ if before_text:
+ # skip content in rawtext after *and incl.* a matching text
+ before_index = rawtext.find(before_text)
+ if before_index < 0:
+ raise self.severe('Problem with "end-before" option of "%s" '
+ "directive:\nText not found." % self.name)
+ rawtext = rawtext[:before_index]
+
+ return rawtext
+
def xref_text(self, env, path, tab_width):
"""
Read and add contents from a C file parsed to have cross references.
@@ -163,38 +199,6 @@ class KernelInclude(Include):
return []
- def apply_range(self, rawtext):
- # Get to-be-included content
- startline = self.options.get('start-line', None)
- endline = self.options.get('end-line', None)
- try:
- if startline or (endline is not None):
- lines = rawtext.splitlines()
- rawtext = '\n'.join(lines[startline:endline])
- except UnicodeError as error:
- raise self.severe(f'Problem with "{self.name}" directive:\n'
- + io.error_string(error))
- # start-after/end-before: no restrictions on newlines in match-text,
- # and no restrictions on matching inside lines vs. line boundaries
- after_text = self.options.get("start-after", None)
- if after_text:
- # skip content in rawtext before *and incl.* a matching text
- after_index = rawtext.find(after_text)
- if after_index < 0:
- raise self.severe('Problem with "start-after" option of "%s" '
- "directive:\nText not found." % self.name)
- rawtext = rawtext[after_index + len(after_text) :]
- before_text = self.options.get("end-before", None)
- if before_text:
- # skip content in rawtext after *and incl.* a matching text
- before_index = rawtext.find(before_text)
- if before_index < 0:
- raise self.severe('Problem with "end-before" option of "%s" '
- "directive:\nText not found." % self.name)
- rawtext = rawtext[:before_index]
-
- return rawtext
-
def literal(self, path, tab_width, rawtext):
"""Output a literal block"""