Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version:content-type;
        bh=6yUWpCExEYKp/QE6n/Kl2DvW5umoA5T4eMoHqrTNIFA=;
        b=e+yAf69hf6iDV810kXoHJFAdoR9WDCs3CZko8Gn8lwAbTiFg5X+I3hUB5H+AQlFP9F
         Ong/aN+3hJJeYDIAysQv/hkaK84UpR/4f9ZAgWlpfhcQ3Q/czsWfkefFheyt+F+rtTWb
         Y7AIob/h9BkabQidpvsFR8IhmJ1mdjVc7mid6EMREcZUA369J9TeZUP1nRyq3zt3Iypk
         QEa6uOAn7QThEx16CkzuRP/8S+TqtsuqCbHBBAZlS4kwyTekNTVXTgZ9aRDoGED50Ett
         MKOD5Y2AP+6TUw291xGE8xEsZ9zXFpUSBRZoQYQD6ra0wpnyg0Kr2fitqpZoH8cS3bjO
         P9EQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version:content-type;
        bh=6yUWpCExEYKp/QE6n/Kl2DvW5umoA5T4eMoHqrTNIFA=;
        b=DU5QU39T91pTBHCIgE2UQOOZWJtwrUEih13BNzYwS5s3X+j8pK70gIaW3xYoAL2l/p
         Qp9b3hM7iTBDk1Rr9wF0V+WU0Ub0pe57MXRP2Q3ZWIQbLrRR0MwnHqa5mpwuG0upz4M3
         Zh73QwWFSo2phFM+DnKIt899sxWxpazmj/WOqSq6Dxzgd19oZiiDRhyvr+GBEt0GP1zc
         XYgoAe1tEI469ZFkpH/DdbYPNcacq4EueegsxKnsyQgMahm76LPZNuwKkwGV21Pfk9vB
         Nt7e32ZDJlSaFCj9kSt63UlrhdkaSUN23MB3rlSNDNCRftcU5P8uM5/LgCd0tGoMfJNk
         zipg==
X-Gm-Message-State: ALoCoQnQZiXn667e8gPhwSBJpC22ka1WceOgTCdPCCFVh1qpfROrPf5ROzh13BNvr+WXc0e2PMwdEJvJ44biL7t+LPoNd18iPw==
X-Received: by 10.98.72.210 with SMTP id q79mr57393476pfi.16.1451770952906;
        Sat, 02 Jan 2016 13:42:32 -0800 (PST)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160102134237.ZM17072@torch.brasslantern.com>
Date: Sat, 2 Jan 2016 13:42:37 -0800
In-Reply-To: <CAKc7PVA5sdMnjLMObmAV5xkUe1jSgAmaR30S7zZ0od5su13fOA@mail.gmail.com>
Comments: In reply to Sebastian Gniazdowski <sgniazdowski@gmail.com>
        "Re: Printf builtin missing v flag support" (Jan  2,  8:17am)
References: <068ca8f5-315b-444c-b281-5f183e1daa8c@email.android.com> 
	<151231104858.ZM24513@torch.brasslantern.com> 
	<CAKc7PVCXaicToQHdgaqnOmoqHjqQLxUXQSUrBx=fjs9JH2USKQ@mail.gmail.com> 
	<160101135224.ZM10746@torch.brasslantern.com> 
	<CAKc7PVDsXof4TFRvtY15qThTEPqLz6NiSeL6dsKxqGXyK2aVeg@mail.gmail.com> 
	<160101201724.ZM1844@torch.brasslantern.com> 
	<CAKc7PVA5sdMnjLMObmAV5xkUe1jSgAmaR30S7zZ0od5su13fOA@mail.gmail.com>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Printf builtin missing v flag support
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 37496

On Jan 2,  8:17am, Sebastian Gniazdowski wrote:
}
} Maybe one other way is available - instead of moving memstream to the
} top, moving -X/x above memstream?

It's not that simple (and anyway it would be moving -X/-x down).  The
code is structured like

    do expansion for -P/-D
    do sorting for -o/-O
    if (not -z or -s [added: or -v])
       change output stream for -p or -u
    if (there is no format string) {
       if (-c/-C) {
          do columnation
	  test for write error
          return
       }
       if (-z or -s [added: or -v]) {
          copy argument list into data structure
          return
       }
       do -x/-X or -l/-N
       test for write error
       return
    }

    if (-z or -s [added: or -v])
       set up memstream [or tempfile if memstream not supported]

    do all the printf stuff
    if (there was a memstream)
       copy the memstream [or tempfile] into data structure

The two largest problems are that -x/-X are implemented by a function
that writes directly to a stdio object without keeping track of the
number of bytes written (needed for the "copy" step), and that the
test for write error is structured in a way incompatible with the
maybe-memstream-or-maybe-tempfile compile-time conditional.

Also it would be sort of annoying/inconsistent to have -v work with -x
but not with -c or -l.  -N is an oddball, I don't even know what to do
with that one; would we want a parameter value with embedded NULs?

Having written that out, it looks like there might be bugs with using
all off -u/-p plus -z/-s/-v plus -c/-C.  Haven't actually tried.  There
might also be bugs with printf-ing of NUL bytes into the memstream.

