From nobody Wed Oct 1 21:27:58 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A5F82DECDD; Wed, 1 Oct 2025 14:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330199; cv=none; b=im3kxja3aBFwygxItvDMD2i5BcmqS0s2dNAnpZa+Ibr2+6wWDDyF0tdOhbJPM+YGjx0X5oKvsCpFosf4PjAyHUOLnIKNJcJvmsYs5yLzcaJwHNlNcsg8hBq7tEx2NeMuSM89trc83XLV9we2UN2MsU9DWcswWiIy26BhQVon89U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330199; c=relaxed/simple; bh=qB159IYUOz+MSNR6iulmqvylalzUczQT+mGqT4T/ngs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g6fkISdnrm9aaHUnfg9wLtk3IsjQiGm3Qufn8PjMlQhENFahjZW9MlQmlZvICFwcblUHu61QN1y77OPoqIMJuzYvBodETVjDos3qgdP5gZhqFu9s3hlIfngY3tFqEb4R7nhMt0C0COwtWNS5pBZVOKLXlO1XArPFSsFFz2JzEVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ppegjNb8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ppegjNb8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 022D0C4AF09; Wed, 1 Oct 2025 14:49:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759330199; bh=qB159IYUOz+MSNR6iulmqvylalzUczQT+mGqT4T/ngs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ppegjNb8B4VJfFLes6+pEWUlE3jpRc5heDj0Do6dQJrxxxJIMoGXbZHeXu/+LEat8 wmtZHYuntupy4g8K3gh/oa2MctkjfR310JQdPEtKAtPcvbgGUEg3XNf7X1+lVKLXeN KHqjCugHd3JOqENkjmlblzsJqsTPabEhb0CakKhBqe6uGh10tv6p6ogWmlpe+B/rxv DKc3744YL9kdOis+MN8/K0oV44uqawjKFhbBqveaXV1XYwSWzNSqc3/97e8eAnN4kN E/t4H5ISHWHeah/2FhhSDHPWZCzUUbzV8ylJatQen9Gf+p0prBeN59HhyVhTzQRw2M ANBLvK367FVYA== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1v3y9V-0000000BLIB-0pcH; Wed, 01 Oct 2025 16:49:57 +0200 From: Mauro Carvalho Chehab To: "Jonathan Corbet" , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH 03/23] docs: kernel_include.py: fix line numbers for TOC Date: Wed, 1 Oct 2025 16:49:26 +0200 Message-ID: <74eed96e32f79eaaef7a99ffe7c3224fed369c27.1759329363.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab Content-Type: text/plain; charset="utf-8" On TOC output, we need to embeed line numbers with ViewList. Change the parse class to produce a line-number parsed result, and adjust the output accordingly. Signed-off-by: Mauro Carvalho Chehab --- Documentation/sphinx/kernel_include.py | 36 ++++++++++++++++---------- tools/docs/lib/parse_data_structs.py | 2 +- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Documentation/sphinx/kernel_include.py b/Documentation/sphinx/= kernel_include.py index f94412cd17c9..ed819e9821c2 100755 --- a/Documentation/sphinx/kernel_include.py +++ b/Documentation/sphinx/kernel_include.py @@ -104,6 +104,7 @@ logger =3D logging.getLogger(__name__) =20 RE_DOMAIN_REF =3D re.compile(r'\\ :(ref|c:type|c:func):`([^<`]+)(?:<([^>]+= )>)?`\\') RE_SIMPLE_REF =3D re.compile(r'`([^`]+)`') +RE_LINENO_REF =3D re.compile(r'^\s*-\s+LINENO_(\d+):\s+(.*)') =20 def ErrorString(exc): # Shamelessly stolen from docutils return f'{exc.__class__.__name}: {exc}' @@ -242,23 +243,32 @@ class KernelInclude(Directive): # TOC output is a ReST file, not a literal. So, we can add line # numbers =20 - rawtext =3D parser.gen_toc() - - include_lines =3D statemachine.string2lines(rawtext, tab_width, - convert_whitespace=3DTru= e) - - # Append line numbers data - startline =3D self.options.get('start-line', None) + endline =3D self.options.get('end-line', None) + + relpath =3D os.path.relpath(path, srctree) =20 result =3D ViewList() - if startline and startline > 0: - offset =3D startline - 1 - else: - offset =3D 0 + for line in parser.gen_toc().split("\n"): + match =3D RE_LINENO_REF.match(line) + if not match: + result.append(line, path) + continue =20 - for ln, line in enumerate(include_lines, start=3Doffset): - result.append(line, path, ln) + ln, ref =3D match.groups() + ln =3D int(ln) + + # Filter line range if needed + if startline and (ln < startline): + continue + + if endline and (ln > endline): + continue + + # Sphinx numerates starting with zero, but text editors + # and other tools start from one + realln =3D ln + 1 + result.append(f"- {ref}: {relpath}#{realln}", path, ln) =20 self.state_machine.insert_input(result, path) =20 diff --git a/tools/docs/lib/parse_data_structs.py b/tools/docs/lib/parse_da= ta_structs.py index d28471a045f1..9ad621712103 100755 --- a/tools/docs/lib/parse_data_structs.py +++ b/tools/docs/lib/parse_data_structs.py @@ -422,7 +422,7 @@ class ParseDataStructs: =20 # Sort symbols alphabetically for symbol, (ref, ln) in sorted(refs.items()): - text.append(f"* {ref}: line #{ln}") + text.append(f"- LINENO_{ln}: {ref}") =20 text.append("") # Add empty line between categories =20 --=20 2.51.0