From nobody Thu May 25 13:25:50 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QRphv16Rwz4V0Fm; Thu, 25 May 2023 13:25:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QRphv0ckMz46QJ; Thu, 25 May 2023 13:25:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685021151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=H9RUfMvDzC7dn5aSq0d4aMaBrH76oeTN4M+BvG4nThE=; b=qTH6Pk2SRd+3gQsr+r9DURA9cW5o1H/8Rqn8fF7MmgLnOTu0zK/VdmXtGtlHuGjNoq2wFf /qZVH+lb9zrObX36VQHZLMWv9nWeurNicHK+/aYDrpJNEZvAsH6vih5CoV4kDf7zqJ0Omy K3feiqHwWX32MjX3tAOVM+t3s7syh51KJ19rxeG8Rma4eYQotkBxlAILLWGFtNbxtKvGRW WFfXBXq/MSOHtVHlQxjfrhepio8+mTqshHJiqILyFzdXZbMKHY5g3Q1PI8kv3qCoWmsB59 /0QFt0lbIBlDxqyAMRyia6iQM/UjF+5JtA/5t8ufbRJS1J1lND/ACagZC44feA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685021151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=H9RUfMvDzC7dn5aSq0d4aMaBrH76oeTN4M+BvG4nThE=; b=VctqNYzsGN+mPBy6UXGuJkR+LJTKKuI8KQFJ0NiVsHyvi0q1OYsITlyu5nlKxvw1UQYbFB Mbvuc73DHqGsjOYvD6Mcav5IZkdfKtiapoy5/vgxDdUBOlXiw/MbtRPi7en187VUr6lunJ zGACxXAam09cCyvUYtMBndk4VIANV2SMHkXSUhy/mk6IzTWmhqoMehm6BO5aeOaBIHkozA IZGriW504lsupzexuw7HU26r5IZnpaeZUK4Ca41zlPnVavC5Q1QKtY6AFi81aI+PD54/Uz 5VdE2qiF1iRnvApAH3Ayi2a+FLlgxgNRjKGMlmIBeSFYe6Doo2qpTfDzta5/pw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685021151; a=rsa-sha256; cv=none; b=SZky/N96iK9BDj1cITeN+WkWMxKwfrrErt2+k9HVi3NXhkAfXSj4q/jP6bQNU6qU2QmYoL DlvQyqPS7910SfjIhoo/l/hB+mGmsyGOV+EqUyJ7sdMCwGrXpuNZdXkXwPdi3pNKsaL1Wu tE7pvWj0apo5MHXPxqD/AOx8O+wUFtD5sLvmGjD6NecDyo6CtmkU1ktReFUFZoaYQNKpjw v9TWxFy2lV6l3yT02xk9nHkW5STug7v9fNf/VRAdlgqC/nB2/M66/tH3781IIeXmXs+yQG llW7stQ7gaVDaQ7T2RbbnfGcYYnOU0aGd9GPa/msYS8NmdjRQ/hXbQ44hUZiJw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QRpht6qZnzRG1; Thu, 25 May 2023 13:25:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34PDPoNR064473; Thu, 25 May 2023 13:25:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34PDPonu064472; Thu, 25 May 2023 13:25:50 GMT (envelope-from git) Date: Thu, 25 May 2023 13:25:50 GMT Message-Id: <202305251325.34PDPonu064472@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: 430d064ba5b0 - main - ctags: Support writing to stdout instead of a file. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 430d064ba5b0cb2e91a26af34c15df48d290e417 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=430d064ba5b0cb2e91a26af34c15df48d290e417 commit 430d064ba5b0cb2e91a26af34c15df48d290e417 Author: Dag-Erling Smørgrav AuthorDate: 2023-05-25 11:55:56 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-05-25 13:22:18 +0000 ctags: Support writing to stdout instead of a file. * Understand "-" to mean stdout as per convention. * Check that the output is a regular file and ignore -u if not, otherwise we might try to rm /dev/stdout. * As a bonus, if -u was specified but the output file does not exist, proceed as if -u had not been specified instead of erroring out. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: cracauer, debdrup Differential Revision: https://reviews.freebsd.org/D40237 --- usr.bin/ctags/ctags.1 | 16 +++++++++++++--- usr.bin/ctags/ctags.c | 23 +++++++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/usr.bin/ctags/ctags.1 b/usr.bin/ctags/ctags.1 index 9b68f669202e..40c502b3ecdd 100644 --- a/usr.bin/ctags/ctags.1 +++ b/usr.bin/ctags/ctags.1 @@ -28,7 +28,7 @@ .\" @(#)ctags.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd June 6, 1993 +.Dd May 23, 2023 .Dt CTAGS 1 .Os .Sh NAME @@ -93,16 +93,26 @@ Place the tag descriptions in a file called .Ar tagsfile . The default behaviour is to place them in a file called .Pa tags . +If +.Ar tagsfile +is +.Dq - , +the tags will be written to standard output instead. .It Fl u Update the specified files in the .Pa tags file, that is, all references to them are deleted, and the new values are appended to the file. -(Beware: this option is implemented in a way which is rather +This is ignored if the tags file does not exist or is not a regular +file (e.g. +.Fl f Ns - +was used to write to standard output). +.Pp +Beware: this option is implemented in a way which is rather slow; it is usually faster to simply rebuild the .Pa tags -file.) +file. .It Fl v An index of the form expected by .Xr vgrind 1 diff --git a/usr.bin/ctags/ctags.c b/usr.bin/ctags/ctags.c index 409b07f5354b..d94b6e87ae1b 100644 --- a/usr.bin/ctags/ctags.c +++ b/usr.bin/ctags/ctags.c @@ -42,11 +42,14 @@ static char sccsid[] = "@(#)ctags.c 8.4 (Berkeley) 2/7/95"; #endif #include +__FBSDID("$FreeBSD$"); + #include +#include #include -__FBSDID("$FreeBSD$"); #include +#include #include #include #include @@ -143,6 +146,9 @@ main(int argc, char **argv) if (!argc) usage(); + if (strcmp(outfile, "-") == 0) + outfile = "/dev/stdout"; + if (!xflag) setlocale(LC_COLLATE, "C"); @@ -164,11 +170,23 @@ main(int argc, char **argv) put_entries(head); else { if (uflag) { + struct stat sb; FILE *oldf; regex_t *regx; - if ((oldf = fopen(outfile, "r")) == NULL) + if ((oldf = fopen(outfile, "r")) == NULL) { + if (errno == ENOENT) { + uflag = 0; + goto udone; + } err(1, "opening %s", outfile); + } + if (fstat(fileno(oldf), &sb) != 0 || + !S_ISREG(sb.st_mode)) { + fclose(oldf); + uflag = 0; + goto udone; + } if (unlink(outfile)) err(1, "unlinking %s", outfile); if ((outf = fopen(outfile, "w")) == NULL) @@ -198,6 +216,7 @@ nextline: fclose(outf); ++aflag; } +udone: if (!(outf = fopen(outfile, aflag ? "a" : "w"))) err(1, "%s", outfile); put_entries(head);