programmatically determine whether records exist

Fairlight fairlite at fairlite.com
Mon Feb 16 08:56:00 PST 2015


What's DDW stand for?  Dat Didn't Work?  :)

What you describe is what I was told, but I couldn't even reproduce that on
another system when I tried to.  I was able to be in rclerk and it read and
passed record 1.

Interesting about the byte having a value of 2.  That's not documented in
the key file specification on the official website.  I worked from those
docs.  In any event, I only explicitly check against 1, and infer zero if
it's not 1.  So that's not it.

Code below...

#!/usr/bin/perl

use strict;

$| = 1;

my $debug = 9;

my $fpfile = shift;
my $qual = shift;
if (not defined(${fpfile})) {
     &fl_die("No filePro file specified.\n");
}

my $fpdata = '';
my $fpdir = '';
open(FPPATH,"</etc/default/fppath");
my @pathlines = <FPPATH>;
close(FPPATH);
foreach my $line (@pathlines) {
     chomp(${line});
}
if (scalar(@pathlines) >= 3) {
}
if (defined(${ENV{'FPDATA'}})) {
     $fpdata = ${ENV{'FPDATA'}};
} elsif (defined(${ENV{'PFDATA'}})) {
     $fpdata = ${ENV{'PFDATA'}};
}
if (defined(${ENV{'FPDIR'}})) {
     $fpdir = ${ENV{'FPDIR'}};
} elsif (defined(${ENV{'PFDIR'}})) {
     $fpdir = ${ENV{'PFDIR'}};
}
my $fppath = '';
if (${fpdata} ne '') {
     $fppath .= ${fpdata};
}
if (${fpdir} ne '') {
     $fppath .= ${fpdir};
}
$fppath .= '/filepro';
&fl_die("The path to your filePro data is not set via either /etc/default/fppath
 or \nvia environment variables.\n") if ${fppath} eq '/filepro';

my $mapfile = "${fppath}/${fpfile}/map";
my $keyfile = "${fppath}/${fpfile}/key${qual}";

print("map: ${mapfile}\n");
print("key: ${keyfile}\n");

my $reclen = 0;
open(MAP,"<${mapfile}") or die("Could not open key file '${mapfile}'\n") or &fl_die("Could not open '${mapfile}'.\n");
my @maplines = <MAP>;
my $suppline = shift(@maplines);
chomp(${suppline});
my (undef,$supposed_length,undef) = split(/:/,${suppline},3);
foreach my $line (@maplines) {
     chomp(${line});
     my (undef,$length,undef) = split(/:/,${line},3);
     $length =~ s/\s*//g;
     $reclen += ${length};
}
close(MAP) or die("Could not close map file '${mapfile}'\n");
print("Supposed Record Length: ${supposed_length}\n") if ${debug};
print("Record Length: ${reclen}\n") if ${debug};
&fl_die if ${supposed_length} != ${reclen};
print("Record length passes sanity check.\n") if ${debug};

open(KEY,"<${keyfile}") or die("Could not open key file '${keyfile}'\n") or &fl_die("Could not open '${keyfile}'.\n");
binmode(KEY);
my @usedrecs = ();
my $foundused = 0;
my $totalrecs = 0;
my $noteof = 1;
while (${noteof}) { 
     $totalrecs++;
     my $buffer = '';
     my $res = sysread(KEY,${buffer},20);
     print("Read ${res} bytes.\n") if ${debug} == 9;
     $noteof++, last if ${res} == 0;
     &fl_die("Tried to read 20 byte header and only got ${res} bytes.\n") if ${res} != 20;
     my @delchars = split(//,${buffer});
     my $delchar = ord(${delchars}[0]);
     my $thistime = 0;
     if (${delchar} == 1) {
          $thistime++;
          print("Record deleted value: ${delchar}\n") if ${debug} == 9;
          $foundused++; 
          push(@usedrecs,${totalrecs});
          $res = sysread(KEY,${buffer},${reclen});
          print("Read ${res} bytes.\n") if ${debug} == 9;
          last;
     }
     $res = sysread(KEY,${buffer},${reclen});
     print("Read ${res} bytes.\n") if ${debug} == 9;
     print("BUFFER: |${buffer}|\n") if ${debug} == 10;
     $noteof++, last if ${res} == 0;
     &fl_die("Tried to read ${reclen} byte record and only got ${res} bytes.\n") if ${res} != ${reclen};
     #print("Found non-spaces in record space on record ${totalrecs}.\n") if ${buffer} !~ /^ *$/ and not ${thistime};
     #$foundused++, push(@usedrecs,${totalrecs}) if ${buffer} !~ /^ *$/ and not ${thistime};
}
close(KEY) or die("Could not close key file '${keyfile}'\n");

if (${foundused}) {
     print("Found live record(s).\n");
} else {
     print("Did not find any live records.\n");
}

exit;

##### Custom die.
sub fl_die {
     my $err = shift;
     chomp(${err});
     print STDERR ("ERROR: ${err}\n");
     exit(1);
}


On Mon, Feb 16, 2015 at 11:40:23AM -0500, Kenneth Brody thus spoke:
> On 2/16/2015 11:15 AM, Fairlight wrote:
> >Hey Ken?
> >
> >I wrote something external which just reads in every record and checks byte
> >one of the header.  If it's 0, it's not used, if it's 1, it's used.  It
> >apparently runs fine, -except- if someone is in the middle of modifying
> >record #1.
> 
> "DDW".  :-)
> 
> What about record 2?  Are you saying that people can be updating
> other records, and only record 1 causes a problem?
> 
> >Any clue why that would be?
> 
> Not without knowing what, exactly "doesn't work", what O/S this is,
> and not without knowing what, exactly, your code does to read the
> records.
> 
> FYI - There's another possible value for the first byte of the
> record.  If someone is creating a record, the byte will be 2.  (It's
> been removed from the freechain, but doesn't yet "exist".)
> 
> -- 
> Kenneth Brody
> 

-- 
Audio panton, cogito singularis.


More information about the Filepro-list mailing list