zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Read file with escaped newlines into array
Date: Fri, 20 Nov 2015 02:17:01 +0100	[thread overview]
Message-ID: <CAHYJk3S7JkHmRrgCkwQjBXWs7spPWobBoypRZnbjOCysSHh9-A@mail.gmail.com> (raw)
In-Reply-To: <CAKc7PVCZzEfKkcWyPUb58ffmne6E8Eh6_CDpeLc0efd6hEQAow@mail.gmail.com>

On Thu, Nov 19, 2015 at 6:34 PM, Sebastian Gniazdowski
<sgniazdowski@gmail.com> 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;
}


      parent reply	other threads:[~2015-11-20  1:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-19 17:34 Sebastian Gniazdowski
2015-11-19 19:17 ` Bart Schaefer
2015-11-19 20:14   ` Sebastian Gniazdowski
2016-05-10 14:26   ` Sebastian Gniazdowski
2016-05-10 16:15     ` Bart Schaefer
2016-05-10 18:10       ` Sebastian Gniazdowski
2015-11-20  1:17 ` Mikael Magnusson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHYJk3S7JkHmRrgCkwQjBXWs7spPWobBoypRZnbjOCysSHh9-A@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=sgniazdowski@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).