131067Swosch#!/bin/sh 231067Swosch# 331067Swosch# Copyright (c) 1997 Wolfram Schneider <wosch@FreeBSD.org>. Berlin. 431067Swosch# All rights reserved. 531067Swosch# 631067Swosch# rename sgml/html generated file names to human readable file names 731067Swosch# 831067Swosch# $ cd FAQ 931067Swosch# $ make FORMATS=html 1031067Swosch# $ html-mv FAQ 1131067Swosch# $ ls 1231067Swosch# FAQ_ACKNOWLEDGMENTS.html 1331067Swosch# FAQ_Any_restrictions_on_how_I_divide_the_disk_up_.html 1431067Swosch# FAQ_Are_there_any_Database_systems_for_FreeBSD_.html 1531067Swosch# FAQ_Are_there_any_commercial_high-performance_X_servers_.html 1631067Swosch# FAQ_Books_on_FreeBSD.html 1731067Swosch# FAQ_Can_FreeBSD_handle_multiport_serial_cards_sharing_irqs_.html 1831067Swosch# [...] 1931067Swosch# 2050477Speter# $FreeBSD$ 2131067Swosch 2231067Swoschcase $# in 0) 2331067Swosch echo "usage `basename $0` file" 2431067Swosch exit 1 2531067Swoschesac 2631067Swosch 2731067Swoschfile=$1; export file 2831067Swosch 2931067Swoschif [ -f "$file.html" ]; then : 3031067Swoschelse 3131067Swosch echo "$file.html does not exist" 3231067Swosch exit 1 3331067Swoschfi 3431067Swosch 3531067Swosch# search for title name 3631067Swoschegrep -i '^<title' $file[1-9]*.html | 3731067Swosch perl -npe 's/<TITLE>[\*\s]*//; s%\s*</TITLE>.*%%; 3831067Swosch s/[^a-zA-Z0-9\_\-\.:\n]/_/g' > .list 3931067Swosch 4031067Swosch# create sed commands 4131067Swoschawk -F: '{print "s/" $1 "/'$file'_" $2 ".html/g;"}' .list > .sed 4231067Swosch 4331067Swosch# create mv(1) shell script 4431067Swoschperl -ne 'chop;($a,$b)=split(/:/); 4531067Swosch print qq[rename ("$a", "$ENV{'file'}_$b.html") || ] . 4631067Swosch qq[die "rename $a $ENV{'file'}_$b.html:\$\!";\n]' .list > .mv 4731067Swosch 4831067Swosch# replace links 4931067Swoschif [ -f "$file.ln" ]; then 5031067Swosch perl -i -p .sed $file.ln 5131067Swoschfi 5231067Swosch 5331067Swosch# replace links 5431067Swoschperl -i -p .sed $file*.html 5531067Swosch 5631067Swosch# rename file names 5731067Swoschperl .mv 5831067Swosch 5931067Swoschrm -f .mv .sed .list 60