#!/usr/perl5/bin/perl -w # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" require 5.005; use strict; use warnings; use Time::localtime; use File::Basename; our ($cmd, $chapfile, $htmlfile, $dtrace_url, %chaps); $cmd = "mkdemo"; $chapfile = "chapters"; $htmlfile = "index.html"; $dtrace_url = "http://www.sun.com/bigadmin/content/dtrace"; sub chaps_read { my $fatal; my %hash; open(CHAPS, "$chapfile"); while () { my $field; my $value; chop; if (/^#/) { next; } if (!/:/) { if (exists $hash{'name'}) { if (exists $chaps{$hash{'name'}}) { print "$cmd: chapter $hash{'name'} "; print "has two entries.\n"; $fatal = 1; } $chaps{$hash{'name'}} = { %hash }; %hash = (); next; } %hash = (); next; } ($field, $value) = split /:\s*/, $_, 2; if ($field eq "descr") { $value .= " "; } $hash{$field} .= $value; } if ($fatal) { print "$cmd: fatal errors; cannot proceed.\n"; exit; } close (CHAPS); } sub chaps_ascending { $chaps{$a}{number} <=> $chaps{$b}{number}; } sub demo_process { my $chap = $_[0]; my $demo = $_[1]; my $year = localtime->year() + 1900; open DEMO, "<$chap/$demo" or die "Can't open demo $chap/$demo"; open OUT, ">$demo" or die "Can't open $demo"; while () { print OUT $_; if (/Use is subject to license terms/) { print OUT <$outfile" or die "Can't open $outfile."; print HTML "\n\n"; print HTML "Example DTrace Scripts\n"; print HTML "\n\n"; print HTML "\n

\n\n"; print HTML "

\n"; print HTML "
"; print HTML "

DTrace Examples

\n"; print HTML "

\n"; print HTML "Here are the DTrace scripts\n"; print HTML "that are used as examples in the\n"; print HTML "$chaps{book}{title}. "; print HTML "For more information on any one script, follow the link\n"; print HTML "to its corresponding chapter.\n"; print HTML "

\n


\n"; print HTML "\n"; print HTML "\n"; print HTML "\n"; print HTML "\n"; foreach $chap (sort chaps_ascending (keys %chaps)) { my @demos; my $demo; # # Open the directory associated with the chapter. # if ($chap =~ /^book$/) { next; } opendir(DEMOS, $chap) || die("Cannot open directory $chap"); @demos = readdir(DEMOS); closedir(DEMOS); print HTML "\n"; print HTML "\n"; print HTML "\n"; } print HTML "
"; print HTML "ChapterScript
"; print HTML ""; print HTML "Chapter $chaps{$chap}{number}: "; print HTML "$chaps{$chap}{title}\n"; foreach $demo (sort(@demos)) { if ($demo !~ /^[a-z].*\.d$/) { next; } print HTML "\n"; demo_process($chap, $demo); } print HTML "
$demo"; print HTML "
\n


Copyright "; print HTML localtime->year() + 1900; print HTML " Sun Microsystems\n"; print HTML "
\n"; print HTML "\n\n"; close HTML; } chaps_read(); if (basename($ARGV[0]) ne "$htmlfile") { demo_find(basename($ARGV[0])); } else { chaps_process($htmlfile); }