unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: prj@po.cwru.edu (Paul Jarc)
Subject: patch: (read "\x1b") => #\esc
Date: Mon, 10 Nov 2003 17:41:59 -0500	[thread overview]
Message-ID: <m3oevjong2.fsf@multivac.cwru.edu> (raw)

[-- Attachment #1: Type: TEXT/PLAIN, Size: 453 bytes --]

This patch fixes a failure to detect EOF, and also provides "\xNN" in
strings, where NN are exactly two hexadecimal digits.  This way, your
source code can be safe to print to a tty even if the strings it
defines would not be.  If this is acceptable, I'd also like to change
print.c to use this when (write)ing strings containing control
characters.

	* read.c (scm_lreadr): detect EOF after backslash, and
	interpret \xNN hexadecimal sequences.


paul

[-- Attachment #2: read-string-hex.patch --]
[-- Type: text/x-patch, Size: 1761 bytes --]

Index: guile-core/libguile/read.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/read.c,v
retrieving revision 1.91
diff -u -r1.91 read.c
--- guile-core/libguile/read.c	4 Jun 2003 16:36:03 -0000	1.91
+++ guile-core/libguile/read.c	10 Nov 2003 22:28:07 -0000
@@ -489,7 +489,7 @@
       while ('"' != (c = scm_getc (port)))
 	{
 	  if (c == EOF)
-	    scm_input_error (FUNC_NAME, port, "end of file in string constant", SCM_EOL);
+	    str_eof: scm_input_error (FUNC_NAME, port, "end of file in string constant", SCM_EOL);
 
 	  while (j + 2 >= SCM_STRING_LENGTH (*tok_buf))
 	    scm_grow_tok_buf (tok_buf);
@@ -497,6 +497,8 @@
 	  if (c == '\\')
 	    switch (c = scm_getc (port))
 	      {
+	      case EOF:
+		goto str_eof;
 	      case '\n':
 		continue;
 	      case '0':
@@ -520,6 +522,30 @@
 	      case 'v':
 		c = '\v';
 		break;
+	      case 'x':
+		{
+		  int a, b, a_09 = 0, b_09 = 0, a_AF = 0, b_AF = 0, a_af = 0,
+		    b_af = 0;
+		  a = scm_getc (port);
+		  if (a == EOF) goto str_eof;
+		  b = scm_getc (port);
+		  if (b == EOF) goto str_eof;
+		  if      ('0' <= a && a <= '9') a_09 = 1;
+		  else if ('A' <= a && a <= 'F') a_AF = 1;
+		  else if ('a' <= a && a <= 'f') a_af = 1;
+		  if      ('0' <= b && b <= '9') b_09 = 1;
+		  else if ('A' <= b && b <= 'F') b_AF = 1;
+		  else if ('a' <= b && b <= 'f') b_af = 1;
+		  if ((a_09 || a_AF || a_af) && (b_09 || b_AF || b_af))
+		    c = (a_09? a - '0': a_AF? a - 'A' + 10: a - 'a' + 10) * 16
+		      + (b_09? b - '0': b_AF? b - 'A' + 10: b - 'a' + 10);
+		  else
+		    {
+		      scm_ungetc (b, port);
+		      scm_ungetc (a, port);
+		    }
+		  break;
+		}
 	      }
 	  SCM_STRING_CHARS (*tok_buf)[j] = c;
 	  ++j;

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

             reply	other threads:[~2003-11-10 22:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-10 22:41 Paul Jarc [this message]
2003-11-10 22:48 ` patch: (read "\x1b") => #\esc Paul Jarc
2003-11-10 23:18 ` Kevin Ryde
2003-11-11  2:45   ` Paul Jarc
2003-11-11 21:48     ` Kevin Ryde
2003-11-13 20:10 ` Marius Vollmer
2003-11-18 20:04   ` Paul Jarc
2003-11-19  0:24     ` Paul Jarc
2003-11-29 23:43     ` Marius Vollmer
2003-11-25 17:12   ` Paul Jarc
2003-11-30  1:05     ` Marius Vollmer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3oevjong2.fsf@multivac.cwru.edu \
    --to=prj@po.cwru.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).