1#!/bin/sh
2# 
3# Copyright (c) 1997 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
4# All rights reserved.
5#
6# rename sgml/html generated file names to human readable file names
7# 
8# $ cd FAQ
9# $ make FORMATS=html
10# $ html-mv FAQ
11# $ ls
12# FAQ_ACKNOWLEDGMENTS.html
13# FAQ_Any_restrictions_on_how_I_divide_the_disk_up_.html
14# FAQ_Are_there_any_Database_systems_for_FreeBSD_.html
15# FAQ_Are_there_any_commercial_high-performance_X_servers_.html
16# FAQ_Books_on_FreeBSD.html
17# FAQ_Can_FreeBSD_handle_multiport_serial_cards_sharing_irqs_.html
18# [...]
19# 
20# $FreeBSD$
21
22case $# in 0)
23	echo "usage `basename $0` file"
24	exit 1
25esac
26
27file=$1; export file
28
29if [ -f "$file.html" ]; then :
30else
31	echo "$file.html does not exist"
32	exit 1
33fi
34
35# search for title name
36egrep -i '^<title' $file[1-9]*.html |
37	perl -npe 's/<TITLE>[\*\s]*//; s%\s*</TITLE>.*%%;
38	           s/[^a-zA-Z0-9\_\-\.:\n]/_/g' > .list
39
40# create sed commands
41awk -F: '{print "s/" $1 "/'$file'_" $2 ".html/g;"}' .list > .sed
42
43# create mv(1) shell script
44perl -ne 'chop;($a,$b)=split(/:/); 
45	      print qq[rename ("$a", "$ENV{'file'}_$b.html") || ] .
46	            qq[die "rename $a $ENV{'file'}_$b.html:\$\!";\n]' .list > .mv
47
48# replace links
49if [ -f "$file.ln" ]; then
50	perl -i -p .sed $file.ln
51fi
52
53# replace links
54perl -i -p .sed $file*.html
55
56# rename file names
57perl .mv
58
59rm -f .mv .sed .list
60