Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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 X-Mailer: Mozilla 4.7 [en] (WinNT; I) X-Accept-Language: de,en MIME-Version: 1.0 To: DJ Delorie 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> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 #include +#include #include #include @@ -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