Esempio n. 1
0
static void do_intro_line(long row, char_u *mesg, int attr)
{
  long col;
  char_u *p;
  int l;
  int clen;

  // Center the message horizontally.
  col = vim_strsize(mesg);

  col = (Columns - col) / 2;

  if (col < 0) {
    col = 0;
  }

  // Split up in parts to highlight <> items differently.
  for (p = mesg; *p != NUL; p += l) {
    clen = 0;

    for (l = 0; p[l] != NUL
         && (l == 0 || (p[l] != '<' && p[l - 1] != '>')); ++l) {
      if (has_mbyte) {
        clen += ptr2cells(p + l);
        l += (*mb_ptr2len)(p + l) - 1;
      } else {
        clen += byte2cells(p[l]);
      }
    }
    assert(row <= INT_MAX && col <= INT_MAX);
    screen_puts_len(p, l, (int)row, (int)col, *p == '<' ? hl_attr(HLF_8) : attr);
    col += clen;
  }
}
Esempio n. 2
0
/*
 * Translate a string into allocated memory, replacing special chars with
 * printable chars.  Returns NULL when out of memory.
 */
char_u *transstr(char_u *s)
{
  char_u      *res;
  char_u      *p;
  int l, len, c;
  char_u hexbuf[11];

  if (has_mbyte) {
    /* Compute the length of the result, taking account of unprintable
     * multi-byte characters. */
    len = 0;
    p = s;
    while (*p != NUL) {
      if ((l = (*mb_ptr2len)(p)) > 1) {
        c = (*mb_ptr2char)(p);
        p += l;
        if (vim_isprintc(c))
          len += l;
        else {
          transchar_hex(hexbuf, c);
          len += (int)STRLEN(hexbuf);
        }
      } else   {
        l = byte2cells(*p++);
        if (l > 0)
          len += l;
        else
          len += 4;             /* illegal byte sequence */
      }
    }
    res = alloc((unsigned)(len + 1));
  } else
    res = alloc((unsigned)(vim_strsize(s) + 1));
  if (res != NULL) {
    *res = NUL;
    p = s;
    while (*p != NUL) {
      if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) {
        c = (*mb_ptr2char)(p);
        if (vim_isprintc(c))
          STRNCAT(res, p, l);           /* append printable multi-byte char */
        else
          transchar_hex(res + STRLEN(res), c);
        p += l;
      } else
        STRCAT(res, transchar_byte(*p++));
    }
  }
  return res;
}
Esempio n. 3
0
static void do_intro_line(int row, char_u *mesg, int add_version, int attr)
{
  char_u vers[20];
  int col;
  char_u *p;
  int l;
  int clen;

#ifdef MODIFIED_BY
# define MODBY_LEN 150
  char_u modby[MODBY_LEN];

  if (*mesg == ' ') {
    vim_strncpy(modby, (char_u *)_("Modified by "), MODBY_LEN - 1);
    l = STRLEN(modby);
    vim_strncpy(modby + l, (char_u *)MODIFIED_BY, MODBY_LEN - l - 1);
    mesg = modby;
  }
#endif  // ifdef MODIFIED_BY

  // Center the message horizontally.
  col = vim_strsize(mesg);

  if (add_version) {
    STRCPY(vers, mediumVersion);

    if (highest_patch()) {
      // Check for 9.9x or 9.9xx, alpha/beta version
      if (isalpha((int)vers[3])) {
        int len = (isalpha((int)vers[4])) ? 5 : 4;
        sprintf((char *)vers + len, ".%d%s", highest_patch(),
                mediumVersion + len);
      } else {
        sprintf((char *)vers + 3,   ".%d",   highest_patch());
      }
    }
    col += (int)STRLEN(vers);
  }
  col = (Columns - col) / 2;

  if (col < 0) {
    col = 0;
  }

  // Split up in parts to highlight <> items differently.
  for (p = mesg; *p != NUL; p += l) {
    clen = 0;

    for (l = 0; p[l] != NUL
         && (l == 0 || (p[l] != '<' && p[l - 1] != '>')); ++l) {
      if (has_mbyte) {
        clen += ptr2cells(p + l);
        l += (*mb_ptr2len)(p + l) - 1;
      } else {
        clen += byte2cells(p[l]);
      }
    }
    screen_puts_len(p, l, row, col, *p == '<' ? hl_attr(HLF_8) : attr);
    col += clen;
  }

  // Add the version number to the version line.
  if (add_version) {
    screen_puts(vers, row, col, 0);
  }
}
Esempio n. 4
0
/// Translate a string into allocated memory, replacing special chars with
/// printable chars.  Returns NULL when out of memory.
///
/// @param s
///
/// @return translated string
char_u *transstr(char_u *s)
{
  char_u *res;
  char_u *p;
  int l, c;
  char_u hexbuf[11];

  if (has_mbyte) {
    // Compute the length of the result, taking account of unprintable
    // multi-byte characters.
    size_t len = 0;
    p = s;

    while (*p != NUL) {
      if ((l = (*mb_ptr2len)(p)) > 1) {
        c = (*mb_ptr2char)(p);
        p += l;

        if (vim_isprintc(c)) {
          len += l;
        } else {
          transchar_hex(hexbuf, c);
          len += STRLEN(hexbuf);
        }
      } else {
        l = byte2cells(*p++);

        if (l > 0) {
          len += l;
        } else {
          // illegal byte sequence
          len += 4;
        }
      }
    }
    res = xmallocz(len);
  } else {
    res = xmallocz(vim_strsize(s));
  }

  *res = NUL;
  p = s;

  while (*p != NUL) {
    if (has_mbyte && ((l = (*mb_ptr2len)(p)) > 1)) {
      c = (*mb_ptr2char)(p);

      if (vim_isprintc(c)) {
        // append printable multi-byte char
        STRNCAT(res, p, l);
      } else {
        transchar_hex(res + STRLEN(res), c);
      }
      p += l;
    } else {
      STRCAT(res, transchar_byte(*p++));
    }
  }

  return res;
}