guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] GNU Guile branch, master, updated. release_1-9-11-192-ge


From: Michael Gran
Subject: [Guile-commits] GNU Guile branch, master, updated. release_1-9-11-192-ge50d921
Date: Fri, 16 Jul 2010 13:51:01 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

http://git.savannah.gnu.org/cgit/guile.git/commit/?id=e50d921bd87e53df33c04831ecf8b3d100af2b7b

The branch, master has been updated
       via  e50d921bd87e53df33c04831ecf8b3d100af2b7b (commit)
       via  daedbca7de1350e85cc059654e204744052575c1 (commit)
      from  63479112d6176515850fcbf72cbe5f64b633f564 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e50d921bd87e53df33c04831ecf8b3d100af2b7b
Author: Michael Gran <address@hidden>
Date:   Fri Jul 16 06:44:59 2010 -0700

    read-line should use port's encoding, not locale's encoding
    
    * libguile/rdelim.c (scm_read_line): modified, use port's encoding
    * test-suite/test/ports.test: new test

commit daedbca7de1350e85cc059654e204744052575c1
Author: Michael Gran <address@hidden>
Date:   Fri Jul 16 05:39:52 2010 -0700

    More explicit variable names in scm_i_scan_for_encoding
    
    Note especially that the variable 'i' has two different uses in this
    function, and they get confused.
    
    * libguile/read.c (scm_i_scan_for_encoding): cleanup

-----------------------------------------------------------------------

Summary of changes:
 libguile/rdelim.c           |   17 ++++++++++++-----
 libguile/read.c             |   33 ++++++++++++++++++---------------
 test-suite/tests/ports.test |   16 ++++++++++++++++
 3 files changed, 46 insertions(+), 20 deletions(-)

diff --git a/libguile/rdelim.c b/libguile/rdelim.c
index 1f46e5b..1340c62 100644
--- a/libguile/rdelim.c
+++ b/libguile/rdelim.c
@@ -205,12 +205,16 @@ SCM_DEFINE (scm_read_line, "%read-line", 0, 1, 0,
   char *s;
   size_t slen = 0;
   SCM line, term;
+  const char *enc;
+  scm_t_string_failed_conversion_handler hndl;
 
   if (SCM_UNBNDP (port))
     port = scm_current_input_port ();
   SCM_VALIDATE_OPINPORT (1,port);
 
   pt = SCM_PTAB_ENTRY (port);
+  enc = pt->encoding;
+  hndl = pt->ilseq_handler;
   if (pt->rw_active == SCM_PORT_WRITE)
     scm_ptobs[SCM_PTOBNUM (port)].flush (port);
 
@@ -220,19 +224,22 @@ SCM_DEFINE (scm_read_line, "%read-line", 0, 1, 0,
     term = line = SCM_EOF_VAL;
   else
     {
-      if (s[slen-1] == '\n')
+      if (s[slen - 1] == '\n')
        {
          term = SCM_MAKE_CHAR ('\n');
-         s[slen-1] = '\0';
-         line = scm_take_locale_stringn (s, slen-1);
+         s[slen - 1] = '\0';
+
+         line = scm_from_stringn (s, slen - 1, enc, hndl);
+         free (s);
          SCM_INCLINE (port);
        }
       else
        {
          /* Fix: we should check for eof on the port before assuming this. */
          term = SCM_EOF_VAL;
-         line = scm_take_locale_stringn (s, slen);
-         SCM_COL (port) += slen;
+         line = scm_from_stringn (s, slen, enc, hndl);
+         free (s);
+         SCM_COL (port) += scm_i_string_length (line);
        }
     }
 
diff --git a/libguile/read.c b/libguile/read.c
index df987c7..2ac4d10 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -1627,11 +1627,10 @@ char *
 scm_i_scan_for_encoding (SCM port)
 {
   char header[SCM_ENCODING_SEARCH_SIZE+1];
-  size_t bytes_read;
+  size_t bytes_read, encoding_length, i;
   char *encoding = NULL;
   int utf8_bom = 0;
-  char *pos;
-  int i;
+  char *pos, *encoding_start;
   int in_comment;
 
   if (SCM_FPORTP (port) && !SCM_FDES_RANDOM_P (SCM_FPORT_FDES (port)))
@@ -1669,46 +1668,50 @@ scm_i_scan_for_encoding (SCM port)
     pos ++;
 
   /* grab the next token */
+  encoding_start = pos;
   i = 0;
-  while (pos + i - header <= SCM_ENCODING_SEARCH_SIZE 
-         && pos + i - header < bytes_read
-        && (isalnum ((int) pos[i]) || strchr ("_-.:/,+=()", pos[i]) != NULL))
+  while (encoding_start + i - header <= SCM_ENCODING_SEARCH_SIZE
+         && encoding_start + i - header < bytes_read
+        && (isalnum ((int) encoding_start[i])
+            || strchr ("_-.:/,+=()", encoding_start[i]) != NULL))
     i++;
 
-  if (i == 0)
+  encoding_length = i;
+  if (encoding_length == 0)
     return NULL;
 
-  encoding = scm_gc_strndup (pos, i, "encoding");
-  for (i = 0; i < strlen (encoding); i++)
+  encoding = scm_gc_strndup (encoding_start, encoding_length, "encoding");
+  for (i = 0; i < encoding_length; i++)
     encoding[i] = toupper ((int) encoding[i]);
 
   /* push backwards to make sure we were in a comment */
   in_comment = 0;
-  while (pos - i - header > 0)
+  pos = encoding_start;
+  while (pos >= header)
     {
-      if (*(pos - i) == '\n')
+      if (*pos == '\n')
        {
          /* This wasn't in a semicolon comment. Check for a
           hash-bang comment. */
          char *beg = strstr (header, "#!");
          char *end = strstr (header, "!#");
-         if (beg < pos && pos < end)
+         if (beg < encoding_start && encoding_start + encoding_length < end)
            in_comment = 1;
          break;
        }
-      if (*(pos - i) == ';')
+      if (*pos == ';')
        {
          in_comment = 1;
          break;
        }
-      i ++;
+      pos --;
     }
   if (!in_comment)
     /* This wasn't in a comment */
     return NULL;
 
   if (utf8_bom && strcmp(encoding, "UTF-8"))
-    scm_misc_error (NULL, 
+    scm_misc_error (NULL,
                    "the port input declares the encoding ~s but is encoded as 
UTF-8",
                    scm_list_1 (scm_from_locale_string (encoding)));
 
diff --git a/test-suite/tests/ports.test b/test-suite/tests/ports.test
index 1d8bd50..9f9985a 100644
--- a/test-suite/tests/ports.test
+++ b/test-suite/tests/ports.test
@@ -182,6 +182,22 @@
             (string=? line test-string)))
   (delete-file filename))
 
+;;; read-line should use the port encoding (not the locale encoding).
+(let ((str "ĉu bone?"))
+      (with-locale "C"
+        (let* ((filename (test-file))
+               (port (open-file filename "wl")))
+          (set-port-encoding! port "UTF-8")
+          (write-line str port)
+          (let ((in-port (open-input-file filename)))
+            (set-port-encoding! in-port "UTF-8")
+            (let ((line (read-line in-port)))
+              (close-port in-port)
+              (close-port port)
+              (pass-if "file: read-line honors port encoding"
+                       (string=? line str))))
+          (delete-file filename))))
+
 ;;; ungetting characters and strings.
 (with-input-from-string "walk on the moon\nmoon"
                        (lambda ()


hooks/post-receive
-- 
GNU Guile



reply via email to

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