Working with afppowertools

Rule = condition + action

The parser reads a Structured Field, test the condition, and if the condition is met, apply the action. Condition and action must be references to subs.

First Steps: a single rule

Consider the following code snippet:

#! /usr/bin/perl -w
use strict;
use AFP::PowerTools::Parser;


my $afpfile = shift or die "give an afp file as argument";

my $get_value = sub {
        my $sf = shift;
        my $obj_type = get_triplet_parameter($sf->{members}, "ObjType", "21");
        printf "\"%s\"type: %s\n", get_fixed_parameter( $sf->{RSName}), $obj_type;

};


my $parser = AFP::PowerTools::Parser->new();
$parser->set_rule(is_SF("BRS"),$get_value);
$parser->parse_AFP_file($afpfile);

First you create the parser with AFP::PowerTools::Parser->new()

Then register the handlers with set_rule

Note

Note: $get_value is a reference to a sub.

is_SF() is a function from the library, it generates also a reference to a sub.

If you have more than one rule, you will need to register each rule separately with set_rule(). Rules are applied in the order in which they have been registered.

Basic utilities

Here is a list of scripts that come bundled with afppowertools:

  • afp_wc.pl

    Similar to unix' wc. It displays the number of pages, of structured fields and various statistics on a AFP file. For example if you want to check the BRS and ERS SF's:

    ./afp_hexdump_sf.pl sample.afp BRS ERS

  • afp_hexdump.pl <inputfile> <SF>

    Hexadecimal dump of the structured fields <SF> of that file.

  • afp_list_resources*pl

    List the resources by reading RSName in BRS.

  • afp_yamldump.pl

    Use YAML to dumps a "prettied" version of the structured fields. (see "internals" for what is meant by pretty). Beware, this can generate a huge output.

    You can give a list of SF's at the command line to only display those Structured Fields.

  • afp_get_ptxtext_with_encodings.pl

    Displays the text of PTX TRNDATA, showing for each string which encoding was used. Makes no attempt at formatting: each sequence is displayed in a new line.

  • afp_get_ptxdata.pl

    Displays all the PTX sequences of your file.

  • afp_print_tles.pl

    Prints all the TLE's, each on one line.

  • afp_tle2tab.pl

    For each page or named group, print some TLE's to a tab-separated file. You can configure the field separator, the names and the order of the columns.