From nobody Thu Nov 13 22:11:59 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=1582904917; cv=none; d=zohomail.com; s=zohoarc; b=k3VWCFEqpjq8uxlo6DqTzlnNWKREwRlzYgbhjlS6/6oF6x8h3ap8ym842sAt6HqqdK2vzswsuocBgmaHu3pXPExJ0s9d4DyHy3qy3wNpc3yeyUBlYCA8RbQQn4hXAz2seS8Zfe239bdDxvt9zWPrl8O3/sSbEX11A3ihVr19sOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582904917; h=Content-Type:Content-Transfer-Encoding:Cc: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=B3NhFkcMtDjhdPvA9G8QXToc593uTJoPg9kwAJf/gXQ=; b=TO25w3bZ/LmMFbJVwsnuS60MorygTaqhchhP0vZcin7y+jMMh3P3rJhaVUerxmMY79LueC27q+NfoRaQmRFdgSuFdOQixf1Qrs5Lhcm5nqB0fdIhHCgRHTka2aZVIsyi9EhbdhK56XftkuhyyhKUoDKyC+6cuOleNB4xLABzOkg= 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 158290491759441.022448309998595; Fri, 28 Feb 2020 07:48:37 -0800 (PST) Received: from localhost ([::1]:49038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7hsR-0005bg-Um for importer@patchew.org; Fri, 28 Feb 2020 10:48:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46971) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7hhI-0001Pn-84 for qemu-devel@nongnu.org; Fri, 28 Feb 2020 10:37:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j7hhG-00055i-Lj for qemu-devel@nongnu.org; Fri, 28 Feb 2020 10:37:04 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:35719) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j7hhG-00055F-F5 for qemu-devel@nongnu.org; Fri, 28 Feb 2020 10:37:02 -0500 Received: by mail-wm1-x32f.google.com with SMTP id m3so3683126wmi.0 for ; Fri, 28 Feb 2020 07:37:02 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id u23sm2659452wmu.14.2020.02.28.07.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2020 07:37:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B3NhFkcMtDjhdPvA9G8QXToc593uTJoPg9kwAJf/gXQ=; b=asQAiJMRC1DL7aXj3nhyt60TSidA9aozJ4qR2hxu+0l+XerypP1e6EFXbUekqrstF8 +5BNWuAq1QpeJ5wY4jV2ZSBY5gVAOx9UygIzG7oe8ALTC0KfAzw9+6exxPgNRb2WO55D WxNC+Olxpd/H9LcLmTDbI/vCwcE5gQjQZmXgaKFgob9cuHO86d2OaMXvovJ8a1aQu5LQ GOB53nx5E2gopuMzBNrlpBdmAqMo3/AcKddwgr4U2mkFd0iiblKqm/OZ8rok4FBtjeFF C0zHXWknGfpzZBM4qkE/fuIpWoXTArIMwbdc+Rkr0tfxLlI0Dx078o3mW+6U0mezN1Qu ZbWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B3NhFkcMtDjhdPvA9G8QXToc593uTJoPg9kwAJf/gXQ=; b=K5e87hc0nlD61ha9Yz/H0rd1Q0GjmV8FeSNdhFfOveQDYDRmA4vzCNByCcoewMN7fT B8HILrcVWM9rkehrAM5Itj5mdakGuCRG9ZO37Io+qKSGRW1DjMYdoVkdRUigo7n2vik6 Tg0OXLXOfKwlBsHssj/EO296p1z+SDP8/NfjLqkTfEidU6mx97c0cOqVhUTK8ktUe1EU oqQT8ZtVI4CbFeGrwLlhZvsgYDz7kndceQ7kk9LA0fgvn6gtXxNQt5d27u/aE4+OslHV CRFmraw25Ab/6kFNaKWhQORyssxss00p0nri5Idsq0Ew/T5aA31zdtUBLtPB1dJC/gsG Anzw== X-Gm-Message-State: APjAAAX1oN1qh4fmpnAOANNb5zWOz8Ck5J+xElL+H4pMAHg/dgv4RZE+ VSm3tDSLMTQXHzOLZChEHzhYDHxCr2Kvzw== X-Google-Smtp-Source: APXvYqzrHUV9sXPybWTBTxdPnuxWE93dxIxSsGabjSiEbPwaDLhPz0U2u8DLJP1xZZuFmODtQnXCAw== X-Received: by 2002:a7b:c08d:: with SMTP id r13mr5394944wmh.84.1582904221036; Fri, 28 Feb 2020 07:37:01 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH v3 25/33] scripts/hxtool-conv: Archive script used in qemu-options.hx conversion Date: Fri, 28 Feb 2020 15:36:11 +0000 Message-Id: <20200228153619.9906-26-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200228153619.9906-1-peter.maydell@linaro.org> References: <20200228153619.9906-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::32f 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: , Cc: Paolo Bonzini , Kashyap Chamarthy 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 --- Please don't critique the script, it is purely for a one-off conversion job, and I then did manual fixups on the output to get the changes in the following patch. I merely felt it was potentially useful to archive a copy of the mechanism used. Or we could drop this patch if that's not needed. --- 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