view mcabber/mcabber/utf8.c @ 2304:fa8365fb6ac2

[PATCH 1/3] New option: vi_mode If the new vi_mode option is set to 1, let MCabber's non-chat mode accept a few commands loosely based on those available in vi(1)'s normal mode, e.g.: A Call "/roster unread_first". a Call "/roster unread_next". F Call "/roster group_prev". f Call "/roster group_next". G Call "/roster bottom". gg Call "/roster top". i Enter chat mode. [<n>]j Call "/roster down [<n>]". [<n>]k Call "/roster up [<n>]". n Repeat the previous search (if any). O Call "/roster unread_first" and open chat window. o Call "/roster unread_next" and open chat window. ZZ Call "/quit". zM Call "/group fold" for all groups. zR Call "/group unfold" for all groups. <Space> Call "/group toggle" for the current group. '' Call "/roster alternate". ! Toggle attention flag for current buddy. # Toggle unread messages flag for current buddy. /<str> Call "/roster search <str>". :q Call "/quit". :wq Call "/quit". :x Call "/quit". :<n> Jump to line <n> in the roster. :<cmd> Call "/<cmd>" (unless <cmd> matches one of the above commands).
author Holger Weiß <holger@zedat.fu-berlin.de>
date Wed, 22 Jul 2015 19:25:22 +0200
parents dda89a3801c4
children
line wrap: on
line source

/*
 * utf8.c       -- UTF-8 routines
 *
 * Copyright (C) 2006 Reimar Döffinger <Reimar.Doeffinger@stud.uni-karlsruhe.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

#include "utf8.h"

char *prev_char(char *str, const char *limit)
{
  if (str <= limit)
    return str;
  str--;
  if (utf8_mode)
    while ((str > limit) && ((*str & 0xc0) == 0x80))
      str--;
  return str;
}

char *next_char(char *str)
{
  if (!*str)
    return str;
  str++;
  if (utf8_mode)
    while ((*str & 0xc0) == 0x80)
      str++;
  return str;
}

unsigned get_char(const char *str)
{
  unsigned char *strp = (unsigned char *)str;
  unsigned c = *strp++;
  unsigned mask = 0x80;
  int len = -1;
  if (!utf8_mode)
    return c;
  while (c & mask) {
    mask >>= 1;
    len++;
  }
  if (len <= 0 || len > 4)
    goto no_utf8;
  c &= mask - 1;
  while ((*strp & 0xc0) == 0x80) {
    if (len-- <= 0)
      goto no_utf8;
    c = (c << 6) | (*strp++ & 0x3f);
  }
  if (len)
    goto no_utf8;
  return c;

no_utf8:
  return *str;
}

char *put_char(char *str, unsigned c)
{
  int mask = 0xffffffc0;
  int i = 4;
  char code[5];
  if (!utf8_mode || c < 128) {
    *str++ = c;
    return str;
  }
  while (c & mask) {
    code[i--] = 0x80 | (c & 0x3f);
    c >>= 6;
    mask >>= 1;
    if (i < 0) {
      *str++ = '?';
      return str;
    }
  }
  code[i] = (mask << 1) | c;
  for (; i < 5; i++)
    *str++ = code[i];
  return str;
}

/* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2:  For Vim users... */