mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/5] Documentation: gen_commands.py: escape special characters
@ 2025-10-24  9:07 Ahmad Fatoum
  2025-10-24  9:07 ` [PATCH 2/5] Documentation: gen_commands.py: align whitespace with coding style Ahmad Fatoum
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2025-10-24  9:07 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

commands/global.c has following line:

  BAREBOX_CMD_HELP_TEXT("Without options, print all global and env
                        (prefixed with *) variables.")

which triggers a warning as the * has a special meaning in ReST and it
is never terminated.

On the other hand, we have escapes for double quotes, which should be
stripped:

  BAREBOX_CMD_HELP_TEXT("- \"bootchooser\": boot with barebox bootchooser")

Fix these and other issues by processing escapes for all strings we extract,
except for those in literal blocks.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 Documentation/gen_commands.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/Documentation/gen_commands.py b/Documentation/gen_commands.py
index 4fcb4dda6e74..53fd59d8f692 100755
--- a/Documentation/gen_commands.py
+++ b/Documentation/gen_commands.py
@@ -26,12 +26,19 @@ CMD_END    = re.compile(r"""^BAREBOX_CMD_END\s*$""")
 
 CONT = re.compile(r"""\s*"(.*?)"\s*\)?\s*$""")
 
+ESCAPE = re.compile(r"""([*_`|<>\\])""")
+UNESCAPE = re.compile(r'''\\(["\\])''')
+
 CMDS = {}
 
+
+def string_escape_literal(s):
+    return re.sub(UNESCAPE, r'\1', s.replace(r'\t', '').replace(r'\n', ''))
+
+
 def string_escape(s):
-  # This used to do s.decode("string_escape") which isn't available on Python 3.
-  # Actually we only need to drop '\t' and '\n', so do this here.
-  return s.replace(r'\t', '').replace(r'\n', '')
+    return re.sub(ESCAPE, r'\\\1', string_escape_literal(s))
+
 
 def parse_c(name):
   cmd = None
@@ -78,7 +85,7 @@ def parse_c(name):
     x = CMD_OPTS.match(line)
     if x:
       last = cmd['c_opts']
-      last.append(string_escape(x.group(1)))
+      last.append(string_escape_literal(x.group(1)))
       continue
     x = CMD_GROUP.match(line)
     if x:
-- 
2.47.3




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-10-24  9:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-24  9:07 [PATCH 1/5] Documentation: gen_commands.py: escape special characters Ahmad Fatoum
2025-10-24  9:07 ` [PATCH 2/5] Documentation: gen_commands.py: align whitespace with coding style Ahmad Fatoum
2025-10-24  9:07 ` [PATCH 3/5] Documentation: gen_commands.py: rework if statements for compactness Ahmad Fatoum
2025-10-24  9:07 ` [PATCH 4/5] Documentation: gen_commands.py: use literal block for help text Ahmad Fatoum
2025-10-24  9:07 ` [PATCH 5/5] Documentation: gen_commands.py: escape name in title Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox