unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* patch: (read "\x1b") => #\esc
@ 2003-11-10 22:41 Paul Jarc
  2003-11-10 22:48 ` Paul Jarc
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Paul Jarc @ 2003-11-10 22:41 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-11-30  1:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-10 22:41 patch: (read "\x1b") => #\esc Paul Jarc
2003-11-10 22:48 ` 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

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).