Mail Archives: cygwin-developers/2000/01/21/00:08:53
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 -