From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3852 invoked by alias); 20 Nov 2015 01:17:05 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20970 Received: (qmail 7708 invoked from network); 20 Nov 2015 01:17:04 -0000 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,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=i4rWjaVe6aemR9zF/nyNLEBCuBypGk5FttkY7GrkvJs=; b=Mo4kUthmc6bYS4dnhiJ6h6I9cYQYoZu4/+0CTlr6KywUACukL+yd9/PZO6lWvXaeXV pvJ4s06VWGWvbO7u6Ugk6VrcJbZPP+5RbrCSu91pCoooIYSLvDvxmXoWAPehTipCZuKh i4seiy6loLAAsRznlDDIttngoxAwgIcZ3NnbTy0ujla1dKdVPxhP65KvSYmWYTUDcKpw 6ZHJZy4JvLwcALrbZAWYPDAe2CN1P4deYJuTQCGEHb6cQPspXtZU9eAN9/TLLXgEMRt6 AVGMf9FdXOantFFfJa/xzE/Ka8wNY4/XFsRaj4nz5GNy/0UN+4qLzDFIT9ib8HDeJuBD 9T3g== MIME-Version: 1.0 X-Received: by 10.55.18.40 with SMTP id c40mr9945362qkh.99.1447982221871; Thu, 19 Nov 2015 17:17:01 -0800 (PST) In-Reply-To: References: Date: Fri, 20 Nov 2015 02:17:01 +0100 Message-ID: Subject: Re: Read file with escaped newlines into array From: Mikael Magnusson To: Sebastian Gniazdowski Cc: Zsh Users Content-Type: text/plain; charset=UTF-8 On Thu, Nov 19, 2015 at 6:34 PM, Sebastian Gniazdowski wrote: > Hello > fc -W stores history to a given file. It escapes newlines with \. How > to read such file into array and have "\^M" lines put back together > into single array entries? Also note that the history file is stored metafied, so even if you take care of escaped newlines, you still would need to unmetafy it. -- Mikael Magnusson unmetafy.c #define Meta ((char) 0x83) #define _GNU_SOURCE #include #include /* from zsh utils.c */ char *unmetafy(char *s, int *len) { char *p, *t; for (p = s; *p && *p != Meta; p++); for (t = p; (*t = *p++);) if (*t++ == Meta) t[-1] = *p++ ^ 32; if (len) *len = t - s; return s; } int main(int argc, char *argv[]) { char *line = NULL; size_t size; while (getline(&line, &size, stdin) != -1) { unmetafy(line, NULL); printf("%s", line); } if (line) free(line); return EXIT_SUCCESS; }