Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/cron make consistent escape sequence handling



details:   https://anonhg.NetBSD.org/src/rev/5cce55281eda
branches:  trunk
changeset: 513772:5cce55281eda
user:      yamt <yamt%NetBSD.org@localhost>
date:      Mon Aug 13 06:54:58 2001 +0000

description:
make consistent escape sequence handling
between commandline and command input.

pointed by Christoph Badura <bad%netbsd.org@localhost>

diffstat:

 usr.sbin/cron/do_command.c |  40 +++++++++++++++++++++-------------------
 1 files changed, 21 insertions(+), 19 deletions(-)

diffs (71 lines):

diff -r 3104c6412a2b -r 5cce55281eda usr.sbin/cron/do_command.c
--- a/usr.sbin/cron/do_command.c        Mon Aug 13 06:10:09 2001 +0000
+++ b/usr.sbin/cron/do_command.c        Mon Aug 13 06:54:58 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: do_command.c,v 1.8 2001/08/03 04:10:51 yamt Exp $      */
+/*     $NetBSD: do_command.c,v 1.9 2001/08/13 06:54:58 yamt Exp $      */
 
 /* Copyright 1988,1990,1993,1994 by Paul Vixie
  * All rights reserved
@@ -22,7 +22,7 @@
 #if 0
 static char rcsid[] = "Id: do_command.c,v 2.12 1994/01/15 20:43:43 vixie Exp ";
 #else
-__RCSID("$NetBSD: do_command.c,v 1.8 2001/08/03 04:10:51 yamt Exp $");
+__RCSID("$NetBSD: do_command.c,v 1.9 2001/08/13 06:54:58 yamt Exp $");
 #endif
 #endif
 
@@ -133,33 +133,35 @@
         * command, and subsequent characters are the additional input to
         * the command.  Subsequent %'s will be transformed into newlines,
         * but that happens later.
-        *
-        * If there are escaped %'s, remove the escape character.
         */
        /*local*/{
                int escaped = FALSE;
                int ch;
                char *p;
 
-               for (input_data = p = e->cmd;  (ch = *input_data) != '\0'; 
-                   input_data++, p++) {
-                       if (p != input_data)
-                               *p = ch;
+               /* translation:
+                *      \% -> %
+                *      %  -> end of command, following is command input.
+                *      \x -> \x        for all x != %
+                */
+               input_data = p = e->cmd;
+               while ((ch = *input_data++) != '\0') {
                        if (escaped) {
-                               if (ch == '%' || ch == '\\')
-                                       *--p = ch;
-                               escaped = FALSE;
-                               continue;
+                               if (ch != '%')
+                                       *p++ = '\\';
+                       } else {
+                               if (ch == '%') {
+                                       break;
+                               }
                        }
-                       if (ch == '\\') {
-                               escaped = TRUE;
-                               continue;
-                       }
-                       if (ch == '%') {
-                               input_data++;
-                               break;
+
+                       if (!(escaped = (ch == '\\'))) {
+                               *p++ = ch;
                        }
                }
+               if (escaped)
+                       *p++ = '\\';
+
                *p = '\0';
        }
 



Home | Main Index | Thread Index | Old Index