guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

guile 2.0.1 working on cygwin (probably 2.0.0 also)


From: objc
Subject: guile 2.0.1 working on cygwin (probably 2.0.0 also)
Date: Mon, 23 May 2011 02:59:47 +0100

Hi Guilers,
 
I've got guile 2.0.1 to work on cygwin with a nasty "test hack".
 
in scm_to_stringn function:
 
      ret = mem_iconveh (jrgbuf, ilen,
                         "ISO-8859-1"
                        //??????????
                        , enc,//"ANSI_X3.4-1968"  "ISO-8859-1" "UTF-8"
                         (enum iconv_ilseq_handler) handler, NULL,
                         &buf, &len);
 
The mem_iconveh function fails.
re-trying with "ANSI_X3.4-1968" or "UTF-8" in the //?????????? gets it work.
 
I've got guile 2.0.1 to work on cygwin, but have not investigated how or why it works.
Any thoughts of a fix ?
 
Cheers,
objcjohn
 
libguile/strings.c (orig.)
=================
char *
scm_to_stringn (SCM str, size_t *lenp, const char *encoding,
                scm_t_string_failed_conversion_handler handler)
{
  char *buf;
  size_t ilen, len, i;
  int ret;
  const char *enc;
 
  if (!scm_is_string (str))
    scm_wrong_type_arg_msg (NULL, 0, str, "string");
  ilen = scm_i_string_length (str);
 
  if (ilen == 0)
    {
      buf = scm_malloc (1);
      buf[0] = '\0';
      if (lenp)
        *lenp = 0;
      return buf;
    }
 
  if (lenp == NULL)
    for (i = 0; i < ilen; i++)
      if (scm_i_string_ref (str, i) == '\0')
        scm_misc_error (NULL,
                        "string contains #\\nul character: ~S",
                        scm_list_1 (str));
 
  if (scm_i_is_narrow_string (str) && (encoding == NULL))
    {
      /* If using native Latin-1 encoding, just copy the string
         contents.  */
      if (lenp)
        {
          buf = scm_malloc (ilen);
          memcpy (buf, scm_i_string_chars (str), ilen);
          *lenp = ilen;
          return buf;
        }
      else
        {
          buf = scm_malloc (ilen + 1);
          memcpy (buf, scm_i_string_chars (str), ilen);
          buf[ilen] = '\0';
          return buf;
        }
    }
 

  buf = NULL;
  len = 0;
  enc = encoding;
  if (enc == NULL)
    enc = "ISO-8859-1";
  if (scm_i_is_narrow_string (str))
    {
      ret = mem_iconveh (scm_i_string_chars (str), ilen,
                         "ISO-8859-1", enc,
                         (enum iconv_ilseq_handler) handler, NULL,
                         &buf, &len);
 
      if (ret != 0)
        scm_encoding_error (__func__, errno,
       "cannot convert narrow string to output locale",
       SCM_BOOL_F,
       /* FIXME: Faulty character unknown.  */
       SCM_BOOL_F);
    }
  else
    {
      buf = u32_conv_to_encoding (enc,
                                  (enum iconv_ilseq_handler) handler,
                                  (scm_t_uint32 *) scm_i_string_wide_chars (str),
                                  ilen,
                                  NULL,
                                  NULL, &len);
      if (buf == NULL)
        scm_encoding_error (__func__, errno,
       "cannot convert wide string to output locale",
       SCM_BOOL_F,
       /* FIXME: Faulty character unknown.  */
       SCM_BOOL_F);
    }
  if (handler == SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE)
    {
      if (SCM_R6RS_ESCAPES_P)
 {
   /* The worst case is if the input string contains all 4-digit
      hex escapes.  "\uXXXX" (six characters) becomes "\xXXXX;"
      (seven characters).  Make BUF large enough to hold
      that.  */
   buf = scm_realloc (buf, (len * 7) / 6 + 1);
   unistring_escapes_to_r6rs_escapes (buf, &len);
 }
      else
        unistring_escapes_to_guile_escapes (buf, &len);
 
      buf = scm_realloc (buf, len);
    }
  if (lenp)
    *lenp = len;
  else
    {
      buf = scm_realloc (buf, len + 1);
      buf[len] = '\0';
    }
 
  scm_remember_upto_here_1 (str);
  return buf;
}
 
libguile/strings.c (test)
================
char *
scm_to_stringn (SCM str, size_t *lenp, const char *encoding,
                scm_t_string_failed_conversion_handler handler)
{
  char *buf;
  const char *jrgbuf;//jrg
  size_t ilen, len, i;
  int ret;
  const char *enc;
 
  if (!scm_is_string (str))
    scm_wrong_type_arg_msg (NULL, 0, str, "string");
  ilen = scm_i_string_length (str);
 
  if (ilen == 0)
    {
      buf = scm_malloc (1);
      buf[0] = '\0';
      if (lenp)
        *lenp = 0;
      return buf;
    }
 
  if (lenp == NULL)
    for (i = 0; i < ilen; i++)
      if (scm_i_string_ref (str, i) == '\0')
        scm_misc_error (NULL,
                        "string contains #\\nul character: ~S",
                        scm_list_1 (str));
 
  if (scm_i_is_narrow_string (str) && (encoding == NULL))
    {
      /* If using native Latin-1 encoding, just copy the string
         contents.  */
      if (lenp)
        {
          buf = scm_malloc (ilen);
          memcpy (buf, scm_i_string_chars (str), ilen);
          *lenp = ilen;
          return buf;
        }
      else
        {
          buf = scm_malloc (ilen + 1);
          memcpy (buf, scm_i_string_chars (str), ilen);
          buf[ilen] = '\0';
          return buf;
        }
    }
 

  buf = NULL;
  jrgbuf = NULL;
  len = 0;
  enc = encoding;
 
//jrg  if (enc == NULL) enc = "ISO-8859-1";
  if (enc == NULL) enc = "ANSI_X3.4-1968";
 
  if (scm_i_is_narrow_string (str))
    {
   jrgbuf = scm_i_string_chars (str);     //jrg
//      fprintf (stderr,"jrgbuf [%s]ilen[%d]encoding[%s]enc[%s]lenp[%d]\n",jrgbuf,ilen,encoding,enc,(int)(size_t )lenp);//jrg
      ret = mem_iconveh (jrgbuf, ilen,
                         "ANSI_X3.4-1968", enc,//"ANSI_X3.4-1968"  "ISO-8859-1" "UTF-8"
                         (enum iconv_ilseq_handler) handler, NULL,
                         &buf, &len);
 
      if (ret != 0)
      {//jrg
      //try another one !!
//      fprintf (stderr,"try ISO-8859-1 jrgbuf [%s]ilen[%d]encoding[%s]enc[%s]lenp[%d]\n",jrgbuf,ilen,encoding,enc,(int)(size_t )lenp);//jrg
      ret = mem_iconveh (jrgbuf, ilen,
                         "ISO-8859-1", enc,//"ANSI_X3.4-1968"  "ISO-8859-1" "UTF-8"
                         (enum iconv_ilseq_handler) handler, NULL,
                         &buf, &len);
      }
      if (ret != 0)
      {//jrg
      //try another one !!
//      fprintf (stderr,"try UTF-8jrgbuf [%s]ilen[%d]encoding[%s]enc[%s]lenp[%d]\n",jrgbuf,ilen,encoding,enc,(int)(size_t )lenp);//jrg
      ret = mem_iconveh (jrgbuf, ilen,
                         "UTF-8", enc,//"ANSI_X3.4-1968"  "ISO-8859-1" "UTF-8"
                         (enum iconv_ilseq_handler) handler, NULL,
                         &buf, &len);
      }
      if (ret != 0)
      {//jrg
 
        printf("(ret != 0) jrgbuf [%s] buf[%s]\n",jrgbuf,buf);//jrg
       fprintf (stderr,"failed return jrgbuf jrgbuf [%s]ilen[%d]encoding[%s]enc[%s]lenp[%d]\n",jrgbuf,ilen,encoding,enc,(int)(size_t )lenp);//jrg
        return (char*)jrgbuf;//hmmm
 
        scm_encoding_error (__func__, errno,
       "cannot convert narrow string to output locale",
       SCM_BOOL_F,
       /* FIXME: Faulty character unknown.  */
       SCM_BOOL_F);
   }//jrg
    }
  else
    {
   jrgbuf = (char *)(scm_t_uint32 *) scm_i_string_wide_chars (str);     //jrg
   fprintf (stderr,"jrgbuf [%s]ilen[%d]encoding[%s]enc[%s]lenp[%d]\n",jrgbuf,ilen,encoding,enc,(int)(size_t )lenp);//jrg
      buf = u32_conv_to_encoding (enc,
                                  (enum iconv_ilseq_handler) handler,
                                  (scm_t_uint32 *) scm_i_string_wide_chars (str),
                                  ilen,
                                  NULL,
                                  NULL, &len);
      if (buf == NULL)
      {//jrg
        printf("(buf == NULL) jrgbuf [%s] buf [%s]\n",jrgbuf,buf);//jrg
        scm_encoding_error (__func__, errno,
       "cannot convert wide string to output locale",
       SCM_BOOL_F,
       /* FIXME: Faulty character unknown.  */
       SCM_BOOL_F);
   }
    }
  if (handler == SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE)
    {
      if (SCM_R6RS_ESCAPES_P)
 {
   /* The worst case is if the input string contains all 4-digit
      hex escapes.  "\uXXXX" (six characters) becomes "\xXXXX;"
      (seven characters).  Make BUF large enough to hold
      that.  */
   buf = scm_realloc (buf, (len * 7) / 6 + 1);
   unistring_escapes_to_r6rs_escapes (buf, &len);
 }
      else
        unistring_escapes_to_guile_escapes (buf, &len);
 
      buf = scm_realloc (buf, len);
    }
  if (lenp)
    *lenp = len;
  else
    {
      buf = scm_realloc (buf, len + 1);
      buf[len] = '\0';
    }
 
  scm_remember_upto_here_1 (str);
  return buf;
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]