- The iconv-supporting code can now ask filtered_fwrite() to use
authorWayne Davison <wayned@samba.org>
Mon, 6 Feb 2006 16:54:12 +0000 (16:54 +0000)
committerWayne Davison <wayned@samba.org>
Mon, 6 Feb 2006 16:54:12 +0000 (16:54 +0000)
  isprint() when iconv() could not be setup.
- Changed the output idiom for escaped chars to use \#123 instead
  of \0123 because that makes it possible for a script to know for
  sure what version of rsync did the output (and thus, what the
  unescape rules are).

log.c

diff --git a/log.c b/log.c
index 91b57d4374d838572daa619e144bbab84de38dc4..4b78d25b3b40bc1d427f54888aa82b83f839baab 100644 (file)
--- a/log.c
+++ b/log.c
@@ -195,24 +195,21 @@ void logfile_reopen(void)
        }
 }
 
-static void filtered_fwrite(const char *buf, int len, FILE *f)
+static void filtered_fwrite(FILE *f, const char *buf, int len, int use_isprint)
 {
        const char *s, *end = buf + len;
        for (s = buf; s < end; s++) {
                if ((s < end - 4
-                 && *s == '\\' && s[1] == '0'
+                 && *s == '\\' && s[1] == '#'
                  && isdigit(*(uchar*)(s+2))
                  && isdigit(*(uchar*)(s+3))
                  && isdigit(*(uchar*)(s+4)))
-#if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H
-                || (*(uchar*)s < ' ' && *s != '\t')
-#else
-                || ((!isprint(*(uchar*)s) || *(uchar*)s < ' ') && *s != '\t')
-#endif
-               ) {
+                || (*s != '\t'
+                 && ((use_isprint && !isprint(*(uchar*)s))
+                  || *(uchar*)s < ' '))) {
                        if (s != buf && fwrite(buf, s - buf, 1, f) != 1)
                                exit_cleanup(RERR_MESSAGEIO);
-                       fprintf(f, "\\%04o", *(uchar*)s);
+                       fprintf(f, "\\#%03o", *(uchar*)s);
                        buf = s + 1;
                }
        }
@@ -308,20 +305,20 @@ void rwrite(enum logcode code, char *buf, int len)
                while (iconv(ic_chck, &in_buf,&in_cnt,
                                 &out_buf,&out_cnt) == (size_t)-1) {
                        if (out_buf != convbuf) {
-                               filtered_fwrite(convbuf, out_buf - convbuf, f);
+                               filtered_fwrite(f, convbuf, out_buf - convbuf, 0);
                                out_buf = convbuf;
                                out_cnt = sizeof convbuf - 1;
                        }
                        if (errno == E2BIG)
                                continue;
-                       fprintf(f, "\\%04o", *(uchar*)in_buf++);
+                       fprintf(f, "\\#%03o", *(uchar*)in_buf++);
                        in_cnt--;
                }
                if (out_buf != convbuf)
-                       filtered_fwrite(convbuf, out_buf - convbuf, f);
+                       filtered_fwrite(f, convbuf, out_buf - convbuf, 0);
        } else
 #endif
-               filtered_fwrite(buf, len, f);
+               filtered_fwrite(f, buf, len, 1);
 
        if (trailing_CR_or_NL) {
                fputc(trailing_CR_or_NL, f);