From nobody Sun Oct 5 14:30:44 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583493945; cv=none; d=zohomail.com; s=zohoarc; b=X/pLfW8jJFh0k+EKfUXWudvSiu9HCYyuChY/7t2BKEY1+au7DhP+mCR1jd/3r+uzgDt0L4bpGadXUcKgCmZhGzG9Eujj3mFLAew853bjbzUQWD9/vNfU0un+T/1VqJ1pcBWvLFsgLyZdm1JSCeFNmKO0eI33XTCARHtO3+qy2yQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583493945; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KEuiqLQJQeVIcNdqiDmm+jMBwfWT2SyGRR7407Clxj8=; b=hTr/qSbhTiscuQKzcrxlpwSmRTHT5ASI65J9+ow+Z9AxXFZ1mdiEZxUpM+lTdVxeL7HuQOEwouK2zWwh/P++gPHv3czAK3khxJATiJe/wC8NHViay/13EGaQPJrXiPmb7HTj5YHws+tWrhNoE0sgeew52ANB8cOtSZbEHYx3dg4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583493945156422.63882729980753; Fri, 6 Mar 2020 03:25:45 -0800 (PST) Received: from localhost ([::1]:35174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAB6u-0006bi-39 for importer@patchew.org; Fri, 06 Mar 2020 06:25:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39898) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAAsP-0004Gi-NH for qemu-devel@nongnu.org; Fri, 06 Mar 2020 06:10:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAAsN-0005mf-W1 for qemu-devel@nongnu.org; Fri, 06 Mar 2020 06:10:45 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:51437) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jAAsN-0005io-Ha for qemu-devel@nongnu.org; Fri, 06 Mar 2020 06:10:43 -0500 Received: by mail-wm1-x329.google.com with SMTP id a132so1935368wme.1 for ; Fri, 06 Mar 2020 03:10:40 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id y10sm12553029wma.26.2020.03.06.03.10.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2020 03:10:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=KEuiqLQJQeVIcNdqiDmm+jMBwfWT2SyGRR7407Clxj8=; b=xAzZgT306BpsxEsIzrzeH2R0ba7leC42M3kH+8GLSabzcRbwAJXtl02Xt4Gw0DswTM SKcMfgRvi+qvrvcG5i9h7xERK+x54sI3+xNHp4ZiR9VYUg3XzTEQQ/wSFSuDEVlbeqzh /ihAooOP//6fVWgkljlxLM/URuV8ntdiGTbCMGfGateIPPJNI0/r6I2fVQbolDUqQv6g W6uUNFQuvL3hNwH3vaGLGcD31meRBTS9CpT3W4Wa576FekZuGDIuuyqjMOIyqqWrh1F4 EcM+vznR3aueKp+svdNj19CQfftMCEIkvrSmXcbyUiDxEYZGUGRDFDLrjMFoY2WjGmMv mNaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KEuiqLQJQeVIcNdqiDmm+jMBwfWT2SyGRR7407Clxj8=; b=XExI/jDkGtrw8VwlGMbmziYKUUCSxNEjp1nn78Y1ycPYiBDNeYcSgTGLFhbDIVSDO6 btYwb/pRltzFZpkLNYjUHEApxOeoFHRTdgYn/1T5Egvo75uoywxf7v0dPG5JIAzht5kH 1KHWO9npbXLtBPZkGrjzyFXGrlm8dBprxVi0kRRxQ7tvjFfM7q5PkJUMQ6TlOvHINajC 3YcC0W3yNsNN06xpaVtNMaiNgBG0858fCuJCP7ifYR6jnHQpJ5d1P7xRFz7XNh0ZNbjf xeIjMh66Bjs6WE6gmuh05IeNiKJE/xqAq7supRsEvmmhIQhl+FbUIQCbY/8/u0uV5J8J qpTA== X-Gm-Message-State: ANhLgQ07ORNR9nqZCXwBw7QpLM+IPvy2hF8us5IKQ6mLbbEXE3+O+zYU Hpco8YrQdXOi5PmCC9IavpFDy7w2aRez8g== X-Google-Smtp-Source: ADFU+vvM48ilmydGx6ykhlxvSDSxP4cK9RvsMlrYXJPY0HsfE9qFpKAVH8uSEi9TD1kI5mdOB/lhHA== X-Received: by 2002:a7b:c1c1:: with SMTP id a1mr3650043wmj.56.1583493038315; Fri, 06 Mar 2020 03:10:38 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 25/33] scripts/hxtool-conv: Archive script used in qemu-options.hx conversion Date: Fri, 6 Mar 2020 11:09:51 +0000 Message-Id: <20200306110959.29461-26-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200306110959.29461-1-peter.maydell@linaro.org> References: <20200306110959.29461-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::329 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) This commit archives the perl script used to do conversion of the STEXI/ETEXI blocks in qemu-options.hx. (The other .hx files were manually converted, but qemu-options.hx is complicated enough that I felt I needed some scripting.) Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Tested-by: Alex Benn=C3=A9e Message-id: 20200228153619.9906-26-peter.maydell@linaro.org --- scripts/hxtool-conv.pl | 137 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100755 scripts/hxtool-conv.pl diff --git a/scripts/hxtool-conv.pl b/scripts/hxtool-conv.pl new file mode 100755 index 00000000000..eede40b3462 --- /dev/null +++ b/scripts/hxtool-conv.pl @@ -0,0 +1,137 @@ +#!/usr/bin/perl -w +# +# Script to convert .hx file STEXI/ETEXI blocks to SRST/ERST +# +# Copyright (C) 2020 Linaro +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# (at your option) any later version. See the COPYING file in the +# top-level directory. + +# This script was only ever intended as a one-off conversion operation. +# Please excuse the places where it is a bit hacky. +# Some manual intervention after the conversion is expected, as are +# some warnings from makeinfo. +# Warning: this script is not idempotent: don't try to run it on +# a .hx file that already has SRST/ERST sections. + +# Expected usage: +# scripts/hxtool-conv.pl file.hx > file.hx.new + +use utf8; + +my $reading_texi =3D 0; +my $texiblock =3D ''; +my @tables =3D (); + +sub update_tables($) { + my ($texi) =3D @_; + # Update our list of open table directives: every @table + # line in the texi fragment is added to the list, and every + # @end table line means we remove an entry from the list. + # If this fragment had a completely self contained table with + # both the @table and @end table lines, this will be a no-op. + foreach (split(/\n/, $texi)) { + push @tables, $_ if /^\@table/; + pop @tables if /^\@end table/; + } +} + +sub only_table_directives($) { + # Return true if every line in the fragment is a start or end table di= rective + my ($texi) =3D @_; + foreach (split(/\n/, $texi)) { + return 0 unless /^\@table/ or /^\@end table/; + } + return 1; +} + +sub output_rstblock($) { + # Write the output to /tmp/frag.texi, wrapped in whatever current @tab= le + # lines we need. + my ($texi) =3D @_; + + # As a special case, if this fragment is only table directives and + # nothing else, update our set of open table directives but otherwise + # ignore it. This avoids emitting an empty SRST/ERST block. + if (only_table_directives($texi)) { + update_tables($texi); + return; + } + + open(my $fragfh, '>', '/tmp/frag.texi'); + # First output the currently active set of open table directives + print $fragfh join("\n", @tables); + # Next, update our list of open table directives. + # We need to do this before we emit the closing table directives + # so that we emit the right number if this fragment had an + # unbalanced set of directives. + update_tables($texi); + # Then emit the texi fragment itself. + print $fragfh "\n$texi\n"; + # Finally, add the necessary closing table directives. + print $fragfh "\@end table\n" x scalar @tables; + close $fragfh; + + # Now invoke makeinfo/pandoc on it and slurp the results into a string + open(my $fh, '-|', "makeinfo --force -o - --docbook " + . "-D 'qemu_system_x86 QEMU_SYSTEM_X86_MACRO' " + . "-D 'qemu_system QEMU_SYSTEM_MACRO' /tmp/frag.texi " + . " | pandoc -f docbook -t rst") + or die "can't start makeinfo/pandoc: $!"; + + binmode $fh, ':encoding(utf8)'; + + print "SRST\n"; + + # Slurp the whole thing into a string so we can do multiline + # string matches on it. + my $rst =3D do { + local $/ =3D undef; + <$fh>; + }; + $rst =3D~ s/^- =E2=88=92 /- /gm; + $rst =3D~ s/=E2=80=9C/"/gm; + $rst =3D~ s/=E2=80=9D/"/gm; + $rst =3D~ s/=E2=80=98/'/gm; + $rst =3D~ s/=E2=80=99/'/gm; + $rst =3D~ s/QEMU_SYSTEM_MACRO/|qemu_system|/g; + $rst =3D~ s/QEMU_SYSTEM_X86_MACRO/|qemu_system_x86|/g; + $rst =3D~ s/(?=3D::\n\n +\|qemu)/.. parsed-literal/g; + $rst =3D~ s/:\n\n::$/::/gm; + + # Fix up the invalid reference format makeinfo/pandoc emit: + # `Some string here <#anchorname>`__ + # should be: + # :ref:`anchorname` + $rst =3D~ s/\`[^<`]+\<\#([^>]+)\>\`__/:ref:`$1`/gm; + print $rst; + + close $fh or die "error on close: $!"; + print "ERST\n"; +} + +# Read the whole .hx input file. +while (<>) { + # Always print the current line + print; + if (/STEXI/) { + $reading_texi =3D 1; + $texiblock =3D ''; + next; + } + if (/ETEXI/) { + $reading_texi =3D 0; + # dump RST version of block + output_rstblock($texiblock); + next; + } + if ($reading_texi) { + # Accumulate the texi into a string + # but drop findex entries as they will confuse makeinfo + next if /^\@findex/; + $texiblock .=3D $_; + } +} + +die "Unexpectedly still in texi block at EOF" if $reading_texi; --=20 2.20.1