head 1.20; access; symbols SHTOOL_1_4_0:1.18 SHTOOL_1_3_3:1.16 SHTOOL_1_3_2:1.15 SHTOOL_1_3_1:1.14 SHTOOL_1_3_0:1.14 SHTOOL_1_2_9:1.6 SHTOOL_1_2_8:1.5 SHTOOL_1_2_7:1.5 SHTOOL_1_2_6:1.5 SHTOOL_1_2_5:1.4 SHTOOL_1_2_4:1.4 SHTOOL_1_2_3:1.4 SHTOOL_1_2_2:1.4 SHTOOL_1_2_1:1.3 SHTOOL_1_2_0:1.1.1.2 SHTOOL_1_1_0:1.1.1.1 RSE:1.1.1; locks; strict; comment @# @; 1.20 date 99.07.07.06.43.03; author rse; state dead; branches; next 1.19; 1.19 date 99.07.06.10.17.50; author rse; state Exp; branches; next 1.18; 1.18 date 99.07.01.15.06.56; author rse; state Exp; branches; next 1.17; 1.17 date 99.07.01.13.37.29; author rse; state Exp; branches; next 1.16; 1.16 date 99.06.29.17.35.04; author rse; state Exp; branches; next 1.15; 1.15 date 99.06.28.15.18.44; author rse; state Exp; branches; next 1.14; 1.14 date 99.06.17.14.45.08; author rse; state Exp; branches; next 1.13; 1.13 date 99.06.17.13.52.54; author rse; state Exp; branches; next 1.12; 1.12 date 99.06.17.07.35.08; author rse; state Exp; branches; next 1.11; 1.11 date 99.06.15.07.55.57; author rse; state Exp; branches; next 1.10; 1.10 date 99.06.15.07.49.19; author rse; state Exp; branches; next 1.9; 1.9 date 99.06.15.07.02.44; author rse; state Exp; branches; next 1.8; 1.8 date 99.06.12.14.46.37; author rse; state Exp; branches; next 1.7; 1.7 date 99.06.12.14.08.50; author rse; state Exp; branches; next 1.6; 1.6 date 99.06.02.12.02.10; author rse; state Exp; branches; next 1.5; 1.5 date 99.05.13.11.29.59; author rse; state Exp; branches; next 1.4; 1.4 date 99.05.05.12.15.52; author rse; state Exp; branches; next 1.3; 1.3 date 99.04.29.12.30.12; author rse; state Exp; branches; next 1.2; 1.2 date 99.04.29.11.27.30; author rse; state Exp; branches; next 1.1; 1.1 date 99.04.29.11.19.50; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 99.04.29.11.19.50; author rse; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 99.04.29.11.20.01; author rse; state Exp; branches; next ; desc @@ 1.20 log @*** empty log message *** @ text @#!/sw/bin/perl ## ## shtool.gen -- Generate shtool out of sh.* scripts ## Copyright (c) 1999 Ralf S. Engelschall ## ## This file is part of shtool and free software; you can redistribute ## it and/or modify it under the terms of the GNU General Public ## License as published by the Free Software Foundation; either version ## 2 of the License, or (at your option) any later version. ## ## This file is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, ## USA, or contact Ralf S. Engelschall . ## require 5.000; use strict; # # READ SCRIPTS # my $SCRIPT = {}; my @@scripts = (); my $s; my $code; foreach $s (@@ARGV) { my $name = $s; $name =~ s|^sh\.||; open(FP, "<$s") || die; $code = ''; $code .= $_ while (); close(FP); my $len = length($code); my $oneline = ''; if ($code =~ m|##\s+$name\s+--\s+(.+?)\s*\n|s) { $oneline = $1; } my $usage = ''; if ($code =~ m|##\s+Usage:\s+$name([^\n]*)\n|s) { $usage = $1; $usage =~ s|^\s+||s; $usage =~ s|\s+$||s; } if ($code =~ m|str_usage="\s*([^"]+?)\s*"|s) { $usage = $1; } $code =~ s|^#!/bin/sh\n||s; my $head = ''; 1 while ($code =~ s|^(##\s*\n)|$head .= $1, ''|se || $code =~ s|^(##\s+.*?\n)|$head .= $1, ''|se); $head =~ s|##\s+This file is.+\n##\s+USA.+?\n##\n||s; $code =~ s|\n\n+|\n\n|sg; my ($code1, $code2); if ($code =~ m|^(.+\n)\.\s+\./sh\.common\n(.+)$|s) { ($code1, $code2) = ($1, $2); } else { ($code1, $code2) = (": #NOP\n", $code); } $code1 =~ s|^[\s\n]+||s; $code1 =~ s|[\s\n]+$|\n|s; $code2 =~ s|^[\s\n]+||s; $code2 =~ s|[\s\n]+$|\n|s; $code2 = $head.$code2; push(@@scripts, $name); $SCRIPT->{$name} = {}; $SCRIPT->{$name}->{ONELINE} = $oneline; $SCRIPT->{$name}->{USAGE} = $usage; $SCRIPT->{$name}->{CODE1} = $code1; $SCRIPT->{$name}->{CODE2} = $code2; printf(STDERR "(%s %d/%d bytes)...", $name, length($code), $len); } printf(STDERR "\n"); # # GENERATE OVERVIEW LIST AND USAGE # my $list = ''; my $name; foreach $name (@@scripts) { $list .= sprintf("## %-10s %s\n", $name, $SCRIPT->{$name}->{ONELINE}); } $list =~ s|\n$||s; my $ulist = ''; foreach $name (@@scripts) { my $usage = $SCRIPT->{$name}->{USAGE}; my $usage2 = ''; if ($usage =~ m|^(.{50}.*?)\s+(.+)$|) { ($usage, $usage2) = ($1, $2); } $ulist .= sprintf(" echo ' %-8s %s'\n", $name, $usage); if ($usage2) { $ulist .= sprintf(" echo ' %-8s %s'\n", '', $usage2); } } $ulist =~ s|\n$||s; # # DETERMINE VERSION # my $version = `sh sh.version -l txt -d long VERSION`; $version =~ s|\n$||s; # # GENERATE HEADER OF SCRIPT # print STDOUT <<"EOT"; #!/bin/sh ## ## GNU shtool -- The GNU Portable Shell Tool ## Copyright (c) 1994-1999 Ralf S. Engelschall ## ## See http://www.gnu.org/software/shtool/ for more information. ## See ftp://ftp.gnu.org/gnu/shtool/ for latest version. ## ## Version ${version} ## ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, ## USA, or contact Ralf S. Engelschall . ## ## Notice: Given that you include this file verbatim into your own ## source tree, you are justified in saying that it remains separate ## from your package, and that this way you are simply just using GNU ## shtool. So, in this situation, there is no requirement that your ## package itself is licensed under the GNU General Public License in ## order to take advantage of GNU shtool. ## ## ## Usage: shtool [] [ [] []] ## ## Available commands: ${list} ## if [ \$# -eq 0 ]; then echo "\$0:ERROR: invalid command line" 1>&2 echo "\$0:HINT: run \\`\$0 -h' for usage" 1>&2 exit 1 fi if [ ".\$1" = ".-h" -o ".\$1" = ".--help" ]; then echo "This is shtool, version ${version}" echo "Copyright (c) 1994-1999 Ralf S. Engelschall " echo '' echo "Usage: shtool [] [ [] []]" echo '' echo 'Available global :' echo ' -v, --version display shtool version information' echo ' -h, --help display shtool usage help page (this one)' echo '' echo 'Available [] []:' ${ulist} echo '' exit 0 fi if [ ".\$1" = ".-v" -o ".\$1" = ."--version" ]; then echo "shtool ${version}" exit 0 fi tool=\"\$1\" shift arg_spec="" opt_spec="" gen_tmpfile=no EOT # # INSERT THE FIRST PART OF THE SCRIPT INGREDIENTS # my $oneline; my $usage; print STDOUT <<"EOT"; ## ## DISPATCH INTO SCRIPT PROLOG ## case \$tool in EOT foreach $name (@@scripts) { print STDOUT " $name )\n"; $code = $SCRIPT->{$name}->{CODE1}; $code =~ s|^| |mg; sub mysub { my ($prolog, $code, $epilog) = @@_; $code =~ s|^ ||mg; return $prolog.$code.$epilog; } $code =~ s|(\<\<['"]?EOT['"]?\s*\n)(.+?\n)\s+(EOT)|&mysub($1, $2, $3)|sge; print STDOUT $code; print STDOUT " ;;\n"; } print STDOUT <<"EOT"; * ) echo "\$0:ERROR: unknown command \\`\$tool'" 2>&1 echo "\$0:HINT: run \\`\$0 -h' for usage" 2>&1 exit 1 ;; esac EOT # # INSERT SHARED PART # open(FP, "); close(FP); $common =~ s|^.+?\n\n|\n|s; print STDOUT $common; # # INSERT THE SECOND PART OF THE SCRIPT INGREDIENTS # print STDOUT <<"EOT"; ## ## DISPATCH INTO SCRIPT BODY ## case \$tool in EOT foreach $name (@@scripts) { print STDOUT "$name )\n"; $code = $SCRIPT->{$name}->{CODE2}; $code =~ s|^| |mg; sub mysub { my ($prolog, $code, $epilog) = @@_; $code =~ s|^ ||mg; return $prolog.$code.$epilog; } $code =~ s|(\<\<['"]?EOT['"]?\s*\n)(.+?\n)\s+(EOT)|&mysub($1, $2, $3)|sge; $code =~ s|(IFS='\s*\n)\s+(')|$1$2|sg; print STDOUT $code; print STDOUT " ;;\n"; print STDOUT "\n"; } print STDOUT <<"EOT"; esac exit 0 ##EOF## EOT @ 1.19 log @*** empty log message *** @ text @@ 1.18 log @*** empty log message *** @ text @d51 1 a51 1 if ($code =~ m|str_usage="([^"]+)"|s) { a52 2 $usage =~ s|^\s+||s; $usage =~ s|\s+$||s; @ 1.17 log @*** empty log message *** @ text @d258 1 a258 1 $code =~ s|(IFS='\s+\n)\s+(')|$1$2|sg; @ 1.16 log @*** empty log message *** @ text @d39 1 d82 1 d84 1 @ 1.15 log @*** empty log message *** @ text @d255 1 @ 1.14 log @*** empty log message *** @ text @d63 1 a63 1 if ($code =~ m|^(.+\n)\.\s+sh\.common\n(.+)$|s) { @ 1.13 log @*** empty log message *** @ text @d118 1 a118 1 ## GNU shtool -- The GNU Portable Shell Tool, version ${version} d120 5 a124 1 ## See http://www.gnu.org/software/shtool/ for the latest version. @ 1.12 log @*** empty log message *** @ text @d118 1 a118 1 ## shtool -- Portable Shell Tool, version ${version} d120 1 a120 1 ## See http://www.engelschall.com/sw/shtool/ for latest version. d139 6 a144 7 ## As a special exception to the GNU General Public License, if you ## distribute this file as part of the source tree of another program ## you can include it in unmodified version under the same distribution ## terms that are used for the rest of that program. In other words, ## although this file itself remains covered by the GNU General Public ## License, the program which uses it is not forced to be also licensed ## under the GPL. @ 1.11 log @*** empty log message *** @ text @d40 1 a40 1 my $oneline = 'unknown'; d44 1 a44 1 my $usage = 'unknown'; d96 1 a96 1 if ($usage =~ m|^(.{40}.*?)\s+(.+)$|) { d99 1 a99 1 $ulist .= sprintf(" echo ' %-10s %s'\n", $name, $usage); d101 1 a101 1 $ulist .= sprintf(" echo ' %-10s %s'\n", '', $usage2); d149 1 a149 1 ## Usage: shtool [] [] [] d157 1 a157 1 echo "\$0:HINT: run \\`\$0 -h' for usage" 1>&2 d160 3 a162 2 if [ ".\$1" = ".-h" ]; then echo "Usage: shtool [] []" d164 7 d175 1 a175 1 if [ ".\$1" = ".-v" ]; then d215 1 a215 1 echo "\$0:HINT: run \\`\$0 -h' for usage" 2>&1 @ 1.10 log @*** empty log message *** @ text @d143 3 a145 3 ## although this file itself remains licenced under the GNU General ## Public License, the program which uses it is not forced to be also ## licensed under the GPL. @ 1.9 log @*** empty log message *** @ text @d142 4 a145 3 ## terms that are used for the rest of that program. Nevertheless this ## file itself remains licenced under the GNU General Public License, of ## course. @ 1.8 log @*** empty log message *** @ text @d139 6 a144 9 ## As a special exception to the GNU General Public License, if ## you distribute this program as part of a program that contains ## a configuration script generated by GNU Autoconf or at least is ## distributed under a license which fully conforms to The Open Source ## Definition (see http://www.opensource.org/osd.html), version 1.4, ## or (at your option) any later version, you may include this program ## in unmodified version under the same distribution terms that you ## use for the rest of that program. Nevertheless this program itself ## always stay under the GNU General Public License. @ 1.7 log @*** empty log message *** @ text @d4 16 a19 1 ## Copyright (c) 1999 Ralf S. Engelschall, All Rights Reserved. d60 1 d107 1 a107 1 # DETERMINE LICENSE AND VERSION a108 6 open(FP, ") { $license .= "##$_"; } close(FP); d118 2 a119 2 ## shtool -- Portable Shell Tool ## Copyright (c) 1994-1999 Ralf S. Engelschall, All Rights Reserved. a120 1 ## Version ${version} d123 27 a149 1 ${license} d219 2 a220 1 print STDOUT $_ while (); d222 2 @ 1.6 log @*** empty log message *** @ text @d35 5 d42 3 a44 1 1 while ($code =~ s|^##\s*\n||s || $code =~ s|^##\s+.*?\n||s); d46 12 a57 2 $code =~ s|^[\s\n]+||s; $code =~ s|[\s\n]+$|\n|s; d63 2 a64 1 $SCRIPT->{$name}->{CODE} = $code; d73 1 a73 1 $list .= sprintf("## %-12s %s\n", $name, $SCRIPT->{$name}->{ONELINE}); d110 1 d123 3 a125 1 echo "\$0:Error: Invalid command line" 1>&2 d127 3 a129 5 if [ \$# -eq 0 -o ".\$1" = .-h ]; then echo "\$0:Usage: shtool [] []" echo "" echo "Available commands are:" echo "" d131 2 a132 2 echo "" exit 1 d134 1 a134 1 if [ ".\$1" = .-v ]; then d138 1 a138 1 util=\$1 d140 3 a142 1 case \$util in d147 1 a147 1 # INSERT THE INGREDIENTS OF THE SCRIPT d151 7 d159 27 a185 3 $code = $SCRIPT->{$name}->{CODE}; $oneline = $SCRIPT->{$name}->{ONELINE}; $usage = $SCRIPT->{$name}->{USAGE}; d187 12 d200 1 d209 1 a209 1 print STDOUT ";;\n"; a211 4 # # GENERATE FOOTER OF SCRIPT # a212 5 * ) echo "\$0:Error: Unknown command" 2>&1 echo "\$0:Hint: Run '\$0 -h' for usage" 2>&1 exit 1 ;; d214 2 @ 1.5 log @*** empty log message *** @ text @d91 1 a91 1 ## Copyright (c) 1999 Ralf S. Engelschall, All Rights Reserved. d97 1 a97 1 ## Usage: shtool [] [] @ 1.4 log @*** empty log message *** @ text @d154 1 a154 1 echo "\$0:Hint: Run '$0 -h' for usage" 2>&1 @ 1.3 log @*** empty log message *** @ text @d36 2 a37 3 $code =~ s|#!/bin/sh\n||sg; $code =~ s|##\n||sg; $code =~ s|##\s+.*?\n||sg; @ 1.2 log @*** empty log message *** @ text @d7 10 a16 2 %SCRIPT = {}; @@scripts = (); d18 1 a18 1 $name = $s; d25 1 a25 1 $oneline = 'unknown'; d29 1 a29 1 $usage = 'unknown'; d50 5 a54 1 $list = ''; d59 1 a59 1 $ulist = ''; d61 2 a62 2 $usage = $SCRIPT->{$name}->{USAGE}; $usage2 = ''; d73 3 d79 1 a79 1 $license .= "##$_"; a81 1 d85 3 d126 5 d149 3 @ 1.1 log @Initial revision @ text @d8 2 a9 2 @@scripts = @@ARGV; foreach $s (@@scripts) { d35 1 d43 1 a43 1 foreach $name (sort(keys(%{$SCRIPT}))) { d48 1 a48 1 foreach $name (sort(keys(%{$SCRIPT}))) { d74 1 a74 1 ## shtool -- Shell Tool d109 1 a109 1 foreach $name (sort(keys(%{$SCRIPT}))) { @ 1.1.1.1 log @Import of shtool 1.1.0 @ text @@ 1.1.1.2 log @Import of shtool 1.2.0 @ text @d8 2 a9 2 @@scripts = (); foreach $s (@@ARGV) { a34 1 push(@@scripts, $name); d42 1 a42 1 foreach $name (@@scripts) { d47 1 a47 1 foreach $name (@@scripts) { d108 1 a108 1 foreach $name (@@scripts) { @