From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: prj@po.cwru.edu (Paul Jarc) Newsgroups: gmane.lisp.guile.devel Subject: Re: libguile/print.c fixes Date: Tue, 06 May 2003 10:51:29 -0400 Organization: What did you have in mind? A short, blunt, human pyramid? Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: References: <87ade0zwwe.fsf@raven.i.defaultvalue.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1052233008 14193 80.91.224.249 (6 May 2003 14:56:48 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 6 May 2003 14:56:48 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue May 06 16:56:46 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19D3rG-0003c1-00 for ; Tue, 06 May 2003 16:55:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19D3sA-0007iw-01 for guile-devel@m.gmane.org; Tue, 06 May 2003 10:56:50 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 19D3pu-0006lo-00 for guile-devel@gnu.org; Tue, 06 May 2003 10:54:30 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 19D3oq-0005rw-00 for guile-devel@gnu.org; Tue, 06 May 2003 10:53:25 -0400 Original-Received: from multivac.student.cwru.edu ([129.22.114.26] helo=multivac.cwru.edu) by monty-python.gnu.org with smtp (Exim 4.10.13) id 19D3n1-0004zI-00 for guile-devel@gnu.org; Tue, 06 May 2003 10:51:31 -0400 Original-Received: (qmail 10182 invoked by uid 500); 6 May 2003 14:51:52 -0000 Original-To: Rob Browning In-Reply-To: <87ade0zwwe.fsf@raven.i.defaultvalue.org> (Rob Browning's message of "Mon, 05 May 2003 20:28:17 -0500") Mail-Copies-To: nobody Mail-Followup-To: Rob Browning , guile-devel@gnu.org Original-Lines: 19 User-Agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2283 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2283 --=-=-= Rob Browning wrote: > prj@po.cwru.edu (Paul Jarc) writes: >> Symbol names containing \ don't strictly need to be printed in >> #{this}# style, but it would significantly simplify the code if they >> were. Any objections? > > Not sure. It's nice to avoid the escaping when you don't need it, but > I'm not sure how much complexity that introduces. I guess it's not that complex, although it does introduce a performance hit for certain long symbol names, since part of the string is re-scanned. This patch fixes the bugs with symbol names, but leaves backslash handling the way it is. * print.c (scm_print_symbol_name): Bug fixes and comments. paul --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=guile.patch Index: libguile/print.c =================================================================== RCS file: /cvsroot/guile/guile/guile-core/libguile/print.c,v retrieving revision 1.149 diff -u -r1.149 print.c --- libguile/print.c 5 Apr 2003 20:45:17 -0000 1.149 +++ libguile/print.c 6 May 2003 14:48:58 -0000 @@ -282,27 +282,37 @@ void scm_print_symbol_name (const char *str, size_t len, SCM port) { - size_t pos; + /* This points to the first character that has not yet been written to the + * port. */ + size_t pos = 0; + /* This points to the character we're currently looking at. */ size_t end; - int weird; - int maybe_weird; + /* If the name contains weird characters, we'll escape them with + * backslashes and set this flag; it indicates that we should surround the + * name with "#{" and "}#". */ + int weird = 0; + /* Backslashes are not sufficient to make a name weird, but if a name is + * weird because of other characters, backslahes need to be escaped too. + * The first time we see a backslash, we set maybe_weird, and mw_pos points + * to the backslash. Then if the name turns out to be weird, we re-process + * everything starting from mw_pos. */ + int maybe_weird = 0; size_t mw_pos = 0; - - pos = 0; - weird = 0; - maybe_weird = 0; - - /* XXX - Lots of weird symbol names are missed, such as "12" or - "'a". */ + /* If the name is purely numeric, then it's weird as a whole, even though + * none of the individual characters is weird. But we won't know this + * until we reach the end of the name. This flag describes the part of the + * name we've looked at so far. */ + int all_digits = 1; if (len == 0) scm_lfwrite ("#{}#", 4, port); - else if (str[0] == '#' || str[0] == ':' || str[len-1] == ':') + else if (str[0] == '#' || str[0] == '\'' || + str[0] == ':' || str[len-1] == ':') { scm_lfwrite ("#{", 2, port); weird = 1; } - + for (end = pos; end < len; ++end) switch (str[end]) { @@ -314,8 +324,10 @@ case ')': case '"': case ';': + case '#': case SCM_WHITE_SPACES: case SCM_LINE_INCREMENTORS: + all_digits = 0; weird_handler: if (maybe_weird) { @@ -328,9 +340,7 @@ weird = 1; } if (pos < end) - { - scm_lfwrite (str + pos, end - pos, port); - } + scm_lfwrite (str + pos, end - pos, port); { char buf[2]; buf[0] = '\\'; @@ -340,6 +350,7 @@ pos = end + 1; break; case '\\': + all_digits = 0; if (weird) goto weird_handler; if (!maybe_weird) @@ -348,14 +359,18 @@ mw_pos = pos; } break; - case '}': - case '#': - if (weird) - goto weird_handler; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': break; default: + all_digits = 0; break; } + if (all_digits) + { + scm_lfwrite ("#{", 2, port); + weird = 1; + } if (pos < end) scm_lfwrite (str + pos, end - pos, port); if (weird) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--