Пример #1
0
static void
setup_windows_coding_system (Lisp_Object coding_system,
			     struct coding_system * coding)
{
  memset (coding, 0, sizeof (*coding));
  setup_coding_system (coding_system, coding);

  /* Unset CODING_ANNOTATE_COMPOSITION_MASK.  Previous code had
     comments about crashes in encode_coding_iso2022 trying to
     dereference a null pointer when composition was on.  Selection
     data should not contain any composition sequence on Windows.

     CODING_ANNOTATION_MASK also includes
     CODING_ANNOTATE_DIRECTION_MASK and CODING_ANNOTATE_CHARSET_MASK,
     which both apply to ISO6429 only.  We don't know if these really
     need to be unset on Windows, but it probably doesn't hurt
     either.  */
  coding->common_flags &= ~CODING_ANNOTATION_MASK;
  coding->mode |= CODING_MODE_LAST_BLOCK | CODING_MODE_SAFE_ENCODING;
}
Пример #2
0
static HGLOBAL
convert_to_handle_as_coded (Lisp_Object coding_system)
{
  HGLOBAL htext = NULL, htext2;
  int nbytes;
  unsigned char *src;
  unsigned char *dst = NULL;
  int bufsize;
  struct coding_system coding;
  Lisp_Object string = Qnil;

  ONTRACE (fprintf (stderr, "convert_to_handle_as_coded: %s\n",	
		    SDATA (SYMBOL_NAME (coding_system))));

  setup_coding_system (Fcheck_coding_system (coding_system), &coding);
  coding.src_multibyte = 1;
  coding.dst_multibyte = 0;
  /* Need to set COMPOSITION_DISABLED, otherwise Emacs crashes in
     encode_coding_iso2022 trying to dereference a null pointer.  */
  coding.composing = COMPOSITION_DISABLED;
  if (coding.type == coding_type_iso2022)
    coding.flags |= CODING_FLAG_ISO_SAFE;
  coding.mode |= CODING_MODE_LAST_BLOCK;
  /* Force DOS line-ends. */
  coding.eol_type = CODING_EOL_CRLF;

  if (SYMBOLP (coding.pre_write_conversion)
      && !NILP (Ffboundp (coding.pre_write_conversion)))
    string = run_pre_post_conversion_on_str (current_text, &coding, 1);
  else
    string = current_text;

  nbytes = SBYTES (string);
  src = SDATA (string);

  bufsize = encoding_buffer_size (&coding, nbytes) +2;
  htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bufsize);

  if (htext != NULL)
    dst = (unsigned char *) GlobalLock (htext);

  if (dst != NULL)
    {
      encode_coding (&coding, src, dst, nbytes, bufsize-2);
      /* Add the string terminator.  Add two NULs in case we are
	 producing Unicode here.  */
      dst[coding.produced] = dst[coding.produced+1] = '\0';
    }

  if (dst != NULL)
    GlobalUnlock (htext);

  if (htext != NULL)
    {
      /* Shrink data block to actual size.  */
      htext2 = GlobalReAlloc (htext, coding.produced+2,
			      GMEM_MOVEABLE | GMEM_DDESHARE);
      if (htext2 != NULL) htext = htext2;
    }

  return htext;
}