From owner-cvs-all Tue May 7 14:42:47 2002 Delivered-To: cvs-all@freebsd.org Received: from finntroll.newgold.net (durham-ar1-4-64-252-019.durham.dsl-verizon.net [4.64.252.19]) by hub.freebsd.org (Postfix) with SMTP id A9F6737B409 for ; Tue, 7 May 2002 14:42:25 -0700 (PDT) Received: (qmail 9289 invoked by uid 1001); 7 May 2002 21:46:12 -0000 Date: Tue, 7 May 2002 21:46:11 +0000 From: "J. Mallett" To: "J. Mallett" Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/usr.bin/sed main.c sed.1 Message-ID: <20020507214610.GA30780@FreeBSD.ORG> References: <200205071832.g47IWJO26790@freefall.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200205071832.g47IWJO26790@freefall.freebsd.org> User-Agent: Mutt/1.3.27i Organisation: The FreeBSD Project Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, May 07, 2002 at 11:32:18AM -0700, J. Mallett wrote: > jmallett 2002/05/07 11:32:18 PDT > > Modified files: > usr.bin/sed main.c sed.1 > Log: > Add a -i option to sed(1) to do inplace editing, to give us an alternative to > Perl for such things. The key difference to Perl is that a backup extension > *MUST* be specified, because on one hand it isn't recommended to have options > which optionally take a parameter, and on the other hand, it'd be slightly > unpleasent to implement proper handling for that. > > The difference between this and the version posted to developers@ is that it > does handle multiple files in argv after the getopt(3) handling "correctly", > in that the inplace editing-specific code has been moved out to a function, > and that function is used beyond the first file in our linked list. > > This option has been documented as FreeBSD-specific in the manpage. > > Reviewed by: developers@ (got feedback from: des, fanf, sobomax, roberto, > obrien) > MFC after: 1 week Patch to remove the "droppings" as jhb put it, if a nil extension is specified. I'll implement a -I option which takes no arguments on top of this, if it looks kosher. freefall% cvs diff -u cvs diff: Diffing . Index: main.c =================================================================== RCS file: /home/ncvs/src/usr.bin/sed/main.c,v retrieving revision 1.16 diff -u -r1.16 main.c --- main.c 7 May 2002 18:32:18 -0000 1.16 +++ main.c 7 May 2002 21:36:18 -0000 @@ -320,6 +320,8 @@ fname = files->fname; if ((f = fopen(fname, "r")) == NULL) err(1, "%s", fname); + if (inplace != NULL && *inplace == '\0') + unlink(fname); } if ((c = getc(f)) != EOF) { (void)ungetc(c, f); @@ -366,6 +368,8 @@ fname = files->fname; if ((f = fopen(fname, "r")) == NULL) err(1, "%s", fname); + if (inplace != NULL && *inplace == '\0') + unlink(fname); } } (void)ungetc(c, f); @@ -427,8 +431,16 @@ return -1; } - strlcpy(backup, *fname, MAXPATHLEN); - strlcat(backup, inplace, MAXPATHLEN); + if (*inplace == '\0') { + char template[] = "/tmp/sed.XXXXXXXXXX"; + + if (mktemp(template) == NULL) + err(1, "mktemp"); + strlcpy(backup, template, MAXPATHLEN); + } else { + strlcpy(backup, *fname, MAXPATHLEN); + strlcat(backup, inplace, MAXPATHLEN); + } input = open(*fname, O_RDONLY); if (input == -1) cvs diff: Diffing TEST cvs diff: Diffing USD.doc To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message