[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to get a QuickScan scanner to read a whole file in one call?
From: |
David Sanderson |
Subject: |
How to get a QuickScan scanner to read a whole file in one call? |
Date: |
Wed, 25 Jul 2001 12:42:20 -0400 |
I have been having trouble with QuickScan and I am curious if anyone can
point out my mistake, or say for sure whether it is a bug in cons or in
perl. I have tried this with cons-2.3dev and also cons-2.2.0; I'm using
perl5.005_03.
What I'd like to do is have my QuickScan function read the whole file.
The trouble is that I can't seem to read from the SCAN filehandle. When
I do so, perl -w says
Read on closed filehandle <SCAN> at Construct line 14.
The attached shar file contains some files for a small example; an
example session is
Script started on Wed Jul 25 12:29:49 2001
$
$ cons -d
Target out1: dummy.idl
Checking out1
Checking dummy.idl
dummy_scan ENTER: lines found: 1
dummy_scan LEAVE: returning file1.inc
dummy_scan ENTER: lines found: 1
dummy_scan LEAVE: returning file2.inc
Checking file2.inc
dummy_scan ENTER: lines found: 1
dummy_scan LEAVE: returning
Checking file1.inc
dummy_scan ENTER: lines found: 1
dummy_scan LEAVE: returning
Rebuilding out1: out of date.
[perl] &cons::dummy_idl('IMPORT_A', 'dummy.idl', 'out1')
$
Script done on Wed Jul 25 12:29:57 2001
What I'd like is to see it enter and leave dummy.idl just once.
Thanks for any help,
David Sanderson (address@hidden)
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2001-07-25 12:28 EDT by <address@hidden>.
# Source directory was `/usr10/home/dsanderson/sb/test2'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 2225 -rw------- Construct
# 38 -rw-r--r-- dummy.idl
# 16 -rw-r--r-- file1.inc
# 15 -rw-r--r-- file2.inc
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
set `$dir/gettext --version 2>&1`
if test "$3" = GNU
then
gettext_dir=$dir
fi
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f
200112312359.59 -a -f $$.touch; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f
123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a
-f $$.touch; then
shar_touch='touch -am $3$4$5$6$2 "$8"'
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
#
if mkdir _sh17083; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= Construct ==============
if test -f 'Construct' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'Construct' '(file already exists)'
else
$echo 'x -' extracting 'Construct' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'Construct' &&
use strict;
X
# a scanner for QuickScan
#
# I try my best to read the whole file at once, but it won't come in.
# Why does <> return false even though there is more data in the file?
# Could it have something to do with the funky symbol table manipulation
# that cons does?
sub dummy_scan
{
X my @includes = ();
X
X my @lines = ($_);
X push @lines, (<SCAN>);
X
print "dummy_scan ENTER: lines found: ".scalar(@lines)."\n";
X
X for (@lines) {
X if (/^\s*(IMPORT_A|IMPORT_B)\s*(\S+)/ && $2) {
X push(@includes, $2);
X }
X }
X
print "dummy_scan LEAVE: returning @includes\n";
X
X @includes;
}
X
#
# For dependency purposes, this acts like an IDL compiler; called with a
# key (either IMPORT_A or IMPORT_B) , an input filename, and an output
# filename, it reads the files named in ifile on lines beginning with
# the key and copies them into ofile. It also copies any lines it
# doesn't know what to do with.
#
# Example:
# With an input file, 'dummy.idl', containing the lines
#
# IMPORT_A file1.inc
# IMPORT_B file2.inc
#
# and the file 'file1.inc' containing
#
# This is file 1.
#
# and invoking
#
# dummy_idl('IMPORT_A', 'dummy.idl', 'out1');
#
# you'd expect 'out1' to contain
#
# This is file 1.
# IMPORT_B file2.inc
#
X
sub cons::dummy_idl # key, ifile, ofile
{
X my $key = shift(@_);
X my $ifile = shift(@_);
X my $ofile = shift(@_);
X # IMPORT_A file1.inc
X # IMPORT_B file2.inc
X
X open(IFILE, $ifile) || die "could not open $ifile: $!";
X open(OFILE, ">$ofile") || die "could not open $ofile: $!";
X while (<IFILE>) {
X
X if (/^$key (\S+)/) {
X my $kfile = $1;
X open(KFILE, $kfile) || die "could not open $kfile: $!";
X while (<KFILE>) {
X print OFILE $_;
X }
X close(KFILE);
X } else {
X print OFILE $_;
X }
X
X }
X close(IFILE) || die;
X close(OFILE) || die;
}
X
#
# set a default build target
#
X
Default (
X 'out1',
);
X
#
# make the default construction environment
#
X
my $CONS = new cons();
X
QuickScan $CONS (\&dummy_scan, 'dummy.idl');
X
Command $CONS 'out1', 'dummy.idl', qq(
X [perl] &cons::dummy_idl('IMPORT_A', '%<', '%>')
);
SHAR_EOF
(set 20 01 07 25 12 26 25 'Construct'; eval "$shar_touch") &&
chmod 0600 'Construct' ||
$echo 'restore of' 'Construct' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'Construct:' 'MD5 check failed'
65303adb35f6047792da50bd8418d0ef Construct
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Construct'`"
test 2225 -eq "$shar_count" ||
$echo 'Construct:' 'original size' '2225,' 'current size' "$shar_count!"
fi
fi
# ============= dummy.idl ==============
if test -f 'dummy.idl' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'dummy.idl' '(file already exists)'
else
$echo 'x -' extracting 'dummy.idl' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'dummy.idl' &&
IMPORT_A file1.inc
IMPORT_B file2.inc
SHAR_EOF
(set 20 01 07 25 12 08 42 'dummy.idl'; eval "$shar_touch") &&
chmod 0644 'dummy.idl' ||
$echo 'restore of' 'dummy.idl' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'dummy.idl:' 'MD5 check failed'
d30dac702a53082a724058a03f76d31c dummy.idl
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'dummy.idl'`"
test 38 -eq "$shar_count" ||
$echo 'dummy.idl:' 'original size' '38,' 'current size' "$shar_count!"
fi
fi
# ============= file1.inc ==============
if test -f 'file1.inc' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'file1.inc' '(file already exists)'
else
$echo 'x -' extracting 'file1.inc' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'file1.inc' &&
This is file 1.
SHAR_EOF
(set 20 01 07 25 11 50 16 'file1.inc'; eval "$shar_touch") &&
chmod 0644 'file1.inc' ||
$echo 'restore of' 'file1.inc' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'file1.inc:' 'MD5 check failed'
2a92a3af0aca77382eb248c2d16d3716 file1.inc
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'file1.inc'`"
test 16 -eq "$shar_count" ||
$echo 'file1.inc:' 'original size' '16,' 'current size' "$shar_count!"
fi
fi
# ============= file2.inc ==============
if test -f 'file2.inc' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'file2.inc' '(file already exists)'
else
$echo 'x -' extracting 'file2.inc' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'file2.inc' &&
This is file2.
SHAR_EOF
(set 20 01 07 25 11 22 22 'file2.inc'; eval "$shar_touch") &&
chmod 0644 'file2.inc' ||
$echo 'restore of' 'file2.inc' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'file2.inc:' 'MD5 check failed'
e3f69261e61136bedc1961ee7f95a897 file2.inc
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'file2.inc'`"
test 15 -eq "$shar_count" ||
$echo 'file2.inc:' 'original size' '15,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh17083
exit 0
- How to get a QuickScan scanner to read a whole file in one call?,
David Sanderson <=