zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: [bug] history corrupt on utf8
Date: Sun, 23 Jun 2013 23:24:04 +0200	[thread overview]
Message-ID: <CAHYJk3SFaF8Y3+2SPKXjmp3BRS3fE6FqKj7YGcWA5EaidoMmnw@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7ZQiT8g3uU+rzmKNWC+WE-xOrVCX_LUHZKJq5tPnOxgtw@mail.gmail.com>

On 23 June 2013 20:33, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Jun 22, 2013 7:07 PM, "Mikael Magnusson" <mikachu@gmail.com> wrote:
>>
>> The history file isn't saved verbatim, since the command line can
>> contain non-utf8, nuls, etc.
>
> To be more specific, the history file is saved in the same format used to
> represent history lines internally, except for prefixing newlines with
> backslash.  The file is only "corrupted" if zsh itself can't re-read it.
> We gave up on sharing history files with other shells a long time ago.

If you want, you can use this small program to "uncorrupt" it
(obviously don't overwrite the history file with the result),

#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;
}

--
Mikael Magnusson


      reply	other threads:[~2013-06-23 21:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-22 18:45 Alexander Voikov
2013-06-23  2:06 ` Mikael Magnusson
2013-06-23 18:33   ` Bart Schaefer
2013-06-23 21:24     ` 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=CAHYJk3SFaF8Y3+2SPKXjmp3BRS3fE6FqKj7YGcWA5EaidoMmnw@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=zsh-workers@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).