Convert Perl scripts to awk(1).

This commit is contained in:
Ruslan Ermilov 2002-05-24 11:03:41 +00:00
parent 3af4dcb223
commit 08198a0e3e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97239
4 changed files with 148 additions and 107 deletions

View File

@ -647,11 +647,11 @@ release.9:
sh ${.CURDIR}/${TARGET_ARCH}/dokern.sh ${FDSIZE} < GENERIC > BOOTMFS && \
[ -r GENERIC.hints ] && cp GENERIC.hints BOOTMFS.hints
.if exists(${.CURDIR}/${TARGET}/drivers.conf)
@perl ${.CURDIR}/scripts/driver-remove.pl \
@awk -f ${.CURDIR}/scripts/driver-remove.awk \
${.CURDIR}/${TARGET}/drivers.conf \
${.CURDIR}/../sys/${TARGET}/conf/BOOTMFS
@mkdir -p ${RD}/mfsfd/stand/modules
@perl ${.CURDIR}/scripts/driver-copy2.pl \
@awk -f ${.CURDIR}/scripts/driver-copy2.awk \
${.CURDIR}/${TARGET}/drivers.conf \
${RD}/trees/base/boot/kernel ${RD}/mfsfd/stand/modules
.endif

View File

@ -0,0 +1,96 @@
#!/usr/bin/awk -f
#
# Copyright (c) 2000 "HOSOKAWA, Tatsumi" <hosokawa@FreeBSD.org>
# Copyright (c) 2002 Ruslan Ermilov <ru@FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$
#
function usage()
{
print "usage: driver-copy2.awk config_file src_ko_dir dst_ko_dir" > "/dev/stderr";
exit 1;
}
function err(eval, fmt, what)
{
printf "driver-copy2.awk: " fmt ": %s\n", what, ERRNO > "/dev/stderr";
exit eval;
}
function errx(eval, fmt, what)
{
printf "driver-copy2.awk: " fmt "\n", what > "/dev/stderr";
exit eval;
}
function readconfig(config)
{
while ((getline < config) > 0) {
sub("#.*$", "");
if (split(gensub(/^(\w+)[ \t]+(\w+)[ \t]+([0-9]+)[ \t]+(\w+)[ \t]+\"(.*)\"[ \t]*$/,
"\\1#\\2#\\3#\\4#\\5", "g"), arg, "#") == 5) {
flp[arg[2]] = arg[3];
dsc[arg[2]] = arg[5];
}
}
if (ERRNO)
err(1, "reading %s", config);
close(config);
}
BEGIN {
if (ARGC != 4)
usage();
config = ARGV[1];
srcdir = ARGV[2];
dstdir = ARGV[3];
readconfig(config);
if (system("test -d " srcdir) != 0)
errx(1, "cannot find %s directory", srcdir);
if (system("test -d " dstdir) != 0)
errx(1, "cannot find %s directory", dstdir);
for (f in flp) {
if (flp[f] == 1) {
print f ": There's nothing to do with driver on first floppy." > "/dev/stderr";
} else if (flp[f] == 2) {
srcfile = srcdir "/" f ".ko";
dstfile = dstdir "/" f ".ko";
dscfile = dstdir "/" f ".dsc";
print "Copying " f ".ko to " dstdir > "/dev/stderr";
if (system("cp " srcfile " " dstfile) != 0)
exit 1;
printf "%s", dsc[f] > dscfile;
close(dscfile);
} else if (flp[f] == 3) {
# third driver floppy (not yet implemented)
errx(1, "%s: 3rd driver floppy support is not implemented", f);
}
}
}

View File

@ -1,78 +0,0 @@
#!/usr/bin/perl
#
# Copyright (c) 2000 "HOSOKAWA, Tatsumi" <hosokawa@FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$
#
if ($#ARGV != 2) {
print STDERR "usage: driver-copy.pl config_file src_ko_dir dst_ko_dir\n";
exit 1;
}
$config = $ARGV[0];
$srcdir = $ARGV[1];
$dstdir = $ARGV[2];
open CONFIG, "< $config" or die "Cannot open $config.\n";
while (<CONFIG>) {
s/#.*$//;
if (/^(\w+)\s+(\w+)\s+(\d+)\s+(\w+)\s+\"(.*)\"\s*$/) {
$flp{$2} = $3;
$dsc{$2} = $5;
}
}
close CONFIG;
-d $srcdir or die "Cannot find $srcdir directory.\n";
-d $dstdir or die "Cannot find $dstdir directory.\n";
undef $/;
foreach $f (sort keys %flp) {
if ($flp{$f} == 1) {
print STDERR "$f: There's nothing to do with driver on first floppy.\n";
}
elsif ($flp{$f} == 2) {
$srcfile = $srcdir . '/' . $f . '.ko';
$dstfile = $dstdir . '/' . $f . '.ko';
$dscfile = $dstdir . '/' . $f . '.dsc';
print STDERR "Copying $f.ko to $dstdir\n";
open SRC, "< $srcfile" or die "Cannot open $srcfile\n";
$file = <SRC>;
close SRC;
open DST, "> $dstfile" or die "Cannot open $dstfile\n";
print DST $file;
close DST;
open DSC, "> $dscfile" or die "Cannot open $dscfile\n";
print DSC $dsc{$f};
close DSC;
}
elsif ($flp{$f} == 3) {
# third driver floppy (currently not implemnted yet...)
print STDERR "3rd driver floppy support has not implemented yet\n";
exit 1;
}
}

View File

@ -1,6 +1,7 @@
#!/usr/bin/perl
#!/usr/bin/awk -f
#
# Copyright (c) 2000 "HOSOKAWA, Tatsumi" <hosokawa@FreeBSD.org>
# Copyright (c) 2002 Ruslan Ermilov <ru@FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -27,37 +28,59 @@
# $FreeBSD$
#
if ($#ARGV != 1) {
print STDERR "usage: driver-remove.pl config_file BOOTMFS\n";
exit 1;
function usage()
{
print "usage: driver-remove.awk config_file BOOTMFS" > "/dev/stderr";
exit 1;
}
$config = $ARGV[0];
$bootmfs = $ARGV[1];
function err(eval, fmt, what)
{
printf "driver-remove.awk: " fmt ": %s\n", what, ERRNO > "/dev/stderr";
exit eval;
}
open CONFIG, "< $config" or die "Cannot open $config.\n";
while (<CONFIG>) {
s/#.*$//;
if (/^(\w+)\s+(\w+)\s+(\d+)\s+(\w+)\s+\"(.*)\"\s*$/) {
if ($4 eq "options") {
$options{$1} = 1;
} else {
$drivers{$1} = 1;
function readconfig(config)
{
while ((getline < config) > 0) {
sub("#.*$", "");
if (split(gensub(/^(\w+)[ \t]+(\w+)[ \t]+([0-9]+)[ \t]+(\w+)[ \t]+\"(.*)\"[ \t]*$/,
"\\1#\\2#\\3#\\4#\\5", "g"), arg, "#") == 5) {
if (arg[4] == "options")
options[arg[1]] = 1;
else
drivers[arg[1]] = 1;
}
}
}
if (ERRNO)
err(1, "reading %s", config);
close(config);
}
close CONFIG;
open BOOTMFS, "< $bootmfs" or die "Cannot open $bootmfs.\n";
while (<BOOTMFS>) {
next if (/^device\s+(\w+)/ && $drivers{$1});
next if (/^options\s+(\w+)/ && $options{$1});
push @bootmfs, $_;
}
close BOOTMFS;
BEGIN {
if (ARGC != 3)
usage();
open BOOTMFS, "> $bootmfs" or die "Cannot open $bootmfs.\n";
foreach (@bootmfs) {
print BOOTMFS;
config = ARGV[1];
bootmfs = ARGV[2];
readconfig(config);
lines = 0;
while ((getline < bootmfs) > 0) {
if (/^device[ \t]+\w+/ &&
gensub(/^device[ \t]+(\w+).*$/, "\\1", "g") in drivers)
continue;
if (/^options[ \t]+\w+/ &&
gensub(/^options[ \t]+(\w+).*$/, "\\1", "g") in options)
continue;
line[lines++] = $0;
}
if (ERRNO)
err(1, "reading %s", bootmfs);
close(bootmfs);
printf "" > bootmfs;
for (i = 0; i < lines; i++)
print line[i] >> bootmfs;
close(bootmfs);
}
close BOOTMFS;