Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Read file with escaped newlines into array
- X-seq: zsh-users 20970
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Subject: Re: Read file with escaped newlines into array
- Date: Fri, 20 Nov 2015 02:17:01 +0100
- Cc: Zsh Users <zsh-users@xxxxxxx>
- 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==
- In-reply-to: <CAKc7PVCZzEfKkcWyPUb58ffmne6E8Eh6_CDpeLc0efd6hEQAow@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVCZzEfKkcWyPUb58ffmne6E8Eh6_CDpeLc0efd6hEQAow@mail.gmail.com>
On Thu, Nov 19, 2015 at 6:34 PM, Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> 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 <stdio.h>
#include <stdlib.h>
/* 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;
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author