add --dry-run like gnu patch.

This commit is contained in:
skd 2005-03-25 23:00:55 +00:00
parent b279845eed
commit 4f9669ed8d
4 changed files with 23 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: common.h,v 1.16 2003/07/30 08:51:55 itojun Exp $ */
/* $NetBSD: common.h,v 1.17 2005/03/25 23:00:55 skd Exp $ */
/*
* Copyright (c) 1988, Larry Wall
@ -90,6 +90,9 @@ typedef int LINENUM; /* must be signed */
EXT int Argc; /* guess */
EXT char **Argv;
/* TRUE if -C was specified on command line. */
EXT int check_only;
EXT struct stat filestat; /* file statistics area */
EXT mode_t filemode INIT(0644);

View File

@ -1,4 +1,4 @@
.\" $NetBSD: patch.1,v 1.9 2003/01/06 12:48:06 wiz Exp $ -*- nroff -*-
.\" $NetBSD: patch.1,v 1.10 2005/03/25 23:00:55 skd Exp $ -*- nroff -*-
.rn '' }`
.de Sh
.br
@ -226,6 +226,11 @@ forces
.I patch
to interpret the patch file as a context diff.
.TP 5
.B \-C or \-\-dry\-run
causes
.I patch
to report what would be done, but not to actully modify any files or create any rejects.
.TP 5
.B \-d or \-\-directory
causes
.I patch

View File

@ -1,4 +1,4 @@
/* $NetBSD: patch.c,v 1.22 2004/12/09 18:06:10 mycroft Exp $ */
/* $NetBSD: patch.c,v 1.23 2005/03/25 23:00:55 skd Exp $ */
/* patch - a program to apply diffs to original files
*
@ -25,7 +25,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: patch.c,v 1.22 2004/12/09 18:06:10 mycroft Exp $");
__RCSID("$NetBSD: patch.c,v 1.23 2005/03/25 23:00:55 skd Exp $");
#endif /* not lint */
#include "INTERN.h"
@ -83,6 +83,8 @@ main(int argc, char *argv[])
myuid = getuid();
check_only = FALSE;
/* Cons up the names of the temporary files. */
{
/* Directory for temporary files. */
@ -398,10 +400,10 @@ decode_long_option(char *opt)
*/
static struct option options[] = {
{ "batch", 't' },
{ "check", 'C' },
{ "context", 'c' },
{ "debug", 'x' },
{ "directory", 'd' },
{ "dry-run", 'C' },
{ "ed", 'e' },
{ "force", 'f' },
{ "forward", 'N' },
@ -477,6 +479,9 @@ exclusive\n");
case 'c':
diff_type = CONTEXT_DIFF;
break;
case 'C':
check_only = TRUE;
break;
case 'd':
if (!*++s)
s = nextarg();

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.20 2004/10/30 21:52:09 dsl Exp $ */
/* $NetBSD: util.c,v 1.21 2005/03/25 23:00:55 skd Exp $ */
/*
* Copyright (c) 1988, Larry Wall
@ -24,7 +24,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: util.c,v 1.20 2004/10/30 21:52:09 dsl Exp $");
__RCSID("$NetBSD: util.c,v 1.21 2005/03/25 23:00:55 skd Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -51,6 +51,9 @@ move_file(char *from, char *to)
size_t i;
int fromfd;
if ( check_only == TRUE )
return(0);
/* to stdout? */
if (strEQ(to, "-")) {