From a5d9e758793e4799e24103abe0d38269814cab97 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 21 Nov 2004 10:59:32 +0000 Subject: [PATCH] Implement Ian's suggestion that nntpid should output via $PAGER by default, partly for convenience and partly as a guard against disruptive escape sequences in the article. Disabled if its stdout isn't a terminal, and also explicitly disableable by -d. git-svn-id: svn://svn.tartarus.org/sgt/utils@4863 cda61777-01e9-0310-a592-d414129be87e --- nntpid/nntpid | 24 ++++++++++++++++++++---- nntpid/nntpid.but | 22 ++++++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/nntpid/nntpid b/nntpid/nntpid index 2966964..13e0732 100755 --- a/nntpid/nntpid +++ b/nntpid/nntpid @@ -23,9 +23,10 @@ use Socket; use FileHandle; $usage = - "usage: nntpid [ -v ] \n" . - " or: nntpid [ -v ] \n" . + "usage: nntpid [ -v ] [ -d ] \n" . + " or: nntpid [ -v ] [ -d ] \n" . "where: -v verbose (print interaction with news server)\n" . + " -d direct output (don't consider using PAGER)\n" . " also: nntpid --version report version number\n" . " nntpid --help display this help text\n" . " nntpid --licence display (MIT) licence text\n"; @@ -53,9 +54,13 @@ $licence = "CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n" . "SOFTWARE.\n"; +$pager = 1; +$verbose = 0; + while ($ARGV[0] =~ /^-(.+)$/) { shift @ARGV; - $verbose=1, next if $1 eq "v"; + $verbose = 1, next if $1 eq "v"; + $pager = 0, next if $1 eq "d"; if ($1 eq "-help") { print STDERR $usage; exit 0; @@ -106,16 +111,27 @@ $code =~ /^2\d\d/ or die "no initial greeting from server\n"; # some servers require a GROUP before an ARTICLE command &docmd("GROUP $group"); &docmd("ARTICLE $mid"); +$art = ""; while (1) { &getline; s/[\r\n]//g; last if /^\.$/; s/^\.//; - print STDOUT "$_\n"; + $art .= "$_\n"; } &docmd("QUIT"); close S; +if ($pager and -t STDOUT) { + $pagername = $ENV{"PAGER"}; + $pagername = "more" unless defined $pagername; + open PAGER, "| $pagername"; + print PAGER $art; + close PAGER; +} else { + print $art; +} + sub putline { my ($line) = @_; print STDERR ">>> $line\n" if $verbose; diff --git a/nntpid/nntpid.but b/nntpid/nntpid.but index f1d89ee..7f21512 100644 --- a/nntpid/nntpid.but +++ b/nntpid/nntpid.but @@ -8,10 +8,10 @@ \U SYNOPSIS -\c nntpid [ -v ] message-id -\e bbbbbb bb iiiiiiiiii -\c nntpid [ -v ] newsgroup-name article-number -\e bbbbbb bb iiiiiiiiiiiiii iiiiiiiiiiiiii +\c nntpid [ -v ] [ -d ] message-id +\e bbbbbb bb bb iiiiiiiiii +\c nntpid [ -v ] [ -d ] newsgroup-name article-number +\e bbbbbb bb bb iiiiiiiiiiiiii iiiiiiiiiiiiii \U DESCRIPTION @@ -29,6 +29,15 @@ newsgroup. Article numbers are assigned internally by a particular news server, so they will be different on other servers carrying the same group. +By default, \cw{nntpid} will try to display the article using a +pager (\cw{more}(1), unless you have specified an alternative in the +environment variable \cw{PAGER}). This is partly for convenience, +and partly a mild security measure: it gives you some protection +against the news article potentially containing control sequences +that cause unexpected behaviour in your terminal. If \cw{nntpid} +detects that its standard output is not a terminal, however, it will +bypass the pager and just write out the article directly. + \U ARGUMENTS If you specify one argument, \cw{nntpid} assumes it is a Message-ID. @@ -46,6 +55,11 @@ as a newsgroup name, and the second as an article number. \dd Verbose mode. In this mode, \cw{nntpid} will log its entire conversation with the news server on standard error. +\dt \cw{-d} + +\dd Direct output. In this mode, \cw{nntpid} will write the article +straight to standard output without bothering to try using a pager. + \U AUTHENTICATION Currently, the only form of authentication supported by \cw{nntpid} -- 2.11.0