My shots for same issue... these programs are my first, second and third actual
perl scripts (not counting
test-programs, of course),
respectively.
As for the more minor ones:
autolinker.pl
This thing is nodevertizer's best friend. Um, well, at least an acquaintance. Give it your node's node_id as parameter and feed its body into stdin (ie. ./autolinker.pl 1234567, and, cut-and-paste), and after a while you should see a nice bunch of soft links on your node (and, more importantly, on the nodes you hardlinked to).
*BZZT* I was informed of E2 node autolinker in perl. Somehow I'm not surprised I'm not the first one think of that, but still, I didn't know it was done. I must say that my code is certainly much shorter, with less bloat, but more on user. I think I'll leave it here as slim alternative. BTW, I really think someone should make E2 perl scripts metanode. And no, don't think it's as easy as it sounds... "*.pl" isn't searchable currently :( that makes it one hell of a job to find all the perl thingies by crawling through softlinks.
#!/usr/bin/perl -w
use Socket;
$node_id=shift(@ARGV);
while (<>) {
$urf=$_;
while ($urf =~ /\[(.*?)(?:\|.*?)?\]/) {
$next=$';
$hop=$1;
$hop =~ s/ /+/g;
$hop =~ s/([^A-Za-z+])/"%".sprintf("%02X",ord($1))/ge;
push @node_list,$hop;
$urf=$next;
}
}
for $i (0 .. $#node_list) {
$request=
"GET /?node=$node_list[$i]&lastnode_id=$node_id HTTP/1.0\r\n\r\n";
consock(HTTP,"everything2.com",80)
|| die "can't connect to server!";
hotfh(HTTP);
# print $request;
print HTTP $request;
<HTTP>; # this should make me sleep until something comes out
# while (<HTTP>) { }
# <HTTP> =~ /<HTTP>/m;
close(HTTP);
print "$i/$#node_list\n";
}
sub hotfh {
my $ofh;
$ofh = select $_[0];
$|++;
select $ofh;
}
sub consock {
# SYNTAX: consock(filehandle, address, port)
my ($remote, $port, $iaddr, $paddr, $proto, $fh, $sval);
$fh = $_[0];
$remote = $_[1];
$port = $_[2];
if (!($iaddr = inet_aton($remote))) {
return;
}
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');
socket($fh, PF_INET, SOCK_STREAM, $proto);
$sval = connect($fh, $paddr);
return $sval;
}
E2ify_source.pl
This thing does the same thing countless other scripties, escapes the [ ] < and >, but it also leaves comments unescaped ! Whoa! Innovantion! ... It also collapses tabs.
#!/usr/bin/perl -w
## (perl )?source E2ifier, written in, of course, perl! ;)
## feed perl source in stdin, it will puke E2-ready text to output.
## actually, what makes this anything but your basic E2 escaper is
## that it ignores "literal" comment fields (##), so link off.
## oh, that and of course that it collapses tab-indented code; tab is
## fine for my terminal (especially since it's resizable), but too
## wide for E2.
$tabreplace=" ";
print "<pre>";
while (<STDIN>) {
if (!/^\s*##/) {
s/&/&/g;
s/\[/[/g;
s/\]/]/g;
s/</</g;
s/>/>/g;
}
while (s/^((?:\s*#)?(?:$tabreplace)*)\t/$1$tabreplace/g) { }
print $_;
}
print "</pre>\n";