xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/CGI/eg/RunMeFirst (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/usr/local/bin/perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate# Make a world-writeable directory for saving state.
4*0Sstevel@tonic-gate$ww = 'WORLD_WRITABLE';
5*0Sstevel@tonic-gateunless (-w $ww) {
6*0Sstevel@tonic-gate    $u = umask 0;
7*0Sstevel@tonic-gate    mkdir $ww, 0777;
8*0Sstevel@tonic-gate    umask $u;
9*0Sstevel@tonic-gate}
10*0Sstevel@tonic-gate
11*0Sstevel@tonic-gate# Decode the sample image.
12*0Sstevel@tonic-gatefor $uu (<*.uu>) {
13*0Sstevel@tonic-gate    unless (open UU, "<$uu") { warn "Can't open $uu: $!\n"; next }
14*0Sstevel@tonic-gate    while (<UU>) {
15*0Sstevel@tonic-gate        chomp;
16*0Sstevel@tonic-gate	if (/^begin\s+\d+\s+(.+)$/) {
17*0Sstevel@tonic-gate	    $bin = $1;
18*0Sstevel@tonic-gate	    last;
19*0Sstevel@tonic-gate	}
20*0Sstevel@tonic-gate    }
21*0Sstevel@tonic-gate    unless (open BIN, "> $bin") { warn "Can't create $bin: $!\n"; next }
22*0Sstevel@tonic-gate    binmode BIN;
23*0Sstevel@tonic-gate    while (<UU>) {
24*0Sstevel@tonic-gate	chomp;
25*0Sstevel@tonic-gate	last if /^end/;
26*0Sstevel@tonic-gate	print BIN unpack "u", $_;
27*0Sstevel@tonic-gate    }
28*0Sstevel@tonic-gate    close BIN;
29*0Sstevel@tonic-gate    close UU;
30*0Sstevel@tonic-gate}
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gate# Create symlinks from *.txt to *.cgi for documentation purposes.
33*0Sstevel@tonic-gateforeach (<*.cgi>) {
34*0Sstevel@tonic-gate    ($target = $_) =~ s/cgi$/txt/i;
35*0Sstevel@tonic-gate    symlink $_, $target unless -e $target;
36*0Sstevel@tonic-gate}
37