delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/2000/01/21/00:08:53

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-developers-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-developers-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
Message-ID: <3887C146.EC3A310F@vinschen.de>
Date: Fri, 21 Jan 2000 03:15:34 +0100
From: Corinna Vinschen <corinna AT vinschen DOT de>
X-Mailer: Mozilla 4.7 [en] (WinNT; I)
X-Accept-Language: de,en
MIME-Version: 1.0
To: DJ Delorie <dj AT delorie DOT com>
CC: cygwin-developers AT sourceware DOT cygnus DOT com
Subject: Re: Suggestion for regtool
References: <3886E0DE DOT EE734589 AT vinschen DOT de> <200001201852 DOT NAA28114 AT envy DOT delorie DOT com>

DJ Delorie wrote:
> [...]
> This patch handles backslashes inconsistently.  I'd rather see it more
> unix-like where backslashes always quote the next character, not just
> when the next character is a slash (not that Windows would allow the
> few cases that would allow).

Do you think of sth. like this?

Corinna

Index: regtool.cc
===================================================================
RCS file: /src/cvsroot/winsup-000108/utils/regtool.cc,v
retrieving revision 1.2
diff -u -p -r1.2 regtool.cc
--- regtool.cc  2000/01/20 22:20:54     1.2
+++ regtool.cc  2000/01/21 02:10:26
@@ -10,6 +10,7 @@ details. */

 #include <stdio.h>
 #include <stdlib.h>
+#include <ctype.h>
 #include <getopt.h>
 #include <windows.h>

@@ -94,12 +95,75 @@ struct {

 void translate(char *key)
 {
-  char *c = key;
-  while (c = strchr (c, '/'))
-    if (c > key && c[-1] == '\\')
-      memmove(c-1, c, strlen(c)+1);
-    else
-      *c++ = '\\';
+#define isodigit(c) (strchr("01234567", c))
+#define tooct(c)    ((c)-'0')
+#define tohex(c)    (strchr(_hs,tolower(c))-_hs)
+  static char _hs[] = "0123456789abcdef";
+
+  char *d = key;
+  char *s = key;
+  char c;
+
+  while (*s)
+    {
+      if (*s == '\\')
+        switch (*++s)
+          {
+          case 'a':
+            *d++ = '\007';
+            break;
+          case 'b':
+            *d++ = '\b';
+            break;
+          case 'e':
+            *d++ = '\033';
+            break;
+          case 'f':
+            *d++ = '\f';
+            break;
+          case 'n':
+            *d++ = '\n';
+            break;
+          case 'r':
+            *d++ = '\r';
+            break;
+          case 't':
+            *d++ = '\t';
+            break;
+          case 'v':
+            *d++ = '\v';
+            break;
+          case '0': case '1': case '2': case '3':
+          case '4': case '5': case '6': case '7':
+            c = tooct(*s);
+            if (isodigit(s[1]))
+              {
+                c = (c << 3) | tooct(*++s);
+                if (isodigit(s[1]))
+                  c = (c << 3) | tooct(*++s);
+              }
+            *d++ = c;
+            break;
+          case 'x':
+            if (isxdigit(s[1]))
+              {
+                c = tohex(*++s);
+                if (isxdigit(s[1]))
+                  c = (c << 4) | tohex(*++s);
+              }
+            *d++ = c;
+            break;
+          default:     /* before non-special char: just add the char */
+            *d++ = *s;
+            break;
+          }
+      else if (*s == '/')
+        *d++ = '\\';
+      else
+        *d++ = *s;
+      ++s;
+    }
+  *d = '\0';
 }

 void

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019