From 3a2b9d8c2b6b27a7837d6feb38628eeef89a4c79 Mon Sep 17 00:00:00 2001 From: jtc Date: Wed, 27 Oct 1993 17:52:30 +0000 Subject: [PATCH] Added -print0 (like GNU find). This will allow file names that contain newlines to be correctly interpreted by programs that process find output. --- usr.bin/find/extern.h | 3 ++- usr.bin/find/find.1 | 11 ++++++++--- usr.bin/find/find.h | 4 ++-- usr.bin/find/function.c | 20 +++++++++++++++++++- usr.bin/find/option.c | 3 ++- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h index 9ebc72ebf9f8..35102058dcff 100644 --- a/usr.bin/find/extern.h +++ b/usr.bin/find/extern.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)extern.h 5.2 (Berkeley) 5/24/91 - * $Id: extern.h,v 1.2 1993/08/01 18:16:18 mycroft Exp $ + * $Id: extern.h,v 1.3 1993/10/27 17:52:30 jtc Exp $ */ #include @@ -65,6 +65,7 @@ PLAN *c_nogroup __P((void)); PLAN *c_nouser __P((void)); PLAN *c_perm __P((char *)); PLAN *c_print __P((void)); +PLAN *c_print0 __P((void)); PLAN *c_prune __P((void)); PLAN *c_size __P((char *)); PLAN *c_type __P((char *)); diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1 index 98e79299c755..bc141779c97f 100644 --- a/usr.bin/find/find.1 +++ b/usr.bin/find/find.1 @@ -33,7 +33,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)find.1 6.29 (Berkeley) 7/29/91 -.\" $Id: find.1,v 1.3 1993/08/01 07:32:54 mycroft Exp $ +.\" $Id: find.1,v 1.4 1993/10/27 17:52:37 jtc Exp $ .\" .Dd July 29, 1991 .Dt FIND 1 @@ -253,13 +253,18 @@ the bits in the mode exactly match the file's mode bits. Note, the first character of a symbolic mode may not be a dash (``\-''). .It Ic -print This primary always evaluates to true. -It prints the pathname of the current file to standard output. +It prints the pathname of the current file to standard output, followed +by a newline character. The expression is appended to the user specified expression if neither .Ic -exec , .Ic -ls -or +nor .Ic \&-ok is specified. +.It Ic -print0 +This primary always evaluates to true. +It prints the pathname of the current file to standard output, followed +by a null character. .It Ic -prune This primary always evaluates to true. It causes diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h index 7d39ecff9bfa..3eb3b2c30184 100644 --- a/usr.bin/find/find.h +++ b/usr.bin/find/find.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)find.h 5.8 (Berkeley) 5/24/91 - * $Id: find.h,v 1.3 1993/08/01 18:16:17 mycroft Exp $ + * $Id: find.h,v 1.4 1993/10/27 17:52:39 jtc Exp $ */ /* node type */ @@ -43,7 +43,7 @@ enum ntype { N_ATIME, N_CLOSEPAREN, N_CTIME, N_DEPTH, N_EXEC, N_EXPR, N_FOLLOW, N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PERM, N_PRINT, - N_PRUNE, N_SIZE, N_TYPE, N_USER, N_XDEV, + N_PRINT0, N_PRUNE, N_SIZE, N_TYPE, N_USER, N_XDEV, }; /* node definition */ diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 2d88f6b08047..d6b5ac10bbed 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -36,7 +36,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)function.c 5.17 (Berkeley) 5/24/91";*/ -static char rcsid[] = "$Id: function.c,v 1.8 1993/09/16 21:41:30 cgd Exp $"; +static char rcsid[] = "$Id: function.c,v 1.9 1993/10/27 17:52:41 jtc Exp $"; #endif /* not lint */ #include @@ -709,6 +709,16 @@ f_print(plan, entry) (void)printf("%s\n", entry->fts_path); return(1); } + +/* ARGSUSED */ +f_print0(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + (void)fputs(entry->fts_path, stdout); + (void)fputc('\0', stdout); + return(1); +} PLAN * c_print() @@ -717,6 +727,14 @@ c_print() return(palloc(N_PRINT, f_print)); } + +PLAN * +c_print0() +{ + isoutput = 1; + + return(palloc(N_PRINT0, f_print0)); +} /* * -prune functions -- diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c index cbbb9ddea583..2c99154a35b0 100644 --- a/usr.bin/find/option.c +++ b/usr.bin/find/option.c @@ -36,7 +36,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)option.c 5.8 (Berkeley) 6/4/91";*/ -static char rcsid[] = "$Id: option.c,v 1.3 1993/08/01 18:16:08 mycroft Exp $"; +static char rcsid[] = "$Id: option.c,v 1.4 1993/10/27 17:52:44 jtc Exp $"; #endif /* not lint */ #include @@ -84,6 +84,7 @@ OPTION options[] = { "-or", N_OR, c_or, O_ZERO, "-perm", N_PERM, c_perm, O_ARGV, "-print", N_PRINT, c_print, O_ZERO, + "-print0", N_PRINT0, c_print0, O_ZERO, "-prune", N_PRUNE, c_prune, O_ZERO, "-size", N_SIZE, c_size, O_ARGV, "-type", N_TYPE, c_type, O_ARGV,