]> sjero.net Git - wget/commitdiff
[svn] Slightly reduce the code repetition between two loops in
authorhniksic <devnull@localhost>
Thu, 5 May 2005 16:39:19 +0000 (09:39 -0700)
committerhniksic <devnull@localhost>
Thu, 5 May 2005 16:39:19 +0000 (09:39 -0700)
copy_and_escape.

src/ChangeLog
src/log.c

index 7a3c70d1c74fc9b930383b6dc1567f93311a2793..e270f2781803f00c958426233c8416c6c8171c81 100644 (file)
@@ -1,3 +1,8 @@
+2005-05-05  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * log.c (copy_and_escape): Slightly reduce code repetition between
+       the two loops.
+
 2005-05-05  Charles C.Fu  <ccwf@bacchus.com>
 
        * utils.c (proclist): Strip leading slash when calling fnmatch
index 196325c93428aaab03dc59595679d1d9699598e3..2a9d586372ebbc85e5aaa4537ce1662493acc7c8 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -618,11 +618,7 @@ log_dump_context (void)
 /* String escape functions. */
 
 /* Return the number of non-printable characters in SOURCE.
-
-   Non-printable characters are determined as per safe-ctype.h,
-   i.e. the non-printable characters of the "C" locale.  This code is
-   meant to be used to protect the user from binary characters in
-   (normally ASCII) server messages. */
+   Non-printable characters are determined as per safe-ctype.c.  */
 
 static int
 count_nonprint (const char *source)
@@ -639,21 +635,21 @@ count_nonprint (const char *source)
 
    Non-printable refers to anything outside the non-control ASCII
    range (32-126) which means that, for example, CR, LF, and TAB are
-   considered non-printable along with ESC and other control chars.
-   This is by design: it makes sure that messages from remote servers
-   cannot be used to deceive the users by mimicking Wget's output.
-   Disallowing non-ASCII characters is another necessary security
-   measure, which makes sure that remote servers cannot garble the
-   screen or guess the local charset and perform homographic attacks.
-
-   Of course, the above means that escnonprint must only be used in
-   decidedly ASCII-only context, such as when printing host names,
-   responses from HTTP headers, messages coming from FTP servers, and
-   the like.
-
-   ESCAPE is the character used to introduce the escape sequence.
-   BASE should be the base of the escape sequence, and must be either
-   8 for octal or 16 for hex.
+   considered non-printable along with ESC, BS, and other control
+   chars.  This is by design: it makes sure that messages from remote
+   servers cannot be easily used to deceive the users by mimicking
+   Wget's output.  Disallowing non-ASCII characters is another
+   necessary security measure, which makes sure that remote servers
+   cannot garble the screen or guess the local charset and perform
+   homographic attacks.
+
+   Of course, the above mandates that escnonprint only be used in
+   contexts expected to be ASCII, such as when printing host names,
+   URL components, HTTP headers, FTP server messages, and the like.
+
+   ESCAPE is the leading character of the escape sequence.  BASE
+   should be the base of the escape sequence, and must be either 8 for
+   octal or 16 for hex.
 
    DEST must point to a location with sufficient room to store an
    encoded version of SOURCE.  */
@@ -661,19 +657,19 @@ count_nonprint (const char *source)
 static void
 copy_and_escape (const char *source, char *dest, char escape, int base)
 {
-  const char *from;
-  char *to;
+  const char *from = source;
+  char *to = dest;
+  unsigned char c;
 
-  /* Copy the string from SOURCE to DEST, escaping non-printable chars. */
+  /* Copy chars from SOURCE to DEST, escaping non-printable ones. */
   switch (base)
     {
     case 8:
-      for (from = source, to = dest; *from; from++)
-       if (ISPRINT (*from))
-         *to++ = *from;
+      while ((c = *from++) != '\0')
+       if (ISPRINT (c))
+         *to++ = c;
        else
          {
-           const unsigned char c = *from;
            *to++ = escape;
            *to++ = '0' + (c >> 6);
            *to++ = '0' + ((c >> 3) & 7);
@@ -681,12 +677,11 @@ copy_and_escape (const char *source, char *dest, char escape, int base)
          }
       break;
     case 16:
-      for (from = source, to = dest; *from; from++)
-       if (ISPRINT (*from))
-         *to++ = *from;
+      while ((c = *from++) != '\0')
+       if (ISPRINT (c))
+         *to++ = c;
        else
          {
-           const unsigned char c = *from;
            *to++ = escape;
            *to++ = XNUM_TO_DIGIT (c >> 4);
            *to++ = XNUM_TO_DIGIT (c & 0xf);