From patchwork Fri Nov 12 14:01:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: david larsson X-Patchwork-Id: 34412 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 9147327BBE3; Fri, 12 Nov 2021 14:02:22 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 1FF8F27BBE1 for ; Fri, 12 Nov 2021 14:02:22 +0000 (GMT) Received: from localhost ([::1]:35260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlX8H-0006WS-Aa for patchwork@mira.cbaines.net; Fri, 12 Nov 2021 09:02:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlX7y-0006WJ-4F for guix-patches@gnu.org; Fri, 12 Nov 2021 09:02:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:60450) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlX7x-0006Q0-Rl for guix-patches@gnu.org; Fri, 12 Nov 2021 09:02:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mlX7x-0000nZ-PM for guix-patches@gnu.org; Fri, 12 Nov 2021 09:02:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51791] [PATCH 1/2]: Update guile-bash Resent-From: david larsson Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 12 Nov 2021 14:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51791 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51791@debbugs.gnu.org Cc: Guix-patches Received: via spool by 51791-submit@debbugs.gnu.org id=B51791.16367256733010 (code B ref 51791); Fri, 12 Nov 2021 14:02:01 +0000 Received: (at 51791) by debbugs.gnu.org; 12 Nov 2021 14:01:13 +0000 Received: from localhost ([127.0.0.1]:43763 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlX7B-0000mU-1X for submit@debbugs.gnu.org; Fri, 12 Nov 2021 09:01:13 -0500 Received: from server0.selfhosted.xyz ([217.64.149.7]:53636) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlX79-0000mH-Jh for 51791@debbugs.gnu.org; Fri, 12 Nov 2021 09:01:12 -0500 Received: from server0.selfhosted.xyz (localhost [127.0.0.1]) by server0.selfhosted.xyz (Postfix) with ESMTP id 61DFD272F3A9; Fri, 12 Nov 2021 15:01:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=selfhosted.xyz; s=dkim; t=1636725665; bh=6J9Tni9GAxS/e1zMb/xQLbN2T5XZZ7hxsVG2FJLrTY0=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=dFgKOLGjpm/EU3QbzdJ0BVFZ2KJXnb+PI+x4pYB8mMw3IcTW1wNvVz13LK9C6t7p/ LpemN+MwT/4FKcqBejhVBQ/xWYCKPjpDqOo0fRbMtFmzfvQpteuPUHkVdYw7FS55Kt qSspg1QsT93bGcm3aovrHEXLBPigLEsdRHAf2785oG5vRyu7V61+hlWIDxZjqIMTsi DKzwPkTH7XUjnXHq/XdleUlAdT2ntGKooTjKWq63piablDZWfMlWke9/Shhtw+rygp ET1oNGxzcL7/KUnlZXX7LePek7EgZYCIC7wRNrMYFlu7pW3lPNKJ3oH1L3yJxw5v9n ZalES2NnqDwIA== X-Fuglu-Suspect: 8368d40cf3ca47509fd0b57557993790 X-Fuglu-Spamstatus: NO Received: from webmail.selfhosted.xyz (office.selfhosted.xyz [192.168.1.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: mail@selfhosted.xyz) by server0.selfhosted.xyz (Postfix) with ESMTPSA; Fri, 12 Nov 2021 15:01:00 +0100 (CET) MIME-Version: 1.0 Date: Fri, 12 Nov 2021 15:01:00 +0100 From: david larsson In-Reply-To: References: Message-ID: X-Sender: david.larsson@selfhosted.xyz X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches On 2021-11-12 14:56, david larsson wrote: > Hi, > > The following 2 patches update the guile-bash source url and > home-page, and adds a patch for it that does 2 things: > - fixes a bug, see below > - enables reading newline- or null-separated arguments via stdin to > guile-bash-defined bash functions. > > The bug is that guile-bash can't read string args with whitespaces in > it. Example: > ------------------------ > ~$ enable -f ~/.guix-profile/lib/bash/libguile-bash.so scm > ~$ scm /tmp/printargs > ~$ printargs "apa bepa" cepa > In procedure printargs: scm-function called from Bash with args (apa > bepa cepa) failed to match signature (file1 file2) > ~$ cat /tmp/printargs > (use-modules > (gnu bash)) > (define-bash-function (printargs file1 file2) > (display file1) > (display "\n") > (display file2) > (display "\n")) > ------------------------- > > After this patch, you can read args "as normal", or via stdin that are > either newline- or null-separated: > ------------------------- > ~$ printargs "apa bepa" cepa > apa bepa > cepa > ~$ echo "$apa" > aba > aca > ~$ printf '%s\0' "$apa" bepa | printargs -z > aba > aca > bepa > ~$ echo "$apa" | printargs > aba > aca > ------------------------- > > Best regards, > David From 10cc67f7c25991ec2aca2044a9e18e90001d7a1a Mon Sep 17 00:00:00 2001 From: David Larsson Date: Fri, 12 Nov 2021 13:42:41 +0100 Subject: [PATCH 2/2] gnu: guile-bash: Add patch that fixes reading args. This patch allows guile-bash defined bash-functions to read newline- or null-separated arguments from stdin, making it usable in bash pipelines. It also fixes a bug with arguments containing whitespace not being properly passed to the corresponding guile function. * gnu/packages/guile-xyz (guile-bash)[patches]: add patch. * gnu/packages/patches/guile-bash-args-from-stdin.patch: new file. --- gnu/packages/guile-xyz.scm | 1 + .../patches/guile-bash-args-from-stdin.patch | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch diff --git a/gnu/packages/guile-xyz.scm b/gnu/packages/guile-xyz.scm index 1d35c41796..511d766a6f 100644 --- a/gnu/packages/guile-xyz.scm +++ b/gnu/packages/guile-xyz.scm @@ -419,6 +419,7 @@ dictionary and suggesting spelling corrections.") (uri (git-reference (commit commit) (url home-page))) + (patches (search-patches "guile-bash-args-from-stdin.patch")) (sha256 (base32 "097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p")) diff --git a/gnu/packages/patches/guile-bash-args-from-stdin.patch b/gnu/packages/patches/guile-bash-args-from-stdin.patch new file mode 100644 index 0000000000..ad42616c70 --- /dev/null +++ b/gnu/packages/patches/guile-bash-args-from-stdin.patch @@ -0,0 +1,42 @@ +From a124921666a16cb4e93f59a653f98b99c78eb2ca Mon Sep 17 00:00:00 2001 +From: David Larsson +Date: Thu, 11 Nov 2021 14:07:04 +0100 +Subject: [PATCH] Enable reading arguments from bash via stdin + +* lisp/gnu/bash.scm(define-bash-function): read from stdin +to SCM_ARGS array when it is open, and separate args by null +instead of newline if -z option is passed as $1. +--- + lisp/gnu/bash.scm | 16 ++++++++++++---- + 1 file changed, 12 insertions(+), 4 deletions(-) + +diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm +index 199ebc0..e9dcea5 100644 +--- a/lisp/gnu/bash.scm ++++ b/lisp/gnu/bash.scm +@@ -326,10 +326,18 @@ + (hashq-set! *funcs* symbol thunk) + (unsafe-format/eval + "function ~a { +- SCM_ARGS=($@) ; +- local retval=$~a ; +- unset SCM_ARGS ; +- return $retval ; ++ local -a Input SCM_ARGS ; ++ [[ ! -t 0 ]] && mapfile -d '' Input ; ++ if [[ -n \"${Input[@]}\" ]]; then ++ if [[ \"$1\" == -z ]]; then ++ local -a SCM_ARGS=\"(${Input[*]@Q})\" ; ++ else ++ mapfile -t SCM_ARGS < <(printf '%s' \"${Input[@]}\"); fi ; ++ else ++ SCM_ARGS=(\"$@\"); fi ; ++ local retval=$~a ; ++ unset SCM_ARGS ; ++ return $retval ; + }" + symbol special-varname)))) + +-- +2.31.0 + -- 2.31.0