lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple command-line URL's (was: Re: lynx-dev When unhighlighting s


From: Ismael Cordeiro
Subject: Re: Multiple command-line URL's (was: Re: lynx-dev When unhighlighting some highlighted links, lynx draws them incorrectly)
Date: Wed, 17 Mar 1999 07:26:43 -0500 (EST)

On Tue, 16 Mar 1999, Michael Warner wrote:

> > I don't want 'lynx  URL-1 URL-2 [...] URL-N' to be suddenly treated as
> > an error - it works fine as far as I am concerned. But making URL-1 ...
> > URL-N-1 available for 'g' command recall after startup would be a nice
> > touch.
> 
> This gets my vote as the most desirable new feature at the moment. I use a
> utility that extracts URL's from email messages, puts them in a menu/list,
> and launches lynx on a selected URL.

Is it urlview?

> Since I just get presented with a list of 'bare' - and cryptic - URL's, I
> have to keep quitting out of lynx to go back and pick another URL. If I
> could tweak the utility to concatenate all the extracted URL's into one
> 'pseudo-URL', they'd all be available without switching back and forth.

The Perl script below does what you want. I use it with mutt and tin.
However, it can't handle soem URLs properly and in those cases I use
urlview. It would need to be improved. Any Perl experts here?

#!/usr/local/bin/perl5.001/perl
#
#  Purpose: Scans through standard text, looking for any urls (universal
#    resource locater) (common with the world wide web). It extracts any
#    urls it can identify, and hands them (reformated) over to lynx for easy
#    reference, and following.
#
#  Usage:  urls [filename]
#    where filename is the file to scan through for any urls, if one isn't
#    given, stdin will be opened and hunted through (for use primarly with
#    pipes from news/mail readers).
#
#  Written by Scott Seligman (address@hidden)
#

require 'getopts.pl';

&Getopts("aeuh");

if ($opt_h) {
  print<<'EOT';

   To use urls one would generally pipe a body of text to it, but
   alternately, you could specify the body of text to scan via a command
   line argument. From there you'll be prompted with a simple lynx screen
   giving you a choice of all found urls.

   Urls also understand the following command line options:
     * -u -- Don't scan for standard urls
     * -e -- Don't scan for email addresses
     * -a -- Don't scan for article id's
     * -h -- This basic help screen

EOT
  exit 0;
}


$version = "2.2";
$verdate = "7/30/95";

$fn = "/tmp/huntweb.$$.html";
$maxlength = 60;
$found = 0;
$found_art = 0;
$add = 1;

open (WEB, ">$fn");

while ($line = <>) {
  chop $line;
  $line = " " . $line . " "; #.+/
  $found_line = 1;
  while ($found_line == 1) {
    $found_line = 0;
    $url = "";
    if ($line =~ address@hidden(\w+://[\w/\.~\-\:address@hidden)[\W]@ ) {
      if (!($opt_u)) {
        $url = $1;
        $urlkey = $1;
        chop $url if ( substr($url,length($url)-1,1) =~ /\./ );
        ## addition for netcom (to stop using ftp.netcom whenever possible) ##
        #$url =~ address@hidden://address@hidden://localhost/ftp@;            ##
        ## end of netcom addition                                           ##
        if (length($urlkey)>$maxlength) {
          $minlength = $maxlength-6;
          $urlkey =~ /^(.{$minlength}).*(.{5})/;
          $urlkey = $1 . "-" . $2;
        }
        if ($urls{$urlkey} ne undef) {
          if ($urls{$urlkey} ne $url) {
            $urlkey .= $add;
            $add ++;
          }
        }
        $urls{$urlkey} = $url;
        $found = 1;
        $found_line = 1;
      }
    }
    $path = "none";
    if ($line =~ address@hidden(\<[^ address@hidden ]+\>)[\W]@ ) {
      if (!($opt_a)) {
        $artid = $1;
        open NEWSHIST, "/usr/lib/newsbin/maint/newshist \'" .
          $artid . "\' 2> /dev/null |";
        while ($line2 = <NEWSHIST>) {
          chop $line2;
          $path = "/usr/spool/news/" . (split(/[\t ]/,$line2))[2];
          $path =~ address@hidden@/@;
        }
        close NEWSHIST;
        if ($path ne "none") {
          open ARTICLE, $path;
          while ($line2 = <ARTICLE>) {
            chop $line2;
            if ($line2 =~ /Subject: (.*)/) {
              $subject = $1;
              close ARTICLE;
            }
          }
          $subjects{$artid} = $subject;
          $ids{$artid} = $path;
          $found_art = 1;
        }
        $url = $artid;
        $found_line = 1;
      }
    } elsif ($line =~ m/[\W](address@hidden)\W/ ) {
      if (!($opt_e)) {
        $url = $1;
        $urls{$url} = "mailto:$url";;
        $found = 1;
        $found_line = 1;
      }
    }
    $spot = index($line, $url);
    $line = substr($line,0,$spot) . substr($line,$spot+length($url));
  }
}

%types = ("ahttp", "WWW", "b(ftp|file)", "FTP", "cgopher", "Gopher",
          "dmailto", "E-Mail", "z", "Other");

if ($found) {
  print WEB "<HTML>\n\nUrls found:<br>\n<ul>";
  foreach $key (sort(keys %types)) {
    $newkey = substr($key,1);
    $header = 0;
    foreach $url (keys %urls) {
      if ($urls{$url} =~ /^$newkey/i) {
        unless ($header) {
          $header = 1;
          print WEB "<li>$types{$key}<ul>\n";
        }
        print WEB "<li><a href=\"$urls{$url}\">$url</a>\n";
        delete $urls{$url};
      }
    }
    print WEB "</ul>\n" if ($header);
  }
} else {
  print WEB "<HTML>\n\n -- No urls were found. --<br>\n<ul>";
}

if ($found_art) {
  print WEB "<HTML>\n\nArticles found:<br>\n<ul>";
  foreach $id (keys %ids) {
    $id2 = $id;
    $id2 =~ s/\</\&lt /g;
    $id2 =~ s/\>/\&gt /g;
    print WEB "<li>Subject: " . $subjects{$id} . "\n";
    print WEB "   <ul><li> Id: <a href=\"file://localhost" . $ids{$id} .
      "\">" . $id2 . "</a>\n</ul>";
    delete $ids{$url};
  }
  print WEB "</ul>\n" if ($header);
} else {
  print WEB "</ul>\n";
#  print WEB "<HTML>\n\n -- No articles were found. --<br>\n<ul>";
}


print WEB "</ul><br>\n";
print WEB "       <A HREF=",
      "\"file:/u9/seligman/lib/urls/urls.info.html\">urls</A>",
      " v$version ($verdate), by Scott Seligman (<A HREF=",
      "\"mailto:address@hidden";>address@hidden</A>)</HTML>\n";
close (WEB);

$lynx = "";
foreach $dir (split(/:/, $ENV{'PATH'})) {
  if ($lynx eq "") {
    if (-x $dir . "/newlynx") { $lynx = $dir . "/newlynx"; }
    if (-x $dir . "/lynx") { $lynx = $dir . "/lynx"; }
  }
}
if ($lynx eq "") { $lynx = "/usr/local/bin/lynx"; }

system ("$lynx $fn < /dev/tty");

unlink ("$fn");


-- 

       +--------------------------------------------------------------+
       | ISMAEL CORDEIRO            | mailto:address@hidden      |
       | Production sound mixer     | http://www.ismael.cordeiro.com/ |
       | Montréal - Québec - Canada | ftp://ftp.cam.org/users/ismael/ |
       +--------------------------------------------------------------+

reply via email to

[Prev in Thread] Current Thread [Next in Thread]