From: boone@convex.cl.msu.edu (Dennis Boone)
Newsgroups: comp.infosystems.gopher
Subject: New Items In Gopher (bugfix)
Keywords: newitems gopher directory bugfix
Date: 14 Oct 92 20:16:42 GMT
Organization: Michigan State University, East Lansing

newitems is a perl script which generates a link file listing all items
in a gopher tree modified in the last n days.

This is a bugfix.  Sorry folks.  This revised script should generate
usable link files.

------------------------------------------------------------------------
#!/usr/local/bin/perl
# newitems, boone, 09/30/92
# Generate a link file listing new items in the last n days
# Copyright (C) 1992, Trustees of Michigan State University
#
# Modifications:
# 09/30/92 Boone      Initial coding
# 10/01/92 Boone      Added ability to exclude individual directories
# 10/14/92 Boone      Fixed bug in generation of Path= field
# End Modifications

# Extract path part of pathname

sub path
{
	local($path) = @_;
	local($pathsep) = rindex($path, "/");
	if ($pathsep < 0)
	{
		return "";
	}
	else
	{
		$wanted = substr($path, 0, $pathsep+1);
		return $wanted;
	}
}

# Extract filename part of pathname

sub base
{
	local($path) = @_;
	local($pathsep) = rindex($path, "/");
	if ($pathsep < 0)
	{
		return $path;
	}
	else
	{
		$wanted = substr($path, $pathsep+1);
		return $wanted;
	}
}

# Determine whether this item is part of a subtree which wants to be
# announced as a single new entry if any file in it has changed.  <pant>
# Example: /news/newspapers/state_news contains a file called .topnew,
# indicating that any file in the state news subtree will cause the
# /news/newspapers/state_news entry to be listed once in the new items
# list.

sub skip
{
	local(@args) = @_;
	foreach $i (@topnew)
	{
		if (index($args[0], $i) == 0)
		{
			$toplist{$i} = $args[0];
			return 1;
		}
		else
		{
		}
	} 
	return 0;
}

# Write a link file entry

sub writelink
{
	local($line, $path) = @_;
	local(@fields) = split(/\t/, $line);
	local($name) = substr($fields[0], 1);
	local($type) = substr($fields[0], 0, 1);
	print LF "Name=$name\nType=$type\nPath=$type$path\nHost=$host\nPort=$port\n\n";
}

# The real code

$[ = 0;
if ($#ARGV < 3)
{
	print STDERR "Usage: newitems  path days host port\n";
	exit(1);
}

open(LF, ">.newlinks") || die "Unable to create .newlinks\n";
chdir($ARGV[0]);
chop($here = `pwd`);
$days = $ARGV[1];
$host = $ARGV[2];
$port = $ARGV[3];

@topnew = `find . -name .topnew -print`;
foreach $i (@topnew)
{
	$i = &path($i);
}
open(NF, "find . -mtime $days -type f -print | grep -v .cap |") || 
	die "Unable to spawn find\n";
while (<NF>)
{
	next if /\.cap/;
	next if /\.ts/;
	next if /\.bin/;
	chop;
	$path = &path($_);
	$base = &base($_);
	next if ($base =~ /^\./);
	chdir($path) || die "chdir($path) died: $!\n";
	if (! -f ".nonew")
	{
		@lines = `/usr/local/etc/gopherls .`;
		foreach $i (@lines)
		{
			chop($i); chop($i);
			@fields = split(/\t/, $i);
			$thisname = substr($fields[1], 2);
			if ($thisname eq $base)
			{
				if (! &skip($_))
				{
					&writelink($i, $_);
				}
			}
			undef(@fields);
		}
		undef(@lines);
	}
	chdir($here) || die "chdir($here) died: $!\n";
}
foreach $i (keys %toplist)
{
	chop($i);
	$base = &base($i);
	chdir($i) || die "chdir($path) died: $!\n";
	chdir("..") || die "chdir(..) died: $!\n";
	@lines = `/usr/local/etc/gopherls .`;
	foreach $j (@lines)
	{
		chop($j); chop($j);
		@fields = split(/\t/, $j);
		$thisname = substr($fields[1], 2);
		if ($thisname eq $base)
		{
			&writelink($j, $i);
		}
		undef(@fields);
	}
	undef(@lines);
	chdir($here) || die "chdir($here) died: $!\n";
}
close(NF);
close(LF);
--------------------------------------------------------------------------
--
 == If you choose not to decide, you still have made a choice. ==